Skip to content

Commit

Permalink
Implemented removeRule in CakeValidationSet
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed May 7, 2012
1 parent 1ff1af3 commit a7222bc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/Cake/Model/Validator/CakeValidationSet.php
Expand Up @@ -167,7 +167,7 @@ public function getRules() {
*
* @param mixed $key The key under which the rule should be set
* @param CakeRule|array $rule The validation rule to be set
* @return ModelField
* @return CakeValidationSet this instance
*/
public function setRule($key, $rule) {
if (!$rule instanceof CakeRule) {
Expand All @@ -177,6 +177,17 @@ public function setRule($key, $rule) {
return $this;
}

/**
* Removes a validation rule from the set
*
* @param mixed $key The key under which the rule should be unset
* @return CakeValidationSet this instance
*/
public function removeRule($key) {
unset($this->_rules[$key]);
return $this;
}

/**
* Sets the rules for a given field
*
Expand Down
22 changes: 22 additions & 0 deletions lib/Cake/Test/Case/Model/Validator/CakeValidationSetTest.php
Expand Up @@ -291,4 +291,26 @@ public function testCount() {
$this->assertCount(2, $Set);
}

/**
* Test removeRule method
*
* @return void
*/
public function testRemoveRule() {
$Set = new CakeValidationSet('title', array(
'notEmpty' => array('rule' => 'notEmpty', 'required' => true),
'numeric' => array('rule' => 'numeric'),
'other' => array('rule' => array('other', 1)),
));

$Set->removeRule('notEmpty');
$this->assertFalse(isset($Set['notEmpty']));

$Set->removeRule('numeric');
$this->assertFalse(isset($Set['numeric']));

$Set->removeRule('other');
$this->assertFalse(isset($Set['other']));
}

}

0 comments on commit a7222bc

Please sign in to comment.