mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Added test for combination of self joins and belongsTo
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4773 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
a53e15ee51
commit
003e30673e
3 changed files with 400 additions and 1 deletions
|
@ -177,6 +177,35 @@
|
|||
)
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Short description for class.
|
||||
*
|
||||
* @package cake.tests
|
||||
* @subpackage cake.tests.cases.libs.model
|
||||
*/
|
||||
class Apple extends CakeTestModel {
|
||||
var $name = 'Apple';
|
||||
var $validate = array('name' => VALID_NOT_EMPTY);
|
||||
var $hasOne = array('Sample');
|
||||
var $hasMany = array('Child' => array(
|
||||
'className' => 'Apple',
|
||||
'dependent' => true
|
||||
));
|
||||
var $belongsTo = array('Parent' => array(
|
||||
'className' => 'Apple',
|
||||
'foreignKey' => 'apple_id'
|
||||
));
|
||||
}
|
||||
/**
|
||||
* Short description for class.
|
||||
*
|
||||
* @package cake.tests
|
||||
* @subpackage cake.tests.cases.libs.model
|
||||
*/
|
||||
class Sample extends CakeTestModel {
|
||||
var $name = 'Sample';
|
||||
var $belongsTo = 'Apple';
|
||||
}
|
||||
/**
|
||||
* Short description for class.
|
||||
*
|
||||
|
@ -184,7 +213,11 @@
|
|||
* @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_featured', 'core.tag', 'core.articles_tag', 'core.comment', 'core.attachment' );
|
||||
var $fixtures = array(
|
||||
'core.category', 'core.category_thread', 'core.user', 'core.article', 'core.featured',
|
||||
'core.article_featured', 'core.tag', 'core.articles_tag', 'core.comment', 'core.attachment',
|
||||
'core.apple', 'core.sample'
|
||||
);
|
||||
|
||||
function start() {
|
||||
parent::start();
|
||||
|
@ -1081,6 +1114,267 @@ class ModelTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
function testFindCombinedRelations() {
|
||||
$this->model =& new Apple();
|
||||
|
||||
$result = $this->model->findAll();
|
||||
|
||||
$expected = array (
|
||||
array (
|
||||
'Apple' => array (
|
||||
'id' => '1',
|
||||
'apple_id' => '2',
|
||||
'color' => 'Red 1',
|
||||
'name' => 'Red Apple 1',
|
||||
'created' => '2006-11-22 10:38:58',
|
||||
'date' => '1951-01-04',
|
||||
'modified' => '2006-12-01 13:31:26'
|
||||
),
|
||||
'Parent' => array (
|
||||
'id' => '2',
|
||||
'apple_id' => '1',
|
||||
'color' => 'Bright Red 1',
|
||||
'name' => 'Bright Red Apple',
|
||||
'created' => '2006-11-22 10:43:13',
|
||||
'date' => '2014-01-01',
|
||||
'modified' => '2006-11-30 18:38:10'
|
||||
),
|
||||
'Sample' => array (
|
||||
'id' => null,
|
||||
'apple_id' => null,
|
||||
'name' => null
|
||||
),
|
||||
'Child' => array (
|
||||
array (
|
||||
'id' => '2',
|
||||
'apple_id' => '1',
|
||||
'color' => 'Bright Red 1',
|
||||
'name' => 'Bright Red Apple',
|
||||
'created' => '2006-11-22 10:43:13',
|
||||
'date' => '2014-01-01',
|
||||
'modified' => '2006-11-30 18:38:10'
|
||||
)
|
||||
)
|
||||
),
|
||||
array (
|
||||
'Apple' => array (
|
||||
'id' => '2',
|
||||
'apple_id' => '1',
|
||||
'color' => 'Bright Red 1',
|
||||
'name' => 'Bright Red Apple',
|
||||
'created' => '2006-11-22 10:43:13',
|
||||
'date' => '2014-01-01',
|
||||
'modified' => '2006-11-30 18:38:10'
|
||||
),
|
||||
'Parent' => array (
|
||||
'id' => '1',
|
||||
'apple_id' => '2',
|
||||
'color' => 'Red 1',
|
||||
'name' => 'Red Apple 1',
|
||||
'created' => '2006-11-22 10:38:58',
|
||||
'date' => '1951-01-04',
|
||||
'modified' => '2006-12-01 13:31:26'
|
||||
),
|
||||
'Sample' => array (
|
||||
'id' => '2',
|
||||
'apple_id' => '2',
|
||||
'name' => 'sample2'
|
||||
),
|
||||
'Child' => array (
|
||||
array (
|
||||
'id' => '1',
|
||||
'apple_id' => '2',
|
||||
'color' => 'Red 1',
|
||||
'name' => 'Red Apple 1',
|
||||
'created' => '2006-11-22 10:38:58',
|
||||
'date' => '1951-01-04',
|
||||
'modified' => '2006-12-01 13:31:26'
|
||||
),
|
||||
array (
|
||||
'id' => '3',
|
||||
'apple_id' => '2',
|
||||
'color' => 'blue green',
|
||||
'name' => 'green blue',
|
||||
'created' => '2006-12-25 05:13:36',
|
||||
'date' => '2006-12-25',
|
||||
'modified' => '2006-12-25 05:23:24'
|
||||
),
|
||||
array (
|
||||
'id' => '6',
|
||||
'apple_id' => '2',
|
||||
'color' => 'Blue Green',
|
||||
'name' => 'Test Name',
|
||||
'created' => '2006-12-25 05:23:36',
|
||||
'date' => '2006-12-25',
|
||||
'modified' => '2006-12-25 05:23:36'
|
||||
)
|
||||
)
|
||||
),
|
||||
array (
|
||||
'Apple' => array (
|
||||
'id' => '3',
|
||||
'apple_id' => '2',
|
||||
'color' => 'blue green',
|
||||
'name' => 'green blue',
|
||||
'created' => '2006-12-25 05:13:36',
|
||||
'date' => '2006-12-25',
|
||||
'modified' => '2006-12-25 05:23:24'
|
||||
),
|
||||
'Parent' => array (
|
||||
'id' => '2',
|
||||
'apple_id' => '1',
|
||||
'color' => 'Bright Red 1',
|
||||
'name' => 'Bright Red Apple',
|
||||
'created' => '2006-11-22 10:43:13',
|
||||
'date' => '2014-01-01',
|
||||
'modified' => '2006-11-30 18:38:10'
|
||||
),
|
||||
'Sample' => array (
|
||||
'id' => '1',
|
||||
'apple_id' => '3',
|
||||
'name' => 'sample1'
|
||||
),
|
||||
'Child' => array ( )
|
||||
),
|
||||
array (
|
||||
'Apple' => array (
|
||||
'id' => '6',
|
||||
'apple_id' => '2',
|
||||
'color' => 'Blue Green',
|
||||
'name' => 'Test Name',
|
||||
'created' => '2006-12-25 05:23:36',
|
||||
'date' => '2006-12-25',
|
||||
'modified' => '2006-12-25 05:23:36'
|
||||
),
|
||||
'Parent' => array (
|
||||
'id' => '2',
|
||||
'apple_id' => '1',
|
||||
'color' => 'Bright Red 1',
|
||||
'name' => 'Bright Red Apple',
|
||||
'created' => '2006-11-22 10:43:13',
|
||||
'date' => '2014-01-01',
|
||||
'modified' => '2006-11-30 18:38:10'
|
||||
),
|
||||
'Sample' => array (
|
||||
'id' => '3',
|
||||
'apple_id' => '6',
|
||||
'name' => 'sample3'
|
||||
),
|
||||
'Child' => array (
|
||||
array (
|
||||
'id' => '8',
|
||||
'apple_id' => '6',
|
||||
'color' => 'My new appleOrange',
|
||||
'name' => 'My new apple',
|
||||
'created' => '2006-12-25 05:29:39',
|
||||
'date' => '2006-12-25',
|
||||
'modified' => '2006-12-25 05:29:39'
|
||||
)
|
||||
)
|
||||
),
|
||||
array (
|
||||
'Apple' => array (
|
||||
'id' => '7',
|
||||
'apple_id' => '7',
|
||||
'color' => 'Green',
|
||||
'name' => 'Blue Green',
|
||||
'created' => '2006-12-25 05:24:06',
|
||||
'date' => '2006-12-25',
|
||||
'modified' => '2006-12-25 05:29:16'
|
||||
),
|
||||
'Parent' => array (
|
||||
'id' => '7',
|
||||
'apple_id' => '7',
|
||||
'color' => 'Green',
|
||||
'name' => 'Blue Green',
|
||||
'created' => '2006-12-25 05:24:06',
|
||||
'date' => '2006-12-25',
|
||||
'modified' => '2006-12-25 05:29:16'
|
||||
),
|
||||
'Sample' => array (
|
||||
'id' => '4',
|
||||
'apple_id' => '7',
|
||||
'name' => 'sample4'
|
||||
),
|
||||
'Child' => array (
|
||||
array (
|
||||
'id' => '7',
|
||||
'apple_id' => '7',
|
||||
'color' => 'Green',
|
||||
'name' => 'Blue Green',
|
||||
'created' => '2006-12-25 05:24:06',
|
||||
'date' => '2006-12-25',
|
||||
'modified' => '2006-12-25 05:29:16'
|
||||
)
|
||||
)
|
||||
),
|
||||
array (
|
||||
'Apple' => array (
|
||||
'id' => '8',
|
||||
'apple_id' => '6',
|
||||
'color' => 'My new appleOrange',
|
||||
'name' => 'My new apple',
|
||||
'created' => '2006-12-25 05:29:39',
|
||||
'date' => '2006-12-25',
|
||||
'modified' => '2006-12-25 05:29:39'
|
||||
),
|
||||
'Parent' => array (
|
||||
'id' => '6',
|
||||
'apple_id' => '2',
|
||||
'color' => 'Blue Green',
|
||||
'name' => 'Test Name',
|
||||
'created' => '2006-12-25 05:23:36',
|
||||
'date' => '2006-12-25',
|
||||
'modified' => '2006-12-25 05:23:36'
|
||||
),
|
||||
'Sample' => array (
|
||||
'id' => null,
|
||||
'apple_id' => null,
|
||||
'name' => null
|
||||
),
|
||||
'Child' => array (
|
||||
array (
|
||||
'id' => '9',
|
||||
'apple_id' => '8',
|
||||
'color' => 'Some wierd color',
|
||||
'name' => 'Some odd color',
|
||||
'created' => '2006-12-25 05:34:21',
|
||||
'date' => '2006-12-25',
|
||||
'modified' => '2006-12-25 05:34:21'
|
||||
)
|
||||
)
|
||||
),
|
||||
array (
|
||||
'Apple' => array (
|
||||
'id' => '9',
|
||||
'apple_id' => '8',
|
||||
'color' => 'Some wierd color',
|
||||
'name' => 'Some odd color',
|
||||
'created' => '2006-12-25 05:34:21',
|
||||
'date' => '2006-12-25',
|
||||
'modified' => '2006-12-25 05:34:21'
|
||||
),
|
||||
'Parent' => array (
|
||||
'id' => '8',
|
||||
'apple_id' => '6',
|
||||
'color' => 'My new appleOrange',
|
||||
'name' => 'My new apple',
|
||||
'created' => '2006-12-25 05:29:39',
|
||||
'date' => '2006-12-25',
|
||||
'modified' => '2006-12-25 05:29:39'
|
||||
),
|
||||
'Sample' => array (
|
||||
'id' => null,
|
||||
'apple_id' => null,
|
||||
'name' => null
|
||||
),
|
||||
'Child' => array ( )
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
57
cake/tests/fixtures/apple_fixture.php
vendored
Normal file
57
cake/tests/fixtures/apple_fixture.php
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
/* SVN FILE: $Id: apple_fixture.php 4668 2007-03-23 22:11:06Z mariano $ */
|
||||
/**
|
||||
* 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: 4668 $
|
||||
* @modifiedby $LastChangedBy: phpnut $
|
||||
* @lastmodified $Date: 2007-03-23 19:11:06 -0300 (Vie, 23 Mar 2007) $
|
||||
* @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 AppleFixture extends CakeTestFixture {
|
||||
var $name = 'Apple';
|
||||
var $fields = array(
|
||||
'id' => array('type' => 'integer', 'key' => 'primary'),
|
||||
'apple_id' => array('type' => 'integer', 'null' => true),
|
||||
'color' => array('type' => 'string', 'length' => 40, 'null' => false),
|
||||
'name' => array('type' => 'string', 'length' => 40, 'null' => false),
|
||||
'created' => 'datetime',
|
||||
'date' => 'date',
|
||||
'modified' => 'datetime'
|
||||
);
|
||||
var $records = array(
|
||||
array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26'),
|
||||
array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10'),
|
||||
array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24'),
|
||||
array('id' => 6, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36'),
|
||||
array('id' => 7, 'apple_id' => 7, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16'),
|
||||
array('id' => 8, 'apple_id' => 6, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39'),
|
||||
array('id' => 9, 'apple_id' => 8, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21')
|
||||
);
|
||||
}
|
||||
|
||||
?>
|
48
cake/tests/fixtures/sample_fixture.php
vendored
Normal file
48
cake/tests/fixtures/sample_fixture.php
vendored
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
/* SVN FILE: $Id: sample_fixture.php 4668 2007-03-23 22:11:06Z mariano $ */
|
||||
/**
|
||||
* 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: 4668 $
|
||||
* @modifiedby $LastChangedBy: phpnut $
|
||||
* @lastmodified $Date: 2007-03-23 19:11:06 -0300 (Vie, 23 Mar 2007) $
|
||||
* @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 SampleFixture extends CakeTestFixture {
|
||||
var $name = 'Sample';
|
||||
var $fields = array(
|
||||
'id' => array('type' => 'integer', 'key' => 'primary'),
|
||||
'apple_id' => array('type' => 'integer', 'null' => false),
|
||||
'name' => array('type' => 'string', 'length' => 40, 'null' => false)
|
||||
);
|
||||
var $records = array(
|
||||
array('id' => 1, 'apple_id' => 3, 'name' => 'sample1'),
|
||||
array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'),
|
||||
array('id' => 3, 'apple_id' => 6, 'name' => 'sample3'),
|
||||
array('id' => 4, 'apple_id' => 7, 'name' => 'sample4')
|
||||
);
|
||||
}
|
Loading…
Reference in a new issue