Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

3697 lines (3567 sloc) 154.964 kb
<?php
/* SVN FILE: $Id$ */
/**
* ContainableBehaviorTest file
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake
* @subpackage cake.tests.cases.libs.model.behaviors
* @since CakePHP(tm) v 1.2.0.5669
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
App::import('Core', array('AppModel', 'Model'));
require_once(dirname(dirname(__FILE__)) . DS . 'models.php');
/**
* ContainableTest class
*
* @package cake
* @subpackage cake.tests.cases.libs.model.behaviors
*/
class ContainableBehaviorTest extends CakeTestCase {
/**
* Fixtures associated with this test case
*
* @var array
* @access public
*/
var $fixtures = array(
'core.article', 'core.article_featured', 'core.article_featureds_tags', 'core.articles_tag', 'core.attachment', 'core.category',
'core.comment', 'core.featured', 'core.tag', 'core.user'
);
/**
* Method executed before each test
*
* @access public
*/
function startTest() {
$this->User =& ClassRegistry::init('User');
$this->Article =& ClassRegistry::init('Article');
$this->Tag =& ClassRegistry::init('Tag');
$this->User->bind(array(
'Article' => array('type' => 'hasMany'),
'ArticleFeatured' => array('type' => 'hasMany'),
'Comment' => array('type' => 'hasMany')
));
$this->User->ArticleFeatured->unbindModel(array('belongsTo' => array('Category')), false);
$this->User->ArticleFeatured->hasMany['Comment']['foreignKey'] = 'article_id';
$this->Tag->bind(array(
'Article' => array('type' => 'hasAndBelongsToMany')
));
$this->User->Behaviors->attach('Containable');
$this->Article->Behaviors->attach('Containable');
$this->Tag->Behaviors->attach('Containable');
}
/**
* Method executed after each test
*
* @access public
*/
function endTest() {
unset($this->Article);
unset($this->User);
unset($this->Tag);
ClassRegistry::flush();
}
/**
* testContainments method
*
* @access public
* @return void
*/
function testContainments() {
$r = $this->__containments($this->Article, array('Comment' => array('conditions' => array('Comment.user_id' => 2))));
$this->assertTrue(Set::matches('/Article/keep/Comment/conditions[Comment.user_id=2]', $r));
$r = $this->__containments($this->User, array(
'ArticleFeatured' => array(
'Featured' => array(
'id',
'Category' => 'name'
)
)));
$this->assertEqual(Set::extract('/ArticleFeatured/keep/Featured/fields', $r), array('id'));
$r = $this->__containments($this->Article, array(
'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));
$r = $this->__containments($this->Article, array('Comment(comment, published)' => 'Attachment(attachment)', 'User(user)'));
$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));
$this->assertEqual(Set::extract('/Article/keep/Comment/fields', $r), array('comment', 'published'));
$this->assertEqual(Set::extract('/Article/keep/User/fields', $r), array('user'));
$this->assertTrue(Set::matches('/Comment/keep/Attachment', $r));
$this->assertEqual(Set::extract('/Comment/keep/Attachment/fields', $r), array('attachment'));
$r = $this->__containments($this->Article, array('Comment' => array('limit' => 1)));
$this->assertEqual(array_keys($r), array('Comment', 'Article'));
$this->assertEqual(array_shift(Set::extract('/Comment/keep', $r)), array('keep' => array()));
$this->assertTrue(Set::matches('/Article/keep/Comment', $r));
$this->assertEqual(array_shift(Set::extract('/Article/keep/Comment/.', $r)), array('limit' => 1));
$r = $this->__containments($this->Article, array('Comment.User'));
$this->assertEqual(array_keys($r), array('User', 'Comment', 'Article'));
$this->assertEqual(array_shift(Set::extract('/User/keep', $r)), array('keep' => array()));
$this->assertEqual(array_shift(Set::extract('/Comment/keep', $r)), array('keep' => array('User' => array())));
$this->assertEqual(array_shift(Set::extract('/Article/keep', $r)), array('keep' => array('Comment' => array())));
$r = $this->__containments($this->Tag, array('Article' => array('User' => array('Comment' => array(
'Attachment' => array('conditions' => array('Attachment.id >' => 1))
)))));
$this->assertTrue(Set::matches('/Attachment', $r));
$this->assertTrue(Set::matches('/Comment/keep/Attachment/conditions', $r));
$this->assertEqual($r['Comment']['keep']['Attachment']['conditions'], array('Attachment.id >' => 1));
$this->assertTrue(Set::matches('/User/keep/Comment', $r));
$this->assertTrue(Set::matches('/Article/keep/User', $r));
$this->assertTrue(Set::matches('/Tag/keep/Article', $r));
}
/**
* testInvalidContainments method
*
* @access public
* @return void
*/
function testInvalidContainments() {
$this->expectError();
$r = $this->__containments($this->Article, array('Comment', 'InvalidBinding'));
$this->Article->Behaviors->attach('Containable', array('notices' => false));
$r = $this->__containments($this->Article, array('Comment', 'InvalidBinding'));
}
/**
* testBeforeFind method
*
* @access public
* @return void
*/
function testBeforeFind() {
$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'));
$ids = $descIds = Set::extract('/Comment[1]/id', $r);
rsort($descIds);
$this->assertEqual($ids, $descIds);
$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));
$this->expectError();
$r = $this->Article->find('all', array('contain' => array('Comment' => 'NonExistingBinding')));
}
/**
* testContain method
*
* @access public
* @return void
*/
function testContain() {
$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));
}
/**
* testFindEmbeddedNoBindings method
*
* @access public
* @return void
*/
function testFindEmbeddedNoBindings() {
$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'
))
);
$this->assertEqual($result, $expected);
}
/**
* testFindFirstLevel method
*
* @access public
* @return void
*/
function testFindFirstLevel() {
$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'
)
)
);
$this->assertEqual($result, $expected);
$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()
)
);
$this->assertEqual($result, $expected);
}
/**
* testFindEmbeddedFirstLevel method
*
* @access public
* @return void
*/
function testFindEmbeddedFirstLevel() {
$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'
)
)
);
$this->assertEqual($result, $expected);
$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()
)
);
$this->assertEqual($result, $expected);
}
/**
* testFindSecondLevel method
*
* @access public
* @return void
*/
function testFindSecondLevel() {
$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()
)
);
$this->assertEqual($result, $expected);
$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'
)
)
)
)
);
$this->assertEqual($result, $expected);
$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'
)
)
)
)
);
$this->assertEqual($result, $expected);
$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()
)
);
$this->assertEqual($result, $expected);
}
/**
* testFindEmbeddedSecondLevel method
*
* @access public
* @return void
*/
function testFindEmbeddedSecondLevel() {
$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()
)
);
$this->assertEqual($result, $expected);
$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'
)
)
)
)
);
$this->assertEqual($result, $expected);
$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'
)
)
)
)
);
$this->assertEqual($result, $expected);
$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()
)
);
$this->assertEqual($result, $expected);
}
/**
* testFindThirdLevel method
*
* @access public
* @return void
*/
function testFindThirdLevel() {
$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()
)
);
$this->assertEqual($result, $expected);
$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()
)
);
$this->assertEqual($result, $expected);
$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()
)
);
$this->assertEqual($result, $expected);
}
/**
* testFindEmbeddedThirdLevel method
*
* @access public
* @return void
*/
function testFindEmbeddedThirdLevel() {
$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()
)
);
$this->assertEqual($result, $expected);
$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()
)
);
$this->assertEqual($result, $expected);
$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()
)
);
$this->assertEqual($result, $expected);
}
/**
* testSettingsThirdLevel method
*
* @access public
* @return void
*/
function testSettingsThirdLevel() {
$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()
)
);
$this->assertEqual($result, $expected);
$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'