From 1e2ac0b9c8f8b00e322242bb24dca9e546d59fba Mon Sep 17 00:00:00 2001 From: euromark Date: Thu, 11 Oct 2012 14:03:59 +0200 Subject: [PATCH] comp mod for saveAll() better approach test case to assert saveAll still behaves like previous versions --- lib/Cake/Model/Model.php | 2 +- lib/Cake/Test/Case/Model/ModelWriteTest.php | 28 ++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 9dd82b6b5d6..101fac91f74 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -2017,7 +2017,7 @@ protected function _prepareUpdateFields($data) { * @link http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-saveassociated-array-data-null-array-options-array * @link http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-saveall-array-data-null-array-options-array */ - public function saveAll($data, $options = array()) { + public function saveAll($data = array(), $options = array()) { $options = array_merge(array('validate' => 'first'), $options); if (Hash::numeric(array_keys($data))) { if ($options['validate'] === 'only') { diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index 31327e7deec..c7976412ece 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -4725,6 +4725,32 @@ public function testSaveAllHasManyValidationOnly() { $this->assertEquals($expected, $TestModel->Comment->validationErrors); } +/** + * test that saveAll still behaves like previous versions (does not necessarily need a first argument) + * + * @return void + */ + public function testSaveAllWithSet() { + $this->loadFixtures('Article', 'Tag', 'Comment', 'User', 'ArticlesTag'); + $data = array( + 'Article' => array( + 'user_id' => 1, + 'title' => 'Article Has and belongs to Many Tags' + ), + 'Tag' => array( + 'Tag' => array(1, 2) + ), + 'Comment' => array( + array( + 'comment' => 'Article comment', + 'user_id' => 1 + ))); + $Article = new Article(); + $Article->set($data); + $result = $Article->saveAll(); + $this->assertFalse(empty($result)); + } + /** * test that saveAll behaves like plain save() when supplied empty data * @@ -4740,7 +4766,7 @@ public function testSaveAllEmptyData() { $this->assertFalse(empty($result)); $model = new ProductUpdateAll(); - $result = $model->saveAll(array()); + $result = $model->saveAll(); $this->assertFalse($result); }