mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding test case from '0x20h'. Fixing issue where atomic = false, validate = first and saveAll() saving many rows could return an incorrect value. Fixes #1050
This commit is contained in:
parent
ea9e30890f
commit
b02e213958
2 changed files with 60 additions and 1 deletions
|
@ -1593,6 +1593,7 @@ class Model extends Overloadable {
|
|||
|
||||
if (Set::numeric(array_keys($data))) {
|
||||
while ($validates) {
|
||||
$return = array();
|
||||
foreach ($data as $key => $record) {
|
||||
if (!$currentValidates = $this->__save($record, $options)) {
|
||||
$validationErrors[$key] = $this->validationErrors;
|
||||
|
@ -1624,7 +1625,6 @@ class Model extends Overloadable {
|
|||
break;
|
||||
case ($options['validate'] === 'first'):
|
||||
$options['validate'] = true;
|
||||
$return = array();
|
||||
break;
|
||||
default:
|
||||
if ($options['atomic']) {
|
||||
|
|
|
@ -3584,6 +3584,65 @@ class ModelWriteTest extends BaseModelTest {
|
|||
$this->assertEqual($result[0]['Comment'][0]['comment'], 'Only new comment');
|
||||
}
|
||||
|
||||
/**
|
||||
* test saveAll()'s return is correct when using atomic = false and validate = first.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testSaveAllValidateFirstAtomicFalse() {
|
||||
$Something =& new Something();
|
||||
$invalidData = array(
|
||||
array(
|
||||
'title' => 'foo',
|
||||
'body' => 'bar',
|
||||
'published' => 'baz',
|
||||
),
|
||||
array(
|
||||
'body' => 3,
|
||||
'published' =>'sd',
|
||||
),
|
||||
);
|
||||
$Something->create();
|
||||
$Something->validate = array(
|
||||
'title' => array(
|
||||
'rule' => 'alphaNumeric',
|
||||
'required' => true,
|
||||
),
|
||||
'body' => array(
|
||||
'rule' => 'alphaNumeric',
|
||||
'required' => true,
|
||||
'allowEmpty' => true,
|
||||
),
|
||||
);
|
||||
$result = $Something->saveAll($invalidData, array(
|
||||
'atomic' => false,
|
||||
'validate' => 'first',
|
||||
));
|
||||
$expected = array(true, false);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$Something =& new Something();
|
||||
$validData = array(
|
||||
array(
|
||||
'title' => 'title value',
|
||||
'body' => 'body value',
|
||||
'published' => 'baz',
|
||||
),
|
||||
array(
|
||||
'title' => 'valid',
|
||||
'body' => 'this body',
|
||||
'published' =>'sd',
|
||||
),
|
||||
);
|
||||
$Something->create();
|
||||
$result = $Something->saveAll($validData, array(
|
||||
'atomic' => false,
|
||||
'validate' => 'first',
|
||||
));
|
||||
$expected = array(true, true);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* testUpdateWithCalculation method
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue