Skip to content
Permalink
Browse files

Implementing the setter for validatePresence

  • Loading branch information...
lorenzo committed Oct 31, 2013
1 parent d15fcd6 commit 29e788ba37d0b2d8b653590a39336a73e0595c65
Showing with 34 additions and 1 deletion.
  1. +1 −1 Cake/ORM/Validation/ValidationSet.php
  2. +12 −0 Cake/ORM/Validator.php
  3. +21 −0 Cake/Test/TestCase/ORM/ValidatorTest.php
@@ -83,7 +83,7 @@ class ValidationSet implements \ArrayAccess, \IteratorAggregate, \Countable {
* @param boolean|string $validatePresent Valid values are true, false, 'create', 'update'
* @return boolean|string
*/
public function validatePresent($validatePresent = null) {
public function isPresenceRequired($validatePresent = null) {
if ($validatePresent === null) {
return $this->_validatePresent;
}
@@ -255,4 +255,16 @@ public function remove($field, $rule = null) {
}
return $this;
}
/**
* Sets whether a field is required to be present in data array.
*
* @param string $field the name of the field
* @param boolean|string $allowEmpty Valid values are true, false, 'create', 'update'
* @return Validator this instance
*/
public function validatePresence($field, $type = true) {
$this->field($field)->isPresenceRequired($type);
return $this;
}
}
@@ -90,4 +90,25 @@ public function testRemove() {
$this->assertCount(1, $validator->field('title'));
$this->assertNull($validator->field('title')->rule('foo'));
}
/**
* Tests the validatePresence method
*
* @return void
*/
public function testValidatePresence() {
$validator = new Validator;
$this->assertSame($validator, $validator->validatePresence('title'));
$this->assertTrue($validator->field('title')->isPresenceRequired());
$validator->validatePresence('title', false);
$this->assertFalse($validator->field('title')->isPresenceRequired());
$validator->validatePresence('title', 'created');
$this->assertEquals('created', $validator->field('title')->isPresenceRequired());
$validator->validatePresence('title', 'updated');
$this->assertEquals('updated', $validator->field('title')->isPresenceRequired());
}
}

0 comments on commit 29e788b

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