/**
  * Test error on associated entities.
  *
  * @return void
  */
 public function testErrorAssociatedHasMany()
 {
     $this->_setupTables();
     $comments = TableRegistry::get('Comments');
     $row = new Article(['title' => 'My title', 'comments' => [new Entity(['comment' => '']), new Entity(['comment' => 'Second comment'])]]);
     $row->comments[0]->errors('comment', ['Is required']);
     $row->comments[0]->errors('article_id', ['Is required']);
     $context = new EntityContext($this->request, ['entity' => $row, 'table' => 'Articles', 'validator' => 'default']);
     $this->assertEquals([], $context->error('title'));
     $this->assertEquals([], $context->error('comments.0.user_id'));
     $this->assertEquals([], $context->error('comments.0'));
     $this->assertEquals(['Is required'], $context->error('comments.0.comment'));
     $this->assertEquals(['Is required'], $context->error('comments.0.article_id'));
     $this->assertEquals([], $context->error('comments.1'));
     $this->assertEquals([], $context->error('comments.1.comment'));
     $this->assertEquals([], $context->error('comments.1.article_id'));
 }
 /**
  * Test error
  *
  * @return void
  */
 public function testError()
 {
     $this->_setupTables();
     $row = new Article(['title' => 'My title', 'user' => new Entity(['username' => 'Mark'])]);
     $row->errors('title', []);
     $row->errors('body', 'Gotta have one');
     $row->errors('user_id', ['Required field']);
     $row->user->errors('username', ['Required']);
     $context = new EntityContext($this->request, ['entity' => $row, 'table' => 'Articles']);
     $this->assertEquals([], $context->error('title'));
     $expected = ['Gotta have one'];
     $this->assertEquals($expected, $context->error('body'));
     $expected = ['Required'];
     $this->assertEquals($expected, $context->error('user.username'));
 }