Permalink
Browse files

Adding test for merging belongsToMany in existing entity when passing

_ids
  • Loading branch information...
lorenzo committed Mar 2, 2014
1 parent 704388c commit f333550374f09a6dfa88f0db94851b685d33bd8c
Showing with 30 additions and 0 deletions.
  1. +30 −0 tests/TestCase/ORM/MarshallerTest.php
@@ -682,4 +682,34 @@ public function testMergeMultipleAssociations() {
);
}
+/**
+ * Tests that merging data to an entity containing belongsToMany and _ids
+ * will just overwrite the data
+ *
+ * @return void
+ */
+ public function testMergeBelongsToManyEntitiesFromIds() {
+ $entity = new Entity([
+ 'title' => 'Haz tags',
+ 'body' => 'Some content here',
+ 'tags' => [
+ new Entity(['id' => 1, 'name' => 'Cake']),
+ new Entity(['id' => 2, 'name' => 'PHP'])
+ ]
+ ]);
+
+ $data = [
+ 'title' => 'Haz moar tags',
+ 'tags' => ['_ids' => [1, 2, 3]]
+ ];
+ $entity->accessible('*', true);
+ $marshall = new Marshaller($this->articles);
+ $result = $marshall->merge($entity, $data, ['Tags']);
+
+ $this->assertCount(3, $result->tags);
+ $this->assertInstanceOf('Cake\ORM\Entity', $result->tags[0]);
+ $this->assertInstanceOf('Cake\ORM\Entity', $result->tags[1]);
+ $this->assertInstanceOf('Cake\ORM\Entity', $result->tags[2]);
+ }
+
}

0 comments on commit f333550

Please sign in to comment.