mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Adding test case for Model::saveAll, to allow it to return the results of each record save in an array, if 'atomic' option is false. This means we can now see which records failed and which were successful. Refs #4400.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6695 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
8756f0d471
commit
54121efb3e
1 changed files with 63 additions and 30 deletions
|
@ -2086,21 +2086,54 @@ class ModelTest extends CakeTestCase {
|
|||
$this->assertEqual($result[6]['Attachment'], $expected);
|
||||
}
|
||||
|
||||
function testSaveAllHasMany() {
|
||||
$this->loadFixtures('Article', 'Comment');
|
||||
function testSaveAllAtomic()
|
||||
{
|
||||
$this->model =& new Article();
|
||||
$this->model->belongsTo = $this->model->hasAndBelongsToMany = array();
|
||||
|
||||
$this->assertTrue($this->model->saveAll(
|
||||
array(
|
||||
$result = $this->model->saveAll(array(
|
||||
'Article' => array('title' => 'Post with Author', 'body' => 'This post will be saved with an author'),
|
||||
'Comment' => array('comment' => 'First new comment')
|
||||
), array('atomic' => false));
|
||||
$this->assertIdentical($result, array('Article' => array(true), 'Comment' => array(true)));
|
||||
|
||||
$result = $this->model->saveAll(array(
|
||||
array('id' => '1', 'title' => 'Baleeted First Post', 'body' => 'Baleeted!', 'published' => 'N'),
|
||||
array('id' => '2', 'title' => 'Just update the title'),
|
||||
array('title' => 'Creating a fourth post', 'body' => 'Fourth post body', 'author_id' => 2)
|
||||
), array('atomic' => false));
|
||||
$this->assertIdentical($result, array(true, true, true));
|
||||
|
||||
$this->model->validate = array('title' => VALID_NOT_EMPTY, 'author_id' => 'numeric');
|
||||
$result = $this->model->saveAll(array(
|
||||
array('id' => '1', 'title' => 'Un-Baleeted First Post', 'body' => 'Not Baleeted!', 'published' => 'Y'),
|
||||
array('id' => '2', 'title' => '', 'body' => 'Trying to get away with an empty title'),
|
||||
), array('atomic' => false));
|
||||
$this->assertIdentical($result, array(true, false));
|
||||
|
||||
$result = $this->model->saveAll(array(
|
||||
'Article' => array('id' => 2),
|
||||
'Comment' => array(
|
||||
array('comment' => 'First new comment', 'published' => 'Y', 'user_id' => 1),
|
||||
array('comment' => 'Second new comment', 'published' => 'Y', 'user_id' => 2)
|
||||
)
|
||||
), array('atomic' => false));
|
||||
$this->assertIdentical($result, array('Article' => array(true), 'Comment' => array(true, true)));
|
||||
}
|
||||
|
||||
function testSaveAllHasMany() {
|
||||
$this->loadFixtures('Article', 'Comment');
|
||||
$this->model =& new Article();
|
||||
$this->model->belongsTo = $this->model->hasAndBelongsToMany = array();
|
||||
|
||||
$result = $this->model->saveAll(array(
|
||||
'Article' => array('id' => 2),
|
||||
'Comment' => array(
|
||||
array('comment' => 'First new comment', 'published' => 'Y', 'user_id' => 1),
|
||||
array('comment' => 'Second new comment', 'published' => 'Y', 'user_id' => 2)
|
||||
)
|
||||
),
|
||||
array('atomic' => false)
|
||||
));
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->model->findById(2);
|
||||
$expected = array('First Comment for Second Article', 'Second Comment for Second Article', 'First new comment', 'Second new comment');
|
||||
$this->assertEqual(Set::extract($result['Comment'], '{n}.comment'), $expected);
|
||||
|
|
Loading…
Add table
Reference in a new issue