xref: /plugin/statistics/_test/SearchEnginesTest.php (revision c428ec28b92989bfa72433f30fd3e015edbb413c)
1364ef148SAndreas Gohr<?php
2364ef148SAndreas Gohr
3364ef148SAndreas Gohrnamespace dokuwiki\plugin\statistics\test;
4364ef148SAndreas Gohr
5364ef148SAndreas Gohruse DokuWikiTest;
6364ef148SAndreas Gohruse dokuwiki\plugin\statistics\SearchEngines;
7364ef148SAndreas Gohr
8364ef148SAndreas Gohr/**
9364ef148SAndreas Gohr * Tests for the SearchEngines class
10364ef148SAndreas Gohr *
11364ef148SAndreas Gohr * @group plugin_statistics
12364ef148SAndreas Gohr * @group plugins
13364ef148SAndreas Gohr */
14364ef148SAndreas Gohrclass SearchEnginesTest extends DokuWikiTest
15364ef148SAndreas Gohr{
16364ef148SAndreas Gohr    /**
17364ef148SAndreas Gohr     * Data provider for testing known search engines
18364ef148SAndreas Gohr     */
19364ef148SAndreas Gohr    public function knownSearchEnginesProvider(): array
20364ef148SAndreas Gohr    {
21364ef148SAndreas Gohr        return [
22364ef148SAndreas Gohr            // Google variants
23364ef148SAndreas Gohr            'google.com' => [
24364ef148SAndreas Gohr                'https://www.google.com/search?q=dokuwiki+test',
25364ef148SAndreas Gohr                true,
26364ef148SAndreas Gohr                'google',
27364ef148SAndreas Gohr                'Google',
28364ef148SAndreas Gohr                'dokuwiki test'
29364ef148SAndreas Gohr            ],
30364ef148SAndreas Gohr            'google.co.uk' => [
31364ef148SAndreas Gohr                'https://www.google.co.uk/search?q=php+framework',
32364ef148SAndreas Gohr                true,
33364ef148SAndreas Gohr                'google',
34364ef148SAndreas Gohr                'Google',
35364ef148SAndreas Gohr                'php framework'
36364ef148SAndreas Gohr            ],
37364ef148SAndreas Gohr            'google.de' => [
38364ef148SAndreas Gohr                'https://www.google.de/search?q=test+query',
39364ef148SAndreas Gohr                true,
40364ef148SAndreas Gohr                'google',
41364ef148SAndreas Gohr                'Google',
42364ef148SAndreas Gohr                'test query'
43364ef148SAndreas Gohr            ],
44364ef148SAndreas Gohr
45364ef148SAndreas Gohr            // Bing
46364ef148SAndreas Gohr            'bing.com' => [
47364ef148SAndreas Gohr                'https://www.bing.com/search?q=dokuwiki+plugin',
48364ef148SAndreas Gohr                true,
49364ef148SAndreas Gohr                'bing',
50364ef148SAndreas Gohr                'Bing',
51364ef148SAndreas Gohr                'dokuwiki plugin'
52364ef148SAndreas Gohr            ],
53364ef148SAndreas Gohr            'bing.co.uk' => [
54364ef148SAndreas Gohr                'https://www.bing.co.uk/search?q=search+test',
55364ef148SAndreas Gohr                true,
56364ef148SAndreas Gohr                'bing',
57364ef148SAndreas Gohr                'Bing',
58364ef148SAndreas Gohr                'search test'
59364ef148SAndreas Gohr            ],
60364ef148SAndreas Gohr
61364ef148SAndreas Gohr            // Yahoo
62364ef148SAndreas Gohr            'yahoo.com' => [
63364ef148SAndreas Gohr                'https://search.yahoo.com/search?p=test+search',
64364ef148SAndreas Gohr                true,
65364ef148SAndreas Gohr                'yahoo',
66364ef148SAndreas Gohr                'Yahoo!',
67364ef148SAndreas Gohr                'test search'
68364ef148SAndreas Gohr            ],
69364ef148SAndreas Gohr
70364ef148SAndreas Gohr            // Yandex
71364ef148SAndreas Gohr            'yandex.ru' => [
72364ef148SAndreas Gohr                'https://yandex.ru/search/?query=test+query',
73364ef148SAndreas Gohr                true,
74364ef148SAndreas Gohr                'yandex',
75364ef148SAndreas Gohr                'Яндекс (Yandex)',
76364ef148SAndreas Gohr                'test query'
77364ef148SAndreas Gohr            ],
78364ef148SAndreas Gohr            'yandex.com' => [
79364ef148SAndreas Gohr                'https://yandex.com/search/?query=another+test',
80364ef148SAndreas Gohr                true,
81364ef148SAndreas Gohr                'yandex',
82364ef148SAndreas Gohr                'Яндекс (Yandex)',
83364ef148SAndreas Gohr                'another test'
84364ef148SAndreas Gohr            ],
85364ef148SAndreas Gohr
86364ef148SAndreas Gohr            // Naver
87364ef148SAndreas Gohr            'naver.com' => [
88364ef148SAndreas Gohr                'https://search.naver.com/search.naver?query=korean+search',
89364ef148SAndreas Gohr                true,
90364ef148SAndreas Gohr                'naver',
91364ef148SAndreas Gohr                '네이버 (Naver)',
92364ef148SAndreas Gohr                'korean search'
93364ef148SAndreas Gohr            ],
94364ef148SAndreas Gohr
95364ef148SAndreas Gohr            // Baidu
96364ef148SAndreas Gohr            'baidu.com' => [
97364ef148SAndreas Gohr                'https://www.baidu.com/s?wd=chinese+search',
98364ef148SAndreas Gohr                true,
99364ef148SAndreas Gohr                'baidu',
100364ef148SAndreas Gohr                '百度 (Baidu)',
101364ef148SAndreas Gohr                'chinese search'
102364ef148SAndreas Gohr            ],
103364ef148SAndreas Gohr            'baidu.com word param' => [
104364ef148SAndreas Gohr                'https://www.baidu.com/s?word=test+word',
105364ef148SAndreas Gohr                true,
106364ef148SAndreas Gohr                'baidu',
107364ef148SAndreas Gohr                '百度 (Baidu)',
108364ef148SAndreas Gohr                'test word'
109364ef148SAndreas Gohr            ],
110364ef148SAndreas Gohr            'baidu.com kw param' => [
111364ef148SAndreas Gohr                'https://www.baidu.com/s?kw=keyword+test',
112364ef148SAndreas Gohr                true,
113364ef148SAndreas Gohr                'baidu',
114364ef148SAndreas Gohr                '百度 (Baidu)',
115364ef148SAndreas Gohr                'keyword test'
116364ef148SAndreas Gohr            ],
117364ef148SAndreas Gohr
118364ef148SAndreas Gohr            // Ask
119364ef148SAndreas Gohr            'ask.com' => [
120364ef148SAndreas Gohr                'https://www.ask.com/web?q=ask+search',
121364ef148SAndreas Gohr                true,
122364ef148SAndreas Gohr                'ask',
123364ef148SAndreas Gohr                'Ask',
124364ef148SAndreas Gohr                'ask search'
125364ef148SAndreas Gohr            ],
126364ef148SAndreas Gohr            'ask.com ask param' => [
127364ef148SAndreas Gohr                'https://www.ask.com/web?ask=test+ask',
128364ef148SAndreas Gohr                true,
129364ef148SAndreas Gohr                'ask',
130364ef148SAndreas Gohr                'Ask',
131364ef148SAndreas Gohr                'test ask'
132364ef148SAndreas Gohr            ],
133364ef148SAndreas Gohr            'search-results.com' => [
134364ef148SAndreas Gohr                'https://www.search-results.com/web?q=search+results',
135364ef148SAndreas Gohr                true,
136364ef148SAndreas Gohr                'ask_search_results',
137364ef148SAndreas Gohr                'Ask',
138364ef148SAndreas Gohr                'search results'
139364ef148SAndreas Gohr            ],
140364ef148SAndreas Gohr
141364ef148SAndreas Gohr            // DuckDuckGo
142364ef148SAndreas Gohr            'duckduckgo.com' => [
143364ef148SAndreas Gohr                'https://duckduckgo.com/?q=privacy+search',
144364ef148SAndreas Gohr                true,
145364ef148SAndreas Gohr                'duckduckgo',
146364ef148SAndreas Gohr                'DuckDuckGo',
147364ef148SAndreas Gohr                'privacy search'
148364ef148SAndreas Gohr            ],
149364ef148SAndreas Gohr
150364ef148SAndreas Gohr            // AOL
151364ef148SAndreas Gohr            'aol.com' => [
152364ef148SAndreas Gohr                'https://search.aol.com/aol/search?query=aol+search',
153364ef148SAndreas Gohr                true,
154364ef148SAndreas Gohr                'aol',
155364ef148SAndreas Gohr                'AOL Search',
156364ef148SAndreas Gohr                'aol search'
157364ef148SAndreas Gohr            ],
158364ef148SAndreas Gohr            'aol.co.uk' => [
159364ef148SAndreas Gohr                'https://search.aol.co.uk/aol/search?q=uk+search',
160364ef148SAndreas Gohr                true,
161364ef148SAndreas Gohr                'aol',
162364ef148SAndreas Gohr                'AOL Search',
163364ef148SAndreas Gohr                'uk search'
164364ef148SAndreas Gohr            ],
165364ef148SAndreas Gohr
166364ef148SAndreas Gohr            // Babylon
167364ef148SAndreas Gohr            'babylon.com' => [
168364ef148SAndreas Gohr                'https://search.babylon.com/?q=babylon+search',
169364ef148SAndreas Gohr                true,
170364ef148SAndreas Gohr                'babylon',
171364ef148SAndreas Gohr                'Babylon',
172364ef148SAndreas Gohr                'babylon search'
173364ef148SAndreas Gohr            ],
174364ef148SAndreas Gohr
175364ef148SAndreas Gohr            // Google AVG
176364ef148SAndreas Gohr            'avg.com' => [
177364ef148SAndreas Gohr                'https://search.avg.com/search?q=avg+search',
178364ef148SAndreas Gohr                true,
179364ef148SAndreas Gohr                'google_avg',
180364ef148SAndreas Gohr                'Google',
181364ef148SAndreas Gohr                'avg search'
182364ef148SAndreas Gohr            ],
183364ef148SAndreas Gohr        ];
184364ef148SAndreas Gohr    }
185364ef148SAndreas Gohr
186364ef148SAndreas Gohr    /**
187364ef148SAndreas Gohr     * Data provider for testing generic search engines
188364ef148SAndreas Gohr     */
189364ef148SAndreas Gohr    public function genericSearchEnginesProvider(): array
190364ef148SAndreas Gohr    {
191364ef148SAndreas Gohr        return [
192364ef148SAndreas Gohr            'generic with q param' => [
193364ef148SAndreas Gohr                'https://search.example.com/?q=generic+search',
194364ef148SAndreas Gohr                true,
195364ef148SAndreas Gohr                'example',
196364ef148SAndreas Gohr                'Example',
197364ef148SAndreas Gohr                'generic search'
198364ef148SAndreas Gohr            ],
199364ef148SAndreas Gohr            'generic with query param' => [
200364ef148SAndreas Gohr                'https://find.testsite.org/search?query=test+query',
201364ef148SAndreas Gohr                true,
202364ef148SAndreas Gohr                'testsite',
203364ef148SAndreas Gohr                'Testsite',
204364ef148SAndreas Gohr                'test query'
205364ef148SAndreas Gohr            ],
206364ef148SAndreas Gohr            'generic with search param' => [
207364ef148SAndreas Gohr                'https://www.searchengine.net/?search=search+term',
208364ef148SAndreas Gohr                true,
209364ef148SAndreas Gohr                'searchengine',
210364ef148SAndreas Gohr                'Searchengine',
211364ef148SAndreas Gohr                'search term'
212364ef148SAndreas Gohr            ],
213364ef148SAndreas Gohr            'generic with keywords param' => [
214364ef148SAndreas Gohr                'https://lookup.site.com/?keywords=keyword+test',
215364ef148SAndreas Gohr                true,
216364ef148SAndreas Gohr                'site',
217364ef148SAndreas Gohr                'Site',
218364ef148SAndreas Gohr                'keyword test'
219364ef148SAndreas Gohr            ],
220364ef148SAndreas Gohr            'generic with keyword param' => [
221364ef148SAndreas Gohr                'https://engine.co.uk/?keyword=single+keyword',
222364ef148SAndreas Gohr                true,
223364ef148SAndreas Gohr                'engine',
224364ef148SAndreas Gohr                'Engine',
225364ef148SAndreas Gohr                'single keyword'
226364ef148SAndreas Gohr            ],
227364ef148SAndreas Gohr        ];
228364ef148SAndreas Gohr    }
229364ef148SAndreas Gohr
230364ef148SAndreas Gohr    /**
231364ef148SAndreas Gohr     * Data provider for testing non-search engine referers
232364ef148SAndreas Gohr     */
233364ef148SAndreas Gohr    public function nonSearchEngineProvider(): array
234364ef148SAndreas Gohr    {
235364ef148SAndreas Gohr        return [
236364ef148SAndreas Gohr            'regular website' => [
237364ef148SAndreas Gohr                'https://www.example.com/page',
238364ef148SAndreas Gohr                false,
239364ef148SAndreas Gohr                null,
240364ef148SAndreas Gohr                null,
241364ef148SAndreas Gohr                null
242364ef148SAndreas Gohr            ],
243364ef148SAndreas Gohr            'social media' => [
244364ef148SAndreas Gohr                'https://www.facebook.com/share',
245364ef148SAndreas Gohr                false,
246364ef148SAndreas Gohr                null,
247364ef148SAndreas Gohr                null,
248364ef148SAndreas Gohr                null
249364ef148SAndreas Gohr            ],
250364ef148SAndreas Gohr            'search engine without query' => [
251364ef148SAndreas Gohr                'https://www.google.com/',
252364ef148SAndreas Gohr                false,
253364ef148SAndreas Gohr                null,
254364ef148SAndreas Gohr                null,
255364ef148SAndreas Gohr                null
256364ef148SAndreas Gohr            ],
257364ef148SAndreas Gohr            'search engine with empty query' => [
258364ef148SAndreas Gohr                'https://www.google.com/search?q=',
259364ef148SAndreas Gohr                false,
260364ef148SAndreas Gohr                null,
261364ef148SAndreas Gohr                null,
262364ef148SAndreas Gohr                null
263364ef148SAndreas Gohr            ],
264364ef148SAndreas Gohr            'invalid URL' => [
265364ef148SAndreas Gohr                'not-a-url',
266364ef148SAndreas Gohr                false,
267364ef148SAndreas Gohr                null,
268364ef148SAndreas Gohr                null,
269364ef148SAndreas Gohr                null
270364ef148SAndreas Gohr            ],
271364ef148SAndreas Gohr            'URL without host' => [
272364ef148SAndreas Gohr                '/local/path',
273364ef148SAndreas Gohr                false,
274364ef148SAndreas Gohr                null,
275364ef148SAndreas Gohr                null,
276364ef148SAndreas Gohr                null
277364ef148SAndreas Gohr            ],
278364ef148SAndreas Gohr        ];
279364ef148SAndreas Gohr    }
280364ef148SAndreas Gohr
281364ef148SAndreas Gohr    /**
282364ef148SAndreas Gohr     * Data provider for testing query cleaning
283364ef148SAndreas Gohr     */
284364ef148SAndreas Gohr    public function queryCleaningProvider(): array
285364ef148SAndreas Gohr    {
286364ef148SAndreas Gohr        return [
287364ef148SAndreas Gohr            'cache query removed' => [
288364ef148SAndreas Gohr                'https://www.google.com/search?q=cache:example.com+test',
289364ef148SAndreas Gohr                true,
290364ef148SAndreas Gohr                'google',
291364ef148SAndreas Gohr                'Google',
292364ef148SAndreas Gohr                'test'
293364ef148SAndreas Gohr            ],
294364ef148SAndreas Gohr            'related query removed' => [
295364ef148SAndreas Gohr                'https://www.google.com/search?q=related:example.com+search',
296364ef148SAndreas Gohr                true,
297364ef148SAndreas Gohr                'google',
298364ef148SAndreas Gohr                'Google',
299364ef148SAndreas Gohr                'search'
300364ef148SAndreas Gohr            ],
301364ef148SAndreas Gohr            'multiple spaces compacted' => [
302364ef148SAndreas Gohr                'https://www.google.com/search?q=test++multiple+++spaces',
303364ef148SAndreas Gohr                true,
304364ef148SAndreas Gohr                'google',
305364ef148SAndreas Gohr                'Google',
306364ef148SAndreas Gohr                'test multiple spaces'
307364ef148SAndreas Gohr            ],
308364ef148SAndreas Gohr            'whitespace trimmed' => [
309364ef148SAndreas Gohr                'https://www.google.com/search?q=++trimmed++',
310364ef148SAndreas Gohr                true,
311364ef148SAndreas Gohr                'google',
312364ef148SAndreas Gohr                'Google',
313364ef148SAndreas Gohr                'trimmed'
314364ef148SAndreas Gohr            ],
315364ef148SAndreas Gohr        ];
316364ef148SAndreas Gohr    }
317364ef148SAndreas Gohr
318364ef148SAndreas Gohr    /**
319364ef148SAndreas Gohr     * Data provider for testing fragment-based queries
320364ef148SAndreas Gohr     */
321364ef148SAndreas Gohr    public function fragmentQueryProvider(): array
322364ef148SAndreas Gohr    {
323364ef148SAndreas Gohr        return [
324364ef148SAndreas Gohr            'fragment query' => [
325364ef148SAndreas Gohr                'https://www.google.com/search#q=fragment+query',
326364ef148SAndreas Gohr                true,
327364ef148SAndreas Gohr                'google',
328364ef148SAndreas Gohr                'Google',
329364ef148SAndreas Gohr                'fragment query'
330364ef148SAndreas Gohr            ],
331364ef148SAndreas Gohr            'fragment with multiple params' => [
332364ef148SAndreas Gohr                'https://www.bing.com/search#q=fragment+test&other=param',
333364ef148SAndreas Gohr                true,
334364ef148SAndreas Gohr                'bing',
335364ef148SAndreas Gohr                'Bing',
336364ef148SAndreas Gohr                'fragment test'
337364ef148SAndreas Gohr            ],
338364ef148SAndreas Gohr        ];
339364ef148SAndreas Gohr    }
340364ef148SAndreas Gohr
341364ef148SAndreas Gohr    /**
342364ef148SAndreas Gohr     * Test known search engines
343364ef148SAndreas Gohr     * @dataProvider knownSearchEnginesProvider
344364ef148SAndreas Gohr     */
345364ef148SAndreas Gohr    public function testKnownSearchEngines(
346364ef148SAndreas Gohr        string $referer,
347364ef148SAndreas Gohr        bool $expectedIsSearchEngine,
348364ef148SAndreas Gohr        ?string $expectedEngine,
349364ef148SAndreas Gohr        ?string $expectedName,
350364ef148SAndreas Gohr        ?string $expectedQuery
351364ef148SAndreas Gohr    ): void {
352364ef148SAndreas Gohr        $searchEngine = new SearchEngines($referer);
353364ef148SAndreas Gohr
354364ef148SAndreas Gohr        $this->assertEquals($expectedIsSearchEngine, $searchEngine->isSearchEngine());
355364ef148SAndreas Gohr        $this->assertEquals($expectedEngine, $searchEngine->getEngine());
356364ef148SAndreas Gohr        $this->assertEquals($expectedQuery, $searchEngine->getQuery());
357364ef148SAndreas Gohr
358364ef148SAndreas Gohr        if ($expectedEngine) {
359364ef148SAndreas Gohr            $this->assertEquals($expectedName, SearchEngines::getName($expectedEngine));
360364ef148SAndreas Gohr        }
361364ef148SAndreas Gohr    }
362364ef148SAndreas Gohr
363364ef148SAndreas Gohr    /**
364364ef148SAndreas Gohr     * Test generic search engines
365364ef148SAndreas Gohr     * @dataProvider genericSearchEnginesProvider
366364ef148SAndreas Gohr     */
367364ef148SAndreas Gohr    public function testGenericSearchEngines(
368364ef148SAndreas Gohr        string $referer,
369364ef148SAndreas Gohr        bool $expectedIsSearchEngine,
370364ef148SAndreas Gohr        ?string $expectedEngine,
371364ef148SAndreas Gohr        ?string $expectedName,
372364ef148SAndreas Gohr        ?string $expectedQuery
373364ef148SAndreas Gohr    ): void {
374364ef148SAndreas Gohr        $searchEngine = new SearchEngines($referer);
375364ef148SAndreas Gohr
376364ef148SAndreas Gohr        $this->assertEquals($expectedIsSearchEngine, $searchEngine->isSearchEngine());
377364ef148SAndreas Gohr        $this->assertEquals($expectedEngine, $searchEngine->getEngine());
378364ef148SAndreas Gohr        $this->assertEquals($expectedQuery, $searchEngine->getQuery());
379364ef148SAndreas Gohr
380364ef148SAndreas Gohr        if ($expectedEngine) {
381364ef148SAndreas Gohr            $this->assertEquals($expectedName, SearchEngines::getName($expectedEngine));
382364ef148SAndreas Gohr        }
383364ef148SAndreas Gohr    }
384364ef148SAndreas Gohr
385364ef148SAndreas Gohr    /**
386364ef148SAndreas Gohr     * Test non-search engine referers
387364ef148SAndreas Gohr     * @dataProvider nonSearchEngineProvider
388364ef148SAndreas Gohr     */
389364ef148SAndreas Gohr    public function testNonSearchEngines(
390364ef148SAndreas Gohr        string $referer,
391364ef148SAndreas Gohr        bool $expectedIsSearchEngine,
392364ef148SAndreas Gohr        ?string $expectedEngine,
393364ef148SAndreas Gohr        ?string $expectedName,
394364ef148SAndreas Gohr        ?string $expectedQuery
395364ef148SAndreas Gohr    ): void {
396364ef148SAndreas Gohr        $searchEngine = new SearchEngines($referer);
397364ef148SAndreas Gohr
398364ef148SAndreas Gohr        $this->assertEquals($expectedIsSearchEngine, $searchEngine->isSearchEngine());
399364ef148SAndreas Gohr        $this->assertEquals($expectedEngine, $searchEngine->getEngine());
400364ef148SAndreas Gohr        $this->assertEquals($expectedQuery, $searchEngine->getQuery());
401364ef148SAndreas Gohr    }
402364ef148SAndreas Gohr
403364ef148SAndreas Gohr    /**
404364ef148SAndreas Gohr     * Test query cleaning functionality
405364ef148SAndreas Gohr     * @dataProvider queryCleaningProvider
406364ef148SAndreas Gohr     */
407364ef148SAndreas Gohr    public function testQueryCleaning(
408364ef148SAndreas Gohr        string $referer,
409364ef148SAndreas Gohr        bool $expectedIsSearchEngine,
410364ef148SAndreas Gohr        ?string $expectedEngine,
411364ef148SAndreas Gohr        ?string $expectedName,
412364ef148SAndreas Gohr        ?string $expectedQuery
413364ef148SAndreas Gohr    ): void {
414364ef148SAndreas Gohr        $searchEngine = new SearchEngines($referer);
415364ef148SAndreas Gohr
416364ef148SAndreas Gohr        $this->assertEquals($expectedIsSearchEngine, $searchEngine->isSearchEngine());
417364ef148SAndreas Gohr        $this->assertEquals($expectedEngine, $searchEngine->getEngine());
418364ef148SAndreas Gohr        $this->assertEquals($expectedQuery, $searchEngine->getQuery());
419364ef148SAndreas Gohr    }
420364ef148SAndreas Gohr
421364ef148SAndreas Gohr    /**
422364ef148SAndreas Gohr     * Test fragment-based queries
423364ef148SAndreas Gohr     * @dataProvider fragmentQueryProvider
424364ef148SAndreas Gohr     */
425364ef148SAndreas Gohr    public function testFragmentQueries(
426364ef148SAndreas Gohr        string $referer,
427364ef148SAndreas Gohr        bool $expectedIsSearchEngine,
428364ef148SAndreas Gohr        ?string $expectedEngine,
429364ef148SAndreas Gohr        ?string $expectedName,
430364ef148SAndreas Gohr        ?string $expectedQuery
431364ef148SAndreas Gohr    ): void {
432364ef148SAndreas Gohr        $searchEngine = new SearchEngines($referer);
433364ef148SAndreas Gohr
434364ef148SAndreas Gohr        $this->assertEquals($expectedIsSearchEngine, $searchEngine->isSearchEngine());
435364ef148SAndreas Gohr        $this->assertEquals($expectedEngine, $searchEngine->getEngine());
436364ef148SAndreas Gohr        $this->assertEquals($expectedQuery, $searchEngine->getQuery());
437364ef148SAndreas Gohr    }
438364ef148SAndreas Gohr
439364ef148SAndreas Gohr    /**
440364ef148SAndreas Gohr     * Test static getName method with unknown engine
441364ef148SAndreas Gohr     */
442364ef148SAndreas Gohr    public function testGetNameUnknownEngine(): void
443364ef148SAndreas Gohr    {
444364ef148SAndreas Gohr        $unknownEngine = 'unknown_engine';
445*c428ec28SAndreas Gohr        $this->assertEquals('Unknown_engine', SearchEngines::getName($unknownEngine));
446364ef148SAndreas Gohr    }
447364ef148SAndreas Gohr
448364ef148SAndreas Gohr    /**
449364ef148SAndreas Gohr     * Test static getUrl method
450364ef148SAndreas Gohr     */
451364ef148SAndreas Gohr    public function testGetUrl(): void
452364ef148SAndreas Gohr    {
453364ef148SAndreas Gohr        $this->assertEquals('http://www.google.com', SearchEngines::getUrl('google'));
454364ef148SAndreas Gohr        $this->assertEquals('http://www.bing.com', SearchEngines::getUrl('bing'));
455364ef148SAndreas Gohr        $this->assertNull(SearchEngines::getUrl('unknown_engine'));
456364ef148SAndreas Gohr    }
457364ef148SAndreas Gohr
458364ef148SAndreas Gohr    /**
459364ef148SAndreas Gohr     * Test DokuWiki internal search detection
460364ef148SAndreas Gohr     */
461364ef148SAndreas Gohr    public function testDokuWikiInternalSearch(): void
462364ef148SAndreas Gohr    {
463364ef148SAndreas Gohr        // Mock DOKU_URL for testing
464364ef148SAndreas Gohr        if (!defined('DOKU_URL')) {
465364ef148SAndreas Gohr            define('DOKU_URL', 'https://wiki.example.com/');
466364ef148SAndreas Gohr        }
467364ef148SAndreas Gohr
468364ef148SAndreas Gohr        $referer = 'https://wiki.example.com/doku.php?do=search&q=internal+search';
469364ef148SAndreas Gohr        $searchEngine = new SearchEngines($referer);
470364ef148SAndreas Gohr
471364ef148SAndreas Gohr        $this->assertTrue($searchEngine->isSearchEngine());
472364ef148SAndreas Gohr        $this->assertEquals('dokuwiki', $searchEngine->getEngine());
473364ef148SAndreas Gohr        $this->assertEquals('internal search', $searchEngine->getQuery());
474364ef148SAndreas Gohr        $this->assertEquals('DokuWiki Internal Search', SearchEngines::getName('dokuwiki'));
475364ef148SAndreas Gohr    }
476364ef148SAndreas Gohr
477364ef148SAndreas Gohr    /**
478364ef148SAndreas Gohr     * Test case insensitive domain matching
479364ef148SAndreas Gohr     */
480364ef148SAndreas Gohr    public function testCaseInsensitiveDomainMatching(): void
481364ef148SAndreas Gohr    {
482364ef148SAndreas Gohr        $referer = 'https://WWW.GOOGLE.COM/search?q=case+test';
483364ef148SAndreas Gohr        $searchEngine = new SearchEngines($referer);
484364ef148SAndreas Gohr
485364ef148SAndreas Gohr        $this->assertTrue($searchEngine->isSearchEngine());
486364ef148SAndreas Gohr        $this->assertEquals('google', $searchEngine->getEngine());
487364ef148SAndreas Gohr        $this->assertEquals('case test', $searchEngine->getQuery());
488364ef148SAndreas Gohr    }
489364ef148SAndreas Gohr
490364ef148SAndreas Gohr    /**
491364ef148SAndreas Gohr     * Test URL encoding in queries
492364ef148SAndreas Gohr     */
493364ef148SAndreas Gohr    public function testUrlEncodedQueries(): void
494364ef148SAndreas Gohr    {
495364ef148SAndreas Gohr        $referer = 'https://www.google.com/search?q=url%20encoded%20query';
496364ef148SAndreas Gohr        $searchEngine = new SearchEngines($referer);
497364ef148SAndreas Gohr
498364ef148SAndreas Gohr        $this->assertTrue($searchEngine->isSearchEngine());
499364ef148SAndreas Gohr        $this->assertEquals('google', $searchEngine->getEngine());
500364ef148SAndreas Gohr        $this->assertEquals('url encoded query', $searchEngine->getQuery());
501364ef148SAndreas Gohr    }
502364ef148SAndreas Gohr
503364ef148SAndreas Gohr    /**
504364ef148SAndreas Gohr     * Test plus encoding in queries
505364ef148SAndreas Gohr     */
506364ef148SAndreas Gohr    public function testPlusEncodedQueries(): void
507364ef148SAndreas Gohr    {
508364ef148SAndreas Gohr        $referer = 'https://www.google.com/search?q=plus+encoded+query';
509364ef148SAndreas Gohr        $searchEngine = new SearchEngines($referer);
510364ef148SAndreas Gohr
511364ef148SAndreas Gohr        $this->assertTrue($searchEngine->isSearchEngine());
512364ef148SAndreas Gohr        $this->assertEquals('google', $searchEngine->getEngine());
513364ef148SAndreas Gohr        $this->assertEquals('plus encoded query', $searchEngine->getQuery());
514364ef148SAndreas Gohr    }
515364ef148SAndreas Gohr
516364ef148SAndreas Gohr    /**
517364ef148SAndreas Gohr     * Test empty constructor behavior
518364ef148SAndreas Gohr     */
519364ef148SAndreas Gohr    public function testEmptyReferer(): void
520364ef148SAndreas Gohr    {
521364ef148SAndreas Gohr        $searchEngine = new SearchEngines('');
522364ef148SAndreas Gohr
523364ef148SAndreas Gohr        $this->assertFalse($searchEngine->isSearchEngine());
524364ef148SAndreas Gohr        $this->assertNull($searchEngine->getEngine());
525364ef148SAndreas Gohr        $this->assertNull($searchEngine->getQuery());
526364ef148SAndreas Gohr    }
527364ef148SAndreas Gohr}
528