diff --git a/tests/cases/util/ValidatorTest.php b/tests/cases/util/ValidatorTest.php index bba00f0626..4345a5e039 100644 --- a/tests/cases/util/ValidatorTest.php +++ b/tests/cases/util/ValidatorTest.php @@ -1146,6 +1146,27 @@ public function testEvents() { $this->assertEqual($expected, $result); } + public function testValidationWithArrays() { + $rules = array( + 'foo' => array('arrayTest', 'message' => 'fail') + ); + Validator::add('arrayTest', function($value, $format, $options) { + return ($value == array('bar' => 1)); + }); + + $data = array('foo' => array('bar' => 1)); + $result = Validator::check($data, $rules); + $this->assertTrue(empty($result)); + + $data = array('foo' => null); + $result = Validator::check($data, $rules); + $this->assertFalse(empty($result)); + + $data = array('foo' => array('bar' => 'baz')); + $result = Validator::check($data, $rules); + $this->assertFalse(empty($result)); + } + /** * Tests validating nested fields using dot-separated paths. */ diff --git a/util/Validator.php b/util/Validator.php index 088967c877..9fc1de1c5e 100644 --- a/util/Validator.php +++ b/util/Validator.php @@ -449,7 +449,7 @@ public static function check(array $values, array $rules, array $options = array $errors = array(); $events = (array) (isset($options['events']) ? $options['events'] : null); - $values = Set::flatten($values); + $values = array_merge($values, Set::flatten($values)); foreach ($rules as $field => $rules) { $rules = is_string($rules) ? array('message' => $rules) : $rules;