Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'hotfix/3683' into develop
Forward port #3683
  • Loading branch information
weierophinney committed Feb 8, 2013
2 parents cee8bf6 + 7cd8310 commit 7868119
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
12 changes: 6 additions & 6 deletions library/Zend/InputFilter/Input.php
Expand Up @@ -313,13 +313,13 @@ protected function injectNotEmptyValidator()
}
$chain = $this->getValidatorChain();

// Check if NotEmpty validator is already first in chain
// Check if NotEmpty validator is already in chain
$validators = $chain->getValidators();
if (isset($validators[0]['instance'])
&& $validators[0]['instance'] instanceof NotEmpty
) {
$this->notEmptyValidator = true;
return;
foreach ($validators as $validator) {
if ($validator['instance'] instanceof NotEmpty) {
$this->notEmptyValidator = true;
return;
}
}

$chain->prependByName('NotEmpty', array(), true);
Expand Down
21 changes: 21 additions & 0 deletions tests/ZendTest/InputFilter/InputTest.php
Expand Up @@ -240,4 +240,25 @@ public function testMerge()
$filters = $filterChain->getFilters()->toArray();
$this->assertInstanceOf('Zend\Filter\StringTrim', $filters[0]);
}

public function testDoNotInjectNotEmptyValidatorIfAnywhereInChain()
{
$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->addValidator(new Validator\Digits());
$validatorChain->addValidator($notEmptyMock);
$this->assertFalse($input->isValid());

$validators = $validatorChain->getValidators();
$this->assertEquals(2, count($validators));
$this->assertEquals($notEmptyMock, $validators[1]['instance']);
}
}

0 comments on commit 7868119

Please sign in to comment.