Completed
Push — master ( cace1c...4cd08d )
by Jan-Petter
02:34
created

UserAgentTest::testCharacterCase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
namespace vipnytt\robot\UserAgentParser\Tests;
3
4
use vipnytt\XRobotsTagParser\UserAgentParser;
5
6
class UserAgentTest extends \PHPUnit_Framework_TestCase
7
{
8
    /**
9
     * Character case
10
     */
11
    public function testCharacterCase()
12
    {
13
        $parser = new UserAgentParser('GoogleBot');
14
        $this->assertInstanceOf('vipnytt\XRobotsTagParser\UserAgentParser', $parser);
15
16
        $this->assertEquals('googlebot', $parser->match(['GoogleBot']));
17
    }
18
19
    /**
20
     * Strip version
21
     */
22
    public function testStripVersion()
23
    {
24
        $parser = new UserAgentParser('googlebot/2.1');
25
        $this->assertInstanceOf('vipnytt\XRobotsTagParser\UserAgentParser', $parser);
26
27
        $this->assertEquals('googlebot', $parser->stripVersion());
28
    }
29
30
    /**
31
     * Find match
32
     */
33
    public function testMatch()
34
    {
35
        $parser = new UserAgentParser('googlebot-news');
36
        $this->assertInstanceOf('vipnytt\XRobotsTagParser\UserAgentParser', $parser);
37
38
        $this->assertEquals('googlebot-news', $parser->match(['googlebot', 'googlebot-news', 'google', 'gooblebot-news-unknown'], '*'));
39
        $this->assertEquals('googlebot', $parser->match(['googlebot', 'bingbot', 'mybot', ''], '*'));
40
        $this->assertEquals('*', $parser->match(['yandexbot', 'bingbot', 'mybot', ''], '*'));
41
    }
42
43
    /**
44
     * Get all
45
     */
46
    public function testExport()
47
    {
48
        $parser = new UserAgentParser('googlebot-news/2.1');
49
        $this->assertInstanceOf('vipnytt\XRobotsTagParser\UserAgentParser', $parser);
50
51
        $this->assertContains('googlebot-news/2.1', $parser->export());
52
        $this->assertContains('googlebot-news', $parser->export());
53
        $this->assertContains('googlebot', $parser->export());
54
    }
55
}
56