Skip to content
Permalink
Browse files

Implemented new method isEmptyAllowed in CakeValidationRule

  • Loading branch information...
lorenzo committed May 11, 2012
1 parent 785cf83 commit 217bf85537f213b7b281ceeab2929fe9f891b6c1
@@ -130,6 +130,15 @@ public function isValid() {
return true;
}
/**
* Returns whether the field can be left blank according to this rule
*
* @return boolean
*/
public function isEmptyAllowed() {
return $this->skip() || $this->allowEmpty === true;
}
/**
* Checks if the field is required according to the `required` property
*
@@ -132,4 +132,33 @@ public function testIsRequired() {
$Rule->isUpdate(true);
$this->assertTrue($Rule->isRequired());
}
/**
* Test isEmptyAllowed method
*
* @return void
*/
public function testIsEmplyAllowed() {
$def = array('rule' => 'aRule', 'allowEmpty' => true);
$Rule = new CakeValidationRule($def);
$this->assertTrue($Rule->isEmptyAllowed());
$def = array('rule' => 'aRule', 'allowEmpty' => false);
$Rule = new CakeValidationRule($def);
$this->assertFalse($Rule->isEmptyAllowed());
$def = array('rule' => 'notEmpty', 'allowEmpty' => false, 'on' => 'update');
$Rule = new CakeValidationRule($def);
$this->assertTrue($Rule->isEmptyAllowed());
$Rule->isUpdate(true);
$this->assertFalse($Rule->isEmptyAllowed());
$def = array('rule' => 'notEmpty', 'allowEmpty' => false, 'on' => 'create');
$Rule = new CakeValidationRule($def);
$this->assertFalse($Rule->isEmptyAllowed());
$Rule->isUpdate(true);
$this->assertTrue($Rule->isEmptyAllowed());
}
}

0 comments on commit 217bf85

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