AllowedHostsFilterTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testMatchMultipleDomainsAllowed() 0 17 1
A testMatchFullHostname() 0 11 1
A testMatchSubdomain() 0 13 1
1
<?php
2
3
/*
4
 * This file is part of the Spider package.
5
 *
6
 * (c) Matthijs van den Bos <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace VDB\Spider\Tests\Filter\Prefetch;
13
14
use VDB\Spider\Filter\Prefetch\AllowedHostsFilter;
15
use VDB\Spider\Tests\TestCase;
16
use VDB\Uri\Uri;
17
18
/**
19
 *
20
 */
21
class AllowedHostsFilterTest extends TestCase
22
{
23
    /**
24
     * @covers VDB\Spider\Filter\Prefetch\AllowedHostsFilter
25
     */
26
    public function testMatchFullHostname()
27
    {
28
        $filter = new AllowedHostsFilter(array('http://blog.php-spider.org'));
29
30
        $uri1 = new Uri('http://example.org');
31
        $uri2 = new Uri('http://php-spider.org');
32
        $uri3 = new Uri('http://blog.php-spider.org');
33
34
        $this->assertTrue($filter->match($uri1));
35
        $this->assertTrue($filter->match($uri2));
36
        $this->assertFalse($filter->match($uri3));
37
    }
38
39
    /**
40
     * @covers VDB\Spider\Filter\Prefetch\AllowedHostsFilter
41
     */
42
    public function testMatchSubdomain()
43
    {
44
        $filter = new AllowedHostsFilter(array('http://blog.php-spider.org'), true);
45
46
        $uri1 = new Uri('http://example.com');
47
        $uri2 = new Uri('http://blog.php-spider.org');
48
        $uri3 = new Uri('http://test.php-spider.org');
49
        $uri4 = new Uri('http://php-spider.org');
50
51
        $this->assertTrue($filter->match($uri1));
52
        $this->assertFalse($filter->match($uri2));
53
        $this->assertFalse($filter->match($uri3));
54
        $this->assertFalse($filter->match($uri4));
55
    }
56
57
    /**
58
     * @covers VDB\Spider\Filter\Prefetch\AllowedHostsFilter
59
     */
60
    public function testMatchMultipleDomainsAllowed()
61
    {
62
        $filter = new AllowedHostsFilter(array('http://blog.php-spider.org', 'http://example.com'), true);
63
64
        $uri1 = new Uri('http://example.com');
65
        $uri2 = new Uri('http://test.example.com');
66
        $uri3 = new Uri('http://blog.php-spider.org');
67
        $uri4 = new Uri('http://test.php-spider.org');
68
        $uri5 = new Uri('http://php-spider.org');
69
        $uri6 = new Uri('http://example.org');
70
71
        $this->assertFalse($filter->match($uri1));
72
        $this->assertFalse($filter->match($uri2));
73
        $this->assertFalse($filter->match($uri3));
74
        $this->assertFalse($filter->match($uri4));
75
        $this->assertFalse($filter->match($uri5));
76
        $this->assertTrue($filter->match($uri6));
77
    }
78
}
79