Skip to content

Commit

Permalink
Add additional tests for associations.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Feb 9, 2014
1 parent 1ce283a commit 3d6c9b4
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/TestCase/View/Form/EntityContextTest.php
Expand Up @@ -311,6 +311,35 @@ public function testValAssociated() {
$this->assertNull($result); $this->assertNull($result);
} }


/**
* Test reading values from associated entities.
*
* @return void
*/
public function testValAssociatedHasMany() {
$row = new Entity([
'title' => 'First post',
'user' => new Entity([
'username' => 'mark',
'fname' => 'Mark',
'articles' => [
new Entity(['title' => 'First post']),
new Entity(['title' => 'Second post']),
]
]),
]);
$context = new EntityContext($this->request, [
'entity' => $row,
'table' => 'Articles',
]);

$result = $context->val('user.articles.0.title');
$this->assertEquals('First post', $result);

$result = $context->val('user.articles.1.title');
$this->assertEquals('Second post', $result);
}

/** /**
* Test validator as a string. * Test validator as a string.
* *
Expand Down Expand Up @@ -594,6 +623,7 @@ protected function _setupTables() {


$comments = TableRegistry::get('Comments'); $comments = TableRegistry::get('Comments');
$users = TableRegistry::get('Users'); $users = TableRegistry::get('Users');
$users->hasMany('Articles');


$articles->schema([ $articles->schema([
'id' => ['type' => 'integer', 'length' => 11, 'null' => false], 'id' => ['type' => 'integer', 'length' => 11, 'null' => false],
Expand Down

0 comments on commit 3d6c9b4

Please sign in to comment.