From 944bc96b41678fa09edf6ccb12c98fb4149dae6d Mon Sep 17 00:00:00 2001 From: cjquinn Date: Thu, 2 Apr 2015 17:16:29 +0100 Subject: [PATCH] Added test case for saving belongs to many associations with mixed data array --- tests/TestCase/ORM/MarshallerTest.php | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/TestCase/ORM/MarshallerTest.php b/tests/TestCase/ORM/MarshallerTest.php index b78dcc49a54..117aa03721d 100644 --- a/tests/TestCase/ORM/MarshallerTest.php +++ b/tests/TestCase/ORM/MarshallerTest.php @@ -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 *