Browse Source

Add test for saveAssociated and expression objects.

Add a test for #1514. This issue was fixed during recent refactorings.

Closes #1514
mark_story 12 years ago
parent
commit
016c3aed44
1 changed files with 26 additions and 0 deletions
  1. 26 0
      lib/Cake/Test/Case/Model/ModelWriteTest.php

+ 26 - 0
lib/Cake/Test/Case/Model/ModelWriteTest.php

@@ -6245,6 +6245,32 @@ class ModelWriteTest extends BaseModelTest {
 	}
 
 /**
+ * Test that saveAssociated will accept expression object values when saving.
+ *
+ * @return void
+ */
+	public function testSaveAssociatedExpressionObjects() {
+		$this->loadFixtures('Post', 'Author', 'Comment', 'Attachment', 'Article', 'User');
+		$TestModel = new Post();
+		$db = $TestModel->getDataSource();
+
+		$TestModel->saveAssociated(array(
+			'Post' => array(
+				'title' => $db->expression('(SELECT "Post with Author")'),
+				'body' => 'This post will be saved with an author'
+			),
+			'Author' => array(
+				'user' => 'bob',
+				'password' => '5f4dcc3b5aa765d61d8327deb882cf90'
+		)));
+
+		$result = $TestModel->find('first', array(
+			'order' => array('Post.id ' => 'DESC')
+		));
+		$this->assertEquals('Post with Author', $result['Post']['title']);
+	}
+
+/**
  * testUpdateWithCalculation method
  *
  * @return void