From 6591c8f79b3a7b9f5a100b3e519b9c4fad63ae2c Mon Sep 17 00:00:00 2001 From: "mariano.iglesias" Date: Wed, 24 Oct 2007 16:29:50 +0000 Subject: [PATCH] Adding test for #3455 replicating issue, Secondary model array in model data causes corruption git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5892 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/tests/cases/libs/model/model.test.php | 32 ++++++++++++- cake/tests/fixtures/primary_model_fixture.php | 46 +++++++++++++++++++ .../fixtures/secondary_model_fixture.php | 46 +++++++++++++++++++ 3 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 cake/tests/fixtures/primary_model_fixture.php create mode 100644 cake/tests/fixtures/secondary_model_fixture.php diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index a60f50f60..bca6b779b 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -434,6 +434,12 @@ class Device extends CakeTestModel { class DocumentDirectory extends CakeTestModel { var $name = 'DocumentDirectory'; } +class PrimaryModel extends CakeTestModel { + var $name = 'PrimaryModel'; +} +class SecondaryModel extends CakeTestModel { + var $name = 'SecondaryModel'; +} /** * Short description for class. * @@ -447,7 +453,8 @@ class ModelTest extends CakeTestCase { 'core.apple', 'core.sample', 'core.another_article', 'core.advertisement', 'core.home', 'core.post', 'core.author', 'core.project', 'core.thread', 'core.message', 'core.bid', 'core.portfolio', 'core.item', 'core.items_portfolio', 'core.syfile', 'core.image', - 'core.device_type', 'core.device_type_category', 'core.feature_set', 'core.exterior_type_category', 'core.document', 'core.device', 'core.document_directory' + 'core.device_type', 'core.device_type_category', 'core.feature_set', 'core.exterior_type_category', 'core.document', 'core.device', 'core.document_directory', + 'core.primary_model', 'core.secondary_model' ); function start() { @@ -668,6 +675,29 @@ class ModelTest extends CakeTestCase { array('Article' => array('id' => 4, 'title' => 'Brand New Article')))); } + function testCreationWithMultipleDataSameModelManualInstances() { + $Primary =& new PrimaryModel(); + $Secondary =& new PrimaryModel(); + + $result = $Primary->field('primary_name', array('id' => 1)); + $this->assertEqual($result, 'Primary Name Existing'); + + $data = array('PrimaryModel' => array('primary_name' => 'Primary Name New'), + 'SecondaryModel' => array('id' => 1)); + $Primary->create(); + $result = $Primary->save($data); + $this->assertTrue($result); + + $result = $Primary->field('primary_name', array('id' => 1)); + $this->assertEqual($result, 'Primary Name Existing'); + + $result = $Primary->getInsertID(); + $this->assertTrue(!empty($result)); + + $result = $Primary->findCount(); + $this->assertEqual($result, 2); + } + function testReadFakeThread() { $this->model =& new CategoryThread(); diff --git a/cake/tests/fixtures/primary_model_fixture.php b/cake/tests/fixtures/primary_model_fixture.php new file mode 100644 index 000000000..e85f2c591 --- /dev/null +++ b/cake/tests/fixtures/primary_model_fixture.php @@ -0,0 +1,46 @@ + + * Copyright 2005-2007, 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-2007, 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.4667 + * @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 PrimaryModelFixture extends CakeTestFixture { + var $name = 'PrimaryModel'; + var $fields = array( + 'id' => array('type' => 'integer', 'key' => 'primary', 'extra'=> 'auto_increment'), + 'primary_name' => array('type' => 'string', 'null' => false) + ); + var $records = array( + array ('id' => 1, 'title' => 'Primary Name Existing') + ); +} + +?> \ No newline at end of file diff --git a/cake/tests/fixtures/secondary_model_fixture.php b/cake/tests/fixtures/secondary_model_fixture.php new file mode 100644 index 000000000..25c35c505 --- /dev/null +++ b/cake/tests/fixtures/secondary_model_fixture.php @@ -0,0 +1,46 @@ + + * Copyright 2005-2007, 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-2007, 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.4667 + * @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 SecondaryModelFixture extends CakeTestFixture { + var $name = 'SecondaryModel'; + var $fields = array( + 'id' => array('type' => 'integer', 'key' => 'primary', 'extra'=> 'auto_increment'), + 'secondary_name' => array('type' => 'string', 'null' => false) + ); + var $records = array( + array ('id' => 1, 'title' => 'Secondary Name Existing') + ); +} + +?> \ No newline at end of file