Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Test with data providers
Browse files Browse the repository at this point in the history
  • Loading branch information
BreyndotEchse authored and Marvin Feldmann committed Apr 26, 2016
1 parent ab31167 commit e576b21
Showing 1 changed file with 42 additions and 30 deletions.
72 changes: 42 additions & 30 deletions test/HostnameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,43 +486,55 @@ public function testIDNIL()
}
}

public function testAdditionalUTF8TLDs()
/**
* Ensures that the validator follows expected behavior for UTF-8 and Punycoded (ACE) TLDs
*
* @dataProvider validTLDHostnames
*/
public function testValidTLDHostnames($value)
{
$validator = new Hostname(Hostname::ALLOW_ALL);
$this->assertTrue(
$this->validator->isValid($value),
sprintf(
'%s failed validation: %s',
$value,
implode("\n", $this->validator->getMessages())
)
);
}

// Check UTF-8 TLD matching
$valuesExpected = [
[true, ['test123.онлайн', 'тест.рф', 'туршилтын.мон']],
[false, ['சோதனை3.இலங்கை', 'رات.мон']]
public function validTLDHostnames()
{
// @codingStandardsIgnoreStart
return [
'ASCII label + UTF-8 TLD' => 'test123.онлайн',
'ASCII label + Punycoded TLD' => 'test123.xn--80asehdb',
'UTF-8 label + UTF-8 TLD (cyrillic)' => 'тест.рф',
'Punycoded label + Punycoded TLD (cyrillic)' => 'xn--e1aybc.xn--p1ai',
];
foreach ($valuesExpected as $element) {
foreach ($element[1] as $input) {
$this->assertEquals(
$element[0],
$validator->isValid($input),
implode("\n", $validator->getMessages()) .' - '. $input
);
}
}
// @codingStandardsIgnoreEnd
}

public function testAdditionalPunycodedTLDs()
/**
* Ensures that the validator follows expected behavior for invalid UTF-8 and Punycoded (ACE) TLDs
*
* @dataProvider invalidTLDHostnames
*/
public function testInalidTLDHostnames($value)
{
$validator = new Hostname(Hostname::ALLOW_ALL);
// Check UTF-8 TLD matching
$valuesExpected = [
[true, ['test123.xn--80asehdb', 'xn--e1aybc.xn--p1ai', 'xn--h1aggjjdd5b4a.xn--l1acc']],
[false, ['xn--3-owe4au9mpa.xn--xkc2al3hye2a', 'xn--mgbgt.xn--l1acc']]
$this->assertFalse($this->validator->isValid($value));
}

public function invalidTLDHostnames()
{
// @codingStandardsIgnoreStart
return [
'Invalid mix of UTF-8 and ASCII in label' => 'சோதனை3.இலங்கை',
'Invalid mix of UTF-8 and ASCII in label (Punycoded)' => 'xn--3-owe4au9mpa.xn--xkc2al3hye2a',
'Invalid use of non-cyrillic characters with cyrillic TLD' => 'رات.мон',
'Invalid use of non-cyrillic characters with cyrillic TLD (Punycoded)' => 'xn--mgbgt.xn--l1acc',
];
foreach ($valuesExpected as $element) {
foreach ($element[1] as $input) {
$this->assertEquals(
$element[0],
$validator->isValid($input),
implode("\n", $validator->getMessages()) .' - '. $input
);
}
}
// @codingStandardsIgnoreEnd
}

public function testIDNIT()
Expand Down

0 comments on commit e576b21

Please sign in to comment.