1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the beebot package. |
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
5
|
|
|
* file that was distributed with this source code. |
6
|
|
|
* |
7
|
|
|
* @copyright Bee4 2016 |
8
|
|
|
* @author Stephane HULARD <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Bee4\RobotsTxt\Test\Units; |
12
|
|
|
|
13
|
|
|
use mageekguy\atoum; |
14
|
|
|
use Bee4\RobotsTxt\Parser as SUT; |
15
|
|
|
use Bee4\RobotsTxt as LUT; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Parser unit test |
19
|
|
|
*/ |
20
|
|
|
class Parser extends atoum |
21
|
|
|
{ |
22
|
|
View Code Duplication |
public function testEmptyStringContent() |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
$this |
25
|
|
|
->given($rules = SUT::parse("")) |
26
|
|
|
->when($rule = $rules->get(LUT\Rules::DEFAULT_UA)) |
27
|
|
|
->then |
28
|
|
|
->object($rules) |
29
|
|
|
->isInstanceOf('Bee4\RobotsTxt\Rules') |
30
|
|
|
->object($rule) |
31
|
|
|
->isInstanceOf('Bee4\RobotsTxt\Rule'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
View Code Duplication |
public function testEmptyContentInstance() |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
$this |
37
|
|
|
->given( |
38
|
|
|
$content = new LUT\Content(""), |
39
|
|
|
$rules = SUT::parse($content) |
40
|
|
|
) |
41
|
|
|
->when($rule = $rules->get(LUT\Rules::DEFAULT_UA)) |
42
|
|
|
->then |
43
|
|
|
->object($rules) |
44
|
|
|
->isInstanceOf('Bee4\RobotsTxt\Rules') |
45
|
|
|
->object($rule) |
46
|
|
|
->isInstanceOf('Bee4\RobotsTxt\Rule'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testInvalidContentException() |
50
|
|
|
{ |
51
|
|
|
$this->exception(function () { |
52
|
|
|
SUT::parse(new \stdClass); |
|
|
|
|
53
|
|
|
}) |
54
|
|
|
->isInstanceOf('Bee4\RobotsTxt\Exception\InvalidContentException'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testDuplicateRuleException() |
58
|
|
|
{ |
59
|
|
|
$robot = <<<ROBOTS |
60
|
|
|
User-Agent: * |
61
|
|
|
Allow: / |
62
|
|
|
|
63
|
|
|
User-Agent: * |
64
|
|
|
Disallow: /toto |
65
|
|
|
ROBOTS; |
66
|
|
|
|
67
|
|
|
$this |
68
|
|
|
->given($content = new LUT\Content($robot)) |
69
|
|
|
->exception(function () use ($content) { |
70
|
|
|
SUT::parse($content); |
71
|
|
|
}) |
72
|
|
|
->isInstanceOf('Bee4\RobotsTxt\Exception\DuplicateRuleException'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testParse() |
76
|
|
|
{ |
77
|
|
|
$robot = <<<ROBOTS |
78
|
|
|
User-Agent: * |
79
|
|
|
Allow: / |
80
|
|
|
|
81
|
|
|
User-Agent: Google |
82
|
|
|
Disallow: /toto |
83
|
|
|
ROBOTS; |
84
|
|
|
|
85
|
|
|
$this |
86
|
|
|
->given($rules = SUT::parse($robot)) |
87
|
|
|
->then |
88
|
|
|
->sizeOf($rules) |
89
|
|
|
->isEqualTo(2) |
90
|
|
|
->boolean($rules->match('*', '/page')) |
91
|
|
|
->isTrue() |
92
|
|
|
->boolean($rules->match('Google', '/page')) |
93
|
|
|
->isTrue() |
94
|
|
|
->boolean($rules->match('Google', '/toto/page')) |
95
|
|
|
->isFalse(); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.