Index: InputTest.php =================================================================== --- InputTest.php (revision 23858) +++ InputTest.php (working copy) @@ -41,6 +41,64 @@ */ class Zend_Filter_InputTest extends PHPUnit_Framework_TestCase { + /** + * + * If setAllowEmpty(true) is called, all fields are optional, but fields with + * a NotEmpty validator attached to them, should contain a non empty value. + * + * @group ZF-9289 + */ + function testAllowEmptyTrueRespectsNotEmtpyValidators() + { + require_once 'Zend/Validate/NotEmpty.php'; + require_once 'Zend/Validate/Digits.php'; + + $data = array( + 'field1' => 'foo', + 'field2' => '' + ); + + $validators = array( + 'field1' => array( + new Zend_Validate_NotEmpty(), + Zend_Filter_Input::MESSAGES => array( + array( + Zend_Validate_NotEmpty::IS_EMPTY => '\'field1\' is required' + ) + ) + ), + + 'field2' => array( + new Zend_Validate_NotEmpty() + ) + ); + + $options = array(Zend_Filter_Input::ALLOW_EMPTY => true); + $input = new Zend_Filter_Input( null, $validators, $data, $options ); + $this->assertFalse($input->isValid(), 'Ouch, the NotEmpty validators are ignored!'); + + $validators = array( + 'field1' => array( + 'Digits', + array('NotEmpty', 'integer'), + Zend_Filter_Input::MESSAGES => array( + 1 => + array( + Zend_Validate_NotEmpty::IS_EMPTY => '\'field1\' is required' + ) + ), + ), + + ); + + $data = array( + 'field1' => 0, + 'field2' => '' + ); + $options = array(Zend_Filter_Input::ALLOW_EMPTY => true); + $input = new Zend_Filter_Input( null, $validators, $data, $options ); + $this->assertFalse($input->isValid(), 'Ouch, if the NotEmpty validator is not the first rule, the NotEmpty validators are ignored !'); + } /** * @group ZF-8446