/**
  * Test automatic entity provider setting
  *
  * @return void
  */
 public function testValidatorEntityProvider()
 {
     $row = new Article(['title' => 'Test entity', 'body' => 'Something new']);
     $context = new EntityContext($this->request, ['entity' => $row, 'table' => 'Articles']);
     $context->isRequired('title');
     $articles = TableRegistry::get('Articles');
     $this->assertSame($row, $articles->validator()->provider('entity'));
     $row = new Article(['title' => 'First post', 'user' => new Entity(['username' => 'mark', 'fname' => 'Mark', 'articles' => [new Article(['title' => 'First post']), new Article(['title' => 'Second post'])]])]);
     $context = new EntityContext($this->request, ['entity' => $row, 'table' => 'Articles']);
     $validator = $articles->validator();
     $context->isRequired('user.articles.0.title');
     $this->assertSame($row->user->articles[0], $validator->provider('entity'));
     $context->isRequired('user.articles.1.title');
     $this->assertSame($row->user->articles[1], $validator->provider('entity'));
     $context->isRequired('title');
     $this->assertSame($row, $validator->provider('entity'));
 }
 /**
  * Test isRequired on associated entities.
  *
  * @return void
  */
 public function testIsRequiredAssociatedBelongsTo()
 {
     $this->_setupTables();
     $row = new Article(['title' => 'My title', 'user' => new Entity(['username' => 'Mark'])]);
     $context = new EntityContext($this->request, ['entity' => $row, 'table' => 'Articles', 'validator' => ['Articles' => 'create', 'Users' => 'custom']]);
     $this->assertTrue($context->isRequired('user.username'));
     $this->assertFalse($context->isRequired('user.first_name'));
 }