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

Commit

Permalink
[hotfix/ZF-11294] Zend_Log
Browse files Browse the repository at this point in the history
- manual correction
  • Loading branch information
thomasweidner committed Aug 8, 2011
1 parent ee74907 commit c77add4
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 130 deletions.
28 changes: 1 addition & 27 deletions src/InputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -761,33 +761,7 @@ protected function _validate()
$validatorRule[self::PRESENCE] = $this->defaults[self::PRESENCE];
}
if (!isset($validatorRule[self::ALLOW_EMPTY])) {
$foundNotEmptyValidator = false;

foreach ($validatorRule as $rule) {
if ($rule === 'NotEmpty') {
$foundNotEmptyValidator = true;
// field may not be empty, we are ready
break 1;
}

// we must check if it is an object before using instanceof
if (!is_object($rule)) {
// it cannot be a NotEmpty validator, skip this one
continue;
}

if($rule instanceof Validator\NotEmpty) {
$foundNotEmptyValidator = true;
// field may not be empty, we are ready
break 1;
}
}

if (!$foundNotEmptyValidator) {
$validatorRule[self::ALLOW_EMPTY] = $this->defaults[self::ALLOW_EMPTY];
} else {
$validatorRule[self::ALLOW_EMPTY] = false;
}
$validatorRule[self::ALLOW_EMPTY] = $this->defaults[self::ALLOW_EMPTY];
}

if (!isset($validatorRule[self::MESSAGES])) {
Expand Down
103 changes: 0 additions & 103 deletions test/InputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1859,109 +1859,6 @@ public function testNoNestedMessageArrays()
$this->assertFalse(is_array($messages['field1']['isEmpty']), 'oh oh, we may have got nested messages');
$this->assertTrue(isset($messages['field1']['isEmpty']), 'oh no, we not even got the normally expected messages');
}

/**
* 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()
{
$data = array(
'field1' => 'foo',
'field2' => ''
);

$validators = array(
'field1' => array(
new Validator\NotEmpty(),
InputFilter::MESSAGES => array(
array(
Validator\NotEmpty::IS_EMPTY => '\'field1\' is required'
)
)
),

'field2' => array(
new Validator\NotEmpty()
)
);

$options = array(InputFilter::ALLOW_EMPTY => true);
$input = new InputFilter( null, $validators, $data, $options );
$this->assertFalse($input->isValid(), 'Ouch, the NotEmpty validators are ignored!');

$validators = array(
'field1' => array(
'Digits',
array('NotEmpty', 'integer'),
InputFilter::MESSAGES => array(
1 =>
array(
Validator\NotEmpty::IS_EMPTY => '\'field1\' is required'
)
),
),

);

$data = array(
'field1' => 0,
'field2' => ''
);
$options = array(InputFilter::ALLOW_EMPTY => true);
$input = new InputFilter( null, $validators, $data, $options );
$this->assertFalse($input->isValid(), 'Ouch, if the NotEmpty validator is not the first rule, the NotEmpty validators are ignored !');

// and now with a string 'NotEmpty' instead of an instance:

$validators = array(
'field1' => array(
'NotEmpty',
InputFilter::MESSAGES => array(
0 =>
array(
Validator\NotEmpty::IS_EMPTY => '\'field1\' is required'
)
),
),

);

$data = array(
'field1' => '',
'field2' => ''
);

$options = array(InputFilter::ALLOW_EMPTY => true);
$input = new InputFilter( null, $validators, $data, $options );
$this->assertFalse($input->isValid(), 'If the NotEmpty validator is a string, the NotEmpty validator is ignored !');

// and now with an array

$validators = array(
'field1' => array(
array('NotEmpty', 'integer'),
InputFilter::MESSAGES => array(
0 =>
array(
Validator\NotEmpty::IS_EMPTY => '\'field1\' is required'
)
),
),

);

$data = array(
'field1' => 0,
'field2' => ''
);

$options = array(InputFilter::ALLOW_EMPTY => true);
$input = new InputFilter( null, $validators, $data, $options );
$this->assertFalse($input->isValid(), 'If the NotEmpty validator is an array, the NotEmpty validator is ignored !');
}
}

} // end namespace declaration
Expand Down

0 comments on commit c77add4

Please sign in to comment.