Skip to content

Commit

Permalink
enabling validation on arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Howard3 committed Dec 8, 2011
1 parent 0ee6b81 commit e1d1907
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions tests/cases/util/ValidatorTest.php
Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion util/Validator.php
Expand Up @@ -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;
Expand Down

0 comments on commit e1d1907

Please sign in to comment.