Permalink
Browse files

fix formatting

  • Loading branch information...
1 parent 523bc4d commit 674dc96b6e654550872ed5d18dc022f365429557 @darxmac darxmac committed Feb 9, 2014
Showing with 22 additions and 1 deletion.
  1. +2 −1 src/Validation/Validator.php
  2. +20 −0 tests/TestCase/Validation/ValidatorTest.php
@@ -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) {
@@ -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.