Skip to content

Commit

Permalink
added tests for asArray with through relations
Browse files Browse the repository at this point in the history
  • Loading branch information
cebe committed Jun 22, 2012
1 parent d2ffe6b commit 86d9ff8
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tests/framework/db/ar/CActiveRecordAsArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* Currently uncovered:
* - stat relations
* - composite pk
* - through relations
*/
class CActiveRecordAsArrayTest extends CTestCase
{
Expand Down Expand Up @@ -170,7 +169,9 @@ public function dataFindParams()
array('', array()), // default arguments to find()
array(array('with'=>array('categories')), array()),
array(array('with'=>array('author','categories')), array()),
array(array('with'=>array('author'=>array('with'=>'groups'),'categories')), array()), // groups is a through relation
array(array('with'=>array('author','categories'), 'together'=>true), array()),
array(array('with'=>array('author'=>array('with'=>'groups'),'categories'), 'together'=>true), array()),
);
$data = array();
foreach($ids as $id) {
Expand All @@ -195,7 +196,9 @@ public function dataFindAllParams()
$withs = array(
array(),
array('with'=>array('author','categories')),
array('with'=>array('author'=>array('with'=>'groups'),'categories')), // groups is a through relation
array('with'=>array('author','categories'), 'together'=>true),
array('with'=>array('author'=>array('with'=>'groups'),'categories'), 'together'=>true),
array('with'=>array('author','categories'=>array('index'=>'id', 'with'=>'posts'))),
);

Expand Down Expand Up @@ -392,12 +395,24 @@ public function testRelation()
);
$this->assertFalse($post->getAsArray());

$this->assertArrayMatchesRecord(
$post->asArray()->author(array('with'=>'groups')), // groups is a through relation
$post->author(array('with'=>'groups'))
);
$this->assertFalse($post->getAsArray());

$this->assertArrayMatchesRecord(
$post->asArray()->author(array('with'=>'posts', 'together'=>true)),
$post->author(array('with'=>'posts', 'together'=>true))
);
$this->assertFalse($post->getAsArray());

$this->assertArrayMatchesRecord(
$post->asArray()->author(array('with'=>'groups', 'together'=>true)), // groups is a through relation
$post->author(array('with'=>'groups', 'together'=>true))
);
$this->assertFalse($post->getAsArray());

$post1=Post::model()->findByPk(1);
$this->assertFalse($post1->getAsArray());

Expand Down

0 comments on commit 86d9ff8

Please sign in to comment.