|
|
@@ -206,6 +206,36 @@
|
|
|
var $name = 'Sample';
|
|
|
var $belongsTo = 'Apple';
|
|
|
}
|
|
|
+ /**
|
|
|
+ * Short description for class.
|
|
|
+ *
|
|
|
+ * @package cake.tests
|
|
|
+ * @subpackage cake.tests.cases.libs.model
|
|
|
+ */
|
|
|
+ class AnotherArticle extends CakeTestModel {
|
|
|
+ var $name = 'AnotherArticle';
|
|
|
+ var $hasMany = 'Home';
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * Short description for class.
|
|
|
+ *
|
|
|
+ * @package cake.tests
|
|
|
+ * @subpackage cake.tests.cases.libs.model
|
|
|
+ */
|
|
|
+ class Advertisement extends CakeTestModel {
|
|
|
+ var $name = 'Advertisement';
|
|
|
+ var $hasMany = 'Home';
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * Short description for class.
|
|
|
+ *
|
|
|
+ * @package cake.tests
|
|
|
+ * @subpackage cake.tests.cases.libs.model
|
|
|
+ */
|
|
|
+ class Home extends CakeTestModel {
|
|
|
+ var $name = 'Home';
|
|
|
+ var $belongsTo = array( 'AnotherArticle', 'Advertisement' );
|
|
|
+ }
|
|
|
/**
|
|
|
* Short description for class.
|
|
|
*
|
|
|
@@ -216,7 +246,7 @@ 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',
|
|
|
- 'core.apple', 'core.sample'
|
|
|
+ 'core.apple', 'core.sample', 'core.another_article', 'core.advertisement', 'core.home'
|
|
|
);
|
|
|
|
|
|
function start() {
|
|
|
@@ -229,6 +259,65 @@ class ModelTest extends CakeTestCase {
|
|
|
Configure::write('debug', DEBUG);
|
|
|
}
|
|
|
|
|
|
+ function testFindAllRecursiveSelfJoin() {
|
|
|
+ $this->model =& new Home();
|
|
|
+
|
|
|
+ $this->model->recursive = 2;
|
|
|
+ $result = $this->model->findAll();
|
|
|
+ $expected = array (
|
|
|
+ array (
|
|
|
+ 'Home' => array (
|
|
|
+ 'id' => '1', 'another_article_id' => '1', 'advertisement_id' => '1', 'title' => 'First Home', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
|
|
|
+ ),
|
|
|
+ 'AnotherArticle' => array (
|
|
|
+ 'id' => '1', 'title' => 'First Article', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
|
|
|
+ 'Home' => array (
|
|
|
+ array (
|
|
|
+ 'id' => '1', 'another_article_id' => '1', 'advertisement_id' => '1', 'title' => 'First Home', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
|
|
|
+ )
|
|
|
+ )
|
|
|
+ ),
|
|
|
+ 'Advertisement' => array (
|
|
|
+ 'id' => '1', 'title' => 'First Ad', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
|
|
|
+ 'Home' => array (
|
|
|
+ array (
|
|
|
+ 'id' => '1', 'another_article_id' => '1', 'advertisement_id' => '1', 'title' => 'First Home', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
|
|
|
+ ),
|
|
|
+ array (
|
|
|
+ 'id' => '2', 'another_article_id' => '3', 'advertisement_id' => '1', 'title' => 'Second Home', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
|
|
|
+ )
|
|
|
+ )
|
|
|
+ )
|
|
|
+ ),
|
|
|
+ array (
|
|
|
+ 'Home' => array (
|
|
|
+ 'id' => '2', 'another_article_id' => '3', 'advertisement_id' => '1', 'title' => 'Second Home', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
|
|
|
+ ),
|
|
|
+ 'AnotherArticle' => array (
|
|
|
+ 'id' => '3', 'title' => 'Third Article', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
|
|
|
+ 'Home' => array (
|
|
|
+ array (
|
|
|
+ 'id' => '2', 'another_article_id' => '3', 'advertisement_id' => '1', 'title' => 'Second Home', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
|
|
|
+ )
|
|
|
+ )
|
|
|
+ ),
|
|
|
+ 'Advertisement' => array (
|
|
|
+ 'id' => '1', 'title' => 'First Ad', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
|
|
|
+ 'Home' => array (
|
|
|
+ array (
|
|
|
+ 'id' => '1', 'another_article_id' => '1', 'advertisement_id' => '1', 'title' => 'First Home', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
|
|
|
+ ),
|
|
|
+ array (
|
|
|
+ 'id' => '2', 'another_article_id' => '3', 'advertisement_id' => '1', 'title' => 'Second Home', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
|
|
|
+ )
|
|
|
+ )
|
|
|
+ )
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
+ $this->assertEqual($result, $expected);
|
|
|
+ }
|
|
|
+
|
|
|
function testIdentity() {
|
|
|
$this->model =& new Test();
|
|
|
$result = $this->model->name;
|
|
|
@@ -259,7 +348,7 @@ class ModelTest extends CakeTestCase {
|
|
|
$this->assertEqual($result, $expected);
|
|
|
}
|
|
|
|
|
|
- function testFindAllFakeThread() {
|
|
|
+ function testReadFakeThread() {
|
|
|
$this->model =& new CategoryThread();
|
|
|
|
|
|
$this->db->fullDebug = true;
|
|
|
@@ -276,6 +365,78 @@ class ModelTest extends CakeTestCase {
|
|
|
$this->assertEqual($result, $expected);
|
|
|
}
|
|
|
|
|
|
+ function testFindFakeThread() {
|
|
|
+ $this->model =& new CategoryThread();
|
|
|
+
|
|
|
+ $this->db->fullDebug = true;
|
|
|
+ $this->model->recursive = 6;
|
|
|
+ $result = $this->model->find(array('CategoryThread.id' => 7));
|
|
|
+
|
|
|
+ $expected = array('CategoryThread' => array('id' => 7, 'parent_id' => 6, 'name' => 'Category 2.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'),
|
|
|
+ 'ParentCategory' => array('id' => 6, 'parent_id' => 5, 'name' => 'Category 2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31',
|
|
|
+ 'ParentCategory' => array('id' => 5, 'parent_id' => 4, 'name' => 'Category 1.1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31',
|
|
|
+ 'ParentCategory' => array('id' => 4, 'parent_id' => 3, 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31',
|
|
|
+ 'ParentCategory' => array('id' => 3, 'parent_id' => 2, 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31',
|
|
|
+ 'ParentCategory' => array('id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31',
|
|
|
+ 'ParentCategory' => 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 testFindAllFakeThread() {
|
|
|
+ $this->model =& new CategoryThread();
|
|
|
+
|
|
|
+ $this->db->fullDebug = true;
|
|
|
+ $this->model->recursive = 6;
|
|
|
+ $result = $this->model->findAll();
|
|
|
+
|
|
|
+ $expected = array(
|
|
|
+ array(
|
|
|
+ 'CategoryThread' => array('id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'),
|
|
|
+ 'ParentCategory' => array('id' => null, 'parent_id' => null, 'name' => null, 'created' => null, 'updated' => null)
|
|
|
+ ),
|
|
|
+ array(
|
|
|
+ 'CategoryThread' => array('id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'),
|
|
|
+ 'ParentCategory' => array('id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31')
|
|
|
+ ),
|
|
|
+ array(
|
|
|
+ 'CategoryThread' => array('id' => 3, 'parent_id' => 2, 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'),
|
|
|
+ 'ParentCategory' => array('id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31',
|
|
|
+ 'ParentCategory' => array('id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'))
|
|
|
+ ),
|
|
|
+ array(
|
|
|
+ 'CategoryThread' => array('id' => 4, 'parent_id' => 3, 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'),
|
|
|
+ 'ParentCategory' => array('id' => 3, 'parent_id' => 2, 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31',
|
|
|
+ 'ParentCategory' => array('id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31',
|
|
|
+ 'ParentCategory' => array('id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31')))
|
|
|
+ ),
|
|
|
+ array(
|
|
|
+ 'CategoryThread' => array('id' => 5, 'parent_id' => 4, 'name' => 'Category 1.1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'),
|
|
|
+ 'ParentCategory' => array('id' => 4, 'parent_id' => 3, 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31',
|
|
|
+ 'ParentCategory' => array('id' => 3, 'parent_id' => 2, 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31',
|
|
|
+ 'ParentCategory' => array('id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31',
|
|
|
+ 'ParentCategory' => array('id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'))))
|
|
|
+ ),
|
|
|
+ array(
|
|
|
+ 'CategoryThread' => array('id' => 6, 'parent_id' => 5, 'name' => 'Category 2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'),
|
|
|
+ 'ParentCategory' => array('id' => 5, 'parent_id' => 4, 'name' => 'Category 1.1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31',
|
|
|
+ 'ParentCategory' => array('id' => 4, 'parent_id' => 3, 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31',
|
|
|
+ 'ParentCategory' => array('id' => 3, 'parent_id' => 2, 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31',
|
|
|
+ 'ParentCategory' => array('id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31',
|
|
|
+ 'ParentCategory' => array('id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31')))))
|
|
|
+ ),
|
|
|
+ array(
|
|
|
+ 'CategoryThread' => array('id' => 7, 'parent_id' => 6, 'name' => 'Category 2.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'),
|
|
|
+ 'ParentCategory' => array('id' => 6, 'parent_id' => 5, 'name' => 'Category 2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31',
|
|
|
+ 'ParentCategory' => array('id' => 5, 'parent_id' => 4, 'name' => 'Category 1.1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31',
|
|
|
+ 'ParentCategory' => array('id' => 4, 'parent_id' => 3, 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31',
|
|
|
+ 'ParentCategory' => array('id' => 3, 'parent_id' => 2, 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31',
|
|
|
+ 'ParentCategory' => array('id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31',
|
|
|
+ 'ParentCategory' => 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 testFindAll() {
|
|
|
$this->model =& new User();
|
|
|
|
|
|
@@ -823,10 +984,10 @@ class ModelTest extends CakeTestCase {
|
|
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
function testRecursiveFindAllWithLimit() {
|
|
|
$this->model =& new Article();
|
|
|
-
|
|
|
+
|
|
|
$this->model->hasMany['Comment']['limit'] = 2;
|
|
|
|
|
|
$result = $this->model->findAll(array('Article.user_id' => 1));
|
|
|
@@ -859,7 +1020,7 @@ function testRecursiveFindAllWithLimit() {
|
|
|
)
|
|
|
);
|
|
|
$this->assertEqual($result, $expected);
|
|
|
-
|
|
|
+
|
|
|
$this->model->hasMany['Comment']['limit'] = 1;
|
|
|
|
|
|
$result = $this->model->findAll(array('Article.user_id' => 3), null, null, null, 1, 2);
|