From 304bc01a9d6df9cd9e600f9eb256a5d33ee8a3c5 Mon Sep 17 00:00:00 2001 From: "mariano.iglesias" Date: Wed, 24 Oct 2007 03:32:34 +0000 Subject: [PATCH] Adding test for #3455, secondary model array in model data causes corruption git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5884 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/tests/cases/libs/model/model.test.php | 43 +++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 3a2624b2a..824381828 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -599,6 +599,47 @@ class ModelTest extends CakeTestCase { $expected = array('Article' => array('published' => 'N')); $this->assertEqual($result, $expected); } + + function testCreationWithMultipleData() { + $this->Article =& new Article(); + $this->Comment =& new Comment(); + + $articles = $this->Article->find('all', array('fields' => array('id','title'), 'recursive' => -1)); + $comments = $this->Comment->find('all', array('fields' => array('id','article_id','user_id','comment','published'), 'recursive' => -1)); + $this->assertEqual($articles, array( + array('Article' => array('id' => 1, 'title' => 'First Article')), + array('Article' => array('id' => 2, 'title' => 'Second Article')), + array('Article' => array('id' => 3, 'title' => 'Third Article')))); + $this->assertEqual($comments, array( + array('Comment' => array('id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y')), + array('Comment' => array('id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y')), + array('Comment' => array('id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y')), + array('Comment' => array('id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N')), + array('Comment' => array('id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y')), + array('Comment' => array('id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y')))); + + $data = array('Comment' => array('article_id' => 2, 'user_id' => 4, 'comment' => 'Brand New Comment', 'published' => 'N'), + 'Article' => array('id' => 2, 'title' => 'Second Article Modified')); + $result = $this->Comment->create($data); + $this->assertTrue($result); + $result = $this->Comment->save(); + $this->assertTrue($result); + + $articles = $this->Article->find('all', array('fields' => array('id','title'), 'recursive' => -1)); + $comments = $this->Comment->find('all', array('fields' => array('id','article_id','user_id','comment','published'), 'recursive' => -1)); + $this->assertEqual($articles, array( + array('Article' => array('id' => 1, 'title' => 'First Article')), + array('Article' => array('id' => 2, 'title' => 'Second Article')), + array('Article' => array('id' => 3, 'title' => 'Third Article')))); + $this->assertEqual($comments, array( + array('Comment' => array('id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y')), + array('Comment' => array('id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y')), + array('Comment' => array('id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y')), + array('Comment' => array('id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N')), + array('Comment' => array('id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y')), + array('Comment' => array('id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y')), + array('Comment' => array('id' => 7, 'article_id' => 2, 'user_id' => 4, 'comment' => 'Brand New Comment', 'published' => 'N')))); + } function testReadFakeThread() { $this->model =& new CategoryThread(); @@ -822,7 +863,7 @@ class ModelTest extends CakeTestCase { $this->model->id = $id = 1000; $this->model->delete(); - $this->model->save(array('User' => array('id' => $id, 'user' => 'some user'))); + $this->model->save(array('User' => array('id' => $id, 'user' => 'some user', 'password' => 'some password'))); $this->assertEqual($this->model->id, $id); $this->model->save(array('User' => array('user' => 'updated user')));