scratch – Blame information for rev 126

Subversion Repositories:
Rev:
Rev Author Line No. Line
126 office 1 <?php
2  
3 namespace Aura\Uri;
4  
5 class HostTest extends \PHPUnit_Framework_TestCase
6 {
7 /**
8 * @var \Aura\Uri\Host
9 */
10 protected $host;
11  
12 protected function setUp()
13 {
14 parent::setUp();
15  
16 $file = dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR
17 . 'data' . DIRECTORY_SEPARATOR
18 . 'public-suffix-list.php';
19 $psl = new PublicSuffixList(require $file);
20  
21 $this->host = new Host($psl);
22 }
23  
24 protected function tearDown()
25 {
26 $this->host = null;
27 parent::tearDown();
28 }
29  
30 /**
31 * @dataProvider hostDataProvider
32 */
33 public function test__toString($string)
34 {
35 $this->host->setFromString($string);
36 $this->assertEquals($string, $this->host->__toString());
37 }
38  
39 /**
40 * @dataProvider hostDataProvider
41 */
42 public function testGet($string)
43 {
44 $this->host->setFromString($string);
45 $this->assertEquals($string, $this->host->get());
46 }
47  
48 /**
49 * @dataProvider hostDataProvider
50 */
51 public function testSetFromString($string)
52 {
53 $this->host->setFromString($string);
54 $this->assertEquals($string, $this->host->__toString());
55 }
56  
57 public function hostDataProvider()
58 {
59 return array(
60 array('example.com'),
61 array('purple.com'),
62 array('localhost'),
63 );
64 }
65  
66 /**
67 * @dataProvider parseDataProvider
68 */
69 public function testParse($url, $publicSuffix, $registerableDomain, $subdomain)
70 {
71 $this->host->setFromString($url);
72 $this->assertSame($subdomain, $this->host->getSubdomain());
73 $this->assertEquals($publicSuffix, $this->host->getPublicSuffix());
74 $this->assertEquals($registerableDomain, $this->host->getRegisterableDomain());
75 $this->assertEquals($url, $this->host->get());
76 }
77  
78 public function parseDataProvider()
79 {
80 // $url, $publicSuffix, $registerableDomain, $subdomain
81 return array(
82 array('www.waxaudio.com.au', 'com.au', 'waxaudio.com.au', 'www'),
83 array('example.com', 'com', 'example.com', null),
84 array('us.example.com', 'com', 'example.com', 'us', 'us.example.com'),
85 array('us.example.na', 'na', 'example.na', 'us', 'us.example.na'),
86 array('www.example.us.na', 'us.na', 'example.us.na', 'www', 'www.example.us.na'),
87 array('us.example.org', 'org', 'example.org', 'us', 'us.example.org'),
88 array('webhop.broken.biz', 'biz', 'broken.biz', 'webhop', 'webhop.broken.biz'),
89 array('www.broken.webhop.biz', 'webhop.biz', 'broken.webhop.biz', 'www', 'www.broken.webhop.biz'),
90 array('cea-law.co.il', 'co.il', 'cea-law.co.il', null),
91 array('edition.cnn.com', 'com', 'cnn.com', 'edition'),
92 array('en.wikipedia.org', 'org', 'wikipedia.org', 'en'),
93 array('a.b.c.cy', 'c.cy', 'b.c.cy', 'a'),
94 array('test.k12.ak.us', 'k12.ak.us', 'test.k12.ak.us', null),
95 array('www.scottwills.co.uk', 'co.uk', 'scottwills.co.uk', 'www'),
96 array('b.ide.kyoto.jp', 'ide.kyoto.jp', 'b.ide.kyoto.jp', null),
97 array('a.b.example.uk.com', 'uk.com', 'example.uk.com', 'a.b'),
98 array('test.nic.ar', 'ar', 'nic.ar', 'test'),
99 array('a.b.test.ck', 'test.ck', 'b.test.ck', 'a', null),
100 array('baez.songfest.om', 'om', 'songfest.om', 'baez'),
101 array('politics.news.omanpost.om', 'om', 'omanpost.om', 'politics.news'),
102 array('localhost', null, null, null),
103 );
104 }
105  
106 }