Skip to content

Commit 944bc96

Browse files
cjquinncjquinn
authored andcommitted
Added test case for saving belongs to many associations with mixed data array
1 parent 71d3859 commit 944bc96

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/TestCase/ORM/MarshallerTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,51 @@ public function testOneBelongsToManyJoinDataAssociatedWithIds()
557557
$this->assertEquals($data['tags'][5]['_joinData']['user']['username'], $result->tags[1]->_joinData->user->username);
558558
}
559559

560+
/**
561+
* Test belongsToMany association with mixed data array
562+
*
563+
* @return void
564+
*/
565+
public function testBelongsToManyWithMixedData()
566+
{
567+
568+
$data = [
569+
'title' => 'My title',
570+
'body' => 'My content',
571+
'author_id' => 1,
572+
'tags' => [
573+
[
574+
'name' => 'tag4'
575+
],
576+
[
577+
'name' => 'tag5'
578+
],
579+
[
580+
'id' => 1
581+
]
582+
]
583+
];
584+
585+
$articles = TableRegistry::get('Articles');
586+
$articles->belongsToMany('Tags');
587+
588+
$tags = TableRegistry::get('Tags');
589+
590+
$article = $articles->newEntity($data, [
591+
'associated' => [
592+
'Tags'
593+
]
594+
]);
595+
596+
$this->assertEquals($article->tags[2], $tags->get(1));
597+
598+
$tag_count = $tags->find()->count();
599+
$articles->save($article);
600+
601+
$this->assertEquals($tag_count + 2, $tags->find()->count());
602+
603+
}
604+
560605
/**
561606
* Test HasMany association with _ids attribute
562607
*

0 commit comments

Comments
 (0)