示例#1
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function testValidators()
 {
     $element = new Element('test');
     $element->addValidator('\\Zend\\Validator\\NotEmpty');
     $validator = $element->getValidator(Validator::getValidatorInstance('Zend\\Validator\\NotEmpty'));
     $this->assertInstanceOf('\\Zend\\Validator\\NotEmpty', $validator);
     $this->assertTrue($element->hasValidator($validator));
     $this->assertEquals(array(Validator::getValidatorInstance('Zend\\Validator\\NotEmpty')), $element->getValidators());
     $this->assertEquals(array(Validator::getValidatorInstance('Zend\\Validator\\NotEmpty')), $element->getValidator());
     $this->assertNull($element->getValidator('unknown'));
     $validator = Validator::getValidatorInstance('Zend\\Validator\\StringLength', array('max' => 128));
     $this->assertInstanceOf('\\Zend\\Validator\\StringLength', $validator);
     $element->addValidator($validator);
     $this->assertTrue($element->hasValidator($validator));
     $element = new Element('test');
     $validatorInstance = Validator::getValidatorInstance('Zend\\Validator\\StringLength', array('max' => 128));
     $validator = array('Zend\\Validator\\StringLength', array('max' => 128));
     $element->addValidator($validator);
     $this->assertTrue($element->hasValidator($validatorInstance));
     $element = new Element('test');
     $validatorInstance = Validator::getValidatorInstance('Zend\\Validator\\StringLength', array('max' => 128));
     $validator = array('type' => 'Zend\\Validator\\StringLength', 'params' => array('max' => 128));
     $element->addValidator($validator);
     $this->assertTrue($element->hasValidator($validatorInstance));
     $element = new Element('test');
     $validator = array('type' => 'Zend\\Validator\\StringLength', 'params' => array('max' => 128));
     $element->addValidator($validator);
     $this->assertFalse($element->hasValidator('Unknown'));
     $element->addValidator($validator);
     $element->addValidator(new \stdClass());
 }