scratch – Blame information for rev 126
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
126 | office | 1 | <?php |
2 | |||
3 | namespace Aura\Uri; |
||
4 | |||
5 | /** |
||
6 | * This test case is based on the test data linked at |
||
7 | * http://publicsuffix.org/list/ and provided by Rob Strading of Comodo. |
||
8 | * @link |
||
9 | * http://mxr.mozilla.org/mozilla-central/source/netwerk/test/unit/data/test_psl.txt?raw=1 |
||
10 | */ |
||
11 | class CheckPublicSuffixTest extends \PHPUnit_Framework_TestCase |
||
12 | { |
||
13 | /** |
||
14 | * @var \Aura\Uri\PublicSuffixList |
||
15 | */ |
||
16 | protected $psl; |
||
17 | |||
18 | protected function setUp() |
||
19 | { |
||
20 | parent::setUp(); |
||
21 | $file = dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR |
||
22 | . 'data' . DIRECTORY_SEPARATOR |
||
23 | . 'public-suffix-list.php'; |
||
24 | $this->psl = new PublicSuffixList(require $file); |
||
25 | } |
||
26 | |||
27 | public function testPublicSuffixSpec() |
||
28 | { |
||
29 | // Test data from Rob Stradling at Comodo |
||
30 | // http://mxr.mozilla.org/mozilla-central/source/netwerk/test/unit/data/test_psl.txt?raw=1 |
||
31 | |||
32 | // null input. |
||
33 | $this->checkPublicSuffix(null, null); |
||
34 | // Mixed case. |
||
35 | $this->checkPublicSuffix('COM', null); |
||
36 | $this->checkPublicSuffix('example.COM', 'example.com'); |
||
37 | $this->checkPublicSuffix('WwW.example.COM', 'example.com'); |
||
38 | // Leading dot. |
||
39 | $this->checkPublicSuffix('.com', null); |
||
40 | $this->checkPublicSuffix('.example', null); |
||
41 | $this->checkPublicSuffix('.example.com', null); |
||
42 | $this->checkPublicSuffix('.example.example', null); |
||
43 | $this->checkPublicSuffix('localhost', null); |
||
44 | // Unlisted TLD. |
||
45 | // Addresses algorithm rule #2: If no rules match, the prevailing rule is "*". |
||
46 | $this->checkPublicSuffix('example', null); |
||
47 | $this->checkPublicSuffix('example.example', 'example.example'); |
||
48 | $this->checkPublicSuffix('b.example.example', 'example.example'); |
||
49 | $this->checkPublicSuffix('a.b.example.example', 'example.example'); |
||
50 | // TLD with only 1 rule. |
||
51 | $this->checkPublicSuffix('biz', null); |
||
52 | $this->checkPublicSuffix('domain.biz', 'domain.biz'); |
||
53 | $this->checkPublicSuffix('b.domain.biz', 'domain.biz'); |
||
54 | $this->checkPublicSuffix('a.b.domain.biz', 'domain.biz'); |
||
55 | // TLD with some 2-level rules. |
||
56 | $this->checkPublicSuffix('com', null); |
||
57 | $this->checkPublicSuffix('example.com', 'example.com'); |
||
58 | $this->checkPublicSuffix('b.example.com', 'example.com'); |
||
59 | $this->checkPublicSuffix('a.b.example.com', 'example.com'); |
||
60 | $this->checkPublicSuffix('uk.com', null); |
||
61 | $this->checkPublicSuffix('example.uk.com', 'example.uk.com'); |
||
62 | $this->checkPublicSuffix('b.example.uk.com', 'example.uk.com'); |
||
63 | $this->checkPublicSuffix('a.b.example.uk.com', 'example.uk.com'); |
||
64 | $this->checkPublicSuffix('test.ac', 'test.ac'); |
||
65 | // TLD with only 1 (wildcard) rule. |
||
66 | $this->checkPublicSuffix('cy', null); |
||
67 | $this->checkPublicSuffix('c.cy', null); |
||
68 | $this->checkPublicSuffix('b.c.cy', 'b.c.cy'); |
||
69 | $this->checkPublicSuffix('a.b.c.cy', 'b.c.cy'); |
||
70 | // More complex TLD. |
||
71 | $this->checkPublicSuffix('jp', null); |
||
72 | $this->checkPublicSuffix('test.jp', 'test.jp'); |
||
73 | $this->checkPublicSuffix('www.test.jp', 'test.jp'); |
||
74 | $this->checkPublicSuffix('ac.jp', null); |
||
75 | $this->checkPublicSuffix('test.ac.jp', 'test.ac.jp'); |
||
76 | $this->checkPublicSuffix('www.test.ac.jp', 'test.ac.jp'); |
||
77 | $this->checkPublicSuffix('kyoto.jp', null); |
||
78 | $this->checkPublicSuffix('test.kyoto.jp', 'test.kyoto.jp'); |
||
79 | $this->checkPublicSuffix('ide.kyoto.jp', null); |
||
80 | $this->checkPublicSuffix('b.ide.kyoto.jp', 'b.ide.kyoto.jp'); |
||
81 | $this->checkPublicSuffix('a.b.ide.kyoto.jp', 'b.ide.kyoto.jp'); |
||
82 | $this->checkPublicSuffix('c.kobe.jp', null); |
||
83 | $this->checkPublicSuffix('b.c.kobe.jp', 'b.c.kobe.jp'); |
||
84 | $this->checkPublicSuffix('a.b.c.kobe.jp', 'b.c.kobe.jp'); |
||
85 | $this->checkPublicSuffix('city.kobe.jp', 'city.kobe.jp'); |
||
86 | $this->checkPublicSuffix('www.city.kobe.jp', 'city.kobe.jp'); |
||
87 | // TLD with a wildcard rule and exceptions. |
||
88 | $this->checkPublicSuffix('om', null); |
||
89 | $this->checkPublicSuffix('test.ck', null); |
||
90 | $this->checkPublicSuffix('b.test.ck', 'b.test.ck'); |
||
91 | $this->checkPublicSuffix('a.b.test.ck', 'b.test.ck'); |
||
92 | $this->checkPublicSuffix('www.ck', 'www.ck'); |
||
93 | $this->checkPublicSuffix('www.www.ck', 'www.ck'); |
||
94 | // US K12. |
||
95 | $this->checkPublicSuffix('us', null); |
||
96 | $this->checkPublicSuffix('test.us', 'test.us'); |
||
97 | $this->checkPublicSuffix('www.test.us', 'test.us'); |
||
98 | $this->checkPublicSuffix('ak.us', null); |
||
99 | $this->checkPublicSuffix('test.ak.us', 'test.ak.us'); |
||
100 | $this->checkPublicSuffix('www.test.ak.us', 'test.ak.us'); |
||
101 | $this->checkPublicSuffix('k12.ak.us', null); |
||
102 | $this->checkPublicSuffix('test.k12.ak.us', 'test.k12.ak.us'); |
||
103 | $this->checkPublicSuffix('www.test.k12.ak.us', 'test.k12.ak.us'); |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * This is my version of the checkPublicSuffix function referred to in the |
||
108 | * test instructions at the Public Suffix List project. |
||
109 | * |
||
110 | * "You will need to define a checkPublicSuffix() function which takes as a |
||
111 | * parameter a domain name and the public suffix, runs your implementation |
||
112 | * on the domain name and checks the result is the public suffix expected." |
||
113 | * |
||
114 | * @link http://publicsuffix.org/list/ |
||
115 | * |
||
116 | * @param string $input Domain and public suffix |
||
117 | * @param string $expected Expected result |
||
118 | */ |
||
119 | public function checkPublicSuffix($input, $expected) |
||
120 | { |
||
121 | $this->assertSame($expected, $this->psl->getRegisterableDomain($input)); |
||
122 | } |
||
123 | } |