統計
| ブランチ: | リビジョン:

pictcode / lib / Cake / Test / Case / Model / ModelReadTest.php @ 635eef61

履歴 | 表示 | アノテート | ダウンロード (213.885 KB)

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