public function getValidators(ZfInput $input) { $validators = $input->getValidatorChain()->getValidators(); if ($input->isRequired()) { $validators[] = 'Zend\\Validator\\NotEmpty'; } return array_map(array($this, 'buildValidator'), $validators); }
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']); }
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']); }
public function testNotEmptyValidatorAddedWhenIsValidIsCalled() { $input = new Input('foo'); $this->assertTrue($input->isRequired()); $input->setValue(''); $this->assertFalse($input->isValid()); $messages = $input->getMessages(); $this->assertArrayHasKey('isEmpty', $messages); }