From 3d22390739bdaadd09a19fb22512295de8be8305 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 9 Jul 2014 14:32:39 -0400 Subject: [PATCH] Add tests for Entity::errors() being able to read data with a path. Refs #3807 --- tests/TestCase/ORM/EntityTest.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/TestCase/ORM/EntityTest.php b/tests/TestCase/ORM/EntityTest.php index 5727c267c40..0c7a30f337a 100644 --- a/tests/TestCase/ORM/EntityTest.php +++ b/tests/TestCase/ORM/EntityTest.php @@ -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