Completed
Push — develop ( cfc9ab...e7bb49 )
by Stéphane
02:08
created

Rule::testDisallow()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 18

Duplication

Lines 21
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 21
loc 21
rs 9.3142
cc 1
eloc 18
nc 1
nop 0
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\Rule as SUT;
15
16
/**
17
 * Rule unit test
18
 */
19
class Rule extends atoum
20
{
21
    public function testAllowAllAsDefault()
22
    {
23
        $this
24
            ->given($sut = new SUT(''))
25
            ->when($match = $sut->match('/some/url'))
26
            ->then
27
                ->boolean($match)
28
                    ->isTrue();
29
    }
30
31
    public function testAllow()
32
    {
33
        $this
34
            ->given(
35
                $sut = new SUT(''),
36
                $sut->allow('/foo/bar')
37
            )
38
            ->when($match = $sut->match('/foo/bar'))
39
            ->then
40
                ->boolean($match)
41
                    ->isTrue();
42
    }
43
44
    public function testDisallow()
45
    {
46
        $this
47
            ->given(
48
                $sut = new SUT(''),
49
                $sut->disallow('/foo/bar'),
50
                $sut->allow('/foo/bar/baz$')
51
            )
52
            ->when($match = $sut->match('/foo/bar'))
53
            ->then
54
                ->boolean($match)
55
                    ->isFalse()
56
            ->when($match = $sut->match('/foo/bar/baz/'))
57
            ->then
58
                ->boolean($match)
59
                    ->isFalse()
60
            ->when($match = $sut->match('/foo/bar/baz'))
61
            ->then
62
                ->boolean($match)
63
                    ->isTrue();
64
    }
65
66
    public function testUserAgent()
67
    {
68
        $this
69
            ->given($sut = new SUT('UA'))
70
            ->then
71
                ->string($sut->getUserAgent())
72
                    ->isEqualTo('UA');
73
    }
74
75
    public function testMultipleExpression()
76
    {
77
        $this
78
            ->given(
79
                $sut = new SUT(''),
80
                $sut->disallow('/foo/bar'),
81
                $sut->allow('/foo/bar/baz$'),
82
                $sut->allow('/foo$')
83
            )
84
            ->when($match = $sut->match('/foo/bar'))
85
            ->then
86
                ->boolean($match)
87
                    ->isFalse()
88
            ->when($match = $sut->match('/foo/bar/baz/'))
89
            ->then
90
                ->boolean($match)
91
                    ->isFalse()
92
            ->when($match = $sut->match('/foo/bar/baz'))
93
            ->then
94
                ->boolean($match)
95
                    ->isTrue();
96
    }
97
}
98