Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
darxmac committed Feb 9, 2014
1 parent 523bc4d commit 674dc96
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Validation/Validator.php
Expand Up @@ -237,11 +237,12 @@ public function count() {
* @return Validator this instance
*/
public function add($field, $name, $rule = []) {
$rules = $rule;
$field = $this->field($field);

if (!is_array($name)) {
$rules = [$name => $rule];
} else {
$rules = $name;
}

foreach ($rules as $name => $rule) {
Expand Down
20 changes: 20 additions & 0 deletions tests/TestCase/Validation/ValidatorTest.php
Expand Up @@ -485,4 +485,24 @@ public function testCount() {
$this->assertCount(2, $validator);
}


/**
* Tests adding rules via alternative syntax
*
* @return void
*/
public function testMulitple() {
$validator = new Validator;
$validator->add('title', [
'notEmpty' => [
'rule' => 'notEmpty'],
'length' => [
'rule' => [
'minLength',
10],
'message' => 'Titles need to be at least 10 characters long',]]);
$set = $validator->field('title');
$this->assertInstanceOf('\Cake\Validation\ValidationSet', $set);
$this->assertCount(2, $set);
}
}

0 comments on commit 674dc96

Please sign in to comment.