Browse Source

Add test for #4877

Appending into list properties does not mark them dirty, one must
manually mark list properties as dirty.

Refs #4877
Mark Story 11 years ago
parent
commit
0077ebf87f
1 changed files with 28 additions and 0 deletions
  1. 28 0
      tests/TestCase/ORM/TableTest.php

+ 28 - 0
tests/TestCase/ORM/TableTest.php

@@ -2773,6 +2773,34 @@ class TableTest extends TestCase {
 	}
 
 /**
+ * Tests saving belongsToMany records when record exists.
+ *
+ * @group save
+ * @return void
+ */
+	public function testSaveBelongsToManyJoinDataOnExistingRecord() {
+		$tags = TableRegistry::get('Tags');
+		$table = TableRegistry::get('Articles');
+		$table->belongsToMany('Tags');
+
+		$entity = $table->find()->contain('Tags')->first();
+		// not associated to the article already.
+		$entity->tags[] = $tags->get(3);
+		$entity->dirty('tags', true);
+
+		$this->assertSame($entity, $table->save($entity));
+
+		$this->assertFalse($entity->isNew());
+		$this->assertFalse($entity->tags[0]->isNew());
+		$this->assertFalse($entity->tags[1]->isNew());
+		$this->assertFalse($entity->tags[2]->isNew());
+
+		$this->assertNotEmpty($entity->tags[0]->_joinData);
+		$this->assertNotEmpty($entity->tags[1]->_joinData);
+		$this->assertNotEmpty($entity->tags[2]->_joinData);
+	}
+
+/**
  * Tests saving belongsToMany records can delete all links.
  *
  * @group save