PageRenderTime 45ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/cake/tests/cases/libs/model/behaviors/containable.test.php

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