mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Fix rules set being updated with array instead of CakeValidationRule objects. Closes #3367
This commit is contained in:
parent
e0586da808
commit
ac087ec938
2 changed files with 17 additions and 4 deletions
|
@ -192,7 +192,7 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable {
|
||||||
* @return CakeValidationSet this instance
|
* @return CakeValidationSet this instance
|
||||||
*/
|
*/
|
||||||
public function setRule($name, $rule) {
|
public function setRule($name, $rule) {
|
||||||
if (!$rule instanceof CakeValidationRule) {
|
if (!($rule instanceof CakeValidationRule)) {
|
||||||
$rule = new CakeValidationRule($rule);
|
$rule = new CakeValidationRule($rule);
|
||||||
}
|
}
|
||||||
$this->_rules[$name] = $rule;
|
$this->_rules[$name] = $rule;
|
||||||
|
@ -236,9 +236,10 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable {
|
||||||
*/
|
*/
|
||||||
public function setRules($rules = array(), $mergeVars = true) {
|
public function setRules($rules = array(), $mergeVars = true) {
|
||||||
if ($mergeVars === false) {
|
if ($mergeVars === false) {
|
||||||
$this->_rules = $rules;
|
$this->_rules = array();
|
||||||
} else {
|
}
|
||||||
$this->_rules = array_merge($this->_rules, $rules);
|
foreach ($rules as $name => $rule) {
|
||||||
|
$this->setRule($name, $rule);
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,10 +156,22 @@ class CakeValidationSetTest extends CakeTestCase {
|
||||||
$result = $Field->getRules();
|
$result = $Field->getRules();
|
||||||
$this->assertEquals(array('validEmail'), array_keys($result));
|
$this->assertEquals(array('validEmail'), array_keys($result));
|
||||||
|
|
||||||
|
$Field->setRules(array('validEmail' => $rule), false);
|
||||||
|
$result = $Field->getRules();
|
||||||
|
$this->assertEquals(array('validEmail'), array_keys($result));
|
||||||
|
$this->assertTrue(array_pop($result) instanceof CakeValidationRule);
|
||||||
|
|
||||||
$rules = array('notEmpty' => $RuleEmpty);
|
$rules = array('notEmpty' => $RuleEmpty);
|
||||||
$Field->setRules($rules, true);
|
$Field->setRules($rules, true);
|
||||||
$result = $Field->getRules();
|
$result = $Field->getRules();
|
||||||
$this->assertEquals(array('validEmail', 'notEmpty'), array_keys($result));
|
$this->assertEquals(array('validEmail', 'notEmpty'), array_keys($result));
|
||||||
|
|
||||||
|
$rules = array('notEmpty' => array('rule' => 'notEmpty'));
|
||||||
|
$Field->setRules($rules, true);
|
||||||
|
$result = $Field->getRules();
|
||||||
|
$this->assertEquals(array('validEmail', 'notEmpty'), array_keys($result));
|
||||||
|
$this->assertTrue(array_pop($result) instanceof CakeValidationRule);
|
||||||
|
$this->assertTrue(array_pop($result) instanceof CakeValidationRule);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue