Ejemplo n.º 1
0
 /**
  * Ensure the TLD check works as expected
  *
  */
 public function testTLD()
 {
     $validator = new Hostname();
     // Check TLD matching
     $valuesExpected = array(array(true, array('domain.co.uk', 'domain.uk.com', 'domain.tl', 'domain.zw')), array(false, array('domain.xx', 'domain.zz', 'domain.madeup')));
     foreach ($valuesExpected as $element) {
         foreach ($element[1] as $input) {
             $this->assertEquals($element[0], $validator->isValid($input), implode("\n", $validator->getMessages()) . $input);
         }
     }
     // Check no TLD matching
     $validator->useTldCheck(false);
     $valuesExpected = array(array(true, array('domain.xx', 'domain.zz', 'domain.madeup')));
     foreach ($valuesExpected as $element) {
         foreach ($element[1] as $input) {
             $this->assertEquals($element[0], $validator->isValid($input), implode("\n", $validator->getMessages()) . $input);
         }
     }
     // Check setting no TLD matching via constructor
     unset($validator);
     $validator = new Hostname(Hostname::ALLOW_DNS, true, false);
     $valuesExpected = array(array(true, array('domain.xx', 'domain.zz', 'domain.madeup')));
     foreach ($valuesExpected as $element) {
         foreach ($element[1] as $input) {
             $this->assertEquals($element[0], $validator->isValid($input), implode("\n", $validator->getMessages()) . $input);
         }
     }
 }