comparison cake/tests/cases/libs/model/model_read.test.php @ 0:261e66bd5a0c

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