Browse Source

fix formatting

Thomas von Hassel 12 years ago
parent
commit
674dc96b6e
2 changed files with 22 additions and 1 deletions
  1. 2 1
      src/Validation/Validator.php
  2. 20 0
      tests/TestCase/Validation/ValidatorTest.php

+ 2 - 1
src/Validation/Validator.php

@@ -237,11 +237,12 @@ class Validator implements \ArrayAccess, \IteratorAggregate, \Countable {
  * @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) {

+ 20 - 0
tests/TestCase/Validation/ValidatorTest.php

@@ -485,4 +485,24 @@ class ValidatorTest extends \Cake\TestSuite\TestCase {
 		$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);
+	}
 }