PageRenderTime 42ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php

https://bitbucket.org/udeshika/fake_twitter
PHP | 3695 lines | 3323 code | 167 blank | 205 comment | 14 complexity | 82090e006d10c17e45ace2eedd168e16 MD5 | raw file
  1. <?php
  2. /**
  3. * ContainableBehaviorTest file
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
  8. * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice
  12. *
  13. * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
  15. * @package Cake.Test.Case.Model.Behavior
  16. * @since CakePHP(tm) v 1.2.0.5669
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. App::uses('Model', 'Model');
  20. App::uses('AppModel', 'Model');
  21. require_once(dirname(dirname(__FILE__)) . DS . 'models.php');
  22. /**
  23. * ContainableTest class
  24. *
  25. * @package Cake.Test.Case.Model.Behavior
  26. */
  27. class ContainableBehaviorTest extends CakeTestCase {
  28. /**
  29. * Fixtures associated with this test case
  30. *
  31. * @var array
  32. */
  33. public $fixtures = array(
  34. 'core.article', 'core.article_featured', 'core.article_featureds_tags',
  35. 'core.articles_tag', 'core.attachment', 'core.category',
  36. 'core.comment', 'core.featured', 'core.tag', 'core.user',
  37. 'core.join_a', 'core.join_b', 'core.join_c', 'core.join_a_c', 'core.join_a_b'
  38. );
  39. /**
  40. * Method executed before each test
  41. *
  42. */
  43. public function setUp() {
  44. parent::setUp();
  45. $this->User = ClassRegistry::init('User');
  46. $this->Article = ClassRegistry::init('Article');
  47. $this->Tag = ClassRegistry::init('Tag');
  48. $this->User->bindModel(array(
  49. 'hasMany' => array('Article', 'ArticleFeatured', 'Comment')
  50. ), false);
  51. $this->User->ArticleFeatured->unbindModel(array('belongsTo' => array('Category')), false);
  52. $this->User->ArticleFeatured->hasMany['Comment']['foreignKey'] = 'article_id';
  53. $this->Tag->bindModel(array(
  54. 'hasAndBelongsToMany' => array('Article')
  55. ), false);
  56. $this->User->Behaviors->attach('Containable');
  57. $this->Article->Behaviors->attach('Containable');
  58. $this->Tag->Behaviors->attach('Containable');
  59. }
  60. /**
  61. * Method executed after each test
  62. *
  63. */
  64. public function tearDown() {
  65. unset($this->Article);
  66. unset($this->User);
  67. unset($this->Tag);
  68. parent::tearDown();
  69. }
  70. /**
  71. * testContainments method
  72. *
  73. * @return void
  74. */
  75. public function testContainments() {
  76. $r = $this->__containments($this->Article, array('Comment' => array('conditions' => array('Comment.user_id' => 2))));
  77. $this->assertTrue(Set::matches('/Article/keep/Comment/conditions[Comment.user_id=2]', $r));
  78. $r = $this->__containments($this->User, array(
  79. 'ArticleFeatured' => array(
  80. 'Featured' => array(
  81. 'id',
  82. 'Category' => 'name'
  83. )
  84. )));
  85. $this->assertEquals(Set::extract('/ArticleFeatured/keep/Featured/fields', $r), array('id'));
  86. $r = $this->__containments($this->Article, array(
  87. 'Comment' => array(
  88. 'User',
  89. 'conditions' => array('Comment' => array('user_id' => 2)),
  90. ),
  91. ));
  92. $this->assertTrue(Set::matches('/User', $r));
  93. $this->assertTrue(Set::matches('/Comment', $r));
  94. $this->assertTrue(Set::matches('/Article/keep/Comment/conditions/Comment[user_id=2]', $r));
  95. $r = $this->__containments($this->Article, array('Comment(comment, published)' => 'Attachment(attachment)', 'User(user)'));
  96. $this->assertTrue(Set::matches('/Comment', $r));
  97. $this->assertTrue(Set::matches('/User', $r));
  98. $this->assertTrue(Set::matches('/Article/keep/Comment', $r));
  99. $this->assertTrue(Set::matches('/Article/keep/User', $r));
  100. $this->assertEquals(Set::extract('/Article/keep/Comment/fields', $r), array('comment', 'published'));
  101. $this->assertEquals(Set::extract('/Article/keep/User/fields', $r), array('user'));
  102. $this->assertTrue(Set::matches('/Comment/keep/Attachment', $r));
  103. $this->assertEquals(Set::extract('/Comment/keep/Attachment/fields', $r), array('attachment'));
  104. $r = $this->__containments($this->Article, array('Comment' => array('limit' => 1)));
  105. $this->assertEquals(array_keys($r), array('Comment', 'Article'));
  106. $result = Set::extract('/Comment/keep', $r);
  107. $this->assertEquals(array_shift($result), array('keep' => array()));
  108. $this->assertTrue(Set::matches('/Article/keep/Comment', $r));
  109. $result = Set::extract('/Article/keep/Comment/.', $r);
  110. $this->assertEquals(array_shift($result), array('limit' => 1));
  111. $r = $this->__containments($this->Article, array('Comment.User'));
  112. $this->assertEquals(array_keys($r), array('User', 'Comment', 'Article'));
  113. $result = Set::extract('/User/keep', $r);
  114. $this->assertEquals(array_shift($result), array('keep' => array()));
  115. $result = Set::extract('/Comment/keep', $r);
  116. $this->assertEquals(array_shift($result), array('keep' => array('User' => array())));
  117. $result = Set::extract('/Article/keep', $r);
  118. $this->assertEquals(array_shift($result), array('keep' => array('Comment' => array())));
  119. $r = $this->__containments($this->Tag, array('Article' => array('User' => array('Comment' => array(
  120. 'Attachment' => array('conditions' => array('Attachment.id >' => 1))
  121. )))));
  122. $this->assertTrue(Set::matches('/Attachment', $r));
  123. $this->assertTrue(Set::matches('/Comment/keep/Attachment/conditions', $r));
  124. $this->assertEquals($r['Comment']['keep']['Attachment']['conditions'], array('Attachment.id >' => 1));
  125. $this->assertTrue(Set::matches('/User/keep/Comment', $r));
  126. $this->assertTrue(Set::matches('/Article/keep/User', $r));
  127. $this->assertTrue(Set::matches('/Tag/keep/Article', $r));
  128. }
  129. /**
  130. * testInvalidContainments method
  131. *
  132. * @expectedException PHPUnit_Framework_Error
  133. * @return void
  134. */
  135. public function testInvalidContainments() {
  136. $r = $this->__containments($this->Article, array('Comment', 'InvalidBinding'));
  137. }
  138. /**
  139. * testInvalidContainments method with suppressing error notices
  140. *
  141. * @return void
  142. */
  143. public function testInvalidContainmentsNoNotices() {
  144. $this->Article->Behaviors->attach('Containable', array('notices' => false));
  145. $r = $this->__containments($this->Article, array('Comment', 'InvalidBinding'));
  146. }
  147. /**
  148. * testBeforeFind method
  149. *
  150. * @return void
  151. */
  152. public function testBeforeFind() {
  153. $r = $this->Article->find('all', array('contain' => array('Comment')));
  154. $this->assertFalse(Set::matches('/User', $r));
  155. $this->assertTrue(Set::matches('/Comment', $r));
  156. $this->assertFalse(Set::matches('/Comment/User', $r));
  157. $r = $this->Article->find('all', array('contain' => 'Comment.User'));
  158. $this->assertTrue(Set::matches('/Comment/User', $r));
  159. $this->assertFalse(Set::matches('/Comment/Article', $r));
  160. $r = $this->Article->find('all', array('contain' => array('Comment' => array('User', 'Article'))));
  161. $this->assertTrue(Set::matches('/Comment/User', $r));
  162. $this->assertTrue(Set::matches('/Comment/Article', $r));
  163. $r = $this->Article->find('all', array('contain' => array('Comment' => array('conditions' => array('Comment.user_id' => 2)))));
  164. $this->assertFalse(Set::matches('/Comment[user_id!=2]', $r));
  165. $this->assertTrue(Set::matches('/Comment[user_id=2]', $r));
  166. $r = $this->Article->find('all', array('contain' => array('Comment.user_id = 2')));
  167. $this->assertFalse(Set::matches('/Comment[user_id!=2]', $r));
  168. $r = $this->Article->find('all', array('contain' => 'Comment.id DESC'));
  169. $ids = $descIds = Set::extract('/Comment[1]/id', $r);
  170. rsort($descIds);
  171. $this->assertEquals($ids, $descIds);
  172. $r = $this->Article->find('all', array('contain' => 'Comment'));
  173. $this->assertTrue(Set::matches('/Comment[user_id!=2]', $r));
  174. $r = $this->Article->find('all', array('contain' => array('Comment' => array('fields' => 'comment'))));
  175. $this->assertFalse(Set::matches('/Comment/created', $r));
  176. $this->assertTrue(Set::matches('/Comment/comment', $r));
  177. $this->assertFalse(Set::matches('/Comment/updated', $r));
  178. $r = $this->Article->find('all', array('contain' => array('Comment' => array('fields' => array('comment', 'updated')))));
  179. $this->assertFalse(Set::matches('/Comment/created', $r));
  180. $this->assertTrue(Set::matches('/Comment/comment', $r));
  181. $this->assertTrue(Set::matches('/Comment/updated', $r));
  182. $r = $this->Article->find('all', array('contain' => array('Comment' => array('comment', 'updated'))));
  183. $this->assertFalse(Set::matches('/Comment/created', $r));
  184. $this->assertTrue(Set::matches('/Comment/comment', $r));
  185. $this->assertTrue(Set::matches('/Comment/updated', $r));
  186. $r = $this->Article->find('all', array('contain' => array('Comment(comment,updated)')));
  187. $this->assertFalse(Set::matches('/Comment/created', $r));
  188. $this->assertTrue(Set::matches('/Comment/comment', $r));
  189. $this->assertTrue(Set::matches('/Comment/updated', $r));
  190. $r = $this->Article->find('all', array('contain' => 'Comment.created'));
  191. $this->assertTrue(Set::matches('/Comment/created', $r));
  192. $this->assertFalse(Set::matches('/Comment/comment', $r));
  193. $r = $this->Article->find('all', array('contain' => array('User.Article(title)', 'Comment(comment)')));
  194. $this->assertFalse(Set::matches('/Comment/Article', $r));
  195. $this->assertFalse(Set::matches('/Comment/User', $r));
  196. $this->assertTrue(Set::matches('/Comment/comment', $r));
  197. $this->assertFalse(Set::matches('/Comment/created', $r));
  198. $this->assertTrue(Set::matches('/User/Article/title', $r));
  199. $this->assertFalse(Set::matches('/User/Article/created', $r));
  200. $r = $this->Article->find('all', array('contain' => array()));
  201. $this->assertFalse(Set::matches('/User', $r));
  202. $this->assertFalse(Set::matches('/Comment', $r));
  203. }
  204. /**
  205. * testBeforeFindWithNonExistingBinding method
  206. *
  207. * @expectedException PHPUnit_Framework_Error
  208. * @return void
  209. */
  210. public function testBeforeFindWithNonExistingBinding() {
  211. $r = $this->Article->find('all', array('contain' => array('Comment' => 'NonExistingBinding')));
  212. }
  213. /**
  214. * testContain method
  215. *
  216. * @return void
  217. */
  218. public function testContain() {
  219. $this->Article->contain('Comment.User');
  220. $r = $this->Article->find('all');
  221. $this->assertTrue(Set::matches('/Comment/User', $r));
  222. $this->assertFalse(Set::matches('/Comment/Article', $r));
  223. $r = $this->Article->find('all');
  224. $this->assertFalse(Set::matches('/Comment/User', $r));
  225. }
  226. /**
  227. * testFindEmbeddedNoBindings method
  228. *
  229. * @return void
  230. */
  231. public function testFindEmbeddedNoBindings() {
  232. $result = $this->Article->find('all', array('contain' => false));
  233. $expected = array(
  234. array('Article' => array(
  235. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  236. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  237. )),
  238. array('Article' => array(
  239. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  240. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  241. )),
  242. array('Article' => array(
  243. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  244. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  245. ))
  246. );
  247. $this->assertEquals($expected, $result);
  248. }
  249. /**
  250. * testFindFirstLevel method
  251. *
  252. * @return void
  253. */
  254. public function testFindFirstLevel() {
  255. $this->Article->contain('User');
  256. $result = $this->Article->find('all', array('recursive' => 1));
  257. $expected = array(
  258. array(
  259. 'Article' => array(
  260. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  261. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  262. ),
  263. 'User' => array(
  264. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  265. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  266. )
  267. ),
  268. array(
  269. 'Article' => array(
  270. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  271. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  272. ),
  273. 'User' => array(
  274. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  275. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  276. )
  277. ),
  278. array(
  279. 'Article' => array(
  280. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  281. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  282. ),
  283. 'User' => array(
  284. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  285. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  286. )
  287. )
  288. );
  289. $this->assertEquals($expected, $result);
  290. $this->Article->contain('User', 'Comment');
  291. $result = $this->Article->find('all', array('recursive' => 1));
  292. $expected = array(
  293. array(
  294. 'Article' => array(
  295. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  296. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  297. ),
  298. 'User' => array(
  299. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  300. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  301. ),
  302. 'Comment' => array(
  303. array(
  304. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  305. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'
  306. ),
  307. array(
  308. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  309. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31'
  310. ),
  311. array(
  312. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  313. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'
  314. ),
  315. array(
  316. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  317. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  318. )
  319. )
  320. ),
  321. array(
  322. 'Article' => array(
  323. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  324. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  325. ),
  326. 'User' => array(
  327. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  328. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  329. ),
  330. 'Comment' => array(
  331. array(
  332. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  333. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'
  334. ),
  335. array(
  336. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  337. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31'
  338. )
  339. )
  340. ),
  341. array(
  342. 'Article' => array(
  343. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  344. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  345. ),
  346. 'User' => array(
  347. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  348. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  349. ),
  350. 'Comment' => array()
  351. )
  352. );
  353. $this->assertEquals($expected, $result);
  354. }
  355. /**
  356. * testFindEmbeddedFirstLevel method
  357. *
  358. * @return void
  359. */
  360. public function testFindEmbeddedFirstLevel() {
  361. $result = $this->Article->find('all', array('contain' => array('User')));
  362. $expected = array(
  363. array(
  364. 'Article' => array(
  365. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  366. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  367. ),
  368. 'User' => array(
  369. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  370. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  371. )
  372. ),
  373. array(
  374. 'Article' => array(
  375. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  376. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  377. ),
  378. 'User' => array(
  379. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  380. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  381. )
  382. ),
  383. array(
  384. 'Article' => array(
  385. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  386. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  387. ),
  388. 'User' => array(
  389. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  390. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  391. )
  392. )
  393. );
  394. $this->assertEquals($expected, $result);
  395. $result = $this->Article->find('all', array('contain' => array('User', 'Comment')));
  396. $expected = array(
  397. array(
  398. 'Article' => array(
  399. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  400. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  401. ),
  402. 'User' => array(
  403. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  404. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  405. ),
  406. 'Comment' => array(
  407. array(
  408. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  409. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'
  410. ),
  411. array(
  412. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  413. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31'
  414. ),
  415. array(
  416. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  417. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'
  418. ),
  419. array(
  420. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  421. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  422. )
  423. )
  424. ),
  425. array(
  426. 'Article' => array(
  427. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  428. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  429. ),
  430. 'User' => array(
  431. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  432. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  433. ),
  434. 'Comment' => array(
  435. array(
  436. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  437. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'
  438. ),
  439. array(
  440. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  441. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31'
  442. )
  443. )
  444. ),
  445. array(
  446. 'Article' => array(
  447. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  448. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  449. ),
  450. 'User' => array(
  451. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  452. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  453. ),
  454. 'Comment' => array()
  455. )
  456. );
  457. $this->assertEquals($expected, $result);
  458. }
  459. /**
  460. * testFindSecondLevel method
  461. *
  462. * @return void
  463. */
  464. public function testFindSecondLevel() {
  465. $this->Article->contain(array('Comment' => 'User'));
  466. $result = $this->Article->find('all', array('recursive' => 2));
  467. $expected = array(
  468. array(
  469. 'Article' => array(
  470. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  471. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  472. ),
  473. 'Comment' => array(
  474. array(
  475. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  476. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  477. 'User' => array(
  478. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  479. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  480. )
  481. ),
  482. array(
  483. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  484. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  485. 'User' => array(
  486. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  487. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  488. )
  489. ),
  490. array(
  491. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  492. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  493. 'User' => array(
  494. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  495. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  496. )
  497. ),
  498. array(
  499. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  500. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  501. 'User' => array(
  502. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  503. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  504. )
  505. )
  506. )
  507. ),
  508. array(
  509. 'Article' => array(
  510. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  511. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  512. ),
  513. 'Comment' => array(
  514. array(
  515. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  516. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  517. 'User' => array(
  518. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  519. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  520. )
  521. ),
  522. array(
  523. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  524. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  525. 'User' => array(
  526. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  527. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  528. )
  529. )
  530. )
  531. ),
  532. array(
  533. 'Article' => array(
  534. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  535. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  536. ),
  537. 'Comment' => array()
  538. )
  539. );
  540. $this->assertEquals($expected, $result);
  541. $this->Article->contain(array('User' => 'ArticleFeatured'));
  542. $result = $this->Article->find('all', array('recursive' => 2));
  543. $expected = array(
  544. array(
  545. 'Article' => array(
  546. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  547. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  548. ),
  549. 'User' => array(
  550. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  551. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  552. 'ArticleFeatured' => array(
  553. array(
  554. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  555. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  556. ),
  557. array(
  558. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  559. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  560. )
  561. )
  562. )
  563. ),
  564. array(
  565. 'Article' => array(
  566. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  567. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  568. ),
  569. 'User' => array(
  570. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  571. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31',
  572. 'ArticleFeatured' => array(
  573. array(
  574. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  575. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  576. )
  577. )
  578. )
  579. ),
  580. array(
  581. 'Article' => array(
  582. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  583. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  584. ),
  585. 'User' => array(
  586. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  587. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  588. 'ArticleFeatured' => array(
  589. array(
  590. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  591. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  592. ),
  593. array(
  594. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  595. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  596. )
  597. )
  598. )
  599. )
  600. );
  601. $this->assertEquals($expected, $result);
  602. $this->Article->contain(array('User' => array('ArticleFeatured', 'Comment')));
  603. $result = $this->Article->find('all', array('recursive' => 2));
  604. $expected = array(
  605. array(
  606. 'Article' => array(
  607. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  608. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  609. ),
  610. 'User' => array(
  611. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  612. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  613. 'ArticleFeatured' => array(
  614. array(
  615. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  616. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  617. ),
  618. array(
  619. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  620. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  621. )
  622. ),
  623. 'Comment' => array(
  624. array(
  625. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  626. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'
  627. ),
  628. array(
  629. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  630. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  631. ),
  632. array(
  633. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  634. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'
  635. )
  636. )
  637. )
  638. ),
  639. array(
  640. 'Article' => array(
  641. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  642. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  643. ),
  644. 'User' => array(
  645. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  646. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31',
  647. 'ArticleFeatured' => array(
  648. array(
  649. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  650. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  651. )
  652. ),
  653. 'Comment' => array()
  654. )
  655. ),
  656. array(
  657. 'Article' => array(
  658. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  659. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  660. ),
  661. 'User' => array(
  662. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  663. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  664. 'ArticleFeatured' => array(
  665. array(
  666. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  667. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  668. ),
  669. array(
  670. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  671. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  672. )
  673. ),
  674. 'Comment' => array(
  675. array(
  676. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  677. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'
  678. ),
  679. array(
  680. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  681. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  682. ),
  683. array(
  684. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  685. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'
  686. )
  687. )
  688. )
  689. )
  690. );
  691. $this->assertEquals($expected, $result);
  692. $this->Article->contain(array('User' => array('ArticleFeatured')), 'Tag', array('Comment' => 'Attachment'));
  693. $result = $this->Article->find('all', array('recursive' => 2));
  694. $expected = array(
  695. array(
  696. 'Article' => array(
  697. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  698. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  699. ),
  700. 'User' => array(
  701. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  702. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  703. 'ArticleFeatured' => array(
  704. array(
  705. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  706. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  707. ),
  708. array(
  709. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  710. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  711. )
  712. )
  713. ),
  714. 'Comment' => array(
  715. array(
  716. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  717. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  718. 'Attachment' => array()
  719. ),
  720. array(
  721. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  722. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  723. 'Attachment' => array()
  724. ),
  725. array(
  726. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  727. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  728. 'Attachment' => array()
  729. ),
  730. array(
  731. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  732. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  733. 'Attachment' => array()
  734. )
  735. ),
  736. 'Tag' => array(
  737. array('id' => 1, 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'),
  738. array('id' => 2, 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31')
  739. )
  740. ),
  741. array(
  742. 'Article' => array(
  743. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  744. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  745. ),
  746. 'User' => array(
  747. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  748. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31',
  749. 'ArticleFeatured' => array(
  750. array(
  751. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  752. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  753. )
  754. )
  755. ),
  756. 'Comment' => array(
  757. array(
  758. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  759. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  760. 'Attachment' => array(
  761. 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
  762. 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  763. )
  764. ),
  765. array(
  766. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  767. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  768. 'Attachment' => array()
  769. )
  770. ),
  771. 'Tag' => array(
  772. array('id' => 1, 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'),
  773. array('id' => 3, 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31')
  774. )
  775. ),
  776. array(
  777. 'Article' => array(
  778. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  779. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  780. ),
  781. 'User' => array(
  782. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  783. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  784. 'ArticleFeatured' => array(
  785. array(
  786. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  787. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  788. ),
  789. array(
  790. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  791. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  792. )
  793. )
  794. ),
  795. 'Comment' => array(),
  796. 'Tag' => array()
  797. )
  798. );
  799. $this->assertEquals($expected, $result);
  800. }
  801. /**
  802. * testFindEmbeddedSecondLevel method
  803. *
  804. * @return void
  805. */
  806. public function testFindEmbeddedSecondLevel() {
  807. $result = $this->Article->find('all', array('contain' => array('Comment' => 'User')));
  808. $expected = array(
  809. array(
  810. 'Article' => array(
  811. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  812. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  813. ),
  814. 'Comment' => array(
  815. array(
  816. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  817. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  818. 'User' => array(
  819. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  820. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  821. )
  822. ),
  823. array(
  824. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  825. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  826. 'User' => array(
  827. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  828. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  829. )
  830. ),
  831. array(
  832. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  833. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  834. 'User' => array(
  835. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  836. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  837. )
  838. ),
  839. array(
  840. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  841. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  842. 'User' => array(
  843. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  844. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  845. )
  846. )
  847. )
  848. ),
  849. array(
  850. 'Article' => array(
  851. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  852. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  853. ),
  854. 'Comment' => array(
  855. array(
  856. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  857. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  858. 'User' => array(
  859. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  860. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  861. )
  862. ),
  863. array(
  864. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  865. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  866. 'User' => array(
  867. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  868. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  869. )
  870. )
  871. )
  872. ),
  873. array(
  874. 'Article' => array(
  875. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  876. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  877. ),
  878. 'Comment' => array()
  879. )
  880. );
  881. $this->assertEquals($expected, $result);
  882. $result = $this->Article->find('all', array('contain' => array('User' => 'ArticleFeatured')));
  883. $expected = array(
  884. array(
  885. 'Article' => array(
  886. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  887. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  888. ),
  889. 'User' => array(
  890. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  891. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  892. 'ArticleFeatured' => array(
  893. array(
  894. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  895. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  896. ),
  897. array(
  898. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  899. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  900. )
  901. )
  902. )
  903. ),
  904. array(
  905. 'Article' => array(
  906. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  907. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  908. ),
  909. 'User' => array(
  910. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  911. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31',
  912. 'ArticleFeatured' => array(
  913. array(
  914. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  915. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  916. )
  917. )
  918. )
  919. ),
  920. array(
  921. 'Article' => array(
  922. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  923. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  924. ),
  925. 'User' => array(
  926. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  927. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  928. 'ArticleFeatured' => array(
  929. array(
  930. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  931. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  932. ),
  933. array(
  934. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  935. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  936. )
  937. )
  938. )
  939. )
  940. );
  941. $this->assertEquals($expected, $result);
  942. $result = $this->Article->find('all', array('contain' => array('User' => array('ArticleFeatured', 'Comment'))));
  943. $expected = array(
  944. array(
  945. 'Article' => array(
  946. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  947. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  948. ),
  949. 'User' => array(
  950. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  951. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  952. 'ArticleFeatured' => array(
  953. array(
  954. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  955. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  956. ),
  957. array(
  958. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  959. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  960. )
  961. ),
  962. 'Comment' => array(
  963. array(
  964. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  965. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'
  966. ),
  967. array(
  968. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  969. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  970. ),
  971. array(
  972. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  973. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'
  974. )
  975. )
  976. )
  977. ),
  978. array(
  979. 'Article' => array(
  980. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  981. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  982. ),
  983. 'User' => array(
  984. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  985. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31',
  986. 'ArticleFeatured' => array(
  987. array(
  988. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  989. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  990. )
  991. ),
  992. 'Comment' => array()
  993. )
  994. ),
  995. array(
  996. 'Article' => array(
  997. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  998. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  999. ),
  1000. 'User' => array(
  1001. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1002. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  1003. 'ArticleFeatured' => array(
  1004. array(
  1005. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1006. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1007. ),
  1008. array(
  1009. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1010. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  1011. )
  1012. ),
  1013. 'Comment' => array(
  1014. array(
  1015. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  1016. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'
  1017. ),
  1018. array(
  1019. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  1020. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  1021. ),
  1022. array(
  1023. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  1024. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'
  1025. )
  1026. )
  1027. )
  1028. )
  1029. );
  1030. $this->assertEquals($expected, $result);
  1031. $result = $this->Article->find('all', array('contain' => array('User' => 'ArticleFeatured', 'Tag', 'Comment' => 'Attachment')));
  1032. $expected = array(
  1033. array(
  1034. 'Article' => array(
  1035. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1036. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1037. ),
  1038. 'User' => array(
  1039. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1040. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  1041. 'ArticleFeatured' => array(
  1042. array(
  1043. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1044. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1045. ),
  1046. array(
  1047. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1048. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  1049. )
  1050. )
  1051. ),
  1052. 'Comment' => array(
  1053. array(
  1054. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  1055. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  1056. 'Attachment' => array()
  1057. ),
  1058. array(
  1059. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  1060. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  1061. 'Attachment' => array()
  1062. ),
  1063. array(
  1064. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  1065. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  1066. 'Attachment' => array()
  1067. ),
  1068. array(
  1069. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  1070. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  1071. 'Attachment' => array()
  1072. )
  1073. ),
  1074. 'Tag' => array(
  1075. array('id' => 1, 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'),
  1076. array('id' => 2, 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31')
  1077. )
  1078. ),
  1079. array(
  1080. 'Article' => array(
  1081. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1082. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  1083. ),
  1084. 'User' => array(
  1085. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1086. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31',
  1087. 'ArticleFeatured' => array(
  1088. array(
  1089. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1090. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  1091. )
  1092. )
  1093. ),
  1094. 'Comment' => array(
  1095. array(
  1096. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  1097. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  1098. 'Attachment' => array(
  1099. 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
  1100. 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  1101. )
  1102. ),
  1103. array(
  1104. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  1105. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  1106. 'Attachment' => array()
  1107. )
  1108. ),
  1109. 'Tag' => array(
  1110. array('id' => 1, 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'),
  1111. array('id' => 3, 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31')
  1112. )
  1113. ),
  1114. array(
  1115. 'Article' => array(
  1116. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1117. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  1118. ),
  1119. 'User' => array(
  1120. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1121. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31',
  1122. 'ArticleFeatured' => array(
  1123. array(
  1124. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1125. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1126. ),
  1127. array(
  1128. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1129. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  1130. )
  1131. )
  1132. ),
  1133. 'Comment' => array(),
  1134. 'Tag' => array()
  1135. )
  1136. );
  1137. $this->assertEquals($expected, $result);
  1138. }
  1139. /**
  1140. * testFindThirdLevel method
  1141. *
  1142. * @return void
  1143. */
  1144. public function testFindThirdLevel() {
  1145. $this->User->contain(array('ArticleFeatured' => array('Featured' => 'Category')));
  1146. $result = $this->User->find('all', array('recursive' => 3));
  1147. $expected = array(
  1148. array(
  1149. 'User' => array(
  1150. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1151. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  1152. ),
  1153. 'ArticleFeatured' => array(
  1154. array(
  1155. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1156. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1157. 'Featured' => array(
  1158. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1159. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1160. 'Category' => array(
  1161. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1162. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1163. )
  1164. )
  1165. ),
  1166. array(
  1167. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1168. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  1169. 'Featured' => array()
  1170. )
  1171. )
  1172. ),
  1173. array(
  1174. 'User' => array(
  1175. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1176. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  1177. ),
  1178. 'ArticleFeatured' => array()
  1179. ),
  1180. array(
  1181. 'User' => array(
  1182. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1183. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  1184. ),
  1185. 'ArticleFeatured' => array(
  1186. array(
  1187. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1188. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  1189. 'Featured' => array(
  1190. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1191. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1192. 'Category' => array(
  1193. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1194. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1195. )
  1196. )
  1197. )
  1198. )
  1199. ),
  1200. array(
  1201. 'User' => array(
  1202. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1203. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  1204. ),
  1205. 'ArticleFeatured' => array()
  1206. )
  1207. );
  1208. $this->assertEquals($expected, $result);
  1209. $this->User->contain(array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment'))));
  1210. $result = $this->User->find('all', array('recursive' => 3));
  1211. $expected = array(
  1212. array(
  1213. 'User' => array(
  1214. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1215. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  1216. ),
  1217. 'ArticleFeatured' => array(
  1218. array(
  1219. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1220. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1221. 'Featured' => array(
  1222. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1223. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1224. 'Category' => array(
  1225. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1226. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1227. )
  1228. ),
  1229. 'Comment' => array(
  1230. array(
  1231. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  1232. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  1233. 'Article' => array(
  1234. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1235. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1236. ),
  1237. 'Attachment' => array()
  1238. ),
  1239. array(
  1240. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  1241. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  1242. 'Article' => array(
  1243. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1244. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1245. ),
  1246. 'Attachment' => array()
  1247. ),
  1248. array(
  1249. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  1250. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  1251. 'Article' => array(
  1252. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1253. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1254. ),
  1255. 'Attachment' => array()
  1256. ),
  1257. array(
  1258. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  1259. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  1260. 'Article' => array(
  1261. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1262. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1263. ),
  1264. 'Attachment' => array()
  1265. )
  1266. )
  1267. ),
  1268. array(
  1269. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1270. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  1271. 'Featured' => array(),
  1272. 'Comment' => array()
  1273. )
  1274. )
  1275. ),
  1276. array(
  1277. 'User' => array(
  1278. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1279. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  1280. ),
  1281. 'ArticleFeatured' => array()
  1282. ),
  1283. array(
  1284. 'User' => array(
  1285. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1286. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  1287. ),
  1288. 'ArticleFeatured' => array(
  1289. array(
  1290. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1291. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  1292. 'Featured' => array(
  1293. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1294. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1295. 'Category' => array(
  1296. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1297. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1298. )
  1299. ),
  1300. 'Comment' => array(
  1301. array(
  1302. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  1303. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  1304. 'Article' => array(
  1305. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1306. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  1307. ),
  1308. 'Attachment' => array(
  1309. 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
  1310. 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  1311. )
  1312. ),
  1313. array(
  1314. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  1315. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  1316. 'Article' => array(
  1317. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1318. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  1319. ),
  1320. 'Attachment' => array()
  1321. )
  1322. )
  1323. )
  1324. )
  1325. ),
  1326. array(
  1327. 'User' => array(
  1328. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1329. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  1330. ),
  1331. 'ArticleFeatured' => array()
  1332. )
  1333. );
  1334. $this->assertEquals($expected, $result);
  1335. $this->User->contain(array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => 'Attachment'), 'Article'));
  1336. $result = $this->User->find('all', array('recursive' => 3));
  1337. $expected = array(
  1338. array(
  1339. 'User' => array(
  1340. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1341. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  1342. ),
  1343. 'Article' => array(
  1344. array(
  1345. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1346. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1347. ),
  1348. array(
  1349. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1350. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  1351. )
  1352. ),
  1353. 'ArticleFeatured' => array(
  1354. array(
  1355. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1356. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1357. 'Featured' => array(
  1358. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1359. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1360. 'Category' => array(
  1361. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1362. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1363. )
  1364. ),
  1365. 'Comment' => array(
  1366. array(
  1367. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  1368. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  1369. 'Attachment' => array()
  1370. ),
  1371. array(
  1372. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  1373. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  1374. 'Attachment' => array()
  1375. ),
  1376. array(
  1377. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  1378. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  1379. 'Attachment' => array()
  1380. ),
  1381. array(
  1382. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  1383. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  1384. 'Attachment' => array()
  1385. )
  1386. )
  1387. ),
  1388. array(
  1389. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1390. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  1391. 'Featured' => array(),
  1392. 'Comment' => array()
  1393. )
  1394. )
  1395. ),
  1396. array(
  1397. 'User' => array(
  1398. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1399. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  1400. ),
  1401. 'Article' => array(),
  1402. 'ArticleFeatured' => array()
  1403. ),
  1404. array(
  1405. 'User' => array(
  1406. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1407. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  1408. ),
  1409. 'Article' => array(
  1410. array(
  1411. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1412. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  1413. )
  1414. ),
  1415. 'ArticleFeatured' => array(
  1416. array(
  1417. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1418. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  1419. 'Featured' => array(
  1420. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1421. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1422. 'Category' => array(
  1423. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1424. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1425. )
  1426. ),
  1427. 'Comment' => array(
  1428. array(
  1429. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  1430. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  1431. 'Attachment' => array(
  1432. 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
  1433. 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  1434. )
  1435. ),
  1436. array(
  1437. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  1438. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  1439. 'Attachment' => array()
  1440. )
  1441. )
  1442. )
  1443. )
  1444. ),
  1445. array(
  1446. 'User' => array(
  1447. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1448. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  1449. ),
  1450. 'Article' => array(),
  1451. 'ArticleFeatured' => array()
  1452. )
  1453. );
  1454. $this->assertEquals($expected, $result);
  1455. }
  1456. /**
  1457. * testFindEmbeddedThirdLevel method
  1458. *
  1459. * @return void
  1460. */
  1461. public function testFindEmbeddedThirdLevel() {
  1462. $result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => 'Category'))));
  1463. $expected = array(
  1464. array(
  1465. 'User' => array(
  1466. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1467. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  1468. ),
  1469. 'ArticleFeatured' => array(
  1470. array(
  1471. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1472. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1473. 'Featured' => array(
  1474. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1475. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1476. 'Category' => array(
  1477. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1478. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1479. )
  1480. )
  1481. ),
  1482. array(
  1483. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1484. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  1485. 'Featured' => array()
  1486. )
  1487. )
  1488. ),
  1489. array(
  1490. 'User' => array(
  1491. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1492. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  1493. ),
  1494. 'ArticleFeatured' => array()
  1495. ),
  1496. array(
  1497. 'User' => array(
  1498. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1499. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  1500. ),
  1501. 'ArticleFeatured' => array(
  1502. array(
  1503. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1504. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  1505. 'Featured' => array(
  1506. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1507. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1508. 'Category' => array(
  1509. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1510. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1511. )
  1512. )
  1513. )
  1514. )
  1515. ),
  1516. array(
  1517. 'User' => array(
  1518. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1519. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  1520. ),
  1521. 'ArticleFeatured' => array()
  1522. )
  1523. );
  1524. $this->assertEquals($expected, $result);
  1525. $result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment')))));
  1526. $expected = array(
  1527. array(
  1528. 'User' => array(
  1529. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1530. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  1531. ),
  1532. 'ArticleFeatured' => array(
  1533. array(
  1534. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1535. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1536. 'Featured' => array(
  1537. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1538. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1539. 'Category' => array(
  1540. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1541. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1542. )
  1543. ),
  1544. 'Comment' => array(
  1545. array(
  1546. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  1547. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  1548. 'Article' => array(
  1549. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1550. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1551. ),
  1552. 'Attachment' => array()
  1553. ),
  1554. array(
  1555. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  1556. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  1557. 'Article' => array(
  1558. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1559. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1560. ),
  1561. 'Attachment' => array()
  1562. ),
  1563. array(
  1564. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  1565. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  1566. 'Article' => array(
  1567. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1568. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1569. ),
  1570. 'Attachment' => array()
  1571. ),
  1572. array(
  1573. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  1574. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  1575. 'Article' => array(
  1576. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1577. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1578. ),
  1579. 'Attachment' => array()
  1580. )
  1581. )
  1582. ),
  1583. array(
  1584. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1585. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  1586. 'Featured' => array(),
  1587. 'Comment' => array()
  1588. )
  1589. )
  1590. ),
  1591. array(
  1592. 'User' => array(
  1593. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1594. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  1595. ),
  1596. 'ArticleFeatured' => array()
  1597. ),
  1598. array(
  1599. 'User' => array(
  1600. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1601. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  1602. ),
  1603. 'ArticleFeatured' => array(
  1604. array(
  1605. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1606. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  1607. 'Featured' => array(
  1608. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1609. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1610. 'Category' => array(
  1611. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1612. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1613. )
  1614. ),
  1615. 'Comment' => array(
  1616. array(
  1617. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  1618. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  1619. 'Article' => array(
  1620. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1621. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  1622. ),
  1623. 'Attachment' => array(
  1624. 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
  1625. 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  1626. )
  1627. ),
  1628. array(
  1629. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  1630. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  1631. 'Article' => array(
  1632. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1633. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  1634. ),
  1635. 'Attachment' => array()
  1636. )
  1637. )
  1638. )
  1639. )
  1640. ),
  1641. array(
  1642. 'User' => array(
  1643. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1644. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  1645. ),
  1646. 'ArticleFeatured' => array()
  1647. )
  1648. );
  1649. $this->assertEquals($expected, $result);
  1650. $result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => 'Attachment'), 'Article')));
  1651. $expected = array(
  1652. array(
  1653. 'User' => array(
  1654. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1655. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  1656. ),
  1657. 'Article' => array(
  1658. array(
  1659. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1660. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  1661. ),
  1662. array(
  1663. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1664. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  1665. )
  1666. ),
  1667. 'ArticleFeatured' => array(
  1668. array(
  1669. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1670. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1671. 'Featured' => array(
  1672. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1673. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1674. 'Category' => array(
  1675. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1676. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1677. )
  1678. ),
  1679. 'Comment' => array(
  1680. array(
  1681. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  1682. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  1683. 'Attachment' => array()
  1684. ),
  1685. array(
  1686. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  1687. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  1688. 'Attachment' => array()
  1689. ),
  1690. array(
  1691. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  1692. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  1693. 'Attachment' => array()
  1694. ),
  1695. array(
  1696. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  1697. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  1698. 'Attachment' => array()
  1699. )
  1700. )
  1701. ),
  1702. array(
  1703. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1704. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  1705. 'Featured' => array(),
  1706. 'Comment' => array()
  1707. )
  1708. )
  1709. ),
  1710. array(
  1711. 'User' => array(
  1712. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1713. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  1714. ),
  1715. 'Article' => array(),
  1716. 'ArticleFeatured' => array()
  1717. ),
  1718. array(
  1719. 'User' => array(
  1720. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1721. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  1722. ),
  1723. 'Article' => array(
  1724. array(
  1725. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1726. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  1727. )
  1728. ),
  1729. 'ArticleFeatured' => array(
  1730. array(
  1731. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1732. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  1733. 'Featured' => array(
  1734. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1735. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1736. 'Category' => array(
  1737. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  1738. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  1739. )
  1740. ),
  1741. 'Comment' => array(
  1742. array(
  1743. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  1744. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  1745. 'Attachment' => array(
  1746. 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
  1747. 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  1748. )
  1749. ),
  1750. array(
  1751. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  1752. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  1753. 'Attachment' => array()
  1754. )
  1755. )
  1756. )
  1757. )
  1758. ),
  1759. array(
  1760. 'User' => array(
  1761. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1762. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  1763. ),
  1764. 'Article' => array(),
  1765. 'ArticleFeatured' => array()
  1766. )
  1767. );
  1768. $this->assertEquals($expected, $result);
  1769. }
  1770. /**
  1771. * testSettingsThirdLevel method
  1772. *
  1773. * @return void
  1774. */
  1775. public function testSettingsThirdLevel() {
  1776. $result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => array('Category' => array('id', 'name'))))));
  1777. $expected = array(
  1778. array(
  1779. 'User' => array(
  1780. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1781. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  1782. ),
  1783. 'ArticleFeatured' => array(
  1784. array(
  1785. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  1786. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1787. 'Featured' => array(
  1788. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1789. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1790. 'Category' => array(
  1791. 'id' => 1, 'name' => 'Category 1'
  1792. )
  1793. )
  1794. ),
  1795. array(
  1796. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  1797. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  1798. 'Featured' => array()
  1799. )
  1800. )
  1801. ),
  1802. array(
  1803. 'User' => array(
  1804. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1805. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  1806. ),
  1807. 'ArticleFeatured' => array()
  1808. ),
  1809. array(
  1810. 'User' => array(
  1811. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1812. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  1813. ),
  1814. 'ArticleFeatured' => array(
  1815. array(
  1816. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  1817. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  1818. 'Featured' => array(
  1819. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  1820. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  1821. 'Category' => array(
  1822. 'id' => 1, 'name' => 'Category 1'
  1823. )
  1824. )
  1825. )
  1826. )
  1827. ),
  1828. array(
  1829. 'User' => array(
  1830. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1831. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  1832. ),
  1833. 'ArticleFeatured' => array()
  1834. )
  1835. );
  1836. $this->assertEquals($expected, $result);
  1837. $r = $this->User->find('all', array('contain' => array(
  1838. 'ArticleFeatured' => array(
  1839. 'id', 'title',
  1840. 'Featured' => array(
  1841. 'id', 'category_id',
  1842. 'Category' => array('id', 'name')
  1843. )
  1844. )
  1845. )));
  1846. $this->assertTrue(Set::matches('/User[id=1]', $r));
  1847. $this->assertFalse(Set::matches('/Article', $r) || Set::matches('/Comment', $r));
  1848. $this->assertTrue(Set::matches('/ArticleFeatured', $r));
  1849. $this->assertFalse(Set::matches('/ArticleFeatured/User', $r) || Set::matches('/ArticleFeatured/Comment', $r) || Set::matches('/ArticleFeatured/Tag', $r));
  1850. $this->assertTrue(Set::matches('/ArticleFeatured/Featured', $r));
  1851. $this->assertFalse(Set::matches('/ArticleFeatured/Featured/ArticleFeatured', $r));
  1852. $this->assertTrue(Set::matches('/ArticleFeatured/Featured/Category', $r));
  1853. $this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]', $r));
  1854. $this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]/Category[id=1]', $r));
  1855. $this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]/Category[name=Category 1]', $r));
  1856. $r = $this->User->find('all', array('contain' => array(
  1857. 'ArticleFeatured' => array(
  1858. 'title',
  1859. 'Featured' => array(
  1860. 'id',
  1861. 'Category' => 'name'
  1862. )
  1863. )
  1864. )));
  1865. $this->assertTrue(Set::matches('/User[id=1]', $r));
  1866. $this->assertFalse(Set::matches('/Article', $r) || Set::matches('/Comment', $r));
  1867. $this->assertTrue(Set::matches('/ArticleFeatured', $r));
  1868. $this->assertFalse(Set::matches('/ArticleFeatured/User', $r) || Set::matches('/ArticleFeatured/Comment', $r) || Set::matches('/ArticleFeatured/Tag', $r));
  1869. $this->assertTrue(Set::matches('/ArticleFeatured/Featured', $r));
  1870. $this->assertFalse(Set::matches('/ArticleFeatured/Featured/ArticleFeatured', $r));
  1871. $this->assertTrue(Set::matches('/ArticleFeatured/Featured/Category', $r));
  1872. $this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]', $r));
  1873. $this->assertTrue(Set::matches('/ArticleFeatured/Featured[id=1]/Category[name=Category 1]', $r));
  1874. $result = $this->User->find('all', array('contain' => array(
  1875. 'ArticleFeatured' => array(
  1876. 'title',
  1877. 'Featured' => array(
  1878. 'category_id',
  1879. 'Category' => 'name'
  1880. )
  1881. )
  1882. )));
  1883. $expected = array(
  1884. array(
  1885. 'User' => array(
  1886. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1887. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  1888. ),
  1889. 'ArticleFeatured' => array(
  1890. array(
  1891. 'title' => 'First Article', 'id' => 1, 'user_id' => 1,
  1892. 'Featured' => array(
  1893. 'category_id' => 1, 'id' => 1,
  1894. 'Category' => array(
  1895. 'name' => 'Category 1'
  1896. )
  1897. )
  1898. ),
  1899. array(
  1900. 'title' => 'Third Article', 'id' => 3, 'user_id' => 1,
  1901. 'Featured' => array()
  1902. )
  1903. )
  1904. ),
  1905. array(
  1906. 'User' => array(
  1907. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1908. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  1909. ),
  1910. 'ArticleFeatured' => array()
  1911. ),
  1912. array(
  1913. 'User' => array(
  1914. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1915. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  1916. ),
  1917. 'ArticleFeatured' => array(
  1918. array(
  1919. 'title' => 'Second Article', 'id' => 2, 'user_id' => 3,
  1920. 'Featured' => array(
  1921. 'category_id' => 1, 'id' => 2,
  1922. 'Category' => array(
  1923. 'name' => 'Category 1'
  1924. )
  1925. )
  1926. )
  1927. )
  1928. ),
  1929. array(
  1930. 'User' => array(
  1931. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1932. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  1933. ),
  1934. 'ArticleFeatured' => array()
  1935. )
  1936. );
  1937. $this->assertEquals($expected, $result);
  1938. $orders = array(
  1939. 'title DESC', 'title DESC, published DESC',
  1940. array('title' => 'DESC'), array('title' => 'DESC', 'published' => 'DESC'),
  1941. );
  1942. foreach ($orders as $order) {
  1943. $result = $this->User->find('all', array('contain' => array(
  1944. 'ArticleFeatured' => array(
  1945. 'title', 'order' => $order,
  1946. 'Featured' => array(
  1947. 'category_id',
  1948. 'Category' => 'name'
  1949. )
  1950. )
  1951. )));
  1952. $expected = array(
  1953. array(
  1954. 'User' => array(
  1955. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1956. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  1957. ),
  1958. 'ArticleFeatured' => array(
  1959. array(
  1960. 'title' => 'Third Article', 'id' => 3, 'user_id' => 1,
  1961. 'Featured' => array()
  1962. ),
  1963. array(
  1964. 'title' => 'First Article', 'id' => 1, 'user_id' => 1,
  1965. 'Featured' => array(
  1966. 'category_id' => 1, 'id' => 1,
  1967. 'Category' => array(
  1968. 'name' => 'Category 1'
  1969. )
  1970. )
  1971. )
  1972. )
  1973. ),
  1974. array(
  1975. 'User' => array(
  1976. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1977. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  1978. ),
  1979. 'ArticleFeatured' => array()
  1980. ),
  1981. array(
  1982. 'User' => array(
  1983. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  1984. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  1985. ),
  1986. 'ArticleFeatured' => array(
  1987. array(
  1988. 'title' => 'Second Article', 'id' => 2, 'user_id' => 3,
  1989. 'Featured' => array(
  1990. 'category_id' => 1, 'id' => 2,
  1991. 'Category' => array(
  1992. 'name' => 'Category 1'
  1993. )
  1994. )
  1995. )
  1996. )
  1997. ),
  1998. array(
  1999. 'User' => array(
  2000. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2001. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  2002. ),
  2003. 'ArticleFeatured' => array()
  2004. )
  2005. );
  2006. $this->assertEquals($expected, $result);
  2007. }
  2008. }
  2009. /**
  2010. * testFindThirdLevelNonReset method
  2011. *
  2012. * @return void
  2013. */
  2014. public function testFindThirdLevelNonReset() {
  2015. $this->User->contain(false, array('ArticleFeatured' => array('Featured' => 'Category')));
  2016. $result = $this->User->find('all', array('recursive' => 3));
  2017. $expected = array(
  2018. array(
  2019. 'User' => array(
  2020. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2021. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  2022. ),
  2023. 'ArticleFeatured' => array(
  2024. array(
  2025. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2026. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2027. 'Featured' => array(
  2028. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2029. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2030. 'Category' => array(
  2031. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2032. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2033. )
  2034. )
  2035. ),
  2036. array(
  2037. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  2038. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  2039. 'Featured' => array()
  2040. )
  2041. )
  2042. ),
  2043. array(
  2044. 'User' => array(
  2045. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2046. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  2047. ),
  2048. 'ArticleFeatured' => array()
  2049. ),
  2050. array(
  2051. 'User' => array(
  2052. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2053. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  2054. ),
  2055. 'ArticleFeatured' => array(
  2056. array(
  2057. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2058. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  2059. 'Featured' => array(
  2060. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2061. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2062. 'Category' => array(
  2063. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2064. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2065. )
  2066. )
  2067. )
  2068. )
  2069. ),
  2070. array(
  2071. 'User' => array(
  2072. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2073. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  2074. ),
  2075. 'ArticleFeatured' => array()
  2076. )
  2077. );
  2078. $this->assertEquals($expected, $result);
  2079. $this->User->resetBindings();
  2080. $this->User->contain(false, array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment'))));
  2081. $result = $this->User->find('all', array('recursive' => 3));
  2082. $expected = array(
  2083. array(
  2084. 'User' => array(
  2085. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2086. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  2087. ),
  2088. 'ArticleFeatured' => array(
  2089. array(
  2090. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2091. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2092. 'Featured' => array(
  2093. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2094. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2095. 'Category' => array(
  2096. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2097. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2098. )
  2099. ),
  2100. 'Comment' => array(
  2101. array(
  2102. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  2103. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  2104. 'Article' => array(
  2105. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2106. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2107. ),
  2108. 'Attachment' => array()
  2109. ),
  2110. array(
  2111. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  2112. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  2113. 'Article' => array(
  2114. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2115. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2116. ),
  2117. 'Attachment' => array()
  2118. ),
  2119. array(
  2120. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  2121. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  2122. 'Article' => array(
  2123. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2124. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2125. ),
  2126. 'Attachment' => array()
  2127. ),
  2128. array(
  2129. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  2130. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  2131. 'Article' => array(
  2132. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2133. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2134. ),
  2135. 'Attachment' => array()
  2136. )
  2137. )
  2138. ),
  2139. array(
  2140. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  2141. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  2142. 'Featured' => array(),
  2143. 'Comment' => array()
  2144. )
  2145. )
  2146. ),
  2147. array(
  2148. 'User' => array(
  2149. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2150. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  2151. ),
  2152. 'ArticleFeatured' => array()
  2153. ),
  2154. array(
  2155. 'User' => array(
  2156. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2157. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  2158. ),
  2159. 'ArticleFeatured' => array(
  2160. array(
  2161. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2162. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  2163. 'Featured' => array(
  2164. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2165. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2166. 'Category' => array(
  2167. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2168. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2169. )
  2170. ),
  2171. 'Comment' => array(
  2172. array(
  2173. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  2174. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  2175. 'Article' => array(
  2176. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2177. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  2178. ),
  2179. 'Attachment' => array(
  2180. 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
  2181. 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  2182. )
  2183. ),
  2184. array(
  2185. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  2186. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  2187. 'Article' => array(
  2188. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2189. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  2190. ),
  2191. 'Attachment' => array()
  2192. )
  2193. )
  2194. )
  2195. )
  2196. ),
  2197. array(
  2198. 'User' => array(
  2199. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2200. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  2201. ),
  2202. 'ArticleFeatured' => array()
  2203. )
  2204. );
  2205. $this->assertEquals($expected, $result);
  2206. $this->User->resetBindings();
  2207. $this->User->contain(false, array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => 'Attachment'), 'Article'));
  2208. $result = $this->User->find('all', array('recursive' => 3));
  2209. $expected = array(
  2210. array(
  2211. 'User' => array(
  2212. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2213. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  2214. ),
  2215. 'Article' => array(
  2216. array(
  2217. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2218. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2219. ),
  2220. array(
  2221. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  2222. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  2223. )
  2224. ),
  2225. 'ArticleFeatured' => array(
  2226. array(
  2227. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2228. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2229. 'Featured' => array(
  2230. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2231. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2232. 'Category' => array(
  2233. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2234. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2235. )
  2236. ),
  2237. 'Comment' => array(
  2238. array(
  2239. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  2240. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  2241. 'Attachment' => array()
  2242. ),
  2243. array(
  2244. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  2245. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  2246. 'Attachment' => array()
  2247. ),
  2248. array(
  2249. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  2250. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  2251. 'Attachment' => array()
  2252. ),
  2253. array(
  2254. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  2255. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  2256. 'Attachment' => array()
  2257. )
  2258. )
  2259. ),
  2260. array(
  2261. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  2262. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  2263. 'Featured' => array(),
  2264. 'Comment' => array()
  2265. )
  2266. )
  2267. ),
  2268. array(
  2269. 'User' => array(
  2270. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2271. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  2272. ),
  2273. 'Article' => array(),
  2274. 'ArticleFeatured' => array()
  2275. ),
  2276. array(
  2277. 'User' => array(
  2278. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2279. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  2280. ),
  2281. 'Article' => array(
  2282. array(
  2283. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2284. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  2285. )
  2286. ),
  2287. 'ArticleFeatured' => array(
  2288. array(
  2289. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2290. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  2291. 'Featured' => array(
  2292. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2293. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2294. 'Category' => array(
  2295. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2296. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2297. )
  2298. ),
  2299. 'Comment' => array(
  2300. array(
  2301. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  2302. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  2303. 'Attachment' => array(
  2304. 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
  2305. 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  2306. )
  2307. ),
  2308. array(
  2309. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  2310. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  2311. 'Attachment' => array()
  2312. )
  2313. )
  2314. )
  2315. )
  2316. ),
  2317. array(
  2318. 'User' => array(
  2319. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2320. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  2321. ),
  2322. 'Article' => array(),
  2323. 'ArticleFeatured' => array()
  2324. )
  2325. );
  2326. $this->assertEquals($expected, $result);
  2327. }
  2328. /**
  2329. * testFindEmbeddedThirdLevelNonReset method
  2330. *
  2331. * @return void
  2332. */
  2333. public function testFindEmbeddedThirdLevelNonReset() {
  2334. $result = $this->User->find('all', array('reset' => false, 'contain' => array('ArticleFeatured' => array('Featured' => 'Category'))));
  2335. $expected = array(
  2336. array(
  2337. 'User' => array(
  2338. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2339. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  2340. ),
  2341. 'ArticleFeatured' => array(
  2342. array(
  2343. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2344. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2345. 'Featured' => array(
  2346. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2347. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2348. 'Category' => array(
  2349. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2350. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2351. )
  2352. )
  2353. ),
  2354. array(
  2355. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  2356. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  2357. 'Featured' => array()
  2358. )
  2359. )
  2360. ),
  2361. array(
  2362. 'User' => array(
  2363. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2364. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  2365. ),
  2366. 'ArticleFeatured' => array()
  2367. ),
  2368. array(
  2369. 'User' => array(
  2370. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2371. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  2372. ),
  2373. 'ArticleFeatured' => array(
  2374. array(
  2375. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2376. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  2377. 'Featured' => array(
  2378. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2379. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2380. 'Category' => array(
  2381. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2382. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2383. )
  2384. )
  2385. )
  2386. )
  2387. ),
  2388. array(
  2389. 'User' => array(
  2390. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2391. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  2392. ),
  2393. 'ArticleFeatured' => array()
  2394. )
  2395. );
  2396. $this->assertEquals($expected, $result);
  2397. $this->__assertBindings($this->User, array('hasMany' => array('ArticleFeatured')));
  2398. $this->__assertBindings($this->User->ArticleFeatured, array('hasOne' => array('Featured')));
  2399. $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('Category')));
  2400. $this->User->resetBindings();
  2401. $this->__assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured', 'Comment')));
  2402. $this->__assertBindings($this->User->ArticleFeatured, array('belongsTo' => array('User'), 'hasOne' => array('Featured'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag')));
  2403. $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('ArticleFeatured', 'Category')));
  2404. $this->__assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article', 'User'), 'hasOne' => array('Attachment')));
  2405. $result = $this->User->find('all', array('reset' => false, 'contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment')))));
  2406. $expected = array(
  2407. array(
  2408. 'User' => array(
  2409. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2410. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  2411. ),
  2412. 'ArticleFeatured' => array(
  2413. array(
  2414. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2415. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2416. 'Featured' => array(
  2417. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2418. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2419. 'Category' => array(
  2420. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2421. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2422. )
  2423. ),
  2424. 'Comment' => array(
  2425. array(
  2426. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  2427. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  2428. 'Article' => array(
  2429. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2430. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2431. ),
  2432. 'Attachment' => array()
  2433. ),
  2434. array(
  2435. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  2436. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  2437. 'Article' => array(
  2438. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2439. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2440. ),
  2441. 'Attachment' => array()
  2442. ),
  2443. array(
  2444. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  2445. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  2446. 'Article' => array(
  2447. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2448. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2449. ),
  2450. 'Attachment' => array()
  2451. ),
  2452. array(
  2453. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  2454. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  2455. 'Article' => array(
  2456. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2457. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2458. ),
  2459. 'Attachment' => array()
  2460. )
  2461. )
  2462. ),
  2463. array(
  2464. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  2465. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  2466. 'Featured' => array(),
  2467. 'Comment' => array()
  2468. )
  2469. )
  2470. ),
  2471. array(
  2472. 'User' => array(
  2473. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2474. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  2475. ),
  2476. 'ArticleFeatured' => array()
  2477. ),
  2478. array(
  2479. 'User' => array(
  2480. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2481. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  2482. ),
  2483. 'ArticleFeatured' => array(
  2484. array(
  2485. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2486. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  2487. 'Featured' => array(
  2488. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2489. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2490. 'Category' => array(
  2491. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2492. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2493. )
  2494. ),
  2495. 'Comment' => array(
  2496. array(
  2497. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  2498. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  2499. 'Article' => array(
  2500. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2501. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  2502. ),
  2503. 'Attachment' => array(
  2504. 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
  2505. 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  2506. )
  2507. ),
  2508. array(
  2509. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  2510. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  2511. 'Article' => array(
  2512. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2513. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  2514. ),
  2515. 'Attachment' => array()
  2516. )
  2517. )
  2518. )
  2519. )
  2520. ),
  2521. array(
  2522. 'User' => array(
  2523. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2524. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  2525. ),
  2526. 'ArticleFeatured' => array()
  2527. )
  2528. );
  2529. $this->assertEquals($expected, $result);
  2530. $this->__assertBindings($this->User, array('hasMany' => array('ArticleFeatured')));
  2531. $this->__assertBindings($this->User->ArticleFeatured, array('hasOne' => array('Featured'), 'hasMany' => array('Comment')));
  2532. $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('Category')));
  2533. $this->__assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article'), 'hasOne' => array('Attachment')));
  2534. $this->User->resetBindings();
  2535. $this->__assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured', 'Comment')));
  2536. $this->__assertBindings($this->User->ArticleFeatured, array('belongsTo' => array('User'), 'hasOne' => array('Featured'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag')));
  2537. $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('ArticleFeatured', 'Category')));
  2538. $this->__assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article', 'User'), 'hasOne' => array('Attachment')));
  2539. $result = $this->User->find('all', array('contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => array('Article', 'Attachment')), false)));
  2540. $expected = array(
  2541. array(
  2542. 'User' => array(
  2543. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2544. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  2545. ),
  2546. 'ArticleFeatured' => array(
  2547. array(
  2548. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2549. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2550. 'Featured' => array(
  2551. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2552. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2553. 'Category' => array(
  2554. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2555. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2556. )
  2557. ),
  2558. 'Comment' => array(
  2559. array(
  2560. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  2561. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  2562. 'Article' => array(
  2563. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2564. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2565. ),
  2566. 'Attachment' => array()
  2567. ),
  2568. array(
  2569. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  2570. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  2571. 'Article' => array(
  2572. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2573. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2574. ),
  2575. 'Attachment' => array()
  2576. ),
  2577. array(
  2578. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  2579. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  2580. 'Article' => array(
  2581. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2582. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2583. ),
  2584. 'Attachment' => array()
  2585. ),
  2586. array(
  2587. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  2588. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  2589. 'Article' => array(
  2590. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2591. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2592. ),
  2593. 'Attachment' => array()
  2594. )
  2595. )
  2596. ),
  2597. array(
  2598. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  2599. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  2600. 'Featured' => array(),
  2601. 'Comment' => array()
  2602. )
  2603. )
  2604. ),
  2605. array(
  2606. 'User' => array(
  2607. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2608. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  2609. ),
  2610. 'ArticleFeatured' => array()
  2611. ),
  2612. array(
  2613. 'User' => array(
  2614. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2615. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  2616. ),
  2617. 'ArticleFeatured' => array(
  2618. array(
  2619. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2620. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  2621. 'Featured' => array(
  2622. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2623. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2624. 'Category' => array(
  2625. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2626. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2627. )
  2628. ),
  2629. 'Comment' => array(
  2630. array(
  2631. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  2632. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  2633. 'Article' => array(
  2634. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2635. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  2636. ),
  2637. 'Attachment' => array(
  2638. 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
  2639. 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  2640. )
  2641. ),
  2642. array(
  2643. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  2644. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  2645. 'Article' => array(
  2646. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2647. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  2648. ),
  2649. 'Attachment' => array()
  2650. )
  2651. )
  2652. )
  2653. )
  2654. ),
  2655. array(
  2656. 'User' => array(
  2657. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2658. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  2659. ),
  2660. 'ArticleFeatured' => array()
  2661. )
  2662. );
  2663. $this->assertEquals($expected, $result);
  2664. $this->__assertBindings($this->User, array('hasMany' => array('ArticleFeatured')));
  2665. $this->__assertBindings($this->User->ArticleFeatured, array('hasOne' => array('Featured'), 'hasMany' => array('Comment')));
  2666. $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('Category')));
  2667. $this->__assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article'), 'hasOne' => array('Attachment')));
  2668. $this->User->resetBindings();
  2669. $this->__assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured', 'Comment')));
  2670. $this->__assertBindings($this->User->ArticleFeatured, array('belongsTo' => array('User'), 'hasOne' => array('Featured'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag')));
  2671. $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('ArticleFeatured', 'Category')));
  2672. $this->__assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article', 'User'), 'hasOne' => array('Attachment')));
  2673. $result = $this->User->find('all', array('reset' => false, 'contain' => array('ArticleFeatured' => array('Featured' => 'Category', 'Comment' => 'Attachment'), 'Article')));
  2674. $expected = array(
  2675. array(
  2676. 'User' => array(
  2677. 'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2678. 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
  2679. ),
  2680. 'Article' => array(
  2681. array(
  2682. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2683. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'
  2684. ),
  2685. array(
  2686. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  2687. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'
  2688. )
  2689. ),
  2690. 'ArticleFeatured' => array(
  2691. array(
  2692. 'id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body',
  2693. 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2694. 'Featured' => array(
  2695. 'id' => 1, 'article_featured_id' => 1, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2696. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2697. 'Category' => array(
  2698. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2699. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2700. )
  2701. ),
  2702. 'Comment' => array(
  2703. array(
  2704. 'id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article',
  2705. 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31',
  2706. 'Attachment' => array()
  2707. ),
  2708. array(
  2709. 'id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article',
  2710. 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31',
  2711. 'Attachment' => array()
  2712. ),
  2713. array(
  2714. 'id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article',
  2715. 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31',
  2716. 'Attachment' => array()
  2717. ),
  2718. array(
  2719. 'id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article',
  2720. 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31',
  2721. 'Attachment' => array()
  2722. )
  2723. )
  2724. ),
  2725. array(
  2726. 'id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body',
  2727. 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31',
  2728. 'Featured' => array(),
  2729. 'Comment' => array()
  2730. )
  2731. )
  2732. ),
  2733. array(
  2734. 'User' => array(
  2735. 'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2736. 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
  2737. ),
  2738. 'Article' => array(),
  2739. 'ArticleFeatured' => array()
  2740. ),
  2741. array(
  2742. 'User' => array(
  2743. 'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2744. 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
  2745. ),
  2746. 'Article' => array(
  2747. array(
  2748. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2749. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'
  2750. )
  2751. ),
  2752. 'ArticleFeatured' => array(
  2753. array(
  2754. 'id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body',
  2755. 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31',
  2756. 'Featured' => array(
  2757. 'id' => 2, 'article_featured_id' => 2, 'category_id' => 1, 'published_date' => '2007-03-31 10:39:23',
  2758. 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31',
  2759. 'Category' => array(
  2760. 'id' => 1, 'parent_id' => 0, 'name' => 'Category 1',
  2761. 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'
  2762. )
  2763. ),
  2764. 'Comment' => array(
  2765. array(
  2766. 'id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article',
  2767. 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31',
  2768. 'Attachment' => array(
  2769. 'id' => 1, 'comment_id' => 5, 'attachment' => 'attachment.zip',
  2770. 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'
  2771. )
  2772. ),
  2773. array(
  2774. 'id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article',
  2775. 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31',
  2776. 'Attachment' => array()
  2777. )
  2778. )
  2779. )
  2780. )
  2781. ),
  2782. array(
  2783. 'User' => array(
  2784. 'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  2785. 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
  2786. ),
  2787. 'Article' => array(),
  2788. 'ArticleFeatured' => array()
  2789. )
  2790. );
  2791. $this->assertEquals($expected, $result);
  2792. $this->__assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured')));
  2793. $this->__assertBindings($this->User->Article);
  2794. $this->__assertBindings($this->User->ArticleFeatured, array('hasOne' => array('Featured'), 'hasMany' => array('Comment')));
  2795. $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('Category')));
  2796. $this->__assertBindings($this->User->ArticleFeatured->Comment, array('hasOne' => array('Attachment')));
  2797. $this->User->resetBindings();
  2798. $this->__assertBindings($this->User, array('hasMany' => array('Article', 'ArticleFeatured', 'Comment')));
  2799. $this->__assertBindings($this->User->Article, array('belongsTo' => array('User'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag')));
  2800. $this->__assertBindings($this->User->ArticleFeatured, array('belongsTo' => array('User'), 'hasOne' => array('Featured'), 'hasMany' => array('Comment'), 'hasAndBelongsToMany' => array('Tag')));
  2801. $this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('ArticleFeatured', 'Category')));
  2802. $this->__assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article', 'User'), 'hasOne' => array('Attachment')));
  2803. }
  2804. /**
  2805. * testEmbeddedFindFields method
  2806. *
  2807. * @return void
  2808. */
  2809. public function testEmbeddedFindFields() {
  2810. $result = $this->Article->find('all', array(
  2811. 'contain' => array('User(user)'),
  2812. 'fields' => array('title'),
  2813. 'order' => array('Article.id' => 'ASC')
  2814. ));
  2815. $expected = array(
  2816. array('Article' => array('title' => 'First Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
  2817. array('Article' => array('title' => 'Second Article'), 'User' => array('user' => 'larry', 'id' => 3)),
  2818. array('Article' => array('title' => 'Third Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
  2819. );
  2820. $this->assertEquals($expected, $result);
  2821. $result = $this->Article->find('all', array(
  2822. 'contain' => array('User(id, user)'),
  2823. 'fields' => array('title'),
  2824. 'order' => array('Article.id' => 'ASC')
  2825. ));
  2826. $expected = array(
  2827. array('Article' => array('title' => 'First Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
  2828. array('Article' => array('title' => 'Second Article'), 'User' => array('user' => 'larry', 'id' => 3)),
  2829. array('Article' => array('title' => 'Third Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
  2830. );
  2831. $this->assertEquals($expected, $result);
  2832. $result = $this->Article->find('all', array(
  2833. 'contain' => array(
  2834. 'Comment(comment, published)' => 'Attachment(attachment)', 'User(user)'
  2835. ),
  2836. 'fields' => array('title'),
  2837. 'order' => array('Article.id' => 'ASC')
  2838. ));
  2839. if (!empty($result)) {
  2840. foreach ($result as $i => $article) {
  2841. foreach ($article['Comment'] as $j => $comment) {
  2842. $result[$i]['Comment'][$j] = array_diff_key($comment, array('id' => true));
  2843. }
  2844. }
  2845. }
  2846. $expected = array(
  2847. array(
  2848. 'Article' => array('title' => 'First Article', 'id' => 1),
  2849. 'User' => array('user' => 'mariano', 'id' => 1),
  2850. 'Comment' => array(
  2851. array('comment' => 'First Comment for First Article', 'published' => 'Y', 'article_id' => 1, 'Attachment' => array()),
  2852. array('comment' => 'Second Comment for First Article', 'published' => 'Y', 'article_id' => 1, 'Attachment' => array()),
  2853. array('comment' => 'Third Comment for First Article', 'published' => 'Y', 'article_id' => 1, 'Attachment' => array()),
  2854. array('comment' => 'Fourth Comment for First Article', 'published' => 'N', 'article_id' => 1, 'Attachment' => array()),
  2855. )
  2856. ),
  2857. array(
  2858. 'Article' => array('title' => 'Second Article', 'id' => 2),
  2859. 'User' => array('user' => 'larry', 'id' => 3),
  2860. 'Comment' => array(
  2861. array('comment' => 'First Comment for Second Article', 'published' => 'Y', 'article_id' => 2, 'Attachment' => array(
  2862. 'attachment' => 'attachment.zip', 'id' => 1
  2863. )),
  2864. array('comment' => 'Second Comment for Second Article', 'published' => 'Y', 'article_id' => 2, 'Attachment' => array())
  2865. )
  2866. ),
  2867. array(
  2868. 'Article' => array('title' => 'Third Article', 'id' => 3),
  2869. 'User' => array('user' => 'mariano', 'id' => 1),
  2870. 'Comment' => array()
  2871. ),
  2872. );
  2873. $this->assertEquals($expected, $result);
  2874. }
  2875. /**
  2876. * test that hasOne and belongsTo fields act the same in a contain array.
  2877. *
  2878. * @return void
  2879. */
  2880. public function testHasOneFieldsInContain() {
  2881. $this->Article->unbindModel(array(
  2882. 'hasMany' => array('Comment')
  2883. ), true);
  2884. unset($this->Article->Comment);
  2885. $this->Article->bindModel(array(
  2886. 'hasOne' => array('Comment')
  2887. ));
  2888. $result = $this->Article->find('all', array(
  2889. 'fields' => array('title', 'body'),
  2890. 'contain' => array(
  2891. 'Comment' => array(
  2892. 'fields' => array('comment')
  2893. ),
  2894. 'User' => array(
  2895. 'fields' => array('user')
  2896. )
  2897. )
  2898. ));
  2899. $this->assertTrue(isset($result[0]['Article']['title']), 'title missing %s');
  2900. $this->assertTrue(isset($result[0]['Article']['body']), 'body missing %s');
  2901. $this->assertTrue(isset($result[0]['Comment']['comment']), 'comment missing %s');
  2902. $this->assertTrue(isset($result[0]['User']['user']), 'body missing %s');
  2903. $this->assertFalse(isset($result[0]['Comment']['published']), 'published found %s');
  2904. $this->assertFalse(isset($result[0]['User']['password']), 'password found %s');
  2905. }
  2906. /**
  2907. * testFindConditionalBinding method
  2908. *
  2909. * @return void
  2910. */
  2911. public function testFindConditionalBinding() {
  2912. $this->Article->contain(array(
  2913. 'User(user)',
  2914. 'Tag' => array(
  2915. 'fields' => array('tag', 'created'),
  2916. 'conditions' => array('created >=' => '2007-03-18 12:24')
  2917. )
  2918. ));
  2919. $result = $this->Article->find('all', array('fields' => array('title'), 'order' => array('Article.id' => 'ASC')));
  2920. $expected = array(
  2921. array(
  2922. 'Article' => array('id' => 1, 'title' => 'First Article'),
  2923. 'User' => array('id' => 1, 'user' => 'mariano'),
  2924. 'Tag' => array(array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23'))
  2925. ),
  2926. array(
  2927. 'Article' => array('id' => 2, 'title' => 'Second Article'),
  2928. 'User' => array('id' => 3, 'user' => 'larry'),
  2929. 'Tag' => array(array('tag' => 'tag3', 'created' => '2007-03-18 12:26:23'))
  2930. ),
  2931. array(
  2932. 'Article' => array('id' => 3, 'title' => 'Third Article'),
  2933. 'User' => array('id' => 1, 'user' => 'mariano'),
  2934. 'Tag' => array()
  2935. )
  2936. );
  2937. $this->assertEquals($expected, $result);
  2938. $this->Article->contain(array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created'))));
  2939. $result = $this->Article->find('all', array('fields' => array('title'), 'order' => array('Article.id' => 'ASC')));
  2940. $expected = array(
  2941. array(
  2942. 'Article' => array('id' => 1, 'title' => 'First Article'),
  2943. 'User' => array('id' => 1, 'user' => 'mariano'),
  2944. 'Tag' => array(
  2945. array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'),
  2946. array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23')
  2947. )
  2948. ),
  2949. array(
  2950. 'Article' => array('id' => 2, 'title' => 'Second Article'),
  2951. 'User' => array('id' => 3, 'user' => 'larry'),
  2952. 'Tag' => array(
  2953. array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'),
  2954. array('tag' => 'tag3', 'created' => '2007-03-18 12:26:23')
  2955. )
  2956. ),
  2957. array(
  2958. 'Article' => array('id' => 3, 'title' => 'Third Article'),
  2959. 'User' => array('id' => 1, 'user' => 'mariano'),
  2960. 'Tag' => array()
  2961. )
  2962. );
  2963. $this->assertEquals($expected, $result);
  2964. $result = $this->Article->find('all', array(
  2965. 'fields' => array('title'),
  2966. 'contain' => array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created'))),
  2967. 'order' => array('Article.id' => 'ASC')
  2968. ));
  2969. $expected = array(
  2970. array(
  2971. 'Article' => array('id' => 1, 'title' => 'First Article'),
  2972. 'User' => array('id' => 1, 'user' => 'mariano'),
  2973. 'Tag' => array(
  2974. array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'),
  2975. array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23')
  2976. )
  2977. ),
  2978. array(
  2979. 'Article' => array('id' => 2, 'title' => 'Second Article'),
  2980. 'User' => array('id' => 3, 'user' => 'larry'),
  2981. 'Tag' => array(
  2982. array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'),
  2983. array('tag' => 'tag3', 'created' => '2007-03-18 12:26:23')
  2984. )
  2985. ),
  2986. array(
  2987. 'Article' => array('id' => 3, 'title' => 'Third Article'),
  2988. 'User' => array('id' => 1, 'user' => 'mariano'),
  2989. 'Tag' => array()
  2990. )
  2991. );
  2992. $this->assertEquals($expected, $result);
  2993. $this->Article->contain(array(
  2994. 'User(id,user)',
  2995. 'Tag' => array(
  2996. 'fields' => array('tag', 'created'),
  2997. 'conditions' => array('created >=' => '2007-03-18 12:24')
  2998. )
  2999. ));
  3000. $result = $this->Article->find('all', array('fields' => array('title'), 'order' => array('Article.id' => 'ASC')));
  3001. $expected = array(
  3002. array(
  3003. 'Article' => array('id' => 1, 'title' => 'First Article'),
  3004. 'User' => array('id' => 1, 'user' => 'mariano'),
  3005. 'Tag' => array(array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23'))
  3006. ),
  3007. array(
  3008. 'Article' => array('id' => 2, 'title' => 'Second Article'),
  3009. 'User' => array('id' => 3, 'user' => 'larry'),
  3010. 'Tag' => array(array('tag' => 'tag3', 'created' => '2007-03-18 12:26:23'))
  3011. ),
  3012. array(
  3013. 'Article' => array('id' => 3, 'title' => 'Third Article'),
  3014. 'User' => array('id' => 1, 'user' => 'mariano'),
  3015. 'Tag' => array()
  3016. )
  3017. );
  3018. $this->assertEquals($expected, $result);
  3019. $this->assertTrue(empty($this->User->Article->hasAndBelongsToMany['Tag']['conditions']));
  3020. $result = $this->User->find('all', array('contain' => array(
  3021. 'Article.Tag' => array('conditions' => array('created >=' => '2007-03-18 12:24'))
  3022. )));
  3023. $this->assertTrue(Set::matches('/User[id=1]', $result));
  3024. $this->assertFalse(Set::matches('/Article[id=1]/Tag[id=1]', $result));
  3025. $this->assertTrue(Set::matches('/Article[id=1]/Tag[id=2]', $result));
  3026. $this->assertTrue(empty($this->User->Article->hasAndBelongsToMany['Tag']['conditions']));
  3027. $this->assertTrue(empty($this->User->Article->hasAndBelongsToMany['Tag']['order']));
  3028. $result = $this->User->find('all', array('contain' => array(
  3029. 'Article.Tag' => array('order' => 'created DESC')
  3030. )));
  3031. $this->assertTrue(Set::matches('/User[id=1]', $result));
  3032. $this->assertTrue(Set::matches('/Article[id=1]/Tag[id=1]', $result));
  3033. $this->assertTrue(Set::matches('/Article[id=1]/Tag[id=2]', $result));
  3034. $this->assertTrue(empty($this->User->Article->hasAndBelongsToMany['Tag']['order']));
  3035. }
  3036. /**
  3037. * testOtherFinds method
  3038. *
  3039. * @return void
  3040. */
  3041. public function testOtherFinds() {
  3042. $result = $this->Article->find('count');
  3043. $expected = 3;
  3044. $this->assertEquals($expected, $result);
  3045. $result = $this->Article->find('count', array('conditions' => array('Article.id >' => '1')));
  3046. $expected = 2;
  3047. $this->assertEquals($expected, $result);
  3048. $result = $this->Article->find('count', array('contain' => array()));
  3049. $expected = 3;
  3050. $this->assertEquals($expected, $result);
  3051. $this->Article->contain(array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created'), 'conditions' => array('created >=' => '2007-03-18 12:24'))));
  3052. $result = $this->Article->find('first', array('fields' => array('title')));
  3053. $expected = array(
  3054. 'Article' => array('id' => 1, 'title' => 'First Article'),
  3055. 'User' => array('id' => 1, 'user' => 'mariano'),
  3056. 'Tag' => array(array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23'))
  3057. );
  3058. $this->assertEquals($expected, $result);
  3059. $this->Article->contain(array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created'))));
  3060. $result = $this->Article->find('first', array('fields' => array('title')));
  3061. $expected = array(
  3062. 'Article' => array('id' => 1, 'title' => 'First Article'),
  3063. 'User' => array('id' => 1, 'user' => 'mariano'),
  3064. 'Tag' => array(
  3065. array('tag' => 'tag1', 'created' => '2007-03-18 12:22:23'),
  3066. array('tag' => 'tag2', 'created' => '2007-03-18 12:24:23')
  3067. )
  3068. );
  3069. $this->assertEquals($expected, $result);
  3070. $result = $this->Article->find('first', array(
  3071. 'fields' => array('title'),
  3072. 'order' => 'Article.id DESC',
  3073. 'contain' => array('User(id,user)', 'Tag' => array('fields' => array('tag', 'created')))
  3074. ));
  3075. $expected = array(
  3076. 'Article' => array('id' => 3, 'title' => 'Third Article'),
  3077. 'User' => array('id' => 1, 'user' => 'mariano'),
  3078. 'Tag' => array()
  3079. );
  3080. $this->assertEquals($expected, $result);
  3081. $result = $this->Article->find('list', array(
  3082. 'contain' => array('User(id,user)'),
  3083. 'fields' => array('Article.id', 'Article.title')
  3084. ));
  3085. $expected = array(
  3086. 1 => 'First Article',
  3087. 2 => 'Second Article',
  3088. 3 => 'Third Article'
  3089. );
  3090. $this->assertEquals($expected, $result);
  3091. }
  3092. /**
  3093. * testOriginalAssociations method
  3094. *
  3095. * @return void
  3096. */
  3097. public function testOriginalAssociations() {
  3098. $this->Article->Comment->Behaviors->attach('Containable');
  3099. $options = array(
  3100. 'conditions' => array(
  3101. 'Comment.published' => 'Y',
  3102. ),
  3103. 'contain' => 'User',
  3104. 'recursive' => 1
  3105. );
  3106. $firstResult = $this->Article->Comment->find('all', $options);
  3107. $dummyResult = $this->Article->Comment->find('all', array(
  3108. 'conditions' => array(
  3109. 'User.user' => 'mariano'
  3110. ),
  3111. 'fields' => array('User.password'),
  3112. 'contain' => array('User.password'),
  3113. ));
  3114. $result = $this->Article->Comment->find('all', $options);
  3115. $this->assertEquals($result, $firstResult);
  3116. $this->Article->unbindModel(array('hasMany' => array('Comment'), 'belongsTo' => array('User'), 'hasAndBelongsToMany' => array('Tag')), false);
  3117. $this->Article->bindModel(array('hasMany' => array('Comment'), 'belongsTo' => array('User')), false);
  3118. $r = $this->Article->find('all', array('contain' => array('Comment(comment)', 'User(user)'), 'fields' => array('title')));
  3119. $this->assertTrue(Set::matches('/Article[id=1]', $r));
  3120. $this->assertTrue(Set::matches('/User[id=1]', $r));
  3121. $this->assertTrue(Set::matches('/Comment[article_id=1]', $r));
  3122. $this->assertFalse(Set::matches('/Comment[id=1]', $r));
  3123. $r = $this->Article->find('all');
  3124. $this->assertTrue(Set::matches('/Article[id=1]', $r));
  3125. $this->assertTrue(Set::matches('/User[id=1]', $r));
  3126. $this->assertTrue(Set::matches('/Comment[article_id=1]', $r));
  3127. $this->assertTrue(Set::matches('/Comment[id=1]', $r));
  3128. $this->Article->bindModel(array('hasAndBelongsToMany' => array('Tag')), false);
  3129. $this->Article->contain(false, array('User(id,user)', 'Comment' => array('fields' => array('comment'), 'conditions' => array('created >=' => '2007-03-18 10:49'))));
  3130. $result = $this->Article->find('all', array('fields' => array('title'), 'limit' => 1, 'page' => 1, 'order' => 'Article.id ASC'));
  3131. $expected = array(array(
  3132. 'Article' => array('id' => 1, 'title' => 'First Article'),
  3133. 'User' => array('id' => 1, 'user' => 'mariano'),
  3134. 'Comment' => array(
  3135. array('comment' => 'Third Comment for First Article', 'article_id' => 1),
  3136. array('comment' => 'Fourth Comment for First Article', 'article_id' => 1)
  3137. )
  3138. ));
  3139. $this->assertEquals($expected, $result);
  3140. $result = $this->Article->find('all', array('fields' => array('title', 'User.id', 'User.user'), 'limit' => 1, 'page' => 2, 'order' => 'Article.id ASC'));
  3141. $expected = array(array(
  3142. 'Article' => array('id' => 2, 'title' => 'Second Article'),
  3143. 'User' => array('id' => 3, 'user' => 'larry'),
  3144. 'Comment' => array(
  3145. array('comment' => 'First Comment for Second Article', 'article_id' => 2),
  3146. array('comment' => 'Second Comment for Second Article', 'article_id' => 2)
  3147. )
  3148. ));
  3149. $this->assertEquals($expected, $result);
  3150. $result = $this->Article->find('all', array('fields' => array('title', 'User.id', 'User.user'), 'limit' => 1, 'page' => 3, 'order' => 'Article.id ASC'));
  3151. $expected = array(array(
  3152. 'Article' => array('id' => 3, 'title' => 'Third Article'),
  3153. 'User' => array('id' => 1, 'user' => 'mariano'),
  3154. 'Comment' => array()
  3155. ));
  3156. $this->assertEquals($expected, $result);
  3157. $this->Article->contain(false, array('User' => array('fields' => 'user'), 'Comment'));
  3158. $result = $this->Article->find('all');
  3159. $this->assertTrue(Set::matches('/Article[id=1]', $result));
  3160. $this->assertTrue(Set::matches('/User[user=mariano]', $result));
  3161. $this->assertTrue(Set::matches('/Comment[article_id=1]', $result));
  3162. $this->Article->resetBindings();
  3163. $this->Article->contain(false, array('User' => array('fields' => array('user')), 'Comment'));
  3164. $result = $this->Article->find('all');
  3165. $this->assertTrue(Set::matches('/Article[id=1]', $result));
  3166. $this->assertTrue(Set::matches('/User[user=mariano]', $result));
  3167. $this->assertTrue(Set::matches('/Comment[article_id=1]', $result));
  3168. $this->Article->resetBindings();
  3169. }
  3170. /**
  3171. * testResetAddedAssociation method
  3172. *
  3173. */
  3174. public function testResetAddedAssociation() {
  3175. $this->assertTrue(empty($this->Article->hasMany['ArticlesTag']));
  3176. $this->Article->bindModel(array(
  3177. 'hasMany' => array('ArticlesTag')
  3178. ));
  3179. $this->assertTrue(!empty($this->Article->hasMany['ArticlesTag']));
  3180. $result = $this->Article->find('first', array(
  3181. 'conditions' => array('Article.id' => 1),
  3182. 'contain' => array('ArticlesTag')
  3183. ));
  3184. $expected = array('Article', 'ArticlesTag');
  3185. $this->assertTrue(!empty($result));
  3186. $this->assertEquals('First Article', $result['Article']['title']);
  3187. $this->assertTrue(!empty($result['ArticlesTag']));
  3188. $this->assertEquals($expected, array_keys($result));
  3189. $this->assertTrue(empty($this->Article->hasMany['ArticlesTag']));
  3190. $this->JoinA = ClassRegistry::init('JoinA');
  3191. $this->JoinB = ClassRegistry::init('JoinB');
  3192. $this->JoinC = ClassRegistry::init('JoinC');
  3193. $this->JoinA->Behaviors->attach('Containable');
  3194. $this->JoinB->Behaviors->attach('Containable');
  3195. $this->JoinC->Behaviors->attach('Containable');
  3196. $this->JoinA->JoinB->find('all', array('contain' => array('JoinA')));
  3197. $this->JoinA->bindModel(array('hasOne' => array('JoinAsJoinC' => array('joinTable' => 'as_cs'))), false);
  3198. $result = $this->JoinA->hasOne;
  3199. $this->JoinA->find('all');
  3200. $resultAfter = $this->JoinA->hasOne;
  3201. $this->assertEquals($result, $resultAfter);
  3202. }
  3203. /**
  3204. * testResetAssociation method
  3205. *
  3206. */
  3207. public function testResetAssociation() {
  3208. $this->Article->Behaviors->attach('Containable');
  3209. $this->Article->Comment->Behaviors->attach('Containable');
  3210. $this->Article->User->Behaviors->attach('Containable');
  3211. $initialOptions = array(
  3212. 'conditions' => array(
  3213. 'Comment.published' => 'Y',
  3214. ),
  3215. 'contain' => 'User',
  3216. 'recursive' => 1,
  3217. );
  3218. $initialModels = $this->Article->Comment->find('all', $initialOptions);
  3219. $findOptions = array(
  3220. 'conditions' => array(
  3221. 'User.user' => 'mariano',
  3222. ),
  3223. 'fields' => array('User.password'),
  3224. 'contain' => array('User.password')
  3225. );
  3226. $result = $this->Article->Comment->find('all', $findOptions);
  3227. $result = $this->Article->Comment->find('all', $initialOptions);
  3228. $this->assertEquals($result, $initialModels);
  3229. }
  3230. /**
  3231. * testResetDeeperHasOneAssociations method
  3232. *
  3233. */
  3234. public function testResetDeeperHasOneAssociations() {
  3235. $this->Article->User->unbindModel(array(
  3236. 'hasMany' => array('ArticleFeatured', 'Comment')
  3237. ), false);
  3238. $userHasOne = array('hasOne' => array('ArticleFeatured', 'Comment'));
  3239. $this->Article->User->bindModel($userHasOne, false);
  3240. $expected = $this->Article->User->hasOne;
  3241. $this->Article->find('all');
  3242. $this->assertEquals($expected, $this->Article->User->hasOne);
  3243. $this->Article->User->bindModel($userHasOne, false);
  3244. $expected = $this->Article->User->hasOne;
  3245. $this->Article->find('all', array(
  3246. 'contain' => array(
  3247. 'User' => array('ArticleFeatured', 'Comment')
  3248. )
  3249. ));
  3250. $this->assertEquals($expected, $this->Article->User->hasOne);
  3251. $this->Article->User->bindModel($userHasOne, false);
  3252. $expected = $this->Article->User->hasOne;
  3253. $this->Article->find('all', array(
  3254. 'contain' => array(
  3255. 'User' => array(
  3256. 'ArticleFeatured',
  3257. 'Comment' => array('fields' => array('created'))
  3258. )
  3259. )
  3260. ));
  3261. $this->assertEquals($expected, $this->Article->User->hasOne);
  3262. $this->Article->User->bindModel($userHasOne, false);
  3263. $expected = $this->Article->User->hasOne;
  3264. $this->Article->find('all', array(
  3265. 'contain' => array(
  3266. 'User' => array(
  3267. 'Comment' => array('fields' => array('created'))
  3268. )
  3269. )
  3270. ));
  3271. $this->assertEquals($expected, $this->Article->User->hasOne);
  3272. $this->Article->User->bindModel($userHasOne, false);
  3273. $expected = $this->Article->User->hasOne;
  3274. $this->Article->find('all', array(
  3275. 'contain' => array(
  3276. 'User.ArticleFeatured' => array(
  3277. 'conditions' => array('ArticleFeatured.published' => 'Y')
  3278. ),
  3279. 'User.Comment'
  3280. )
  3281. ));
  3282. $this->assertEquals($expected, $this->Article->User->hasOne);
  3283. }
  3284. /**
  3285. * testResetMultipleHabtmAssociations method
  3286. *
  3287. */
  3288. public function testResetMultipleHabtmAssociations() {
  3289. $articleHabtm = array(
  3290. 'hasAndBelongsToMany' => array(
  3291. 'Tag' => array(
  3292. 'className' => 'Tag',
  3293. 'joinTable' => 'articles_tags',
  3294. 'foreignKey' => 'article_id',
  3295. 'associationForeignKey' => 'tag_id'
  3296. ),
  3297. 'ShortTag' => array(
  3298. 'className' => 'Tag',
  3299. 'joinTable' => 'articles_tags',
  3300. 'foreignKey' => 'article_id',
  3301. 'associationForeignKey' => 'tag_id',
  3302. // LENGHT function mysql-only, using LIKE does almost the same
  3303. 'conditions' => "ShortTag.tag LIKE '???'"
  3304. )
  3305. )
  3306. );
  3307. $this->Article->resetBindings();
  3308. $this->Article->bindModel($articleHabtm, false);
  3309. $expected = $this->Article->hasAndBelongsToMany;
  3310. $this->Article->find('all');
  3311. $this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
  3312. $this->Article->resetBindings();
  3313. $this->Article->bindModel($articleHabtm, false);
  3314. $expected = $this->Article->hasAndBelongsToMany;
  3315. $this->Article->find('all', array('contain' => 'Tag.tag'));
  3316. $this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
  3317. $this->Article->resetBindings();
  3318. $this->Article->bindModel($articleHabtm, false);
  3319. $expected = $this->Article->hasAndBelongsToMany;
  3320. $this->Article->find('all', array('contain' => 'Tag'));
  3321. $this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
  3322. $this->Article->resetBindings();
  3323. $this->Article->bindModel($articleHabtm, false);
  3324. $expected = $this->Article->hasAndBelongsToMany;
  3325. $this->Article->find('all', array('contain' => array('Tag' => array('fields' => array(null)))));
  3326. $this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
  3327. $this->Article->resetBindings();
  3328. $this->Article->bindModel($articleHabtm, false);
  3329. $expected = $this->Article->hasAndBelongsToMany;
  3330. $this->Article->find('all', array('contain' => array('Tag' => array('fields' => array('Tag.tag')))));
  3331. $this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
  3332. $this->Article->resetBindings();
  3333. $this->Article->bindModel($articleHabtm, false);
  3334. $expected = $this->Article->hasAndBelongsToMany;
  3335. $this->Article->find('all', array('contain' => array('Tag' => array('fields' => array('Tag.tag', 'Tag.created')))));
  3336. $this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
  3337. $this->Article->resetBindings();
  3338. $this->Article->bindModel($articleHabtm, false);
  3339. $expected = $this->Article->hasAndBelongsToMany;
  3340. $this->Article->find('all', array('contain' => 'ShortTag.tag'));
  3341. $this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
  3342. $this->Article->resetBindings();
  3343. $this->Article->bindModel($articleHabtm, false);
  3344. $expected = $this->Article->hasAndBelongsToMany;
  3345. $this->Article->find('all', array('contain' => 'ShortTag'));
  3346. $this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
  3347. $this->Article->resetBindings();
  3348. $this->Article->bindModel($articleHabtm, false);
  3349. $expected = $this->Article->hasAndBelongsToMany;
  3350. $this->Article->find('all', array('contain' => array('ShortTag' => array('fields' => array(null)))));
  3351. $this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
  3352. $this->Article->resetBindings();
  3353. $this->Article->bindModel($articleHabtm, false);
  3354. $expected = $this->Article->hasAndBelongsToMany;
  3355. $this->Article->find('all', array('contain' => array('ShortTag' => array('fields' => array('ShortTag.tag')))));
  3356. $this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
  3357. $this->Article->resetBindings();
  3358. $this->Article->bindModel($articleHabtm, false);
  3359. $expected = $this->Article->hasAndBelongsToMany;
  3360. $this->Article->find('all', array('contain' => array('ShortTag' => array('fields' => array('ShortTag.tag', 'ShortTag.created')))));
  3361. $this->assertEquals($expected, $this->Article->hasAndBelongsToMany);
  3362. }
  3363. /**
  3364. * test that bindModel and unbindModel work with find() calls in between.
  3365. */
  3366. function testBindMultipleTimesWithFind() {
  3367. $binding = array(
  3368. 'hasOne' => array(
  3369. 'ArticlesTag' => array(
  3370. 'foreignKey' => false,
  3371. 'type' => 'INNER',
  3372. 'conditions' => array(
  3373. 'ArticlesTag.article_id = Article.id'
  3374. )
  3375. ),
  3376. 'Tag' => array(
  3377. 'type' => 'INNER',
  3378. 'foreignKey' => false,
  3379. 'conditions' => array(
  3380. 'ArticlesTag.tag_id = Tag.id'
  3381. )
  3382. )
  3383. )
  3384. );
  3385. $this->Article->unbindModel(array('hasAndBelongsToMany' => array('Tag')));
  3386. $this->Article->bindModel($binding);
  3387. $result = $this->Article->find('all', array('limit' => 1, 'contain' => array('ArticlesTag', 'Tag')));
  3388. $this->Article->unbindModel(array('hasAndBelongsToMany' => array('Tag')));
  3389. $this->Article->bindModel($binding);
  3390. $result = $this->Article->find('all', array('limit' => 1, 'contain' => array('ArticlesTag', 'Tag')));
  3391. $associated = $this->Article->getAssociated();
  3392. $this->assertEquals('hasAndBelongsToMany', $associated['Tag']);
  3393. $this->assertFalse(isset($associated['ArticleTag']));
  3394. }
  3395. /**
  3396. * test that autoFields doesn't splice in fields from other databases.
  3397. *
  3398. * @return void
  3399. */
  3400. public function testAutoFieldsWithMultipleDatabases() {
  3401. $config = new DATABASE_CONFIG();
  3402. $this->skipIf(
  3403. !isset($config->test) || !isset($config->test2),
  3404. 'Primary and secondary test databases not configured, skipping cross-database join tests.'
  3405. . ' To run these tests, you must define $test and $test2 in your database configuration.'
  3406. );
  3407. $db = ConnectionManager::getDataSource('test2');
  3408. $this->fixtureManager->loadSingle('User', $db);
  3409. $this->Article->User->setDataSource('test2');
  3410. $result = $this->Article->find('all', array(
  3411. 'fields' => array('Article.title'),
  3412. 'contain' => array('User')
  3413. ));
  3414. $this->assertTrue(isset($result[0]['Article']));
  3415. $this->assertTrue(isset($result[0]['User']));
  3416. }
  3417. /**
  3418. * test that autoFields doesn't splice in columns that aren't part of the join.
  3419. *
  3420. * @return void
  3421. */
  3422. public function testAutoFieldsWithRecursiveNegativeOne() {
  3423. $this->Article->recursive = -1;
  3424. $result = $this->Article->field('title', array('Article.title' => 'First Article'));
  3425. $this->assertNoErrors();
  3426. $this->assertEquals($result, 'First Article', 'Field is wrong');
  3427. }
  3428. /**
  3429. * test that find(all) doesn't return incorrect values when mixed with containable.
  3430. *
  3431. * @return void
  3432. */
  3433. public function testFindAllReturn() {
  3434. $result = $this->Article->find('all', array(
  3435. 'conditions' => array('Article.id' => 999999999)
  3436. ));
  3437. $this->assertEmpty($result, 'Should be empty.');
  3438. }
  3439. /**
  3440. * testLazyLoad method
  3441. *
  3442. * @return void
  3443. */
  3444. public function testLazyLoad() {
  3445. // Local set up
  3446. $this->User = ClassRegistry::init('User');
  3447. $this->User->bindModel(array(
  3448. 'hasMany' => array('Article', 'ArticleFeatured', 'Comment')
  3449. ), false);
  3450. try {
  3451. $this->User->find('first', array(
  3452. 'contain' => 'Comment',
  3453. 'lazyLoad' => true
  3454. ));
  3455. } catch (Exception $e) {
  3456. $exceptions = true;
  3457. }
  3458. $this->assertTrue(empty($exceptions));
  3459. }
  3460. /**
  3461. * containments method
  3462. *
  3463. * @param mixed $Model
  3464. * @param array $contain
  3465. * @return void
  3466. */
  3467. function __containments(&$Model, $contain = array()) {
  3468. if (!is_array($Model)) {
  3469. $result = $Model->containments($contain);
  3470. return $this->__containments($result['models']);
  3471. } else {
  3472. $result = $Model;
  3473. foreach ($result as $i => $containment) {
  3474. $result[$i] = array_diff_key($containment, array('instance' => true));
  3475. }
  3476. }
  3477. return $result;
  3478. }
  3479. /**
  3480. * assertBindings method
  3481. *
  3482. * @param mixed $Model
  3483. * @param array $expected
  3484. * @return void
  3485. */
  3486. function __assertBindings(&$Model, $expected = array()) {
  3487. $expected = array_merge(array('belongsTo' => array(), 'hasOne' => array(), 'hasMany' => array(), 'hasAndBelongsToMany' => array()), $expected);
  3488. foreach ($expected as $binding => $expect) {
  3489. $this->assertEquals(array_keys($Model->$binding), $expect);
  3490. }
  3491. }
  3492. /**
  3493. * bindings method
  3494. *
  3495. * @param mixed $Model
  3496. * @param array $extra
  3497. * @param bool $output
  3498. * @return void
  3499. */
  3500. function __bindings(&$Model, $extra = array(), $output = true) {
  3501. $relationTypes = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
  3502. $debug = '[';
  3503. $lines = array();
  3504. foreach ($relationTypes as $binding) {
  3505. if (!empty($Model->$binding)) {
  3506. $models = array_keys($Model->$binding);
  3507. foreach ($models as $linkedModel) {
  3508. $line = $linkedModel;
  3509. if (!empty($extra) && !empty($Model->{$binding}[$linkedModel])) {
  3510. $extraData = array();
  3511. foreach (array_intersect_key($Model->{$binding}[$linkedModel], array_flip($extra)) as $key => $value) {
  3512. $extraData[] = $key . ': ' . (is_array($value) ? '(' . implode(', ', $value) . ')' : $value);
  3513. }
  3514. $line .= ' {' . implode(' - ', $extraData) . '}';
  3515. }
  3516. $lines[] = $line;
  3517. }
  3518. }
  3519. }
  3520. $debug .= implode(' | ' , $lines);
  3521. $debug .= ']';
  3522. $debug = '<strong>' . $Model->alias . '</strong>: ' . $debug . '<br />';
  3523. if ($output) {
  3524. echo $debug;
  3525. }
  3526. return $debug;
  3527. }
  3528. }