Correcting inconsistent return values in Model::saveAll(), updating bad tests, fixes #4981

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7283 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-06-27 06:07:00 +00:00
parent 0fc7355e6b
commit 14e8c5fe7b
3 changed files with 56 additions and 9 deletions

View file

@ -117,7 +117,7 @@ class AclNode extends AppModel {
'conditions' => array(
$db->name("{$type}{$i}.lft") . ' > ' . $db->name("{$type}{$j}.lft"),
$db->name("{$type}{$i}.rght") . ' < ' . $db->name("{$type}{$j}.rght"),
$db->name("{$type}{$i}.alias") . ' = ' . $db->value($alias)
$db->name("{$type}{$i}.alias") . ' = ' . $db->value($alias, 'string')
)
);

View file

@ -1350,7 +1350,7 @@ class Model extends Overloadable {
switch (true) {
case ($options['validate'] === 'only'):
return $validates;
return ($options['atomic'] ? $validates : $return);
break;
case ($options['validate'] === 'first'):
$options['validate'] = true;
@ -1395,7 +1395,7 @@ class Model extends Overloadable {
$validates = false;
}
if (!$options['atomic']) {
$return[$this->alias][] = $validates;
$return[$this->alias] = $validates;
}
$validating = ($options['validate'] === 'only' || $options['validate'] === 'first');
@ -1447,15 +1447,15 @@ class Model extends Overloadable {
}
}
}
$this->validationErrors = $validationErrors;
if (isset($validationErrors[$this->alias])) {
$this->validationErrors = $validationErrors[$this->alias];
}
switch (true) {
case ($options['validate'] === 'only'):
return $validates;
return ($options['atomic'] ? $validates : $return);
break;
case ($options['validate'] === 'first'):
$options['validate'] = true;

View file

@ -2730,7 +2730,7 @@ class ModelTest extends CakeTestCase {
'Article' => array('title' => 'Post with Author', 'body' => 'This post will be saved with an author', 'user_id' => 2),
'Comment' => array(array('comment' => 'First new comment', 'user_id' => 2))
), array('atomic' => false));
$this->assertIdentical($result, array('Article' => array(true), 'Comment' => array(true)));
$this->assertIdentical($result, array('Article' => true, 'Comment' => array(true)));
$result = $TestModel->saveAll(array(
array('id' => '1', 'title' => 'Baleeted First Post', 'body' => 'Baleeted!', 'published' => 'N'),
@ -2753,7 +2753,7 @@ class ModelTest extends CakeTestCase {
array('comment' => 'Second new comment', 'published' => 'Y', 'user_id' => 2)
)
), array('atomic' => false));
$this->assertIdentical($result, array('Article' => array(true), 'Comment' => array(true, true)));
$this->assertIdentical($result, array('Article' => true, 'Comment' => array(true, true)));
}
/**
* testSaveAllHasMany method
@ -2804,7 +2804,7 @@ class ModelTest extends CakeTestCase {
),
array('atomic' => false)
);
$this->assertEqual($result, array('Article' => array(0 => false)));
$this->assertEqual($result, array('Article' => false));
$result = $TestModel->findById(2);
$expected = array('First Comment for Second Article', 'Second Comment for Second Article', 'First new comment', 'Second new comment', 'Third new comment');
@ -5129,6 +5129,53 @@ class ModelTest extends CakeTestCase {
$this->assertTrue(is_array($result));
$this->assertEqual($result, $expected);
}
/**
* testSaveAllHasManyValidationOnly method
*
* @access public
* @return void
*/
function testSaveAllHasManyValidationOnly() {
$this->loadFixtures('Article', 'Comment');
$TestModel =& new Article();
$TestModel->belongsTo = $TestModel->hasAndBelongsToMany = array();
$TestModel->Comment->validate = array('comment' => VALID_NOT_EMPTY);
$result = $TestModel->saveAll(
array(
'Article' => array('id' => 2),
'Comment' => array(
array('id' => 1, 'comment' => '', 'published' => 'Y', 'user_id' => 1),
array('id' => 2, 'comment' => 'comment', 'published' => 'Y', 'user_id' => 1),
)
),
array('validate' => 'only')
);
$this->assertIdentical($result, false);
$result = $TestModel->saveAll(
array(
'Article' => array('id' => 2),
'Comment' => array(
array('id' => 1, 'comment' => '', 'published' => 'Y', 'user_id' => 1),
array('id' => 2, 'comment' => 'comment', 'published' => 'Y', 'user_id' => 1),
)
),
array('validate' => 'only', 'atomic' => false)
);
$expected = array('Article' => true, 'Comment' => array(false, true));
$this->assertIdentical($result, $expected);
$expected = array('Comment' => array(
1 => array('comment' => 'This field cannot be left blank')
));
$this->assertEqual($TestModel->validationErrors, $expected);
$expected = array(
1 => array('comment' => 'This field cannot be left blank')
);
$this->assertEqual($TestModel->Comment->validationErrors, $expected);
}
/**
* endTest method
*
@ -5140,4 +5187,4 @@ class ModelTest extends CakeTestCase {
}
}
?>
?>