From 4191e2e573fdf6f416ea7b412a8364e6b3fc2a6d Mon Sep 17 00:00:00 2001 From: Ceeram Date: Mon, 19 Mar 2012 01:27:35 +0100 Subject: [PATCH] adding test to disprove ticket, closes #2691 --- lib/Cake/Test/Case/Model/ModelWriteTest.php | 52 +++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index 631342ee6..10be95b73 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -6560,4 +6560,56 @@ class ModelWriteTest extends BaseModelTest { $this->assertEquals($expected, $result); } +/** + * testSaveAllDeepHasManyBelongsTo method + * + * return @void + */ + public function testSaveAllDeepHasManyBelongsTo() { + $this->loadFixtures('Article', 'Comment', 'User'); + $TestModel = new Article(); + $TestModel->belongsTo = $TestModel->hasAndBelongsToMany = array(); + + $this->db->truncate($TestModel); + $this->db->truncate(new Comment()); + + $result = $TestModel->saveAll(array( + 'Article' => array('id' => 2, 'title' => 'I will not save'), + 'Comment' => array( + array('comment' => 'First new comment', 'published' => 'Y', 'user_id' => 1), + array( + 'comment' => 'belongsto', 'published' => 'Y', + 'User' => array('user' => 'findme', 'password' => 'somepass') + ) + ) + ), array('deep' => true)); + + $result = $TestModel->Comment->User->find('first', array( + 'conditions' => array('User.user' => 'findme'), + 'fields' => array('id', 'user', 'password') + )); + $expected = array( + 'User' => array( + 'id' => 5, + 'user' => 'findme', + 'password' => 'somepass', + ) + ); + $this->assertEquals($expected, $result); + + $result = $TestModel->Comment->find('first', array( + 'conditions' => array('Comment.user_id' => 5), + 'fields' => array('id', 'comment', 'published', 'user_id') + )); + $expected = array( + 'Comment' => array( + 'id' => 2, + 'comment' => 'belongsto', + 'published' => 'Y', + 'user_id' => 5 + ) + ); + $this->assertEquals($expected, $result); + } + }