Permalink
Browse files

Added test for Marshaller::mergeMany

  • Loading branch information...
1 parent 52e36fe commit 6c131a60b05a5996217e23845bc38f3d1d0aa468 @lorenzo lorenzo committed Mar 2, 2014
Showing with 29 additions and 0 deletions.
  1. +29 −0 tests/TestCase/ORM/MarshallerTest.php
@@ -848,4 +848,33 @@ public function testMergeJoinDataAssociations() {
$this->assertEquals('ber', $entity->tags[1]->_joinData->user->username);
}
+/**
+ * Test mergeMany() with a simple set of data.
+ *
+ * @return void
+ */
+ public function testMergeManySimple() {
+ $entities = [
+ new OpenEntity(['id' => 1, 'comment' => 'First post', 'user_id' => 2]),
+ new OpenEntity(['id' => 2, 'comment' => 'Second post', 'user_id' => 2])
+ ];
+ $entities[0]->clean();
+ $entities[1]->clean();
+
+ $data = [
+ ['id' => 2, 'comment' => 'Changed 2', 'user_id' => 2],
+ ['id' => 1, 'comment' => 'Changed 1', 'user_id' => 1]
+ ];
+ $marshall = new Marshaller($this->comments);
+ $result = $marshall->mergeMany($entities, $data);
+
+ $this->assertSame($entities[0], $result[0]);
+ $this->assertSame($entities[1], $result[1]);
+ $this->assertEquals('Changed 1', $result[0]->comment);
+ $this->assertEquals(1, $result[0]->user_id);
+ $this->assertEquals('Changed 2', $result[1]->comment);
+ $this->assertTrue($result[0]->dirty('user_id'));
+ $this->assertFalse($result[1]->dirty('user_id'));
+ }
+
}

0 comments on commit 6c131a6

Please sign in to comment.