File tree Expand file tree Collapse file tree 2 files changed +60
-1
lines changed Expand file tree Collapse file tree 2 files changed +60
-1
lines changed Original file line number Diff line number Diff line change @@ -1593,6 +1593,7 @@ function saveAll($data = null, $options = array()) {
1593
1593
1594
1594
if (Set::numeric (array_keys ($ data ))) {
1595
1595
while ($ validates ) {
1596
+ $ return = array ();
1596
1597
foreach ($ data as $ key => $ record ) {
1597
1598
if (!$ currentValidates = $ this ->__save ($ record , $ options )) {
1598
1599
$ validationErrors [$ key ] = $ this ->validationErrors ;
@@ -1624,7 +1625,6 @@ function saveAll($data = null, $options = array()) {
1624
1625
break ;
1625
1626
case ($ options ['validate ' ] === 'first ' ):
1626
1627
$ options ['validate ' ] = true ;
1627
- $ return = array ();
1628
1628
break ;
1629
1629
default :
1630
1630
if ($ options ['atomic ' ]) {
Original file line number Diff line number Diff line change @@ -3584,6 +3584,65 @@ function testSaveAllValidateFirst() {
3584
3584
$ this ->assertEqual ($ result [0 ]['Comment ' ][0 ]['comment ' ], 'Only new comment ' );
3585
3585
}
3586
3586
3587
+ /**
3588
+ * test saveAll()'s return is correct when using atomic = false and validate = first.
3589
+ *
3590
+ * @return void
3591
+ */
3592
+ function testSaveAllValidateFirstAtomicFalse () {
3593
+ $ Something =& new Something ();
3594
+ $ invalidData = array (
3595
+ array (
3596
+ 'title ' => 'foo ' ,
3597
+ 'body ' => 'bar ' ,
3598
+ 'published ' => 'baz ' ,
3599
+ ),
3600
+ array (
3601
+ 'body ' => 3 ,
3602
+ 'published ' =>'sd ' ,
3603
+ ),
3604
+ );
3605
+ $ Something ->create ();
3606
+ $ Something ->validate = array (
3607
+ 'title ' => array (
3608
+ 'rule ' => 'alphaNumeric ' ,
3609
+ 'required ' => true ,
3610
+ ),
3611
+ 'body ' => array (
3612
+ 'rule ' => 'alphaNumeric ' ,
3613
+ 'required ' => true ,
3614
+ 'allowEmpty ' => true ,
3615
+ ),
3616
+ );
3617
+ $ result = $ Something ->saveAll ($ invalidData , array (
3618
+ 'atomic ' => false ,
3619
+ 'validate ' => 'first ' ,
3620
+ ));
3621
+ $ expected = array (true , false );
3622
+ $ this ->assertEqual ($ result , $ expected );
3623
+
3624
+ $ Something =& new Something ();
3625
+ $ validData = array (
3626
+ array (
3627
+ 'title ' => 'title value ' ,
3628
+ 'body ' => 'body value ' ,
3629
+ 'published ' => 'baz ' ,
3630
+ ),
3631
+ array (
3632
+ 'title ' => 'valid ' ,
3633
+ 'body ' => 'this body ' ,
3634
+ 'published ' =>'sd ' ,
3635
+ ),
3636
+ );
3637
+ $ Something ->create ();
3638
+ $ result = $ Something ->saveAll ($ validData , array (
3639
+ 'atomic ' => false ,
3640
+ 'validate ' => 'first ' ,
3641
+ ));
3642
+ $ expected = array (true , true );
3643
+ $ this ->assertEqual ($ result , $ expected );
3644
+ }
3645
+
3587
3646
/**
3588
3647
* testUpdateWithCalculation method
3589
3648
*
You can’t perform that action at this time.
0 commit comments