mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Closes #4202
Adding patches Added fixture files git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7198 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
01bf6526c4
commit
886183fcd4
6 changed files with 515 additions and 236 deletions
|
@ -1577,13 +1577,16 @@ class Model extends Overloadable {
|
||||||
if ($data['dependent'] === true && $cascade === true) {
|
if ($data['dependent'] === true && $cascade === true) {
|
||||||
|
|
||||||
$model =& $this->{$assoc};
|
$model =& $this->{$assoc};
|
||||||
$field = $model->escapeField($data['foreignKey']);
|
$conditions = array($model->escapeField($data['foreignKey']) => $id);
|
||||||
|
if ($data['conditions']) {
|
||||||
|
$conditions = am($data['conditions'], $conditions);
|
||||||
|
}
|
||||||
$model->recursive = -1;
|
$model->recursive = -1;
|
||||||
|
|
||||||
if (isset($data['exclusive']) && $data['exclusive']) {
|
if (isset($data['exclusive']) && $data['exclusive']) {
|
||||||
$model->deleteAll(array($field => $id));
|
$model->deleteAll($conditions);
|
||||||
} else {
|
} else {
|
||||||
$records = $model->find('all', array('conditions' => array($field => $id), 'fields' => $model->primaryKey));
|
$records = $model->find('all', array('conditions' => $conditions, 'fields' => $model->primaryKey));
|
||||||
|
|
||||||
if (!empty($records)) {
|
if (!empty($records)) {
|
||||||
foreach ($records as $record) {
|
foreach ($records as $record) {
|
||||||
|
|
|
@ -59,8 +59,7 @@ class ModelTest extends CakeTestCase {
|
||||||
'core.document', 'core.device', 'core.document_directory', 'core.primary_model', 'core.secondary_model', 'core.something',
|
'core.document', 'core.device', 'core.document_directory', 'core.primary_model', 'core.secondary_model', 'core.something',
|
||||||
'core.something_else', 'core.join_thing', 'core.join_a', 'core.join_b', 'core.join_c', 'core.join_a_b', 'core.join_a_c',
|
'core.something_else', 'core.join_thing', 'core.join_a', 'core.join_b', 'core.join_c', 'core.join_a_b', 'core.join_a_c',
|
||||||
'core.uuid', 'core.data_test', 'core.posts_tag', 'core.the_paper_monkies', 'core.person', 'core.underscore_field',
|
'core.uuid', 'core.data_test', 'core.posts_tag', 'core.the_paper_monkies', 'core.person', 'core.underscore_field',
|
||||||
'core.node', 'core.dependency',
|
'core.node', 'core.dependency', 'core.story', 'core.stories_tag', 'core.cd', 'core.book', 'core.overall_favorite'
|
||||||
'core.story', 'core.stories_tag'
|
|
||||||
);
|
);
|
||||||
/**
|
/**
|
||||||
* start method
|
* start method
|
||||||
|
@ -4870,6 +4869,26 @@ class ModelTest extends CakeTestCase {
|
||||||
$this->assertEqual($testResult['Article']['created'], '2008-01-01 00:00:00');
|
$this->assertEqual($testResult['Article']['created'], '2008-01-01 00:00:00');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* testDeleteDependentWithConditions method
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testDeleteDependentWithConditions() {
|
||||||
|
$this->loadFixtures('Cd','Book','OverallFavorite');
|
||||||
|
|
||||||
|
$Cd =& new Cd();
|
||||||
|
$OverallFavorite =& new OverallFavorite();
|
||||||
|
|
||||||
|
$Cd->del(1);
|
||||||
|
|
||||||
|
$result = $OverallFavorite->find('all', array('fields' => array('model_type', 'model_id', 'priority')));
|
||||||
|
$expected = array(array('OverallFavorite' => array('model_type' => 'Book', 'model_id' => 1, 'priority' => 2)));
|
||||||
|
|
||||||
|
$this->assertTrue(is_array($result));
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* endTest method
|
* endTest method
|
||||||
*
|
*
|
||||||
|
|
|
@ -1910,4 +1910,63 @@ class Story extends CakeTestModel {
|
||||||
*/
|
*/
|
||||||
var $validate = array('title' => VALID_NOT_EMPTY);
|
var $validate = array('title' => VALID_NOT_EMPTY);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Short description for class.
|
||||||
|
*
|
||||||
|
* @package cake.tests
|
||||||
|
* @subpackage cake.tests.cases.libs.model
|
||||||
|
*/
|
||||||
|
class Cd extends CakeTestModel {
|
||||||
|
/**
|
||||||
|
* name property
|
||||||
|
*
|
||||||
|
* @var string 'Cd'
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $name = 'Cd';
|
||||||
|
/**
|
||||||
|
* hasOne property
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $hasOne = array('OverallFavorite' => array('foreignKey' => 'model_id', 'dependent' => true, 'conditions' => array('model_type' => 'Cd')));
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Short description for class.
|
||||||
|
*
|
||||||
|
* @package cake.tests
|
||||||
|
* @subpackage cake.tests.cases.libs.model
|
||||||
|
*/
|
||||||
|
class Book extends CakeTestModel {
|
||||||
|
/**
|
||||||
|
* name property
|
||||||
|
*
|
||||||
|
* @var string 'Book'
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $name = 'Book';
|
||||||
|
/**
|
||||||
|
* hasOne property
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $hasOne = array('OverallFavorite' => array('foreignKey' => 'model_id', 'dependent' => true, 'conditions' => array('model_type' => 'Book')));
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Short description for class.
|
||||||
|
*
|
||||||
|
* @package cake.tests
|
||||||
|
* @subpackage cake.tests.cases.libs.model
|
||||||
|
*/
|
||||||
|
class OverallFavorite extends CakeTestModel {
|
||||||
|
/**
|
||||||
|
* name property
|
||||||
|
*
|
||||||
|
* @var string 'OverallFavorite'
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $name = 'OverallFavorite';
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|
67
cake/tests/fixtures/book_fixture.php
vendored
Normal file
67
cake/tests/fixtures/book_fixture.php
vendored
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
<?php
|
||||||
|
/* SVN FILE: $Id$ */
|
||||||
|
/**
|
||||||
|
* Short description for file.
|
||||||
|
*
|
||||||
|
* Long description for file
|
||||||
|
*
|
||||||
|
* PHP versions 4 and 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
||||||
|
* Copyright 2005-2008, Cake Software Foundation, Inc.
|
||||||
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
|
* Las Vegas, Nevada 89104
|
||||||
|
*
|
||||||
|
* Licensed under The Open Group Test Suite License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @filesource
|
||||||
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
|
||||||
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
||||||
|
* @package cake.tests
|
||||||
|
* @subpackage cake.tests.fixtures
|
||||||
|
* @since CakePHP(tm) v 1.2.0.7198
|
||||||
|
* @version $Revision$
|
||||||
|
* @modifiedby $LastChangedBy$
|
||||||
|
* @lastmodified $Date$
|
||||||
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Short description for class.
|
||||||
|
*
|
||||||
|
* @package cake.tests
|
||||||
|
* @subpackage cake.tests.fixtures
|
||||||
|
*/
|
||||||
|
class BookFixture extends CakeTestFixture {
|
||||||
|
/**
|
||||||
|
* name property
|
||||||
|
*
|
||||||
|
* @var string 'Book'
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $name = 'Book';
|
||||||
|
/**
|
||||||
|
* fields property
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $fields = array(
|
||||||
|
'id' => array('type' => 'integer', 'key' => 'primary'),
|
||||||
|
'isbn' => array('type' => 'string', 'length' => 13),
|
||||||
|
'title' => array('type' => 'string', 'length' => 255),
|
||||||
|
'author' => array('type' => 'string', 'length' => 255),
|
||||||
|
'year' => array('type' => 'integer', 'null' => true),
|
||||||
|
'pages' => array('type' => 'integer', 'null' => true)
|
||||||
|
);
|
||||||
|
/**
|
||||||
|
* records property
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $records = array(
|
||||||
|
array('id' => 1, 'isbn' => '1234567890', 'title' => 'Faust', 'author' => 'Johann Wolfgang von Goethe')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
?>
|
65
cake/tests/fixtures/cd_fixture.php
vendored
Normal file
65
cake/tests/fixtures/cd_fixture.php
vendored
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
<?php
|
||||||
|
/* SVN FILE: $Id$ */
|
||||||
|
/**
|
||||||
|
* Short description for file.
|
||||||
|
*
|
||||||
|
* Long description for file
|
||||||
|
*
|
||||||
|
* PHP versions 4 and 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
||||||
|
* Copyright 2005-2008, Cake Software Foundation, Inc.
|
||||||
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
|
* Las Vegas, Nevada 89104
|
||||||
|
*
|
||||||
|
* Licensed under The Open Group Test Suite License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @filesource
|
||||||
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
|
||||||
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
||||||
|
* @package cake.tests
|
||||||
|
* @subpackage cake.tests.fixtures
|
||||||
|
* @since CakePHP(tm) v 1.2.0.7198
|
||||||
|
* @version $Revision$
|
||||||
|
* @modifiedby $LastChangedBy$
|
||||||
|
* @lastmodified $Date$
|
||||||
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Short description for class.
|
||||||
|
*
|
||||||
|
* @package cake.tests
|
||||||
|
* @subpackage cake.tests.fixtures
|
||||||
|
*/
|
||||||
|
class CdFixture extends CakeTestFixture {
|
||||||
|
/**
|
||||||
|
* name property
|
||||||
|
*
|
||||||
|
* @var string 'Cd'
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $name = 'Cd';
|
||||||
|
/**
|
||||||
|
* fields property
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $fields = array(
|
||||||
|
'id' => array('type' => 'integer', 'key' => 'primary'),
|
||||||
|
'title' => array('type' => 'string', 'length' => 255),
|
||||||
|
'artist' => array('type' => 'string', 'length' => 255, 'null' => true),
|
||||||
|
'genre' => array('type' => 'string', 'length' => 255, 'null' => true)
|
||||||
|
);
|
||||||
|
/**
|
||||||
|
* records property
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $records = array(
|
||||||
|
array('id' => 1, 'title' => 'Grace', 'artist' => 'Jeff Buckley', 'genre' => 'awesome')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
?>
|
66
cake/tests/fixtures/overall_favorite_fixture.php
vendored
Normal file
66
cake/tests/fixtures/overall_favorite_fixture.php
vendored
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
<?php
|
||||||
|
/* SVN FILE: $Id$ */
|
||||||
|
/**
|
||||||
|
* Short description for file.
|
||||||
|
*
|
||||||
|
* Long description for file
|
||||||
|
*
|
||||||
|
* PHP versions 4 and 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
||||||
|
* Copyright 2005-2008, Cake Software Foundation, Inc.
|
||||||
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
|
* Las Vegas, Nevada 89104
|
||||||
|
*
|
||||||
|
* Licensed under The Open Group Test Suite License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @filesource
|
||||||
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
|
||||||
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
||||||
|
* @package cake.tests
|
||||||
|
* @subpackage cake.tests.fixtures
|
||||||
|
* @since CakePHP(tm) v 1.2.0.7198
|
||||||
|
* @version $Revision$
|
||||||
|
* @modifiedby $LastChangedBy$
|
||||||
|
* @lastmodified $Date$
|
||||||
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Short description for class.
|
||||||
|
*
|
||||||
|
* @package cake.tests
|
||||||
|
* @subpackage cake.tests.fixtures
|
||||||
|
*/
|
||||||
|
class OverallFavoriteFixture extends CakeTestFixture {
|
||||||
|
/**
|
||||||
|
* name property
|
||||||
|
*
|
||||||
|
* @var string 'OverallFavorite'
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $name = 'OverallFavorite';
|
||||||
|
/**
|
||||||
|
* fields property
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $fields = array(
|
||||||
|
'id' => array('type' => 'integer', 'key' => 'primary'),
|
||||||
|
'model_type' => array('type' => 'string', 'length' => 255),
|
||||||
|
'model_id' => array('type' => 'integer'),
|
||||||
|
'priority' => array('type' => 'integer')
|
||||||
|
);
|
||||||
|
/**
|
||||||
|
* records property
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $records = array(
|
||||||
|
array('id' => 1, 'model_type' => 'Cd', 'model_id' => '1', 'priority' => '1'),
|
||||||
|
array('id' => 2, 'model_type' => 'Book', 'model_id' => '1', 'priority' => '2')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
?>
|
Loading…
Reference in a new issue