Browse Source

Fix callable arrays being mishandled by ValidationRule.

We should not be manipulating callable arrays like normal validation
rule arrays.

Refs #4330
mark_story 11 years ago
parent
commit
a3d7d2aaaa

+ 1 - 1
src/Validation/ValidationRule.php

@@ -180,7 +180,7 @@ class ValidationRule {
 			if (!isset($value) || empty($value)) {
 				continue;
 			}
-			if ($key === 'rule' && is_array($value)) {
+			if ($key === 'rule' && is_array($value) && !is_callable($value)) {
 				$this->_pass = array_slice($value, 1);
 				$value = array_shift($value);
 			}

+ 16 - 0
tests/TestCase/Validation/ValidationRuleTest.php

@@ -74,6 +74,22 @@ class ValidationRuleTest extends TestCase {
 	}
 
 /**
+ * Test using a custom validation method with no provider declared.
+ *
+ * @return void
+ */
+	public function testCustomMethodNoProvider() {
+		$data = 'some data';
+		$context = ['field' => 'custom', 'newRecord' => true];
+		$providers = ['default' => ''];
+
+		$rule = new ValidationRule([
+			'rule' => [$this, 'myTestRule']
+		]);
+		$this->assertFalse($rule->process($data, $providers, $context));
+	}
+
+/**
  * Make sure errors are triggered when validation is missing.
  *
  * @expectedException \InvalidArgumentException