Added test that replicates issue in bakery with nested models after doing some bindModel() and unbindModel()

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4723 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mariano.iglesias 2007-04-01 04:40:18 +00:00
parent 0039859101
commit 024fc47407
2 changed files with 164 additions and 1 deletions

View file

@ -88,6 +88,15 @@
'body' => VALID_NOT_EMPTY
);
}
class Featured extends CakeTestModel {
var $name = 'Featured';
var $belongsTo = array(
'Article'=> array('className' => 'Article'),
'Category'=> array('className' => 'Category')
);
}
/**
* Short description for class.
*
@ -150,7 +159,7 @@
* @subpackage cake.tests.cases.libs.model
*/
class ModelTest extends CakeTestCase {
var $fixtures = array( 'core.category', 'core.category_thread', 'core.user', 'core.article', 'core.tag', 'core.articles_tag', 'core.comment', 'core.attachment' );
var $fixtures = array( 'core.category', 'core.category_thread', 'core.user', 'core.article', 'core.featured', 'core.tag', 'core.articles_tag', 'core.comment', 'core.attachment' );
function start() {
parent::start();
@ -642,6 +651,108 @@ class ModelTest extends CakeTestCase {
)
);
$this->assertEqual($result, $expected);
/*
$this->Article = new Article();
$this->Article->bindModel(array('hasOne' => array('Featured'=> array('className' => 'Featured'))));
$this->Article->bindModel(array('belongsTo' => array('Category')));
$this->Article->Featured->recursive = 2;
$orderBy = 'Article.published DESC';
$this->Article->Featured->bindModel(array('belongsTo' =>
array('Article' => array('conditions' => 'Article.published = \'Y\'',
'fields' => 'id, title, user_id, published'))));
$this->Article->unbindModel(array('hasMany' => array('Attachment', 'Leaf', 'Rating', 'Comment'), 'hasAndBelongsToMany'=>array('Tag')));
$result = $this->Article->Featured->findAll(null, null, $orderBy, 3);
$expected = array (
0 => array (
'Featured' => array (
'id' => '1',
'article_id' => '1',
'category_id' => '1',
'published_date' => '2007-03-31 10:39:23',
'end_date' => '2007-05-15 10:39:23',
'created' => '2007-03-18 10:39:23',
'updated' => '2007-03-18 10:41:31'
),
'Article' => array (
'id' => '1',
'title' => 'First Article',
'user_id' => '1',
'published' => 'Y',
'User' => array (
'id' => '1',
'user' => 'mariano',
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
'created' => '2007-03-17 01:16:23',
'updated' => '2007-03-17 01:18:31'
),
'Featured' => array (
'id' => '1',
'article_id' => '1',
'category_id' => '1',
'published_date' => '2007-03-31 10:39:23',
'end_date' => '2007-05-15 10:39:23',
'created' => '2007-03-18 10:39:23',
'updated' => '2007-03-18 10:41:31'
)
),
'Category' => array (
'id' => '1',
'parent_id' => '0',
'name' => 'Category 1',
'created' => '2007-03-18 15:30:23',
'updated' => '2007-03-18 15:32:31'
)
),
1 => array (
'Featured' => array (
'id' => '2',
'article_id' => '2',
'category_id' => '1',
'published_date' => '2007-03-31 10:39:23',
'end_date' => '2007-05-15 10:39:23',
'created' => '2007-03-18 10:39:23',
'updated' => '2007-03-18 10:41:31'
),
'Article' => array (
'id' => '2',
'title' => 'Second Article',
'user_id' => '3',
'published' => 'Y',
'User' => array (
'id' => '3',
'user' => 'larry',
'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
'created' => '2007-03-17 01:20:23',
'updated' => '2007-03-17 01:22:31'
),
'Featured' => array (
'id' => '2',
'article_id' => '2',
'category_id' => '1',
'published_date' => '2007-03-31 10:39:23',
'end_date' => '2007-05-15 10:39:23',
'created' => '2007-03-18 10:39:23',
'updated' => '2007-03-18 10:41:31'
)
),
'Category' => array (
'id' => '1',
'parent_id' => '0',
'name' => 'Category 1',
'created' => '2007-03-18 15:30:23',
'updated' => '2007-03-18 15:32:31'
)
)
);
$this->assertEqual($result, $expected);
*/
}
function testSaveField() {

View file

@ -0,0 +1,52 @@
<?php
/* SVN FILE: $Id: article_fixture.php 4668 2007-03-23 22:11:06Z phpnut $ */
/**
* 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 FeaturedFixture extends CakeTestFixture {
var $name = 'Featured';
var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'article_id' => array('type' => 'integer', 'null' => false),
'category_id' => array('type' => 'integer', 'null' => false),
'published_date' => 'datetime',
'end_date' => 'datetime',
'created' => 'datetime',
'updated' => 'datetime'
);
var $records = array(
array ('id' => 1, 'article_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'),
array ('id' => 2, 'article_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'),
);
}
?>