Permalink
Browse files

Add additional tests for associations.

  • Loading branch information...
1 parent 1ce283a commit 3d6c9b435dc50443ead0ac9918a253faadda95f5 @markstory markstory committed Feb 9, 2014
Showing with 30 additions and 0 deletions.
  1. +30 −0 tests/TestCase/View/Form/EntityContextTest.php
@@ -312,6 +312,35 @@ public function testValAssociated() {
}
/**
+ * 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.
*
* @return void
@@ -594,6 +623,7 @@ protected function _setupTables() {
$comments = TableRegistry::get('Comments');
$users = TableRegistry::get('Users');
+ $users->hasMany('Articles');
$articles->schema([
'id' => ['type' => 'integer', 'length' => 11, 'null' => false],

0 comments on commit 3d6c9b4

Please sign in to comment.