Skip to content

Commit d2e0d88

Browse files
committed
Improve IDNAOptions test suite
1 parent ff2bf36 commit d2e0d88

File tree

5 files changed

+54
-16
lines changed

5 files changed

+54
-16
lines changed

src/TLDConverter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use function strpos;
2525
use function trim;
2626
use const DATE_ATOM;
27+
use const IDNA_DEFAULT;
2728

2829
/**
2930
* IANA Root Zone Database Parser.

tests/DomainTest.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
use PHPUnit\Framework\TestCase;
2727
use TypeError;
2828
use function date_create;
29+
use const IDNA_NONTRANSITIONAL_TO_ASCII;
30+
use const IDNA_NONTRANSITIONAL_TO_UNICODE;
2931

3032
/**
3133
* @coversDefaultClass Pdp\Domain
@@ -691,7 +693,7 @@ public function withPublicSuffixWorksProvider()
691693
'isPrivate' => false,
692694
],
693695
'with custom IDNA domain options' =>[
694-
'domain' => new Domain('www.bébé.be', new PublicSuffix('be', Rules::ICANN_DOMAINS), 16, 32),
696+
'domain' => new Domain('www.bébé.be', new PublicSuffix('be', Rules::ICANN_DOMAINS), IDNA_NONTRANSITIONAL_TO_ASCII, IDNA_NONTRANSITIONAL_TO_UNICODE),
695697
'publicSuffix' => null,
696698
'expected' => null,
697699
'isKnown' => false,
@@ -1002,7 +1004,10 @@ public function testwithoutLabelWorksWithMultipleKeys()
10021004
public function testConstructWithCustomIDNAOptions()
10031005
{
10041006
$domain = new Domain('example.com', null, IDNA_NONTRANSITIONAL_TO_ASCII, IDNA_NONTRANSITIONAL_TO_UNICODE);
1005-
self::assertSame([16, 32], [$domain->getAsciiIDNAOption(), $domain->getUnicodeIDNAOption()]);
1007+
self::assertSame(
1008+
[IDNA_NONTRANSITIONAL_TO_ASCII, IDNA_NONTRANSITIONAL_TO_UNICODE],
1009+
[$domain->getAsciiIDNAOption(), $domain->getUnicodeIDNAOption()]
1010+
);
10061011
}
10071012

10081013
/**
@@ -1094,7 +1099,13 @@ public function resolveCustomIDNAOptionsProvider()
10941099

10951100
public function testInstanceCreationWithCustomIDNAOptions()
10961101
{
1097-
$domain = new Domain('example.com', new PublicSuffix('com'), 16, 32);
1102+
$domain = new Domain(
1103+
'example.com',
1104+
new PublicSuffix('com'),
1105+
IDNA_NONTRANSITIONAL_TO_ASCII,
1106+
IDNA_NONTRANSITIONAL_TO_UNICODE
1107+
);
1108+
10981109
$instance = $domain->toAscii();
10991110
self::assertSame(
11001111
[$domain->getAsciiIDNAOption(), $domain->getUnicodeIDNAOption()],
@@ -1181,15 +1192,15 @@ public function testwithIDNAOptions()
11811192
));
11821193

11831194
self::assertNotEquals($domain, $domain->withAsciiIDNAOption(
1184-
128
1195+
IDNA_NONTRANSITIONAL_TO_ASCII
11851196
));
11861197

11871198
self::assertSame($domain, $domain->withUnicodeIDNAOption(
11881199
$domain->getUnicodeIDNAOption()
11891200
));
11901201

11911202
self::assertNotEquals($domain, $domain->withUnicodeIDNAOption(
1192-
128
1203+
IDNA_NONTRANSITIONAL_TO_UNICODE
11931204
));
11941205
}
11951206
}

tests/PublicSuffixTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use Pdp\PublicSuffix;
2222
use Pdp\Rules;
2323
use PHPUnit\Framework\TestCase;
24+
use const IDNA_NONTRANSITIONAL_TO_ASCII;
25+
use const IDNA_NONTRANSITIONAL_TO_UNICODE;
2426

2527
/**
2628
* @coversDefaultClass Pdp\PublicSuffix
@@ -263,7 +265,7 @@ public function createFromDomainProvider()
263265
'expected' => null,
264266
],
265267
[
266-
'domain' => new Domain('www.bébé.be', new PublicSuffix('be', Rules::ICANN_DOMAINS), 16, 32),
268+
'domain' => new Domain('www.bébé.be', new PublicSuffix('be', Rules::ICANN_DOMAINS), IDNA_NONTRANSITIONAL_TO_ASCII, IDNA_NONTRANSITIONAL_TO_UNICODE),
267269
'expected' => 'be',
268270
],
269271
];
@@ -285,7 +287,7 @@ public function testResolveWithCustomIDNAOptions(
285287
string $expectedAscii,
286288
string $expectedUnicode
287289
) {
288-
$publicSuffix = new PublicSuffix($name, '', 16, 32);
290+
$publicSuffix = new PublicSuffix($name, '', IDNA_NONTRANSITIONAL_TO_ASCII, IDNA_NONTRANSITIONAL_TO_UNICODE);
289291
self::assertSame($expectedContent, $publicSuffix->getContent());
290292
self::assertSame($expectedAscii, $publicSuffix->toAscii()->getContent());
291293
self::assertSame($expectedUnicode, $publicSuffix->toUnicode()->getContent());
@@ -367,15 +369,15 @@ public function testwithIDNAOptions()
367369
));
368370

369371
self::assertNotEquals($publicSuffix, $publicSuffix->withAsciiIDNAOption(
370-
128
372+
IDNA_NONTRANSITIONAL_TO_ASCII
371373
));
372374

373375
self::assertSame($publicSuffix, $publicSuffix->withUnicodeIDNAOption(
374376
$publicSuffix->getUnicodeIDNAOption()
375377
));
376378

377379
self::assertNotEquals($publicSuffix, $publicSuffix->withUnicodeIDNAOption(
378-
128
380+
IDNA_NONTRANSITIONAL_TO_UNICODE
379381
));
380382
}
381383
}

tests/RulesTest.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
use Pdp\Rules;
2727
use PHPUnit\Framework\TestCase;
2828
use TypeError;
29+
use const IDNA_DEFAULT;
30+
use const IDNA_NONTRANSITIONAL_TO_ASCII;
31+
use const IDNA_NONTRANSITIONAL_TO_UNICODE;
2932

3033
/**
3134
* @coversDefaultClass Pdp\Rules
@@ -92,15 +95,15 @@ public function testwithIDNAOptions()
9295
));
9396

9497
self::assertNotEquals($this->rules, $this->rules->withAsciiIDNAOption(
95-
128
98+
IDNA_NONTRANSITIONAL_TO_ASCII
9699
));
97100

98101
self::assertSame($this->rules, $this->rules->withUnicodeIDNAOption(
99102
$this->rules->getUnicodeIDNAOption()
100103
));
101104

102105
self::assertNotEquals($this->rules, $this->rules->withUnicodeIDNAOption(
103-
128
106+
IDNA_NONTRANSITIONAL_TO_UNICODE
104107
));
105108
}
106109

@@ -667,11 +670,16 @@ public function testResolveWithIDNAOptions()
667670
{
668671
$resolvedByDefault = $this->rules->resolve('foo.de', Rules::ICANN_DOMAINS);
669672
self::assertSame(
670-
[0, 0],
673+
[IDNA_DEFAULT, IDNA_DEFAULT],
671674
[$resolvedByDefault->getAsciiIDNAOption(), $resolvedByDefault->getUnicodeIDNAOption()]
672675
);
673676
$manager = new Manager(new Cache(), new CurlHttpClient());
674-
$rules = $manager->getRules(Manager::PSL_URL, null, 16, 32);
677+
$rules = $manager->getRules(
678+
Manager::PSL_URL,
679+
null,
680+
IDNA_NONTRANSITIONAL_TO_ASCII,
681+
IDNA_NONTRANSITIONAL_TO_UNICODE
682+
);
675683
$resolved = $rules->resolve('foo.de', Rules::ICANN_DOMAINS);
676684
self::assertSame(
677685
[$rules->getAsciiIDNAOption(), $rules->getUnicodeIDNAOption()],

tests/TopLevelDomainsTest.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
use Pdp\TopLevelDomains;
2525
use PHPUnit\Framework\TestCase;
2626
use TypeError;
27+
use const IDNA_DEFAULT;
28+
use const IDNA_NONTRANSITIONAL_TO_ASCII;
29+
use const IDNA_NONTRANSITIONAL_TO_UNICODE;
2730

2831
/**
2932
* @coversDefaultClass Pdp\TopLevelDomains
@@ -177,10 +180,23 @@ public function testResolveWithUnregisteredTLD()
177180
public function testResolveWithIDNAOptions()
178181
{
179182
$resolved = $this->collection->resolve('foo.de');
180-
self::assertSame([0, 0], [$resolved->getAsciiIDNAOption(), $resolved->getUnicodeIDNAOption()]);
181-
$collection = TopLevelDomains::createFromPath(__DIR__.'/data/root_zones.dat', null, 16, 32);
183+
self::assertSame(
184+
[IDNA_DEFAULT, IDNA_DEFAULT],
185+
[$resolved->getAsciiIDNAOption(), $resolved->getUnicodeIDNAOption(),
186+
]
187+
);
188+
189+
$collection = TopLevelDomains::createFromPath(
190+
__DIR__.'/data/root_zones.dat',
191+
null,
192+
IDNA_NONTRANSITIONAL_TO_ASCII,
193+
IDNA_NONTRANSITIONAL_TO_UNICODE
194+
);
182195
$resolved = $collection->resolve('foo.de');
183-
self::assertSame([16, 32], [$resolved->getAsciiIDNAOption(), $resolved->getUnicodeIDNAOption()]);
196+
self::assertSame(
197+
[IDNA_NONTRANSITIONAL_TO_ASCII, IDNA_NONTRANSITIONAL_TO_UNICODE],
198+
[$resolved->getAsciiIDNAOption(), $resolved->getUnicodeIDNAOption()]
199+
);
184200
}
185201
/**
186202
* @dataProvider validTldProvider

0 commit comments

Comments
 (0)