@@ -486,24 +486,55 @@ public function testIDNIL()
486
486
}
487
487
}
488
488
489
- public function testAdditionalUTF8TLDs ()
489
+ /**
490
+ * Ensures that the validator follows expected behavior for UTF-8 and Punycoded (ACE) TLDs
491
+ *
492
+ * @dataProvider validTLDHostnames
493
+ */
494
+ public function testValidTLDHostnames ($ value )
490
495
{
491
- $ validator = new Hostname (Hostname::ALLOW_ALL );
496
+ $ this ->assertTrue (
497
+ $ this ->validator ->isValid ($ value ),
498
+ sprintf (
499
+ '%s failed validation: %s ' ,
500
+ $ value ,
501
+ implode ("\n" , $ this ->validator ->getMessages ())
502
+ )
503
+ );
504
+ }
492
505
493
- // Check UTF-8 TLD matching
494
- $ valuesExpected = [
495
- [true , ['test123.онлайн ' , 'тест.рф ' , 'туршилтын.мон ' ]],
496
- [false , ['சோதனை3.இலங்கை ' , 'رات.мон ' ]]
506
+ public function validTLDHostnames ()
507
+ {
508
+ // @codingStandardsIgnoreStart
509
+ return [
510
+ 'ASCII label + UTF-8 TLD ' => ['test123.онлайн ' ],
511
+ 'ASCII label + Punycoded TLD ' => ['test123.xn--80asehdb ' ],
512
+ 'UTF-8 label + UTF-8 TLD (cyrillic) ' => ['тест.рф ' ],
513
+ 'Punycoded label + Punycoded TLD (cyrillic) ' => ['xn--e1aybc.xn--p1ai ' ],
497
514
];
498
- foreach ($ valuesExpected as $ element ) {
499
- foreach ($ element [1 ] as $ input ) {
500
- $ this ->assertEquals (
501
- $ element [0 ],
502
- $ validator ->isValid ($ input ),
503
- implode ("\n" , $ validator ->getMessages ()) .' - ' . $ input
504
- );
505
- }
506
- }
515
+ // @codingStandardsIgnoreEnd
516
+ }
517
+
518
+ /**
519
+ * Ensures that the validator follows expected behavior for invalid UTF-8 and Punycoded (ACE) TLDs
520
+ *
521
+ * @dataProvider invalidTLDHostnames
522
+ */
523
+ public function testInalidTLDHostnames ($ value )
524
+ {
525
+ $ this ->assertFalse ($ this ->validator ->isValid ($ value ));
526
+ }
527
+
528
+ public function invalidTLDHostnames ()
529
+ {
530
+ // @codingStandardsIgnoreStart
531
+ return [
532
+ 'Invalid mix of UTF-8 and ASCII in label ' => ['சோதனை3.இலங்கை ' ],
533
+ 'Invalid mix of UTF-8 and ASCII in label (Punycoded) ' => ['xn--3-owe4au9mpa.xn--xkc2al3hye2a ' ],
534
+ 'Invalid use of non-cyrillic characters with cyrillic TLD ' => ['رات.мон ' ],
535
+ 'Invalid use of non-cyrillic characters with cyrillic TLD (Punycoded) ' => ['xn--mgbgt.xn--l1acc ' ],
536
+ ];
537
+ // @codingStandardsIgnoreEnd
507
538
}
508
539
509
540
public function testIDNIT ()
0 commit comments