Skip to content

Commit a207562

Browse files
committed
Refactors and adds tests
1 parent 428718f commit a207562

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

tests/library/Pdp/ParserTest.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected function tearDown()
2828
public function testParseBadUrlThrowsInvalidArgumentException()
2929
{
3030
$this->setExpectedException(
31-
'\InvalidArgumentException',
31+
'\InvalidArgumentException',
3232
'Invalid url http:///example.com'
3333
);
3434

@@ -95,14 +95,17 @@ public function testGetSubdomain($url, $publicSuffix, $registerableDomain, $subd
9595
$this->assertSame($subdomain, $pdpUrl->host->subdomain);
9696
$this->assertSame($subdomain, $this->parser->getSubdomain($hostPart));
9797
}
98-
99-
/**
98+
99+
/**
100100
* @dataProvider parseDataProvider
101-
*/
102-
public function testPHPparse_urlCanReturnCorrectHost($url, $publicSuffix, $registerableDomain, $subdomain, $hostPart)
103-
{
104-
$this->assertEquals($hostPart, parse_url('http://' . $hostPart, PHP_URL_HOST));
105-
}
101+
*/
102+
public function testMbParseUrlCanReturnCorrectHost($url, $publicSuffix, $registerableDomain, $subdomain, $hostPart)
103+
{
104+
$this->assertEquals(
105+
$hostPart,
106+
$this->parser->mbParseUrl('http://' . $hostPart, PHP_URL_HOST)
107+
);
108+
}
106109

107110
public function parseDataProvider()
108111
{
@@ -140,6 +143,14 @@ public function parseDataProvider()
140143
array('test.museum', 'museum', 'test.museum', null, 'test.museum'),
141144
array('bob.smith.name', 'name', 'smith.name', 'bob', 'bob.smith.name'),
142145
array('tons.of.info', 'info', 'of.info', 'tons', 'tons.of.info'),
146+
// Test IDN parsing
147+
// Related to https://github.com/jeremykendall/php-domain-parser/issues/29
148+
array('http://Яндекс.РФ', 'рф', 'яндекс.рф', null, 'яндекс.рф'),
149+
array('www.食狮.中国', '中国', '食狮.中国', 'www', 'www.食狮.中国'),
150+
array('食狮.com.cn', 'com.cn', '食狮.com.cn', null, '食狮.com.cn'),
151+
// Test punycode URLs
152+
array('www.xn--85x722f.xn--fiqs8s', 'xn--fiqs8s', 'xn--85x722f.xn--fiqs8s', 'www', 'www.xn--85x722f.xn--fiqs8s'),
153+
array('xn--85x722f.com.cn', 'com.cn', 'xn--85x722f.com.cn', null, 'xn--85x722f.com.cn'),
143154
);
144155
}
145156
}

0 commit comments

Comments
 (0)