PageRenderTime 87ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/cake/tests/cases/libs/model/model_read.test.php

https://bitbucket.org/webpolis/hurli
PHP | 7456 lines | 6784 code | 326 blank | 346 comment | 24 complexity | 2cd3a3cc5297beb0d6137e2610f2f396 MD5 | raw file
  1. <?php
  2. /**
  3. * ModelReadTest file
  4. *
  5. * PHP versions 4 and 5
  6. *
  7. * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
  8. * Copyright 2005-2010, 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-2010, 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
  17. * @since CakePHP(tm) v 1.2.0.4206
  18. * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  19. */
  20. require_once dirname(__FILE__) . DS . 'model.test.php';
  21. /**
  22. * ModelReadTest
  23. *
  24. * @package cake
  25. * @subpackage cake.tests.cases.libs.model.operations
  26. */
  27. class ModelReadTest extends BaseModelTest {
  28. /**
  29. * testFetchingNonUniqueFKJoinTableRecords()
  30. *
  31. * Tests if the results are properly returned in the case there are non-unique FK's
  32. * in the join table but another fields value is different. For example:
  33. * something_id | something_else_id | doomed = 1
  34. * something_id | something_else_id | doomed = 0
  35. * Should return both records and not just one.
  36. *
  37. * @access public
  38. * @return void
  39. */
  40. function testFetchingNonUniqueFKJoinTableRecords() {
  41. $this->loadFixtures('Something', 'SomethingElse', 'JoinThing');
  42. $Something = new Something();
  43. $joinThingData = array(
  44. 'JoinThing' => array(
  45. 'something_id' => 1,
  46. 'something_else_id' => 2,
  47. 'doomed' => '0',
  48. 'created' => '2007-03-18 10:39:23',
  49. 'updated' => '2007-03-18 10:41:31'
  50. )
  51. );
  52. $Something->JoinThing->create($joinThingData);
  53. $Something->JoinThing->save();
  54. $result = $Something->JoinThing->find('all', array('conditions' => array('something_else_id' => 2)));
  55. $this->assertEqual($result[0]['JoinThing']['doomed'], true);
  56. $this->assertEqual($result[1]['JoinThing']['doomed'], false);
  57. $result = $Something->find('first');
  58. $this->assertEqual(count($result['SomethingElse']), 2);
  59. $doomed = Set::extract('/JoinThing/doomed', $result['SomethingElse']);
  60. $this->assertTrue(in_array(true, $doomed));
  61. $this->assertTrue(in_array(false, $doomed));
  62. }
  63. /**
  64. * testGroupBy method
  65. *
  66. * These tests will never pass with Postgres or Oracle as all fields in a select must be
  67. * part of an aggregate function or in the GROUP BY statement.
  68. *
  69. * @access public
  70. * @return void
  71. */
  72. function testGroupBy() {
  73. $db = ConnectionManager::getDataSource('test_suite');
  74. $isStrictGroupBy = in_array($db->config['driver'], array('postgres', 'oracle'));
  75. $message = '%s Postgres and Oracle have strict GROUP BY and are incompatible with this test.';
  76. if ($this->skipIf($isStrictGroupBy, $message )) {
  77. return;
  78. }
  79. $this->loadFixtures('Project', 'Product', 'Thread', 'Message', 'Bid');
  80. $Thread =& new Thread();
  81. $Product =& new Product();
  82. $result = $Thread->find('all', array(
  83. 'group' => 'Thread.project_id',
  84. 'order' => 'Thread.id ASC'
  85. ));
  86. $expected = array(
  87. array(
  88. 'Thread' => array(
  89. 'id' => 1,
  90. 'project_id' => 1,
  91. 'name' => 'Project 1, Thread 1'
  92. ),
  93. 'Project' => array(
  94. 'id' => 1,
  95. 'name' => 'Project 1'
  96. ),
  97. 'Message' => array(
  98. array(
  99. 'id' => 1,
  100. 'thread_id' => 1,
  101. 'name' => 'Thread 1, Message 1'
  102. ))),
  103. array(
  104. 'Thread' => array(
  105. 'id' => 3,
  106. 'project_id' => 2,
  107. 'name' => 'Project 2, Thread 1'
  108. ),
  109. 'Project' => array(
  110. 'id' => 2,
  111. 'name' => 'Project 2'
  112. ),
  113. 'Message' => array(
  114. array(
  115. 'id' => 3,
  116. 'thread_id' => 3,
  117. 'name' => 'Thread 3, Message 1'
  118. ))));
  119. $this->assertEqual($result, $expected);
  120. $rows = $Thread->find('all', array(
  121. 'group' => 'Thread.project_id',
  122. 'fields' => array('Thread.project_id', 'COUNT(*) AS total')
  123. ));
  124. $result = array();
  125. foreach($rows as $row) {
  126. $result[$row['Thread']['project_id']] = $row[0]['total'];
  127. }
  128. $expected = array(
  129. 1 => 2,
  130. 2 => 1
  131. );
  132. $this->assertEqual($result, $expected);
  133. $rows = $Thread->find('all', array(
  134. 'group' => 'Thread.project_id',
  135. 'fields' => array('Thread.project_id', 'COUNT(*) AS total'),
  136. 'order'=> 'Thread.project_id'
  137. ));
  138. $result = array();
  139. foreach($rows as $row) {
  140. $result[$row['Thread']['project_id']] = $row[0]['total'];
  141. }
  142. $expected = array(
  143. 1 => 2,
  144. 2 => 1
  145. );
  146. $this->assertEqual($result, $expected);
  147. $result = $Thread->find('all', array(
  148. 'conditions' => array('Thread.project_id' => 1),
  149. 'group' => 'Thread.project_id'
  150. ));
  151. $expected = array(
  152. array(
  153. 'Thread' => array(
  154. 'id' => 1,
  155. 'project_id' => 1,
  156. 'name' => 'Project 1, Thread 1'
  157. ),
  158. 'Project' => array(
  159. 'id' => 1,
  160. 'name' => 'Project 1'
  161. ),
  162. 'Message' => array(
  163. array(
  164. 'id' => 1,
  165. 'thread_id' => 1,
  166. 'name' => 'Thread 1, Message 1'
  167. ))));
  168. $this->assertEqual($result, $expected);
  169. $result = $Thread->find('all', array(
  170. 'conditions' => array('Thread.project_id' => 1),
  171. 'group' => 'Thread.project_id, Project.id'
  172. ));
  173. $this->assertEqual($result, $expected);
  174. $result = $Thread->find('all', array(
  175. 'conditions' => array('Thread.project_id' => 1),
  176. 'group' => 'project_id'
  177. ));
  178. $this->assertEqual($result, $expected);
  179. $result = $Thread->find('all', array(
  180. 'conditions' => array('Thread.project_id' => 1),
  181. 'group' => array('project_id')
  182. ));
  183. $this->assertEqual($result, $expected);
  184. $result = $Thread->find('all', array(
  185. 'conditions' => array('Thread.project_id' => 1),
  186. 'group' => array('project_id', 'Project.id')
  187. ));
  188. $this->assertEqual($result, $expected);
  189. $result = $Thread->find('all', array(
  190. 'conditions' => array('Thread.project_id' => 1),
  191. 'group' => array('Thread.project_id', 'Project.id')
  192. ));
  193. $this->assertEqual($result, $expected);
  194. $expected = array(
  195. array('Product' => array('type' => 'Clothing'), array('price' => 32)),
  196. array('Product' => array('type' => 'Food'), array('price' => 9)),
  197. array('Product' => array('type' => 'Music'), array( 'price' => 4)),
  198. array('Product' => array('type' => 'Toy'), array('price' => 3))
  199. );
  200. $result = $Product->find('all',array(
  201. 'fields'=>array('Product.type', 'MIN(Product.price) as price'),
  202. 'group'=> 'Product.type',
  203. 'order' => 'Product.type ASC'
  204. ));
  205. $this->assertEqual($result, $expected);
  206. $result = $Product->find('all', array(
  207. 'fields'=>array('Product.type', 'MIN(Product.price) as price'),
  208. 'group'=> array('Product.type'),
  209. 'order' => 'Product.type ASC'));
  210. $this->assertEqual($result, $expected);
  211. }
  212. /**
  213. * testOldQuery method
  214. *
  215. * @access public
  216. * @return void
  217. */
  218. function testOldQuery() {
  219. $this->loadFixtures('Article');
  220. $Article =& new Article();
  221. $query = 'SELECT title FROM ';
  222. $query .= $this->db->fullTableName('articles');
  223. $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.id IN (1,2)';
  224. $results = $Article->query($query);
  225. $this->assertTrue(is_array($results));
  226. $this->assertEqual(count($results), 2);
  227. $query = 'SELECT title, body FROM ';
  228. $query .= $this->db->fullTableName('articles');
  229. $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.id = 1';
  230. $results = $Article->query($query, false);
  231. $this->assertTrue(!isset($this->db->_queryCache[$query]));
  232. $this->assertTrue(is_array($results));
  233. $query = 'SELECT title, id FROM ';
  234. $query .= $this->db->fullTableName('articles');
  235. $query .= ' WHERE ' . $this->db->fullTableName('articles');
  236. $query .= '.published = ' . $this->db->value('Y');
  237. $results = $Article->query($query, true);
  238. $this->assertTrue(isset($this->db->_queryCache[$query]));
  239. $this->assertTrue(is_array($results));
  240. }
  241. /**
  242. * testPreparedQuery method
  243. *
  244. * @access public
  245. * @return void
  246. */
  247. function testPreparedQuery() {
  248. $this->loadFixtures('Article');
  249. $Article =& new Article();
  250. $this->db->_queryCache = array();
  251. $finalQuery = 'SELECT title, published FROM ';
  252. $finalQuery .= $this->db->fullTableName('articles');
  253. $finalQuery .= ' WHERE ' . $this->db->fullTableName('articles');
  254. $finalQuery .= '.id = ' . $this->db->value(1);
  255. $finalQuery .= ' AND ' . $this->db->fullTableName('articles');
  256. $finalQuery .= '.published = ' . $this->db->value('Y');
  257. $query = 'SELECT title, published FROM ';
  258. $query .= $this->db->fullTableName('articles');
  259. $query .= ' WHERE ' . $this->db->fullTableName('articles');
  260. $query .= '.id = ? AND ' . $this->db->fullTableName('articles') . '.published = ?';
  261. $params = array(1, 'Y');
  262. $result = $Article->query($query, $params);
  263. $expected = array(
  264. '0' => array(
  265. $this->db->fullTableName('articles', false) => array(
  266. 'title' => 'First Article', 'published' => 'Y')
  267. ));
  268. if (isset($result[0][0])) {
  269. $expected[0][0] = $expected[0][$this->db->fullTableName('articles', false)];
  270. unset($expected[0][$this->db->fullTableName('articles', false)]);
  271. }
  272. $this->assertEqual($result, $expected);
  273. $this->assertTrue(isset($this->db->_queryCache[$finalQuery]));
  274. $finalQuery = 'SELECT id, created FROM ';
  275. $finalQuery .= $this->db->fullTableName('articles');
  276. $finalQuery .= ' WHERE ' . $this->db->fullTableName('articles');
  277. $finalQuery .= '.title = ' . $this->db->value('First Article');
  278. $query = 'SELECT id, created FROM ';
  279. $query .= $this->db->fullTableName('articles');
  280. $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.title = ?';
  281. $params = array('First Article');
  282. $result = $Article->query($query, $params, false);
  283. $this->assertTrue(is_array($result));
  284. $this->assertTrue(
  285. isset($result[0][$this->db->fullTableName('articles', false)])
  286. || isset($result[0][0])
  287. );
  288. $this->assertFalse(isset($this->db->_queryCache[$finalQuery]));
  289. $query = 'SELECT title FROM ';
  290. $query .= $this->db->fullTableName('articles');
  291. $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.title LIKE ?';
  292. $params = array('%First%');
  293. $result = $Article->query($query, $params);
  294. $this->assertTrue(is_array($result));
  295. $this->assertTrue(
  296. isset($result[0][$this->db->fullTableName('articles', false)]['title'])
  297. || isset($result[0][0]['title'])
  298. );
  299. //related to ticket #5035
  300. $query = 'SELECT title FROM ';
  301. $query .= $this->db->fullTableName('articles') . ' WHERE title = ? AND published = ?';
  302. $params = array('First? Article', 'Y');
  303. $Article->query($query, $params);
  304. $expected = 'SELECT title FROM ';
  305. $expected .= $this->db->fullTableName('articles');
  306. $expected .= " WHERE title = 'First? Article' AND published = 'Y'";
  307. $this->assertTrue(isset($this->db->_queryCache[$expected]));
  308. }
  309. /**
  310. * testParameterMismatch method
  311. *
  312. * @access public
  313. * @return void
  314. */
  315. function testParameterMismatch() {
  316. $this->loadFixtures('Article');
  317. $Article =& new Article();
  318. $query = 'SELECT * FROM ' . $this->db->fullTableName('articles');
  319. $query .= ' WHERE ' . $this->db->fullTableName('articles');
  320. $query .= '.published = ? AND ' . $this->db->fullTableName('articles') . '.user_id = ?';
  321. $params = array('Y');
  322. $this->expectError();
  323. ob_start();
  324. $result = $Article->query($query, $params);
  325. ob_end_clean();
  326. $this->assertEqual($result, null);
  327. }
  328. /**
  329. * testVeryStrangeUseCase method
  330. *
  331. * @access public
  332. * @return void
  333. */
  334. function testVeryStrangeUseCase() {
  335. $message = "%s skipping SELECT * FROM ? WHERE ? = ? AND ? = ?; prepared query.";
  336. $message .= " MSSQL is incompatible with this test.";
  337. if ($this->skipIf($this->db->config['driver'] == 'mssql', $message)) {
  338. return;
  339. }
  340. $this->loadFixtures('Article');
  341. $Article =& new Article();
  342. $query = 'SELECT * FROM ? WHERE ? = ? AND ? = ?';
  343. $param = array(
  344. $this->db->fullTableName('articles'),
  345. $this->db->fullTableName('articles') . '.user_id', '3',
  346. $this->db->fullTableName('articles') . '.published', 'Y'
  347. );
  348. $this->expectError();
  349. ob_start();
  350. $result = $Article->query($query, $param);
  351. ob_end_clean();
  352. }
  353. /**
  354. * testRecursiveUnbind method
  355. *
  356. * @access public
  357. * @return void
  358. */
  359. function testRecursiveUnbind() {
  360. $this->loadFixtures('Apple', 'Sample');
  361. $TestModel =& new Apple();
  362. $TestModel->recursive = 2;
  363. $result = $TestModel->find('all');
  364. $expected = array(
  365. array(
  366. 'Apple' => array (
  367. 'id' => 1,
  368. 'apple_id' => 2,
  369. 'color' => 'Red 1',
  370. 'name' => 'Red Apple 1',
  371. 'created' => '2006-11-22 10:38:58',
  372. 'date' => '1951-01-04',
  373. 'modified' => '2006-12-01 13:31:26',
  374. 'mytime' => '22:57:17'
  375. ),
  376. 'Parent' => array(
  377. 'id' => 2,
  378. 'apple_id' => 1,
  379. 'color' => 'Bright Red 1',
  380. 'name' => 'Bright Red Apple',
  381. 'created' => '2006-11-22 10:43:13',
  382. 'date' => '2014-01-01',
  383. 'modified' => '2006-11-30 18:38:10',
  384. 'mytime' => '22:57:17',
  385. 'Parent' => array(
  386. 'id' => 1,
  387. 'apple_id' => 2,
  388. 'color' => 'Red 1',
  389. 'name' => 'Red Apple 1',
  390. 'created' => '2006-11-22 10:38:58',
  391. 'date' => '1951-01-04',
  392. 'modified' => '2006-12-01 13:31:26',
  393. 'mytime' => '22:57:17'
  394. ),
  395. 'Sample' => array(
  396. 'id' => 2,
  397. 'apple_id' => 2,
  398. 'name' => 'sample2'
  399. ),
  400. 'Child' => array(
  401. array(
  402. 'id' => 1,
  403. 'apple_id' => 2,
  404. 'color' => 'Red 1',
  405. 'name' => 'Red Apple 1',
  406. 'created' => '2006-11-22 10:38:58',
  407. 'date' => '1951-01-04',
  408. 'modified' => '2006-12-01 13:31:26',
  409. 'mytime' => '22:57:17'
  410. ),
  411. array(
  412. 'id' => 3,
  413. 'apple_id' => 2,
  414. 'color' => 'blue green',
  415. 'name' => 'green blue',
  416. 'created' => '2006-12-25 05:13:36',
  417. 'date' => '2006-12-25',
  418. 'modified' => '2006-12-25 05:23:24',
  419. 'mytime' => '22:57:17'
  420. ),
  421. array(
  422. 'id' => 4,
  423. 'apple_id' => 2,
  424. 'color' => 'Blue Green',
  425. 'name' => 'Test Name',
  426. 'created' => '2006-12-25 05:23:36',
  427. 'date' => '2006-12-25',
  428. 'modified' => '2006-12-25 05:23:36',
  429. 'mytime' => '22:57:17'
  430. ))),
  431. 'Sample' => array(
  432. 'id' =>'',
  433. 'apple_id' => '',
  434. 'name' => ''
  435. ),
  436. 'Child' => array(
  437. array(
  438. 'id' => 2,
  439. 'apple_id' => 1,
  440. 'color' => 'Bright Red 1',
  441. 'name' => 'Bright Red Apple',
  442. 'created' => '2006-11-22 10:43:13',
  443. 'date' => '2014-01-01',
  444. 'modified' => '2006-11-30 18:38:10',
  445. 'mytime' => '22:57:17',
  446. 'Parent' => array(
  447. 'id' => 1,
  448. 'apple_id' => 2,
  449. 'color' => 'Red 1',
  450. 'name' => 'Red Apple 1',
  451. 'created' => '2006-11-22 10:38:58',
  452. 'date' => '1951-01-04',
  453. 'modified' => '2006-12-01 13:31:26',
  454. 'mytime' => '22:57:17'
  455. ),
  456. 'Sample' => array(
  457. 'id' => 2,
  458. 'apple_id' => 2,
  459. 'name' => 'sample2'
  460. ),
  461. 'Child' => array(
  462. array(
  463. 'id' => 1,
  464. 'apple_id' => 2,
  465. 'color' => 'Red 1',
  466. 'name' => 'Red Apple 1',
  467. 'created' => '2006-11-22 10:38:58',
  468. 'date' => '1951-01-04',
  469. 'modified' => '2006-12-01 13:31:26',
  470. 'mytime' => '22:57:17'
  471. ),
  472. array(
  473. 'id' => 3,
  474. 'apple_id' => 2,
  475. 'color' => 'blue green',
  476. 'name' => 'green blue',
  477. 'created' => '2006-12-25 05:13:36',
  478. 'date' => '2006-12-25',
  479. 'modified' => '2006-12-25 05:23:24',
  480. 'mytime' => '22:57:17'
  481. ),
  482. array(
  483. 'id' => 4,
  484. 'apple_id' => 2,
  485. 'color' => 'Blue Green',
  486. 'name' => 'Test Name',
  487. 'created' => '2006-12-25 05:23:36',
  488. 'date' => '2006-12-25',
  489. 'modified' => '2006-12-25 05:23:36',
  490. 'mytime' => '22:57:17'
  491. ))))),
  492. array(
  493. 'Apple' => array(
  494. 'id' => 2,
  495. 'apple_id' => 1,
  496. 'color' => 'Bright Red 1',
  497. 'name' => 'Bright Red Apple',
  498. 'created' => '2006-11-22 10:43:13',
  499. 'date' => '2014-01-01',
  500. 'modified' => '2006-11-30 18:38:10',
  501. 'mytime' => '22:57:17'
  502. ),
  503. 'Parent' => array(
  504. 'id' => 1,
  505. 'apple_id' => 2,
  506. 'color' => 'Red 1',
  507. 'name' => 'Red Apple 1',
  508. 'created' => '2006-11-22 10:38:58',
  509. 'date' => '1951-01-04',
  510. 'modified' => '2006-12-01 13:31:26',
  511. 'mytime' => '22:57:17',
  512. 'Parent' => array(
  513. 'id' => 2,
  514. 'apple_id' => 1,
  515. 'color' => 'Bright Red 1',
  516. 'name' => 'Bright Red Apple',
  517. 'created' => '2006-11-22 10:43:13',
  518. 'date' => '2014-01-01',
  519. 'modified' => '2006-11-30 18:38:10',
  520. 'mytime' => '22:57:17'
  521. ),
  522. 'Sample' => array(),
  523. 'Child' => array(
  524. array(
  525. 'id' => 2,
  526. 'apple_id' => 1,
  527. 'color' => 'Bright Red 1',
  528. 'name' => 'Bright Red Apple',
  529. 'created' => '2006-11-22 10:43:13',
  530. 'date' => '2014-01-01',
  531. 'modified' => '2006-11-30 18:38:10',
  532. 'mytime' => '22:57:17'
  533. ))),
  534. 'Sample' => array(
  535. 'id' => 2,
  536. 'apple_id' => 2,
  537. 'name' => 'sample2',
  538. 'Apple' => array(
  539. 'id' => 2,
  540. 'apple_id' => 1,
  541. 'color' => 'Bright Red 1',
  542. 'name' => 'Bright Red Apple',
  543. 'created' => '2006-11-22 10:43:13',
  544. 'date' => '2014-01-01',
  545. 'modified' => '2006-11-30 18:38:10',
  546. 'mytime' => '22:57:17'
  547. )),
  548. 'Child' => array(
  549. array(
  550. 'id' => 1,
  551. 'apple_id' => 2,
  552. 'color' => 'Red 1',
  553. 'name' => 'Red Apple 1',
  554. 'created' => '2006-11-22 10:38:58',
  555. 'date' => '1951-01-04',
  556. 'modified' => '2006-12-01 13:31:26',
  557. 'mytime' => '22:57:17',
  558. 'Parent' => array(
  559. 'id' => 2,
  560. 'apple_id' => 1,
  561. 'color' => 'Bright Red 1',
  562. 'name' => 'Bright Red Apple',
  563. 'created' => '2006-11-22 10:43:13',
  564. 'date' => '2014-01-01',
  565. 'modified' => '2006-11-30 18:38:10',
  566. 'mytime' => '22:57:17'
  567. ),
  568. 'Sample' => array(),
  569. 'Child' => array(
  570. array(
  571. 'id' => 2,
  572. 'apple_id' => 1,
  573. 'color' => 'Bright Red 1',
  574. 'name' => 'Bright Red Apple',
  575. 'created' => '2006-11-22 10:43:13',
  576. 'date' => '2014-01-01',
  577. 'modified' => '2006-11-30 18:38:10',
  578. 'mytime' => '22:57:17'
  579. ))),
  580. array(
  581. 'id' => 3,
  582. 'apple_id' => 2,
  583. 'color' => 'blue green',
  584. 'name' => 'green blue',
  585. 'created' => '2006-12-25 05:13:36',
  586. 'date' => '2006-12-25',
  587. 'modified' => '2006-12-25 05:23:24',
  588. 'mytime' => '22:57:17',
  589. 'Parent' => array(
  590. 'id' => 2,
  591. 'apple_id' => 1,
  592. 'color' => 'Bright Red 1',
  593. 'name' => 'Bright Red Apple',
  594. 'created' => '2006-11-22 10:43:13',
  595. 'date' => '2014-01-01',
  596. 'modified' => '2006-11-30 18:38:10',
  597. 'mytime' => '22:57:17'
  598. ),
  599. 'Sample' => array(
  600. 'id' => 1,
  601. 'apple_id' => 3,
  602. 'name' => 'sample1'
  603. )),
  604. array(
  605. 'id' => 4,
  606. 'apple_id' => 2,
  607. 'color' => 'Blue Green',
  608. 'name' => 'Test Name',
  609. 'created' => '2006-12-25 05:23:36',
  610. 'date' => '2006-12-25',
  611. 'modified' => '2006-12-25 05:23:36',
  612. 'mytime' => '22:57:17',
  613. 'Parent' => array(
  614. 'id' => 2,
  615. 'apple_id' => 1,
  616. 'color' => 'Bright Red 1',
  617. 'name' => 'Bright Red Apple',
  618. 'created' => '2006-11-22 10:43:13',
  619. 'date' => '2014-01-01',
  620. 'modified' => '2006-11-30 18:38:10',
  621. 'mytime' => '22:57:17'
  622. ),
  623. 'Sample' => array(
  624. 'id' => 3,
  625. 'apple_id' => 4,
  626. 'name' => 'sample3'
  627. ),
  628. 'Child' => array(
  629. array(
  630. 'id' => 6,
  631. 'apple_id' => 4,
  632. 'color' => 'My new appleOrange',
  633. 'name' => 'My new apple',
  634. 'created' => '2006-12-25 05:29:39',
  635. 'date' => '2006-12-25',
  636. 'modified' => '2006-12-25 05:29:39',
  637. 'mytime' => '22:57:17'
  638. ))))),
  639. array(
  640. 'Apple' => array(
  641. 'id' => 3,
  642. 'apple_id' => 2,
  643. 'color' => 'blue green',
  644. 'name' => 'green blue',
  645. 'created' => '2006-12-25 05:13:36',
  646. 'date' => '2006-12-25',
  647. 'modified' => '2006-12-25 05:23:24',
  648. 'mytime' => '22:57:17'
  649. ),
  650. 'Parent' => array(
  651. 'id' => 2,
  652. 'apple_id' => 1,
  653. 'color' => 'Bright Red 1',
  654. 'name' => 'Bright Red Apple',
  655. 'created' => '2006-11-22 10:43:13',
  656. 'date' => '2014-01-01',
  657. 'modified' => '2006-11-30 18:38:10',
  658. 'mytime' => '22:57:17',
  659. 'Parent' => array(
  660. 'id' => 1,
  661. 'apple_id' => 2,
  662. 'color' => 'Red 1',
  663. 'name' => 'Red Apple 1',
  664. 'created' => '2006-11-22 10:38:58',
  665. 'date' => '1951-01-04',
  666. 'modified' => '2006-12-01 13:31:26',
  667. 'mytime' => '22:57:17'
  668. ),
  669. 'Sample' => array(
  670. 'id' => 2,
  671. 'apple_id' => 2,
  672. 'name' => 'sample2'
  673. ),
  674. 'Child' => array(
  675. array(
  676. 'id' => 1,
  677. 'apple_id' => 2,
  678. 'color' => 'Red 1',
  679. 'name' => 'Red Apple 1',
  680. 'created' => '2006-11-22 10:38:58',
  681. 'date' => '1951-01-04',
  682. 'modified' => '2006-12-01 13:31:26',
  683. 'mytime' => '22:57:17'
  684. ),
  685. array(
  686. 'id' => 3,
  687. 'apple_id' => 2,
  688. 'color' => 'blue green',
  689. 'name' => 'green blue',
  690. 'created' => '2006-12-25 05:13:36',
  691. 'date' => '2006-12-25',
  692. 'modified' => '2006-12-25 05:23:24',
  693. 'mytime' => '22:57:17'
  694. ),
  695. array(
  696. 'id' => 4,
  697. 'apple_id' => 2,
  698. 'color' => 'Blue Green',
  699. 'name' => 'Test Name',
  700. 'created' => '2006-12-25 05:23:36',
  701. 'date' => '2006-12-25',
  702. 'modified' => '2006-12-25 05:23:36',
  703. 'mytime' => '22:57:17'
  704. ))),
  705. 'Sample' => array(
  706. 'id' => 1,
  707. 'apple_id' => 3,
  708. 'name' => 'sample1',
  709. 'Apple' => array(
  710. 'id' => 3,
  711. 'apple_id' => 2,
  712. 'color' => 'blue green',
  713. 'name' => 'green blue',
  714. 'created' => '2006-12-25 05:13:36',
  715. 'date' => '2006-12-25',
  716. 'modified' => '2006-12-25 05:23:24',
  717. 'mytime' => '22:57:17'
  718. )),
  719. 'Child' => array()
  720. ),
  721. array(
  722. 'Apple' => array(
  723. 'id' => 4,
  724. 'apple_id' => 2,
  725. 'color' => 'Blue Green',
  726. 'name' => 'Test Name',
  727. 'created' => '2006-12-25 05:23:36',
  728. 'date' => '2006-12-25',
  729. 'modified' => '2006-12-25 05:23:36',
  730. 'mytime' => '22:57:17'
  731. ),
  732. 'Parent' => array(
  733. 'id' => 2,
  734. 'apple_id' => 1,
  735. 'color' => 'Bright Red 1',
  736. 'name' => 'Bright Red Apple',
  737. 'created' => '2006-11-22 10:43:13',
  738. 'date' => '2014-01-01',
  739. 'modified' => '2006-11-30 18:38:10',
  740. 'mytime' => '22:57:17',
  741. 'Parent' => array(
  742. 'id' => 1,
  743. 'apple_id' => 2,
  744. 'color' => 'Red 1',
  745. 'name' => 'Red Apple 1',
  746. 'created' => '2006-11-22 10:38:58',
  747. 'date' => '1951-01-04',
  748. 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'),
  749. 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'),
  750. 'Child' => array(
  751. array(
  752. 'id' => 1,
  753. 'apple_id' => 2,
  754. 'color' => 'Red 1',
  755. 'name' => 'Red Apple 1',
  756. 'created' => '2006-11-22 10:38:58',
  757. 'date' => '1951-01-04',
  758. 'modified' => '2006-12-01 13:31:26',
  759. 'mytime' => '22:57:17'
  760. ),
  761. array(
  762. 'id' => 3,
  763. 'apple_id' => 2,
  764. 'color' => 'blue green',
  765. 'name' => 'green blue',
  766. 'created' => '2006-12-25 05:13:36',
  767. 'date' => '2006-12-25',
  768. 'modified' => '2006-12-25 05:23:24',
  769. 'mytime' => '22:57:17'
  770. ),
  771. array(
  772. 'id' => 4,
  773. 'apple_id' => 2,
  774. 'color' => 'Blue Green',
  775. 'name' => 'Test Name',
  776. 'created' => '2006-12-25 05:23:36',
  777. 'date' => '2006-12-25',
  778. 'modified' => '2006-12-25 05:23:36',
  779. 'mytime' => '22:57:17'
  780. ))),
  781. 'Sample' => array(
  782. 'id' => 3,
  783. 'apple_id' => 4,
  784. 'name' => 'sample3',
  785. 'Apple' => array(
  786. 'id' => 4,
  787. 'apple_id' => 2,
  788. 'color' => 'Blue Green',
  789. 'name' => 'Test Name',
  790. 'created' => '2006-12-25 05:23:36',
  791. 'date' => '2006-12-25',
  792. 'modified' => '2006-12-25 05:23:36',
  793. 'mytime' => '22:57:17'
  794. )),
  795. 'Child' => array(
  796. array(
  797. 'id' => 6,
  798. 'apple_id' => 4,
  799. 'color' => 'My new appleOrange',
  800. 'name' => 'My new apple',
  801. 'created' => '2006-12-25 05:29:39',
  802. 'date' => '2006-12-25',
  803. 'modified' => '2006-12-25 05:29:39',
  804. 'mytime' => '22:57:17',
  805. 'Parent' => array(
  806. 'id' => 4,
  807. 'apple_id' => 2,
  808. 'color' => 'Blue Green',
  809. 'name' => 'Test Name',
  810. 'created' => '2006-12-25 05:23:36',
  811. 'date' => '2006-12-25',
  812. 'modified' => '2006-12-25 05:23:36',
  813. 'mytime' => '22:57:17'
  814. ),
  815. 'Sample' => array(),
  816. 'Child' => array(
  817. array(
  818. 'id' => 7,
  819. 'apple_id' => 6,
  820. 'color' => 'Some wierd color',
  821. 'name' => 'Some odd color',
  822. 'created' => '2006-12-25 05:34:21',
  823. 'date' => '2006-12-25',
  824. 'modified' => '2006-12-25 05:34:21',
  825. 'mytime' => '22:57:17'
  826. ))))),
  827. array(
  828. 'Apple' => array(
  829. 'id' => 5,
  830. 'apple_id' => 5,
  831. 'color' => 'Green',
  832. 'name' => 'Blue Green',
  833. 'created' => '2006-12-25 05:24:06',
  834. 'date' => '2006-12-25',
  835. 'modified' => '2006-12-25 05:29:16',
  836. 'mytime' => '22:57:17'
  837. ),
  838. 'Parent' => array(
  839. 'id' => 5,
  840. 'apple_id' => 5,
  841. 'color' => 'Green',
  842. 'name' => 'Blue Green',
  843. 'created' => '2006-12-25 05:24:06',
  844. 'date' => '2006-12-25',
  845. 'modified' => '2006-12-25 05:29:16',
  846. 'mytime' => '22:57:17',
  847. 'Parent' => array(
  848. 'id' => 5,
  849. 'apple_id' => 5,
  850. 'color' => 'Green',
  851. 'name' => 'Blue Green',
  852. 'created' => '2006-12-25 05:24:06',
  853. 'date' => '2006-12-25',
  854. 'modified' => '2006-12-25 05:29:16',
  855. 'mytime' => '22:57:17'
  856. ),
  857. 'Sample' => array(
  858. 'id' => 4,
  859. 'apple_id' => 5,
  860. 'name' => 'sample4'
  861. ),
  862. 'Child' => array(
  863. array(
  864. 'id' => 5,
  865. 'apple_id' => 5,
  866. 'color' => 'Green',
  867. 'name' => 'Blue Green',
  868. 'created' => '2006-12-25 05:24:06',
  869. 'date' => '2006-12-25',
  870. 'modified' => '2006-12-25 05:29:16',
  871. 'mytime' => '22:57:17'
  872. ))),
  873. 'Sample' => array(
  874. 'id' => 4,
  875. 'apple_id' => 5,
  876. 'name' => 'sample4',
  877. 'Apple' => array(
  878. 'id' => 5,
  879. 'apple_id' => 5,
  880. 'color' => 'Green',
  881. 'name' => 'Blue Green',
  882. 'created' => '2006-12-25 05:24:06',
  883. 'date' => '2006-12-25',
  884. 'modified' => '2006-12-25 05:29:16',
  885. 'mytime' => '22:57:17'
  886. )),
  887. 'Child' => array(
  888. array(
  889. 'id' => 5,
  890. 'apple_id' => 5,
  891. 'color' => 'Green',
  892. 'name' => 'Blue Green',
  893. 'created' => '2006-12-25 05:24:06',
  894. 'date' => '2006-12-25',
  895. 'modified' => '2006-12-25 05:29:16',
  896. 'mytime' => '22:57:17',
  897. 'Parent' => array(
  898. 'id' => 5,
  899. 'apple_id' => 5,
  900. 'color' => 'Green',
  901. 'name' => 'Blue Green',
  902. 'created' => '2006-12-25 05:24:06',
  903. 'date' => '2006-12-25',
  904. 'modified' => '2006-12-25 05:29:16',
  905. 'mytime' => '22:57:17'
  906. ),
  907. 'Sample' => array(
  908. 'id' => 4,
  909. 'apple_id' => 5,
  910. 'name' => 'sample4'
  911. ),
  912. 'Child' => array(
  913. array(
  914. 'id' => 5,
  915. 'apple_id' => 5,
  916. 'color' => 'Green',
  917. 'name' => 'Blue Green',
  918. 'created' => '2006-12-25 05:24:06',
  919. 'date' => '2006-12-25',
  920. 'modified' => '2006-12-25 05:29:16',
  921. 'mytime' => '22:57:17'
  922. ))))),
  923. array(
  924. 'Apple' => array(
  925. 'id' => 6,
  926. 'apple_id' => 4,
  927. 'color' => 'My new appleOrange',
  928. 'name' => 'My new apple',
  929. 'created' => '2006-12-25 05:29:39',
  930. 'date' => '2006-12-25',
  931. 'modified' => '2006-12-25 05:29:39',
  932. 'mytime' => '22:57:17'
  933. ),
  934. 'Parent' => array(
  935. 'id' => 4,
  936. 'apple_id' => 2,
  937. 'color' => 'Blue Green',
  938. 'name' => 'Test Name',
  939. 'created' => '2006-12-25 05:23:36',
  940. 'date' => '2006-12-25',
  941. 'modified' => '2006-12-25 05:23:36',
  942. 'mytime' => '22:57:17',
  943. 'Parent' => array(
  944. 'id' => 2,
  945. 'apple_id' => 1,
  946. 'color' => 'Bright Red 1',
  947. 'name' => 'Bright Red Apple',
  948. 'created' => '2006-11-22 10:43:13',
  949. 'date' => '2014-01-01',
  950. 'modified' => '2006-11-30 18:38:10',
  951. 'mytime' => '22:57:17'
  952. ),
  953. 'Sample' => array(
  954. 'id' => 3,
  955. 'apple_id' => 4,
  956. 'name' => 'sample3'
  957. ),
  958. 'Child' => array(
  959. array(
  960. 'id' => 6,
  961. 'apple_id' => 4,
  962. 'color' => 'My new appleOrange',
  963. 'name' => 'My new apple',
  964. 'created' => '2006-12-25 05:29:39',
  965. 'date' => '2006-12-25',
  966. 'modified' => '2006-12-25 05:29:39',
  967. 'mytime' => '22:57:17'
  968. ))),
  969. 'Sample' => array(
  970. 'id' => '',
  971. 'apple_id' => '',
  972. 'name' => ''
  973. ),
  974. 'Child' => array(
  975. array(
  976. 'id' => 7,
  977. 'apple_id' => 6,
  978. 'color' => 'Some wierd color',
  979. 'name' => 'Some odd color',
  980. 'created' => '2006-12-25 05:34:21',
  981. 'date' => '2006-12-25',
  982. 'modified' => '2006-12-25 05:34:21',
  983. 'mytime' => '22:57:17',
  984. 'Parent' => array(
  985. 'id' => 6,
  986. 'apple_id' => 4,
  987. 'color' => 'My new appleOrange',
  988. 'name' => 'My new apple',
  989. 'created' => '2006-12-25 05:29:39',
  990. 'date' => '2006-12-25',
  991. 'modified' => '2006-12-25 05:29:39',
  992. 'mytime' => '22:57:17'
  993. ),
  994. 'Sample' => array()
  995. ))),
  996. array(
  997. 'Apple' => array(
  998. 'id' => 7,
  999. 'apple_id' => 6,
  1000. 'color' =>
  1001. 'Some wierd color',
  1002. 'name' => 'Some odd color',
  1003. 'created' => '2006-12-25 05:34:21',
  1004. 'date' => '2006-12-25',
  1005. 'modified' => '2006-12-25 05:34:21',
  1006. 'mytime' => '22:57:17'
  1007. ),
  1008. 'Parent' => array(
  1009. 'id' => 6,
  1010. 'apple_id' => 4,
  1011. 'color' => 'My new appleOrange',
  1012. 'name' => 'My new apple',
  1013. 'created' => '2006-12-25 05:29:39',
  1014. 'date' => '2006-12-25',
  1015. 'modified' => '2006-12-25 05:29:39',
  1016. 'mytime' => '22:57:17',
  1017. 'Parent' => array(
  1018. 'id' => 4,
  1019. 'apple_id' => 2,
  1020. 'color' => 'Blue Green',
  1021. 'name' => 'Test Name',
  1022. 'created' => '2006-12-25 05:23:36',
  1023. 'date' => '2006-12-25',
  1024. 'modified' => '2006-12-25 05:23:36',
  1025. 'mytime' => '22:57:17'
  1026. ),
  1027. 'Sample' => array(),
  1028. 'Child' => array(
  1029. array(
  1030. 'id' => 7,
  1031. 'apple_id' => 6,
  1032. 'color' => 'Some wierd color',
  1033. 'name' => 'Some odd color',
  1034. 'created' => '2006-12-25 05:34:21',
  1035. 'date' => '2006-12-25',
  1036. 'modified' => '2006-12-25 05:34:21',
  1037. 'mytime' => '22:57:17'
  1038. ))),
  1039. 'Sample' => array(
  1040. 'id' => '',
  1041. 'apple_id' => '',
  1042. 'name' => ''
  1043. ),
  1044. 'Child' => array()));
  1045. $this->assertEqual($result, $expected);
  1046. $result = $TestModel->Parent->unbindModel(array('hasOne' => array('Sample')));
  1047. $this->assertTrue($result);
  1048. $result = $TestModel->find('all');
  1049. $expected = array(
  1050. array(
  1051. 'Apple' => array(
  1052. 'id' => 1,
  1053. 'apple_id' => 2,
  1054. 'color' => 'Red 1',
  1055. 'name' => 'Red Apple 1',
  1056. 'created' => '2006-11-22 10:38:58',
  1057. 'date' => '1951-01-04',
  1058. 'modified' => '2006-12-01 13:31:26',
  1059. 'mytime' => '22:57:17'),
  1060. 'Parent' => array(
  1061. 'id' => 2,
  1062. 'apple_id' => 1,
  1063. 'color' => 'Bright Red 1',
  1064. 'name' => 'Bright Red Apple',
  1065. 'created' => '2006-11-22 10:43:13',
  1066. 'date' => '2014-01-01',
  1067. 'modified' => '2006-11-30 18:38:10',
  1068. 'mytime' => '22:57:17',
  1069. 'Parent' => array(
  1070. 'id' => 1,
  1071. 'apple_id' => 2,
  1072. 'color' => 'Red 1',
  1073. 'name' => 'Red Apple 1',
  1074. 'created' => '2006-11-22 10:38:58',
  1075. 'date' => '1951-01-04',
  1076. 'modified' => '2006-12-01 13:31:26',
  1077. 'mytime' => '22:57:17'
  1078. ),
  1079. 'Child' => array(
  1080. array(
  1081. 'id' => 1,
  1082. 'apple_id' => 2,
  1083. 'color' => 'Red 1',
  1084. 'name' => 'Red Apple 1',
  1085. 'created' => '2006-11-22 10:38:58',
  1086. 'date' => '1951-01-04',
  1087. 'modified' => '2006-12-01 13:31:26',
  1088. 'mytime' => '22:57:17'
  1089. ),
  1090. array(
  1091. 'id' => 3,
  1092. 'apple_id' => 2,
  1093. 'color' => 'blue green',
  1094. 'name' => 'green blue',
  1095. 'created' => '2006-12-25 05:13:36',
  1096. 'date' => '2006-12-25',
  1097. 'modified' => '2006-12-25 05:23:24',
  1098. 'mytime' => '22:57:17'
  1099. ),
  1100. array(
  1101. 'id' => 4,
  1102. 'apple_id' => 2,
  1103. 'color' => 'Blue Green',
  1104. 'name' => 'Test Name',
  1105. 'created' => '2006-12-25 05:23:36',
  1106. 'date' => '2006-12-25',
  1107. 'modified' => '2006-12-25 05:23:36',
  1108. 'mytime' => '22:57:17'
  1109. ))),
  1110. 'Sample' => array(
  1111. 'id' =>'',
  1112. 'apple_id' => '',
  1113. 'name' => ''
  1114. ),
  1115. 'Child' => array(
  1116. array(
  1117. 'id' => 2,
  1118. 'apple_id' => 1,
  1119. 'color' => 'Bright Red 1',
  1120. 'name' => 'Bright Red Apple',
  1121. 'created' => '2006-11-22 10:43:13',
  1122. 'date' => '2014-01-01',
  1123. 'modified' => '2006-11-30 18:38:10',
  1124. 'mytime' => '22:57:17',
  1125. 'Parent' => array(
  1126. 'id' => 1,
  1127. 'apple_id' => 2,
  1128. 'color' => 'Red 1',
  1129. 'name' => 'Red Apple 1',
  1130. 'created' => '2006-11-22 10:38:58',
  1131. 'date' => '1951-01-04',
  1132. 'modified' => '2006-12-01 13:31:26',
  1133. 'mytime' => '22:57:17'
  1134. ),
  1135. 'Sample' => array(
  1136. 'id' => 2,
  1137. 'apple_id' => 2,
  1138. 'name' => 'sample2'
  1139. ),
  1140. 'Child' => array(
  1141. array(
  1142. 'id' => 1,
  1143. 'apple_id' => 2,
  1144. 'color' => 'Red 1',
  1145. 'name' => 'Red Apple 1',
  1146. 'created' => '2006-11-22 10:38:58',
  1147. 'date' => '1951-01-04',
  1148. 'modified' => '2006-12-01 13:31:26',
  1149. 'mytime' => '22:57:17'
  1150. ),
  1151. array(
  1152. 'id' => 3,
  1153. 'apple_id' => 2,
  1154. 'color' => 'blue green',
  1155. 'name' => 'green blue',
  1156. 'created' => '2006-12-25 05:13:36',
  1157. 'date' => '2006-12-25',
  1158. 'modified' => '2006-12-25 05:23:24',
  1159. 'mytime' => '22:57:17'
  1160. ),
  1161. array(
  1162. 'id' => 4,
  1163. 'apple_id' => 2,
  1164. 'color' => 'Blue Green',
  1165. 'name' => 'Test Name',
  1166. 'created' => '2006-12-25 05:23:36',
  1167. 'date' => '2006-12-25',
  1168. 'modified' => '2006-12-25 05:23:36',
  1169. 'mytime' => '22:57:17'
  1170. ))))),
  1171. array(
  1172. 'Apple' => array(
  1173. 'id' => 2,
  1174. 'apple_id' => 1,
  1175. 'color' => 'Bright Red 1',
  1176. 'name' => 'Bright Red Apple',
  1177. 'created' => '2006-11-22 10:43:13',
  1178. 'date' => '2014-01-01',
  1179. 'modified' => '2006-11-30 18:38:10',
  1180. 'mytime' => '22:57:17'
  1181. ),
  1182. 'Parent' => array(
  1183. 'id' => 1,
  1184. 'apple_id' => 2,
  1185. 'color' => 'Red 1',
  1186. 'name' => 'Red Apple 1',
  1187. 'created' => '2006-11-22 10:38:58',
  1188. 'date' => '1951-01-04',
  1189. 'modified' => '2006-12-01 13:31:26',
  1190. 'mytime' => '22:57:17',
  1191. 'Parent' => array(
  1192. 'id' => 2,
  1193. 'apple_id' => 1,
  1194. 'color' => 'Bright Red 1',
  1195. 'name' => 'Bright Red Apple',
  1196. 'created' => '2006-11-22 10:43:13',
  1197. 'date' => '2014-01-01',
  1198. 'modified' => '2006-11-30 18:38:10',
  1199. 'mytime' => '22:57:17'
  1200. ),
  1201. 'Child' => array(
  1202. array(
  1203. 'id' => 2,
  1204. 'apple_id' => 1,
  1205. 'color' => 'Bright Red 1',
  1206. 'name' => 'Bright Red Apple',
  1207. 'created' => '2006-11-22 10:43:13',
  1208. 'date' => '2014-01-01',
  1209. 'modified' => '2006-11-30 18:38:10',
  1210. 'mytime' => '22:57:17'
  1211. ))),
  1212. 'Sample' => array(
  1213. 'id' => 2,
  1214. 'apple_id' => 2,
  1215. 'name' => 'sample2',
  1216. 'Apple' => array(
  1217. 'id' => 2,
  1218. 'apple_id' => 1,
  1219. 'color' => 'Bright Red 1',
  1220. 'name' => 'Bright Red Apple',
  1221. 'created' => '2006-11-22 10:43:13',
  1222. 'date' => '2014-01-01',
  1223. 'modified' => '2006-11-30 18:38:10',
  1224. 'mytime' => '22:57:17'
  1225. )),
  1226. 'Child' => array(
  1227. array(
  1228. 'id' => 1,
  1229. 'apple_id' => 2,
  1230. 'color' => 'Red 1',
  1231. 'name' => 'Red Apple 1',
  1232. 'created' => '2006-11-22 10:38:58',
  1233. 'date' => '1951-01-04',
  1234. 'modified' => '2006-12-01 13:31:26',
  1235. 'mytime' => '22:57:17',
  1236. 'Parent' => array(
  1237. 'id' => 2,
  1238. 'apple_id' => 1,
  1239. 'color' => 'Bright Red 1',
  1240. 'name' => 'Bright Red Apple',
  1241. 'created' => '2006-11-22 10:43:13',
  1242. 'date' => '2014-01-01',
  1243. 'modified' => '2006-11-30 18:38:10',
  1244. 'mytime' => '22:57:17'
  1245. ),
  1246. 'Sample' => array(),
  1247. 'Child' => array(
  1248. array(
  1249. 'id' => 2,
  1250. 'apple_id' => 1,
  1251. 'color' => 'Bright Red 1',
  1252. 'name' => 'Bright Red Apple',
  1253. 'created' => '2006-11-22 10:43:13',
  1254. 'date' => '2014-01-01', 'modified' =>
  1255. '2006-11-30 18:38:10',
  1256. 'mytime' => '22:57:17'
  1257. ))),
  1258. array(
  1259. 'id' => 3,
  1260. 'apple_id' => 2,
  1261. 'color' => 'blue green',
  1262. 'name' => 'green blue',
  1263. 'created' => '2006-12-25 05:13:36',
  1264. 'date' => '2006-12-25',
  1265. 'modified' => '2006-12-25 05:23:24',
  1266. 'mytime' => '22:57:17',
  1267. 'Parent' => array(
  1268. 'id' => 2,
  1269. 'apple_id' => 1,
  1270. 'color' => 'Bright Red 1',
  1271. 'name' => 'Bright Red Apple',
  1272. 'created' => '2006-11-22 10:43:13',
  1273. 'date' => '2014-01-01',
  1274. 'modified' => '2006-11-30 18:38:10',
  1275. 'mytime' => '22:57:17'
  1276. ),
  1277. 'Sample' => array(
  1278. 'id' => 1,
  1279. 'apple_id' => 3,
  1280. 'name' => 'sample1'
  1281. )),
  1282. array(
  1283. 'id' => 4,
  1284. 'apple_id' => 2,
  1285. 'color' => 'Blue Green',
  1286. 'name' => 'Test Name',
  1287. 'created' => '2006-12-25 05:23:36',
  1288. 'date' => '2006-12-25',
  1289. 'modified' => '2006-12-25 05:23:36',
  1290. 'mytime' => '22:57:17',
  1291. 'Parent' => array(
  1292. 'id' => 2,
  1293. 'apple_id' => 1,
  1294. 'color' => 'Bright Red 1',
  1295. 'name' => 'Bright Red Apple',
  1296. 'created' => '2006-11-22 10:43:13',
  1297. 'date' => '2014-01-01',
  1298. 'modified' => '2006-11-30 18:38:10',
  1299. 'mytime' => '22:57:17'
  1300. ),
  1301. 'Sample' => array(
  1302. 'id' => 3,
  1303. 'apple_id' => 4,
  1304. 'name' => 'sample3'
  1305. ),
  1306. 'Child' => array(
  1307. array(
  1308. 'id' => 6,
  1309. 'apple_id' => 4,
  1310. 'color' => 'My new appleOrange',
  1311. 'name' => 'My new apple',
  1312. 'created' => '2006-12-25 05:29:39',
  1313. 'date' => '2006-12-25',
  1314. 'modified' => '2006-12-25 05:29:39',
  1315. 'mytime' => '22:57:17'
  1316. ))))),
  1317. array(
  1318. 'Apple' => array(
  1319. 'id' => 3,
  1320. 'apple_id' => 2,
  1321. 'color' => 'blue green',
  1322. 'name' => 'green blue',
  1323. 'created' => '2006-12-25 05:13:36',
  1324. 'date' => '2006-12-25',
  1325. 'modified' => '2006-12-25 05:23:24',
  1326. 'mytime' => '22:57:17'
  1327. ),
  1328. 'Parent' => array(
  1329. 'id' => 2,
  1330. 'apple_id' => 1,
  1331. 'color' => 'Bright Red 1',
  1332. 'name' => 'Bright Red Apple',
  1333. 'created' => '2006-11-22 10:43:13',
  1334. 'date' => '2014-01-01',
  1335. 'modified' => '2006-11-30 18:38:10',
  1336. 'mytime' => '22:57:17',
  1337. 'Parent' => array(
  1338. 'id' => 1,
  1339. 'apple_id' => 2,
  1340. 'color' => 'Red 1',
  1341. 'name' => 'Red Apple 1',
  1342. 'created' => '2006-11-22 10:38:58',
  1343. 'date' => '1951-01-04',
  1344. 'modified' => '2006-12-01 13:31:26',
  1345. 'mytime' => '22:57:17'
  1346. ),
  1347. 'Child' => array(
  1348. array(
  1349. 'id' => 1,
  1350. 'apple_id' => 2,
  1351. 'color' => 'Red 1',
  1352. 'name' => 'Red Apple 1',
  1353. 'created' => '2006-11-22 10:38:58',
  1354. 'date' => '1951-01-04',
  1355. 'modified' => '2006-12-01 13:31:26',
  1356. 'mytime' => '22:57:17'
  1357. ),
  1358. array(
  1359. 'id' => 3,
  1360. 'apple_id' => 2,
  1361. 'color' => 'blue green',
  1362. 'name' => 'green blue',
  1363. 'created' => '2006-12-25 05:13:36',
  1364. 'date' => '2006-12-25',
  1365. 'modified' => '2006-12-25 05:23:24',
  1366. 'mytime' => '22:57:17'
  1367. ),
  1368. array(
  1369. 'id' => 4,
  1370. 'apple_id' => 2,
  1371. 'color' => 'Blue Green',
  1372. 'name' => 'Test Name',
  1373. 'created' => '2006-12-25 05:23:36',
  1374. 'date' => '2006-12-25',
  1375. 'modified' => '2006-12-25 05:23:36',
  1376. 'mytime' => '22:57:17'
  1377. ))),
  1378. 'Sample' => array(
  1379. 'id' => 1,
  1380. 'apple_id' => 3,
  1381. 'name' => 'sample1',
  1382. 'Apple' => array(
  1383. 'id' => 3,
  1384. 'apple_id' => 2,
  1385. 'color' => 'blue green',
  1386. 'name' => 'green blue',
  1387. 'created' => '2006-12-25 05:13:36',
  1388. 'date' => '2006-12-25',
  1389. 'modified' => '2006-12-25 05:23:24',
  1390. 'mytime' => '22:57:17'
  1391. )),
  1392. 'Child' => array()
  1393. ),
  1394. array(
  1395. 'Apple' => array(
  1396. 'id' => 4,
  1397. 'apple_id' => 2,
  1398. 'color' => 'Blue Green',
  1399. 'name' => 'Test Name',
  1400. 'created' => '2006-12-25 05:23:36',
  1401. 'date' => '2006-12-25',
  1402. 'modified' => '2006-12-25 05:23:36',
  1403. 'mytime' => '22:57:17'
  1404. ),
  1405. 'Parent' => array(
  1406. 'id' => 2,
  1407. 'apple_id' => 1,
  1408. 'color' => 'Bright Red 1',
  1409. 'name' => 'Bright Red Apple',
  1410. 'created' => '2006-11-22 10:43:13',
  1411. 'date' => '2014-01-01',
  1412. 'modified' => '2006-11-30 18:38:10',
  1413. 'mytime' => '22:57:17',
  1414. 'Parent' => array(
  1415. 'id' => 1,
  1416. 'apple_id' => 2,
  1417. 'color' => 'Red 1',
  1418. 'name' => 'Red Apple 1',
  1419. 'created' => '2006-11-22 10:38:58',
  1420. 'date' => '1951-01-04',
  1421. 'modified' => '2006-12-01 13:31:26',
  1422. 'mytime' => '22:57:17'
  1423. ),
  1424. 'Child' => array(
  1425. array(
  1426. 'id' => 1,
  1427. 'apple_id' => 2,
  1428. 'color' => 'Red 1',
  1429. 'name' => 'Red Apple 1',
  1430. 'created' => '2006-11-22 10:38:58',
  1431. 'date' => '1951-01-04',
  1432. 'modified' => '2006-12-01 13:31:26',
  1433. 'mytime' => '22:57:17'
  1434. ),
  1435. array(
  1436. 'id' => 3,
  1437. 'apple_id' => 2,
  1438. 'color' => 'blue green',
  1439. 'name' => 'green blue',
  1440. 'created' => '2006-12-25 05:13:36',
  1441. 'date' => '2006-12-25',
  1442. 'modified' => '2006-12-25 05:23:24',
  1443. 'mytime' => '22:57:17'
  1444. ),
  1445. array(
  1446. 'id' => 4,
  1447. 'apple_id' => 2,
  1448. 'color' => 'Blue Green',
  1449. 'name' => 'Test Name',
  1450. 'created' => '2006-12-25 05:23:36',
  1451. 'date' => '2006-12-25',
  1452. 'modified' => '2006-12-25 05:23:36',
  1453. 'mytime' => '22:57:17'
  1454. ))),
  1455. 'Sample' => array(
  1456. 'id' => 3,
  1457. 'apple_id' => 4,
  1458. 'name' => 'sample3',
  1459. 'Apple' => array(
  1460. 'id' => 4,
  1461. 'apple_id' => 2,
  1462. 'color' => 'Blue Green',
  1463. 'name' => 'Test Name',
  1464. 'created' => '2006-12-25 05:23:36',
  1465. 'date' => '2006-12-25',
  1466. 'modified' => '2006-12-25 05:23:36',
  1467. 'mytime' => '22:57:17'
  1468. )),
  1469. 'Child' => array(
  1470. array(
  1471. 'id' => 6,
  1472. 'apple_id' => 4,
  1473. 'color' => 'My new appleOrange',
  1474. 'name' => 'My new apple',
  1475. 'created' => '2006-12-25 05:29:39',
  1476. 'date' => '2006-12-25',
  1477. 'modified' => '2006-12-25 05:29:39',
  1478. 'mytime' => '22:57:17',
  1479. 'Parent' => array(
  1480. 'id' => 4,
  1481. 'apple_id' => 2,
  1482. 'color' => 'Blue Green',
  1483. 'name' => 'Test Name',
  1484. 'created' => '2006-12-25 05:23:36',
  1485. 'date' => '2006-12-25',
  1486. 'modified' => '2006-12-25 05:23:36',
  1487. 'mytime' => '22:57:17'
  1488. ),
  1489. 'Sample' => array(),
  1490. 'Child' => array(
  1491. array(
  1492. 'id' => 7,
  1493. 'apple_id' => 6,
  1494. 'color' => 'Some wierd color',
  1495. 'name' => 'Some odd color',
  1496. 'created' => '2006-12-25 05:34:21',
  1497. 'date' => '2006-12-25',
  1498. 'modified' => '2006-12-25 05:34:21',
  1499. 'mytime' => '22:57:17'
  1500. ))))),
  1501. array(
  1502. 'Apple' => array(
  1503. 'id' => 5,
  1504. 'apple_id' => 5,
  1505. 'color' => 'Green',
  1506. 'name' => 'Blue Green',
  1507. 'created' => '2006-12-25 05:24:06',
  1508. 'date' => '2006-12-25',
  1509. 'modified' => '2006-12-25 05:29:16',
  1510. 'mytime' => '22:57:17'
  1511. ),
  1512. 'Parent' => array(
  1513. 'id' => 5,
  1514. 'apple_id' => 5,
  1515. 'color' => 'Green',
  1516. 'name' => 'Blue Green',
  1517. 'created' => '2006-12-25 05:24:06',
  1518. 'date' => '2006-12-25',
  1519. 'modified' => '2006-12-25 05:29:16',
  1520. 'mytime' => '22:57:17',
  1521. 'Parent' => array(
  1522. 'id' => 5,
  1523. 'apple_id' => 5,
  1524. 'color' => 'Green',
  1525. 'name' => 'Blue Green',
  1526. 'created' => '2006-12-25 05:24:06',
  1527. 'date' => '2006-12-25',
  1528. 'modified' => '2006-12-25 05:29:16',
  1529. 'mytime' => '22:57:17'
  1530. ),
  1531. 'Child' => array(
  1532. array(
  1533. 'id' => 5,
  1534. 'apple_id' => 5,
  1535. 'color' => 'Green',
  1536. 'name' => 'Blue Green',
  1537. 'created' => '2006-12-25 05:24:06',
  1538. 'date' => '2006-12-25',
  1539. 'modified' => '2006-12-25 05:29:16',
  1540. 'mytime' => '22:57:17'
  1541. ))),
  1542. 'Sample' => array(
  1543. 'id' => 4,
  1544. 'apple_id' => 5,
  1545. 'name' => 'sample4',
  1546. 'Apple' => array(
  1547. 'id' => 5,
  1548. 'apple_id' => 5,
  1549. 'color' => 'Green',
  1550. 'name' => 'Blue Green',
  1551. 'created' => '2006-12-25 05:24:06',
  1552. 'date' => '2006-12-25',
  1553. 'modified' => '2006-12-25 05:29:16',
  1554. 'mytime' => '22:57:17'
  1555. )),
  1556. 'Child' => array(
  1557. array(
  1558. 'id' => 5,
  1559. 'apple_id' => 5,
  1560. 'color' => 'Green',
  1561. 'name' => 'Blue Green',
  1562. 'created' => '2006-12-25 05:24:06',
  1563. 'date' => '2006-12-25',
  1564. 'modified' => '2006-12-25 05:29:16',
  1565. 'mytime' => '22:57:17',
  1566. 'Parent' => array(
  1567. 'id' => 5,
  1568. 'apple_id' => 5,
  1569. 'color' => 'Green',
  1570. 'name' => 'Blue Green',
  1571. 'created' => '2006-12-25 05:24:06',
  1572. 'date' => '2006-12-25',
  1573. 'modified' => '2006-12-25 05:29:16',
  1574. 'mytime' => '22:57:17'
  1575. ),
  1576. 'Sample' => array(
  1577. 'id' => 4,
  1578. 'apple_id' => 5,
  1579. 'name' => 'sample4'
  1580. ),
  1581. 'Child' => array(
  1582. array(
  1583. 'id' => 5,
  1584. 'apple_id' => 5,
  1585. 'color' => 'Green',
  1586. 'name' => 'Blue Green',
  1587. 'created' => '2006-12-25 05:24:06',
  1588. 'date' => '2006-12-25',
  1589. 'modified' => '2006-12-25 05:29:16',
  1590. 'mytime' => '22:57:17'
  1591. ))))),
  1592. array(
  1593. 'Apple' => array(
  1594. 'id' => 6,
  1595. 'apple_id' => 4,
  1596. 'color' => 'My new appleOrange',
  1597. 'name' => 'My new apple',
  1598. 'created' => '2006-12-25 05:29:39',
  1599. 'date' => '2006-12-25',
  1600. 'modified' => '2006-12-25 05:29:39',
  1601. 'mytime' => '22:57:17'
  1602. ),
  1603. 'Parent' => array(
  1604. 'id' => 4,
  1605. 'apple_id' => 2,
  1606. 'color' => 'Blue Green',
  1607. 'name' => 'Test Name',
  1608. 'created' => '2006-12-25 05:23:36',
  1609. 'date' => '2006-12-25',
  1610. 'modified' => '2006-12-25 05:23:36',
  1611. 'mytime' => '22:57:17',
  1612. 'Parent' => array(
  1613. 'id' => 2,
  1614. 'apple_id' => 1,
  1615. 'color' => 'Bright Red 1',
  1616. 'name' => 'Bright Red Apple',
  1617. 'created' => '2006-11-22 10:43:13',
  1618. 'date' => '2014-01-01',
  1619. 'modified' => '2006-11-30 18:38:10',
  1620. 'mytime' => '22:57:17'
  1621. ),
  1622. 'Child' => array(
  1623. array(
  1624. 'id' => 6,
  1625. 'apple_id' => 4,
  1626. 'color' => 'My new appleOrange',
  1627. 'name' => 'My new apple',
  1628. 'created' => '2006-12-25 05:29:39',
  1629. 'date' => '2006-12-25',
  1630. 'modified' => '2006-12-25 05:29:39',
  1631. 'mytime' => '22:57:17'
  1632. ))),
  1633. 'Sample' => array(
  1634. 'id' => '',
  1635. 'apple_id' => '',
  1636. 'name' => ''
  1637. ),
  1638. 'Child' => array(
  1639. array(
  1640. 'id' => 7,
  1641. 'apple_id' => 6,
  1642. 'color' => 'Some wierd color',
  1643. 'name' => 'Some odd color',
  1644. 'created' => '2006-12-25 05:34:21',
  1645. 'date' => '2006-12-25',
  1646. 'modified' => '2006-12-25 05:34:21',
  1647. 'mytime' => '22:57:17',
  1648. 'Parent' => array(
  1649. 'id' => 6,
  1650. 'apple_id' => 4,
  1651. 'color' => 'My new appleOrange',
  1652. 'name' => 'My new apple',
  1653. 'created' => '2006-12-25 05:29:39',
  1654. 'date' => '2006-12-25',
  1655. 'modified' => '2006-12-25 05:29:39',
  1656. 'mytime' => '22:57:17'
  1657. ),
  1658. 'Sample' => array()
  1659. ))),
  1660. array(
  1661. 'Apple' => array(
  1662. 'id' => 7,
  1663. 'apple_id' => 6,
  1664. 'color' => 'Some wierd color',
  1665. 'name' => 'Some odd color',
  1666. 'created' => '2006-12-25 05:34:21',
  1667. 'date' => '2006-12-25',
  1668. 'modified' => '2006-12-25 05:34:21',
  1669. 'mytime' => '22:57:17'
  1670. ),
  1671. 'Parent' => array(
  1672. 'id' => 6,
  1673. 'apple_id' => 4,
  1674. 'color' => 'My new appleOrange',
  1675. 'name' => 'My new apple',
  1676. 'created' => '2006-12-25 05:29:39',
  1677. 'date' => '2006-12-25',
  1678. 'modified' => '2006-12-25 05:29:39',
  1679. 'mytime' => '22:57:17',
  1680. 'Parent' => array(
  1681. 'id' => 4,
  1682. 'apple_id' => 2,
  1683. 'color' => 'Blue Green',
  1684. 'name' => 'Test Name',
  1685. 'created' => '2006-12-25 05:23:36',
  1686. 'date' => '2006-12-25',
  1687. 'modified' => '2006-12-25 05:23:36',
  1688. 'mytime' => '22:57:17'
  1689. ),
  1690. 'Child' => array(
  1691. array(
  1692. 'id' => 7,
  1693. 'apple_id' => 6,
  1694. 'color' => 'Some wierd color',
  1695. 'name' => 'Some odd color',
  1696. 'created' => '2006-12-25 05:34:21',
  1697. 'date' => '2006-12-25',
  1698. 'modified' => '2006-12-25 05:34:21',
  1699. 'mytime' => '22:57:17'
  1700. ))),
  1701. 'Sample' => array(
  1702. 'id' => '',
  1703. 'apple_id' => '',
  1704. 'name' => ''
  1705. ),
  1706. 'Child' => array()
  1707. ));
  1708. $this->assertEqual($result, $expected);
  1709. $result = $TestModel->Parent->unbindModel(array('hasOne' => array('Sample')));
  1710. $this->assertTrue($result);
  1711. $result = $TestModel->unbindModel(array('hasMany' => array('Child')));
  1712. $this->assertTrue($result);
  1713. $result = $TestModel->find('all');
  1714. $expected = array(
  1715. array(
  1716. 'Apple' => array (
  1717. 'id' => 1,
  1718. 'apple_id' => 2,
  1719. 'color' => 'Red 1',
  1720. 'name' => 'Red Apple 1',
  1721. 'created' => '2006-11-22 10:38:58',
  1722. 'date' => '1951-01-04',
  1723. 'modified' => '2006-12-01 13:31:26',
  1724. 'mytime' => '22:57:17'
  1725. ),
  1726. 'Parent' => array(
  1727. 'id' => 2,
  1728. 'apple_id' => 1,
  1729. 'color' => 'Bright Red 1',
  1730. 'name' => 'Bright Red Apple',
  1731. 'created' => '2006-11-22 10:43:13',
  1732. 'date' => '2014-01-01',
  1733. 'modified' => '2006-11-30 18:38:10',
  1734. 'mytime' => '22:57:17',
  1735. 'Parent' => array(
  1736. 'id' => 1,
  1737. 'apple_id' => 2,
  1738. 'color' => 'Red 1',
  1739. 'name' => 'Red Apple 1',
  1740. 'created' => '2006-11-22 10:38:58',
  1741. 'date' => '1951-01-04',
  1742. 'modified' => '2006-12-01 13:31:26',
  1743. 'mytime' => '22:57:17'
  1744. ),
  1745. 'Child' => array(
  1746. array(
  1747. 'id' => 1,
  1748. 'apple_id' => 2,
  1749. 'color' => 'Red 1',
  1750. 'name' => 'Red Apple 1',
  1751. 'created' => '2006-11-22 10:38:58',
  1752. 'date' => '1951-01-04',
  1753. 'modified' => '2006-12-01 13:31:26',
  1754. 'mytime' => '22:57:17'
  1755. ),
  1756. array(
  1757. 'id' => 3,
  1758. 'apple_id' => 2,
  1759. 'color' => 'blue green',
  1760. 'name' => 'green blue',
  1761. 'created' => '2006-12-25 05:13:36',
  1762. 'date' => '2006-12-25',
  1763. 'modified' => '2006-12-25 05:23:24',
  1764. 'mytime' => '22:57:17'
  1765. ),
  1766. array(
  1767. 'id' => 4,
  1768. 'apple_id' => 2,
  1769. 'color' => 'Blue Green',
  1770. 'name' => 'Test Name',
  1771. 'created' => '2006-12-25 05:23:36',
  1772. 'date' => '2006-12-25',
  1773. 'modified' => '2006-12-25 05:23:36',
  1774. 'mytime' => '22:57:17'
  1775. ))),
  1776. 'Sample' => array(
  1777. 'id' =>'',
  1778. 'apple_id' => '',
  1779. 'name' => ''
  1780. )),
  1781. array(
  1782. 'Apple' => array(
  1783. 'id' => 2,
  1784. 'apple_id' => 1,
  1785. 'color' => 'Bright Red 1',
  1786. 'name' => 'Bright Red Apple',
  1787. 'created' => '2006-11-22 10:43:13',
  1788. 'date' => '2014-01-01',
  1789. 'modified' => '2006-11-30 18:38:10',
  1790. 'mytime' => '22:57:17'
  1791. ),
  1792. 'Parent' => array(
  1793. 'id' => 1,
  1794. 'apple_id' => 2,
  1795. 'color' => 'Red 1',
  1796. 'name' => 'Red Apple 1',
  1797. 'created' => '2006-11-22 10:38:58',
  1798. 'date' => '1951-01-04',
  1799. 'modified' => '2006-12-01 13:31:26',
  1800. 'mytime' => '22:57:17',
  1801. 'Parent' => array(
  1802. 'id' => 2,
  1803. 'apple_id' => 1,
  1804. 'color' => 'Bright Red 1',
  1805. 'name' => 'Bright Red Apple',
  1806. 'created' => '2006-11-22 10:43:13',
  1807. 'date' => '2014-01-01',
  1808. 'modified' => '2006-11-30 18:38:10',
  1809. 'mytime' => '22:57:17'
  1810. ),
  1811. 'Child' => array(
  1812. array(
  1813. 'id' => 2,
  1814. 'apple_id' => 1,
  1815. 'color' => 'Bright Red 1',
  1816. 'name' => 'Bright Red Apple',
  1817. 'created' => '2006-11-22 10:43:13',
  1818. 'date' => '2014-01-01',
  1819. 'modified' => '2006-11-30 18:38:10',
  1820. 'mytime' => '22:57:17'
  1821. ))),
  1822. 'Sample' => array(
  1823. 'id' => 2,
  1824. 'apple_id' => 2,
  1825. 'name' => 'sample2',
  1826. 'Apple' => array(
  1827. 'id' => 2,
  1828. 'apple_id' => 1,
  1829. 'color' => 'Bright Red 1',
  1830. 'name' => 'Bright Red Apple',
  1831. 'created' => '2006-11-22 10:43:13',
  1832. 'date' => '2014-01-01',
  1833. 'modified' => '2006-11-30 18:38:10',
  1834. 'mytime' => '22:57:17'
  1835. ))),
  1836. array(
  1837. 'Apple' => array(
  1838. 'id' => 3,
  1839. 'apple_id' => 2,
  1840. 'color' => 'blue green',
  1841. 'name' => 'green blue',
  1842. 'created' => '2006-12-25 05:13:36',
  1843. 'date' => '2006-12-25',
  1844. 'modified' => '2006-12-25 05:23:24',
  1845. 'mytime' => '22:57:17'
  1846. ),
  1847. 'Parent' => array(
  1848. 'id' => 2,
  1849. 'apple_id' => 1,
  1850. 'color' => 'Bright Red 1',
  1851. 'name' => 'Bright Red Apple',
  1852. 'created' => '2006-11-22 10:43:13',
  1853. 'date' => '2014-01-01',
  1854. 'modified' => '2006-11-30 18:38:10',
  1855. 'mytime' => '22:57:17',
  1856. 'Parent' => array(
  1857. 'id' => 1,
  1858. 'apple_id' => 2,
  1859. 'color' => 'Red 1',
  1860. 'name' => 'Red Apple 1',
  1861. 'created' => '2006-11-22 10:38:58',
  1862. 'date' => '1951-01-04',
  1863. 'modified' => '2006-12-01 13:31:26',
  1864. 'mytime' => '22:57:17'
  1865. ),
  1866. 'Child' => array(
  1867. array(
  1868. 'id' => 1,
  1869. 'apple_id' => 2,
  1870. 'color' => 'Red 1',
  1871. 'name' => 'Red Apple 1',
  1872. 'created' => '2006-11-22 10:38:58',
  1873. 'date' => '1951-01-04',
  1874. 'modified' => '2006-12-01 13:31:26',
  1875. 'mytime' => '22:57:17'
  1876. ),
  1877. array(
  1878. 'id' => 3,
  1879. 'apple_id' => 2,
  1880. 'color' => 'blue green',
  1881. 'name' => 'green blue',
  1882. 'created' => '2006-12-25 05:13:36',
  1883. 'date' => '2006-12-25',
  1884. 'modified' => '2006-12-25 05:23:24',
  1885. 'mytime' => '22:57:17'
  1886. ),
  1887. array(
  1888. 'id' => 4,
  1889. 'apple_id' => 2,
  1890. 'color' => 'Blue Green',
  1891. 'name' => 'Test Name',
  1892. 'created' => '2006-12-25 05:23:36',
  1893. 'date' => '2006-12-25',
  1894. 'modified' => '2006-12-25 05:23:36',
  1895. 'mytime' => '22:57:17'
  1896. ))),
  1897. 'Sample' => array(
  1898. 'id' => 1,
  1899. 'apple_id' => 3,
  1900. 'name' => 'sample1',
  1901. 'Apple' => array(
  1902. 'id' => 3,
  1903. 'apple_id' => 2,
  1904. 'color' => 'blue green',
  1905. 'name' => 'green blue',
  1906. 'created' => '2006-12-25 05:13:36',
  1907. 'date' => '2006-12-25',
  1908. 'modified' => '2006-12-25 05:23:24',
  1909. 'mytime' => '22:57:17'
  1910. ))),
  1911. array(
  1912. 'Apple' => array(
  1913. 'id' => 4,
  1914. 'apple_id' => 2,
  1915. 'color' => 'Blue Green',
  1916. 'name' => 'Test Name',
  1917. 'created' => '2006-12-25 05:23:36',
  1918. 'date' => '2006-12-25',
  1919. 'modified' => '2006-12-25 05:23:36',
  1920. 'mytime' => '22:57:17'
  1921. ),
  1922. 'Parent' => array(
  1923. 'id' => 2,
  1924. 'apple_id' => 1,
  1925. 'color' => 'Bright Red 1',
  1926. 'name' => 'Bright Red Apple',
  1927. 'created' => '2006-11-22 10:43:13',
  1928. 'date' => '2014-01-01',
  1929. 'modified' => '2006-11-30 18:38:10',
  1930. 'mytime' => '22:57:17',
  1931. 'Parent' => array(
  1932. 'id' => 1,
  1933. 'apple_id' => 2,
  1934. 'color' => 'Red 1',
  1935. 'name' => 'Red Apple 1',
  1936. 'created' => '2006-11-22 10:38:58',
  1937. 'date' => '1951-01-04',
  1938. 'modified' => '2006-12-01 13:31:26',
  1939. 'mytime' => '22:57:17'
  1940. ),
  1941. 'Child' => array(
  1942. array(
  1943. 'id' => 1,
  1944. 'apple_id' => 2,
  1945. 'color' => 'Red 1',
  1946. 'name' => 'Red Apple 1',
  1947. 'created' => '2006-11-22 10:38:58',
  1948. 'date' => '1951-01-04',
  1949. 'modified' => '2006-12-01 13:31:26',
  1950. 'mytime' => '22:57:17'
  1951. ),
  1952. array(
  1953. 'id' => 3,
  1954. 'apple_id' => 2,
  1955. 'color' => 'blue green',
  1956. 'name' => 'green blue',
  1957. 'created' => '2006-12-25 05:13:36',
  1958. 'date' => '2006-12-25',
  1959. 'modified' => '2006-12-25 05:23:24',
  1960. 'mytime' => '22:57:17'
  1961. ),
  1962. array(
  1963. 'id' => 4,
  1964. 'apple_id' => 2,
  1965. 'color' => 'Blue Green',
  1966. 'name' => 'Test Name',
  1967. 'created' => '2006-12-25 05:23:36',
  1968. 'date' => '2006-12-25',
  1969. 'modified' => '2006-12-25 05:23:36',
  1970. 'mytime' => '22:57:17'
  1971. ))),
  1972. 'Sample' => array(
  1973. 'id' => 3,
  1974. 'apple_id' => 4,
  1975. 'name' => 'sample3',
  1976. 'Apple' => array(
  1977. 'id' => 4,
  1978. 'apple_id' => 2,
  1979. 'color' => 'Blue Green',
  1980. 'name' => 'Test Name',
  1981. 'created' => '2006-12-25 05:23:36',
  1982. 'date' => '2006-12-25',
  1983. 'modified' => '2006-12-25 05:23:36',
  1984. 'mytime' => '22:57:17'
  1985. ))),
  1986. array(
  1987. 'Apple' => array(
  1988. 'id' => 5,
  1989. 'apple_id' => 5,
  1990. 'color' => 'Green',
  1991. 'name' => 'Blue Green',
  1992. 'created' => '2006-12-25 05:24:06',
  1993. 'date' => '2006-12-25',
  1994. 'modified' => '2006-12-25 05:29:16',
  1995. 'mytime' => '22:57:17'
  1996. ),
  1997. 'Parent' => array(
  1998. 'id' => 5,
  1999. 'apple_id' => 5,
  2000. 'color' => 'Green',
  2001. 'name' => 'Blue Green',
  2002. 'created' => '2006-12-25 05:24:06',
  2003. 'date' => '2006-12-25',
  2004. 'modified' => '2006-12-25 05:29:16',
  2005. 'mytime' => '22:57:17',
  2006. 'Parent' => array(
  2007. 'id' => 5,
  2008. 'apple_id' => 5,
  2009. 'color' => 'Green',
  2010. 'name' => 'Blue Green',
  2011. 'created' => '2006-12-25 05:24:06',
  2012. 'date' => '2006-12-25',
  2013. 'modified' => '2006-12-25 05:29:16',
  2014. 'mytime' => '22:57:17'
  2015. ),
  2016. 'Child' => array(
  2017. array(
  2018. 'id' => 5,
  2019. 'apple_id' => 5,
  2020. 'color' => 'Green',
  2021. 'name' => 'Blue Green',
  2022. 'created' => '2006-12-25 05:24:06',
  2023. 'date' => '2006-12-25',
  2024. 'modified' => '2006-12-25 05:29:16',
  2025. 'mytime' => '22:57:17'
  2026. ))),
  2027. 'Sample' => array(
  2028. 'id' => 4,
  2029. 'apple_id' => 5,
  2030. 'name' => 'sample4',
  2031. 'Apple' => array(
  2032. 'id' => 5,
  2033. 'apple_id' => 5,
  2034. 'color' => 'Green',
  2035. 'name' => 'Blue Green',
  2036. 'created' => '2006-12-25 05:24:06',
  2037. 'date' => '2006-12-25',
  2038. 'modified' => '2006-12-25 05:29:16',
  2039. 'mytime' => '22:57:17'
  2040. ))),
  2041. array(
  2042. 'Apple' => array(
  2043. 'id' => 6,
  2044. 'apple_id' => 4,
  2045. 'color' => 'My new appleOrange',
  2046. 'name' => 'My new apple',
  2047. 'created' => '2006-12-25 05:29:39',
  2048. 'date' => '2006-12-25',
  2049. 'modified' => '2006-12-25 05:29:39',
  2050. 'mytime' => '22:57:17'
  2051. ),
  2052. 'Parent' => array(
  2053. 'id' => 4,
  2054. 'apple_id' => 2,
  2055. 'color' => 'Blue Green',
  2056. 'name' => 'Test Name',
  2057. 'created' => '2006-12-25 05:23:36',
  2058. 'date' => '2006-12-25',
  2059. 'modified' => '2006-12-25 05:23:36',
  2060. 'mytime' => '22:57:17',
  2061. 'Parent' => array(
  2062. 'id' => 2,
  2063. 'apple_id' => 1,
  2064. 'color' => 'Bright Red 1',
  2065. 'name' => 'Bright Red Apple',
  2066. 'created' => '2006-11-22 10:43:13',
  2067. 'date' => '2014-01-01',
  2068. 'modified' => '2006-11-30 18:38:10',
  2069. 'mytime' => '22:57:17'
  2070. ),
  2071. 'Child' => array(
  2072. array(
  2073. 'id' => 6,
  2074. 'apple_id' => 4,
  2075. 'color' => 'My new appleOrange',
  2076. 'name' => 'My new apple',
  2077. 'created' => '2006-12-25 05:29:39',
  2078. 'date' => '2006-12-25',
  2079. 'modified' => '2006-12-25 05:29:39',
  2080. 'mytime' => '22:57:17'
  2081. ))),
  2082. 'Sample' => array(
  2083. 'id' => '',
  2084. 'apple_id' => '',
  2085. 'name' => ''
  2086. )),
  2087. array(
  2088. 'Apple' => array(
  2089. 'id' => 7,
  2090. 'apple_id' => 6,
  2091. 'color' => 'Some wierd color',
  2092. 'name' => 'Some odd color',
  2093. 'created' => '2006-12-25 05:34:21',
  2094. 'date' => '2006-12-25',
  2095. 'modified' => '2006-12-25 05:34:21',
  2096. 'mytime' => '22:57:17'
  2097. ),
  2098. 'Parent' => array(
  2099. 'id' => 6,
  2100. 'apple_id' => 4,
  2101. 'color' => 'My new appleOrange',
  2102. 'name' => 'My new apple',
  2103. 'created' => '2006-12-25 05:29:39',
  2104. 'date' => '2006-12-25',
  2105. 'modified' => '2006-12-25 05:29:39',
  2106. 'mytime' => '22:57:17',
  2107. 'Parent' => array(
  2108. 'id' => 4,
  2109. 'apple_id' => 2,
  2110. 'color' => 'Blue Green',
  2111. 'name' => 'Test Name',
  2112. 'created' => '2006-12-25 05:23:36',
  2113. 'date' => '2006-12-25',
  2114. 'modified' => '2006-12-25 05:23:36',
  2115. 'mytime' => '22:57:17'
  2116. ),
  2117. 'Child' => array(
  2118. array(
  2119. 'id' => 7,
  2120. 'apple_id' => 6,
  2121. 'color' => 'Some wierd color',
  2122. 'name' => 'Some odd color',
  2123. 'created' => '2006-12-25 05:34:21',
  2124. 'date' => '2006-12-25',
  2125. 'modified' => '2006-12-25 05:34:21',
  2126. 'mytime' => '22:57:17'
  2127. ))),
  2128. 'Sample' => array(
  2129. 'id' => '',
  2130. 'apple_id' => '',
  2131. 'name' => ''
  2132. )));
  2133. $this->assertEqual($result, $expected);
  2134. $result = $TestModel->unbindModel(array('hasMany' => array('Child')));
  2135. $this->assertTrue($result);
  2136. $result = $TestModel->Sample->unbindModel(array('belongsTo' => array('Apple')));
  2137. $this->assertTrue($result);
  2138. $result = $TestModel->find('all');
  2139. $expected = array(
  2140. array(
  2141. 'Apple' => array(
  2142. 'id' => 1,
  2143. 'apple_id' => 2,
  2144. 'color' => 'Red 1',
  2145. 'name' => 'Red Apple 1',
  2146. 'created' => '2006-11-22 10:38:58',
  2147. 'date' => '1951-01-04',
  2148. 'modified' => '2006-12-01 13:31:26',
  2149. 'mytime' => '22:57:17'
  2150. ),
  2151. 'Parent' => array(
  2152. 'id' => 2,
  2153. 'apple_id' => 1,
  2154. 'color' => 'Bright Red 1',
  2155. 'name' => 'Bright Red Apple',
  2156. 'created' => '2006-11-22 10:43:13',
  2157. 'date' => '2014-01-01',
  2158. 'modified' => '2006-11-30 18:38:10',
  2159. 'mytime' => '22:57:17',
  2160. 'Parent' => array(
  2161. 'id' => 1,
  2162. 'apple_id' => 2,
  2163. 'color' => 'Red 1',
  2164. 'name' => 'Red Apple 1',
  2165. 'created' => '2006-11-22 10:38:58',
  2166. 'date' => '1951-01-04',
  2167. 'modified' => '2006-12-01 13:31:26',
  2168. 'mytime' => '22:57:17'
  2169. ),
  2170. 'Sample' => array(
  2171. 'id' => 2,
  2172. 'apple_id' => 2,
  2173. 'name' => 'sample2'
  2174. ),
  2175. 'Child' => array(
  2176. array(
  2177. 'id' => 1,
  2178. 'apple_id' => 2,
  2179. 'color' => 'Red 1',
  2180. 'name' => 'Red Apple 1',
  2181. 'created' => '2006-11-22 10:38:58',
  2182. 'date' => '1951-01-04',
  2183. 'modified' => '2006-12-01 13:31:26',
  2184. 'mytime' => '22:57:17'
  2185. ),
  2186. array(
  2187. 'id' => 3,
  2188. 'apple_id' => 2,
  2189. 'color' => 'blue green',
  2190. 'name' => 'green blue',
  2191. 'created' => '2006-12-25 05:13:36',
  2192. 'date' => '2006-12-25',
  2193. 'modified' => '2006-12-25 05:23:24',
  2194. 'mytime' => '22:57:17'
  2195. ),
  2196. array(
  2197. 'id' => 4,
  2198. 'apple_id' => 2,
  2199. 'color' => 'Blue Green',
  2200. 'name' => 'Test Name',
  2201. 'created' => '2006-12-25 05:23:36',
  2202. 'date' => '2006-12-25',
  2203. 'modified' => '2006-12-25 05:23:36',
  2204. 'mytime' => '22:57:17'
  2205. ))),
  2206. 'Sample' => array(
  2207. 'id' =>'',
  2208. 'apple_id' => '',
  2209. 'name' => ''
  2210. )),
  2211. array(
  2212. 'Apple' => array(
  2213. 'id' => 2,
  2214. 'apple_id' => 1,
  2215. 'color' => 'Bright Red 1',
  2216. 'name' => 'Bright Red Apple',
  2217. 'created' => '2006-11-22 10:43:13',
  2218. 'date' => '2014-01-01',
  2219. 'modified' => '2006-11-30 18:38:10',
  2220. 'mytime' => '22:57:17'
  2221. ),
  2222. 'Parent' => array(
  2223. 'id' => 1,
  2224. 'apple_id' => 2,
  2225. 'color' => 'Red 1',
  2226. 'name' => 'Red Apple 1',
  2227. 'created' => '2006-11-22 10:38:58',
  2228. 'date' => '1951-01-04',
  2229. 'modified' => '2006-12-01 13:31:26',
  2230. 'mytime' => '22:57:17',
  2231. 'Parent' => array(
  2232. 'id' => 2,
  2233. 'apple_id' => 1,
  2234. 'color' => 'Bright Red 1',
  2235. 'name' => 'Bright Red Apple',
  2236. 'created' => '2006-11-22 10:43:13',
  2237. 'date' => '2014-01-01',
  2238. 'modified' => '2006-11-30 18:38:10',
  2239. 'mytime' => '22:57:17'
  2240. ),
  2241. 'Sample' => array(),
  2242. 'Child' => array(
  2243. array(
  2244. 'id' => 2,
  2245. 'apple_id' => 1,
  2246. 'color' => 'Bright Red 1',
  2247. 'name' => 'Bright Red Apple',
  2248. 'created' => '2006-11-22 10:43:13',
  2249. 'date' => '2014-01-01',
  2250. 'modified' => '2006-11-30 18:38:10',
  2251. 'mytime' => '22:57:17'
  2252. ))),
  2253. 'Sample' => array(
  2254. 'id' => 2,
  2255. 'apple_id' => 2,
  2256. 'name' => 'sample2'
  2257. )),
  2258. array(
  2259. 'Apple' => array(
  2260. 'id' => 3,
  2261. 'apple_id' => 2,
  2262. 'color' => 'blue green',
  2263. 'name' => 'green blue',
  2264. 'created' => '2006-12-25 05:13:36',
  2265. 'date' => '2006-12-25',
  2266. 'modified' => '2006-12-25 05:23:24',
  2267. 'mytime' => '22:57:17'
  2268. ),
  2269. 'Parent' => array(
  2270. 'id' => 2,
  2271. 'apple_id' => 1,
  2272. 'color' => 'Bright Red 1',
  2273. 'name' => 'Bright Red Apple',
  2274. 'created' => '2006-11-22 10:43:13',
  2275. 'date' => '2014-01-01',
  2276. 'modified' => '2006-11-30 18:38:10',
  2277. 'mytime' => '22:57:17',
  2278. 'Parent' => array(
  2279. 'id' => 1,
  2280. 'apple_id' => 2,
  2281. 'color' => 'Red 1',
  2282. 'name' => 'Red Apple 1',
  2283. 'created' => '2006-11-22 10:38:58',
  2284. 'date' => '1951-01-04',
  2285. 'modified' => '2006-12-01 13:31:26',
  2286. 'mytime' => '22:57:17'
  2287. ),
  2288. 'Sample' => array(
  2289. 'id' => 2,
  2290. 'apple_id' => 2,
  2291. 'name' => 'sample2'
  2292. ),
  2293. 'Child' => array(
  2294. array(
  2295. 'id' => 1,
  2296. 'apple_id' => 2,
  2297. 'color' => 'Red 1',
  2298. 'name' => 'Red Apple 1',
  2299. 'created' => '2006-11-22 10:38:58',
  2300. 'date' => '1951-01-04',
  2301. 'modified' => '2006-12-01 13:31:26',
  2302. 'mytime' => '22:57:17'
  2303. ),
  2304. array(
  2305. 'id' => 3,
  2306. 'apple_id' => 2,
  2307. 'color' => 'blue green',
  2308. 'name' => 'green blue',
  2309. 'created' => '2006-12-25 05:13:36',
  2310. 'date' => '2006-12-25',
  2311. 'modified' => '2006-12-25 05:23:24',
  2312. 'mytime' => '22:57:17'
  2313. ),
  2314. array(
  2315. 'id' => 4,
  2316. 'apple_id' => 2,
  2317. 'color' => 'Blue Green',
  2318. 'name' => 'Test Name',
  2319. 'created' => '2006-12-25 05:23:36',
  2320. 'date' => '2006-12-25',
  2321. 'modified' => '2006-12-25 05:23:36',
  2322. 'mytime' => '22:57:17'
  2323. ))),
  2324. 'Sample' => array(
  2325. 'id' => 1,
  2326. 'apple_id' => 3,
  2327. 'name' => 'sample1'
  2328. )),
  2329. array(
  2330. 'Apple' => array(
  2331. 'id' => 4,
  2332. 'apple_id' => 2,
  2333. 'color' => 'Blue Green',
  2334. 'name' => 'Test Name',
  2335. 'created' => '2006-12-25 05:23:36',
  2336. 'date' => '2006-12-25',
  2337. 'modified' => '2006-12-25 05:23:36',
  2338. 'mytime' => '22:57:17'
  2339. ),
  2340. 'Parent' => array(
  2341. 'id' => 2,
  2342. 'apple_id' => 1,
  2343. 'color' => 'Bright Red 1',
  2344. 'name' => 'Bright Red Apple',
  2345. 'created' => '2006-11-22 10:43:13',
  2346. 'date' => '2014-01-01',
  2347. 'modified' => '2006-11-30 18:38:10',
  2348. 'mytime' => '22:57:17',
  2349. 'Parent' => array(
  2350. 'id' => 1,
  2351. 'apple_id' => 2,
  2352. 'color' => 'Red 1',
  2353. 'name' => 'Red Apple 1',
  2354. 'created' => '2006-11-22 10:38:58',
  2355. 'date' => '1951-01-04',
  2356. 'modified' => '2006-12-01 13:31:26',
  2357. 'mytime' => '22:57:17'
  2358. ),
  2359. 'Sample' => array(
  2360. 'id' => 2,
  2361. 'apple_id' => 2,
  2362. 'name' => 'sample2'
  2363. ),
  2364. 'Child' => array(
  2365. array(
  2366. 'id' => 1,
  2367. 'apple_id' => 2,
  2368. 'color' => 'Red 1',
  2369. 'name' => 'Red Apple 1',
  2370. 'created' => '2006-11-22 10:38:58',
  2371. 'date' => '1951-01-04',
  2372. 'modified' => '2006-12-01 13:31:26',
  2373. 'mytime' => '22:57:17'
  2374. ),
  2375. array(
  2376. 'id' => 3,
  2377. 'apple_id' => 2,
  2378. 'color' => 'blue green',
  2379. 'name' => 'green blue',
  2380. 'created' => '2006-12-25 05:13:36',
  2381. 'date' => '2006-12-25',
  2382. 'modified' => '2006-12-25 05:23:24',
  2383. 'mytime' => '22:57:17'
  2384. ),
  2385. array(
  2386. 'id' => 4,
  2387. 'apple_id' => 2,
  2388. 'color' => 'Blue Green',
  2389. 'name' => 'Test Name',
  2390. 'created' => '2006-12-25 05:23:36',
  2391. 'date' => '2006-12-25',
  2392. 'modified' => '2006-12-25 05:23:36',
  2393. 'mytime' => '22:57:17'
  2394. ))),
  2395. 'Sample' => array(
  2396. 'id' => 3,
  2397. 'apple_id' => 4,
  2398. 'name' => 'sample3'
  2399. )),
  2400. array(
  2401. 'Apple' => array(
  2402. 'id' => 5,
  2403. 'apple_id' => 5,
  2404. 'color' => 'Green',
  2405. 'name' => 'Blue Green',
  2406. 'created' => '2006-12-25 05:24:06',
  2407. 'date' => '2006-12-25',
  2408. 'modified' => '2006-12-25 05:29:16',
  2409. 'mytime' => '22:57:17'
  2410. ),
  2411. 'Parent' => array(
  2412. 'id' => 5,
  2413. 'apple_id' => 5,
  2414. 'color' => 'Green',
  2415. 'name' => 'Blue Green',
  2416. 'created' => '2006-12-25 05:24:06',
  2417. 'date' => '2006-12-25',
  2418. 'modified' => '2006-12-25 05:29:16',
  2419. 'mytime' => '22:57:17',
  2420. 'Parent' => array(
  2421. 'id' => 5,
  2422. 'apple_id' => 5,
  2423. 'color' => 'Green',
  2424. 'name' => 'Blue Green',
  2425. 'created' => '2006-12-25 05:24:06',
  2426. 'date' => '2006-12-25',
  2427. 'modified' => '2006-12-25 05:29:16',
  2428. 'mytime' => '22:57:17'
  2429. ),
  2430. 'Sample' => array(
  2431. 'id' => 4,
  2432. 'apple_id' => 5,
  2433. 'name' => 'sample4'
  2434. ),
  2435. 'Child' => array(
  2436. array(
  2437. 'id' => 5,
  2438. 'apple_id' => 5,
  2439. 'color' => 'Green',
  2440. 'name' => 'Blue Green',
  2441. 'created' => '2006-12-25 05:24:06',
  2442. 'date' => '2006-12-25',
  2443. 'modified' => '2006-12-25 05:29:16',
  2444. 'mytime' => '22:57:17'
  2445. ))),
  2446. 'Sample' => array(
  2447. 'id' => 4,
  2448. 'apple_id' => 5,
  2449. 'name' => 'sample4'
  2450. )),
  2451. array(
  2452. 'Apple' => array(
  2453. 'id' => 6,
  2454. 'apple_id' => 4,
  2455. 'color' => 'My new appleOrange',
  2456. 'name' => 'My new apple',
  2457. 'created' => '2006-12-25 05:29:39',
  2458. 'date' => '2006-12-25',
  2459. 'modified' => '2006-12-25 05:29:39',
  2460. 'mytime' => '22:57:17'
  2461. ),
  2462. 'Parent' => array(
  2463. 'id' => 4,
  2464. 'apple_id' => 2,
  2465. 'color' => 'Blue Green',
  2466. 'name' => 'Test Name',
  2467. 'created' => '2006-12-25 05:23:36',
  2468. 'date' => '2006-12-25',
  2469. 'modified' => '2006-12-25 05:23:36',
  2470. 'mytime' => '22:57:17',
  2471. 'Parent' => array(
  2472. 'id' => 2,
  2473. 'apple_id' => 1,
  2474. 'color' => 'Bright Red 1',
  2475. 'name' => 'Bright Red Apple',
  2476. 'created' => '2006-11-22 10:43:13',
  2477. 'date' => '2014-01-01',
  2478. 'modified' => '2006-11-30 18:38:10',
  2479. 'mytime' => '22:57:17'
  2480. ),
  2481. 'Sample' => array(
  2482. 'id' => 3,
  2483. 'apple_id' => 4,
  2484. 'name' => 'sample3'
  2485. ),
  2486. 'Child' => array(
  2487. array(
  2488. 'id' => 6,
  2489. 'apple_id' => 4,
  2490. 'color' => 'My new appleOrange',
  2491. 'name' => 'My new apple',
  2492. 'created' => '2006-12-25 05:29:39',
  2493. 'date' => '2006-12-25',
  2494. 'modified' => '2006-12-25 05:29:39',
  2495. 'mytime' => '22:57:17'
  2496. ))),
  2497. 'Sample' => array(
  2498. 'id' => '',
  2499. 'apple_id' => '',
  2500. 'name' => ''
  2501. )),
  2502. array(
  2503. 'Apple' => array(
  2504. 'id' => 7,
  2505. 'apple_id' => 6,
  2506. 'color' => 'Some wierd color',
  2507. 'name' => 'Some odd color',
  2508. 'created' => '2006-12-25 05:34:21',
  2509. 'date' => '2006-12-25',
  2510. 'modified' => '2006-12-25 05:34:21',
  2511. 'mytime' => '22:57:17'
  2512. ),
  2513. 'Parent' => array(
  2514. 'id' => 6,
  2515. 'apple_id' => 4,
  2516. 'color' => 'My new appleOrange',
  2517. 'name' => 'My new apple',
  2518. 'created' => '2006-12-25 05:29:39',
  2519. 'date' => '2006-12-25',
  2520. 'modified' => '2006-12-25 05:29:39',
  2521. 'mytime' => '22:57:17',
  2522. 'Parent' => array(
  2523. 'id' => 4,
  2524. 'apple_id' => 2,
  2525. 'color' => 'Blue Green',
  2526. 'name' => 'Test Name',
  2527. 'created' => '2006-12-25 05:23:36',
  2528. 'date' => '2006-12-25',
  2529. 'modified' => '2006-12-25 05:23:36',
  2530. 'mytime' => '22:57:17'
  2531. ),
  2532. 'Sample' => array(),
  2533. 'Child' => array(
  2534. array(
  2535. 'id' => 7,
  2536. 'apple_id' => 6,
  2537. 'color' => 'Some wierd color',
  2538. 'name' => 'Some odd color',
  2539. 'created' => '2006-12-25 05:34:21',
  2540. 'date' => '2006-12-25',
  2541. 'modified' => '2006-12-25 05:34:21',
  2542. 'mytime' => '22:57:17'
  2543. ))),
  2544. 'Sample' => array(
  2545. 'id' => '',
  2546. 'apple_id' => '',
  2547. 'name' => ''
  2548. )));
  2549. $this->assertEqual($result, $expected);
  2550. $result = $TestModel->Parent->unbindModel(array('belongsTo' => array('Parent')));
  2551. $this->assertTrue($result);
  2552. $result = $TestModel->unbindModel(array('hasMany' => array('Child')));
  2553. $this->assertTrue($result);
  2554. $result = $TestModel->find('all');
  2555. $expected = array(
  2556. array(
  2557. 'Apple' => array(
  2558. 'id' => 1,
  2559. 'apple_id' => 2,
  2560. 'color' => 'Red 1',
  2561. 'name' => 'Red Apple 1',
  2562. 'created' => '2006-11-22 10:38:58',
  2563. 'date' => '1951-01-04',
  2564. 'modified' => '2006-12-01 13:31:26',
  2565. 'mytime' => '22:57:17'
  2566. ),
  2567. 'Parent' => array(
  2568. 'id' => 2,
  2569. 'apple_id' => 1,
  2570. 'color' => 'Bright Red 1',
  2571. 'name' => 'Bright Red Apple',
  2572. 'created' => '2006-11-22 10:43:13',
  2573. 'date' => '2014-01-01',
  2574. 'modified' => '2006-11-30 18:38:10',
  2575. 'mytime' => '22:57:17',
  2576. 'Sample' => array(
  2577. 'id' => 2,
  2578. 'apple_id' => 2,
  2579. 'name' => 'sample2'
  2580. ),
  2581. 'Child' => array(
  2582. array(
  2583. 'id' => 1,
  2584. 'apple_id' => 2,
  2585. 'color' => 'Red 1',
  2586. 'name' => 'Red Apple 1',
  2587. 'created' => '2006-11-22 10:38:58',
  2588. 'date' => '1951-01-04',
  2589. 'modified' => '2006-12-01 13:31:26',
  2590. 'mytime' => '22:57:17'
  2591. ),
  2592. array(
  2593. 'id' => 3,
  2594. 'apple_id' => 2,
  2595. 'color' => 'blue green',
  2596. 'name' => 'green blue',
  2597. 'created' => '2006-12-25 05:13:36',
  2598. 'date' => '2006-12-25',
  2599. 'modified' => '2006-12-25 05:23:24',
  2600. 'mytime' => '22:57:17'
  2601. ),
  2602. array(
  2603. 'id' => 4,
  2604. 'apple_id' => 2,
  2605. 'color' => 'Blue Green',
  2606. 'name' => 'Test Name',
  2607. 'created' => '2006-12-25 05:23:36',
  2608. 'date' => '2006-12-25',
  2609. 'modified' => '2006-12-25 05:23:36',
  2610. 'mytime' => '22:57:17'
  2611. ))),
  2612. 'Sample' => array(
  2613. 'id' =>'',
  2614. 'apple_id' => '',
  2615. 'name' => ''
  2616. )),
  2617. array(
  2618. 'Apple' => array(
  2619. 'id' => 2,
  2620. 'apple_id' => 1,
  2621. 'color' => 'Bright Red 1',
  2622. 'name' => 'Bright Red Apple',
  2623. 'created' => '2006-11-22 10:43:13',
  2624. 'date' => '2014-01-01',
  2625. 'modified' => '2006-11-30 18:38:10',
  2626. 'mytime' => '22:57:17'
  2627. ),
  2628. 'Parent' => array(
  2629. 'id' => 1,
  2630. 'apple_id' => 2,
  2631. 'color' => 'Red 1',
  2632. 'name' => 'Red Apple 1',
  2633. 'created' => '2006-11-22 10:38:58',
  2634. 'date' => '1951-01-04',
  2635. 'modified' => '2006-12-01 13:31:26',
  2636. 'mytime' => '22:57:17',
  2637. 'Sample' => array(),
  2638. 'Child' => array(
  2639. array(
  2640. 'id' => 2,
  2641. 'apple_id' => 1,
  2642. 'color' => 'Bright Red 1',
  2643. 'name' => 'Bright Red Apple',
  2644. 'created' => '2006-11-22 10:43:13',
  2645. 'date' => '2014-01-01',
  2646. 'modified' => '2006-11-30 18:38:10',
  2647. 'mytime' => '22:57:17'
  2648. ))),
  2649. 'Sample' => array(
  2650. 'id' => 2,
  2651. 'apple_id' => 2,
  2652. 'name' => 'sample2',
  2653. 'Apple' => array(
  2654. 'id' => 2,
  2655. 'apple_id' => 1,
  2656. 'color' => 'Bright Red 1',
  2657. 'name' => 'Bright Red Apple',
  2658. 'created' => '2006-11-22 10:43:13',
  2659. 'date' => '2014-01-01',
  2660. 'modified' => '2006-11-30 18:38:10',
  2661. 'mytime' => '22:57:17'
  2662. ))),
  2663. array(
  2664. 'Apple' => array(
  2665. 'id' => 3,
  2666. 'apple_id' => 2,
  2667. 'color' => 'blue green',
  2668. 'name' => 'green blue',
  2669. 'created' => '2006-12-25 05:13:36',
  2670. 'date' => '2006-12-25',
  2671. 'modified' => '2006-12-25 05:23:24',
  2672. 'mytime' => '22:57:17'
  2673. ),
  2674. 'Parent' => array(
  2675. 'id' => 2,
  2676. 'apple_id' => 1,
  2677. 'color' => 'Bright Red 1',
  2678. 'name' => 'Bright Red Apple',
  2679. 'created' => '2006-11-22 10:43:13',
  2680. 'date' => '2014-01-01',
  2681. 'modified' => '2006-11-30 18:38:10',
  2682. 'mytime' => '22:57:17',
  2683. 'Sample' => array(
  2684. 'id' => 2,
  2685. 'apple_id' => 2,
  2686. 'name' => 'sample2'
  2687. ),
  2688. 'Child' => array(
  2689. array(
  2690. 'id' => 1,
  2691. 'apple_id' => 2,
  2692. 'color' => 'Red 1',
  2693. 'name' => 'Red Apple 1',
  2694. 'created' => '2006-11-22 10:38:58',
  2695. 'date' => '1951-01-04',
  2696. 'modified' => '2006-12-01 13:31:26',
  2697. 'mytime' => '22:57:17'
  2698. ),
  2699. array(
  2700. 'id' => 3,
  2701. 'apple_id' => 2,
  2702. 'color' => 'blue green',
  2703. 'name' => 'green blue',
  2704. 'created' => '2006-12-25 05:13:36',
  2705. 'date' => '2006-12-25',
  2706. 'modified' => '2006-12-25 05:23:24',
  2707. 'mytime' => '22:57:17'
  2708. ),
  2709. array(
  2710. 'id' => 4,
  2711. 'apple_id' => 2,
  2712. 'color' => 'Blue Green',
  2713. 'name' => 'Test Name',
  2714. 'created' => '2006-12-25 05:23:36',
  2715. 'date' => '2006-12-25',
  2716. 'modified' => '2006-12-25 05:23:36',
  2717. 'mytime' => '22:57:17'
  2718. ))),
  2719. 'Sample' => array(
  2720. 'id' => 1,
  2721. 'apple_id' => 3,
  2722. 'name' => 'sample1',
  2723. 'Apple' => array(
  2724. 'id' => 3,
  2725. 'apple_id' => 2,
  2726. 'color' => 'blue green',
  2727. 'name' => 'green blue',
  2728. 'created' => '2006-12-25 05:13:36',
  2729. 'date' => '2006-12-25',
  2730. 'modified' => '2006-12-25 05:23:24',
  2731. 'mytime' => '22:57:17'
  2732. ))),
  2733. array(
  2734. 'Apple' => array(
  2735. 'id' => 4,
  2736. 'apple_id' => 2,
  2737. 'color' => 'Blue Green',
  2738. 'name' => 'Test Name',
  2739. 'created' => '2006-12-25 05:23:36',
  2740. 'date' => '2006-12-25',
  2741. 'modified' => '2006-12-25 05:23:36',
  2742. 'mytime' => '22:57:17'
  2743. ),
  2744. 'Parent' => array(
  2745. 'id' => 2,
  2746. 'apple_id' => 1,
  2747. 'color' => 'Bright Red 1',
  2748. 'name' => 'Bright Red Apple',
  2749. 'created' => '2006-11-22 10:43:13',
  2750. 'date' => '2014-01-01',
  2751. 'modified' => '2006-11-30 18:38:10',
  2752. 'mytime' => '22:57:17',
  2753. 'Sample' => array(
  2754. 'id' => 2,
  2755. 'apple_id' => 2,
  2756. 'name' => 'sample2'
  2757. ),
  2758. 'Child' => array(
  2759. array(
  2760. 'id' => 1,
  2761. 'apple_id' => 2,
  2762. 'color' => 'Red 1',
  2763. 'name' => 'Red Apple 1',
  2764. 'created' => '2006-11-22 10:38:58',
  2765. 'date' => '1951-01-04',
  2766. 'modified' => '2006-12-01 13:31:26',
  2767. 'mytime' => '22:57:17'
  2768. ),
  2769. array(
  2770. 'id' => 3,
  2771. 'apple_id' => 2,
  2772. 'color' => 'blue green',
  2773. 'name' => 'green blue',
  2774. 'created' => '2006-12-25 05:13:36',
  2775. 'date' => '2006-12-25',
  2776. 'modified' => '2006-12-25 05:23:24',
  2777. 'mytime' => '22:57:17'
  2778. ),
  2779. array(
  2780. 'id' => 4,
  2781. 'apple_id' => 2,
  2782. 'color' => 'Blue Green',
  2783. 'name' => 'Test Name',
  2784. 'created' => '2006-12-25 05:23:36',
  2785. 'date' => '2006-12-25',
  2786. 'modified' => '2006-12-25 05:23:36',
  2787. 'mytime' => '22:57:17'
  2788. ))),
  2789. 'Sample' => array(
  2790. 'id' => 3,
  2791. 'apple_id' => 4,
  2792. 'name' => 'sample3',
  2793. 'Apple' => array(
  2794. 'id' => 4,
  2795. 'apple_id' => 2,
  2796. 'color' => 'Blue Green',
  2797. 'name' => 'Test Name',
  2798. 'created' => '2006-12-25 05:23:36',
  2799. 'date' => '2006-12-25',
  2800. 'modified' => '2006-12-25 05:23:36',
  2801. 'mytime' => '22:57:17'
  2802. ))),
  2803. array(
  2804. 'Apple' => array(
  2805. 'id' => 5,
  2806. 'apple_id' => 5,
  2807. 'color' => 'Green',
  2808. 'name' => 'Blue Green',
  2809. 'created' => '2006-12-25 05:24:06',
  2810. 'date' => '2006-12-25',
  2811. 'modified' =>
  2812. '2006-12-25 05:29:16',
  2813. 'mytime' => '22:57:17'
  2814. ),
  2815. 'Parent' => array(
  2816. 'id' => 5,
  2817. 'apple_id' => 5,
  2818. 'color' => 'Green',
  2819. 'name' => 'Blue Green',
  2820. 'created' => '2006-12-25 05:24:06',
  2821. 'date' => '2006-12-25',
  2822. 'modified' => '2006-12-25 05:29:16',
  2823. 'mytime' => '22:57:17',
  2824. 'Sample' => array(
  2825. 'id' => 4,
  2826. 'apple_id' => 5,
  2827. 'name' => 'sample4'
  2828. ),
  2829. 'Child' => array(
  2830. array(
  2831. 'id' => 5,
  2832. 'apple_id' => 5,
  2833. 'color' => 'Green',
  2834. 'name' => 'Blue Green',
  2835. 'created' => '2006-12-25 05:24:06',
  2836. 'date' => '2006-12-25',
  2837. 'modified' => '2006-12-25 05:29:16',
  2838. 'mytime' => '22:57:17'
  2839. ))),
  2840. 'Sample' => array(
  2841. 'id' => 4,
  2842. 'apple_id' => 5,
  2843. 'name' => 'sample4',
  2844. 'Apple' => array(
  2845. 'id' => 5,
  2846. 'apple_id' => 5,
  2847. 'color' => 'Green',
  2848. 'name' => 'Blue Green',
  2849. 'created' => '2006-12-25 05:24:06',
  2850. 'date' => '2006-12-25',
  2851. 'modified' => '2006-12-25 05:29:16',
  2852. 'mytime' => '22:57:17'
  2853. ))),
  2854. array(
  2855. 'Apple' => array(
  2856. 'id' => 6,
  2857. 'apple_id' => 4,
  2858. 'color' => 'My new appleOrange',
  2859. 'name' => 'My new apple',
  2860. 'created' => '2006-12-25 05:29:39',
  2861. 'date' => '2006-12-25',
  2862. 'modified' => '2006-12-25 05:29:39',
  2863. 'mytime' => '22:57:17'),
  2864. 'Parent' => array(
  2865. 'id' => 4,
  2866. 'apple_id' => 2,
  2867. 'color' => 'Blue Green',
  2868. 'name' => 'Test Name',
  2869. 'created' => '2006-12-25 05:23:36',
  2870. 'date' => '2006-12-25',
  2871. 'modified' => '2006-12-25 05:23:36',
  2872. 'mytime' => '22:57:17',
  2873. 'Sample' => array(
  2874. 'id' => 3,
  2875. 'apple_id' => 4,
  2876. 'name' => 'sample3'
  2877. ),
  2878. 'Child' => array(
  2879. array(
  2880. 'id' => 6,
  2881. 'apple_id' => 4,
  2882. 'color' => 'My new appleOrange',
  2883. 'name' => 'My new apple',
  2884. 'created' => '2006-12-25 05:29:39',
  2885. 'date' => '2006-12-25',
  2886. 'modified' => '2006-12-25 05:29:39',
  2887. 'mytime' => '22:57:17'
  2888. ))),
  2889. 'Sample' => array(
  2890. 'id' => '',
  2891. 'apple_id' => '',
  2892. 'name' => ''
  2893. )),
  2894. array(
  2895. 'Apple' => array(
  2896. 'id' => 7,
  2897. 'apple_id' => 6,
  2898. 'color' => 'Some wierd color',
  2899. 'name' => 'Some odd color',
  2900. 'created' => '2006-12-25 05:34:21',
  2901. 'date' => '2006-12-25',
  2902. 'modified' => '2006-12-25 05:34:21',
  2903. 'mytime' => '22:57:17'
  2904. ),
  2905. 'Parent' => array(
  2906. 'id' => 6,
  2907. 'apple_id' => 4,
  2908. 'color' => 'My new appleOrange',
  2909. 'name' => 'My new apple',
  2910. 'created' => '2006-12-25 05:29:39',
  2911. 'date' => '2006-12-25',
  2912. 'modified' => '2006-12-25 05:29:39',
  2913. 'mytime' => '22:57:17',
  2914. 'Sample' => array(),
  2915. 'Child' => array(
  2916. array(
  2917. 'id' => 7,
  2918. 'apple_id' => 6,
  2919. 'color' => 'Some wierd color',
  2920. 'name' => 'Some odd color',
  2921. 'created' => '2006-12-25 05:34:21',
  2922. 'date' => '2006-12-25', 'modified' =>
  2923. '2006-12-25 05:34:21',
  2924. 'mytime' => '22:57:17'
  2925. ))),
  2926. 'Sample' => array(
  2927. 'id' => '',
  2928. 'apple_id' => '',
  2929. 'name' => ''
  2930. )));
  2931. $this->assertEqual($result, $expected);
  2932. }
  2933. /**
  2934. * testSelfAssociationAfterFind method
  2935. *
  2936. * @access public
  2937. * @return void
  2938. */
  2939. function testSelfAssociationAfterFind() {
  2940. $this->loadFixtures('Apple');
  2941. $afterFindModel = new NodeAfterFind();
  2942. $afterFindModel->recursive = 3;
  2943. $afterFindData = $afterFindModel->find('all');
  2944. $duplicateModel = new NodeAfterFind();
  2945. $duplicateModel->recursive = 3;
  2946. $duplicateModelData = $duplicateModel->find('all');
  2947. $noAfterFindModel = new NodeNoAfterFind();
  2948. $noAfterFindModel->recursive = 3;
  2949. $noAfterFindData = $noAfterFindModel->find('all');
  2950. $this->assertFalse($afterFindModel == $noAfterFindModel);
  2951. // Limitation of PHP 4 and PHP 5 > 5.1.6 when comparing recursive objects
  2952. if (PHP_VERSION === '5.1.6') {
  2953. $this->assertFalse($afterFindModel != $duplicateModel);
  2954. }
  2955. $this->assertEqual($afterFindData, $noAfterFindData);
  2956. }
  2957. /**
  2958. * testFindAllThreaded method
  2959. *
  2960. * @access public
  2961. * @return void
  2962. */
  2963. function testFindAllThreaded() {
  2964. $this->loadFixtures('Category');
  2965. $TestModel =& new Category();
  2966. $result = $TestModel->find('threaded');
  2967. $expected = array(
  2968. array(
  2969. 'Category' => array(
  2970. 'id' => '1',
  2971. 'parent_id' => '0',
  2972. 'name' => 'Category 1',
  2973. 'created' => '2007-03-18 15:30:23',
  2974. 'updated' => '2007-03-18 15:32:31'
  2975. ),
  2976. 'children' => array(
  2977. array(
  2978. 'Category' => array(
  2979. 'id' => '2',
  2980. 'parent_id' => '1',
  2981. 'name' => 'Category 1.1',
  2982. 'created' => '2007-03-18 15:30:23',
  2983. 'updated' => '2007-03-18 15:32:31'
  2984. ),
  2985. 'children' => array(
  2986. array('Category' => array(
  2987. 'id' => '7',
  2988. 'parent_id' => '2',
  2989. 'name' => 'Category 1.1.1',
  2990. 'created' => '2007-03-18 15:30:23',
  2991. 'updated' => '2007-03-18 15:32:31'),
  2992. 'children' => array()),
  2993. array('Category' => array(
  2994. 'id' => '8',
  2995. 'parent_id' => '2',
  2996. 'name' => 'Category 1.1.2',
  2997. 'created' => '2007-03-18 15:30:23',
  2998. 'updated' => '2007-03-18 15:32:31'),
  2999. 'children' => array()))
  3000. ),
  3001. array(
  3002. 'Category' => array(
  3003. 'id' => '3',
  3004. 'parent_id' => '1',
  3005. 'name' => 'Category 1.2',
  3006. 'created' => '2007-03-18 15:30:23',
  3007. 'updated' => '2007-03-18 15:32:31'
  3008. ),
  3009. 'children' => array()
  3010. )
  3011. )
  3012. ),
  3013. array(
  3014. 'Category' => array(
  3015. 'id' => '4',
  3016. 'parent_id' => '0',
  3017. 'name' => 'Category 2',
  3018. 'created' => '2007-03-18 15:30:23',
  3019. 'updated' => '2007-03-18 15:32:31'
  3020. ),
  3021. 'children' => array()
  3022. ),
  3023. array(
  3024. 'Category' => array(
  3025. 'id' => '5',
  3026. 'parent_id' => '0',
  3027. 'name' => 'Category 3',
  3028. 'created' => '2007-03-18 15:30:23',
  3029. 'updated' => '2007-03-18 15:32:31'
  3030. ),
  3031. 'children' => array(
  3032. array(
  3033. 'Category' => array(
  3034. 'id' => '6',
  3035. 'parent_id' => '5',
  3036. 'name' => 'Category 3.1',
  3037. 'created' => '2007-03-18 15:30:23',
  3038. 'updated' => '2007-03-18 15:32:31'
  3039. ),
  3040. 'children' => array()
  3041. )
  3042. )
  3043. )
  3044. );
  3045. $this->assertEqual($result, $expected);
  3046. $result = $TestModel->find('threaded', array(
  3047. 'conditions' => array('Category.name LIKE' => 'Category 1%')
  3048. ));
  3049. $expected = array(
  3050. array(
  3051. 'Category' => array(
  3052. 'id' => '1',
  3053. 'parent_id' => '0',
  3054. 'name' => 'Category 1',
  3055. 'created' => '2007-03-18 15:30:23',
  3056. 'updated' => '2007-03-18 15:32:31'
  3057. ),
  3058. 'children' => array(
  3059. array(
  3060. 'Category' => array(
  3061. 'id' => '2',
  3062. 'parent_id' => '1',
  3063. 'name' => 'Category 1.1',
  3064. 'created' => '2007-03-18 15:30:23',
  3065. 'updated' => '2007-03-18 15:32:31'
  3066. ),
  3067. 'children' => array(
  3068. array('Category' => array(
  3069. 'id' => '7',
  3070. 'parent_id' => '2',
  3071. 'name' => 'Category 1.1.1',
  3072. 'created' => '2007-03-18 15:30:23',
  3073. 'updated' => '2007-03-18 15:32:31'),
  3074. 'children' => array()),
  3075. array('Category' => array(
  3076. 'id' => '8',
  3077. 'parent_id' => '2',
  3078. 'name' => 'Category 1.1.2',
  3079. 'created' => '2007-03-18 15:30:23',
  3080. 'updated' => '2007-03-18 15:32:31'),
  3081. 'children' => array()))
  3082. ),
  3083. array(
  3084. 'Category' => array(
  3085. 'id' => '3',
  3086. 'parent_id' => '1',
  3087. 'name' => 'Category 1.2',
  3088. 'created' => '2007-03-18 15:30:23',
  3089. 'updated' => '2007-03-18 15:32:31'
  3090. ),
  3091. 'children' => array()
  3092. )
  3093. )
  3094. )
  3095. );
  3096. $this->assertEqual($result, $expected);
  3097. $result = $TestModel->find('threaded', array(
  3098. 'fields' => 'id, parent_id, name'
  3099. ));
  3100. $expected = array(
  3101. array(
  3102. 'Category' => array(
  3103. 'id' => '1',
  3104. 'parent_id' => '0',
  3105. 'name' => 'Category 1'
  3106. ),
  3107. 'children' => array(
  3108. array(
  3109. 'Category' => array(
  3110. 'id' => '2',
  3111. 'parent_id' => '1',
  3112. 'name' => 'Category 1.1'
  3113. ),
  3114. 'children' => array(
  3115. array('Category' => array(
  3116. 'id' => '7',
  3117. 'parent_id' => '2',
  3118. 'name' => 'Category 1.1.1'),
  3119. 'children' => array()),
  3120. array('Category' => array(
  3121. 'id' => '8',
  3122. 'parent_id' => '2',
  3123. 'name' => 'Category 1.1.2'),
  3124. 'children' => array()))
  3125. ),
  3126. array(
  3127. 'Category' => array(
  3128. 'id' => '3',
  3129. 'parent_id' => '1',
  3130. 'name' => 'Category 1.2'
  3131. ),
  3132. 'children' => array()
  3133. )
  3134. )
  3135. ),
  3136. array(
  3137. 'Category' => array(
  3138. 'id' => '4',
  3139. 'parent_id' => '0',
  3140. 'name' => 'Category 2'
  3141. ),
  3142. 'children' => array()
  3143. ),
  3144. array(
  3145. 'Category' => array(
  3146. 'id' => '5',
  3147. 'parent_id' => '0',
  3148. 'name' => 'Category 3'
  3149. ),
  3150. 'children' => array(
  3151. array(
  3152. 'Category' => array(
  3153. 'id' => '6',
  3154. 'parent_id' => '5',
  3155. 'name' => 'Category 3.1'
  3156. ),
  3157. 'children' => array()
  3158. )
  3159. )
  3160. )
  3161. );
  3162. $this->assertEqual($result, $expected);
  3163. $result = $TestModel->find('threaded', array('order' => 'id DESC'));
  3164. $expected = array(
  3165. array(
  3166. 'Category' => array(
  3167. 'id' => 5,
  3168. 'parent_id' => 0,
  3169. 'name' => 'Category 3',
  3170. 'created' => '2007-03-18 15:30:23',
  3171. 'updated' => '2007-03-18 15:32:31'
  3172. ),
  3173. 'children' => array(
  3174. array(
  3175. 'Category' => array(
  3176. 'id' => 6,
  3177. 'parent_id' => 5,
  3178. 'name' => 'Category 3.1',
  3179. 'created' => '2007-03-18 15:30:23',
  3180. 'updated' => '2007-03-18 15:32:31'
  3181. ),
  3182. 'children' => array()
  3183. )
  3184. )
  3185. ),
  3186. array(
  3187. 'Category' => array(
  3188. 'id' => 4,
  3189. 'parent_id' => 0,
  3190. 'name' => 'Category 2',
  3191. 'created' => '2007-03-18 15:30:23',
  3192. 'updated' => '2007-03-18 15:32:31'
  3193. ),
  3194. 'children' => array()
  3195. ),
  3196. array(
  3197. 'Category' => array(
  3198. 'id' => 1,
  3199. 'parent_id' => 0,
  3200. 'name' => 'Category 1',
  3201. 'created' => '2007-03-18 15:30:23',
  3202. 'updated' => '2007-03-18 15:32:31'
  3203. ),
  3204. 'children' => array(
  3205. array(
  3206. 'Category' => array(
  3207. 'id' => 3,
  3208. 'parent_id' => 1,
  3209. 'name' => 'Category 1.2',
  3210. 'created' => '2007-03-18 15:30:23',
  3211. 'updated' => '2007-03-18 15:32:31'
  3212. ),
  3213. 'children' => array()
  3214. ),
  3215. array(
  3216. 'Category' => array(
  3217. 'id' => 2,
  3218. 'parent_id' => 1,
  3219. 'name' => 'Category 1.1',
  3220. 'created' => '2007-03-18 15:30:23',
  3221. 'updated' => '2007-03-18 15:32:31'
  3222. ),
  3223. 'children' => array(
  3224. array('Category' => array(
  3225. 'id' => '8',
  3226. 'parent_id' => '2',
  3227. 'name' => 'Category 1.1.2',
  3228. 'created' => '2007-03-18 15:30:23',
  3229. 'updated' => '2007-03-18 15:32:31'),
  3230. 'children' => array()),
  3231. array('Category' => array(
  3232. 'id' => '7',
  3233. 'parent_id' => '2',
  3234. 'name' => 'Category 1.1.1',
  3235. 'created' => '2007-03-18 15:30:23',
  3236. 'updated' => '2007-03-18 15:32:31'),
  3237. 'children' => array()))
  3238. )
  3239. )
  3240. )
  3241. );
  3242. $this->assertEqual($result, $expected);
  3243. $result = $TestModel->find('threaded', array(
  3244. 'conditions' => array('Category.name LIKE' => 'Category 3%')
  3245. ));
  3246. $expected = array(
  3247. array(
  3248. 'Category' => array(
  3249. 'id' => '5',
  3250. 'parent_id' => '0',
  3251. 'name' => 'Category 3',
  3252. 'created' => '2007-03-18 15:30:23',
  3253. 'updated' => '2007-03-18 15:32:31'
  3254. ),
  3255. 'children' => array(
  3256. array(
  3257. 'Category' => array(
  3258. 'id' => '6',
  3259. 'parent_id' => '5',
  3260. 'name' => 'Category 3.1',
  3261. 'created' => '2007-03-18 15:30:23',
  3262. 'updated' => '2007-03-18 15:32:31'
  3263. ),
  3264. 'children' => array()
  3265. )
  3266. )
  3267. )
  3268. );
  3269. $this->assertEqual($result, $expected);
  3270. $result = $TestModel->find('threaded', array(
  3271. 'conditions' => array('Category.name LIKE' => 'Category 1.1%')
  3272. ));
  3273. $expected = array(
  3274. array('Category' =>
  3275. array(
  3276. 'id' => '2',
  3277. 'parent_id' => '1',
  3278. 'name' => 'Category 1.1',
  3279. 'created' => '2007-03-18 15:30:23',
  3280. 'updated' => '2007-03-18 15:32:31'),
  3281. 'children' => array(
  3282. array('Category' => array(
  3283. 'id' => '7',
  3284. 'parent_id' => '2',
  3285. 'name' => 'Category 1.1.1',
  3286. 'created' => '2007-03-18 15:30:23',
  3287. 'updated' => '2007-03-18 15:32:31'),
  3288. 'children' => array()),
  3289. array('Category' => array(
  3290. 'id' => '8',
  3291. 'parent_id' => '2',
  3292. 'name' => 'Category 1.1.2',
  3293. 'created' => '2007-03-18 15:30:23',
  3294. 'updated' => '2007-03-18 15:32:31'),
  3295. 'children' => array()))));
  3296. $this->assertEqual($result, $expected);
  3297. $result = $TestModel->find('threaded', array(
  3298. 'fields' => 'id, parent_id, name',
  3299. 'conditions' => array('Category.id !=' => 2)
  3300. ));
  3301. $expected = array(
  3302. array(
  3303. 'Category' => array(
  3304. 'id' => '1',
  3305. 'parent_id' => '0',
  3306. 'name' => 'Category 1'
  3307. ),
  3308. 'children' => array(
  3309. array(
  3310. 'Category' => array(
  3311. 'id' => '3',
  3312. 'parent_id' => '1',
  3313. 'name' => 'Category 1.2'
  3314. ),
  3315. 'children' => array()
  3316. )
  3317. )
  3318. ),
  3319. array(
  3320. 'Category' => array(
  3321. 'id' => '4',
  3322. 'parent_id' => '0',
  3323. 'name' => 'Category 2'
  3324. ),
  3325. 'children' => array()
  3326. ),
  3327. array(
  3328. 'Category' => array(
  3329. 'id' => '5',
  3330. 'parent_id' => '0',
  3331. 'name' => 'Category 3'
  3332. ),
  3333. 'children' => array(
  3334. array(
  3335. 'Category' => array(
  3336. 'id' => '6',
  3337. 'parent_id' => '5',
  3338. 'name' => 'Category 3.1'
  3339. ),
  3340. 'children' => array()
  3341. )
  3342. )
  3343. )
  3344. );
  3345. $this->assertEqual($result, $expected);
  3346. $result = $TestModel->find('all', array(
  3347. 'fields' => 'id, name, parent_id',
  3348. 'conditions' => array('Category.id !=' => 1)
  3349. ));
  3350. $expected = array (
  3351. array ('Category' => array(
  3352. 'id' => '2',
  3353. 'name' => 'Category 1.1',
  3354. 'parent_id' => '1'
  3355. )),
  3356. array ('Category' => array(
  3357. 'id' => '3',
  3358. 'name' => 'Category 1.2',
  3359. 'parent_id' => '1'
  3360. )),
  3361. array ('Category' => array(
  3362. 'id' => '4',
  3363. 'name' => 'Category 2',
  3364. 'parent_id' => '0'
  3365. )),
  3366. array ('Category' => array(
  3367. 'id' => '5',
  3368. 'name' => 'Category 3',
  3369. 'parent_id' => '0'
  3370. )),
  3371. array ('Category' => array(
  3372. 'id' => '6',
  3373. 'name' => 'Category 3.1',
  3374. 'parent_id' => '5'
  3375. )),
  3376. array ('Category' => array(
  3377. 'id' => '7',
  3378. 'name' => 'Category 1.1.1',
  3379. 'parent_id' => '2'
  3380. )),
  3381. array ('Category' => array(
  3382. 'id' => '8',
  3383. 'name' => 'Category 1.1.2',
  3384. 'parent_id' => '2'
  3385. )));
  3386. $this->assertEqual($result, $expected);
  3387. $result = $TestModel->find('threaded', array(
  3388. 'fields' => 'id, parent_id, name',
  3389. 'conditions' => array('Category.id !=' => 1)
  3390. ));
  3391. $expected = array(
  3392. array(
  3393. 'Category' => array(
  3394. 'id' => '2',
  3395. 'parent_id' => '1',
  3396. 'name' => 'Category 1.1'
  3397. ),
  3398. 'children' => array(
  3399. array('Category' => array(
  3400. 'id' => '7',
  3401. 'parent_id' => '2',
  3402. 'name' => 'Category 1.1.1'),
  3403. 'children' => array()),
  3404. array('Category' => array(
  3405. 'id' => '8',
  3406. 'parent_id' => '2',
  3407. 'name' => 'Category 1.1.2'),
  3408. 'children' => array()))
  3409. ),
  3410. array(
  3411. 'Category' => array(
  3412. 'id' => '3',
  3413. 'parent_id' => '1',
  3414. 'name' => 'Category 1.2'
  3415. ),
  3416. 'children' => array()
  3417. )
  3418. );
  3419. $this->assertEqual($result, $expected);
  3420. }
  3421. /**
  3422. * test find('neighbors')
  3423. *
  3424. * @return void
  3425. * @access public
  3426. */
  3427. function testFindNeighbors() {
  3428. $this->loadFixtures('User', 'Article');
  3429. $TestModel =& new Article();
  3430. $TestModel->id = 1;
  3431. $result = $TestModel->find('neighbors', array('fields' => array('id')));
  3432. $expected = array(
  3433. 'prev' => null,
  3434. 'next' => array(
  3435. 'Article' => array('id' => 2)
  3436. ));
  3437. $this->assertEqual($result, $expected);
  3438. $TestModel->id = 2;
  3439. $result = $TestModel->find('neighbors', array(
  3440. 'fields' => array('id')
  3441. ));
  3442. $expected = array(
  3443. 'prev' => array(
  3444. 'Article' => array(
  3445. 'id' => 1
  3446. )),
  3447. 'next' => array(
  3448. 'Article' => array(
  3449. 'id' => 3
  3450. )));
  3451. $this->assertEqual($result, $expected);
  3452. $TestModel->id = 3;
  3453. $result = $TestModel->find('neighbors', array('fields' => array('id')));
  3454. $expected = array(
  3455. 'prev' => array(
  3456. 'Article' => array(
  3457. 'id' => 2
  3458. )),
  3459. 'next' => null
  3460. );
  3461. $this->assertEqual($result, $expected);
  3462. $TestModel->id = 1;
  3463. $result = $TestModel->find('neighbors', array('recursive' => -1));
  3464. $expected = array(
  3465. 'prev' => null,
  3466. 'next' => array(
  3467. 'Article' => array(
  3468. 'id' => 2,
  3469. 'user_id' => 3,
  3470. 'title' => 'Second Article',
  3471. 'body' => 'Second Article Body',
  3472. 'published' => 'Y',
  3473. 'created' => '2007-03-18 10:41:23',
  3474. 'updated' => '2007-03-18 10:43:31'
  3475. )
  3476. )
  3477. );
  3478. $this->assertEqual($result, $expected);
  3479. $TestModel->id = 2;
  3480. $result = $TestModel->find('neighbors', array('recursive' => -1));
  3481. $expected = array(
  3482. 'prev' => array(
  3483. 'Article' => array(
  3484. 'id' => 1,
  3485. 'user_id' => 1,
  3486. 'title' => 'First Article',
  3487. 'body' => 'First Article Body',
  3488. 'published' => 'Y',
  3489. 'created' => '2007-03-18 10:39:23',
  3490. 'updated' => '2007-03-18 10:41:31'
  3491. )
  3492. ),
  3493. 'next' => array(
  3494. 'Article' => array(
  3495. 'id' => 3,
  3496. 'user_id' => 1,
  3497. 'title' => 'Third Article',
  3498. 'body' => 'Third Article Body',
  3499. 'published' => 'Y',
  3500. 'created' => '2007-03-18 10:43:23',
  3501. 'updated' => '2007-03-18 10:45:31'
  3502. )
  3503. )
  3504. );
  3505. $this->assertEqual($result, $expected);
  3506. $TestModel->id = 3;
  3507. $result = $TestModel->find('neighbors', array('recursive' => -1));
  3508. $expected = array(
  3509. 'prev' => array(
  3510. 'Article' => array(
  3511. 'id' => 2,
  3512. 'user_id' => 3,
  3513. 'title' => 'Second Article',
  3514. 'body' => 'Second Article Body',
  3515. 'published' => 'Y',
  3516. 'created' => '2007-03-18 10:41:23',
  3517. 'updated' => '2007-03-18 10:43:31'
  3518. )
  3519. ),
  3520. 'next' => null
  3521. );
  3522. $this->assertEqual($result, $expected);
  3523. $TestModel->recursive = 0;
  3524. $TestModel->id = 1;
  3525. $one = $TestModel->read();
  3526. $TestModel->id = 2;
  3527. $two = $TestModel->read();
  3528. $TestModel->id = 3;
  3529. $three = $TestModel->read();
  3530. $TestModel->id = 1;
  3531. $result = $TestModel->find('neighbors');
  3532. $expected = array('prev' => null, 'next' => $two);
  3533. $this->assertEqual($result, $expected);
  3534. $TestModel->id = 2;
  3535. $result = $TestModel->find('neighbors');
  3536. $expected = array('prev' => $one, 'next' => $three);
  3537. $this->assertEqual($result, $expected);
  3538. $TestModel->id = 3;
  3539. $result = $TestModel->find('neighbors');
  3540. $expected = array('prev' => $two, 'next' => null);
  3541. $this->assertEqual($result, $expected);
  3542. $TestModel->recursive = 2;
  3543. $TestModel->id = 1;
  3544. $one = $TestModel->read();
  3545. $TestModel->id = 2;
  3546. $two = $TestModel->read();
  3547. $TestModel->id = 3;
  3548. $three = $TestModel->read();
  3549. $TestModel->id = 1;
  3550. $result = $TestModel->find('neighbors', array('recursive' => 2));
  3551. $expected = array('prev' => null, 'next' => $two);
  3552. $this->assertEqual($result, $expected);
  3553. $TestModel->id = 2;
  3554. $result = $TestModel->find('neighbors', array('recursive' => 2));
  3555. $expected = array('prev' => $one, 'next' => $three);
  3556. $this->assertEqual($result, $expected);
  3557. $TestModel->id = 3;
  3558. $result = $TestModel->find('neighbors', array('recursive' => 2));
  3559. $expected = array('prev' => $two, 'next' => null);
  3560. $this->assertEqual($result, $expected);
  3561. }
  3562. /**
  3563. * testFindCombinedRelations method
  3564. *
  3565. * @access public
  3566. * @return void
  3567. */
  3568. function testFindCombinedRelations() {
  3569. $this->loadFixtures('Apple', 'Sample');
  3570. $TestModel =& new Apple();
  3571. $result = $TestModel->find('all');
  3572. $expected = array(
  3573. array(
  3574. 'Apple' => array(
  3575. 'id' => '1',
  3576. 'apple_id' => '2',
  3577. 'color' => 'Red 1',
  3578. 'name' => 'Red Apple 1',
  3579. 'created' => '2006-11-22 10:38:58',
  3580. 'date' => '1951-01-04',
  3581. 'modified' => '2006-12-01 13:31:26',
  3582. 'mytime' => '22:57:17'
  3583. ),
  3584. 'Parent' => array(
  3585. 'id' => '2',
  3586. 'apple_id' => '1',
  3587. 'color' => 'Bright Red 1',
  3588. 'name' => 'Bright Red Apple',
  3589. 'created' => '2006-11-22 10:43:13',
  3590. 'date' => '2014-01-01',
  3591. 'modified' => '2006-11-30 18:38:10',
  3592. 'mytime' => '22:57:17'
  3593. ),
  3594. 'Sample' => array(
  3595. 'id' => null,
  3596. 'apple_id' => null,
  3597. 'name' => null
  3598. ),
  3599. 'Child' => array(
  3600. array(
  3601. 'id' => '2',
  3602. 'apple_id' => '1',
  3603. 'color' => 'Bright Red 1',
  3604. 'name' => 'Bright Red Apple',
  3605. 'created' => '2006-11-22 10:43:13',
  3606. 'date' => '2014-01-01',
  3607. 'modified' => '2006-11-30 18:38:10',
  3608. 'mytime' => '22:57:17'
  3609. ))),
  3610. array(
  3611. 'Apple' => array(
  3612. 'id' => '2',
  3613. 'apple_id' => '1',
  3614. 'color' => 'Bright Red 1',
  3615. 'name' => 'Bright Red Apple',
  3616. 'created' => '2006-11-22 10:43:13',
  3617. 'date' => '2014-01-01',
  3618. 'modified' => '2006-11-30 18:38:10',
  3619. 'mytime' => '22:57:17'
  3620. ),
  3621. 'Parent' => array(
  3622. 'id' => '1',
  3623. 'apple_id' => '2',
  3624. 'color' => 'Red 1',
  3625. 'name' => 'Red Apple 1',
  3626. 'created' => '2006-11-22 10:38:58',
  3627. 'date' => '1951-01-04',
  3628. 'modified' => '2006-12-01 13:31:26',
  3629. 'mytime' => '22:57:17'
  3630. ),
  3631. 'Sample' => array(
  3632. 'id' => '2',
  3633. 'apple_id' => '2',
  3634. 'name' => 'sample2'
  3635. ),
  3636. 'Child' => array(
  3637. array(
  3638. 'id' => '1',
  3639. 'apple_id' => '2',
  3640. 'color' => 'Red 1',
  3641. 'name' => 'Red Apple 1',
  3642. 'created' => '2006-11-22 10:38:58',
  3643. 'date' => '1951-01-04',
  3644. 'modified' => '2006-12-01 13:31:26',
  3645. 'mytime' => '22:57:17'
  3646. ),
  3647. array(
  3648. 'id' => '3',
  3649. 'apple_id' => '2',
  3650. 'color' => 'blue green',
  3651. 'name' => 'green blue',
  3652. 'created' => '2006-12-25 05:13:36',
  3653. 'date' => '2006-12-25',
  3654. 'modified' => '2006-12-25 05:23:24',
  3655. 'mytime' => '22:57:17'
  3656. ),
  3657. array(
  3658. 'id' => '4',
  3659. 'apple_id' => '2',
  3660. 'color' => 'Blue Green',
  3661. 'name' => 'Test Name',
  3662. 'created' => '2006-12-25 05:23:36',
  3663. 'date' => '2006-12-25',
  3664. 'modified' => '2006-12-25 05:23:36',
  3665. 'mytime' => '22:57:17'
  3666. ))),
  3667. array(
  3668. 'Apple' => array(
  3669. 'id' => '3',
  3670. 'apple_id' => '2',
  3671. 'color' => 'blue green',
  3672. 'name' => 'green blue',
  3673. 'created' => '2006-12-25 05:13:36',
  3674. 'date' => '2006-12-25',
  3675. 'modified' => '2006-12-25 05:23:24',
  3676. 'mytime' => '22:57:17'
  3677. ),
  3678. 'Parent' => array(
  3679. 'id' => '2',
  3680. 'apple_id' => '1',
  3681. 'color' => 'Bright Red 1',
  3682. 'name' => 'Bright Red Apple',
  3683. 'created' => '2006-11-22 10:43:13',
  3684. 'date' => '2014-01-01',
  3685. 'modified' => '2006-11-30 18:38:10',
  3686. 'mytime' => '22:57:17'
  3687. ),
  3688. 'Sample' => array(
  3689. 'id' => '1',
  3690. 'apple_id' => '3',
  3691. 'name' => 'sample1'
  3692. ),
  3693. 'Child' => array()
  3694. ),
  3695. array(
  3696. 'Apple' => array(
  3697. 'id' => '4',
  3698. 'apple_id' => '2',
  3699. 'color' => 'Blue Green',
  3700. 'name' => 'Test Name',
  3701. 'created' => '2006-12-25 05:23:36',
  3702. 'date' => '2006-12-25',
  3703. 'modified' => '2006-12-25 05:23:36',
  3704. 'mytime' => '22:57:17'
  3705. ),
  3706. 'Parent' => array(
  3707. 'id' => '2',
  3708. 'apple_id' => '1',
  3709. 'color' => 'Bright Red 1',
  3710. 'name' => 'Bright Red Apple',
  3711. 'created' => '2006-11-22 10:43:13',
  3712. 'date' => '2014-01-01',
  3713. 'modified' => '2006-11-30 18:38:10',
  3714. 'mytime' => '22:57:17'
  3715. ),
  3716. 'Sample' => array(
  3717. 'id' => '3',
  3718. 'apple_id' => '4',
  3719. 'name' => 'sample3'
  3720. ),
  3721. 'Child' => array(
  3722. array(
  3723. 'id' => '6',
  3724. 'apple_id' => '4',
  3725. 'color' => 'My new appleOrange',
  3726. 'name' => 'My new apple',
  3727. 'created' => '2006-12-25 05:29:39',
  3728. 'date' => '2006-12-25',
  3729. 'modified' => '2006-12-25 05:29:39',
  3730. 'mytime' => '22:57:17'
  3731. ))),
  3732. array(
  3733. 'Apple' => array(
  3734. 'id' => '5',
  3735. 'apple_id' => '5',
  3736. 'color' => 'Green',
  3737. 'name' => 'Blue Green',
  3738. 'created' => '2006-12-25 05:24:06',
  3739. 'date' => '2006-12-25',
  3740. 'modified' => '2006-12-25 05:29:16',
  3741. 'mytime' => '22:57:17'
  3742. ),
  3743. 'Parent' => array(
  3744. 'id' => '5',
  3745. 'apple_id' => '5',
  3746. 'color' => 'Green',
  3747. 'name' => 'Blue Green',
  3748. 'created' => '2006-12-25 05:24:06',
  3749. 'date' => '2006-12-25',
  3750. 'modified' => '2006-12-25 05:29:16',
  3751. 'mytime' => '22:57:17'
  3752. ),
  3753. 'Sample' => array(
  3754. 'id' => '4',
  3755. 'apple_id' => '5',
  3756. 'name' => 'sample4'
  3757. ),
  3758. 'Child' => array(
  3759. array(
  3760. 'id' => '5',
  3761. 'apple_id' => '5',
  3762. 'color' => 'Green',
  3763. 'name' => 'Blue Green',
  3764. 'created' => '2006-12-25 05:24:06',
  3765. 'date' => '2006-12-25',
  3766. 'modified' => '2006-12-25 05:29:16',
  3767. 'mytime' => '22:57:17'
  3768. ))),
  3769. array(
  3770. 'Apple' => array(
  3771. 'id' => '6',
  3772. 'apple_id' => '4',
  3773. 'color' => 'My new appleOrange',
  3774. 'name' => 'My new apple',
  3775. 'created' => '2006-12-25 05:29:39',
  3776. 'date' => '2006-12-25',
  3777. 'modified' => '2006-12-25 05:29:39',
  3778. 'mytime' => '22:57:17'
  3779. ),
  3780. 'Parent' => array(
  3781. 'id' => '4',
  3782. 'apple_id' => '2',
  3783. 'color' => 'Blue Green',
  3784. 'name' => 'Test Name',
  3785. 'created' => '2006-12-25 05:23:36',
  3786. 'date' => '2006-12-25',
  3787. 'modified' => '2006-12-25 05:23:36',
  3788. 'mytime' => '22:57:17'
  3789. ),
  3790. 'Sample' => array(
  3791. 'id' => null,
  3792. 'apple_id' => null,
  3793. 'name' => null
  3794. ),
  3795. 'Child' => array(
  3796. array(
  3797. 'id' => '7',
  3798. 'apple_id' => '6',
  3799. 'color' => 'Some wierd color',
  3800. 'name' => 'Some odd color',
  3801. 'created' => '2006-12-25 05:34:21',
  3802. 'date' => '2006-12-25',
  3803. 'modified' => '2006-12-25 05:34:21',
  3804. 'mytime' => '22:57:17'
  3805. ))),
  3806. array(
  3807. 'Apple' => array(
  3808. 'id' => '7',
  3809. 'apple_id' => '6',
  3810. 'color' => 'Some wierd color',
  3811. 'name' => 'Some odd color',
  3812. 'created' => '2006-12-25 05:34:21',
  3813. 'date' => '2006-12-25',
  3814. 'modified' => '2006-12-25 05:34:21',
  3815. 'mytime' => '22:57:17'
  3816. ),
  3817. 'Parent' => array(
  3818. 'id' => '6',
  3819. 'apple_id' => '4',
  3820. 'color' => 'My new appleOrange',
  3821. 'name' => 'My new apple',
  3822. 'created' => '2006-12-25 05:29:39',
  3823. 'date' => '2006-12-25',
  3824. 'modified' => '2006-12-25 05:29:39',
  3825. 'mytime' => '22:57:17'
  3826. ),
  3827. 'Sample' => array(
  3828. 'id' => null,
  3829. 'apple_id' => null,
  3830. 'name' => null
  3831. ),
  3832. 'Child' => array()
  3833. ));
  3834. $this->assertEqual($result, $expected);
  3835. }
  3836. /**
  3837. * testSaveEmpty method
  3838. *
  3839. * @access public
  3840. * @return void
  3841. */
  3842. function testSaveEmpty() {
  3843. $this->loadFixtures('Thread');
  3844. $TestModel =& new Thread();
  3845. $data = array();
  3846. $expected = $TestModel->save($data);
  3847. $this->assertFalse($expected);
  3848. }
  3849. /**
  3850. * testFindAllWithConditionInChildQuery
  3851. *
  3852. * @todo external conditions like this are going to need to be revisited at some point
  3853. * @access public
  3854. * @return void
  3855. */
  3856. function testFindAllWithConditionInChildQuery() {
  3857. $this->loadFixtures('Basket', 'FilmFile');
  3858. $TestModel =& new Basket();
  3859. $recursive = 3;
  3860. $result = $TestModel->find('all', compact('conditions', 'recursive'));
  3861. $expected = array(
  3862. array(
  3863. 'Basket' => array(
  3864. 'id' => 1,
  3865. 'type' => 'nonfile',
  3866. 'name' => 'basket1',
  3867. 'object_id' => 1,
  3868. 'user_id' => 1,
  3869. ),
  3870. 'FilmFile' => array(
  3871. 'id' => '',
  3872. 'name' => '',
  3873. )
  3874. ),
  3875. array(
  3876. 'Basket' => array(
  3877. 'id' => 2,
  3878. 'type' => 'file',
  3879. 'name' => 'basket2',
  3880. 'object_id' => 2,
  3881. 'user_id' => 1,
  3882. ),
  3883. 'FilmFile' => array(
  3884. 'id' => 2,
  3885. 'name' => 'two',
  3886. )
  3887. ),
  3888. );
  3889. $this->assertEqual($result, $expected);
  3890. }
  3891. /**
  3892. * testFindAllWithConditionsHavingMixedDataTypes method
  3893. *
  3894. * @access public
  3895. * @return void
  3896. */
  3897. function testFindAllWithConditionsHavingMixedDataTypes() {
  3898. $this->loadFixtures('Article');
  3899. $TestModel =& new Article();
  3900. $expected = array(
  3901. array(
  3902. 'Article' => array(
  3903. 'id' => 1,
  3904. 'user_id' => 1,
  3905. 'title' => 'First Article',
  3906. 'body' => 'First Article Body',
  3907. 'published' => 'Y',
  3908. 'created' => '2007-03-18 10:39:23',
  3909. 'updated' => '2007-03-18 10:41:31'
  3910. )
  3911. ),
  3912. array(
  3913. 'Article' => array(
  3914. 'id' => 2,
  3915. 'user_id' => 3,
  3916. 'title' => 'Second Article',
  3917. 'body' => 'Second Article Body',
  3918. 'published' => 'Y',
  3919. 'created' => '2007-03-18 10:41:23',
  3920. 'updated' => '2007-03-18 10:43:31'
  3921. )
  3922. )
  3923. );
  3924. $conditions = array('id' => array('1', 2));
  3925. $recursive = -1;
  3926. $order = 'Article.id ASC';
  3927. $result = $TestModel->find('all', compact('conditions', 'recursive', 'order'));
  3928. $this->assertEqual($result, $expected);
  3929. if ($this->skipIf($this->db->config['driver'] == 'postgres', 'The rest of testFindAllWithConditionsHavingMixedDataTypes test is not compatible with Postgres')) {
  3930. return;
  3931. }
  3932. $conditions = array('id' => array('1', 2, '3.0'));
  3933. $order = 'Article.id ASC';
  3934. $result = $TestModel->find('all', compact('recursive', 'conditions', 'order'));
  3935. $expected = array(
  3936. array(
  3937. 'Article' => array(
  3938. 'id' => 1,
  3939. 'user_id' => 1,
  3940. 'title' => 'First Article',
  3941. 'body' => 'First Article Body',
  3942. 'published' => 'Y',
  3943. 'created' => '2007-03-18 10:39:23',
  3944. 'updated' => '2007-03-18 10:41:31'
  3945. )
  3946. ),
  3947. array(
  3948. 'Article' => array(
  3949. 'id' => 2,
  3950. 'user_id' => 3,
  3951. 'title' => 'Second Article',
  3952. 'body' => 'Second Article Body',
  3953. 'published' => 'Y',
  3954. 'created' => '2007-03-18 10:41:23',
  3955. 'updated' => '2007-03-18 10:43:31'
  3956. )
  3957. ),
  3958. array(
  3959. 'Article' => array(
  3960. 'id' => 3,
  3961. 'user_id' => 1,
  3962. 'title' => 'Third Article',
  3963. 'body' => 'Third Article Body',
  3964. 'published' => 'Y',
  3965. 'created' => '2007-03-18 10:43:23',
  3966. 'updated' => '2007-03-18 10:45:31'
  3967. )
  3968. )
  3969. );
  3970. $this->assertEqual($result, $expected);
  3971. }
  3972. /**
  3973. * testBindUnbind method
  3974. *
  3975. * @access public
  3976. * @return void
  3977. */
  3978. function testBindUnbind() {
  3979. $this->loadFixtures('User', 'Comment', 'FeatureSet');
  3980. $TestModel =& new User();
  3981. $result = $TestModel->hasMany;
  3982. $expected = array();
  3983. $this->assertEqual($result, $expected);
  3984. $result = $TestModel->bindModel(array('hasMany' => array('Comment')));
  3985. $this->assertTrue($result);
  3986. $result = $TestModel->find('all', array(
  3987. 'fields' => 'User.id, User.user'
  3988. ));
  3989. $expected = array(
  3990. array(
  3991. 'User' => array(
  3992. 'id' => '1',
  3993. 'user' => 'mariano'
  3994. ),
  3995. 'Comment' => array(
  3996. array(
  3997. 'id' => '3',
  3998. 'article_id' => '1',
  3999. 'user_id' => '1',
  4000. 'comment' => 'Third Comment for First Article',
  4001. 'published' => 'Y',
  4002. 'created' => '2007-03-18 10:49:23',
  4003. 'updated' => '2007-03-18 10:51:31'
  4004. ),
  4005. array(
  4006. 'id' => '4',
  4007. 'article_id' => '1',
  4008. 'user_id' => '1',
  4009. 'comment' => 'Fourth Comment for First Article',
  4010. 'published' => 'N',
  4011. 'created' => '2007-03-18 10:51:23',
  4012. 'updated' => '2007-03-18 10:53:31'
  4013. ),
  4014. array(
  4015. 'id' => '5',
  4016. 'article_id' => '2',
  4017. 'user_id' => '1',
  4018. 'comment' => 'First Comment for Second Article',
  4019. 'published' => 'Y',
  4020. 'created' => '2007-03-18 10:53:23',
  4021. 'updated' => '2007-03-18 10:55:31'
  4022. ))),
  4023. array(
  4024. 'User' => array(
  4025. 'id' => '2',
  4026. 'user' => 'nate'
  4027. ),
  4028. 'Comment' => array(
  4029. array(
  4030. 'id' => '1',
  4031. 'article_id' => '1',
  4032. 'user_id' => '2',
  4033. 'comment' => 'First Comment for First Article',
  4034. 'published' => 'Y',
  4035. 'created' => '2007-03-18 10:45:23',
  4036. 'updated' => '2007-03-18 10:47:31'
  4037. ),
  4038. array(
  4039. 'id' => '6',
  4040. 'article_id' => '2',
  4041. 'user_id' => '2',
  4042. 'comment' => 'Second Comment for Second Article',
  4043. 'published' => 'Y',
  4044. 'created' => '2007-03-18 10:55:23',
  4045. 'updated' => '2007-03-18 10:57:31'
  4046. ))),
  4047. array(
  4048. 'User' => array(
  4049. 'id' => '3',
  4050. 'user' => 'larry'
  4051. ),
  4052. 'Comment' => array()
  4053. ),
  4054. array(
  4055. 'User' => array(
  4056. 'id' => '4',
  4057. 'user' => 'garrett'
  4058. ),
  4059. 'Comment' => array(
  4060. array(
  4061. 'id' => '2',
  4062. 'article_id' => '1',
  4063. 'user_id' => '4',
  4064. 'comment' => 'Second Comment for First Article',
  4065. 'published' => 'Y',
  4066. 'created' => '2007-03-18 10:47:23',
  4067. 'updated' => '2007-03-18 10:49:31'
  4068. ))));
  4069. $this->assertEqual($result, $expected);
  4070. $TestModel->resetAssociations();
  4071. $result = $TestModel->hasMany;
  4072. $this->assertEqual($result, array());
  4073. $result = $TestModel->bindModel(array('hasMany' => array('Comment')), false);
  4074. $this->assertTrue($result);
  4075. $result = $TestModel->find('all', array(
  4076. 'fields' => 'User.id, User.user'
  4077. ));
  4078. $expected = array(
  4079. array(
  4080. 'User' => array(
  4081. 'id' => '1',
  4082. 'user' => 'mariano'
  4083. ),
  4084. 'Comment' => array(
  4085. array(
  4086. 'id' => '3',
  4087. 'article_id' => '1',
  4088. 'user_id' => '1',
  4089. 'comment' => 'Third Comment for First Article',
  4090. 'published' => 'Y',
  4091. 'created' => '2007-03-18 10:49:23',
  4092. 'updated' => '2007-03-18 10:51:31'
  4093. ),
  4094. array(
  4095. 'id' => '4',
  4096. 'article_id' => '1',
  4097. 'user_id' => '1',
  4098. 'comment' => 'Fourth Comment for First Article',
  4099. 'published' => 'N',
  4100. 'created' => '2007-03-18 10:51:23',
  4101. 'updated' => '2007-03-18 10:53:31'
  4102. ),
  4103. array(
  4104. 'id' => '5',
  4105. 'article_id' => '2',
  4106. 'user_id' => '1',
  4107. 'comment' => 'First Comment for Second Article',
  4108. 'published' => 'Y',
  4109. 'created' => '2007-03-18 10:53:23',
  4110. 'updated' => '2007-03-18 10:55:31'
  4111. ))),
  4112. array(
  4113. 'User' => array(
  4114. 'id' => '2',
  4115. 'user' => 'nate'
  4116. ),
  4117. 'Comment' => array(
  4118. array(
  4119. 'id' => '1',
  4120. 'article_id' => '1',
  4121. 'user_id' => '2',
  4122. 'comment' => 'First Comment for First Article',
  4123. 'published' => 'Y',
  4124. 'created' => '2007-03-18 10:45:23',
  4125. 'updated' => '2007-03-18 10:47:31'
  4126. ),
  4127. array(
  4128. 'id' => '6',
  4129. 'article_id' => '2',
  4130. 'user_id' => '2',
  4131. 'comment' => 'Second Comment for Second Article',
  4132. 'published' => 'Y',
  4133. 'created' => '2007-03-18 10:55:23',
  4134. 'updated' => '2007-03-18 10:57:31'
  4135. ))),
  4136. array(
  4137. 'User' => array(
  4138. 'id' => '3',
  4139. 'user' => 'larry'
  4140. ),
  4141. 'Comment' => array()
  4142. ),
  4143. array(
  4144. 'User' => array(
  4145. 'id' => '4',
  4146. 'user' => 'garrett'
  4147. ),
  4148. 'Comment' => array(
  4149. array(
  4150. 'id' => '2',
  4151. 'article_id' => '1',
  4152. 'user_id' => '4',
  4153. 'comment' => 'Second Comment for First Article',
  4154. 'published' => 'Y',
  4155. 'created' => '2007-03-18 10:47:23',
  4156. 'updated' => '2007-03-18 10:49:31'
  4157. ))));
  4158. $this->assertEqual($result, $expected);
  4159. $result = $TestModel->hasMany;
  4160. $expected = array(
  4161. 'Comment' => array(
  4162. 'className' => 'Comment',
  4163. 'foreignKey' => 'user_id',
  4164. 'conditions' => null,
  4165. 'fields' => null,
  4166. 'order' => null,
  4167. 'limit' => null,
  4168. 'offset' => null,
  4169. 'dependent' => null,
  4170. 'exclusive' => null,
  4171. 'finderQuery' => null,
  4172. 'counterQuery' => null
  4173. ));
  4174. $this->assertEqual($result, $expected);
  4175. $result = $TestModel->unbindModel(array('hasMany' => array('Comment')));
  4176. $this->assertTrue($result);
  4177. $result = $TestModel->hasMany;
  4178. $expected = array();
  4179. $this->assertEqual($result, $expected);
  4180. $result = $TestModel->find('all', array(
  4181. 'fields' => 'User.id, User.user'
  4182. ));
  4183. $expected = array(
  4184. array('User' => array('id' => '1', 'user' => 'mariano')),
  4185. array('User' => array('id' => '2', 'user' => 'nate')),
  4186. array('User' => array('id' => '3', 'user' => 'larry')),
  4187. array('User' => array('id' => '4', 'user' => 'garrett')));
  4188. $this->assertEqual($result, $expected);
  4189. $result = $TestModel->find('all', array(
  4190. 'fields' => 'User.id, User.user'
  4191. ));
  4192. $expected = array(
  4193. array(
  4194. 'User' => array(
  4195. 'id' => '1',
  4196. 'user' => 'mariano'
  4197. ),
  4198. 'Comment' => array(
  4199. array(
  4200. 'id' => '3',
  4201. 'article_id' => '1',
  4202. 'user_id' => '1',
  4203. 'comment' => 'Third Comment for First Article',
  4204. 'published' => 'Y',
  4205. 'created' => '2007-03-18 10:49:23',
  4206. 'updated' => '2007-03-18 10:51:31'
  4207. ),
  4208. array(
  4209. 'id' => '4',
  4210. 'article_id' => '1',
  4211. 'user_id' => '1',
  4212. 'comment' => 'Fourth Comment for First Article',
  4213. 'published' => 'N',
  4214. 'created' => '2007-03-18 10:51:23',
  4215. 'updated' => '2007-03-18 10:53:31'
  4216. ),
  4217. array(
  4218. 'id' => '5',
  4219. 'article_id' => '2',
  4220. 'user_id' => '1',
  4221. 'comment' => 'First Comment for Second Article',
  4222. 'published' => 'Y',
  4223. 'created' => '2007-03-18 10:53:23',
  4224. 'updated' => '2007-03-18 10:55:31'
  4225. ))),
  4226. array(
  4227. 'User' => array(
  4228. 'id' => '2',
  4229. 'user' => 'nate'
  4230. ),
  4231. 'Comment' => array(
  4232. array(
  4233. 'id' => '1',
  4234. 'article_id' => '1',
  4235. 'user_id' => '2',
  4236. 'comment' => 'First Comment for First Article',
  4237. 'published' => 'Y',
  4238. 'created' => '2007-03-18 10:45:23',
  4239. 'updated' => '2007-03-18 10:47:31'
  4240. ),
  4241. array(
  4242. 'id' => '6',
  4243. 'article_id' => '2',
  4244. 'user_id' => '2',
  4245. 'comment' => 'Second Comment for Second Article',
  4246. 'published' => 'Y',
  4247. 'created' => '2007-03-18 10:55:23',
  4248. 'updated' => '2007-03-18 10:57:31'
  4249. ))),
  4250. array(
  4251. 'User' => array(
  4252. 'id' => '3',
  4253. 'user' => 'larry'
  4254. ),
  4255. 'Comment' => array()
  4256. ),
  4257. array(
  4258. 'User' => array(
  4259. 'id' => '4',
  4260. 'user' => 'garrett'
  4261. ),
  4262. 'Comment' => array(
  4263. array(
  4264. 'id' => '2',
  4265. 'article_id' => '1',
  4266. 'user_id' => '4',
  4267. 'comment' =>
  4268. 'Second Comment for First Article',
  4269. 'published' => 'Y',
  4270. 'created' => '2007-03-18 10:47:23',
  4271. 'updated' => '2007-03-18 10:49:31'
  4272. ))));
  4273. $this->assertEqual($result, $expected);
  4274. $result = $TestModel->unbindModel(array('hasMany' => array('Comment')), false);
  4275. $this->assertTrue($result);
  4276. $result = $TestModel->find('all', array('fields' => 'User.id, User.user'));
  4277. $expected = array(
  4278. array('User' => array('id' => '1', 'user' => 'mariano')),
  4279. array('User' => array('id' => '2', 'user' => 'nate')),
  4280. array('User' => array('id' => '3', 'user' => 'larry')),
  4281. array('User' => array('id' => '4', 'user' => 'garrett')));
  4282. $this->assertEqual($result, $expected);
  4283. $result = $TestModel->hasMany;
  4284. $expected = array();
  4285. $this->assertEqual($result, $expected);
  4286. $result = $TestModel->bindModel(array('hasMany' => array(
  4287. 'Comment' => array('className' => 'Comment', 'conditions' => 'Comment.published = \'Y\'')
  4288. )));
  4289. $this->assertTrue($result);
  4290. $result = $TestModel->find('all', array('fields' => 'User.id, User.user'));
  4291. $expected = array(
  4292. array(
  4293. 'User' => array(
  4294. 'id' => '1',
  4295. 'user' => 'mariano'
  4296. ),
  4297. 'Comment' => array(
  4298. array(
  4299. 'id' => '3',
  4300. 'article_id' => '1',
  4301. 'user_id' => '1',
  4302. 'comment' => 'Third Comment for First Article',
  4303. 'published' => 'Y',
  4304. 'created' => '2007-03-18 10:49:23',
  4305. 'updated' => '2007-03-18 10:51:31'
  4306. ),
  4307. array(
  4308. 'id' => '5',
  4309. 'article_id' => '2',
  4310. 'user_id' => '1',
  4311. 'comment' => 'First Comment for Second Article',
  4312. 'published' => 'Y',
  4313. 'created' => '2007-03-18 10:53:23',
  4314. 'updated' => '2007-03-18 10:55:31'
  4315. ))),
  4316. array(
  4317. 'User' => array(
  4318. 'id' => '2',
  4319. 'user' => 'nate'
  4320. ),
  4321. 'Comment' => array(
  4322. array(
  4323. 'id' => '1',
  4324. 'article_id' => '1',
  4325. 'user_id' => '2',
  4326. 'comment' => 'First Comment for First Article',
  4327. 'published' => 'Y',
  4328. 'created' => '2007-03-18 10:45:23',
  4329. 'updated' => '2007-03-18 10:47:31'
  4330. ),
  4331. array(
  4332. 'id' => '6',
  4333. 'article_id' => '2',
  4334. 'user_id' => '2',
  4335. 'comment' => 'Second Comment for Second Article',
  4336. 'published' => 'Y',
  4337. 'created' => '2007-03-18 10:55:23',
  4338. 'updated' => '2007-03-18 10:57:31'
  4339. ))),
  4340. array(
  4341. 'User' => array(
  4342. 'id' => '3',
  4343. 'user' => 'larry'
  4344. ),
  4345. 'Comment' => array()
  4346. ),
  4347. array(
  4348. 'User' => array(
  4349. 'id' => '4',
  4350. 'user' => 'garrett'
  4351. ),
  4352. 'Comment' => array(
  4353. array(
  4354. 'id' => '2',
  4355. 'article_id' => '1',
  4356. 'user_id' => '4',
  4357. 'comment' => 'Second Comment for First Article',
  4358. 'published' => 'Y',
  4359. 'created' => '2007-03-18 10:47:23',
  4360. 'updated' => '2007-03-18 10:49:31'
  4361. ))));
  4362. $this->assertEqual($result, $expected);
  4363. $TestModel2 =& new DeviceType();
  4364. $expected = array(
  4365. 'className' => 'FeatureSet',
  4366. 'foreignKey' => 'feature_set_id',
  4367. 'conditions' => '',
  4368. 'fields' => '',
  4369. 'order' => '',
  4370. 'counterCache' => ''
  4371. );
  4372. $this->assertEqual($TestModel2->belongsTo['FeatureSet'], $expected);
  4373. $TestModel2->bindModel(array(
  4374. 'belongsTo' => array(
  4375. 'FeatureSet' => array(
  4376. 'className' => 'FeatureSet',
  4377. 'conditions' => array('active' => true)
  4378. )
  4379. )
  4380. ));
  4381. $expected['conditions'] = array('active' => true);
  4382. $this->assertEqual($TestModel2->belongsTo['FeatureSet'], $expected);
  4383. $TestModel2->bindModel(array(
  4384. 'belongsTo' => array(
  4385. 'FeatureSet' => array(
  4386. 'className' => 'FeatureSet',
  4387. 'foreignKey' => false,
  4388. 'conditions' => array('Feature.name' => 'DeviceType.name')
  4389. )
  4390. )
  4391. ));
  4392. $expected['conditions'] = array('Feature.name' => 'DeviceType.name');
  4393. $expected['foreignKey'] = false;
  4394. $this->assertEqual($TestModel2->belongsTo['FeatureSet'], $expected);
  4395. $TestModel2->bindModel(array(
  4396. 'hasMany' => array(
  4397. 'NewFeatureSet' => array(
  4398. 'className' => 'FeatureSet',
  4399. 'conditions' => array('active' => true)
  4400. )
  4401. )
  4402. ));
  4403. $expected = array(
  4404. 'className' => 'FeatureSet',
  4405. 'conditions' => array('active' => true),
  4406. 'foreignKey' => 'device_type_id',
  4407. 'fields' => '',
  4408. 'order' => '',
  4409. 'limit' => '',
  4410. 'offset' => '',
  4411. 'dependent' => '',
  4412. 'exclusive' => '',
  4413. 'finderQuery' => '',
  4414. 'counterQuery' => ''
  4415. );
  4416. $this->assertEqual($TestModel2->hasMany['NewFeatureSet'], $expected);
  4417. $this->assertTrue(is_object($TestModel2->NewFeatureSet));
  4418. }
  4419. /**
  4420. * testBindMultipleTimes method
  4421. *
  4422. * @access public
  4423. * @return void
  4424. */
  4425. function testBindMultipleTimes() {
  4426. $this->loadFixtures('User', 'Comment', 'Article');
  4427. $TestModel =& new User();
  4428. $result = $TestModel->hasMany;
  4429. $expected = array();
  4430. $this->assertEqual($result, $expected);
  4431. $result = $TestModel->bindModel(array(
  4432. 'hasMany' => array(
  4433. 'Items' => array('className' => 'Comment')
  4434. )));
  4435. $this->assertTrue($result);
  4436. $result = $TestModel->find('all', array(
  4437. 'fields' => 'User.id, User.user'
  4438. ));
  4439. $expected = array(
  4440. array(
  4441. 'User' => array(
  4442. 'id' => '1',
  4443. 'user' => 'mariano'
  4444. ),
  4445. 'Items' => array(
  4446. array(
  4447. 'id' => '3',
  4448. 'article_id' => '1',
  4449. 'user_id' => '1',
  4450. 'comment' => 'Third Comment for First Article',
  4451. 'published' => 'Y',
  4452. 'created' => '2007-03-18 10:49:23',
  4453. 'updated' => '2007-03-18 10:51:31'
  4454. ),
  4455. array(
  4456. 'id' => '4',
  4457. 'article_id' => '1',
  4458. 'user_id' => '1',
  4459. 'comment' => 'Fourth Comment for First Article',
  4460. 'published' => 'N',
  4461. 'created' => '2007-03-18 10:51:23',
  4462. 'updated' => '2007-03-18 10:53:31'
  4463. ),
  4464. array(
  4465. 'id' => '5',
  4466. 'article_id' => '2',
  4467. 'user_id' => '1',
  4468. 'comment' => 'First Comment for Second Article',
  4469. 'published' => 'Y',
  4470. 'created' => '2007-03-18 10:53:23',
  4471. 'updated' => '2007-03-18 10:55:31'
  4472. ))),
  4473. array(
  4474. 'User' => array(
  4475. 'id' => '2',
  4476. 'user' => 'nate'
  4477. ),
  4478. 'Items' => array(
  4479. array(
  4480. 'id' => '1',
  4481. 'article_id' => '1',
  4482. 'user_id' => '2',
  4483. 'comment' => 'First Comment for First Article',
  4484. 'published' => 'Y',
  4485. 'created' => '2007-03-18 10:45:23',
  4486. 'updated' => '2007-03-18 10:47:31'
  4487. ),
  4488. array(
  4489. 'id' => '6',
  4490. 'article_id' => '2',
  4491. 'user_id' => '2',
  4492. 'comment' => 'Second Comment for Second Article',
  4493. 'published' => 'Y',
  4494. 'created' => '2007-03-18 10:55:23',
  4495. 'updated' => '2007-03-18 10:57:31'
  4496. ))),
  4497. array(
  4498. 'User' => array(
  4499. 'id' => '3',
  4500. 'user' => 'larry'
  4501. ),
  4502. 'Items' => array()
  4503. ),
  4504. array(
  4505. 'User' => array(
  4506. 'id' => '4', 'user' => 'garrett'),
  4507. 'Items' => array(
  4508. array(
  4509. 'id' => '2',
  4510. 'article_id' => '1',
  4511. 'user_id' => '4',
  4512. 'comment' => 'Second Comment for First Article',
  4513. 'published' => 'Y',
  4514. 'created' => '2007-03-18 10:47:23',
  4515. 'updated' => '2007-03-18 10:49:31'
  4516. ))));
  4517. $this->assertEqual($result, $expected);
  4518. $result = $TestModel->bindModel(array(
  4519. 'hasMany' => array(
  4520. 'Items' => array('className' => 'Article')
  4521. )));
  4522. $this->assertTrue($result);
  4523. $result = $TestModel->find('all', array(
  4524. 'fields' => 'User.id, User.user'
  4525. ));
  4526. $expected = array(
  4527. array(
  4528. 'User' => array(
  4529. 'id' => '1',
  4530. 'user' => 'mariano'
  4531. ),
  4532. 'Items' => array(
  4533. array(
  4534. 'id' => 1,
  4535. 'user_id' => 1,
  4536. 'title' => 'First Article',
  4537. 'body' => 'First Article Body',
  4538. 'published' => 'Y',
  4539. 'created' => '2007-03-18 10:39:23',
  4540. 'updated' => '2007-03-18 10:41:31'
  4541. ),
  4542. array(
  4543. 'id' => 3,
  4544. 'user_id' => 1,
  4545. 'title' => 'Third Article',
  4546. 'body' => 'Third Article Body',
  4547. 'published' => 'Y',
  4548. 'created' => '2007-03-18 10:43:23',
  4549. 'updated' => '2007-03-18 10:45:31'
  4550. ))),
  4551. array(
  4552. 'User' => array(
  4553. 'id' => '2',
  4554. 'user' => 'nate'
  4555. ),
  4556. 'Items' => array()
  4557. ),
  4558. array(
  4559. 'User' => array(
  4560. 'id' => '3',
  4561. 'user' => 'larry'
  4562. ),
  4563. 'Items' => array(
  4564. array(
  4565. 'id' => 2,
  4566. 'user_id' => 3,
  4567. 'title' => 'Second Article',
  4568. 'body' => 'Second Article Body',
  4569. 'published' => 'Y',
  4570. 'created' => '2007-03-18 10:41:23',
  4571. 'updated' => '2007-03-18 10:43:31'
  4572. ))),
  4573. array(
  4574. 'User' => array(
  4575. 'id' => '4',
  4576. 'user' => 'garrett'
  4577. ),
  4578. 'Items' => array()
  4579. ));
  4580. $this->assertEqual($result, $expected);
  4581. }
  4582. /**
  4583. * test that multiple reset = true calls to bindModel() result in the original associations.
  4584. *
  4585. * @return void
  4586. */
  4587. function testBindModelMultipleTimesResetCorrectly() {
  4588. $this->loadFixtures('User', 'Comment', 'Article');
  4589. $TestModel =& new User();
  4590. $TestModel->bindModel(array('hasMany' => array('Comment')));
  4591. $TestModel->bindModel(array('hasMany' => array('Comment')));
  4592. $TestModel->resetAssociations();
  4593. $this->assertFalse(isset($TestModel->hasMany['Comment']), 'Association left behind');
  4594. }
  4595. /**
  4596. * testBindMultipleTimes method with different reset settings
  4597. *
  4598. * @access public
  4599. * @return void
  4600. */
  4601. function testBindMultipleTimesWithDifferentResetSettings() {
  4602. $this->loadFixtures('User', 'Comment', 'Article');
  4603. $TestModel =& new User();
  4604. $result = $TestModel->hasMany;
  4605. $expected = array();
  4606. $this->assertEqual($result, $expected);
  4607. $result = $TestModel->bindModel(array(
  4608. 'hasMany' => array('Comment')
  4609. ));
  4610. $this->assertTrue($result);
  4611. $result = $TestModel->bindModel(
  4612. array('hasMany' => array('Article')),
  4613. false
  4614. );
  4615. $this->assertTrue($result);
  4616. $result = array_keys($TestModel->hasMany);
  4617. $expected = array('Comment', 'Article');
  4618. $this->assertEqual($result, $expected);
  4619. $TestModel->resetAssociations();
  4620. $result = array_keys($TestModel->hasMany);
  4621. $expected = array('Article');
  4622. $this->assertEqual($result, $expected);
  4623. }
  4624. /**
  4625. * test that bindModel behaves with Custom primary Key associations
  4626. *
  4627. * @return void
  4628. */
  4629. function bindWithCustomPrimaryKey() {
  4630. $this->loadFixtures('Story', 'StoriesTag', 'Tag');
  4631. $Model =& ClassRegistry::init('StoriesTag');
  4632. $Model->bindModel(array(
  4633. 'belongsTo' => array(
  4634. 'Tag' => array(
  4635. 'className' => 'Tag',
  4636. 'foreignKey' => 'story'
  4637. ))));
  4638. $result = $Model->find('all');
  4639. $this->assertFalse(empty($result));
  4640. }
  4641. /**
  4642. * test that calling unbindModel() with reset == true multiple times
  4643. * leaves associations in the correct state.
  4644. *
  4645. * @return void
  4646. */
  4647. function testUnbindMultipleTimesResetCorrectly() {
  4648. $this->loadFixtures('User', 'Comment', 'Article');
  4649. $TestModel =& new Article10();
  4650. $TestModel->unbindModel(array('hasMany' => array('Comment')));
  4651. $TestModel->unbindModel(array('hasMany' => array('Comment')));
  4652. $TestModel->resetAssociations();
  4653. $this->assertTrue(isset($TestModel->hasMany['Comment']), 'Association permanently removed');
  4654. }
  4655. /**
  4656. * testBindMultipleTimes method with different reset settings
  4657. *
  4658. * @access public
  4659. * @return void
  4660. */
  4661. function testUnBindMultipleTimesWithDifferentResetSettings() {
  4662. $this->loadFixtures('User', 'Comment', 'Article');
  4663. $TestModel =& new Comment();
  4664. $result = array_keys($TestModel->belongsTo);
  4665. $expected = array('Article', 'User');
  4666. $this->assertEqual($result, $expected);
  4667. $result = $TestModel->unbindModel(array(
  4668. 'belongsTo' => array('User')
  4669. ));
  4670. $this->assertTrue($result);
  4671. $result = $TestModel->unbindModel(
  4672. array('belongsTo' => array('Article')),
  4673. false
  4674. );
  4675. $this->assertTrue($result);
  4676. $result = array_keys($TestModel->belongsTo);
  4677. $expected = array();
  4678. $this->assertEqual($result, $expected);
  4679. $TestModel->resetAssociations();
  4680. $result = array_keys($TestModel->belongsTo);
  4681. $expected = array('User');
  4682. $this->assertEqual($result, $expected);
  4683. }
  4684. /**
  4685. * testAssociationAfterFind method
  4686. *
  4687. * @access public
  4688. * @return void
  4689. */
  4690. function testAssociationAfterFind() {
  4691. $this->loadFixtures('Post', 'Author', 'Comment');
  4692. $TestModel =& new Post();
  4693. $result = $TestModel->find('all');
  4694. $expected = array(
  4695. array(
  4696. 'Post' => array(
  4697. 'id' => '1',
  4698. 'author_id' => '1',
  4699. 'title' => 'First Post',
  4700. 'body' => 'First Post Body',
  4701. 'published' => 'Y',
  4702. 'created' => '2007-03-18 10:39:23',
  4703. 'updated' => '2007-03-18 10:41:31'
  4704. ),
  4705. 'Author' => array(
  4706. 'id' => '1',
  4707. 'user' => 'mariano',
  4708. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  4709. 'created' => '2007-03-17 01:16:23',
  4710. 'updated' => '2007-03-17 01:18:31',
  4711. 'test' => 'working'
  4712. )),
  4713. array(
  4714. 'Post' => array(
  4715. 'id' => '2',
  4716. 'author_id' => '3',
  4717. 'title' => 'Second Post',
  4718. 'body' => 'Second Post Body',
  4719. 'published' => 'Y',
  4720. 'created' => '2007-03-18 10:41:23',
  4721. 'updated' => '2007-03-18 10:43:31'
  4722. ),
  4723. 'Author' => array(
  4724. 'id' => '3',
  4725. 'user' => 'larry',
  4726. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  4727. 'created' => '2007-03-17 01:20:23',
  4728. 'updated' => '2007-03-17 01:22:31',
  4729. 'test' => 'working'
  4730. )),
  4731. array(
  4732. 'Post' => array(
  4733. 'id' => '3',
  4734. 'author_id' => '1',
  4735. 'title' => 'Third Post',
  4736. 'body' => 'Third Post Body',
  4737. 'published' => 'Y',
  4738. 'created' => '2007-03-18 10:43:23',
  4739. 'updated' => '2007-03-18 10:45:31'
  4740. ),
  4741. 'Author' => array(
  4742. 'id' => '1',
  4743. 'user' => 'mariano',
  4744. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  4745. 'created' => '2007-03-17 01:16:23',
  4746. 'updated' => '2007-03-17 01:18:31',
  4747. 'test' => 'working'
  4748. )));
  4749. $this->assertEqual($result, $expected);
  4750. unset($TestModel);
  4751. $Author =& new Author();
  4752. $Author->Post->bindModel(array(
  4753. 'hasMany' => array(
  4754. 'Comment' => array(
  4755. 'className' => 'ModifiedComment',
  4756. 'foreignKey' => 'article_id',
  4757. )
  4758. )));
  4759. $result = $Author->find('all', array(
  4760. 'conditions' => array('Author.id' => 1),
  4761. 'recursive' => 2
  4762. ));
  4763. $expected = array(
  4764. 'id' => 1,
  4765. 'article_id' => 1,
  4766. 'user_id' => 2,
  4767. 'comment' => 'First Comment for First Article',
  4768. 'published' => 'Y',
  4769. 'created' => '2007-03-18 10:45:23',
  4770. 'updated' => '2007-03-18 10:47:31',
  4771. 'callback' => 'Fire'
  4772. );
  4773. $this->assertEqual($result[0]['Post'][0]['Comment'][0], $expected);
  4774. }
  4775. /**
  4776. * Tests that callbacks can be properly disabled
  4777. *
  4778. * @access public
  4779. * @return void
  4780. */
  4781. function testCallbackDisabling() {
  4782. $this->loadFixtures('Author');
  4783. $TestModel = new ModifiedAuthor();
  4784. $result = Set::extract($TestModel->find('all'), '/Author/user');
  4785. $expected = array('mariano (CakePHP)', 'nate (CakePHP)', 'larry (CakePHP)', 'garrett (CakePHP)');
  4786. $this->assertEqual($result, $expected);
  4787. $result = Set::extract($TestModel->find('all', array('callbacks' => 'after')), '/Author/user');
  4788. $expected = array('mariano (CakePHP)', 'nate (CakePHP)', 'larry (CakePHP)', 'garrett (CakePHP)');
  4789. $this->assertEqual($result, $expected);
  4790. $result = Set::extract($TestModel->find('all', array('callbacks' => 'before')), '/Author/user');
  4791. $expected = array('mariano', 'nate', 'larry', 'garrett');
  4792. $this->assertEqual($result, $expected);
  4793. $result = Set::extract($TestModel->find('all', array('callbacks' => false)), '/Author/user');
  4794. $expected = array('mariano', 'nate', 'larry', 'garrett');
  4795. $this->assertEqual($result, $expected);
  4796. }
  4797. /**
  4798. * Tests that the database configuration assigned to the model can be changed using
  4799. * (before|after)Find callbacks
  4800. *
  4801. * @access public
  4802. * @return void
  4803. */
  4804. function testCallbackSourceChange() {
  4805. $this->loadFixtures('Post');
  4806. $TestModel = new Post();
  4807. $this->assertEqual(3, count($TestModel->find('all')));
  4808. $this->expectError(new PatternExpectation('/Non-existent data source foo/i'));
  4809. $this->assertFalse($TestModel->find('all', array('connection' => 'foo')));
  4810. }
  4811. /**
  4812. * testMultipleBelongsToWithSameClass method
  4813. *
  4814. * @access public
  4815. * @return void
  4816. */
  4817. function testMultipleBelongsToWithSameClass() {
  4818. $this->loadFixtures(
  4819. 'DeviceType',
  4820. 'DeviceTypeCategory',
  4821. 'FeatureSet',
  4822. 'ExteriorTypeCategory',
  4823. 'Document',
  4824. 'Device',
  4825. 'DocumentDirectory'
  4826. );
  4827. $DeviceType =& new DeviceType();
  4828. $DeviceType->recursive = 2;
  4829. $result = $DeviceType->read(null, 1);
  4830. $expected = array(
  4831. 'DeviceType' => array(
  4832. 'id' => 1,
  4833. 'device_type_category_id' => 1,
  4834. 'feature_set_id' => 1,
  4835. 'exterior_type_category_id' => 1,
  4836. 'image_id' => 1,
  4837. 'extra1_id' => 1,
  4838. 'extra2_id' => 1,
  4839. 'name' => 'DeviceType 1',
  4840. 'order' => 0
  4841. ),
  4842. 'Image' => array(
  4843. 'id' => 1,
  4844. 'document_directory_id' => 1,
  4845. 'name' => 'Document 1',
  4846. 'DocumentDirectory' => array(
  4847. 'id' => 1,
  4848. 'name' => 'DocumentDirectory 1'
  4849. )),
  4850. 'Extra1' => array(
  4851. 'id' => 1,
  4852. 'document_directory_id' => 1,
  4853. 'name' => 'Document 1',
  4854. 'DocumentDirectory' => array(
  4855. 'id' => 1,
  4856. 'name' => 'DocumentDirectory 1'
  4857. )),
  4858. 'Extra2' => array(
  4859. 'id' => 1,
  4860. 'document_directory_id' => 1,
  4861. 'name' => 'Document 1',
  4862. 'DocumentDirectory' => array(
  4863. 'id' => 1,
  4864. 'name' => 'DocumentDirectory 1'
  4865. )),
  4866. 'DeviceTypeCategory' => array(
  4867. 'id' => 1,
  4868. 'name' => 'DeviceTypeCategory 1'
  4869. ),
  4870. 'FeatureSet' => array(
  4871. 'id' => 1,
  4872. 'name' => 'FeatureSet 1'
  4873. ),
  4874. 'ExteriorTypeCategory' => array(
  4875. 'id' => 1,
  4876. 'image_id' => 1,
  4877. 'name' => 'ExteriorTypeCategory 1',
  4878. 'Image' => array(
  4879. 'id' => 1,
  4880. 'device_type_id' => 1,
  4881. 'name' => 'Device 1',
  4882. 'typ' => 1
  4883. )),
  4884. 'Device' => array(
  4885. array(
  4886. 'id' => 1,
  4887. 'device_type_id' => 1,
  4888. 'name' => 'Device 1',
  4889. 'typ' => 1
  4890. ),
  4891. array(
  4892. 'id' => 2,
  4893. 'device_type_id' => 1,
  4894. 'name' => 'Device 2',
  4895. 'typ' => 1
  4896. ),
  4897. array(
  4898. 'id' => 3,
  4899. 'device_type_id' => 1,
  4900. 'name' => 'Device 3',
  4901. 'typ' => 2
  4902. )));
  4903. $this->assertEqual($result, $expected);
  4904. }
  4905. /**
  4906. * testHabtmRecursiveBelongsTo method
  4907. *
  4908. * @access public
  4909. * @return void
  4910. */
  4911. function testHabtmRecursiveBelongsTo() {
  4912. $this->loadFixtures('Portfolio', 'Item', 'ItemsPortfolio', 'Syfile', 'Image');
  4913. $Portfolio =& new Portfolio();
  4914. $result = $Portfolio->find(array('id' => 2), null, null, 3);
  4915. $expected = array(
  4916. 'Portfolio' => array(
  4917. 'id' => 2,
  4918. 'seller_id' => 1,
  4919. 'name' => 'Portfolio 2'
  4920. ),
  4921. 'Item' => array(
  4922. array(
  4923. 'id' => 2,
  4924. 'syfile_id' => 2,
  4925. 'published' => 0,
  4926. 'name' => 'Item 2',
  4927. 'ItemsPortfolio' => array(
  4928. 'id' => 2,
  4929. 'item_id' => 2,
  4930. 'portfolio_id' => 2
  4931. ),
  4932. 'Syfile' => array(
  4933. 'id' => 2,
  4934. 'image_id' => 2,
  4935. 'name' => 'Syfile 2',
  4936. 'item_count' => null,
  4937. 'Image' => array(
  4938. 'id' => 2,
  4939. 'name' => 'Image 2'
  4940. )
  4941. )),
  4942. array(
  4943. 'id' => 6,
  4944. 'syfile_id' => 6,
  4945. 'published' => 0,
  4946. 'name' => 'Item 6',
  4947. 'ItemsPortfolio' => array(
  4948. 'id' => 6,
  4949. 'item_id' => 6,
  4950. 'portfolio_id' => 2
  4951. ),
  4952. 'Syfile' => array(
  4953. 'id' => 6,
  4954. 'image_id' => null,
  4955. 'name' => 'Syfile 6',
  4956. 'item_count' => null,
  4957. 'Image' => array()
  4958. ))));
  4959. $this->assertEqual($result, $expected);
  4960. }
  4961. /**
  4962. * testHabtmFinderQuery method
  4963. *
  4964. * @access public
  4965. * @return void
  4966. */
  4967. function testHabtmFinderQuery() {
  4968. $this->loadFixtures('Article', 'Tag', 'ArticlesTag');
  4969. $Article =& new Article();
  4970. $sql = $this->db->buildStatement(
  4971. array(
  4972. 'fields' => $this->db->fields($Article->Tag, null, array(
  4973. 'Tag.id', 'Tag.tag', 'ArticlesTag.article_id', 'ArticlesTag.tag_id'
  4974. )),
  4975. 'table' => $this->db->fullTableName('tags'),
  4976. 'alias' => 'Tag',
  4977. 'limit' => null,
  4978. 'offset' => null,
  4979. 'group' => null,
  4980. 'joins' => array(array(
  4981. 'alias' => 'ArticlesTag',
  4982. 'table' => $this->db->fullTableName('articles_tags'),
  4983. 'conditions' => array(
  4984. array("ArticlesTag.article_id" => '{$__cakeID__$}'),
  4985. array("ArticlesTag.tag_id" => $this->db->identifier('Tag.id'))
  4986. )
  4987. )),
  4988. 'conditions' => array(),
  4989. 'order' => null
  4990. ),
  4991. $Article
  4992. );
  4993. $Article->hasAndBelongsToMany['Tag']['finderQuery'] = $sql;
  4994. $result = $Article->find('first');
  4995. $expected = array(
  4996. array(
  4997. 'id' => '1',
  4998. 'tag' => 'tag1'
  4999. ),
  5000. array(
  5001. 'id' => '2',
  5002. 'tag' => 'tag2'
  5003. ));
  5004. $this->assertEqual($result['Tag'], $expected);
  5005. }
  5006. /**
  5007. * testHabtmLimitOptimization method
  5008. *
  5009. * @access public
  5010. * @return void
  5011. */
  5012. function testHabtmLimitOptimization() {
  5013. $this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'ArticlesTag');
  5014. $TestModel =& new Article();
  5015. $TestModel->hasAndBelongsToMany['Tag']['limit'] = 2;
  5016. $result = $TestModel->read(null, 2);
  5017. $expected = array(
  5018. 'Article' => array(
  5019. 'id' => '2',
  5020. 'user_id' => '3',
  5021. 'title' => 'Second Article',
  5022. 'body' => 'Second Article Body',
  5023. 'published' => 'Y',
  5024. 'created' => '2007-03-18 10:41:23',
  5025. 'updated' => '2007-03-18 10:43:31'
  5026. ),
  5027. 'User' => array(
  5028. 'id' => '3',
  5029. 'user' => 'larry',
  5030. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5031. 'created' => '2007-03-17 01:20:23',
  5032. 'updated' => '2007-03-17 01:22:31'
  5033. ),
  5034. 'Comment' => array(
  5035. array(
  5036. 'id' => '5',
  5037. 'article_id' => '2',
  5038. 'user_id' => '1',
  5039. 'comment' => 'First Comment for Second Article',
  5040. 'published' => 'Y',
  5041. 'created' => '2007-03-18 10:53:23',
  5042. 'updated' => '2007-03-18 10:55:31'
  5043. ),
  5044. array(
  5045. 'id' => '6',
  5046. 'article_id' => '2',
  5047. 'user_id' => '2',
  5048. 'comment' => 'Second Comment for Second Article',
  5049. 'published' => 'Y',
  5050. 'created' => '2007-03-18 10:55:23',
  5051. 'updated' => '2007-03-18 10:57:31'
  5052. )),
  5053. 'Tag' => array(
  5054. array(
  5055. 'id' => '1',
  5056. 'tag' => 'tag1',
  5057. 'created' => '2007-03-18 12:22:23',
  5058. 'updated' => '2007-03-18 12:24:31'
  5059. ),
  5060. array(
  5061. 'id' => '3',
  5062. 'tag' => 'tag3',
  5063. 'created' => '2007-03-18 12:26:23',
  5064. 'updated' => '2007-03-18 12:28:31'
  5065. )));
  5066. $this->assertEqual($result, $expected);
  5067. $TestModel->hasAndBelongsToMany['Tag']['limit'] = 1;
  5068. $result = $TestModel->read(null, 2);
  5069. unset($expected['Tag'][1]);
  5070. $this->assertEqual($result, $expected);
  5071. }
  5072. /**
  5073. * testHasManyLimitOptimization method
  5074. *
  5075. * @access public
  5076. * @return void
  5077. */
  5078. function testHasManyLimitOptimization() {
  5079. $this->loadFixtures('Project', 'Thread', 'Message', 'Bid');
  5080. $Project =& new Project();
  5081. $Project->recursive = 3;
  5082. $result = $Project->find('all');
  5083. $expected = array(
  5084. array(
  5085. 'Project' => array(
  5086. 'id' => 1,
  5087. 'name' => 'Project 1'
  5088. ),
  5089. 'Thread' => array(
  5090. array(
  5091. 'id' => 1,
  5092. 'project_id' => 1,
  5093. 'name' => 'Project 1, Thread 1',
  5094. 'Project' => array(
  5095. 'id' => 1,
  5096. 'name' => 'Project 1',
  5097. 'Thread' => array(
  5098. array(
  5099. 'id' => 1,
  5100. 'project_id' => 1,
  5101. 'name' => 'Project 1, Thread 1'
  5102. ),
  5103. array(
  5104. 'id' => 2,
  5105. 'project_id' => 1,
  5106. 'name' => 'Project 1, Thread 2'
  5107. ))),
  5108. 'Message' => array(
  5109. array(
  5110. 'id' => 1,
  5111. 'thread_id' => 1,
  5112. 'name' => 'Thread 1, Message 1',
  5113. 'Bid' => array(
  5114. 'id' => 1,
  5115. 'message_id' => 1,
  5116. 'name' => 'Bid 1.1'
  5117. )))),
  5118. array(
  5119. 'id' => 2,
  5120. 'project_id' => 1,
  5121. 'name' => 'Project 1, Thread 2',
  5122. 'Project' => array(
  5123. 'id' => 1,
  5124. 'name' => 'Project 1',
  5125. 'Thread' => array(
  5126. array(
  5127. 'id' => 1,
  5128. 'project_id' => 1,
  5129. 'name' => 'Project 1, Thread 1'
  5130. ),
  5131. array(
  5132. 'id' => 2,
  5133. 'project_id' => 1,
  5134. 'name' => 'Project 1, Thread 2'
  5135. ))),
  5136. 'Message' => array(
  5137. array(
  5138. 'id' => 2,
  5139. 'thread_id' => 2,
  5140. 'name' => 'Thread 2, Message 1',
  5141. 'Bid' => array(
  5142. 'id' => 4,
  5143. 'message_id' => 2,
  5144. 'name' => 'Bid 2.1'
  5145. )))))),
  5146. array(
  5147. 'Project' => array(
  5148. 'id' => 2,
  5149. 'name' => 'Project 2'
  5150. ),
  5151. 'Thread' => array(
  5152. array(
  5153. 'id' => 3,
  5154. 'project_id' => 2,
  5155. 'name' => 'Project 2, Thread 1',
  5156. 'Project' => array(
  5157. 'id' => 2,
  5158. 'name' => 'Project 2',
  5159. 'Thread' => array(
  5160. array(
  5161. 'id' => 3,
  5162. 'project_id' => 2,
  5163. 'name' => 'Project 2, Thread 1'
  5164. ))),
  5165. 'Message' => array(
  5166. array(
  5167. 'id' => 3,
  5168. 'thread_id' => 3,
  5169. 'name' => 'Thread 3, Message 1',
  5170. 'Bid' => array(
  5171. 'id' => 3,
  5172. 'message_id' => 3,
  5173. 'name' => 'Bid 3.1'
  5174. )))))),
  5175. array(
  5176. 'Project' => array(
  5177. 'id' => 3,
  5178. 'name' => 'Project 3'
  5179. ),
  5180. 'Thread' => array()
  5181. ));
  5182. $this->assertEqual($result, $expected);
  5183. }
  5184. /**
  5185. * testFindAllRecursiveSelfJoin method
  5186. *
  5187. * @access public
  5188. * @return void
  5189. */
  5190. function testFindAllRecursiveSelfJoin() {
  5191. $this->loadFixtures('Home', 'AnotherArticle', 'Advertisement');
  5192. $TestModel =& new Home();
  5193. $TestModel->recursive = 2;
  5194. $result = $TestModel->find('all');
  5195. $expected = array(
  5196. array(
  5197. 'Home' => array(
  5198. 'id' => '1',
  5199. 'another_article_id' => '1',
  5200. 'advertisement_id' => '1',
  5201. 'title' => 'First Home',
  5202. 'created' => '2007-03-18 10:39:23',
  5203. 'updated' => '2007-03-18 10:41:31'
  5204. ),
  5205. 'AnotherArticle' => array(
  5206. 'id' => '1',
  5207. 'title' => 'First Article',
  5208. 'created' => '2007-03-18 10:39:23',
  5209. 'updated' => '2007-03-18 10:41:31',
  5210. 'Home' => array(
  5211. array(
  5212. 'id' => '1',
  5213. 'another_article_id' => '1',
  5214. 'advertisement_id' => '1',
  5215. 'title' => 'First Home',
  5216. 'created' => '2007-03-18 10:39:23',
  5217. 'updated' => '2007-03-18 10:41:31'
  5218. ))),
  5219. 'Advertisement' => array(
  5220. 'id' => '1',
  5221. 'title' => 'First Ad',
  5222. 'created' => '2007-03-18 10:39:23',
  5223. 'updated' => '2007-03-18 10:41:31',
  5224. 'Home' => array(
  5225. array(
  5226. 'id' => '1',
  5227. 'another_article_id' => '1',
  5228. 'advertisement_id' => '1',
  5229. 'title' => 'First Home',
  5230. 'created' => '2007-03-18 10:39:23',
  5231. 'updated' => '2007-03-18 10:41:31'
  5232. ),
  5233. array(
  5234. 'id' => '2',
  5235. 'another_article_id' => '3',
  5236. 'advertisement_id' => '1',
  5237. 'title' => 'Second Home',
  5238. 'created' => '2007-03-18 10:41:23',
  5239. 'updated' => '2007-03-18 10:43:31'
  5240. )))),
  5241. array(
  5242. 'Home' => array(
  5243. 'id' => '2',
  5244. 'another_article_id' => '3',
  5245. 'advertisement_id' => '1',
  5246. 'title' => 'Second Home',
  5247. 'created' => '2007-03-18 10:41:23',
  5248. 'updated' => '2007-03-18 10:43:31'
  5249. ),
  5250. 'AnotherArticle' => array(
  5251. 'id' => '3',
  5252. 'title' => 'Third Article',
  5253. 'created' => '2007-03-18 10:43:23',
  5254. 'updated' => '2007-03-18 10:45:31',
  5255. 'Home' => array(
  5256. array(
  5257. 'id' => '2',
  5258. 'another_article_id' => '3',
  5259. 'advertisement_id' => '1',
  5260. 'title' => 'Second Home',
  5261. 'created' => '2007-03-18 10:41:23',
  5262. 'updated' => '2007-03-18 10:43:31'
  5263. ))),
  5264. 'Advertisement' => array(
  5265. 'id' => '1',
  5266. 'title' => 'First Ad',
  5267. 'created' => '2007-03-18 10:39:23',
  5268. 'updated' => '2007-03-18 10:41:31',
  5269. 'Home' => array(
  5270. array(
  5271. 'id' => '1',
  5272. 'another_article_id' => '1',
  5273. 'advertisement_id' => '1',
  5274. 'title' => 'First Home',
  5275. 'created' => '2007-03-18 10:39:23',
  5276. 'updated' => '2007-03-18 10:41:31'
  5277. ),
  5278. array(
  5279. 'id' => '2',
  5280. 'another_article_id' => '3',
  5281. 'advertisement_id' => '1',
  5282. 'title' => 'Second Home',
  5283. 'created' => '2007-03-18 10:41:23',
  5284. 'updated' => '2007-03-18 10:43:31'
  5285. )))));
  5286. $this->assertEqual($result, $expected);
  5287. }
  5288. /**
  5289. * testFindAllRecursiveWithHabtm method
  5290. *
  5291. * @return void
  5292. * @access public
  5293. */
  5294. function testFindAllRecursiveWithHabtm() {
  5295. $this->loadFixtures(
  5296. 'MyCategoriesMyUsers',
  5297. 'MyCategoriesMyProducts',
  5298. 'MyCategory',
  5299. 'MyUser',
  5300. 'MyProduct'
  5301. );
  5302. $MyUser =& new MyUser();
  5303. $MyUser->recursive = 2;
  5304. $result = $MyUser->find('all');
  5305. $expected = array(
  5306. array(
  5307. 'MyUser' => array('id' => '1', 'firstname' => 'userA'),
  5308. 'MyCategory' => array(
  5309. array(
  5310. 'id' => '1',
  5311. 'name' => 'A',
  5312. 'MyProduct' => array(
  5313. array(
  5314. 'id' => '1',
  5315. 'name' => 'book'
  5316. ))),
  5317. array(
  5318. 'id' => '3',
  5319. 'name' => 'C',
  5320. 'MyProduct' => array(
  5321. array(
  5322. 'id' => '2',
  5323. 'name' => 'computer'
  5324. ))))),
  5325. array(
  5326. 'MyUser' => array(
  5327. 'id' => '2',
  5328. 'firstname' => 'userB'
  5329. ),
  5330. 'MyCategory' => array(
  5331. array(
  5332. 'id' => '1',
  5333. 'name' => 'A',
  5334. 'MyProduct' => array(
  5335. array(
  5336. 'id' => '1',
  5337. 'name' => 'book'
  5338. ))),
  5339. array(
  5340. 'id' => '2',
  5341. 'name' => 'B',
  5342. 'MyProduct' => array(
  5343. array(
  5344. 'id' => '1',
  5345. 'name' => 'book'
  5346. ),
  5347. array(
  5348. 'id' => '2',
  5349. 'name' => 'computer'
  5350. ))))));
  5351. $this->assertIdentical($result, $expected);
  5352. }
  5353. /**
  5354. * testReadFakeThread method
  5355. *
  5356. * @access public
  5357. * @return void
  5358. */
  5359. function testReadFakeThread() {
  5360. $this->loadFixtures('CategoryThread');
  5361. $TestModel =& new CategoryThread();
  5362. $fullDebug = $this->db->fullDebug;
  5363. $this->db->fullDebug = true;
  5364. $TestModel->recursive = 6;
  5365. $TestModel->id = 7;
  5366. $result = $TestModel->read();
  5367. $expected = array(
  5368. 'CategoryThread' => array(
  5369. 'id' => 7,
  5370. 'parent_id' => 6,
  5371. 'name' => 'Category 2.1',
  5372. 'created' => '2007-03-18 15:30:23',
  5373. 'updated' => '2007-03-18 15:32:31'
  5374. ),
  5375. 'ParentCategory' => array(
  5376. 'id' => 6,
  5377. 'parent_id' => 5,
  5378. 'name' => 'Category 2',
  5379. 'created' => '2007-03-18 15:30:23',
  5380. 'updated' => '2007-03-18 15:32:31',
  5381. 'ParentCategory' => array(
  5382. 'id' => 5,
  5383. 'parent_id' => 4,
  5384. 'name' => 'Category 1.1.1.1',
  5385. 'created' => '2007-03-18 15:30:23',
  5386. 'updated' => '2007-03-18 15:32:31',
  5387. 'ParentCategory' => array(
  5388. 'id' => 4,
  5389. 'parent_id' => 3,
  5390. 'name' => 'Category 1.1.2',
  5391. 'created' => '2007-03-18 15:30:23',
  5392. 'updated' => '2007-03-18 15:32:31',
  5393. 'ParentCategory' => array(
  5394. 'id' => 3,
  5395. 'parent_id' => 2,
  5396. 'name' => 'Category 1.1.1',
  5397. 'created' => '2007-03-18 15:30:23',
  5398. 'updated' => '2007-03-18 15:32:31',
  5399. 'ParentCategory' => array(
  5400. 'id' => 2,
  5401. 'parent_id' => 1,
  5402. 'name' => 'Category 1.1',
  5403. 'created' => '2007-03-18 15:30:23',
  5404. 'updated' => '2007-03-18 15:32:31',
  5405. 'ParentCategory' => array(
  5406. 'id' => 1,
  5407. 'parent_id' => 0,
  5408. 'name' => 'Category 1',
  5409. 'created' => '2007-03-18 15:30:23',
  5410. 'updated' => '2007-03-18 15:32:31'
  5411. )))))));
  5412. $this->db->fullDebug = $fullDebug;
  5413. $this->assertEqual($result, $expected);
  5414. }
  5415. /**
  5416. * testFindFakeThread method
  5417. *
  5418. * @access public
  5419. * @return void
  5420. */
  5421. function testFindFakeThread() {
  5422. $this->loadFixtures('CategoryThread');
  5423. $TestModel =& new CategoryThread();
  5424. $fullDebug = $this->db->fullDebug;
  5425. $this->db->fullDebug = true;
  5426. $TestModel->recursive = 6;
  5427. $result = $TestModel->find(array('CategoryThread.id' => 7));
  5428. $expected = array(
  5429. 'CategoryThread' => array(
  5430. 'id' => 7,
  5431. 'parent_id' => 6,
  5432. 'name' => 'Category 2.1',
  5433. 'created' => '2007-03-18 15:30:23',
  5434. 'updated' => '2007-03-18 15:32:31'
  5435. ),
  5436. 'ParentCategory' => array(
  5437. 'id' => 6,
  5438. 'parent_id' => 5,
  5439. 'name' => 'Category 2',
  5440. 'created' => '2007-03-18 15:30:23',
  5441. 'updated' => '2007-03-18 15:32:31',
  5442. 'ParentCategory' => array(
  5443. 'id' => 5,
  5444. 'parent_id' => 4,
  5445. 'name' => 'Category 1.1.1.1',
  5446. 'created' => '2007-03-18 15:30:23',
  5447. 'updated' => '2007-03-18 15:32:31',
  5448. 'ParentCategory' => array(
  5449. 'id' => 4,
  5450. 'parent_id' => 3,
  5451. 'name' => 'Category 1.1.2',
  5452. 'created' => '2007-03-18 15:30:23',
  5453. 'updated' => '2007-03-18 15:32:31',
  5454. 'ParentCategory' => array(
  5455. 'id' => 3,
  5456. 'parent_id' => 2,
  5457. 'name' => 'Category 1.1.1',
  5458. 'created' => '2007-03-18 15:30:23',
  5459. 'updated' => '2007-03-18 15:32:31',
  5460. 'ParentCategory' => array(
  5461. 'id' => 2,
  5462. 'parent_id' => 1,
  5463. 'name' => 'Category 1.1',
  5464. 'created' => '2007-03-18 15:30:23',
  5465. 'updated' => '2007-03-18 15:32:31',
  5466. 'ParentCategory' => array(
  5467. 'id' => 1,
  5468. 'parent_id' => 0,
  5469. 'name' => 'Category 1',
  5470. 'created' => '2007-03-18 15:30:23',
  5471. 'updated' => '2007-03-18 15:32:31'
  5472. )))))));
  5473. $this->db->fullDebug = $fullDebug;
  5474. $this->assertEqual($result, $expected);
  5475. }
  5476. /**
  5477. * testFindAllFakeThread method
  5478. *
  5479. * @access public
  5480. * @return void
  5481. */
  5482. function testFindAllFakeThread() {
  5483. $this->loadFixtures('CategoryThread');
  5484. $TestModel =& new CategoryThread();
  5485. $fullDebug = $this->db->fullDebug;
  5486. $this->db->fullDebug = true;
  5487. $TestModel->recursive = 6;
  5488. $result = $TestModel->find('all', null, null, 'CategoryThread.id ASC');
  5489. $expected = array(
  5490. array(
  5491. 'CategoryThread' => array(
  5492. 'id' => 1,
  5493. 'parent_id' => 0,
  5494. 'name' => 'Category 1',
  5495. 'created' => '2007-03-18 15:30:23',
  5496. 'updated' => '2007-03-18 15:32:31'
  5497. ),
  5498. 'ParentCategory' => array(
  5499. 'id' => null,
  5500. 'parent_id' => null,
  5501. 'name' => null,
  5502. 'created' => null,
  5503. 'updated' => null,
  5504. 'ParentCategory' => array()
  5505. )),
  5506. array(
  5507. 'CategoryThread' => array(
  5508. 'id' => 2,
  5509. 'parent_id' => 1,
  5510. 'name' => 'Category 1.1',
  5511. 'created' => '2007-03-18 15:30:23',
  5512. 'updated' => '2007-03-18 15:32:31'
  5513. ),
  5514. 'ParentCategory' => array(
  5515. 'id' => 1,
  5516. 'parent_id' => 0,
  5517. 'name' => 'Category 1',
  5518. 'created' => '2007-03-18 15:30:23',
  5519. 'updated' => '2007-03-18 15:32:31',
  5520. 'ParentCategory' => array()
  5521. )),
  5522. array(
  5523. 'CategoryThread' => array(
  5524. 'id' => 3,
  5525. 'parent_id' => 2,
  5526. 'name' => 'Category 1.1.1',
  5527. 'created' => '2007-03-18 15:30:23',
  5528. 'updated' => '2007-03-18 15:32:31'
  5529. ),
  5530. 'ParentCategory' => array(
  5531. 'id' => 2,
  5532. 'parent_id' => 1,
  5533. 'name' => 'Category 1.1',
  5534. 'created' => '2007-03-18 15:30:23',
  5535. 'updated' => '2007-03-18 15:32:31',
  5536. 'ParentCategory' => array(
  5537. 'id' => 1,
  5538. 'parent_id' => 0,
  5539. 'name' => 'Category 1',
  5540. 'created' => '2007-03-18 15:30:23',
  5541. 'updated' => '2007-03-18 15:32:31',
  5542. 'ParentCategory' => array()
  5543. ))),
  5544. array(
  5545. 'CategoryThread' => array(
  5546. 'id' => 4,
  5547. 'parent_id' => 3,
  5548. 'name' => 'Category 1.1.2',
  5549. 'created' => '2007-03-18 15:30:23',
  5550. 'updated' => '2007-03-18 15:32:31'
  5551. ),
  5552. 'ParentCategory' => array(
  5553. 'id' => 3,
  5554. 'parent_id' => 2,
  5555. 'name' => 'Category 1.1.1',
  5556. 'created' => '2007-03-18 15:30:23',
  5557. 'updated' => '2007-03-18 15:32:31',
  5558. 'ParentCategory' => array(
  5559. 'id' => 2,
  5560. 'parent_id' => 1,
  5561. 'name' => 'Category 1.1',
  5562. 'created' => '2007-03-18 15:30:23',
  5563. 'updated' => '2007-03-18 15:32:31',
  5564. 'ParentCategory' => array(
  5565. 'id' => 1,
  5566. 'parent_id' => 0,
  5567. 'name' => 'Category 1',
  5568. 'created' => '2007-03-18 15:30:23',
  5569. 'updated' => '2007-03-18 15:32:31',
  5570. 'ParentCategory' => array()
  5571. )))),
  5572. array(
  5573. 'CategoryThread' => array(
  5574. 'id' => 5,
  5575. 'parent_id' => 4,
  5576. 'name' => 'Category 1.1.1.1',
  5577. 'created' => '2007-03-18 15:30:23',
  5578. 'updated' => '2007-03-18 15:32:31'
  5579. ),
  5580. 'ParentCategory' => array(
  5581. 'id' => 4,
  5582. 'parent_id' => 3,
  5583. 'name' => 'Category 1.1.2',
  5584. 'created' => '2007-03-18 15:30:23',
  5585. 'updated' => '2007-03-18 15:32:31',
  5586. 'ParentCategory' => array(
  5587. 'id' => 3,
  5588. 'parent_id' => 2,
  5589. 'name' => 'Category 1.1.1',
  5590. 'created' => '2007-03-18 15:30:23',
  5591. 'updated' => '2007-03-18 15:32:31',
  5592. 'ParentCategory' => array(
  5593. 'id' => 2,
  5594. 'parent_id' => 1,
  5595. 'name' => 'Category 1.1',
  5596. 'created' => '2007-03-18 15:30:23',
  5597. 'updated' => '2007-03-18 15:32:31',
  5598. 'ParentCategory' => array(
  5599. 'id' => 1,
  5600. 'parent_id' => 0,
  5601. 'name' => 'Category 1',
  5602. 'created' => '2007-03-18 15:30:23',
  5603. 'updated' => '2007-03-18 15:32:31',
  5604. 'ParentCategory' => array()
  5605. ))))),
  5606. array(
  5607. 'CategoryThread' => array(
  5608. 'id' => 6,
  5609. 'parent_id' => 5,
  5610. 'name' => 'Category 2',
  5611. 'created' => '2007-03-18 15:30:23',
  5612. 'updated' => '2007-03-18 15:32:31'
  5613. ),
  5614. 'ParentCategory' => array(
  5615. 'id' => 5,
  5616. 'parent_id' => 4,
  5617. 'name' => 'Category 1.1.1.1',
  5618. 'created' => '2007-03-18 15:30:23',
  5619. 'updated' => '2007-03-18 15:32:31',
  5620. 'ParentCategory' => array(
  5621. 'id' => 4,
  5622. 'parent_id' => 3,
  5623. 'name' => 'Category 1.1.2',
  5624. 'created' => '2007-03-18 15:30:23',
  5625. 'updated' => '2007-03-18 15:32:31',
  5626. 'ParentCategory' => array(
  5627. 'id' => 3,
  5628. 'parent_id' => 2,
  5629. 'name' => 'Category 1.1.1',
  5630. 'created' => '2007-03-18 15:30:23',
  5631. 'updated' => '2007-03-18 15:32:31',
  5632. 'ParentCategory' => array(
  5633. 'id' => 2,
  5634. 'parent_id' => 1,
  5635. 'name' => 'Category 1.1',
  5636. 'created' => '2007-03-18 15:30:23',
  5637. 'updated' => '2007-03-18 15:32:31',
  5638. 'ParentCategory' => array(
  5639. 'id' => 1,
  5640. 'parent_id' => 0,
  5641. 'name' => 'Category 1',
  5642. 'created' => '2007-03-18 15:30:23',
  5643. 'updated' => '2007-03-18 15:32:31',
  5644. 'ParentCategory' => array()
  5645. )))))),
  5646. array(
  5647. 'CategoryThread' => array(
  5648. 'id' => 7,
  5649. 'parent_id' => 6,
  5650. 'name' => 'Category 2.1',
  5651. 'created' => '2007-03-18 15:30:23',
  5652. 'updated' => '2007-03-18 15:32:31'
  5653. ),
  5654. 'ParentCategory' => array(
  5655. 'id' => 6,
  5656. 'parent_id' => 5,
  5657. 'name' => 'Category 2',
  5658. 'created' => '2007-03-18 15:30:23',
  5659. 'updated' => '2007-03-18 15:32:31',
  5660. 'ParentCategory' => array(
  5661. 'id' => 5,
  5662. 'parent_id' => 4,
  5663. 'name' => 'Category 1.1.1.1',
  5664. 'created' => '2007-03-18 15:30:23',
  5665. 'updated' => '2007-03-18 15:32:31',
  5666. 'ParentCategory' => array(
  5667. 'id' => 4,
  5668. 'parent_id' => 3,
  5669. 'name' => 'Category 1.1.2',
  5670. 'created' => '2007-03-18 15:30:23',
  5671. 'updated' => '2007-03-18 15:32:31',
  5672. 'ParentCategory' => array(
  5673. 'id' => 3,
  5674. 'parent_id' => 2,
  5675. 'name' => 'Category 1.1.1',
  5676. 'created' => '2007-03-18 15:30:23',
  5677. 'updated' => '2007-03-18 15:32:31',
  5678. 'ParentCategory' => array(
  5679. 'id' => 2,
  5680. 'parent_id' => 1,
  5681. 'name' => 'Category 1.1',
  5682. 'created' => '2007-03-18 15:30:23',
  5683. 'updated' => '2007-03-18 15:32:31',
  5684. 'ParentCategory' => array(
  5685. 'id' => 1,
  5686. 'parent_id' => 0,
  5687. 'name' => 'Category 1',
  5688. 'created' => '2007-03-18 15:30:23',
  5689. 'updated' => '2007-03-18 15:32:31'
  5690. ))))))));
  5691. $this->db->fullDebug = $fullDebug;
  5692. $this->assertEqual($result, $expected);
  5693. }
  5694. /**
  5695. * testConditionalNumerics method
  5696. *
  5697. * @access public
  5698. * @return void
  5699. */
  5700. function testConditionalNumerics() {
  5701. $this->loadFixtures('NumericArticle');
  5702. $NumericArticle =& new NumericArticle();
  5703. $data = array('title' => '12345abcde');
  5704. $result = $NumericArticle->find($data);
  5705. $this->assertTrue(!empty($result));
  5706. $data = array('title' => '12345');
  5707. $result = $NumericArticle->find($data);
  5708. $this->assertTrue(empty($result));
  5709. }
  5710. /**
  5711. * test find('all') method
  5712. *
  5713. * @access public
  5714. * @return void
  5715. */
  5716. function testFindAll() {
  5717. $this->loadFixtures('User');
  5718. $TestModel =& new User();
  5719. $TestModel->cacheQueries = false;
  5720. $result = $TestModel->find('all');
  5721. $expected = array(
  5722. array(
  5723. 'User' => array(
  5724. 'id' => '1',
  5725. 'user' => 'mariano',
  5726. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5727. 'created' => '2007-03-17 01:16:23',
  5728. 'updated' => '2007-03-17 01:18:31'
  5729. )),
  5730. array(
  5731. 'User' => array(
  5732. 'id' => '2',
  5733. 'user' => 'nate',
  5734. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5735. 'created' => '2007-03-17 01:18:23',
  5736. 'updated' => '2007-03-17 01:20:31'
  5737. )),
  5738. array(
  5739. 'User' => array(
  5740. 'id' => '3',
  5741. 'user' => 'larry',
  5742. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5743. 'created' => '2007-03-17 01:20:23',
  5744. 'updated' => '2007-03-17 01:22:31'
  5745. )),
  5746. array(
  5747. 'User' => array(
  5748. 'id' => '4',
  5749. 'user' => 'garrett',
  5750. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5751. 'created' => '2007-03-17 01:22:23',
  5752. 'updated' => '2007-03-17 01:24:31'
  5753. )));
  5754. $this->assertEqual($result, $expected);
  5755. $result = $TestModel->find('all', array('conditions' => 'User.id > 2'));
  5756. $expected = array(
  5757. array(
  5758. 'User' => array(
  5759. 'id' => '3',
  5760. 'user' => 'larry',
  5761. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5762. 'created' => '2007-03-17 01:20:23',
  5763. 'updated' => '2007-03-17 01:22:31'
  5764. )),
  5765. array(
  5766. 'User' => array(
  5767. 'id' => '4',
  5768. 'user' => 'garrett',
  5769. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5770. 'created' => '2007-03-17 01:22:23',
  5771. 'updated' => '2007-03-17 01:24:31'
  5772. )));
  5773. $this->assertEqual($result, $expected);
  5774. $result = $TestModel->find('all', array(
  5775. 'conditions' => array('User.id !=' => '0', 'User.user LIKE' => '%arr%')
  5776. ));
  5777. $expected = array(
  5778. array(
  5779. 'User' => array(
  5780. 'id' => '3',
  5781. 'user' => 'larry',
  5782. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5783. 'created' => '2007-03-17 01:20:23',
  5784. 'updated' => '2007-03-17 01:22:31'
  5785. )),
  5786. array(
  5787. 'User' => array(
  5788. 'id' => '4',
  5789. 'user' => 'garrett',
  5790. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5791. 'created' => '2007-03-17 01:22:23',
  5792. 'updated' => '2007-03-17 01:24:31'
  5793. )));
  5794. $this->assertEqual($result, $expected);
  5795. $result = $TestModel->find('all', array('conditions' => array('User.id' => '0')));
  5796. $expected = array();
  5797. $this->assertEqual($result, $expected);
  5798. $result = $TestModel->find('all', array(
  5799. 'conditions' => array('or' => array('User.id' => '0', 'User.user LIKE' => '%a%')
  5800. )));
  5801. $expected = array(
  5802. array(
  5803. 'User' => array(
  5804. 'id' => '1',
  5805. 'user' => 'mariano',
  5806. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5807. 'created' => '2007-03-17 01:16:23',
  5808. 'updated' => '2007-03-17 01:18:31'
  5809. )),
  5810. array(
  5811. 'User' => array(
  5812. 'id' => '2',
  5813. 'user' => 'nate',
  5814. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5815. 'created' => '2007-03-17 01:18:23',
  5816. 'updated' => '2007-03-17 01:20:31'
  5817. )),
  5818. array(
  5819. 'User' => array(
  5820. 'id' => '3',
  5821. 'user' => 'larry',
  5822. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5823. 'created' => '2007-03-17 01:20:23',
  5824. 'updated' => '2007-03-17 01:22:31'
  5825. )),
  5826. array(
  5827. 'User' => array(
  5828. 'id' => '4',
  5829. 'user' => 'garrett',
  5830. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5831. 'created' => '2007-03-17 01:22:23',
  5832. 'updated' => '2007-03-17 01:24:31'
  5833. )));
  5834. $this->assertEqual($result, $expected);
  5835. $result = $TestModel->find('all', array('fields' => 'User.id, User.user'));
  5836. $expected = array(
  5837. array('User' => array('id' => '1', 'user' => 'mariano')),
  5838. array('User' => array('id' => '2', 'user' => 'nate')),
  5839. array('User' => array('id' => '3', 'user' => 'larry')),
  5840. array('User' => array('id' => '4', 'user' => 'garrett')));
  5841. $this->assertEqual($result, $expected);
  5842. $result = $TestModel->find('all', array('fields' => 'User.user', 'order' => 'User.user ASC'));
  5843. $expected = array(
  5844. array('User' => array('user' => 'garrett')),
  5845. array('User' => array('user' => 'larry')),
  5846. array('User' => array('user' => 'mariano')),
  5847. array('User' => array('user' => 'nate')));
  5848. $this->assertEqual($result, $expected);
  5849. $result = $TestModel->find('all', array('fields' => 'User.user', 'order' => 'User.user DESC'));
  5850. $expected = array(
  5851. array('User' => array('user' => 'nate')),
  5852. array('User' => array('user' => 'mariano')),
  5853. array('User' => array('user' => 'larry')),
  5854. array('User' => array('user' => 'garrett')));
  5855. $this->assertEqual($result, $expected);
  5856. $result = $TestModel->find('all', array('limit' => 3, 'page' => 1));
  5857. $expected = array(
  5858. array(
  5859. 'User' => array(
  5860. 'id' => '1',
  5861. 'user' => 'mariano',
  5862. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5863. 'created' => '2007-03-17 01:16:23',
  5864. 'updated' => '2007-03-17 01:18:31'
  5865. )),
  5866. array(
  5867. 'User' => array(
  5868. 'id' => '2',
  5869. 'user' => 'nate',
  5870. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5871. 'created' => '2007-03-17 01:18:23',
  5872. 'updated' => '2007-03-17 01:20:31'
  5873. )),
  5874. array(
  5875. 'User' => array(
  5876. 'id' => '3',
  5877. 'user' => 'larry',
  5878. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5879. 'created' => '2007-03-17 01:20:23',
  5880. 'updated' => '2007-03-17 01:22:31'
  5881. )));
  5882. $this->assertEqual($result, $expected);
  5883. $ids = array(4 => 1, 5 => 3);
  5884. $result = $TestModel->find('all', array(
  5885. 'conditions' => array('User.id' => $ids),
  5886. 'order' => 'User.id'
  5887. ));
  5888. $expected = array(
  5889. array(
  5890. 'User' => array(
  5891. 'id' => '1',
  5892. 'user' => 'mariano',
  5893. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5894. 'created' => '2007-03-17 01:16:23',
  5895. 'updated' => '2007-03-17 01:18:31'
  5896. )),
  5897. array(
  5898. 'User' => array(
  5899. 'id' => '3',
  5900. 'user' => 'larry',
  5901. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5902. 'created' => '2007-03-17 01:20:23',
  5903. 'updated' => '2007-03-17 01:22:31'
  5904. )));
  5905. $this->assertEqual($result, $expected);
  5906. // These tests are expected to fail on SQL Server since the LIMIT/OFFSET
  5907. // hack can't handle small record counts.
  5908. if ($this->db->config['driver'] != 'mssql') {
  5909. $result = $TestModel->find('all', array('limit' => 3, 'page' => 2));
  5910. $expected = array(
  5911. array(
  5912. 'User' => array(
  5913. 'id' => '4',
  5914. 'user' => 'garrett',
  5915. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  5916. 'created' => '2007-03-17 01:22:23',
  5917. 'updated' => '2007-03-17 01:24:31'
  5918. )));
  5919. $this->assertEqual($result, $expected);
  5920. $result = $TestModel->find('all', array('limit' => 3, 'page' => 3));
  5921. $expected = array();
  5922. $this->assertEqual($result, $expected);
  5923. }
  5924. }
  5925. /**
  5926. * test find('list') method
  5927. *
  5928. * @access public
  5929. * @return void
  5930. */
  5931. function testGenerateFindList() {
  5932. $this->loadFixtures('Article', 'Apple', 'Post', 'Author', 'User');
  5933. $TestModel =& new Article();
  5934. $TestModel->displayField = 'title';
  5935. $result = $TestModel->find('list', array(
  5936. 'order' => 'Article.title ASC'
  5937. ));
  5938. $expected = array(
  5939. 1 => 'First Article',
  5940. 2 => 'Second Article',
  5941. 3 => 'Third Article'
  5942. );
  5943. $this->assertEqual($result, $expected);
  5944. $db =& ConnectionManager::getDataSource('test_suite');
  5945. if ($db->config['driver'] == 'mysql') {
  5946. $result = $TestModel->find('list', array(
  5947. 'order' => array('FIELD(Article.id, 3, 2) ASC', 'Article.title ASC')
  5948. ));
  5949. $expected = array(
  5950. 1 => 'First Article',
  5951. 3 => 'Third Article',
  5952. 2 => 'Second Article'
  5953. );
  5954. $this->assertEqual($result, $expected);
  5955. }
  5956. $result = Set::combine(
  5957. $TestModel->find('all', array(
  5958. 'order' => 'Article.title ASC',
  5959. 'fields' => array('id', 'title')
  5960. )),
  5961. '{n}.Article.id', '{n}.Article.title'
  5962. );
  5963. $expected = array(
  5964. 1 => 'First Article',
  5965. 2 => 'Second Article',
  5966. 3 => 'Third Article'
  5967. );
  5968. $this->assertEqual($result, $expected);
  5969. $result = Set::combine(
  5970. $TestModel->find('all', array(
  5971. 'order' => 'Article.title ASC'
  5972. )),
  5973. '{n}.Article.id', '{n}.Article'
  5974. );
  5975. $expected = array(
  5976. 1 => array(
  5977. 'id' => 1,
  5978. 'user_id' => 1,
  5979. 'title' => 'First Article',
  5980. 'body' => 'First Article Body',
  5981. 'published' => 'Y',
  5982. 'created' => '2007-03-18 10:39:23',
  5983. 'updated' => '2007-03-18 10:41:31'
  5984. ),
  5985. 2 => array(
  5986. 'id' => 2,
  5987. 'user_id' => 3,
  5988. 'title' => 'Second Article',
  5989. 'body' => 'Second Article Body',
  5990. 'published' => 'Y',
  5991. 'created' => '2007-03-18 10:41:23',
  5992. 'updated' => '2007-03-18 10:43:31'
  5993. ),
  5994. 3 => array(
  5995. 'id' => 3,
  5996. 'user_id' => 1,
  5997. 'title' => 'Third Article',
  5998. 'body' => 'Third Article Body',
  5999. 'published' => 'Y',
  6000. 'created' => '2007-03-18 10:43:23',
  6001. 'updated' => '2007-03-18 10:45:31'
  6002. ));
  6003. $this->assertEqual($result, $expected);
  6004. $result = Set::combine(
  6005. $TestModel->find('all', array(
  6006. 'order' => 'Article.title ASC'
  6007. )),
  6008. '{n}.Article.id', '{n}.Article', '{n}.Article.user_id'
  6009. );
  6010. $expected = array(
  6011. 1 => array(
  6012. 1 => array(
  6013. 'id' => 1,
  6014. 'user_id' => 1,
  6015. 'title' => 'First Article',
  6016. 'body' => 'First Article Body',
  6017. 'published' => 'Y',
  6018. 'created' => '2007-03-18 10:39:23',
  6019. 'updated' => '2007-03-18 10:41:31'
  6020. ),
  6021. 3 => array(
  6022. 'id' => 3,
  6023. 'user_id' => 1,
  6024. 'title' => 'Third Article',
  6025. 'body' => 'Third Article Body',
  6026. 'published' => 'Y',
  6027. 'created' => '2007-03-18 10:43:23',
  6028. 'updated' => '2007-03-18 10:45:31'
  6029. )),
  6030. 3 => array(
  6031. 2 => array(
  6032. 'id' => 2,
  6033. 'user_id' => 3,
  6034. 'title' => 'Second Article',
  6035. 'body' => 'Second Article Body',
  6036. 'published' => 'Y',
  6037. 'created' => '2007-03-18 10:41:23',
  6038. 'updated' => '2007-03-18 10:43:31'
  6039. )));
  6040. $this->assertEqual($result, $expected);
  6041. $result = Set::combine(
  6042. $TestModel->find('all', array(
  6043. 'order' => 'Article.title ASC',
  6044. 'fields' => array('id', 'title', 'user_id')
  6045. )),
  6046. '{n}.Article.id', '{n}.Article.title', '{n}.Article.user_id'
  6047. );
  6048. $expected = array(
  6049. 1 => array(
  6050. 1 => 'First Article',
  6051. 3 => 'Third Article'
  6052. ),
  6053. 3 => array(
  6054. 2 => 'Second Article'
  6055. ));
  6056. $this->assertEqual($result, $expected);
  6057. $TestModel =& new Apple();
  6058. $expected = array(
  6059. 1 => 'Red Apple 1',
  6060. 2 => 'Bright Red Apple',
  6061. 3 => 'green blue',
  6062. 4 => 'Test Name',
  6063. 5 => 'Blue Green',
  6064. 6 => 'My new apple',
  6065. 7 => 'Some odd color'
  6066. );
  6067. $this->assertEqual($TestModel->find('list'), $expected);
  6068. $this->assertEqual($TestModel->Parent->find('list'), $expected);
  6069. $TestModel =& new Post();
  6070. $result = $TestModel->find('list', array(
  6071. 'fields' => 'Post.title'
  6072. ));
  6073. $expected = array(
  6074. 1 => 'First Post',
  6075. 2 => 'Second Post',
  6076. 3 => 'Third Post'
  6077. );
  6078. $this->assertEqual($result, $expected);
  6079. $result = $TestModel->find('list', array(
  6080. 'fields' => 'title'
  6081. ));
  6082. $expected = array(
  6083. 1 => 'First Post',
  6084. 2 => 'Second Post',
  6085. 3 => 'Third Post'
  6086. );
  6087. $this->assertEqual($result, $expected);
  6088. $result = $TestModel->find('list', array(
  6089. 'fields' => array('title', 'id')
  6090. ));
  6091. $expected = array(
  6092. 'First Post' => '1',
  6093. 'Second Post' => '2',
  6094. 'Third Post' => '3'
  6095. );
  6096. $this->assertEqual($result, $expected);
  6097. $result = $TestModel->find('list', array(
  6098. 'fields' => array('title', 'id', 'created')
  6099. ));
  6100. $expected = array(
  6101. '2007-03-18 10:39:23' => array(
  6102. 'First Post' => '1'
  6103. ),
  6104. '2007-03-18 10:41:23' => array(
  6105. 'Second Post' => '2'
  6106. ),
  6107. '2007-03-18 10:43:23' => array(
  6108. 'Third Post' => '3'
  6109. ),
  6110. );
  6111. $this->assertEqual($result, $expected);
  6112. $result = $TestModel->find('list', array(
  6113. 'fields' => array('Post.body')
  6114. ));
  6115. $expected = array(
  6116. 1 => 'First Post Body',
  6117. 2 => 'Second Post Body',
  6118. 3 => 'Third Post Body'
  6119. );
  6120. $this->assertEqual($result, $expected);
  6121. $result = $TestModel->find('list', array(
  6122. 'fields' => array('Post.title', 'Post.body')
  6123. ));
  6124. $expected = array(
  6125. 'First Post' => 'First Post Body',
  6126. 'Second Post' => 'Second Post Body',
  6127. 'Third Post' => 'Third Post Body'
  6128. );
  6129. $this->assertEqual($result, $expected);
  6130. $result = $TestModel->find('list', array(
  6131. 'fields' => array('Post.id', 'Post.title', 'Author.user'),
  6132. 'recursive' => 1
  6133. ));
  6134. $expected = array(
  6135. 'mariano' => array(
  6136. 1 => 'First Post',
  6137. 3 => 'Third Post'
  6138. ),
  6139. 'larry' => array(
  6140. 2 => 'Second Post'
  6141. ));
  6142. $this->assertEqual($result, $expected);
  6143. $TestModel =& new User();
  6144. $result = $TestModel->find('list', array(
  6145. 'fields' => array('User.user', 'User.password')
  6146. ));
  6147. $expected = array(
  6148. 'mariano' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6149. 'nate' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6150. 'larry' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6151. 'garrett' => '5f4dcc3b5aa765d61d8327deb882cf99'
  6152. );
  6153. $this->assertEqual($result, $expected);
  6154. $TestModel =& new ModifiedAuthor();
  6155. $result = $TestModel->find('list', array(
  6156. 'fields' => array('Author.id', 'Author.user')
  6157. ));
  6158. $expected = array(
  6159. 1 => 'mariano (CakePHP)',
  6160. 2 => 'nate (CakePHP)',
  6161. 3 => 'larry (CakePHP)',
  6162. 4 => 'garrett (CakePHP)'
  6163. );
  6164. $this->assertEqual($result, $expected);
  6165. $TestModel =& new Article();
  6166. $TestModel->displayField = 'title';
  6167. $result = $TestModel->find('list', array(
  6168. 'conditions' => array('User.user' => 'mariano'),
  6169. 'recursive' => 0
  6170. ));
  6171. $expected = array(
  6172. 1 => 'First Article',
  6173. 3 => 'Third Article'
  6174. );
  6175. $this->assertEqual($result, $expected);
  6176. }
  6177. /**
  6178. * testFindField method
  6179. *
  6180. * @access public
  6181. * @return void
  6182. */
  6183. function testFindField() {
  6184. $this->loadFixtures('User');
  6185. $TestModel =& new User();
  6186. $TestModel->id = 1;
  6187. $result = $TestModel->field('user');
  6188. $this->assertEqual($result, 'mariano');
  6189. $result = $TestModel->field('User.user');
  6190. $this->assertEqual($result, 'mariano');
  6191. $TestModel->id = false;
  6192. $result = $TestModel->field('user', array(
  6193. 'user' => 'mariano'
  6194. ));
  6195. $this->assertEqual($result, 'mariano');
  6196. $result = $TestModel->field('COUNT(*) AS count', true);
  6197. $this->assertEqual($result, 4);
  6198. $result = $TestModel->field('COUNT(*)', true);
  6199. $this->assertEqual($result, 4);
  6200. }
  6201. /**
  6202. * testFindUnique method
  6203. *
  6204. * @access public
  6205. * @return void
  6206. */
  6207. function testFindUnique() {
  6208. $this->loadFixtures('User');
  6209. $TestModel =& new User();
  6210. $this->assertFalse($TestModel->isUnique(array(
  6211. 'user' => 'nate'
  6212. )));
  6213. $TestModel->id = 2;
  6214. $this->assertTrue($TestModel->isUnique(array(
  6215. 'user' => 'nate'
  6216. )));
  6217. $this->assertFalse($TestModel->isUnique(array(
  6218. 'user' => 'nate',
  6219. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99'
  6220. )));
  6221. }
  6222. /**
  6223. * test find('count') method
  6224. *
  6225. * @access public
  6226. * @return void
  6227. */
  6228. function testFindCount() {
  6229. $this->loadFixtures('User', 'Project');
  6230. $TestModel =& new User();
  6231. $result = $TestModel->find('count');
  6232. $this->assertEqual($result, 4);
  6233. $fullDebug = $this->db->fullDebug;
  6234. $this->db->fullDebug = true;
  6235. $TestModel->order = 'User.id';
  6236. $this->db->_queriesLog = array();
  6237. $result = $TestModel->find('count');
  6238. $this->assertEqual($result, 4);
  6239. $this->assertTrue(isset($this->db->_queriesLog[0]['query']));
  6240. $this->assertNoPattern('/ORDER\s+BY/', $this->db->_queriesLog[0]['query']);
  6241. }
  6242. /**
  6243. * Test that find('first') does not use the id set to the object.
  6244. *
  6245. * @return void
  6246. */
  6247. function testFindFirstNoIdUsed() {
  6248. $this->loadFixtures('Project');
  6249. $Project =& new Project();
  6250. $Project->id = 3;
  6251. $result = $Project->find('first');
  6252. $this->assertEqual($result['Project']['name'], 'Project 1', 'Wrong record retrieved');
  6253. }
  6254. /**
  6255. * test find with COUNT(DISTINCT field)
  6256. *
  6257. * @return void
  6258. */
  6259. function testFindCountDistinct() {
  6260. $skip = $this->skipIf(
  6261. $this->db->config['driver'] == 'sqlite',
  6262. 'SELECT COUNT(DISTINCT field) is not compatible with SQLite'
  6263. );
  6264. if ($skip) {
  6265. return;
  6266. }
  6267. $this->loadFixtures('Project');
  6268. $TestModel =& new Project();
  6269. $TestModel->create(array('name' => 'project')) && $TestModel->save();
  6270. $TestModel->create(array('name' => 'project')) && $TestModel->save();
  6271. $TestModel->create(array('name' => 'project')) && $TestModel->save();
  6272. $result = $TestModel->find('count', array('fields' => 'DISTINCT name'));
  6273. $this->assertEqual($result, 4);
  6274. }
  6275. /**
  6276. * Test find(count) with Db::expression
  6277. *
  6278. * @access public
  6279. * @return void
  6280. */
  6281. function testFindCountWithDbExpressions() {
  6282. if ($this->skipIf($this->db->config['driver'] == 'postgres', '%s testFindCountWithExpressions is not compatible with Postgres')) {
  6283. return;
  6284. }
  6285. $this->loadFixtures('Project');
  6286. $db = ConnectionManager::getDataSource('test_suite');
  6287. $TestModel =& new Project();
  6288. $result = $TestModel->find('count', array('conditions' => array(
  6289. $db->expression('Project.name = \'Project 3\'')
  6290. )));
  6291. $this->assertEqual($result, 1);
  6292. $result = $TestModel->find('count', array('conditions' => array(
  6293. 'Project.name' => $db->expression('\'Project 3\'')
  6294. )));
  6295. $this->assertEqual($result, 1);
  6296. }
  6297. /**
  6298. * testFindMagic method
  6299. *
  6300. * @access public
  6301. * @return void
  6302. */
  6303. function testFindMagic() {
  6304. $this->loadFixtures('User');
  6305. $TestModel =& new User();
  6306. $result = $TestModel->findByUser('mariano');
  6307. $expected = array(
  6308. 'User' => array(
  6309. 'id' => '1',
  6310. 'user' => 'mariano',
  6311. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6312. 'created' => '2007-03-17 01:16:23',
  6313. 'updated' => '2007-03-17 01:18:31'
  6314. ));
  6315. $this->assertEqual($result, $expected);
  6316. $result = $TestModel->findByPassword('5f4dcc3b5aa765d61d8327deb882cf99');
  6317. $expected = array('User' => array(
  6318. 'id' => '1',
  6319. 'user' => 'mariano',
  6320. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6321. 'created' => '2007-03-17 01:16:23',
  6322. 'updated' => '2007-03-17 01:18:31'
  6323. ));
  6324. $this->assertEqual($result, $expected);
  6325. }
  6326. /**
  6327. * testRead method
  6328. *
  6329. * @access public
  6330. * @return void
  6331. */
  6332. function testRead() {
  6333. $this->loadFixtures('User', 'Article');
  6334. $TestModel =& new User();
  6335. $result = $TestModel->read();
  6336. $this->assertFalse($result);
  6337. $TestModel->id = 2;
  6338. $result = $TestModel->read();
  6339. $expected = array(
  6340. 'User' => array(
  6341. 'id' => '2',
  6342. 'user' => 'nate',
  6343. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6344. 'created' => '2007-03-17 01:18:23',
  6345. 'updated' => '2007-03-17 01:20:31'
  6346. ));
  6347. $this->assertEqual($result, $expected);
  6348. $result = $TestModel->read(null, 2);
  6349. $expected = array(
  6350. 'User' => array(
  6351. 'id' => '2',
  6352. 'user' => 'nate',
  6353. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6354. 'created' => '2007-03-17 01:18:23',
  6355. 'updated' => '2007-03-17 01:20:31'
  6356. ));
  6357. $this->assertEqual($result, $expected);
  6358. $TestModel->id = 2;
  6359. $result = $TestModel->read(array('id', 'user'));
  6360. $expected = array('User' => array('id' => '2', 'user' => 'nate'));
  6361. $this->assertEqual($result, $expected);
  6362. $result = $TestModel->read('id, user', 2);
  6363. $expected = array(
  6364. 'User' => array(
  6365. 'id' => '2',
  6366. 'user' => 'nate'
  6367. ));
  6368. $this->assertEqual($result, $expected);
  6369. $result = $TestModel->bindModel(array('hasMany' => array('Article')));
  6370. $this->assertTrue($result);
  6371. $TestModel->id = 1;
  6372. $result = $TestModel->read('id, user');
  6373. $expected = array(
  6374. 'User' => array(
  6375. 'id' => '1',
  6376. 'user' => 'mariano'
  6377. ),
  6378. 'Article' => array(
  6379. array(
  6380. 'id' => '1',
  6381. 'user_id' => '1',
  6382. 'title' => 'First Article',
  6383. 'body' => 'First Article Body',
  6384. 'published' => 'Y',
  6385. 'created' => '2007-03-18 10:39:23',
  6386. 'updated' => '2007-03-18 10:41:31'
  6387. ),
  6388. array(
  6389. 'id' => '3',
  6390. 'user_id' => '1',
  6391. 'title' => 'Third Article',
  6392. 'body' => 'Third Article Body',
  6393. 'published' => 'Y',
  6394. 'created' => '2007-03-18 10:43:23',
  6395. 'updated' => '2007-03-18 10:45:31'
  6396. )));
  6397. $this->assertEqual($result, $expected);
  6398. }
  6399. /**
  6400. * testRecursiveRead method
  6401. *
  6402. * @access public
  6403. * @return void
  6404. */
  6405. function testRecursiveRead() {
  6406. $this->loadFixtures(
  6407. 'User',
  6408. 'Article',
  6409. 'Comment',
  6410. 'Tag',
  6411. 'ArticlesTag',
  6412. 'Featured',
  6413. 'ArticleFeatured'
  6414. );
  6415. $TestModel =& new User();
  6416. $result = $TestModel->bindModel(array('hasMany' => array('Article')), false);
  6417. $this->assertTrue($result);
  6418. $TestModel->recursive = 0;
  6419. $result = $TestModel->read('id, user', 1);
  6420. $expected = array(
  6421. 'User' => array('id' => '1', 'user' => 'mariano'),
  6422. );
  6423. $this->assertEqual($result, $expected);
  6424. $TestModel->recursive = 1;
  6425. $result = $TestModel->read('id, user', 1);
  6426. $expected = array(
  6427. 'User' => array(
  6428. 'id' => '1',
  6429. 'user' => 'mariano'
  6430. ),
  6431. 'Article' => array(
  6432. array(
  6433. 'id' => '1',
  6434. 'user_id' => '1',
  6435. 'title' => 'First Article',
  6436. 'body' => 'First Article Body',
  6437. 'published' => 'Y',
  6438. 'created' => '2007-03-18 10:39:23',
  6439. 'updated' => '2007-03-18 10:41:31'
  6440. ),
  6441. array(
  6442. 'id' => '3',
  6443. 'user_id' => '1',
  6444. 'title' => 'Third Article',
  6445. 'body' => 'Third Article Body',
  6446. 'published' => 'Y',
  6447. 'created' => '2007-03-18 10:43:23',
  6448. 'updated' => '2007-03-18 10:45:31'
  6449. )));
  6450. $this->assertEqual($result, $expected);
  6451. $TestModel->recursive = 2;
  6452. $result = $TestModel->read('id, user', 3);
  6453. $expected = array(
  6454. 'User' => array(
  6455. 'id' => '3',
  6456. 'user' => 'larry'
  6457. ),
  6458. 'Article' => array(
  6459. array(
  6460. 'id' => '2',
  6461. 'user_id' => '3',
  6462. 'title' => 'Second Article',
  6463. 'body' => 'Second Article Body',
  6464. 'published' => 'Y',
  6465. 'created' => '2007-03-18 10:41:23',
  6466. 'updated' => '2007-03-18 10:43:31',
  6467. 'User' => array(
  6468. 'id' => '3',
  6469. 'user' => 'larry',
  6470. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6471. 'created' => '2007-03-17 01:20:23',
  6472. 'updated' => '2007-03-17 01:22:31'
  6473. ),
  6474. 'Comment' => array(
  6475. array(
  6476. 'id' => '5',
  6477. 'article_id' => '2',
  6478. 'user_id' => '1',
  6479. 'comment' => 'First Comment for Second Article',
  6480. 'published' => 'Y',
  6481. 'created' => '2007-03-18 10:53:23',
  6482. 'updated' => '2007-03-18 10:55:31'
  6483. ),
  6484. array(
  6485. 'id' => '6',
  6486. 'article_id' => '2',
  6487. 'user_id' => '2',
  6488. 'comment' => 'Second Comment for Second Article',
  6489. 'published' => 'Y',
  6490. 'created' => '2007-03-18 10:55:23',
  6491. 'updated' => '2007-03-18 10:57:31'
  6492. )),
  6493. 'Tag' => array(
  6494. array(
  6495. 'id' => '1',
  6496. 'tag' => 'tag1',
  6497. 'created' => '2007-03-18 12:22:23',
  6498. 'updated' => '2007-03-18 12:24:31'
  6499. ),
  6500. array(
  6501. 'id' => '3',
  6502. 'tag' => 'tag3',
  6503. 'created' => '2007-03-18 12:26:23',
  6504. 'updated' => '2007-03-18 12:28:31'
  6505. )))));
  6506. $this->assertEqual($result, $expected);
  6507. }
  6508. function testRecursiveFindAll() {
  6509. $this->db->truncate(new Featured());
  6510. $this->loadFixtures(
  6511. 'User',
  6512. 'Article',
  6513. 'Comment',
  6514. 'Tag',
  6515. 'ArticlesTag',
  6516. 'Attachment',
  6517. 'ArticleFeatured',
  6518. 'Featured',
  6519. 'Category'
  6520. );
  6521. $TestModel =& new Article();
  6522. $result = $TestModel->find('all', array('conditions' => array('Article.user_id' => 1)));
  6523. $expected = array(
  6524. array(
  6525. 'Article' => array(
  6526. 'id' => '1',
  6527. 'user_id' => '1',
  6528. 'title' => 'First Article',
  6529. 'body' => 'First Article Body',
  6530. 'published' => 'Y',
  6531. 'created' => '2007-03-18 10:39:23',
  6532. 'updated' => '2007-03-18 10:41:31'
  6533. ),
  6534. 'User' => array(
  6535. 'id' => '1',
  6536. 'user' => 'mariano',
  6537. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6538. 'created' => '2007-03-17 01:16:23',
  6539. 'updated' => '2007-03-17 01:18:31'
  6540. ),
  6541. 'Comment' => array(
  6542. array(
  6543. 'id' => '1',
  6544. 'article_id' => '1',
  6545. 'user_id' => '2',
  6546. 'comment' => 'First Comment for First Article',
  6547. 'published' => 'Y',
  6548. 'created' => '2007-03-18 10:45:23',
  6549. 'updated' => '2007-03-18 10:47:31'
  6550. ),
  6551. array(
  6552. 'id' => '2',
  6553. 'article_id' => '1',
  6554. 'user_id' => '4',
  6555. 'comment' => 'Second Comment for First Article',
  6556. 'published' => 'Y',
  6557. 'created' => '2007-03-18 10:47:23',
  6558. 'updated' => '2007-03-18 10:49:31'
  6559. ),
  6560. array(
  6561. 'id' => '3',
  6562. 'article_id' => '1',
  6563. 'user_id' => '1',
  6564. 'comment' => 'Third Comment for First Article',
  6565. 'published' => 'Y',
  6566. 'created' => '2007-03-18 10:49:23',
  6567. 'updated' => '2007-03-18 10:51:31'
  6568. ),
  6569. array(
  6570. 'id' => '4',
  6571. 'article_id' => '1',
  6572. 'user_id' => '1',
  6573. 'comment' => 'Fourth Comment for First Article',
  6574. 'published' => 'N',
  6575. 'created' => '2007-03-18 10:51:23',
  6576. 'updated' => '2007-03-18 10:53:31'
  6577. )
  6578. ),
  6579. 'Tag' => array(
  6580. array(
  6581. 'id' => '1',
  6582. 'tag' => 'tag1',
  6583. 'created' => '2007-03-18 12:22:23',
  6584. 'updated' => '2007-03-18 12:24:31'
  6585. ),
  6586. array(
  6587. 'id' => '2',
  6588. 'tag' => 'tag2',
  6589. 'created' => '2007-03-18 12:24:23',
  6590. 'updated' => '2007-03-18 12:26:31'
  6591. ))),
  6592. array(
  6593. 'Article' => array(
  6594. 'id' => '3',
  6595. 'user_id' => '1',
  6596. 'title' => 'Third Article',
  6597. 'body' => 'Third Article Body',
  6598. 'published' => 'Y',
  6599. 'created' => '2007-03-18 10:43:23',
  6600. 'updated' => '2007-03-18 10:45:31'
  6601. ),
  6602. 'User' => array(
  6603. 'id' => '1',
  6604. 'user' => 'mariano',
  6605. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6606. 'created' => '2007-03-17 01:16:23',
  6607. 'updated' => '2007-03-17 01:18:31'
  6608. ),
  6609. 'Comment' => array(),
  6610. 'Tag' => array()
  6611. )
  6612. );
  6613. $this->assertEqual($result, $expected);
  6614. $result = $TestModel->find('all', array(
  6615. 'conditions' => array('Article.user_id' => 3),
  6616. 'limit' => 1,
  6617. 'recursive' => 2
  6618. ));
  6619. $expected = array(
  6620. array(
  6621. 'Article' => array(
  6622. 'id' => '2',
  6623. 'user_id' => '3',
  6624. 'title' => 'Second Article',
  6625. 'body' => 'Second Article Body',
  6626. 'published' => 'Y',
  6627. 'created' => '2007-03-18 10:41:23',
  6628. 'updated' => '2007-03-18 10:43:31'
  6629. ),
  6630. 'User' => array(
  6631. 'id' => '3',
  6632. 'user' => 'larry',
  6633. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6634. 'created' => '2007-03-17 01:20:23',
  6635. 'updated' => '2007-03-17 01:22:31'
  6636. ),
  6637. 'Comment' => array(
  6638. array(
  6639. 'id' => '5',
  6640. 'article_id' => '2',
  6641. 'user_id' => '1',
  6642. 'comment' => 'First Comment for Second Article',
  6643. 'published' => 'Y',
  6644. 'created' => '2007-03-18 10:53:23',
  6645. 'updated' => '2007-03-18 10:55:31',
  6646. 'Article' => array(
  6647. 'id' => '2',
  6648. 'user_id' => '3',
  6649. 'title' => 'Second Article',
  6650. 'body' => 'Second Article Body',
  6651. 'published' => 'Y',
  6652. 'created' => '2007-03-18 10:41:23',
  6653. 'updated' => '2007-03-18 10:43:31'
  6654. ),
  6655. 'User' => array(
  6656. 'id' => '1',
  6657. 'user' => 'mariano',
  6658. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6659. 'created' => '2007-03-17 01:16:23',
  6660. 'updated' => '2007-03-17 01:18:31'
  6661. ),
  6662. 'Attachment' => array(
  6663. 'id' => '1',
  6664. 'comment_id' => 5,
  6665. 'attachment' => 'attachment.zip',
  6666. 'created' => '2007-03-18 10:51:23',
  6667. 'updated' => '2007-03-18 10:53:31'
  6668. )
  6669. ),
  6670. array(
  6671. 'id' => '6',
  6672. 'article_id' => '2',
  6673. 'user_id' => '2',
  6674. 'comment' => 'Second Comment for Second Article',
  6675. 'published' => 'Y',
  6676. 'created' => '2007-03-18 10:55:23',
  6677. 'updated' => '2007-03-18 10:57:31',
  6678. 'Article' => array(
  6679. 'id' => '2',
  6680. 'user_id' => '3',
  6681. 'title' => 'Second Article',
  6682. 'body' => 'Second Article Body',
  6683. 'published' => 'Y',
  6684. 'created' => '2007-03-18 10:41:23',
  6685. 'updated' => '2007-03-18 10:43:31'
  6686. ),
  6687. 'User' => array(
  6688. 'id' => '2',
  6689. 'user' => 'nate',
  6690. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6691. 'created' => '2007-03-17 01:18:23',
  6692. 'updated' => '2007-03-17 01:20:31'
  6693. ),
  6694. 'Attachment' => false
  6695. )
  6696. ),
  6697. 'Tag' => array(
  6698. array(
  6699. 'id' => '1',
  6700. 'tag' => 'tag1',
  6701. 'created' => '2007-03-18 12:22:23',
  6702. 'updated' => '2007-03-18 12:24:31'
  6703. ),
  6704. array(
  6705. 'id' => '3',
  6706. 'tag' => 'tag3',
  6707. 'created' => '2007-03-18 12:26:23',
  6708. 'updated' => '2007-03-18 12:28:31'
  6709. ))));
  6710. $this->assertEqual($result, $expected);
  6711. $Featured = new Featured();
  6712. $Featured->recursive = 2;
  6713. $Featured->bindModel(array(
  6714. 'belongsTo' => array(
  6715. 'ArticleFeatured' => array(
  6716. 'conditions' => "ArticleFeatured.published = 'Y'",
  6717. 'fields' => 'id, title, user_id, published'
  6718. )
  6719. )
  6720. ));
  6721. $Featured->ArticleFeatured->unbindModel(array(
  6722. 'hasMany' => array('Attachment', 'Comment'),
  6723. 'hasAndBelongsToMany' => array('Tag'))
  6724. );
  6725. $orderBy = 'ArticleFeatured.id ASC';
  6726. $result = $Featured->find('all', array(
  6727. 'order' => $orderBy, 'limit' => 3
  6728. ));
  6729. $expected = array(
  6730. array(
  6731. 'Featured' => array(
  6732. 'id' => '1',
  6733. 'article_featured_id' => '1',
  6734. 'category_id' => '1',
  6735. 'published_date' => '2007-03-31 10:39:23',
  6736. 'end_date' => '2007-05-15 10:39:23',
  6737. 'created' => '2007-03-18 10:39:23',
  6738. 'updated' => '2007-03-18 10:41:31'
  6739. ),
  6740. 'ArticleFeatured' => array(
  6741. 'id' => '1',
  6742. 'title' => 'First Article',
  6743. 'user_id' => '1',
  6744. 'published' => 'Y',
  6745. 'User' => array(
  6746. 'id' => '1',
  6747. 'user' => 'mariano',
  6748. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6749. 'created' => '2007-03-17 01:16:23',
  6750. 'updated' => '2007-03-17 01:18:31'
  6751. ),
  6752. 'Category' => array(),
  6753. 'Featured' => array(
  6754. 'id' => '1',
  6755. 'article_featured_id' => '1',
  6756. 'category_id' => '1',
  6757. 'published_date' => '2007-03-31 10:39:23',
  6758. 'end_date' => '2007-05-15 10:39:23',
  6759. 'created' => '2007-03-18 10:39:23',
  6760. 'updated' => '2007-03-18 10:41:31'
  6761. )),
  6762. 'Category' => array(
  6763. 'id' => '1',
  6764. 'parent_id' => '0',
  6765. 'name' => 'Category 1',
  6766. 'created' => '2007-03-18 15:30:23',
  6767. 'updated' => '2007-03-18 15:32:31'
  6768. )),
  6769. array(
  6770. 'Featured' => array(
  6771. 'id' => '2',
  6772. 'article_featured_id' => '2',
  6773. 'category_id' => '1',
  6774. 'published_date' => '2007-03-31 10:39:23',
  6775. 'end_date' => '2007-05-15 10:39:23',
  6776. 'created' => '2007-03-18 10:39:23',
  6777. 'updated' => '2007-03-18 10:41:31'
  6778. ),
  6779. 'ArticleFeatured' => array(
  6780. 'id' => '2',
  6781. 'title' => 'Second Article',
  6782. 'user_id' => '3',
  6783. 'published' => 'Y',
  6784. 'User' => array(
  6785. 'id' => '3',
  6786. 'user' => 'larry',
  6787. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6788. 'created' => '2007-03-17 01:20:23',
  6789. 'updated' => '2007-03-17 01:22:31'
  6790. ),
  6791. 'Category' => array(),
  6792. 'Featured' => array(
  6793. 'id' => '2',
  6794. 'article_featured_id' => '2',
  6795. 'category_id' => '1',
  6796. 'published_date' => '2007-03-31 10:39:23',
  6797. 'end_date' => '2007-05-15 10:39:23',
  6798. 'created' => '2007-03-18 10:39:23',
  6799. 'updated' => '2007-03-18 10:41:31'
  6800. )),
  6801. 'Category' => array(
  6802. 'id' => '1',
  6803. 'parent_id' => '0',
  6804. 'name' => 'Category 1',
  6805. 'created' => '2007-03-18 15:30:23',
  6806. 'updated' => '2007-03-18 15:32:31'
  6807. )));
  6808. $this->assertEqual($result, $expected);
  6809. }
  6810. /**
  6811. * testRecursiveFindAllWithLimit method
  6812. *
  6813. * @access public
  6814. * @return void
  6815. */
  6816. function testRecursiveFindAllWithLimit() {
  6817. $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag', 'Comment', 'Attachment');
  6818. $TestModel =& new Article();
  6819. $TestModel->hasMany['Comment']['limit'] = 2;
  6820. $result = $TestModel->find('all', array(
  6821. 'conditions' => array('Article.user_id' => 1)
  6822. ));
  6823. $expected = array(
  6824. array(
  6825. 'Article' => array(
  6826. 'id' => '1',
  6827. 'user_id' => '1',
  6828. 'title' => 'First Article',
  6829. 'body' => 'First Article Body',
  6830. 'published' => 'Y',
  6831. 'created' => '2007-03-18 10:39:23',
  6832. 'updated' => '2007-03-18 10:41:31'
  6833. ),
  6834. 'User' => array(
  6835. 'id' => '1',
  6836. 'user' => 'mariano',
  6837. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6838. 'created' => '2007-03-17 01:16:23',
  6839. 'updated' => '2007-03-17 01:18:31'
  6840. ),
  6841. 'Comment' => array(
  6842. array(
  6843. 'id' => '1',
  6844. 'article_id' => '1',
  6845. 'user_id' => '2',
  6846. 'comment' => 'First Comment for First Article',
  6847. 'published' => 'Y',
  6848. 'created' => '2007-03-18 10:45:23',
  6849. 'updated' => '2007-03-18 10:47:31'
  6850. ),
  6851. array(
  6852. 'id' => '2',
  6853. 'article_id' => '1',
  6854. 'user_id' => '4',
  6855. 'comment' => 'Second Comment for First Article',
  6856. 'published' => 'Y',
  6857. 'created' => '2007-03-18 10:47:23',
  6858. 'updated' => '2007-03-18 10:49:31'
  6859. ),
  6860. ),
  6861. 'Tag' => array(
  6862. array(
  6863. 'id' => '1',
  6864. 'tag' => 'tag1',
  6865. 'created' => '2007-03-18 12:22:23',
  6866. 'updated' => '2007-03-18 12:24:31'
  6867. ),
  6868. array(
  6869. 'id' => '2',
  6870. 'tag' => 'tag2',
  6871. 'created' => '2007-03-18 12:24:23',
  6872. 'updated' => '2007-03-18 12:26:31'
  6873. ))),
  6874. array(
  6875. 'Article' => array(
  6876. 'id' => '3',
  6877. 'user_id' => '1',
  6878. 'title' => 'Third Article',
  6879. 'body' => 'Third Article Body',
  6880. 'published' => 'Y',
  6881. 'created' => '2007-03-18 10:43:23',
  6882. 'updated' => '2007-03-18 10:45:31'
  6883. ),
  6884. 'User' => array(
  6885. 'id' => '1',
  6886. 'user' => 'mariano',
  6887. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6888. 'created' => '2007-03-17 01:16:23',
  6889. 'updated' => '2007-03-17 01:18:31'
  6890. ),
  6891. 'Comment' => array(),
  6892. 'Tag' => array()
  6893. )
  6894. );
  6895. $this->assertEqual($result, $expected);
  6896. $TestModel->hasMany['Comment']['limit'] = 1;
  6897. $result = $TestModel->find('all', array(
  6898. 'conditions' => array('Article.user_id' => 3),
  6899. 'limit' => 1,
  6900. 'recursive' => 2
  6901. ));
  6902. $expected = array(
  6903. array(
  6904. 'Article' => array(
  6905. 'id' => '2',
  6906. 'user_id' => '3',
  6907. 'title' => 'Second Article',
  6908. 'body' => 'Second Article Body',
  6909. 'published' => 'Y',
  6910. 'created' => '2007-03-18 10:41:23',
  6911. 'updated' => '2007-03-18 10:43:31'
  6912. ),
  6913. 'User' => array(
  6914. 'id' => '3',
  6915. 'user' => 'larry',
  6916. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6917. 'created' => '2007-03-17 01:20:23',
  6918. 'updated' => '2007-03-17 01:22:31'
  6919. ),
  6920. 'Comment' => array(
  6921. array(
  6922. 'id' => '5',
  6923. 'article_id' => '2',
  6924. 'user_id' => '1',
  6925. 'comment' => 'First Comment for Second Article',
  6926. 'published' => 'Y',
  6927. 'created' => '2007-03-18 10:53:23',
  6928. 'updated' => '2007-03-18 10:55:31',
  6929. 'Article' => array(
  6930. 'id' => '2',
  6931. 'user_id' => '3',
  6932. 'title' => 'Second Article',
  6933. 'body' => 'Second Article Body',
  6934. 'published' => 'Y',
  6935. 'created' => '2007-03-18 10:41:23',
  6936. 'updated' => '2007-03-18 10:43:31'
  6937. ),
  6938. 'User' => array(
  6939. 'id' => '1',
  6940. 'user' => 'mariano',
  6941. 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  6942. 'created' => '2007-03-17 01:16:23',
  6943. 'updated' => '2007-03-17 01:18:31'
  6944. ),
  6945. 'Attachment' => array(
  6946. 'id' => '1',
  6947. 'comment_id' => 5,
  6948. 'attachment' => 'attachment.zip',
  6949. 'created' => '2007-03-18 10:51:23',
  6950. 'updated' => '2007-03-18 10:53:31'
  6951. )
  6952. )
  6953. ),
  6954. 'Tag' => array(
  6955. array(
  6956. 'id' => '1',
  6957. 'tag' => 'tag1',
  6958. 'created' => '2007-03-18 12:22:23',
  6959. 'updated' => '2007-03-18 12:24:31'
  6960. ),
  6961. array(
  6962. 'id' => '3',
  6963. 'tag' => 'tag3',
  6964. 'created' => '2007-03-18 12:26:23',
  6965. 'updated' => '2007-03-18 12:28:31'
  6966. )
  6967. )
  6968. )
  6969. );
  6970. $this->assertEqual($result, $expected);
  6971. }
  6972. /**
  6973. * Testing availability of $this->findQueryType in Model callbacks
  6974. *
  6975. * @return void
  6976. */
  6977. function testFindQueryTypeInCallbacks() {
  6978. $this->loadFixtures('Comment');
  6979. $Comment =& new AgainModifiedComment();
  6980. $comments = $Comment->find('all');
  6981. $this->assertEqual($comments[0]['Comment']['querytype'], 'all');
  6982. $comments = $Comment->find('first');
  6983. $this->assertEqual($comments['Comment']['querytype'], 'first');
  6984. }
  6985. /**
  6986. * testVirtualFields()
  6987. *
  6988. * Test correct fetching of virtual fields
  6989. * currently is not possible to do Relation.virtualField
  6990. *
  6991. * @access public
  6992. * @return void
  6993. */
  6994. function testVirtualFields() {
  6995. $this->loadFixtures('Post', 'Author');
  6996. $Post =& ClassRegistry::init('Post');
  6997. $Post->virtualFields = array('two' => "1 + 1");
  6998. $result = $Post->find('first');
  6999. $this->assertEqual($result['Post']['two'], 2);
  7000. $Post->Author->virtualFields = array('false' => '1 = 2');
  7001. $result = $Post->find('first');
  7002. $this->assertEqual($result['Post']['two'], 2);
  7003. $this->assertEqual($result['Author']['false'], false);
  7004. $result = $Post->find('first',array('fields' => array('author_id')));
  7005. $this->assertFalse(isset($result['Post']['two']));
  7006. $this->assertFalse(isset($result['Author']['false']));
  7007. $result = $Post->find('first',array('fields' => array('author_id', 'two')));
  7008. $this->assertEqual($result['Post']['two'], 2);
  7009. $this->assertFalse(isset($result['Author']['false']));
  7010. $result = $Post->find('first',array('fields' => array('two')));
  7011. $this->assertEqual($result['Post']['two'], 2);
  7012. $Post->id = 1;
  7013. $result = $Post->field('two');
  7014. $this->assertEqual($result, 2);
  7015. $result = $Post->find('first',array(
  7016. 'conditions' => array('two' => 2),
  7017. 'limit' => 1
  7018. ));
  7019. $this->assertEqual($result['Post']['two'], 2);
  7020. $result = $Post->find('first',array(
  7021. 'conditions' => array('two <' => 3),
  7022. 'limit' => 1
  7023. ));
  7024. $this->assertEqual($result['Post']['two'], 2);
  7025. $result = $Post->find('first',array(
  7026. 'conditions' => array('NOT' => array('two >' => 3)),
  7027. 'limit' => 1
  7028. ));
  7029. $this->assertEqual($result['Post']['two'], 2);
  7030. $dbo =& $Post->getDataSource();
  7031. $Post->virtualFields = array('other_field' => 'Post.id + 1');
  7032. $result = $Post->find('first', array(
  7033. 'conditions' => array('other_field' => 3),
  7034. 'limit' => 1
  7035. ));
  7036. $this->assertEqual($result['Post']['id'], 2);
  7037. $Post->virtualFields = array('other_field' => 'Post.id + 1');
  7038. $result = $Post->find('all', array(
  7039. 'fields' => array($dbo->calculate($Post, 'max', array('other_field')))
  7040. ));
  7041. $this->assertEqual($result[0][0]['other_field'], 4);
  7042. ClassRegistry::flush();
  7043. $Writing =& ClassRegistry::init(array('class' => 'Post', 'alias' => 'Writing'), 'Model');
  7044. $Writing->virtualFields = array('two' => "1 + 1");
  7045. $result = $Writing->find('first');
  7046. $this->assertEqual($result['Writing']['two'], 2);
  7047. $Post->create();
  7048. $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1');
  7049. $result = $Post->field('other_field');
  7050. $this->assertEqual($result, 4);
  7051. if ($this->skipIf($this->db->config['driver'] == 'postgres', 'The rest of virtualFieds test is not compatible with Postgres')) {
  7052. return;
  7053. }
  7054. ClassRegistry::flush();
  7055. $Post =& ClassRegistry::init('Post');
  7056. $Post->create();
  7057. $Post->virtualFields = array(
  7058. 'year' => 'YEAR(Post.created)',
  7059. 'unique_test_field' => 'COUNT(Post.id)'
  7060. );
  7061. $expectation = array(
  7062. 'Post' => array(
  7063. 'year' => 2007,
  7064. 'unique_test_field' => 3
  7065. )
  7066. );
  7067. $result = $Post->find('first', array(
  7068. 'fields' => array_keys($Post->virtualFields),
  7069. 'group' => array('year')
  7070. ));
  7071. $this->assertEqual($result, $expectation);
  7072. $Author =& ClassRegistry::init('Author');
  7073. $Author->virtualFields = array(
  7074. 'full_name' => 'CONCAT(Author.user, " ", Author.id)'
  7075. );
  7076. $result = $Author->find('first', array(
  7077. 'conditions' => array('Author.user' => 'mariano'),
  7078. 'fields' => array('Author.password', 'Author.full_name'),
  7079. 'recursive' => -1
  7080. ));
  7081. $this->assertTrue(isset($result['Author']['full_name']));
  7082. $result = $Author->find('first', array(
  7083. 'conditions' => array('Author.user' => 'mariano'),
  7084. 'fields' => array('Author.full_name', 'Author.password'),
  7085. 'recursive' => -1
  7086. ));
  7087. $this->assertTrue(isset($result['Author']['full_name']));
  7088. }
  7089. /**
  7090. * test that virtual fields work when they don't contain functions.
  7091. *
  7092. * @return void
  7093. */
  7094. function testVirtualFieldAsAString() {
  7095. $this->loadFixtures('Post', 'Author');
  7096. $Post =& new Post();
  7097. $Post->virtualFields = array(
  7098. 'writer' => 'Author.user'
  7099. );
  7100. $result = $Post->find('first');
  7101. $this->assertTrue(isset($result['Post']['writer']), 'virtual field not fetched %s');
  7102. }
  7103. /**
  7104. * test that isVirtualField will accept both aliased and non aliased fieldnames
  7105. *
  7106. * @return void
  7107. */
  7108. function testIsVirtualField() {
  7109. $this->loadFixtures('Post');
  7110. $Post =& ClassRegistry::init('Post');
  7111. $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1');
  7112. $this->assertTrue($Post->isVirtualField('other_field'));
  7113. $this->assertTrue($Post->isVirtualField('Post.other_field'));
  7114. $this->assertFalse($Post->isVirtualField('id'));
  7115. $this->assertFalse($Post->isVirtualField('Post.id'));
  7116. $this->assertFalse($Post->isVirtualField(array()));
  7117. }
  7118. /**
  7119. * test that getting virtual fields works with and without model alias attached
  7120. *
  7121. * @return void
  7122. */
  7123. function testGetVirtualField() {
  7124. $this->loadFixtures('Post');
  7125. $Post =& ClassRegistry::init('Post');
  7126. $Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1');
  7127. $this->assertEqual($Post->getVirtualField('other_field'), $Post->virtualFields['other_field']);
  7128. $this->assertEqual($Post->getVirtualField('Post.other_field'), $Post->virtualFields['other_field']);
  7129. }
  7130. }