Skip to content

Commit

Permalink
Add one more test for a reported problem
Browse files Browse the repository at this point in the history
  • Loading branch information
AD7six committed Feb 14, 2015
1 parent 4fe588a commit 74c76d4
Showing 1 changed file with 66 additions and 2 deletions.
68 changes: 66 additions & 2 deletions tests/TestCase/ORM/TableTest.php
Expand Up @@ -48,8 +48,13 @@ class TableTest extends TestCase
{

public $fixtures = [
'core.users', 'core.categories', 'core.articles', 'core.authors',
'core.tags', 'core.articles_tags'
'core.comments',
'core.users',
'core.categories',
'core.articles',
'core.authors',
'core.tags',
'core.articles_tags'
];

/**
Expand Down Expand Up @@ -550,6 +555,65 @@ public function testHasMany()
$this->assertSame($table, $hasMany->source());
}

/**
* testHasManyWithClassName
*
* @return void
*/
public function testHasManyWithClassName()
{
$table = TableRegistry::get('Articles');
$table->hasMany('Comments', [
'className' => 'Comments',
'conditions' => ['published' => 'Y'],
]);

$table->hasMany('UnapprovedComments', [
'className' => 'Comments',
'conditions' => ['published' => 'N'],
'propertyName' => 'unaproved_comments'
]);

$expected = [
'id' => 1,
'title' => 'First Article',
'unaproved_comments' => [
[
'id' => 4,
'article_id' => 1,
'comment' => 'Fourth Comment for First Article'
]
],
'comments' => [
[
'id' => 1,
'article_id' => 1,
'comment' => 'First Comment for First Article'
],
[
'id' => 2,
'article_id' => 1,
'comment' => 'Second Comment for First Article'
],
[
'id' => 3,
'article_id' => 1,
'comment' => 'Third Comment for First Article'
]
]
];
$result = $table->find()
->select(['id', 'title'])
->contain([
'Comments' => ['fields' => ['id', 'article_id', 'comment']],
'UnapprovedComments' => ['fields' => ['id', 'article_id', 'comment']]
])
->where(['id' => 1])
->first();

$this->assertSame($expected, $result->toArray());
}

/**
* Ensure associations use the plugin-prefixed model
*
Expand Down

0 comments on commit 74c76d4

Please sign in to comment.