Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding test case from '0x20h'. Fixing issue where atomic = false, val…

…idate = first and saveAll() saving many rows could return an incorrect value. Fixes #1050
  • Loading branch information...
commit b02e21395834a59f7df5848a1f352f39da696c4c 1 parent ea9e308
@markstory markstory authored
View
2  cake/libs/model/model.php
@@ -1593,6 +1593,7 @@ function saveAll($data = null, $options = array()) {
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 @@ function saveAll($data = null, $options = array()) {
break;
case ($options['validate'] === 'first'):
$options['validate'] = true;
- $return = array();
break;
default:
if ($options['atomic']) {
View
59 cake/tests/cases/libs/model/model_write.test.php
@@ -3585,6 +3585,65 @@ function testSaveAllValidateFirst() {
}
/**
+ * 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
*
* @access public
Please sign in to comment.
Something went wrong with that request. Please try again.