Completed
Push — master ( 64491b...1f7f5f )
by Jan-Petter
30:57
created

UserAgentTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 50
rs 10

4 Methods

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