@@ -486,43 +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
507
516
}
508
517
509
- public function testAdditionalPunycodedTLDs ()
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 )
510
524
{
511
- $ validator = new Hostname (Hostname::ALLOW_ALL );
512
- // Check UTF-8 TLD matching
513
- $ valuesExpected = [
514
- [true , ['test123.xn--80asehdb ' , 'xn--e1aybc.xn--p1ai ' , 'xn--h1aggjjdd5b4a.xn--l1acc ' ]],
515
- [false , ['xn--3-owe4au9mpa.xn--xkc2al3hye2a ' , 'xn--mgbgt.xn--l1acc ' ]]
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 ' ],
516
536
];
517
- foreach ($ valuesExpected as $ element ) {
518
- foreach ($ element [1 ] as $ input ) {
519
- $ this ->assertEquals (
520
- $ element [0 ],
521
- $ validator ->isValid ($ input ),
522
- implode ("\n" , $ validator ->getMessages ()) .' - ' . $ input
523
- );
524
- }
525
- }
537
+ // @codingStandardsIgnoreEnd
526
538
}
527
539
528
540
public function testIDNIT ()
0 commit comments