Skip to content

Commit

Permalink
Add tests for Entity::errors() being able to read data with a path.
Browse files Browse the repository at this point in the history
Refs #3807
  • Loading branch information
markstory committed Jul 9, 2014
1 parent af7666c commit 3d22390
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/TestCase/ORM/EntityTest.php
Expand Up @@ -824,6 +824,33 @@ public function testErrorsDeep() {
$this->assertEquals($expected, $entity->errors('multiple'));
}

/**
* Test that errors can be read with a path.
*
* @return void
*/
public function testErrorPathReading() {
$assoc = new Entity;
$entity= new Entity([
'field' => 'value',
'one' => $assoc,
'many' => [$assoc]
]);
$entity->errors('wrong', 'Bad stuff');
$assoc->errors('nope', 'Terrible things');

$this->assertEquals('Bad stuff', $entity->errors('wrong'));
$this->assertEquals('Terrible things', $entity->errors('many.0.nope'));
$this->assertEquals('Terrible things', $entity->errors('one.nope'));
$this->assertEquals(['nope' => 'Terrible things'], $entity->errors('one'));
$this->assertEquals(['nope' => 'Terrible things'], $entity->errors('many.0'));

$this->assertEquals([], $entity->errors('many.0.mistake'));
$this->assertEquals([], $entity->errors('one.mistake'));
$this->assertEquals([], $entity->errors('one.1.mistake'));
$this->assertEquals([], $entity->errors('many.1.nope'));
}

/**
* Tests that changing the value of a property will remove errors
* stored for it
Expand Down

0 comments on commit 3d22390

Please sign in to comment.