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
This commit is contained in:
mariano.iglesias 2007-10-22 20:20:48 +00:00
parent 8a64dd33e3
commit aaca183da1
8 changed files with 397 additions and 1 deletions

View file

@ -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();

49
cake/tests/fixtures/device_fixture.php vendored Normal file
View file

@ -0,0 +1,49 @@
<?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-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)
);
}
?>

View file

@ -0,0 +1,45 @@
<?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-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')
);
}
?>

View file

@ -0,0 +1,52 @@
<?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-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)
);
}
?>

View file

@ -0,0 +1,45 @@
<?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-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')
);
}
?>

View file

@ -0,0 +1,46 @@
<?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-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')
);
}
?>

View file

@ -0,0 +1,46 @@
<?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-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')
);
}
?>

View file

@ -0,0 +1,45 @@
<?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-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')
);
}
?>