mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
parent
0fc7355e6b
commit
14e8c5fe7b
3 changed files with 56 additions and 9 deletions
|
@ -117,7 +117,7 @@ class AclNode extends AppModel {
|
||||||
'conditions' => array(
|
'conditions' => array(
|
||||||
$db->name("{$type}{$i}.lft") . ' > ' . $db->name("{$type}{$j}.lft"),
|
$db->name("{$type}{$i}.lft") . ' > ' . $db->name("{$type}{$j}.lft"),
|
||||||
$db->name("{$type}{$i}.rght") . ' < ' . $db->name("{$type}{$j}.rght"),
|
$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')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1350,7 +1350,7 @@ class Model extends Overloadable {
|
||||||
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case ($options['validate'] === 'only'):
|
case ($options['validate'] === 'only'):
|
||||||
return $validates;
|
return ($options['atomic'] ? $validates : $return);
|
||||||
break;
|
break;
|
||||||
case ($options['validate'] === 'first'):
|
case ($options['validate'] === 'first'):
|
||||||
$options['validate'] = true;
|
$options['validate'] = true;
|
||||||
|
@ -1395,7 +1395,7 @@ class Model extends Overloadable {
|
||||||
$validates = false;
|
$validates = false;
|
||||||
}
|
}
|
||||||
if (!$options['atomic']) {
|
if (!$options['atomic']) {
|
||||||
$return[$this->alias][] = $validates;
|
$return[$this->alias] = $validates;
|
||||||
}
|
}
|
||||||
$validating = ($options['validate'] === 'only' || $options['validate'] === 'first');
|
$validating = ($options['validate'] === 'only' || $options['validate'] === 'first');
|
||||||
|
|
||||||
|
@ -1447,15 +1447,15 @@ class Model extends Overloadable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->validationErrors = $validationErrors;
|
$this->validationErrors = $validationErrors;
|
||||||
|
|
||||||
if (isset($validationErrors[$this->alias])) {
|
if (isset($validationErrors[$this->alias])) {
|
||||||
$this->validationErrors = $validationErrors[$this->alias];
|
$this->validationErrors = $validationErrors[$this->alias];
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case ($options['validate'] === 'only'):
|
case ($options['validate'] === 'only'):
|
||||||
return $validates;
|
return ($options['atomic'] ? $validates : $return);
|
||||||
break;
|
break;
|
||||||
case ($options['validate'] === 'first'):
|
case ($options['validate'] === 'first'):
|
||||||
$options['validate'] = true;
|
$options['validate'] = true;
|
||||||
|
|
|
@ -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),
|
'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))
|
'Comment' => array(array('comment' => 'First new comment', 'user_id' => 2))
|
||||||
), array('atomic' => false));
|
), 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(
|
$result = $TestModel->saveAll(array(
|
||||||
array('id' => '1', 'title' => 'Baleeted First Post', 'body' => 'Baleeted!', 'published' => 'N'),
|
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('comment' => 'Second new comment', 'published' => 'Y', 'user_id' => 2)
|
||||||
)
|
)
|
||||||
), array('atomic' => false));
|
), 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
|
* testSaveAllHasMany method
|
||||||
|
@ -2804,7 +2804,7 @@ class ModelTest extends CakeTestCase {
|
||||||
),
|
),
|
||||||
array('atomic' => false)
|
array('atomic' => false)
|
||||||
);
|
);
|
||||||
$this->assertEqual($result, array('Article' => array(0 => false)));
|
$this->assertEqual($result, array('Article' => false));
|
||||||
|
|
||||||
$result = $TestModel->findById(2);
|
$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');
|
$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->assertTrue(is_array($result));
|
||||||
$this->assertEqual($result, $expected);
|
$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
|
* endTest method
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue