mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
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
This commit is contained in:
parent
aca88deda4
commit
304bc01a9d
1 changed files with 42 additions and 1 deletions
|
@ -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')));
|
||||
|
|
Loading…
Reference in a new issue