File: DetectAgentTest.php

package info (click to toggle)
matomo-device-detector 6.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,684 kB
  • sloc: php: 7,758; xml: 79; makefile: 15; sh: 3
file content (65 lines) | stat: -rw-r--r-- 2,020 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php

use DeviceDetector\DeviceDetector;

class DetectAgentTest extends \PHPUnit\Framework\TestCase
{
    public function testDetect(): void
    {
        $userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36';

        $dd = new DeviceDetector($userAgent);

        $this->assertFalse($dd->isBot());
        $this->assertFalse($dd->isBrowser());
        $this->assertNull($dd->getOs());
        $this->assertNull($dd->getClient());

        $dd->parse();
        $this->assertFalse($dd->isBot());
        $this->assertTrue($dd->isBrowser());
        $this->assertSame([
            'name' => 'GNU/Linux',
            'short_name' => 'LIN',
            'version' => '',
            'platform' => 'x64',
            'family' => 'GNU/Linux',
        ],$dd->getOs());
        $this->assertSame([
            'type' => 'browser',
            'name' => 'Chrome',
            'short_name' => 'CH',
            'version' => '126.0',
            'engine' => 'Blink',
            'engine_version' => '126.0.0.0',
            'family' => 'Chrome',
        ], $dd->getClient());
    }

    public function testDetectBot(): void
    {
        $userAgent = 'Mozilla/5.0 (compatible; AhrefsBot/7.0; +http://ahrefs.com/robot/)';

        $dd = new DeviceDetector($userAgent);

        $this->assertFalse($dd->isBot());
        $this->assertFalse($dd->isBrowser());
        $this->assertNull($dd->getOs());
        $this->assertNull($dd->getClient());

        $dd->parse();
        $this->assertTrue($dd->isBot());
        $this->assertFalse($dd->isBrowser());
        $this->assertNull($dd->getOs());
        $this->assertNull($dd->getClient());
        $this->assertSame([
            'name' => 'aHrefs Bot',
            'category' => 'Crawler',
            'url' => 'https://ahrefs.com/robot',
            'producer' => [
                'name' => 'Ahrefs Pte Ltd',
                'url' => 'https://ahrefs.com/robot',
            ],
        ], $dd->getBot());
    }
}