Skip to content
Permalink
Browse files

Fix validation regarding multiple() and valid 0 value.

  • Loading branch information...
dereuromark committed Jun 15, 2015
1 parent 464dc9c commit 30af8592886ed39cf33f61ab4d9b8b31f1a9187d
Showing with 10 additions and 6 deletions.
  1. +3 −1 src/Validation/Validation.php
  2. +7 −5 tests/TestCase/Validation/ValidationTest.php
@@ -654,7 +654,9 @@ public static function multiple($check, array $options = [], $caseInsensitive =
$defaults = ['in' => null, 'max' => null, 'min' => null];
$options += $defaults;
$check = array_filter((array)$check);
$check = array_filter((array)$check, function ($value) {
return ($value || is_numeric($value));
});
if (empty($check)) {
return false;
}
@@ -2141,17 +2141,18 @@ public function testMultiple()
$this->assertFalse(Validation::multiple(''));
$this->assertFalse(Validation::multiple(null));
$this->assertFalse(Validation::multiple([]));
$this->assertFalse(Validation::multiple([0]));
$this->assertFalse(Validation::multiple(['0']));
$this->assertTrue(Validation::multiple([0]));
$this->assertTrue(Validation::multiple(['0']));
$this->assertTrue(Validation::multiple([0, 3, 4, 5], ['in' => range(0, 10)]));
$this->assertFalse(Validation::multiple([0, 15, 20, 5], ['in' => range(0, 10)]));
$this->assertFalse(Validation::multiple([0, 5, 10, 11], ['in' => range(0, 10)]));
$this->assertFalse(Validation::multiple(['boo', 'foo', 'bar'], ['in' => ['foo', 'bar', 'baz']]));
$this->assertFalse(Validation::multiple(['foo', '1bar'], ['in' => range(0, 10)]));
$this->assertTrue(Validation::multiple([0, 5, 10, 11], ['max' => 3]));
$this->assertFalse(Validation::multiple([0, 5, 10, 11, 55], ['max' => 3]));
$this->assertFalse(Validation::multiple([1, 5, 10, 11], ['max' => 3]));
$this->assertTrue(Validation::multiple([0, 5, 10, 11], ['max' => 4]));
$this->assertFalse(Validation::multiple([0, 5, 10, 11, 55], ['max' => 4]));
$this->assertTrue(Validation::multiple(['foo', 'bar', 'baz'], ['max' => 3]));
$this->assertFalse(Validation::multiple(['foo', 'bar', 'baz', 'squirrel'], ['max' => 3]));
@@ -2166,7 +2167,8 @@ public function testMultiple()
$this->assertFalse(Validation::multiple([0, 5, 9, 8, 6, 2, 1], ['in' => range(0, 10), 'max' => 5]));
$this->assertFalse(Validation::multiple([0, 5, 9, 8, 11], ['in' => range(0, 10), 'max' => 5]));
$this->assertFalse(Validation::multiple([0, 5, 9], ['in' => range(0, 10), 'max' => 5, 'min' => 3]));
$this->assertTrue(Validation::multiple([0, 5, 9], ['in' => range(0, 10), 'max' => 5, 'min' => 3]));
$this->assertFalse(Validation::multiple(['', '5', '9'], ['max' => 5, 'min' => 3]));
$this->assertFalse(Validation::multiple([0, 5, 9, 8, 6, 2, 1], ['in' => range(0, 10), 'max' => 5, 'min' => 2]));
$this->assertFalse(Validation::multiple([0, 5, 9, 8, 11], ['in' => range(0, 10), 'max' => 5, 'min' => 2]));

0 comments on commit 30af859

Please sign in to comment.
You can’t perform that action at this time.