예제 #1
0
 public function getValidators(ZfInput $input)
 {
     $validators = $input->getValidatorChain()->getValidators();
     if ($input->isRequired()) {
         $validators[] = 'Zend\\Validator\\NotEmpty';
     }
     return array_map(array($this, 'buildValidator'), $validators);
 }
예제 #2
0
 public function testDoNotInjectNotEmptyValidatorIfAnywhereInChain()
 {
     $this->assertTrue($this->input->isRequired());
     $this->input->setValue('');
     $notEmptyMock = $this->getMock('Zend\\Validator\\NotEmpty', array('isValid'));
     $notEmptyMock->expects($this->exactly(1))->method('isValid')->will($this->returnValue(false));
     $validatorChain = $this->input->getValidatorChain();
     $validatorChain->attach(new Validator\Digits());
     $validatorChain->attach($notEmptyMock);
     $this->assertFalse($this->input->isValid());
     $validators = $validatorChain->getValidators();
     $this->assertEquals(2, count($validators));
     $this->assertEquals($notEmptyMock, $validators[1]['instance']);
 }
예제 #3
0
파일: InputTest.php 프로젝트: haoyanfei/zf2
 public function testRequiredNotEmptyValidatorNotAddedWhenOneExists()
 {
     $input = new Input('foo');
     $this->assertTrue($input->isRequired());
     $input->setValue('');
     $notEmptyMock = $this->getMock('Zend\\Validator\\NotEmpty', array('isValid'));
     $notEmptyMock->expects($this->exactly(1))->method('isValid')->will($this->returnValue(false));
     $validatorChain = $input->getValidatorChain();
     $validatorChain->prependValidator($notEmptyMock);
     $this->assertFalse($input->isValid());
     $validators = $validatorChain->getValidators();
     $this->assertEquals(1, count($validators));
     $this->assertEquals($notEmptyMock, $validators[0]['instance']);
 }
예제 #4
0
 public function testNotEmptyValidatorAddedWhenIsValidIsCalled()
 {
     $input = new Input('foo');
     $this->assertTrue($input->isRequired());
     $input->setValue('');
     $this->assertFalse($input->isValid());
     $messages = $input->getMessages();
     $this->assertArrayHasKey('isEmpty', $messages);
 }