Adding new failing test case to showcase problem with HABTM and belongsTo

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5630 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mariano.iglesias 2007-09-11 21:00:58 +00:00
parent 7c6edeb33d
commit d05a5d4804
6 changed files with 320 additions and 2 deletions

View file

@ -419,6 +419,22 @@ class ModelC extends CakeTestModel {
class ModelD extends CakeTestModel {
var $useTable = 'threads';
}
class Portfolio extends CakeTestModel {
var $name = 'Portfolio';
var $hasAndBelongsToMany = array('Item');
}
class Item extends CakeTestModel {
var $name = 'Item';
var $belongsTo = array('Syfile');
var $hasAndBelongsToMany = array('Portfolio');
}
class Syfile extends CakeTestModel {
var $name = 'Syfile';
var $belongsTo = array('Image');
}
class Image extends CakeTestModel {
var $name = 'Image';
}
/**
* Short description for class.
*
@ -426,12 +442,12 @@ class ModelD extends CakeTestModel {
* @subpackage cake.tests.cases.libs.model
*/
class ModelTest extends CakeTestCase {
var $fixtures = array(
'core.category', 'core.category_thread', 'core.user', 'core.article', 'core.featured', 'core.article_featureds_tags',
'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.project', 'core.thread', 'core.message', 'core.bid',
'core.portfolio', 'core.item', 'core.items_portfolio', 'core.syfile', 'core.image'
);
function start() {
@ -445,6 +461,58 @@ class ModelTest extends CakeTestCase {
Configure::write('debug', $this->debug);
}
function testHabtmRecursiveBelongsTo() {
$this->Portfolio =& new Portfolio();
$result = $this->Portfolio->find(array('id' => 2), null, null, 3);
$expected = array(
'Portfolio' => array(
'id' => 2,
'seller_id' => 1,
'name' => 'Portfolio 2'
),
'Item' => array(
array(
'id' => 2,
'syfile_id' => 2,
'name' => 'Item 2',
'ItemsPortfolio' => array(
'id' => 2,
'item_id' => 2,
'portfolio_id' => 2
),
'Syfile' => array(
'id' => 2,
'image_id' => 2,
'name' => 'Syfile 2',
'Image' => array(
'id' => 2,
'name' => 'Image 2'
)
)
),
array(
'id' => 6,
'syfile_id' => 6,
'name' => 'Item 6',
'ItemsPortfolio' => array(
'id' => 6,
'item_id' => 6,
'portfolio_id' => 2
),
'Syfile' => array(
'id' => 2,
'image_id' => null,
'name' => 'Syfile 2',
'Image' => array()
)
)
)
);
$this->assertEqual($result, $expected);
unset($this->Portfolio);
}
function testHasManyOptimization() {
$this->Project =& new Project();

49
cake/tests/fixtures/image_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 ImageFixture extends CakeTestFixture {
var $name = 'Image';
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' => 'Image 1'),
array ('id' => 2, 'name' => 'Image 2'),
array ('id' => 3, 'name' => 'Image 3'),
array ('id' => 4, 'name' => 'Image 4'),
array ('id' => 5, 'name' => 'Image 5')
);
}
?>

51
cake/tests/fixtures/item_fixture.php vendored Normal file
View file

@ -0,0 +1,51 @@
<?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 ItemFixture extends CakeTestFixture {
var $name = 'Item';
var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary', 'extra'=> 'auto_increment'),
'syfile_id' => array('type' => 'integer', 'null' => false),
'name' => array('type' => 'string', 'null' => false)
);
var $records = array(
array ('id' => 1, 'syfile_id' => 1, 'name' => 'Item 1'),
array ('id' => 2, 'syfile_id' => 2, 'name' => 'Item 2'),
array ('id' => 3, 'syfile_id' => 3, 'name' => 'Item 3'),
array ('id' => 4, 'syfile_id' => 4, 'name' => 'Item 4'),
array ('id' => 5, 'syfile_id' => 5, 'name' => 'Item 5'),
array ('id' => 6, 'syfile_id' => 6, 'name' => 'Item 6')
);
}
?>

View file

@ -0,0 +1,51 @@
<?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 ItemsPortfolioFixture extends CakeTestFixture {
var $name = 'ItemsPortfolio';
var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary', 'extra'=> 'auto_increment'),
'item_id' => array('type' => 'integer', 'null' => false),
'portfolio_id' => array('type' => 'integer', 'null' => false)
);
var $records = array(
array ('id' => 1, 'item_id' => 1, 'portfolio_id' => 1),
array ('id' => 2, 'item_id' => 2, 'portfolio_id' => 2),
array ('id' => 3, 'item_id' => 3, 'portfolio_id' => 1),
array ('id' => 4, 'item_id' => 4, 'portfolio_id' => 1),
array ('id' => 5, 'item_id' => 5, 'portfolio_id' => 1),
array ('id' => 6, 'item_id' => 6, 'portfolio_id' => 2)
);
}
?>

View file

@ -0,0 +1,48 @@
<?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 PortfolioFixture extends CakeTestFixture {
var $name = 'Portfolio';
var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary', 'extra'=> 'auto_increment'),
'seller_id' => array('type' => 'integer', 'null' => false),
'name' => array('type' => 'string', 'null' => false)
);
var $records = array(
array ('id' => 1, 'seller_id' => 1, 'name' => 'Portfolio 1'),
array ('id' => 2, 'seller_id' => 1, 'name' => 'Portfolio 2'),
array ('id' => 3, 'seller_id' => 2, 'name' => 'Portfolio 1')
);
}
?>

51
cake/tests/fixtures/syfile_fixture.php vendored Normal file
View file

@ -0,0 +1,51 @@
<?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 SyfileFixture extends CakeTestFixture {
var $name = 'Syfile';
var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary', 'extra'=> 'auto_increment'),
'image_id' => array('type' => 'integer', 'null' => true),
'name' => array('type' => 'string', 'null' => false)
);
var $records = array(
array ('id' => 1, 'image_id' => 1, 'name' => 'Syfile 1'),
array ('id' => 2, 'image_id' => 2, 'name' => 'Syfile 2'),
array ('id' => 3, 'image_id' => 5, 'name' => 'Syfile 3'),
array ('id' => 4, 'image_id' => 3, 'name' => 'Syfile 4'),
array ('id' => 5, 'image_id' => 4, 'name' => 'Syfile 5'),
array ('id' => 6, 'image_id' => null, 'name' => 'Syfile 6')
);
}
?>