2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* ContainableBehaviorTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-04-27 02:49:18 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-10-03 16:31:21 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2012-04-27 02:49:18 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model.Behavior
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5669
|
2010-10-03 16:27:27 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-09 05:55:24 +00:00
|
|
|
|
|
|
|
App::uses('Model', 'Model');
|
|
|
|
App::uses('AppModel', 'Model');
|
2012-03-18 18:31:13 +00:00
|
|
|
require_once dirname(dirname(__FILE__)) . DS . 'models.php';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* ContainableTest class
|
2008-06-23 04:41:15 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Model.Behavior
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2009-03-18 17:55:58 +00:00
|
|
|
class ContainableBehaviorTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Fixtures associated with this test case
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $fixtures = array(
|
2011-05-16 22:49:00 +00:00
|
|
|
'core.article', 'core.article_featured', 'core.article_featureds_tags',
|
2010-12-12 20:48:36 +00:00
|
|
|
'core.articles_tag', 'core.attachment', 'core.category',
|
2011-09-18 16:09:04 +00:00
|
|
|
'core.comment', 'core.featured', 'core.tag', 'core.user',
|
|
|
|
'core.join_a', 'core.join_b', 'core.join_c', 'core.join_a_c', 'core.join_a_b'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Method executed before each test
|
|
|
|
*
|
|
|
|
*/
|
2010-12-12 20:48:36 +00:00
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
$this->User = ClassRegistry::init('User');
|
|
|
|
$this->Article = ClassRegistry::init('Article');
|
|
|
|
$this->Tag = ClassRegistry::init('Tag');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2009-09-01 03:40:47 +00:00
|
|
|
$this->User->bindModel(array(
|
|
|
|
'hasMany' => array('Article', 'ArticleFeatured', 'Comment')
|
|
|
|
), false);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->User->ArticleFeatured->unbindModel(array('belongsTo' => array('Category')), false);
|
|
|
|
$this->User->ArticleFeatured->hasMany['Comment']['foreignKey'] = 'article_id';
|
|
|
|
|
2009-09-01 03:40:47 +00:00
|
|
|
$this->Tag->bindModel(array(
|
|
|
|
'hasAndBelongsToMany' => array('Article')
|
|
|
|
), false);
|
2009-03-22 13:09:50 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->User->Behaviors->attach('Containable');
|
|
|
|
$this->Article->Behaviors->attach('Containable');
|
2009-03-22 13:09:50 +00:00
|
|
|
$this->Tag->Behaviors->attach('Containable');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Method executed after each test
|
|
|
|
*
|
|
|
|
*/
|
2010-12-12 20:48:36 +00:00
|
|
|
public function tearDown() {
|
2008-05-30 11:40:08 +00:00
|
|
|
unset($this->Article);
|
|
|
|
unset($this->User);
|
2009-03-22 13:09:50 +00:00
|
|
|
unset($this->Tag);
|
2010-12-12 20:48:36 +00:00
|
|
|
parent::tearDown();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testContainments method
|
2008-06-23 04:41:15 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testContainments() {
|
2012-02-17 07:32:35 +00:00
|
|
|
$r = $this->_containments($this->Article, array('Comment' => array('conditions' => array('Comment.user_id' => 2))));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue(Set::matches('/Article/keep/Comment/conditions[Comment.user_id=2]', $r));
|
|
|
|
|
2012-02-17 07:32:35 +00:00
|
|
|
$r = $this->_containments($this->User, array(
|
2008-05-30 11:40:08 +00:00
|
|
|
'ArticleFeatured' => array(
|
|
|
|
'Featured' => array(
|
|
|
|
'id',
|
|
|
|
'Category' => 'name'
|
|
|
|
)
|
|
|
|
)));
|
2012-04-04 23:33:57 +00:00
|
|
|
$this->assertEquals(array('id'), Hash::extract($r, 'ArticleFeatured.keep.Featured.fields'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-02-17 07:32:35 +00:00
|
|
|
$r = $this->_containments($this->Article, array(
|
2008-05-30 11:40:08 +00:00
|
|
|
'Comment' => array(
|
|
|
|
'User',
|
|
|
|
'conditions' => array('Comment' => array('user_id' => 2)),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
$this->assertTrue(Set::matches('/User', $r));
|
|
|
|
$this->assertTrue(Set::matches('/Comment', $r));
|
|
|
|
$this->assertTrue(Set::matches('/Article/keep/Comment/conditions/Comment[user_id=2]', $r));
|
|
|
|
|
2012-02-17 07:32:35 +00:00
|
|
|
$r = $this->_containments($this->Article, array('Comment(comment, published)' => 'Attachment(attachment)', 'User(user)'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue(Set::matches('/Comment', $r));
|
|
|
|
$this->assertTrue(Set::matches('/User', $r));
|
|
|
|
$this->assertTrue(Set::matches('/Article/keep/Comment', $r));
|
|
|
|
$this->assertTrue(Set::matches('/Article/keep/User', $r));
|
2012-04-04 23:33:57 +00:00
|
|
|
$this->assertEquals(array('comment', 'published'), Hash::extract($r, 'Article.keep.Comment.fields'));
|
|
|
|
$this->assertEquals(array('user'), Hash::extract($r, 'Article.keep.User.fields'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue(Set::matches('/Comment/keep/Attachment', $r));
|
2012-04-04 23:33:57 +00:00
|
|
|
$this->assertEquals(array('attachment'), Hash::extract($r, 'Comment.keep.Attachment.fields'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-02-17 07:32:35 +00:00
|
|
|
$r = $this->_containments($this->Article, array('Comment' => array('limit' => 1)));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('Comment', 'Article'), array_keys($r));
|
2012-04-04 23:33:57 +00:00
|
|
|
$result = Hash::extract($r, 'Comment[keep]');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('keep' => array()), array_shift($result));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue(Set::matches('/Article/keep/Comment', $r));
|
2012-04-04 23:33:57 +00:00
|
|
|
$result = Hash::extract($r, 'Article.keep');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('limit' => 1), array_shift($result));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-02-17 07:32:35 +00:00
|
|
|
$r = $this->_containments($this->Article, array('Comment.User'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('User', 'Comment', 'Article'), array_keys($r));
|
2010-12-12 20:48:36 +00:00
|
|
|
|
2012-04-04 23:33:57 +00:00
|
|
|
$result = Hash::extract($r, 'User[keep]');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('keep' => array()), array_shift($result));
|
2010-12-12 20:48:36 +00:00
|
|
|
|
2012-04-04 23:33:57 +00:00
|
|
|
$result = Hash::extract($r, 'Comment[keep]');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('keep' => array('User' => array())), array_shift($result));
|
2011-05-16 22:49:00 +00:00
|
|
|
|
2012-04-04 23:33:57 +00:00
|
|
|
$result = Hash::extract($r, 'Article[keep]');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('keep' => array('Comment' => array())), array_shift($result));
|
2009-03-22 13:09:50 +00:00
|
|
|
|
2012-02-17 07:32:35 +00:00
|
|
|
$r = $this->_containments($this->Tag, array('Article' => array('User' => array('Comment' => array(
|
2009-03-22 13:09:50 +00:00
|
|
|
'Attachment' => array('conditions' => array('Attachment.id >' => 1))
|
|
|
|
)))));
|
|
|
|
$this->assertTrue(Set::matches('/Attachment', $r));
|
|
|
|
$this->assertTrue(Set::matches('/Comment/keep/Attachment/conditions', $r));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('Attachment.id >' => 1), $r['Comment']['keep']['Attachment']['conditions']);
|
2009-03-22 13:09:50 +00:00
|
|
|
$this->assertTrue(Set::matches('/User/keep/Comment', $r));
|
|
|
|
$this->assertTrue(Set::matches('/Article/keep/User', $r));
|
|
|
|
$this->assertTrue(Set::matches('/Tag/keep/Article', $r));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testInvalidContainments method
|
2008-06-23 04:41:15 +00:00
|
|
|
*
|
2011-11-16 12:15:14 +00:00
|
|
|
* @expectedException PHPUnit_Framework_Error
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInvalidContainments() {
|
2013-01-23 12:45:50 +00:00
|
|
|
$this->_containments($this->Article, array('Comment', 'InvalidBinding'));
|
2011-09-10 16:23:28 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-09-10 16:23:28 +00:00
|
|
|
/**
|
|
|
|
* testInvalidContainments method with suppressing error notices
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInvalidContainmentsNoNotices() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Article->Behaviors->attach('Containable', array('notices' => false));
|
2013-01-23 12:45:50 +00:00
|
|
|
$this->_containments($this->Article, array('Comment', 'InvalidBinding'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testBeforeFind method
|
2008-06-23 04:41:15 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testBeforeFind() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$r = $this->Article->find('all', array('contain' => array('Comment')));
|
|
|
|
$this->assertFalse(Set::matches('/User', $r));
|
|
|
|
$this->assertTrue(Set::matches('/Comment', $r));
|
|
|
|
$this->assertFalse(Set::matches('/Comment/User', $r));
|
|
|
|
|
|
|
|
$r = $this->Article->find('all', array('contain' => 'Comment.User'));
|
|
|
|
$this->assertTrue(Set::matches('/Comment/User', $r));
|
|
|
|
$this->assertFalse(Set::matches('/Comment/Article', $r));
|
|
|
|
|
|
|
|
$r = $this->Article->find('all', array('contain' => array('Comment' => array('User', 'Article'))));
|
|
|
|
$this->assertTrue(Set::matches('/Comment/User', $r));
|
|
|
|
$this->assertTrue(Set::matches('/Comment/Article', $r));
|
|
|
|
|
|
|
|
$r = $this->Article->find('all', array('contain' => array('Comment' => array('conditions' => array('Comment.user_id' => 2)))));
|
|
|
|
$this->assertFalse(Set::matches('/Comment[user_id!=2]', $r));
|
|
|
|
$this->assertTrue(Set::matches('/Comment[user_id=2]', $r));
|
|
|
|
|
|
|
|
$r = $this->Article->find('all', array('contain' => array('Comment.user_id = 2')));
|
|
|
|
$this->assertFalse(Set::matches('/Comment[user_id!=2]', $r));
|
|
|
|
|
|
|
|
$r = $this->Article->find('all', array('contain' => 'Comment.id DESC'));
|
2012-04-04 23:33:57 +00:00
|
|
|
$ids = $descIds = Hash::extract($r, 'Comment[1].id');
|
2008-05-30 11:40:08 +00:00
|
|
|
rsort($descIds);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($ids, $descIds);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$r = $this->Article->find('all', array('contain' => 'Comment'));
|
|
|
|
$this->assertTrue(Set::matches('/Comment[user_id!=2]', $r));
|
|
|
|
|
|
|
|
$r = $this->Article->find('all', array('contain' => array('Comment' => array('fields' => 'comment'))));
|
|
|
|
$this->assertFalse(Set::matches('/Comment/created', $r));
|
|
|
|
$this->assertTrue(Set::matches('/Comment/comment', $r));
|
|
|
|
$this->assertFalse(Set::matches('/Comment/updated', $r));
|
|
|
|
|
|
|
|
$r = $this->Article->find('all', array('contain' => array('Comment' => array('fields' => array('comment', 'updated')))));
|
|
|
|
$this->assertFalse(Set::matches('/Comment/created', $r));
|
|
|
|
$this->assertTrue(Set::matches('/Comment/comment', $r));
|
|
|
|
$this->assertTrue(Set::matches('/Comment/updated', $r));
|
|
|
|
|
|
|
|
$r = $this->Article->find('all', array('contain' => array('Comment' => array('comment', 'updated'))));
|
|
|
|
$this->assertFalse(Set::matches('/Comment/created', $r));
|
|
|
|
$this->assertTrue(Set::matches('/Comment/comment', $r));
|
|
|
|
$this->assertTrue(Set::matches('/Comment/updated', $r));
|
|
|
|
|
|
|
|
$r = $this->Article->find('all', array('contain' => array('Comment(comment,updated)')));
|
|
|
|
$this->assertFalse(Set::matches('/Comment/created', $r));
|
|
|
|
$this->assertTrue(Set::matches('/Comment/comment', $r));
|
|
|
|
$this->assertTrue(Set::matches('/Comment/updated', $r));
|
|
|
|
|
|
|
|
$r = $this->Article->find('all', array('contain' => 'Comment.created'));
|
|
|
|
$this->assertTrue(Set::matches('/Comment/created', $r));
|
|
|
|
$this->assertFalse(Set::matches('/Comment/comment', $r));
|
|
|
|
|
|
|
|
$r = $this->Article->find('all', array('contain' => array('User.Article(title)', 'Comment(comment)')));
|
|
|
|
$this->assertFalse(Set::matches('/Comment/Article', $r));
|
|
|
|
$this->assertFalse(Set::matches('/Comment/User', $r));
|
|
|
|
$this->assertTrue(Set::matches('/Comment/comment', $r));
|
|
|
|
$this->assertFalse(Set::matches('/Comment/created', $r));
|
|
|
|
$this->assertTrue(Set::matches('/User/Article/title', $r));
|
|
|
|
$this->assertFalse(Set::matches('/User/Article/created', $r));
|
|
|
|
|
|
|
|
$r = $this->Article->find('all', array('contain' => array()));
|
|
|
|
$this->assertFalse(Set::matches('/User', $r));
|
|
|
|
$this->assertFalse(Set::matches('/Comment', $r));
|
2011-09-10 16:23:28 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-09-10 16:23:28 +00:00
|
|
|
/**
|
|
|
|
* testBeforeFindWithNonExistingBinding method
|
2011-10-28 05:01:17 +00:00
|
|
|
*
|
2011-11-16 12:15:14 +00:00
|
|
|
* @expectedException PHPUnit_Framework_Error
|
2011-09-10 16:23:28 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testBeforeFindWithNonExistingBinding() {
|
2013-01-23 12:45:50 +00:00
|
|
|
$this->Article->find('all', array('contain' => array('Comment' => 'NonExistingBinding')));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testContain method
|
2008-06-23 04:41:15 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testContain() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Article->contain('Comment.User');
|
|
|
|
$r = $this->Article->find('all');
|
|
|
|
$this->assertTrue(Set::matches('/Comment/User', $r));
|
|
|
|
$this->assertFalse(Set::matches('/Comment/Article', $r));
|
|
|
|
|
|
|
|
$r = $this->Article->find('all');
|
|
|
|
$this->assertFalse(Set::matches('/Comment/User', $r));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-08-13 06:10:51 +00:00
|
|
|
/**
|
|
|
|
* testContainFindList method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testContainFindList() {
|
|
|
|
$this->Article->contain('Comment.User');
|
|
|
|
$result = $this->Article->find('list');
|
|
|
|
$expected = array(
|
|
|
|
1 => 'First Article',
|
|
|
|
2 => 'Second Article',
|
|
|
|
3 => 'Third Article'
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
2012-08-16 00:19:08 +00:00
|
|
|
$result = $this->Article->find('list', array('fields' => array('Article.id', 'User.id'), 'contain' => array('User')));
|
2012-08-13 06:10:51 +00:00
|
|
|
$expected = array(
|
|
|
|
1 => '1',
|
|
|
|
2 => '3',
|
|
|
|
3 => '1'
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2012-10-20 18:51:52 +00:00
|
|
|
/**
|
|
|
|
* Test that mixing contain() and the contain find option.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testContainAndContainOption() {
|
|
|
|
$this->Article->contain();
|
|
|
|
$r = $this->Article->find('all', array(
|
|
|
|
'contain' => array('Comment')
|
|
|
|
));
|
|
|
|
$this->assertTrue(isset($r[0]['Comment']), 'No comment returned');
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFindEmbeddedNoBindings method
|
2008-06-23 04:41:15 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFindEmbeddedNoBindings() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Article->find('all', array('contain' => false));
|
|
|
|
$expected = array(
|
|
|
|
array('Article' => 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('Article' => 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('Article' => 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'
|
|
|
|
))
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFindFirstLevel method
|
2008-06-23 04:41:15 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFindFirstLevel() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Article->contain('User');
|
|
|
|
$result = $this->Article->find('all', array('recursive' => 1));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->Article->contain('User', 'Comment');
|
|
|
|
$result = $this->Article->find('all', array('recursive' => 1));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
|
|
|
|
'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
),
|
|
|
|
'Comment' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFindEmbeddedFirstLevel method
|
2008-06-23 04:41:15 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFindEmbeddedFirstLevel() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Article->find('all', array('contain' => array('User')));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Article->find('all', array('contain' => array('User', 'Comment')));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
|
|
|
|
'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
),
|
|
|
|
'Comment' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFindSecondLevel method
|
2008-06-23 04:41:15 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFindSecondLevel() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Article->contain(array('Comment' => 'User'));
|
|
|
|
$result = $this->Article->find('all', array('recursive' => 2));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
|
|
|
|
'User' => array(
|
|
|
|
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
|
|
|
|
'User' => array(
|
|
|
|
'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
|
|
|
|
'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
|
|
|
|
'User' => array(
|
|
|
|
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Comment' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->Article->contain(array('User' => 'ArticleFeatured'));
|
|
|
|
$result = $this->Article->find('all', array('recursive' => 2));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
|
|
|
|
'ArticleFeatured' => 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' => 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'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31',
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
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(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
|
|
|
|
'ArticleFeatured' => 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' => 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'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->Article->contain(array('User' => array('ArticleFeatured', 'Comment')));
|
|
|
|
$result = $this->Article->find('all', array('recursive' => 2));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
|
|
|
|
'ArticleFeatured' => 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' => 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'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
|
|
|
|
'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31',
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
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'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array()
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
|
|
|
|
'ArticleFeatured' => 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' => 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'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
|
|
|
|
'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->Article->contain(array('User' => array('ArticleFeatured')), 'Tag', array('Comment' => 'Attachment'));
|
|
|
|
$result = $this->Article->find('all', array('recursive' => 2));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
|
|
|
|
'ArticleFeatured' => 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' => 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'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
|
|
|
|
'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Tag' => array(
|
|
|
|
array('id' => 1, 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'),
|
|
|
|
array('id' => 2, 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31')
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31',
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
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'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
|
|
|
|
'Attachment' => array(
|
|
|
|
'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
|
|
|
|
'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Tag' => array(
|
|
|
|
array('id' => 1, 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'),
|
|
|
|
array('id' => 3, 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31')
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
|
|
|
|
'ArticleFeatured' => 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' => 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'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(),
|
|
|
|
'Tag' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFindEmbeddedSecondLevel method
|
2008-06-23 04:41:15 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFindEmbeddedSecondLevel() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Article->find('all', array('contain' => array('Comment' => 'User')));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
|
|
|
|
'User' => array(
|
|
|
|
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
|
|
|
|
'User' => array(
|
|
|
|
'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
|
|
|
|
'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
|
|
|
|
'User' => array(
|
|
|
|
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Comment' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Article->find('all', array('contain' => array('User' => 'ArticleFeatured')));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
|
|
|
|
'ArticleFeatured' => 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' => 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'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31',
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
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(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
|
|
|
|
'ArticleFeatured' => 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' => 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'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Article->find('all', array('contain' => array('User' => array('ArticleFeatured', 'Comment'))));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
|
|
|
|
'ArticleFeatured' => 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' => 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'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
|
|
|
|
'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31',
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
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'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array()
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
|
|
|
|
'ArticleFeatured' => 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' => 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'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
|
|
|
|
'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Article->find('all', array('contain' => array('User' => 'ArticleFeatured', 'Tag', 'Comment' => 'Attachment')));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
|
|
|
|
'ArticleFeatured' => 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' => 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'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
|
|
|
|
'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Tag' => array(
|
|
|
|
array('id' => 1, 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'),
|
|
|
|
array('id' => 2, 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31')
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31',
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
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'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
|
|
|
|
'Attachment' => array(
|
|
|
|
'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
|
|
|
|
'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Tag' => array(
|
|
|
|
array('id' => 1, 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'),
|
|
|
|
array('id' => 3, 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31')
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
|
|
|
|
'ArticleFeatured' => 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' => 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'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(),
|
|
|
|
'Tag' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFindThirdLevel method
|
2008-06-23 04:41:15 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFindThirdLevel() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->User->contain(array('ArticleFeatured' => array('Featured' => 'Category')));
|
|
|
|
$result = $this->User->find('all', array('recursive' => 3));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => 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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32: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',
|
|
|
|
'Featured' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->User->contain(array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment'))));
|
|
|
|
$result = $this->User->find('all', array('recursive' => 3));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => 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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
|
|
|
|
'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
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',
|
|
|
|
'Featured' => array(),
|
|
|
|
'Comment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array(
|
|
|
|
'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
|
|
|
|
'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->User->contain(array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => 'Attachment'), 'Article'));
|
|
|
|
$result = $this->User->find('all', array('recursive' => 3));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
),
|
|
|
|
'Article' => 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' => 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'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => 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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
|
|
|
|
'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
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',
|
|
|
|
'Featured' => array(),
|
|
|
|
'Comment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
|
|
|
),
|
|
|
|
'Article' => array(),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
|
|
|
),
|
|
|
|
'Article' => array(
|
|
|
|
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'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
|
|
|
|
'Attachment' => array(
|
|
|
|
'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
|
|
|
|
'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
|
|
|
|
),
|
|
|
|
'Article' => array(),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFindEmbeddedThirdLevel method
|
2008-06-23 04:41:15 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFindEmbeddedThirdLevel() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => 'Category'))));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => 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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32: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',
|
|
|
|
'Featured' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment')))));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => 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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
|
|
|
|
'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
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',
|
|
|
|
'Featured' => array(),
|
|
|
|
'Comment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array(
|
|
|
|
'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
|
|
|
|
'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => 'Attachment'), 'Article')));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
),
|
|
|
|
'Article' => 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' => 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'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => 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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
|
|
|
|
'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
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',
|
|
|
|
'Featured' => array(),
|
|
|
|
'Comment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
|
|
|
),
|
|
|
|
'Article' => array(),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
|
|
|
),
|
|
|
|
'Article' => array(
|
|
|
|
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'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
|
|
|
|
'Attachment' => array(
|
|
|
|
'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
|
|
|
|
'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
|
|
|
|
),
|
|
|
|
'Article' => array(),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testSettingsThirdLevel method
|
2008-06-23 04:41:15 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSettingsThirdLevel() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => array('Category' => array('id', 'name'))))));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => 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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'name' => 'Category 1'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
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',
|
|
|
|
'Featured' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'name' => 'Category 1'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$r = $this->User->find('all', array('contain' => array(
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
'id', 'title',
|
|
|
|
'Featured' => array(
|
|
|
|
'id', 'category_id',
|
|
|
|
'Category' => array('id', 'name')
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)));
|
|
|
|
|
|
|
|
$this->assertTrue(Set::matches('/User[id=1]', $r));
|
|
|
|
$this->assertFalse(Set::matches('/Article', $r) || Set::matches('/Comment', $r));
|
|
|
|
$this->assertTrue(Set::matches('/ArticleFeatured', $r));
|
|
|
|
$this->assertFalse(Set::matches('/ArticleFeatured/User', $r) || Set::matches('/ArticleFeatured/Comment', $r) || Set::matches('/ArticleFeatured/Tag', $r));
|
|
|
|
$this->assertTrue(Set::matches('/ArticleFeatured/Featured', $r));
|
|
|
|
$this->assertFalse(Set::matches('/ArticleFeatured/Featured/ArticleFeatured', $r));
|
|
|
|
$this->assertTrue(Set::matches('/ArticleFeatured/Featured/Category', $r));
|
|
|
|
$this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]', $r));
|
|
|
|
$this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]/Category[id=1]', $r));
|
|
|
|
$this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]/Category[name=Category 1]', $r));
|
|
|
|
|
|
|
|
$r = $this->User->find('all', array('contain' => array(
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
'title',
|
|
|
|
'Featured' => array(
|
|
|
|
'id',
|
|
|
|
'Category' => 'name'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)));
|
|
|
|
|
|
|
|
$this->assertTrue(Set::matches('/User[id=1]', $r));
|
|
|
|
$this->assertFalse(Set::matches('/Article', $r) || Set::matches('/Comment', $r));
|
|
|
|
$this->assertTrue(Set::matches('/ArticleFeatured', $r));
|
|
|
|
$this->assertFalse(Set::matches('/ArticleFeatured/User', $r) || Set::matches('/ArticleFeatured/Comment', $r) || Set::matches('/ArticleFeatured/Tag', $r));
|
|
|
|
$this->assertTrue(Set::matches('/ArticleFeatured/Featured', $r));
|
|
|
|
$this->assertFalse(Set::matches('/ArticleFeatured/Featured/ArticleFeatured', $r));
|
|
|
|
$this->assertTrue(Set::matches('/ArticleFeatured/Featured/Category', $r));
|
|
|
|
$this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]', $r));
|
|
|
|
$this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]/Category[name=Category 1]', $r));
|
|
|
|
|
|
|
|
$result = $this->User->find('all', array('contain' => array(
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
'title',
|
|
|
|
'Featured' => array(
|
|
|
|
'category_id',
|
|
|
|
'Category' => 'name'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
array(
|
|
|
|
'title' => 'First Article', 'id' => 1, 'user_id' => 1,
|
|
|
|
'Featured' => array(
|
|
|
|
'category_id' => 1, 'id' => 1,
|
|
|
|
'Category' => array(
|
|
|
|
'name' => 'Category 1'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => 'Third Article', 'id' => 3, 'user_id' => 1,
|
|
|
|
'Featured' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
array(
|
|
|
|
'title' => 'Second Article', 'id' => 2, 'user_id' => 3,
|
|
|
|
'Featured' => array(
|
|
|
|
'category_id' => 1, 'id' => 2,
|
|
|
|
'Category' => array(
|
|
|
|
'name' => 'Category 1'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2009-08-02 06:47:28 +00:00
|
|
|
$orders = array(
|
|
|
|
'title DESC', 'title DESC, published DESC',
|
|
|
|
array('title' => 'DESC'), array('title' => 'DESC', 'published' => 'DESC'),
|
|
|
|
);
|
|
|
|
foreach ($orders as $order) {
|
|
|
|
$result = $this->User->find('all', array('contain' => array(
|
2008-05-30 11:40:08 +00:00
|
|
|
'ArticleFeatured' => array(
|
2009-08-02 06:47:28 +00:00
|
|
|
'title', 'order' => $order,
|
|
|
|
'Featured' => array(
|
|
|
|
'category_id',
|
|
|
|
'Category' => 'name'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
2008-05-30 11:40:08 +00:00
|
|
|
),
|
2009-08-02 06:47:28 +00:00
|
|
|
'ArticleFeatured' => array(
|
|
|
|
array(
|
|
|
|
'title' => 'Third Article', 'id' => 3, 'user_id' => 1,
|
|
|
|
'Featured' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => 'First Article', 'id' => 1, 'user_id' => 1,
|
|
|
|
'Featured' => array(
|
|
|
|
'category_id' => 1, 'id' => 1,
|
|
|
|
'Category' => array(
|
|
|
|
'name' => 'Category 1'
|
|
|
|
)
|
2008-05-30 11:40:08 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
2009-08-02 06:47:28 +00:00
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
2008-05-30 11:40:08 +00:00
|
|
|
),
|
2009-08-02 06:47:28 +00:00
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
array(
|
|
|
|
'title' => 'Second Article', 'id' => 2, 'user_id' => 3,
|
|
|
|
'Featured' => array(
|
|
|
|
'category_id' => 1, 'id' => 2,
|
|
|
|
'Category' => array(
|
|
|
|
'name' => 'Category 1'
|
|
|
|
)
|
2008-05-30 11:40:08 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
2009-08-02 06:47:28 +00:00
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-08-02 06:47:28 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFindThirdLevelNonReset method
|
2008-06-23 04:41:15 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFindThirdLevelNonReset() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->User->contain(false, array('ArticleFeatured' => array('Featured' => 'Category')));
|
|
|
|
$result = $this->User->find('all', array('recursive' => 3));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => 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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32: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',
|
|
|
|
'Featured' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->User->resetBindings();
|
|
|
|
|
|
|
|
$this->User->contain(false, array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment'))));
|
|
|
|
$result = $this->User->find('all', array('recursive' => 3));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => 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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
|
|
|
|
'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
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',
|
|
|
|
'Featured' => array(),
|
|
|
|
'Comment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array(
|
|
|
|
'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
|
|
|
|
'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->User->resetBindings();
|
|
|
|
|
|
|
|
$this->User->contain(false, array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => 'Attachment'), 'Article'));
|
|
|
|
$result = $this->User->find('all', array('recursive' => 3));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
),
|
|
|
|
'Article' => 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' => 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'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => 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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
|
|
|
|
'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
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',
|
|
|
|
'Featured' => array(),
|
|
|
|
'Comment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
|
|
|
),
|
|
|
|
'Article' => array(),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
|
|
|
),
|
|
|
|
'Article' => array(
|
|
|
|
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'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
|
|
|
|
'Attachment' => array(
|
|
|
|
'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
|
|
|
|
'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
|
|
|
|
),
|
|
|
|
'Article' => array(),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFindEmbeddedThirdLevelNonReset method
|
2008-06-23 04:41:15 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFindEmbeddedThirdLevelNonReset() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->User->find('all', array('reset' => false, 'contain' => array('ArticleFeatured' => array('Featured' => 'Category'))));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => 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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32: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',
|
|
|
|
'Featured' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-02-17 07:32:35 +00:00
|
|
|
$this->_assertBindings($this->User, array('hasMany' => array('ArticleFeatured')));
|
|
|
|
$this->_assertBindings($this->User->ArticleFeatured, array('hasOne' => array('Featured')));
|
|
|
|
$this->_assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('Category')));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->User->resetBindings();
|
|
|
|
|
2012-02-17 07:32:35 +00:00
|
|
|
$this->_assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured', 'Comment')));
|
|
|
|
$this->_assertBindings($this->User->ArticleFeatured, array('belongsTo' => array('User'), 'hasOne' => array('Featured'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag')));
|
|
|
|
$this->_assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('ArticleFeatured', 'Category')));
|
|
|
|
$this->_assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article', 'User'), 'hasOne' => array('Attachment')));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->User->find('all', array('reset' => false, 'contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment')))));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => 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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
|
|
|
|
'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
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',
|
|
|
|
'Featured' => array(),
|
|
|
|
'Comment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array(
|
|
|
|
'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
|
|
|
|
'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-02-17 07:32:35 +00:00
|
|
|
$this->_assertBindings($this->User, array('hasMany' => array('ArticleFeatured')));
|
|
|
|
$this->_assertBindings($this->User->ArticleFeatured, array('hasOne' => array('Featured'), 'hasMany' => array('Comment')));
|
|
|
|
$this->_assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('Category')));
|
|
|
|
$this->_assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article'), 'hasOne' => array('Attachment')));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->User->resetBindings();
|
2012-02-17 07:32:35 +00:00
|
|
|
$this->_assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured', 'Comment')));
|
|
|
|
$this->_assertBindings($this->User->ArticleFeatured, array('belongsTo' => array('User'), 'hasOne' => array('Featured'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag')));
|
|
|
|
$this->_assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('ArticleFeatured', 'Category')));
|
|
|
|
$this->_assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article', 'User'), 'hasOne' => array('Attachment')));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment')), false)));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => 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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
|
|
|
|
'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
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',
|
|
|
|
'Featured' => array(),
|
|
|
|
'Comment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array(
|
|
|
|
'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
|
|
|
|
'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
|
|
|
|
'Article' => 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'
|
|
|
|
),
|
|
|
|
'Attachment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-02-17 07:32:35 +00:00
|
|
|
$this->_assertBindings($this->User, array('hasMany' => array('ArticleFeatured')));
|
|
|
|
$this->_assertBindings($this->User->ArticleFeatured, array('hasOne' => array('Featured'), 'hasMany' => array('Comment')));
|
|
|
|
$this->_assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('Category')));
|
|
|
|
$this->_assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article'), 'hasOne' => array('Attachment')));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->User->resetBindings();
|
2012-02-17 07:32:35 +00:00
|
|
|
$this->_assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured', 'Comment')));
|
|
|
|
$this->_assertBindings($this->User->ArticleFeatured, array('belongsTo' => array('User'), 'hasOne' => array('Featured'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag')));
|
|
|
|
$this->_assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('ArticleFeatured', 'Category')));
|
|
|
|
$this->_assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article', 'User'), 'hasOne' => array('Attachment')));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->User->find('all', array('reset' => false, 'contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => 'Attachment'), 'Article')));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
|
|
|
),
|
|
|
|
'Article' => 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' => 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'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => 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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
|
|
|
|
'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
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',
|
|
|
|
'Featured' => array(),
|
|
|
|
'Comment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
|
|
|
),
|
|
|
|
'Article' => array(),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
|
|
|
),
|
|
|
|
'Article' => array(
|
|
|
|
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'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'ArticleFeatured' => array(
|
|
|
|
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',
|
|
|
|
'Featured' => 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',
|
|
|
|
'Category' => array(
|
|
|
|
'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
|
|
|
|
'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Comment' => array(
|
|
|
|
array(
|
|
|
|
'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
|
|
|
|
'Attachment' => array(
|
|
|
|
'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
|
|
|
|
'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
|
|
|
|
'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
|
|
|
|
'Attachment' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'User' => array(
|
|
|
|
'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
|
|
|
'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
|
|
|
|
),
|
|
|
|
'Article' => array(),
|
|
|
|
'ArticleFeatured' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-02-17 07:32:35 +00:00
|
|
|
$this->_assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured')));
|
|
|
|
$this->_assertBindings($this->User->Article);
|
|
|
|
$this->_assertBindings($this->User->ArticleFeatured, array('hasOne' => array('Featured'), 'hasMany' => array('Comment')));
|
|
|
|
$this->_assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('Category')));
|
|
|
|
$this->_assertBindings($this->User->ArticleFeatured->Comment, array('hasOne' => array('Attachment')));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->User->resetBindings();
|
2012-02-17 07:32:35 +00:00
|
|
|
$this->_assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured', 'Comment')));
|
|
|
|
$this->_assertBindings($this->User->Article, array('belongsTo' => array('User'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag')));
|
|
|
|
$this->_assertBindings($this->User->ArticleFeatured, array('belongsTo' => array('User'), 'hasOne' => array('Featured'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag')));
|
|
|
|
$this->_assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('ArticleFeatured', 'Category')));
|
|
|
|
$this->_assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article', 'User'), 'hasOne' => array('Attachment')));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testEmbeddedFindFields method
|
2008-06-23 04:41:15 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testEmbeddedFindFields() {
|
2010-04-06 01:43:16 +00:00
|
|
|
$result = $this->Article->find('all', array(
|
|
|
|
'contain' => array('User(user)'),
|
2011-11-16 12:15:14 +00:00
|
|
|
'fields' => array('title'),
|
|
|
|
'order' => array('Article.id' => 'ASC')
|
2010-04-06 01:43:16 +00:00
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array('Article' => array('title' => 'First Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
|
|
|
|
array('Article' => array('title' => 'Second Article'), 'User' => array('user' => 'larry', 'id' => 3)),
|
|
|
|
array('Article' => array('title' => 'Third Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-04-06 01:43:16 +00:00
|
|
|
$result = $this->Article->find('all', array(
|
|
|
|
'contain' => array('User(id, user)'),
|
2011-11-16 12:15:14 +00:00
|
|
|
'fields' => array('title'),
|
|
|
|
'order' => array('Article.id' => 'ASC')
|
2010-04-06 01:43:16 +00:00
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array('Article' => array('title' => 'First Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
|
|
|
|
array('Article' => array('title' => 'Second Article'), 'User' => array('user' => 'larry', 'id' => 3)),
|
|
|
|
array('Article' => array('title' => 'Third Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-04-06 01:43:16 +00:00
|
|
|
$result = $this->Article->find('all', array(
|
|
|
|
'contain' => array(
|
|
|
|
'Comment(comment, published)' => 'Attachment(attachment)', 'User(user)'
|
|
|
|
),
|
2011-11-16 12:15:14 +00:00
|
|
|
'fields' => array('title'),
|
|
|
|
'order' => array('Article.id' => 'ASC')
|
2010-04-06 01:43:16 +00:00
|
|
|
));
|
2009-03-14 22:24:42 +00:00
|
|
|
if (!empty($result)) {
|
2011-11-30 15:44:11 +00:00
|
|
|
foreach ($result as $i => $article) {
|
|
|
|
foreach ($article['Comment'] as $j => $comment) {
|
2011-12-01 07:21:31 +00:00
|
|
|
$result[$i]['Comment'][$j] = array_diff_key($comment, array('id' => true));
|
2009-03-14 22:24:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'Article' => array('title' => 'First Article', 'id' => 1),
|
|
|
|
'User' => array('user' => 'mariano', 'id' => 1),
|
|
|
|
'Comment' => array(
|
2009-03-14 22:24:42 +00:00
|
|
|
array('comment' => 'First Comment for First Article', 'published' => 'Y', 'article_id' => 1, 'Attachment' => array()),
|
|
|
|
array('comment' => 'Second Comment for First Article', 'published' => 'Y', 'article_id' => 1, 'Attachment' => array()),
|
|
|
|
array('comment' => 'Third Comment for First Article', 'published' => 'Y', 'article_id' => 1, 'Attachment' => array()),
|
|
|
|
array('comment' => 'Fourth Comment for First Article', 'published' => 'N', 'article_id' => 1, 'Attachment' => array()),
|
2008-05-30 11:40:08 +00:00
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => array('title' => 'Second Article', 'id' => 2),
|
|
|
|
'User' => array('user' => 'larry', 'id' => 3),
|
|
|
|
'Comment' => array(
|
2009-03-14 22:24:42 +00:00
|
|
|
array('comment' => 'First Comment for Second Article', 'published' => 'Y', 'article_id' => 2, 'Attachment' => array(
|
2008-05-30 11:40:08 +00:00
|
|
|
'attachment' => 'attachment.zip', 'id' => 1
|
|
|
|
)),
|
2009-03-14 22:24:42 +00:00
|
|
|
array('comment' => 'Second Comment for Second Article', 'published' => 'Y', 'article_id' => 2, 'Attachment' => array())
|
2008-05-30 11:40:08 +00:00
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => array('title' => 'Third Article', 'id' => 3),
|
|
|
|
'User' => array('user' => 'mariano', 'id' => 1),
|
|
|
|
'Comment' => array()
|
|
|
|
),
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-04-06 01:43:16 +00:00
|
|
|
/**
|
|
|
|
* test that hasOne and belongsTo fields act the same in a contain array.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testHasOneFieldsInContain() {
|
2010-04-06 01:43:16 +00:00
|
|
|
$this->Article->unbindModel(array(
|
|
|
|
'hasMany' => array('Comment')
|
|
|
|
), true);
|
|
|
|
unset($this->Article->Comment);
|
|
|
|
$this->Article->bindModel(array(
|
|
|
|
'hasOne' => array('Comment')
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = $this->Article->find('all', array(
|
|
|
|
'fields' => array('title', 'body'),
|
|
|
|
'contain' => array(
|
|
|
|
'Comment' => array(
|
|
|
|
'fields' => array('comment')
|
|
|
|
),
|
|
|
|
'User' => array(
|
|
|
|
'fields' => array('user')
|
|
|
|
)
|
2012-11-10 19:24:30 +00:00
|
|
|
),
|
|
|
|
'order' => 'Article.id ASC',
|
2010-04-06 01:43:16 +00:00
|
|
|
));
|
|
|
|
$this->assertTrue(isset($result[0]['Article']['title']), 'title missing %s');
|
|
|
|
$this->assertTrue(isset($result[0]['Article']['body']), 'body missing %s');
|
|
|
|
$this->assertTrue(isset($result[0]['Comment']['comment']), 'comment missing %s');
|
|
|
|
$this->assertTrue(isset($result[0]['User']['user']), 'body missing %s');
|
|
|
|
$this->assertFalse(isset($result[0]['Comment']['published']), 'published found %s');
|
|
|
|
$this->assertFalse(isset($result[0]['User']['password']), 'password found %s');
|
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFindConditionalBinding method
|
2008-06-23 04:41:15 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFindConditionalBinding() {
|
2010-04-06 01:43:16 +00:00
|
|
|
$this->Article->contain(array(
|
|
|
|
'User(user)',
|
|
|
|
'Tag' => array(
|
|
|
|
'fields' => array('tag', 'created'),
|
|
|
|
'conditions' => array('created >=' => '2007-03-18 12:24')
|
|
|
|
)
|
|
|
|
));
|
2012-11-10 19:24:30 +00:00
|
|
|
$result = $this->Article->find('all', array(
|
|
|
|
'fields' => array('title'),
|
|
|
|
'order' => array('Article.id' => 'ASC')
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'Article' => array('id' => 1, 'title' => 'First Article'),
|
|
|
|
'User' => array('id' => 1, 'user' => 'mariano'),
|
|
|
|
'Tag' => array(array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23'))
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => array('id' => 2, 'title' => 'Second Article'),
|
|
|
|
'User' => array('id' => 3, 'user' => 'larry'),
|
|
|
|
'Tag' => array(array('tag' => 'tag3', 'created' => '2007-03-18 12:26:23'))
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => array('id' => 3, 'title' => 'Third Article'),
|
|
|
|
'User' => array('id' => 1, 'user' => 'mariano'),
|
|
|
|
'Tag' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->Article->contain(array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created'))));
|
2011-11-16 12:15:14 +00:00
|
|
|
$result = $this->Article->find('all', array('fields' => array('title'), 'order' => array('Article.id' => 'ASC')));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'Article' => array('id' => 1, 'title' => 'First Article'),
|
|
|
|
'User' => array('id' => 1, 'user' => 'mariano'),
|
|
|
|
'Tag' => array(
|
|
|
|
array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'),
|
|
|
|
array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23')
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => array('id' => 2, 'title' => 'Second Article'),
|
|
|
|
'User' => array('id' => 3, 'user' => 'larry'),
|
|
|
|
'Tag' => array(
|
|
|
|
array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'),
|
|
|
|
array('tag' => 'tag3', 'created' => '2007-03-18 12:26:23')
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => array('id' => 3, 'title' => 'Third Article'),
|
|
|
|
'User' => array('id' => 1, 'user' => 'mariano'),
|
|
|
|
'Tag' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Article->find('all', array(
|
|
|
|
'fields' => array('title'),
|
2011-11-16 12:15:14 +00:00
|
|
|
'contain' => array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created'))),
|
|
|
|
'order' => array('Article.id' => 'ASC')
|
2008-05-30 11:40:08 +00:00
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'Article' => array('id' => 1, 'title' => 'First Article'),
|
|
|
|
'User' => array('id' => 1, 'user' => 'mariano'),
|
|
|
|
'Tag' => array(
|
|
|
|
array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'),
|
|
|
|
array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23')
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => array('id' => 2, 'title' => 'Second Article'),
|
|
|
|
'User' => array('id' => 3, 'user' => 'larry'),
|
|
|
|
'Tag' => array(
|
|
|
|
array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'),
|
|
|
|
array('tag' => 'tag3', 'created' => '2007-03-18 12:26:23')
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => array('id' => 3, 'title' => 'Third Article'),
|
|
|
|
'User' => array('id' => 1, 'user' => 'mariano'),
|
|
|
|
'Tag' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-04-06 01:43:16 +00:00
|
|
|
$this->Article->contain(array(
|
|
|
|
'User(id,user)',
|
|
|
|
'Tag' => array(
|
|
|
|
'fields' => array('tag', 'created'),
|
|
|
|
'conditions' => array('created >=' => '2007-03-18 12:24')
|
|
|
|
)
|
|
|
|
));
|
2011-11-16 12:15:14 +00:00
|
|
|
$result = $this->Article->find('all', array('fields' => array('title'), 'order' => array('Article.id' => 'ASC')));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array(
|
|
|
|
'Article' => array('id' => 1, 'title' => 'First Article'),
|
|
|
|
'User' => array('id' => 1, 'user' => 'mariano'),
|
|
|
|
'Tag' => array(array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23'))
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => array('id' => 2, 'title' => 'Second Article'),
|
|
|
|
'User' => array('id' => 3, 'user' => 'larry'),
|
|
|
|
'Tag' => array(array('tag' => 'tag3', 'created' => '2007-03-18 12:26:23'))
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Article' => array('id' => 3, 'title' => 'Third Article'),
|
|
|
|
'User' => array('id' => 1, 'user' => 'mariano'),
|
|
|
|
'Tag' => array()
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-06-23 04:41:15 +00:00
|
|
|
|
2008-06-21 23:41:54 +00:00
|
|
|
$this->assertTrue(empty($this->User->Article->hasAndBelongsToMany['Tag']['conditions']));
|
2008-06-23 04:41:15 +00:00
|
|
|
|
2008-06-21 23:41:54 +00:00
|
|
|
$result = $this->User->find('all', array('contain' => array(
|
|
|
|
'Article.Tag' => array('conditions' => array('created >=' => '2007-03-18 12:24'))
|
|
|
|
)));
|
2008-06-23 04:41:15 +00:00
|
|
|
|
2008-06-21 23:41:54 +00:00
|
|
|
$this->assertTrue(Set::matches('/User[id=1]', $result));
|
|
|
|
$this->assertFalse(Set::matches('/Article[id=1]/Tag[id=1]', $result));
|
|
|
|
$this->assertTrue(Set::matches('/Article[id=1]/Tag[id=2]', $result));
|
|
|
|
$this->assertTrue(empty($this->User->Article->hasAndBelongsToMany['Tag']['conditions']));
|
2008-06-23 04:41:15 +00:00
|
|
|
|
2008-06-21 23:41:54 +00:00
|
|
|
$this->assertTrue(empty($this->User->Article->hasAndBelongsToMany['Tag']['order']));
|
2008-06-23 04:41:15 +00:00
|
|
|
|
2008-06-21 23:41:54 +00:00
|
|
|
$result = $this->User->find('all', array('contain' => array(
|
|
|
|
'Article.Tag' => array('order' => 'created DESC')
|
|
|
|
)));
|
2008-06-23 04:41:15 +00:00
|
|
|
|
2008-06-21 23:41:54 +00:00
|
|
|
$this->assertTrue(Set::matches('/User[id=1]', $result));
|
|
|
|
$this->assertTrue(Set::matches('/Article[id=1]/Tag[id=1]', $result));
|
|
|
|
$this->assertTrue(Set::matches('/Article[id=1]/Tag[id=2]', $result));
|
|
|
|
$this->assertTrue(empty($this->User->Article->hasAndBelongsToMany['Tag']['order']));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testOtherFinds method
|
2008-06-23 04:41:15 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testOtherFinds() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Article->find('count');
|
|
|
|
$expected = 3;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-05-31 12:36:38 +00:00
|
|
|
$result = $this->Article->find('count', array('conditions' => array('Article.id >' => '1')));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = 2;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Article->find('count', array('contain' => array()));
|
|
|
|
$expected = 3;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-05-31 12:36:38 +00:00
|
|
|
$this->Article->contain(array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created'), 'conditions' => array('created >=' => '2007-03-18 12:24'))));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Article->find('first', array('fields' => array('title')));
|
|
|
|
$expected = array(
|
|
|
|
'Article' => array('id' => 1, 'title' => 'First Article'),
|
|
|
|
'User' => array('id' => 1, 'user' => 'mariano'),
|
|
|
|
'Tag' => array(array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23'))
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->Article->contain(array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created'))));
|
|
|
|
$result = $this->Article->find('first', array('fields' => array('title')));
|
|
|
|
$expected = array(
|
|
|
|
'Article' => array('id' => 1, 'title' => 'First Article'),
|
|
|
|
'User' => array('id' => 1, 'user' => 'mariano'),
|
|
|
|
'Tag' => array(
|
|
|
|
array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'),
|
|
|
|
array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23')
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Article->find('first', array(
|
|
|
|
'fields' => array('title'),
|
|
|
|
'order' => 'Article.id DESC',
|
|
|
|
'contain' => array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created')))
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'Article' => array('id' => 3, 'title' => 'Third Article'),
|
|
|
|
'User' => array('id' => 1, 'user' => 'mariano'),
|
|
|
|
'Tag' => array()
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Article->find('list', array(
|
|
|
|
'contain' => array('User(id,user)'),
|
|
|
|
'fields' => array('Article.id', 'Article.title')
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
1 => 'First Article',
|
|
|
|
2 => 'Second Article',
|
|
|
|
3 => 'Third Article'
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-22 00:02:30 +00:00
|
|
|
/**
|
2008-06-05 15:20:45 +00:00
|
|
|
* testOriginalAssociations method
|
2008-06-23 04:41:15 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testOriginalAssociations() {
|
2008-06-03 02:41:29 +00:00
|
|
|
$this->Article->Comment->Behaviors->attach('Containable');
|
2008-06-23 04:41:15 +00:00
|
|
|
|
|
|
|
$options = array(
|
|
|
|
'conditions' => array(
|
|
|
|
'Comment.published' => 'Y',
|
|
|
|
),
|
|
|
|
'contain' => 'User',
|
|
|
|
'recursive' => 1
|
|
|
|
);
|
|
|
|
|
|
|
|
$firstResult = $this->Article->Comment->find('all', $options);
|
|
|
|
|
2013-01-23 12:45:50 +00:00
|
|
|
$this->Article->Comment->find('all', array(
|
2008-06-23 04:41:15 +00:00
|
|
|
'conditions' => array(
|
|
|
|
'User.user' => 'mariano'
|
|
|
|
),
|
|
|
|
'fields' => array('User.password'),
|
|
|
|
'contain' => array('User.password'),
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = $this->Article->Comment->find('all', $options);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($firstResult, $result);
|
2008-06-23 04:41:15 +00:00
|
|
|
|
2008-06-02 18:05:45 +00:00
|
|
|
$this->Article->unbindModel(array('hasMany' => array('Comment'), 'belongsTo' => array('User'), 'hasAndBelongsToMany' => array('Tag')), false);
|
|
|
|
$this->Article->bindModel(array('hasMany' => array('Comment'), 'belongsTo' => array('User')), false);
|
2008-06-23 04:41:15 +00:00
|
|
|
|
2008-06-02 18:05:45 +00:00
|
|
|
$r = $this->Article->find('all', array('contain' => array('Comment(comment)', 'User(user)'), 'fields' => array('title')));
|
|
|
|
$this->assertTrue(Set::matches('/Article[id=1]', $r));
|
|
|
|
$this->assertTrue(Set::matches('/User[id=1]', $r));
|
|
|
|
$this->assertTrue(Set::matches('/Comment[article_id=1]', $r));
|
|
|
|
$this->assertFalse(Set::matches('/Comment[id=1]', $r));
|
2008-06-23 04:41:15 +00:00
|
|
|
|
2008-06-02 18:05:45 +00:00
|
|
|
$r = $this->Article->find('all');
|
|
|
|
$this->assertTrue(Set::matches('/Article[id=1]', $r));
|
|
|
|
$this->assertTrue(Set::matches('/User[id=1]', $r));
|
|
|
|
$this->assertTrue(Set::matches('/Comment[article_id=1]', $r));
|
|
|
|
$this->assertTrue(Set::matches('/Comment[id=1]', $r));
|
2008-06-23 04:41:15 +00:00
|
|
|
|
2008-06-03 14:12:38 +00:00
|
|
|
$this->Article->bindModel(array('hasAndBelongsToMany' => array('Tag')), false);
|
2008-06-23 04:41:15 +00:00
|
|
|
|
|
|
|
$this->Article->contain(false, array('User(id,user)', 'Comment' => array('fields' => array('comment'), 'conditions' => array('created >=' => '2007-03-18 10:49'))));
|
2008-06-03 14:12:38 +00:00
|
|
|
$result = $this->Article->find('all', array('fields' => array('title'), 'limit' => 1, 'page' => 1, 'order' => 'Article.id ASC'));
|
2008-06-23 04:41:15 +00:00
|
|
|
$expected = array(array(
|
|
|
|
'Article' => array('id' => 1, 'title' => 'First Article'),
|
|
|
|
'User' => array('id' => 1, 'user' => 'mariano'),
|
2008-06-03 14:12:38 +00:00
|
|
|
'Comment' => array(
|
|
|
|
array('comment' => 'Third Comment for First Article', 'article_id' => 1),
|
|
|
|
array('comment' => 'Fourth Comment for First Article', 'article_id' => 1)
|
2008-06-23 04:41:15 +00:00
|
|
|
)
|
|
|
|
));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-06-23 04:41:15 +00:00
|
|
|
|
|
|
|
$result = $this->Article->find('all', array('fields' => array('title', 'User.id', 'User.user'), 'limit' => 1, 'page' => 2, 'order' => 'Article.id ASC'));
|
|
|
|
$expected = array(array(
|
|
|
|
'Article' => array('id' => 2, 'title' => 'Second Article'),
|
|
|
|
'User' => array('id' => 3, 'user' => 'larry'),
|
2008-06-03 14:12:38 +00:00
|
|
|
'Comment' => array(
|
|
|
|
array('comment' => 'First Comment for Second Article', 'article_id' => 2),
|
|
|
|
array('comment' => 'Second Comment for Second Article', 'article_id' => 2)
|
2008-06-23 04:41:15 +00:00
|
|
|
)
|
|
|
|
));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-06-23 04:41:15 +00:00
|
|
|
|
|
|
|
$result = $this->Article->find('all', array('fields' => array('title', 'User.id', 'User.user'), 'limit' => 1, 'page' => 3, 'order' => 'Article.id ASC'));
|
|
|
|
$expected = array(array(
|
|
|
|
'Article' => array('id' => 3, 'title' => 'Third Article'),
|
|
|
|
'User' => array('id' => 1, 'user' => 'mariano'),
|
|
|
|
'Comment' => array()
|
|
|
|
));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-06-23 04:41:15 +00:00
|
|
|
|
2008-06-21 23:52:38 +00:00
|
|
|
$this->Article->contain(false, array('User' => array('fields' => 'user'), 'Comment'));
|
|
|
|
$result = $this->Article->find('all');
|
2008-06-21 23:55:03 +00:00
|
|
|
$this->assertTrue(Set::matches('/Article[id=1]', $result));
|
|
|
|
$this->assertTrue(Set::matches('/User[user=mariano]', $result));
|
|
|
|
$this->assertTrue(Set::matches('/Comment[article_id=1]', $result));
|
2008-06-21 23:54:00 +00:00
|
|
|
$this->Article->resetBindings();
|
2008-06-23 04:41:15 +00:00
|
|
|
|
2008-06-21 23:54:00 +00:00
|
|
|
$this->Article->contain(false, array('User' => array('fields' => array('user')), 'Comment'));
|
|
|
|
$result = $this->Article->find('all');
|
2008-06-21 23:55:03 +00:00
|
|
|
$this->assertTrue(Set::matches('/Article[id=1]', $result));
|
|
|
|
$this->assertTrue(Set::matches('/User[user=mariano]', $result));
|
|
|
|
$this->assertTrue(Set::matches('/Comment[article_id=1]', $result));
|
2008-06-21 23:52:38 +00:00
|
|
|
$this->Article->resetBindings();
|
2008-05-31 02:59:55 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-03-14 19:34:57 +00:00
|
|
|
/**
|
|
|
|
* testResetAddedAssociation method
|
|
|
|
*
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testResetAddedAssociation() {
|
2010-03-14 19:34:57 +00:00
|
|
|
$this->assertTrue(empty($this->Article->hasMany['ArticlesTag']));
|
|
|
|
|
|
|
|
$this->Article->bindModel(array(
|
|
|
|
'hasMany' => array('ArticlesTag')
|
|
|
|
));
|
|
|
|
$this->assertTrue(!empty($this->Article->hasMany['ArticlesTag']));
|
|
|
|
|
|
|
|
$result = $this->Article->find('first', array(
|
|
|
|
'conditions' => array('Article.id' => 1),
|
|
|
|
'contain' => array('ArticlesTag')
|
|
|
|
));
|
2010-12-12 20:48:36 +00:00
|
|
|
|
2010-03-14 19:34:57 +00:00
|
|
|
$expected = array('Article', 'ArticlesTag');
|
|
|
|
$this->assertTrue(!empty($result));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals('First Article', $result['Article']['title']);
|
2010-03-14 19:34:57 +00:00
|
|
|
$this->assertTrue(!empty($result['ArticlesTag']));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, array_keys($result));
|
2010-03-14 19:34:57 +00:00
|
|
|
|
|
|
|
$this->assertTrue(empty($this->Article->hasMany['ArticlesTag']));
|
2011-10-28 05:01:17 +00:00
|
|
|
|
2011-11-13 01:43:55 +00:00
|
|
|
$this->JoinA = ClassRegistry::init('JoinA');
|
|
|
|
$this->JoinB = ClassRegistry::init('JoinB');
|
|
|
|
$this->JoinC = ClassRegistry::init('JoinC');
|
2011-10-28 05:01:17 +00:00
|
|
|
|
2011-08-31 06:10:59 +00:00
|
|
|
$this->JoinA->Behaviors->attach('Containable');
|
|
|
|
$this->JoinB->Behaviors->attach('Containable');
|
|
|
|
$this->JoinC->Behaviors->attach('Containable');
|
2011-10-28 05:01:17 +00:00
|
|
|
|
2011-08-31 06:10:59 +00:00
|
|
|
$this->JoinA->JoinB->find('all', array('contain' => array('JoinA')));
|
|
|
|
$this->JoinA->bindModel(array('hasOne' => array('JoinAsJoinC' => array('joinTable' => 'as_cs'))), false);
|
|
|
|
$result = $this->JoinA->hasOne;
|
|
|
|
$this->JoinA->find('all');
|
|
|
|
$resultAfter = $this->JoinA->hasOne;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($result, $resultAfter);
|
2010-03-14 19:34:57 +00:00
|
|
|
}
|
2010-03-16 03:26:24 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2008-06-22 00:02:30 +00:00
|
|
|
* testResetAssociation method
|
2008-06-23 04:41:15 +00:00
|
|
|
*
|
2008-06-22 00:02:30 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testResetAssociation() {
|
2008-06-23 04:41:15 +00:00
|
|
|
$this->Article->Behaviors->attach('Containable');
|
|
|
|
$this->Article->Comment->Behaviors->attach('Containable');
|
|
|
|
$this->Article->User->Behaviors->attach('Containable');
|
|
|
|
|
2008-06-22 00:02:30 +00:00
|
|
|
$initialOptions = array(
|
|
|
|
'conditions' => array(
|
2008-06-23 04:41:15 +00:00
|
|
|
'Comment.published' => 'Y',
|
|
|
|
),
|
|
|
|
'contain' => 'User',
|
|
|
|
'recursive' => 1,
|
|
|
|
);
|
|
|
|
|
|
|
|
$initialModels = $this->Article->Comment->find('all', $initialOptions);
|
|
|
|
|
|
|
|
$findOptions = array(
|
|
|
|
'conditions' => array(
|
|
|
|
'User.user' => 'mariano',
|
|
|
|
),
|
|
|
|
'fields' => array('User.password'),
|
|
|
|
'contain' => array('User.password')
|
|
|
|
);
|
2008-06-22 00:02:30 +00:00
|
|
|
$result = $this->Article->Comment->find('all', $findOptions);
|
2008-06-23 04:41:15 +00:00
|
|
|
$result = $this->Article->Comment->find('all', $initialOptions);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($initialModels, $result);
|
2008-06-23 04:41:15 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-08-29 02:13:55 +00:00
|
|
|
/**
|
|
|
|
* testResetDeeperHasOneAssociations method
|
|
|
|
*
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testResetDeeperHasOneAssociations() {
|
2008-08-29 02:13:55 +00:00
|
|
|
$this->Article->User->unbindModel(array(
|
|
|
|
'hasMany' => array('ArticleFeatured', 'Comment')
|
|
|
|
), false);
|
|
|
|
$userHasOne = array('hasOne' => array('ArticleFeatured', 'Comment'));
|
|
|
|
|
|
|
|
$this->Article->User->bindModel($userHasOne, false);
|
|
|
|
$expected = $this->Article->User->hasOne;
|
|
|
|
$this->Article->find('all');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $this->Article->User->hasOne);
|
2008-08-29 02:13:55 +00:00
|
|
|
|
|
|
|
$this->Article->User->bindModel($userHasOne, false);
|
|
|
|
$expected = $this->Article->User->hasOne;
|
|
|
|
$this->Article->find('all', array(
|
|
|
|
'contain' => array(
|
|
|
|
'User' => array('ArticleFeatured', 'Comment')
|
|
|
|
)
|
|
|
|
));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $this->Article->User->hasOne);
|
2008-08-29 02:13:55 +00:00
|
|
|
|
|
|
|
$this->Article->User->bindModel($userHasOne, false);
|
|
|
|
$expected = $this->Article->User->hasOne;
|
|
|
|
$this->Article->find('all', array(
|
|
|
|
'contain' => array(
|
|
|
|
'User' => array(
|
|
|
|
'ArticleFeatured',
|
|
|
|
'Comment' => array('fields' => array('created'))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $this->Article->User->hasOne);
|
2008-08-29 02:13:55 +00:00
|
|
|
|
2009-11-04 11:31:39 +00:00
|
|
|
$this->Article->User->bindModel($userHasOne, false);
|
|
|
|
$expected = $this->Article->User->hasOne;
|
|
|
|
$this->Article->find('all', array(
|
|
|
|
'contain' => array(
|
|
|
|
'User' => array(
|
|
|
|
'Comment' => array('fields' => array('created'))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $this->Article->User->hasOne);
|
2009-11-07 22:43:18 +00:00
|
|
|
|
2008-08-29 02:13:55 +00:00
|
|
|
$this->Article->User->bindModel($userHasOne, false);
|
|
|
|
$expected = $this->Article->User->hasOne;
|
|
|
|
$this->Article->find('all', array(
|
|
|
|
'contain' => array(
|
|
|
|
'User.ArticleFeatured' => array(
|
|
|
|
'conditions' => array('ArticleFeatured.published' => 'Y')
|
|
|
|
),
|
|
|
|
'User.Comment'
|
|
|
|
)
|
|
|
|
));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $this->Article->User->hasOne);
|
2008-08-29 02:13:55 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-16 00:48:58 +00:00
|
|
|
/**
|
|
|
|
* testResetMultipleHabtmAssociations method
|
|
|
|
*
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testResetMultipleHabtmAssociations() {
|
2008-07-16 00:48:58 +00:00
|
|
|
$articleHabtm = array(
|
|
|
|
'hasAndBelongsToMany' => array(
|
|
|
|
'Tag' => array(
|
2012-11-14 11:36:55 +00:00
|
|
|
'className' => 'Tag',
|
|
|
|
'joinTable' => 'articles_tags',
|
|
|
|
'foreignKey' => 'article_id',
|
2008-07-16 00:48:58 +00:00
|
|
|
'associationForeignKey' => 'tag_id'
|
|
|
|
),
|
|
|
|
'ShortTag' => array(
|
2012-11-14 11:36:55 +00:00
|
|
|
'className' => 'Tag',
|
|
|
|
'joinTable' => 'articles_tags',
|
|
|
|
'foreignKey' => 'article_id',
|
2008-07-16 00:48:58 +00:00
|
|
|
'associationForeignKey' => 'tag_id',
|
2009-08-02 06:47:28 +00:00
|
|
|
// LENGHT function mysql-only, using LIKE does almost the same
|
2012-11-14 11:36:55 +00:00
|
|
|
'conditions' => "ShortTag.tag LIKE '???'"
|
2008-07-16 00:48:58 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->Article->resetBindings();
|
|
|
|
$this->Article->bindModel($articleHabtm, false);
|
|
|
|
$expected = $this->Article->hasAndBelongsToMany;
|
|
|
|
$this->Article->find('all');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
|
2008-07-16 00:48:58 +00:00
|
|
|
|
|
|
|
$this->Article->resetBindings();
|
|
|
|
$this->Article->bindModel($articleHabtm, false);
|
|
|
|
$expected = $this->Article->hasAndBelongsToMany;
|
|
|
|
$this->Article->find('all', array('contain' => 'Tag.tag'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
|
2008-07-16 00:48:58 +00:00
|
|
|
|
|
|
|
$this->Article->resetBindings();
|
|
|
|
$this->Article->bindModel($articleHabtm, false);
|
|
|
|
$expected = $this->Article->hasAndBelongsToMany;
|
|
|
|
$this->Article->find('all', array('contain' => 'Tag'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
|
2008-07-16 00:48:58 +00:00
|
|
|
|
|
|
|
$this->Article->resetBindings();
|
|
|
|
$this->Article->bindModel($articleHabtm, false);
|
|
|
|
$expected = $this->Article->hasAndBelongsToMany;
|
|
|
|
$this->Article->find('all', array('contain' => array('Tag' => array('fields' => array(null)))));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
|
2008-07-16 00:48:58 +00:00
|
|
|
|
|
|
|
$this->Article->resetBindings();
|
|
|
|
$this->Article->bindModel($articleHabtm, false);
|
|
|
|
$expected = $this->Article->hasAndBelongsToMany;
|
|
|
|
$this->Article->find('all', array('contain' => array('Tag' => array('fields' => array('Tag.tag')))));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
|
2008-07-16 00:48:58 +00:00
|
|
|
|
|
|
|
$this->Article->resetBindings();
|
|
|
|
$this->Article->bindModel($articleHabtm, false);
|
|
|
|
$expected = $this->Article->hasAndBelongsToMany;
|
|
|
|
$this->Article->find('all', array('contain' => array('Tag' => array('fields' => array('Tag.tag', 'Tag.created')))));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
|
2008-07-16 00:48:58 +00:00
|
|
|
|
|
|
|
$this->Article->resetBindings();
|
|
|
|
$this->Article->bindModel($articleHabtm, false);
|
|
|
|
$expected = $this->Article->hasAndBelongsToMany;
|
|
|
|
$this->Article->find('all', array('contain' => 'ShortTag.tag'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
|
2008-06-23 04:41:15 +00:00
|
|
|
|
2008-07-16 00:48:58 +00:00
|
|
|
$this->Article->resetBindings();
|
|
|
|
$this->Article->bindModel($articleHabtm, false);
|
|
|
|
$expected = $this->Article->hasAndBelongsToMany;
|
|
|
|
$this->Article->find('all', array('contain' => 'ShortTag'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
|
2008-07-16 00:48:58 +00:00
|
|
|
|
|
|
|
$this->Article->resetBindings();
|
|
|
|
$this->Article->bindModel($articleHabtm, false);
|
|
|
|
$expected = $this->Article->hasAndBelongsToMany;
|
|
|
|
$this->Article->find('all', array('contain' => array('ShortTag' => array('fields' => array(null)))));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
|
2008-07-16 00:48:58 +00:00
|
|
|
|
|
|
|
$this->Article->resetBindings();
|
|
|
|
$this->Article->bindModel($articleHabtm, false);
|
|
|
|
$expected = $this->Article->hasAndBelongsToMany;
|
|
|
|
$this->Article->find('all', array('contain' => array('ShortTag' => array('fields' => array('ShortTag.tag')))));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
|
2008-07-16 00:48:58 +00:00
|
|
|
|
|
|
|
$this->Article->resetBindings();
|
|
|
|
$this->Article->bindModel($articleHabtm, false);
|
|
|
|
$expected = $this->Article->hasAndBelongsToMany;
|
|
|
|
$this->Article->find('all', array('contain' => array('ShortTag' => array('fields' => array('ShortTag.tag', 'ShortTag.created')))));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
|
2008-07-16 00:48:58 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-09-18 17:45:39 +00:00
|
|
|
/**
|
|
|
|
* test that bindModel and unbindModel work with find() calls in between.
|
|
|
|
*/
|
2012-02-17 07:13:12 +00:00
|
|
|
public function testBindMultipleTimesWithFind() {
|
2011-09-18 17:45:39 +00:00
|
|
|
$binding = array(
|
|
|
|
'hasOne' => array(
|
|
|
|
'ArticlesTag' => array(
|
|
|
|
'foreignKey' => false,
|
|
|
|
'type' => 'INNER',
|
|
|
|
'conditions' => array(
|
|
|
|
'ArticlesTag.article_id = Article.id'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'Tag' => array(
|
|
|
|
'type' => 'INNER',
|
|
|
|
'foreignKey' => false,
|
|
|
|
'conditions' => array(
|
|
|
|
'ArticlesTag.tag_id = Tag.id'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->Article->unbindModel(array('hasAndBelongsToMany' => array('Tag')));
|
|
|
|
$this->Article->bindModel($binding);
|
|
|
|
$result = $this->Article->find('all', array('limit' => 1, 'contain' => array('ArticlesTag', 'Tag')));
|
|
|
|
|
|
|
|
$this->Article->unbindModel(array('hasAndBelongsToMany' => array('Tag')));
|
|
|
|
$this->Article->bindModel($binding);
|
|
|
|
$result = $this->Article->find('all', array('limit' => 1, 'contain' => array('ArticlesTag', 'Tag')));
|
|
|
|
|
|
|
|
$associated = $this->Article->getAssociated();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals('hasAndBelongsToMany', $associated['Tag']);
|
2011-09-18 17:45:39 +00:00
|
|
|
$this->assertFalse(isset($associated['ArticleTag']));
|
|
|
|
}
|
|
|
|
|
2010-04-20 02:38:18 +00:00
|
|
|
/**
|
|
|
|
* test that autoFields doesn't splice in fields from other databases.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAutoFieldsWithMultipleDatabases() {
|
2010-04-20 02:38:18 +00:00
|
|
|
$config = new DATABASE_CONFIG();
|
|
|
|
|
2011-05-31 00:49:46 +00:00
|
|
|
$this->skipIf(
|
2010-04-20 02:38:18 +00:00
|
|
|
!isset($config->test) || !isset($config->test2),
|
2012-03-18 18:31:13 +00:00
|
|
|
'Primary and secondary test databases not configured, ' .
|
|
|
|
'skipping cross-database join tests. ' .
|
|
|
|
' To run these tests, you must define $test and $test2 ' .
|
|
|
|
'in your database configuration.'
|
2010-04-20 02:38:18 +00:00
|
|
|
);
|
|
|
|
|
2010-12-12 20:48:36 +00:00
|
|
|
$db = ConnectionManager::getDataSource('test2');
|
2011-05-24 17:56:04 +00:00
|
|
|
$this->fixtureManager->loadSingle('User', $db);
|
2010-04-20 02:38:18 +00:00
|
|
|
|
|
|
|
$this->Article->User->setDataSource('test2');
|
|
|
|
|
|
|
|
$result = $this->Article->find('all', array(
|
|
|
|
'fields' => array('Article.title'),
|
|
|
|
'contain' => array('User')
|
|
|
|
));
|
|
|
|
$this->assertTrue(isset($result[0]['Article']));
|
|
|
|
$this->assertTrue(isset($result[0]['User']));
|
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2010-04-20 03:15:59 +00:00
|
|
|
/**
|
|
|
|
* test that autoFields doesn't splice in columns that aren't part of the join.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAutoFieldsWithRecursiveNegativeOne() {
|
2010-04-20 03:15:59 +00:00
|
|
|
$this->Article->recursive = -1;
|
|
|
|
$result = $this->Article->field('title', array('Article.title' => 'First Article'));
|
|
|
|
$this->assertNoErrors();
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('First Article', $result, 'Field is wrong');
|
2010-04-20 03:15:59 +00:00
|
|
|
}
|
2010-10-27 01:39:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test that find(all) doesn't return incorrect values when mixed with containable.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFindAllReturn() {
|
2010-10-27 01:39:48 +00:00
|
|
|
$result = $this->Article->find('all', array(
|
|
|
|
'conditions' => array('Article.id' => 999999999)
|
|
|
|
));
|
2010-12-12 20:48:36 +00:00
|
|
|
$this->assertEmpty($result, 'Should be empty.');
|
2010-10-27 01:39:48 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 14:44:05 +00:00
|
|
|
/**
|
|
|
|
* testLazyLoad method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testLazyLoad() {
|
2011-12-16 06:52:07 +00:00
|
|
|
// Local set up
|
|
|
|
$this->User = ClassRegistry::init('User');
|
2011-09-29 14:44:05 +00:00
|
|
|
$this->User->bindModel(array(
|
|
|
|
'hasMany' => array('Article', 'ArticleFeatured', 'Comment')
|
|
|
|
), false);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$this->User->find('first', array(
|
|
|
|
'contain' => 'Comment',
|
|
|
|
'lazyLoad' => true
|
|
|
|
));
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$exceptions = true;
|
|
|
|
}
|
2011-12-19 13:18:28 +00:00
|
|
|
$this->assertTrue(empty($exceptions));
|
2011-09-29 14:44:05 +00:00
|
|
|
}
|
|
|
|
|
2008-06-22 00:02:30 +00:00
|
|
|
/**
|
2012-02-17 07:32:35 +00:00
|
|
|
* _containments method
|
2008-06-23 04:41:15 +00:00
|
|
|
*
|
2012-02-17 07:32:35 +00:00
|
|
|
* @param Model $Model
|
2008-06-23 04:41:15 +00:00
|
|
|
* @param array $contain
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2012-02-17 07:32:35 +00:00
|
|
|
protected function _containments($Model, $contain = array()) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (!is_array($Model)) {
|
|
|
|
$result = $Model->containments($contain);
|
2012-02-17 07:32:35 +00:00
|
|
|
return $this->_containments($result['models']);
|
2008-05-30 11:40:08 +00:00
|
|
|
} else {
|
|
|
|
$result = $Model;
|
2011-11-30 15:44:11 +00:00
|
|
|
foreach ($result as $i => $containment) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result[$i] = array_diff_key($containment, array('instance' => true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2012-02-17 07:32:35 +00:00
|
|
|
* _assertBindings method
|
2008-06-23 04:41:15 +00:00
|
|
|
*
|
2012-02-17 07:32:35 +00:00
|
|
|
* @param Model $Model
|
2008-06-23 04:41:15 +00:00
|
|
|
* @param array $expected
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2012-02-23 14:10:29 +00:00
|
|
|
protected function _assertBindings(Model $Model, $expected = array()) {
|
2012-02-17 07:32:35 +00:00
|
|
|
$expected = array_merge(array(
|
|
|
|
'belongsTo' => array(),
|
|
|
|
'hasOne' => array(),
|
|
|
|
'hasMany' => array(),
|
|
|
|
'hasAndBelongsToMany' => array()
|
|
|
|
), $expected);
|
2011-11-30 15:44:11 +00:00
|
|
|
foreach ($expected as $binding => $expect) {
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(array_keys($Model->$binding), $expect);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|