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
|
|
|
|