99use Pdp \Domain ;
1010use Pdp \Exception ;
1111use Pdp \Manager ;
12+ use Pdp \PublicSuffix ;
1213use Pdp \Rules ;
1314use PHPUnit \Framework \TestCase ;
15+ use TypeError ;
1416
1517/**
1618 * @coversDefaultClass Pdp\Rules
@@ -72,13 +74,25 @@ public function testDomainInternalPhpMethod()
7274 * @covers \Pdp\PublicSuffix::setSection
7375 * @covers \Pdp\PublicSuffix::isKnown
7476 * @covers \Pdp\Domain::isKnown
77+ * @covers \Pdp\IDNAConverterTrait::setDomain
7578 */
7679 public function testNullWillReturnNullDomain ()
7780 {
7881 $ domain = $ this ->rules ->resolve ('COM ' );
7982 $ this ->assertFalse ($ domain ->isKnown ());
8083 }
8184
85+
86+ /**
87+ * @covers ::resolve
88+ * @covers \Pdp\IDNAConverterTrait::setDomain
89+ */
90+ public function testThrowsTypeErrorOnWrongInput ()
91+ {
92+ $ this ->expectException (TypeError::class);
93+ $ this ->rules ->resolve (date_create ());
94+ }
95+
8296 /**
8397 * @covers ::resolve
8498 * @covers ::validateSection
@@ -98,6 +112,7 @@ public function testResolveThrowsExceptionOnWrongDomainType()
98112 * @covers \Pdp\PublicSuffix::setSection
99113 * @covers \Pdp\PublicSuffix::isKnown
100114 * @covers \Pdp\Domain::isKnown
115+ * @covers \Pdp\IDNAConverterTrait::setDomain
101116 */
102117 public function testIsSuffixValidFalse ()
103118 {
@@ -119,6 +134,7 @@ public function testIsSuffixValidFalse()
119134 * @covers \Pdp\Domain::isKnown
120135 * @covers \Pdp\Domain::isICANN
121136 * @covers \Pdp\Domain::isPrivate
137+ * @covers \Pdp\IDNAConverterTrait::setDomain
122138 */
123139 public function testIsSuffixValidTrue ()
124140 {
@@ -142,6 +158,7 @@ public function testIsSuffixValidTrue()
142158 * @covers \Pdp\Domain::isKnown
143159 * @covers \Pdp\Domain::isICANN
144160 * @covers \Pdp\Domain::isPrivate
161+ * @covers \Pdp\IDNAConverterTrait::setDomain
145162 */
146163 public function testIsSuffixValidFalseWithPunycoded ()
147164 {
@@ -165,6 +182,7 @@ public function testIsSuffixValidFalseWithPunycoded()
165182 * @covers \Pdp\Domain::isKnown
166183 * @covers \Pdp\Domain::isICANN
167184 * @covers \Pdp\Domain::isPrivate
185+ * @covers \Pdp\IDNAConverterTrait::setDomain
168186 */
169187 public function testSubDomainIsNull ()
170188 {
@@ -177,7 +195,7 @@ public function testSubDomainIsNull()
177195 /**
178196 * @covers ::resolve
179197 * @covers ::validateSection
180- * @covers \Pdp\Domain ::setDomain
198+ * @covers \Pdp\IDNAConverterTrait ::setDomain
181199 */
182200 public function testWithInvalidDomainName ()
183201 {
@@ -191,6 +209,7 @@ public function testWithInvalidDomainName()
191209 * @covers ::findPublicSuffix
192210 * @covers ::findPublicSuffixFromSection
193211 * @covers \Pdp\PublicSuffix::setSection
212+ * @covers \Pdp\IDNAConverterTrait::setDomain
194213 */
195214 public function testWithPrivateDomain ()
196215 {
@@ -207,6 +226,7 @@ public function testWithPrivateDomain()
207226 * @covers ::findPublicSuffix
208227 * @covers ::findPublicSuffixFromSection
209228 * @covers \Pdp\PublicSuffix::setSection
229+ * @covers \Pdp\IDNAConverterTrait::setDomain
210230 */
211231 public function testWithPrivateDomainInvalid ()
212232 {
@@ -224,6 +244,7 @@ public function testWithPrivateDomainInvalid()
224244 * @covers ::findPublicSuffix
225245 * @covers ::findPublicSuffixFromSection
226246 * @covers \Pdp\PublicSuffix::setSection
247+ * @covers \Pdp\IDNAConverterTrait::setDomain
227248 */
228249 public function testWithPrivateDomainValid ()
229250 {
@@ -241,6 +262,7 @@ public function testWithPrivateDomainValid()
241262 * @covers ::findPublicSuffix
242263 * @covers ::findPublicSuffixFromSection
243264 * @covers \Pdp\PublicSuffix::setSection
265+ * @covers \Pdp\IDNAConverterTrait::setDomain
244266 */
245267 public function testWithICANNDomainInvalid ()
246268 {
@@ -252,6 +274,37 @@ public function testWithICANNDomainInvalid()
252274 $ this ->assertSame ('ac.be ' , $ domain ->getPublicSuffix ());
253275 }
254276
277+ /**
278+ * @covers ::resolve
279+ * @covers ::validateSection
280+ * @covers ::findPublicSuffix
281+ * @covers ::findPublicSuffixFromSection
282+ * @covers \Pdp\PublicSuffix::setSection
283+ * @covers \Pdp\IDNAConverterTrait::setDomain
284+ */
285+ public function testWithDomainObject ()
286+ {
287+ $ domain = new Domain ('private.ulb.ac.be ' , new PublicSuffix ('ac.be ' , Rules::ICANN_DOMAINS ));
288+ $ newDomain = $ this ->rules ->resolve ($ domain );
289+ $ this ->assertSame ('private.ulb.ac.be ' , $ domain ->getDomain ());
290+ $ this ->assertTrue ($ domain ->isKnown ());
291+ $ this ->assertTrue ($ domain ->isICANN ());
292+ $ this ->assertFalse ($ domain ->isPrivate ());
293+ $ this ->assertSame ('ac.be ' , $ domain ->getPublicSuffix ());
294+ $ this ->assertSame ($ domain , $ newDomain );
295+ }
296+
297+ /**
298+ * @covers ::getPublicSuffix
299+ * @covers \Pdp\IDNAConverterTrait::setDomain
300+ */
301+ public function testWithDomainInterfaceObject ()
302+ {
303+ $ publicSuffix = new PublicSuffix ('ac.be ' , Rules::ICANN_DOMAINS );
304+ $ psl = $ this ->rules ->getPublicSuffix ($ publicSuffix );
305+ $ this ->assertEquals ($ publicSuffix , $ psl );
306+ }
307+
255308 /**
256309 * @dataProvider parseDataProvider
257310 * @param mixed $publicSuffix
@@ -274,6 +327,7 @@ public function testGetRegistrableDomain($publicSuffix, $registrableDomain, $dom
274327 * @param mixed $domain
275328 * @param mixed $expectedDomain
276329 * @covers ::resolve
330+ * @covers \Pdp\IDNAConverterTrait::setDomain
277331 * @covers \Pdp\Domain::setPublicSuffix
278332 * @covers \Pdp\Domain::getPublicSuffix
279333 */
@@ -289,8 +343,8 @@ public function testGetPublicSuffix($publicSuffix, $registrableDomain, $domain,
289343 * @param mixed $domain
290344 * @param mixed $expectedDomain
291345 * @covers ::resolve
346+ * @covers \Pdp\IDNAConverterTrait::setDomain
292347 * @covers \Pdp\Domain::withPublicSuffix
293- * @covers \Pdp\Domain::setDomain
294348 * @covers \Pdp\Domain::getContent
295349 */
296350 public function testGetDomain ($ publicSuffix , $ registrableDomain , $ domain , $ expectedDomain )
@@ -331,8 +385,8 @@ public function parseDataProvider()
331385 *
332386 * @covers ::getPublicSuffix
333387 * @covers ::validateSection
334- * @covers \Pdp\Domain::setDomain
335388 * @covers ::isMatchable
389+ * @covers \Pdp\IDNAConverterTrait::setDomain
336390 */
337391 public function testGetPublicSuffixThrowsException ($ domain , $ section )
338392 {
@@ -360,7 +414,7 @@ public function invalidParseProvider()
360414 * @covers ::getPublicSuffix
361415 * @covers ::validateSection
362416 * @covers ::isMatchable
363- * @covers \Pdp\PublicSuffix ::setDomain
417+ * @covers \Pdp\IDNAConverterTrait ::setDomain
364418 * @dataProvider validPublicSectionProvider
365419 *
366420 * @param string|null $domain
@@ -419,6 +473,7 @@ public function checkPublicSuffix($input, $expected)
419473 * @covers ::findPublicSuffixFromSection
420474 * @covers \Pdp\Domain::withPublicSuffix
421475 * @covers \Pdp\Domain::getRegistrableDomain
476+ * @covers \Pdp\IDNAConverterTrait::setDomain
422477 */
423478 public function testPublicSuffixSpec ()
424479 {
0 commit comments