Skip to content

Commit

Permalink
Removing errors when properties in the entity change
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Nov 20, 2013
1 parent f82ac1b commit a281906
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Cake/ORM/Entity.php
Expand Up @@ -408,6 +408,7 @@ public function dirty($property, $isDirty = null) {
}

$this->_dirty[$property] = true;
unset($this->_errors[$property]);
return true;
}

Expand Down Expand Up @@ -513,8 +514,8 @@ public function errors($field = null, $errors = null) {
return $this->_errors;
}

if (is_string($field) && $errors === null && isset($this->_errors[$field])) {
return $this->_errors[$field];
if (is_string($field) && $errors === null) {
return isset($this->_errors[$field]) ? $this->_errors[$field] : [];
}

if (!is_array($field)) {
Expand Down
28 changes: 28 additions & 0 deletions Cake/Test/TestCase/ORM/EntityTest.php
Expand Up @@ -739,4 +739,32 @@ public function testErrors() {
$this->assertEquals($errors, $entity->errors());
}

/**
* Tests that changing the value of a property will remove errors
* stored for it
*
* @return void
*/
public function testDirtyRemovesError() {
$entity = new Entity(['a' => 'b']);
$entity->errors('a', 'is not good');
$entity->set('a', 'c');
$this->assertEmpty($entity->errors('a'));

$entity->errors('a', 'is not good');
$entity->dirty('a', true);
$this->assertEmpty($entity->errors('a'));
}

/**
* Tests that marking an entity as clean will remove errors too
*
* @return void
*/
public function testCleanRemovesErrors() {
$entity = new Entity(['a' => 'b']);
$entity->errors('a', 'is not good');
$entity->clean();
$this->assertEmpty($entity->errors());
}
}

0 comments on commit a281906

Please sign in to comment.