Skip to content
Permalink
Browse files

Fix issue when passing ValidationRule instance to Validator::add().

Refs #11781.
  • Loading branch information...
ADmad committed Mar 6, 2018
1 parent de1ee60 commit 1dac37a82b020e2cd933de930d00e0664f0eae7c
Showing with 10 additions and 1 deletion.
  1. +4 −1 src/Validation/Validator.php
  2. +6 −0 tests/TestCase/Validation/ValidatorTest.php
@@ -397,7 +397,10 @@ public function add($field, $name, $rule = [])
}
foreach ($rules as $name => $rule) {
$field->add($name, $rule + ['rule' => $name]);
if (is_array($rule)) {
$rule += ['rule' => $name];
}
$field->add($name, $rule);
}
return $this;
@@ -16,6 +16,7 @@
use Cake\TestSuite\TestCase;
use Cake\Validation\Validation;
use Cake\Validation\ValidationRule;
use Cake\Validation\ValidationSet;
use Cake\Validation\Validator;
@@ -48,6 +49,11 @@ public function testAddingRulesToField()
$validator->add('email', 'notBlank');
$result = $validator->field('email')->rule('notBlank')->get('rule');
$this->assertEquals('notBlank', $result);
$rule = new ValidationRule();
$validator->add('field', 'myrule', $rule);
$result = $validator->field('field')->rule('myrule');
$this->assertSame($rule, $result);
}
/**

0 comments on commit 1dac37a

Please sign in to comment.
You can’t perform that action at this time.