Skip to content

Commit 9e91376

Browse files
committed
Adding Rules Effective TLD methods
1 parent 2426336 commit 9e91376

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/Rules.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ final class Rules implements PublicSuffixListSection
6363
/**
6464
* New instance.
6565
*
66+
* @internal
67+
*
6668
* @param array $rules
6769
* @param int $asciiIDNAOption
6870
* @param int $unicodeIDNAOption

tests/RulesTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,4 +708,41 @@ public function testResolveWithIDNAOptions(): void
708708
[$resolved->getAsciiIDNAOption(), $resolved->getUnicodeIDNAOption()]
709709
);
710710
}
711+
712+
/**
713+
* @covers ::getCookieEffectiveTLD
714+
* @covers ::getICANNEffectiveTLD
715+
* @covers ::getPrivateEffectiveTLD
716+
* @dataProvider effectiveTLDProvider
717+
*/
718+
public function testEffectiveTLDResolution(string $host, string $cookieETLD, string $icannETLD, string $privateETLD): void
719+
{
720+
self::assertSame($cookieETLD, (string) $this->rules->getCookieEffectiveTLD($host));
721+
self::assertSame($icannETLD, (string) $this->rules->getICANNEffectiveTLD($host));
722+
self::assertSame($privateETLD, (string) $this->rules->getPrivateEffectiveTLD($host));
723+
}
724+
725+
public function effectiveTLDProvider(): iterable
726+
{
727+
return [
728+
'simple TLD' => [
729+
'host' => 'www.example.com',
730+
'cookieETLD' => 'com',
731+
'icannETLD' => 'com',
732+
'privateETLD' => 'com',
733+
],
734+
'complex ICANN TLD' => [
735+
'host' => 'www.ulb.ac.be',
736+
'cookieETLD' => 'ac.be',
737+
'icannETLD' => 'ac.be',
738+
'privateETLD' => 'be',
739+
],
740+
'private domain effective TLD' => [
741+
'host' => 'myblog.blogspot.com',
742+
'cookieETLD' => 'blogspot.com',
743+
'icannETLD' => 'com',
744+
'privateETLD' => 'blogspot.com',
745+
],
746+
];
747+
}
711748
}

0 commit comments

Comments
 (0)