Permalink
Browse files

enabling validation on arrays

  • Loading branch information...
1 parent 0ee6b81 commit e1d190780a8696c807ed0f0c258f8e5cbe9dd537 @Howard3 Howard3 committed Dec 8, 2011
Showing with 22 additions and 1 deletion.
  1. +21 −0 tests/cases/util/ValidatorTest.php
  2. +1 −1 util/Validator.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.
*/
View
@@ -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;

0 comments on commit e1d1907

Please sign in to comment.