adding test for #4861

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7237 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
DarkAngelBGE 2008-06-22 15:18:30 +00:00
parent ca0fa7b796
commit 8b9aa057dd
8 changed files with 506 additions and 2 deletions

View file

@ -51,7 +51,8 @@ class ModelTest extends CakeTestCase {
* @access public * @access public
*/ */
var $fixtures = array( var $fixtures = array(
'core.category', 'core.category_thread', 'core.user', 'core.article', 'core.featured', 'core.article_featureds_tags', 'core.category', 'core.category_thread', 'core.user', 'core.my_category', 'core.my_product', 'core.my_user', 'core.my_categories_my_users',
'core.my_categories_my_products', 'core.article', 'core.featured', 'core.article_featureds_tags',
'core.article_featured', 'core.articles', 'core.numeric_article', 'core.tag', 'core.articles_tag', 'core.comment', 'core.attachment', 'core.article_featured', 'core.articles', 'core.numeric_article', '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.apple', 'core.sample', 'core.another_article', 'core.advertisement', 'core.home', 'core.post', 'core.author',
'core.product', 'core.project', 'core.thread', 'core.message', 'core.bid', 'core.portfolio', 'core.item', 'core.items_portfolio', 'core.product', 'core.project', 'core.thread', 'core.message', 'core.bid', 'core.portfolio', 'core.item', 'core.items_portfolio',
@ -520,6 +521,82 @@ class ModelTest extends CakeTestCase {
} }
/** /**
* testFindAllRecursiveWithHabtm method
*
* @return void
* @access public
*/
function testFindAllRecursiveWithHabtm() {
$this->loadFixtures('MyCategoriesMyUsers', 'MyCategoriesMyProducts', 'MyCategory', 'MyUser', 'MyProduct');
$MyUser =& new MyUser();
$MyUser->recursive = 2;
$result = $MyUser->find('all');
$expected = array(
array(
'MyUser' => array(
'id' => '1',
'firstname' => 'userA'
),
'MyCategory' => array(
array(
'id' => '1',
'name' => 'A',
'MyProduct' => array(
array(
'id' => '1',
'name' => 'book'
)
)
),
array(
'id' => '3',
'name' => 'C',
'MyProduct' => array(
array(
'id' => '2',
'name' => 'computer'
),
)
)
)
),
array(
'MyUser' => array(
'id' => '2',
'firstname' => 'userB'
),
'MyCategory' => array(
array(
'id' => '1',
'name' => 'A',
'MyProduct' => array(
array(
'id' => '1',
'name' => 'book'
)
)
),
array(
'id' => '2',
'name' => 'B',
'MyProduct' => array(
array(
'id' => '1',
'name' => 'book'
),
array(
'id' => '2',
'name' => 'computer'
)
)
)
)
)
);
$this->assertIdentical($result, $expected);
}
/**
* testFindSelfAssociations method * testFindSelfAssociations method
* *
* @access public * @access public

View file

@ -1973,4 +1973,100 @@ class OverallFavorite extends CakeTestModel {
*/ */
var $name = 'OverallFavorite'; var $name = 'OverallFavorite';
} }
?> /**
* undocumented class
*
* @package default
* @access public
*/
class MyUser extends CakeTestModel {
/**
* name property
*
* @var string 'MyUser'
* @access public
*/
var $name = 'MyUser';
/**
* undocumented variable
*
* @var string
* @access public
*/
var $hasAndBelongsToMany = array('MyCategory');
}
/**
* undocumented class
*
* @package default
* @access public
*/
class MyCategory extends CakeTestModel {
/**
* name property
*
* @var string 'MyCategory'
* @access public
*/
var $name = 'MyCategory';
/**
* undocumented variable
*
* @var string
* @access public
*/
var $hasAndBelongsToMany = array('MyProduct', 'MyUser');
}
/**
* undocumented class
*
* @package default
* @access public
*/
class MyProduct extends CakeTestModel {
/**
* name property
*
* @var string 'MyProduct'
* @access public
*/
var $name = 'MyProduct';
/**
* undocumented variable
*
* @var string
* @access public
*/
var $hasAndBelongsToMany = array('MyCategory');
}
/**
* undocumented class
*
* @package default
* @access public
*/
class MyCategoriesMyUser extends CakeTestModel {
/**
* name property
*
* @var string 'MyCategoriesMyUser'
* @access public
*/
var $name = 'MyCategoriesMyUser';
}
/**
* undocumented class
*
* @package default
* @access public
*/
class MyCategoriesMyProduct extends CakeTestModel {
/**
* name property
*
* @var string 'MyCategoriesMyProduct'
* @access public
*/
var $name = 'MyCategoriesMyProduct';
}
?>

View 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.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 MyCategoriesMyProductsFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'MyCategoriesMyProducts'
* @access public
*/
var $name = 'MyCategoriesMyProducts';
/**
* fields property
*
* @var array
* @access public
*/
var $fields = array(
'my_category_id' => array('type' => 'integer'),
'my_product_id' => array('type' => 'integer'),
);
/**
* records property
*
* @var array
* @access public
*/
var $records = array(
array('my_category_id' => 1, 'my_product_id' => 1),
array('my_category_id' => 2, 'my_product_id' => 1),
array('my_category_id' => 2, 'my_product_id' => 2),
array('my_category_id' => 3, 'my_product_id' => 2),
);
}
?>

View 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.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 MyCategoriesMyUsersFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'MyCategoriesMyUsers'
* @access public
*/
var $name = 'MyCategoriesMyUsers';
/**
* fields property
*
* @var array
* @access public
*/
var $fields = array(
'my_category_id' => array('type' => 'integer'),
'my_user_id' => array('type' => 'integer'),
);
/**
* records property
*
* @var array
* @access public
*/
var $records = array(
array('my_category_id' => 1, 'my_user_id' => 1),
array('my_category_id' => 3, 'my_user_id' => 1),
array('my_category_id' => 1, 'my_user_id' => 2),
array('my_category_id' => 2, 'my_user_id' => 2),
);
}
?>

View 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.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 MyCategoryFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'MyCategory'
* @access public
*/
var $name = 'MyCategory';
/**
* fields property
*
* @var array
* @access public
*/
var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'name' => array('type' => 'string', 'null' => false),
);
/**
* records property
*
* @var array
* @access public
*/
var $records = array(
array('id' => 1, 'name' => 'A'),
array('id' => 2, 'name' => 'B'),
array('id' => 3, 'name' => 'C'),
);
}
?>

View 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.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 MyProductFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'MyProduct'
* @access public
*/
var $name = 'MyProduct';
/**
* fields property
*
* @var array
* @access public
*/
var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'name' => array('type' => 'string', 'null' => false),
);
/**
* records property
*
* @var array
* @access public
*/
var $records = array(
array('id' => 1, 'name' => 'book'),
array('id' => 2, 'name' => 'computer'),
);
}
?>

65
cake/tests/fixtures/my_user_fixture.php vendored Normal file
View 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.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 MyUserFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'MyUser'
* @access public
*/
var $name = 'MyUser';
/**
* fields property
*
* @var array
* @access public
*/
var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'firstname' => array('type' => 'string', 'null' => false),
);
/**
* records property
*
* @var array
* @access public
*/
var $records = array(
array('id' => 1, 'firstname' => 'userA'),
array('id' => 2, 'firstname' => 'userB')
);
}
?>

View file

@ -446,6 +446,7 @@ class CakeTestCase extends UnitTestCase {
foreach ($args as $class) { foreach ($args as $class) {
if (isset($this->_fixtureClassMap[$class])) { if (isset($this->_fixtureClassMap[$class])) {
$fixture = $this->_fixtures[$this->_fixtureClassMap[$class]]; $fixture = $this->_fixtures[$this->_fixtureClassMap[$class]];
$fixture->truncate($this->db); $fixture->truncate($this->db);
$fixture->insert($this->db); $fixture->insert($this->db);
} else { } else {