Fix Validation::multiple() regarding 0 value.

This commit is contained in:
Mark Scherer 2015-06-15 16:35:27 +02:00
parent 0b20f6d334
commit 86c358f3f9
2 changed files with 10 additions and 8 deletions

View file

@ -2085,8 +2085,9 @@ class ValidationTest extends CakeTestCase {
$this->assertFalse(Validation::multiple(''));
$this->assertFalse(Validation::multiple(null));
$this->assertFalse(Validation::multiple(array()));
$this->assertFalse(Validation::multiple(array(0)));
$this->assertFalse(Validation::multiple(array('0')));
$this->assertTrue(Validation::multiple(array(0)));
$this->assertTrue(Validation::multiple(array('0')));
$this->assertFalse(Validation::multiple(array('')));
$this->assertTrue(Validation::multiple(array(0, 3, 4, 5), array('in' => range(0, 10))));
$this->assertFalse(Validation::multiple(array(0, 15, 20, 5), array('in' => range(0, 10))));
@ -2094,8 +2095,9 @@ class ValidationTest extends CakeTestCase {
$this->assertFalse(Validation::multiple(array('boo', 'foo', 'bar'), array('in' => array('foo', 'bar', 'baz'))));
$this->assertFalse(Validation::multiple(array('foo', '1bar'), array('in' => range(0, 10))));
$this->assertTrue(Validation::multiple(array(0, 5, 10, 11), array('max' => 3)));
$this->assertFalse(Validation::multiple(array(0, 5, 10, 11, 55), array('max' => 3)));
$this->assertFalse(Validation::multiple(array(1, 5, 10, 11), array('max' => 3)));
$this->assertTrue(Validation::multiple(array(0, 5, 10, 11), array('max' => 4)));
$this->assertFalse(Validation::multiple(array(0, 5, 10, 11, 55), array('max' => 4)));
$this->assertTrue(Validation::multiple(array('foo', 'bar', 'baz'), array('max' => 3)));
$this->assertFalse(Validation::multiple(array('foo', 'bar', 'baz', 'squirrel'), array('max' => 3)));
@ -2110,8 +2112,8 @@ class ValidationTest extends CakeTestCase {
$this->assertFalse(Validation::multiple(array(0, 5, 9, 8, 6, 2, 1), array('in' => range(0, 10), 'max' => 5)));
$this->assertFalse(Validation::multiple(array(0, 5, 9, 8, 11), array('in' => range(0, 10), 'max' => 5)));
$this->assertFalse(Validation::multiple(array(0, 5, 9), array('in' => range(0, 10), 'max' => 5, 'min' => 3)));
$this->assertFalse(Validation::multiple(array(0, 5, 9, 8, 6, 2, 1), array('in' => range(0, 10), 'max' => 5, 'min' => 2)));
$this->assertFalse(Validation::multiple(array(-1, 5, 9), array('in' => range(0, 10), 'max' => 5, 'min' => 3)));
$this->assertFalse(Validation::multiple(array(-1, 5, 9, 8, 6, 2, 1), array('in' => range(0, 10), 'max' => 5, 'min' => 2)));
$this->assertFalse(Validation::multiple(array(0, 5, 9, 8, 11), array('in' => range(0, 10), 'max' => 5, 'min' => 2)));
$this->assertFalse(Validation::multiple(array('2x', '3x'), array('in' => array(1, 2, 3, 4, 5))));

View file

@ -594,7 +594,7 @@ class Validation {
$defaults = array('in' => null, 'max' => null, 'min' => null);
$options += $defaults;
$check = array_filter((array)$check);
$check = array_filter((array)$check, 'strlen');
if (empty($check)) {
return false;
}