Skip to content

Commit

Permalink
Added test case for saving belongs to many associations with mixed da…
Browse files Browse the repository at this point in the history
…ta array
  • Loading branch information
cjquinn authored and cjquinn committed Apr 5, 2015
1 parent 71d3859 commit 944bc96
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/TestCase/ORM/MarshallerTest.php
Expand Up @@ -557,6 +557,51 @@ public function testOneBelongsToManyJoinDataAssociatedWithIds()
$this->assertEquals($data['tags'][5]['_joinData']['user']['username'], $result->tags[1]->_joinData->user->username);
}

/**
* Test belongsToMany association with mixed data array
*
* @return void
*/
public function testBelongsToManyWithMixedData()
{

$data = [
'title' => 'My title',
'body' => 'My content',
'author_id' => 1,
'tags' => [
[
'name' => 'tag4'
],
[
'name' => 'tag5'
],
[
'id' => 1
]
]
];

$articles = TableRegistry::get('Articles');
$articles->belongsToMany('Tags');

$tags = TableRegistry::get('Tags');

$article = $articles->newEntity($data, [
'associated' => [
'Tags'
]
]);

$this->assertEquals($article->tags[2], $tags->get(1));

$tag_count = $tags->find()->count();
$articles->save($article);

$this->assertEquals($tag_count + 2, $tags->find()->count());

}

/**
* Test HasMany association with _ids attribute
*
Expand Down

0 comments on commit 944bc96

Please sign in to comment.