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