Skip to content

Instantly share code, notes, and snippets.

@ceeram
Created October 2, 2012 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ceeram/3823928 to your computer and use it in GitHub Desktop.
Save ceeram/3823928 to your computer and use it in GitHub Desktop.
ModelSaveAllTest.php
<?php
/**
* ModelWriteTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.Model
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
require_once dirname(__FILE__) . DS . 'ModelTestBase.php';
/**
* ModelWriteTest
*
* @package Cake.Test.Case.Model
*/
class ModelSaveAllTest extends BaseModelTest {
/**
*
*/
public function testSaveAllValidateFirstHasMany() {
$this->loadFixtures(
'Article',
'Comment',
'User'
);
$TestModel = new Article();
$data = array(
'Article' => array(
'title' => 'tecknix',
'body' => 'tecknix article',
'user_id' => 1,
'published' => 'N'
),
'Comment' => array(
array('title' => 'first article', 'body' => 'first body'),
array('title' => 'second article', 'body' => 'second body'),
array('title' => 'third article', 'body' => 'third body')
)
);
$TestModel->beforeSaveReturn = false;
$result = $TestModel->saveAssociated($data, array('validate' => 'first'));
$this->assertFalse($result);
$first = $TestModel->data;
$result = $TestModel->saveAssociated($data, array('validate' => true));
$this->assertFalse($result);
$true = $TestModel->data;
unset($first['Article']['created'], $first['Article']['updated'], $true['Article']['created'], $true['Article']['updated']);
$this->assertEquals($first, $true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment