From aaca183da18ac4c150468287141f8c30ceafc37c Mon Sep 17 00:00:00 2001 From: "mariano.iglesias" Date: Mon, 22 Oct 2007 20:20:48 +0000 Subject: [PATCH] Adding test case for #3430, where different belongsTo bindings that use same class but different alias name in various models would break under certain circumstances git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5865 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/tests/cases/libs/model/model.test.php | 70 ++++++++++++++++++- cake/tests/fixtures/device_fixture.php | 49 +++++++++++++ .../fixtures/device_type_category_fixture.php | 45 ++++++++++++ cake/tests/fixtures/device_type_fixture.php | 52 ++++++++++++++ .../fixtures/document_directory_fixture.php | 45 ++++++++++++ cake/tests/fixtures/document_fixture.php | 46 ++++++++++++ .../exterior_type_category_fixture.php | 46 ++++++++++++ cake/tests/fixtures/feature_set_fixture.php | 45 ++++++++++++ 8 files changed, 397 insertions(+), 1 deletion(-) create mode 100644 cake/tests/fixtures/device_fixture.php create mode 100644 cake/tests/fixtures/device_type_category_fixture.php create mode 100644 cake/tests/fixtures/device_type_fixture.php create mode 100644 cake/tests/fixtures/document_directory_fixture.php create mode 100644 cake/tests/fixtures/document_fixture.php create mode 100644 cake/tests/fixtures/exterior_type_category_fixture.php create mode 100644 cake/tests/fixtures/feature_set_fixture.php diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 6c8b38bf3..cdb181dc1 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -399,6 +399,36 @@ class Syfile extends CakeTestModel { class Image extends CakeTestModel { var $name = 'Image'; } +class DeviceType extends CakeTestModel { + var $name = 'DeviceType'; + var $order = array('DeviceType.order' => 'ASC'); + var $belongsTo = array( + 'DeviceTypeCategory', 'FeatureSet', 'ExteriorTypeCategory', + 'Image' => array('className' => 'Document'), + 'Extra1' => array('className' => 'Document'), + 'Extra2' => array('className' => 'Document')); + var $hasMany = array('Device' => array('order' => array('Device.typ' => 'ASC'))); +} +class DeviceTypeCategory extends CakeTestModel { + var $name = 'DeviceTypeCategory'; +} +class FeatureSet extends CakeTestModel { + var $name = 'FeatureSet'; +} +class ExteriorTypeCategory extends CakeTestModel { + var $name = 'ExteriorTypeCategory'; + var $belongsTo = array('Image' => array('className' => 'Device')); +} +class Document extends CakeTestModel { + var $name = 'Document'; + var $belongsTo = array('DocumentDirectory'); +} +class Device extends CakeTestModel { + var $name = 'Device'; +} +class DocumentDirectory extends CakeTestModel { + var $name = 'DocumentDirectory'; +} /** * Short description for class. * @@ -411,7 +441,9 @@ class ModelTest extends CakeTestCase { 'core.article_featured', 'core.articles', 'core.tag', 'core.articles_tag', 'core.comment', 'core.attachment', '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.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' + ); function start() { parent::start(); @@ -424,6 +456,42 @@ class ModelTest extends CakeTestCase { Configure::write('debug', $this->debug); } + function testMultipleBelongsToWithSameClass() { + $this->DeviceType =& new DeviceType(); + + $this->DeviceType->recursive = 2; + $result = $this->DeviceType->read(null, 1); + $expected = array( + 'DeviceType' => array( + 'id' => 1, 'device_type_category_id' => 1, 'feature_set_id' => 1, 'exterior_type_category_id' => 1, 'image_id' => 1, + 'extra1_id' => 1, 'extra2_id' => 1, 'name' => 'DeviceType 1', 'order' => 0 + ), + 'Image' => array('id' => 1, 'document_directory_id' => 1, 'name' => 'Document 1'), + 'Extra1' => array( + 'id' => 1, 'document_directory_id' => 1, 'name' => 'Document 1', + 'DocumentDirectory' => array('id' => 1, 'name' => 'DocumentDirectory 1') + ), + 'Extra2' => array( + 'id' => 1, 'document_directory_id' => 1, 'name' => 'Document 1', + 'DocumentDirectory' => array('id' => 1, 'name' => 'DocumentDirectory 1') + ), + 'DeviceTypeCategory' => array('id' => 1, 'name' => 'DeviceTypeCategory 1'), + 'FeatureSet' => array('id' => 1, 'name' => 'FeatureSet 1'), + 'ExteriorTypeCategory' => array( + 'id' => 1, 'image_id' => 1, 'name' => 'ExteriorTypeCategory 1', + 'Image' => array('id' => 1, 'device_type_id' => 1, 'name' => 'Device 1', 'typ' => 1) + ), + 'Device' => array( + array('id' => 1, 'device_type_id' => 1, 'name' => 'Device 1', 'typ' => 1), + array('id' => 2, 'device_type_id' => 1, 'name' => 'Device 2', 'typ' => 1), + array('id' => 3, 'device_type_id' => 1, 'name' => 'Device 3', 'typ' => 2) + ) + ); + $this->assertEqual($result, $expected); + + unset($this->DeviceType); + } + function testHabtmRecursiveBelongsTo() { $this->Portfolio =& new Portfolio(); diff --git a/cake/tests/fixtures/device_fixture.php b/cake/tests/fixtures/device_fixture.php new file mode 100644 index 000000000..769beeb58 --- /dev/null +++ b/cake/tests/fixtures/device_fixture.php @@ -0,0 +1,49 @@ + + * 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 DeviceFixture extends CakeTestFixture { + var $name = 'Device'; + var $fields = array( + 'id' => array('type' => 'integer', 'key' => 'primary', 'extra'=> 'auto_increment'), + 'device_type_id' => array('type' => 'integer', 'null' => false), + 'name' => array('type' => 'string', 'null' => false), + 'typ' => array('type' => 'integer', 'null' => false), + ); + var $records = array( + array('id' => 1, 'device_type_id' => 1, 'name' => 'Device 1', 'typ' => 1), + array('id' => 2, 'device_type_id' => 1, 'name' => 'Device 2', 'typ' => 1), + array('id' => 3, 'device_type_id' => 1, 'name' => 'Device 3', 'typ' => 2) + ); +} +?> \ No newline at end of file diff --git a/cake/tests/fixtures/device_type_category_fixture.php b/cake/tests/fixtures/device_type_category_fixture.php new file mode 100644 index 000000000..6d229b9e0 --- /dev/null +++ b/cake/tests/fixtures/device_type_category_fixture.php @@ -0,0 +1,45 @@ + + * 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 DeviceTypeCategoryFixture extends CakeTestFixture { + var $name = 'DeviceTypeCategory'; + var $fields = array( + 'id' => array('type' => 'integer', 'key' => 'primary', 'extra'=> 'auto_increment'), + 'name' => array('type' => 'string', 'null' => false) + ); + var $records = array( + array('id' => 1, 'name' => 'DeviceTypeCategory 1') + ); +} +?> \ No newline at end of file diff --git a/cake/tests/fixtures/device_type_fixture.php b/cake/tests/fixtures/device_type_fixture.php new file mode 100644 index 000000000..321bfe68f --- /dev/null +++ b/cake/tests/fixtures/device_type_fixture.php @@ -0,0 +1,52 @@ + + * 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 DeviceTypeFixture extends CakeTestFixture { + var $name = 'DeviceType'; + var $fields = array( + 'id' => array('type' => 'integer', 'key' => 'primary', 'extra'=> 'auto_increment'), + 'device_type_category_id' => array('type' => 'integer', 'null' => false), + 'feature_set_id' => array('type' => 'integer', 'null' => false), + 'exterior_type_category_id' => array('type' => 'integer', 'null' => false), + 'image_id' => array('type' => 'integer', 'null' => false), + 'extra1_id' => array('type' => 'integer', 'null' => false), + 'extra2_id' => array('type' => 'integer', 'null' => false), + 'name' => array('type' => 'string', 'null' => false), + 'order' => array('type' => 'integer', 'null' => false) + ); + var $records = array( + array('id' => 1, 'device_type_category_id' => 1, 'feature_set_id' => 1, 'exterior_type_category_id' => 1, 'image_id' => 1, 'extra1_id' => 1, 'extra2_id' => 1, 'name' => 'DeviceType 1', 'order' => 0) + ); +} +?> \ No newline at end of file diff --git a/cake/tests/fixtures/document_directory_fixture.php b/cake/tests/fixtures/document_directory_fixture.php new file mode 100644 index 000000000..9c8c4617e --- /dev/null +++ b/cake/tests/fixtures/document_directory_fixture.php @@ -0,0 +1,45 @@ + + * 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 DocumentDirectoryFixture extends CakeTestFixture { + var $name = 'DocumentDirectory'; + var $fields = array( + 'id' => array('type' => 'integer', 'key' => 'primary', 'extra'=> 'auto_increment'), + 'name' => array('type' => 'string', 'null' => false) + ); + var $records = array( + array('id' => 1, 'name' => 'DocumentDirectory 1') + ); +} +?> \ No newline at end of file diff --git a/cake/tests/fixtures/document_fixture.php b/cake/tests/fixtures/document_fixture.php new file mode 100644 index 000000000..bbd5b7f4b --- /dev/null +++ b/cake/tests/fixtures/document_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 DocumentFixture extends CakeTestFixture { + var $name = 'Document'; + var $fields = array( + 'id' => array('type' => 'integer', 'key' => 'primary', 'extra'=> 'auto_increment'), + 'document_directory_id' => array('type' => 'integer', 'null' => false), + 'name' => array('type' => 'string', 'null' => false) + ); + var $records = array( + array('id' => 1, 'document_directory_id' => 1, 'name' => 'Document 1') + ); +} +?> \ No newline at end of file diff --git a/cake/tests/fixtures/exterior_type_category_fixture.php b/cake/tests/fixtures/exterior_type_category_fixture.php new file mode 100644 index 000000000..6775b1b5d --- /dev/null +++ b/cake/tests/fixtures/exterior_type_category_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 ExteriorTypeCategoryFixture extends CakeTestFixture { + var $name = 'ExteriorTypeCategory'; + var $fields = array( + 'id' => array('type' => 'integer', 'key' => 'primary', 'extra'=> 'auto_increment'), + 'image_id' => array('type' => 'integer', 'null' => false), + 'name' => array('type' => 'string', 'null' => false) + ); + var $records = array( + array('id' => 1, 'image_id' => 1, 'name' => 'ExteriorTypeCategory 1') + ); +} +?> \ No newline at end of file diff --git a/cake/tests/fixtures/feature_set_fixture.php b/cake/tests/fixtures/feature_set_fixture.php new file mode 100644 index 000000000..ebd196580 --- /dev/null +++ b/cake/tests/fixtures/feature_set_fixture.php @@ -0,0 +1,45 @@ + + * 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 FeatureSetFixture extends CakeTestFixture { + var $name = 'FeatureSet'; + var $fields = array( + 'id' => array('type' => 'integer', 'key' => 'primary', 'extra'=> 'auto_increment'), + 'name' => array('type' => 'string', 'null' => false) + ); + var $records = array( + array('id' => 1, 'name' => 'FeatureSet 1') + ); +} +?> \ No newline at end of file