diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 44eafbf05..077655634 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -88,11 +88,36 @@ 'body' => VALID_NOT_EMPTY ); } - + /** + * Short description for class. + * + * @package cake.tests + * @subpackage cake.tests.cases.libs.model + */ + class ArticleFeatured extends CakeTestModel { + var $name = 'ArticleFeatured'; + var $belongsTo = array('User', 'Category'); + var $hasOne = array('Featured'); + var $hasMany = array( + 'Comment' => array('className'=>'Comment', 'dependent' => true) + ); + var $hasAndBelongsToMany = array('Tag'); + var $validate = array( + 'user_id' => VALID_NUMBER, + 'title' => VALID_NOT_EMPTY, + 'body' => VALID_NOT_EMPTY + ); + } + /** + * Short description for class. + * + * @package cake.tests + * @subpackage cake.tests.cases.libs.model + */ class Featured extends CakeTestModel { var $name = 'Featured'; var $belongsTo = array( - 'Article'=> array('className' => 'Article'), + 'ArticleFeatured'=> array('className' => 'ArticleFeatured'), 'Category'=> array('className' => 'Category') ); } @@ -159,7 +184,7 @@ * @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.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' ); function start() { parent::start(); @@ -658,38 +683,35 @@ class ModelTest extends CakeTestCase { ); $this->assertEqual($result, $expected); - /* - $this->Article = new Article(); + $this->ArticleFeatured = new ArticleFeatured(); - $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\'', + $this->ArticleFeatured->Featured->recursive = 2; + $orderBy = 'ArticleFeatured.id ASC'; + $this->ArticleFeatured->Featured->bindModel(array('belongsTo' => + array('ArticleFeatured' => array('conditions' => 'ArticleFeatured.published = \'Y\'', 'fields' => 'id, title, user_id, published')))); - $this->Article->unbindModel(array('hasMany' => array('Attachment', 'Leaf', 'Rating', 'Comment'), 'hasAndBelongsToMany'=>array('Tag'))); + $this->ArticleFeatured->Featured->ArticleFeatured->bindModel(array('hasOne' => array('Featured'=> array('className' => 'Featured')))); + $this->ArticleFeatured->Featured->ArticleFeatured->unbindModel(array('hasMany' => array('Attachment', 'Comment'), 'hasAndBelongsToMany'=>array('Tag'))); // UNCOMMENT THE FOLLOWING LINE TO MAKE TEST SUCCEED: // - // $this->Article->unbindModel(array('belongsTo'=>array('Category'))); + // $this->ArticleFeatured->unbindModel(array('belongsTo'=>array('Category'))); - $result = $this->Article->Featured->findAll(null, null, $orderBy, 3); + $result = $this->ArticleFeatured->Featured->findAll(null, null, $orderBy, 3); $expected = array ( - 0 => array ( + array ( 'Featured' => array ( 'id' => '1', - 'article_id' => '1', + 'article_featured_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 ( + 'ArticleFeatured' => array ( 'id' => '1', 'title' => 'First Article', 'user_id' => '1', @@ -703,7 +725,7 @@ class ModelTest extends CakeTestCase { ), 'Featured' => array ( 'id' => '1', - 'article_id' => '1', + 'article_featured_id' => '1', 'category_id' => '1', 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', @@ -719,17 +741,17 @@ class ModelTest extends CakeTestCase { 'updated' => '2007-03-18 15:32:31' ) ), - 1 => array ( + array ( 'Featured' => array ( 'id' => '2', - 'article_id' => '2', + 'article_featured_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 ( + 'ArticleFeatured' => array ( 'id' => '2', 'title' => 'Second Article', 'user_id' => '3', @@ -743,7 +765,7 @@ class ModelTest extends CakeTestCase { ), 'Featured' => array ( 'id' => '2', - 'article_id' => '2', + 'article_featured_id' => '2', 'category_id' => '1', 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', @@ -762,7 +784,6 @@ class ModelTest extends CakeTestCase { ); $this->assertEqual($result, $expected); - */ } function testSaveField() { diff --git a/cake/tests/fixtures/article_featured_fixture.php b/cake/tests/fixtures/article_featured_fixture.php new file mode 100644 index 000000000..00c8b6cbb --- /dev/null +++ b/cake/tests/fixtures/article_featured_fixture.php @@ -0,0 +1,53 @@ + + * 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 ArticleFeaturedFixture extends CakeTestFixture { + var $name = 'ArticleFeatured'; + var $fields = array( + 'id' => array('type' => 'integer', 'key' => 'primary'), + 'user_id' => array('type' => 'integer', 'null' => false), + 'title' => array('type' => 'string', 'null' => false), + 'body' => 'text', + 'published' => array('type' => 'string', 'length' => 1, 'default' => 'N'), + 'created' => 'datetime', + 'updated' => 'datetime' + ); + var $records = array( + array ('id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), + array ('id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), + array ('id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31') + ); +} + +?> \ No newline at end of file diff --git a/cake/tests/fixtures/featured_fixture.php b/cake/tests/fixtures/featured_fixture.php index bab6eea03..0a8a130e1 100644 --- a/cake/tests/fixtures/featured_fixture.php +++ b/cake/tests/fixtures/featured_fixture.php @@ -36,7 +36,7 @@ class FeaturedFixture extends CakeTestFixture { var $name = 'Featured'; var $fields = array( 'id' => array('type' => 'integer', 'key' => 'primary'), - 'article_id' => array('type' => 'integer', 'null' => false), + 'article_featured_id' => array('type' => 'integer', 'null' => false), 'category_id' => array('type' => 'integer', 'null' => false), 'published_date' => 'datetime', 'end_date' => 'datetime', @@ -44,8 +44,8 @@ class FeaturedFixture extends CakeTestFixture { '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'), + array ('id' => 1, 'article_featured_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_featured_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'), ); }