Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12345 anikendra 1
<?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
 
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 find('list') method
6555
 *
6556
 * @return void
6557
 */
6558
	public function testGenerateFindList() {
6559
		$this->loadFixtures('Article', 'Apple', 'Post', 'Author', 'User', 'Comment');
6560
 
6561
		$TestModel = new Article();
6562
		$TestModel->displayField = 'title';
6563
 
6564
		$result = $TestModel->find('list', array(
6565
			'order' => 'Article.title ASC'
6566
		));
6567
 
6568
		$expected = array(
6569
			1 => 'First Article',
6570
			2 => 'Second Article',
6571
			3 => 'Third Article'
6572
		);
6573
		$this->assertEquals($expected, $result);
6574
 
6575
		$db = ConnectionManager::getDataSource('test');
6576
		if ($db instanceof Mysql) {
6577
			$result = $TestModel->find('list', array(
6578
				'order' => array('FIELD(Article.id, 3, 2) ASC', 'Article.title ASC')
6579
			));
6580
			$expected = array(
6581
				1 => 'First Article',
6582
				3 => 'Third Article',
6583
				2 => 'Second Article'
6584
			);
6585
			$this->assertEquals($expected, $result);
6586
		}
6587
 
6588
		$result = Hash::combine(
6589
			$TestModel->find('all', array(
6590
				'order' => 'Article.title ASC',
6591
				'fields' => array('id', 'title')
6592
			)),
6593
			'{n}.Article.id', '{n}.Article.title'
6594
		);
6595
		$expected = array(
6596
			1 => 'First Article',
6597
			2 => 'Second Article',
6598
			3 => 'Third Article'
6599
		);
6600
		$this->assertEquals($expected, $result);
6601
 
6602
		$result = Hash::combine(
6603
			$TestModel->find('all', array(
6604
				'order' => 'Article.title ASC'
6605
			)),
6606
			'{n}.Article.id', '{n}.Article'
6607
		);
6608
		$expected = array(
6609
			1 => array(
6610
				'id' => 1,
6611
				'user_id' => 1,
6612
				'title' => 'First Article',
6613
				'body' => 'First Article Body',
6614
				'published' => 'Y',
6615
				'created' => '2007-03-18 10:39:23',
6616
				'updated' => '2007-03-18 10:41:31'
6617
			),
6618
			2 => array(
6619
				'id' => 2,
6620
				'user_id' => 3,
6621
				'title' => 'Second Article',
6622
				'body' => 'Second Article Body',
6623
				'published' => 'Y',
6624
				'created' => '2007-03-18 10:41:23',
6625
				'updated' => '2007-03-18 10:43:31'
6626
			),
6627
			3 => array(
6628
				'id' => 3,
6629
				'user_id' => 1,
6630
				'title' => 'Third Article',
6631
				'body' => 'Third Article Body',
6632
				'published' => 'Y',
6633
				'created' => '2007-03-18 10:43:23',
6634
				'updated' => '2007-03-18 10:45:31'
6635
		));
6636
 
6637
		$this->assertEquals($expected, $result);
6638
 
6639
		$result = Hash::combine(
6640
			$TestModel->find('all', array(
6641
				'order' => 'Article.title ASC'
6642
			)),
6643
			'{n}.Article.id', '{n}.Article', '{n}.Article.user_id'
6644
		);
6645
		$expected = array(
6646
			1 => array(
6647
				1 => array(
6648
					'id' => 1,
6649
					'user_id' => 1,
6650
					'title' => 'First Article',
6651
					'body' => 'First Article Body',
6652
					'published' => 'Y',
6653
					'created' => '2007-03-18 10:39:23',
6654
					'updated' => '2007-03-18 10:41:31'
6655
				),
6656
				3 => array(
6657
					'id' => 3,
6658
					'user_id' => 1,
6659
					'title' => 'Third Article',
6660
					'body' => 'Third Article Body',
6661
					'published' => 'Y',
6662
					'created' => '2007-03-18 10:43:23',
6663
					'updated' => '2007-03-18 10:45:31'
6664
				)),
6665
			3 => array(
6666
				2 => array(
6667
					'id' => 2,
6668
					'user_id' => 3,
6669
					'title' => 'Second Article',
6670
					'body' => 'Second Article Body',
6671
					'published' => 'Y',
6672
					'created' => '2007-03-18 10:41:23',
6673
					'updated' => '2007-03-18 10:43:31'
6674
		)));
6675
 
6676
		$this->assertEquals($expected, $result);
6677
 
6678
		$result = Hash::combine(
6679
			$TestModel->find('all', array(
6680
				'order' => 'Article.title ASC',
6681
				'fields' => array('id', 'title', 'user_id')
6682
			)),
6683
			'{n}.Article.id', '{n}.Article.title', '{n}.Article.user_id'
6684
		);
6685
 
6686
		$expected = array(
6687
			1 => array(
6688
				1 => 'First Article',
6689
				3 => 'Third Article'
6690
			),
6691
			3 => array(
6692
				2 => 'Second Article'
6693
		));
6694
		$this->assertEquals($expected, $result);
6695
 
6696
		$TestModel = new Apple();
6697
		$expected = array(
6698
			1 => 'Red Apple 1',
6699
			2 => 'Bright Red Apple',
6700
			3 => 'green blue',
6701
			4 => 'Test Name',
6702
			5 => 'Blue Green',
6703
			6 => 'My new apple',
6704
			7 => 'Some odd color'
6705
		);
6706
 
6707
		$this->assertEquals($expected, $TestModel->find('list'));
6708
		$this->assertEquals($expected, $TestModel->Parent->find('list'));
6709
 
6710
		$TestModel = new Post();
6711
		$result = $TestModel->find('list', array(
6712
			'fields' => 'Post.title'
6713
		));
6714
		$expected = array(
6715
			1 => 'First Post',
6716
			2 => 'Second Post',
6717
			3 => 'Third Post'
6718
		);
6719
		$this->assertEquals($expected, $result);
6720
 
6721
		$result = $TestModel->find('list', array(
6722
			'fields' => 'title'
6723
		));
6724
		$expected = array(
6725
			1 => 'First Post',
6726
			2 => 'Second Post',
6727
			3 => 'Third Post'
6728
		);
6729
		$this->assertEquals($expected, $result);
6730
 
6731
		$result = $TestModel->find('list', array(
6732
			'fields' => array('title', 'id')
6733
		));
6734
		$expected = array(
6735
			'First Post' => '1',
6736
			'Second Post' => '2',
6737
			'Third Post' => '3'
6738
		);
6739
		$this->assertEquals($expected, $result);
6740
 
6741
		$result = $TestModel->find('list', array(
6742
			'fields' => array('title', 'id', 'created')
6743
		));
6744
		$expected = array(
6745
			'2007-03-18 10:39:23' => array(
6746
				'First Post' => '1'
6747
			),
6748
			'2007-03-18 10:41:23' => array(
6749
				'Second Post' => '2'
6750
			),
6751
			'2007-03-18 10:43:23' => array(
6752
				'Third Post' => '3'
6753
			),
6754
		);
6755
		$this->assertEquals($expected, $result);
6756
 
6757
		$result = $TestModel->find('list', array(
6758
			'fields' => array('Post.body')
6759
		));
6760
		$expected = array(
6761
			1 => 'First Post Body',
6762
			2 => 'Second Post Body',
6763
			3 => 'Third Post Body'
6764
		);
6765
		$this->assertEquals($expected, $result);
6766
 
6767
		$result = $TestModel->find('list', array(
6768
			'fields' => array('Post.title', 'Post.body')
6769
		));
6770
		$expected = array(
6771
			'First Post' => 'First Post Body',
6772
			'Second Post' => 'Second Post Body',
6773
			'Third Post' => 'Third Post Body'
6774
		);
6775
		$this->assertEquals($expected, $result);
6776
 
6777
		$result = $TestModel->find('list', array(
6778
			'fields' => array('Post.id', 'Post.title', 'Author.user'),
6779
			'recursive' => 1
6780
		));
6781
		$expected = array(
6782
			'mariano' => array(
6783
				1 => 'First Post',
6784
				3 => 'Third Post'
6785
			),
6786
			'larry' => array(
6787
				2 => 'Second Post'
6788
		));
6789
		$this->assertEquals($expected, $result);
6790
 
6791
		$TestModel = new User();
6792
		$result = $TestModel->find('list', array(
6793
			'fields' => array('User.user', 'User.password')
6794
		));
6795
		$expected = array(
6796
			'mariano' => '5f4dcc3b5aa765d61d8327deb882cf99',
6797
			'nate' => '5f4dcc3b5aa765d61d8327deb882cf99',
6798
			'larry' => '5f4dcc3b5aa765d61d8327deb882cf99',
6799
			'garrett' => '5f4dcc3b5aa765d61d8327deb882cf99'
6800
		);
6801
		$this->assertEquals($expected, $result);
6802
 
6803
		$TestModel = new ModifiedAuthor();
6804
		$result = $TestModel->find('list', array(
6805
			'fields' => array('Author.id', 'Author.user')
6806
		));
6807
		$expected = array(
6808
			1 => 'mariano (CakePHP)',
6809
			2 => 'nate (CakePHP)',
6810
			3 => 'larry (CakePHP)',
6811
			4 => 'garrett (CakePHP)'
6812
		);
6813
		$this->assertEquals($expected, $result);
6814
 
6815
		$TestModel = new Article();
6816
		$TestModel->displayField = 'title';
6817
		$result = $TestModel->find('list', array(
6818
			'conditions' => array('User.user' => 'mariano'),
6819
			'recursive' => 0
6820
		));
6821
		$expected = array(
6822
			1 => 'First Article',
6823
			3 => 'Third Article'
6824
		);
6825
		$this->assertEquals($expected, $result);
6826
	}
6827
 
6828
/**
6829
 * testFindField method
6830
 *
6831
 * @return void
6832
 */
6833
	public function testFindField() {
6834
		$this->loadFixtures('User');
6835
		$TestModel = new User();
6836
 
6837
		$TestModel->id = 1;
6838
		$result = $TestModel->field('user');
6839
		$this->assertEquals('mariano', $result);
6840
 
6841
		$result = $TestModel->field('User.user');
6842
		$this->assertEquals('mariano', $result);
6843
 
6844
		$TestModel->id = false;
6845
		$result = $TestModel->field('user', array(
6846
			'user' => 'mariano'
6847
		));
6848
		$this->assertEquals('mariano', $result);
6849
		$TestModel->order = null;
6850
		$result = $TestModel->field('COUNT(*) AS count', true);
6851
		$this->assertEquals(4, $result);
6852
 
6853
		$result = $TestModel->field('COUNT(*)', true);
6854
		$this->assertEquals(4, $result);
6855
	}
6856
 
6857
/**
6858
 * testFindUnique method
6859
 *
6860
 * @return void
6861
 */
6862
	public function testFindUnique() {
6863
		$this->loadFixtures('User');
6864
		$TestModel = new User();
6865
 
6866
		$this->assertFalse($TestModel->isUnique(array(
6867
			'user' => 'nate'
6868
		)));
6869
		$TestModel->id = 2;
6870
		$this->assertTrue($TestModel->isUnique(array(
6871
			'user' => 'nate'
6872
		)));
6873
		$this->assertFalse($TestModel->isUnique(array(
6874
			'user' => 'nate',
6875
			'password' => '5f4dcc3b5aa765d61d8327deb882cf99'
6876
		)));
6877
	}
6878
 
6879
/**
6880
 * test find('count') method
6881
 *
6882
 * @return void
6883
 */
6884
	public function testFindCount() {
6885
		$this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag');
6886
 
6887
		$TestModel = new User();
6888
		$this->db->getLog(false, true);
6889
		$result = $TestModel->find('count');
6890
		$this->assertEquals(4, $result);
6891
 
6892
		$this->db->getLog(false, true);
6893
		$fullDebug = $this->db->fullDebug;
6894
		$this->db->fullDebug = true;
6895
		$TestModel->order = 'User.id';
6896
		$result = $TestModel->find('count');
6897
		$this->db->fullDebug = $fullDebug;
6898
		$this->assertEquals(4, $result);
6899
 
6900
		$log = $this->db->getLog();
6901
		$this->assertTrue(isset($log['log'][0]['query']));
6902
		$this->assertNotRegExp('/ORDER\s+BY/', $log['log'][0]['query']);
6903
 
6904
		$Article = new Article();
6905
		$Article->order = null;
6906
		$Article->recursive = -1;
6907
		$expected = count($Article->find('all', array(
6908
			'fields' => array('Article.user_id'),
6909
			'group' => 'Article.user_id')
6910
		));
6911
		$result = $Article->find('count', array('group' => array('Article.user_id')));
6912
		$this->assertEquals($expected, $result);
6913
 
6914
		$expected = count($Article->find('all', array(
6915
			'fields' => array('Article.user_id'),
6916
			'conditions' => array('Article.user_id' => 1),
6917
			'group' => 'Article.user_id')
6918
		));
6919
		$result = $Article->find('count', array(
6920
			'conditions' => array('Article.user_id' => 1),
6921
			'group' => array('Article.user_id'),
6922
		));
6923
		$this->assertEquals($expected, $result);
6924
	}
6925
 
6926
/**
6927
 * Test that find('first') does not use the id set to the object.
6928
 *
6929
 * @return void
6930
 */
6931
	public function testFindFirstNoIdUsed() {
6932
		$this->loadFixtures('Project');
6933
 
6934
		$Project = new Project();
6935
		$Project->id = 3;
6936
		$result = $Project->find('first');
6937
 
6938
		$this->assertEquals('Project 1', $result['Project']['name'], 'Wrong record retrieved');
6939
	}
6940
 
6941
/**
6942
 * test find with COUNT(DISTINCT field)
6943
 *
6944
 * @return void
6945
 */
6946
	public function testFindCountDistinct() {
6947
		$this->skipIf($this->db instanceof Sqlite, 'SELECT COUNT(DISTINCT field) is not compatible with SQLite.');
6948
		$this->skipIf($this->db instanceof Sqlserver, 'This test is not compatible with SQL Server.');
6949
 
6950
		$this->loadFixtures('Project', 'Thread');
6951
		$TestModel = new Project();
6952
		$TestModel->create(array('name' => 'project')) && $TestModel->save();
6953
		$TestModel->create(array('name' => 'project')) && $TestModel->save();
6954
		$TestModel->create(array('name' => 'project')) && $TestModel->save();
6955
 
6956
		$result = $TestModel->find('count', array('fields' => 'DISTINCT name'));
6957
		$this->assertEquals(4, $result);
6958
	}
6959
 
6960
/**
6961
 * Test find(count) with Db::expression
6962
 *
6963
 * @return void
6964
 */
6965
	public function testFindCountWithDbExpressions() {
6966
		$this->skipIf($this->db instanceof Postgres, 'testFindCountWithDbExpressions is not compatible with Postgres.');
6967
 
6968
		$this->loadFixtures('Project', 'Thread');
6969
		$db = ConnectionManager::getDataSource('test');
6970
		$TestModel = new Project();
6971
 
6972
		$result = $TestModel->find('count', array('conditions' => array(
6973
			$db->expression('Project.name = \'Project 3\'')
6974
		)));
6975
		$this->assertEquals(1, $result);
6976
 
6977
		$result = $TestModel->find('count', array('conditions' => array(
6978
			'Project.name' => $db->expression('\'Project 3\'')
6979
		)));
6980
		$this->assertEquals(1, $result);
6981
	}
6982
 
6983
/**
6984
 * testFindMagic method
6985
 *
6986
 * @return void
6987
 */
6988
	public function testFindMagic() {
6989
		$this->loadFixtures('User');
6990
		$TestModel = new User();
6991
 
6992
		$result = $TestModel->findByUser('mariano');
6993
		$expected = array(
6994
			'User' => array(
6995
				'id' => '1',
6996
				'user' => 'mariano',
6997
				'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
6998
				'created' => '2007-03-17 01:16:23',
6999
				'updated' => '2007-03-17 01:18:31'
7000
		));
7001
		$this->assertEquals($expected, $result);
7002
 
7003
		$result = $TestModel->findByPassword('5f4dcc3b5aa765d61d8327deb882cf99');
7004
		$expected = array('User' => array(
7005
			'id' => '1',
7006
			'user' => 'mariano',
7007
			'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
7008
			'created' => '2007-03-17 01:16:23',
7009
			'updated' => '2007-03-17 01:18:31'
7010
		));
7011
		$this->assertEquals($expected, $result);
7012
	}
7013
 
7014
/**
7015
 * testRead method
7016
 *
7017
 * @return void
7018
 */
7019
	public function testRead() {
7020
		$this->loadFixtures('User', 'Article');
7021
		$TestModel = new User();
7022
 
7023
		$result = $TestModel->read();
7024
		$this->assertFalse($result);
7025
 
7026
		$TestModel->id = 2;
7027
		$result = $TestModel->read();
7028
		$expected = array(
7029
			'User' => array(
7030
				'id' => '2',
7031
				'user' => 'nate',
7032
				'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
7033
				'created' => '2007-03-17 01:18:23',
7034
				'updated' => '2007-03-17 01:20:31'
7035
		));
7036
		$this->assertEquals($expected, $result);
7037
 
7038
		$result = $TestModel->read(null, 2);
7039
		$expected = array(
7040
			'User' => array(
7041
				'id' => '2',
7042
				'user' => 'nate',
7043
				'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
7044
				'created' => '2007-03-17 01:18:23',
7045
				'updated' => '2007-03-17 01:20:31'
7046
		));
7047
		$this->assertEquals($expected, $result);
7048
 
7049
		$TestModel->id = 2;
7050
		$result = $TestModel->read(array('id', 'user'));
7051
		$expected = array('User' => array('id' => '2', 'user' => 'nate'));
7052
		$this->assertEquals($expected, $result);
7053
 
7054
		$result = $TestModel->read('id, user', 2);
7055
		$expected = array(
7056
			'User' => array(
7057
				'id' => '2',
7058
				'user' => 'nate'
7059
		));
7060
		$this->assertEquals($expected, $result);
7061
 
7062
		$result = $TestModel->bindModel(array('hasMany' => array('Article')));
7063
		$this->assertTrue($result);
7064
 
7065
		$TestModel->id = 1;
7066
		$result = $TestModel->read('id, user');
7067
		$expected = array(
7068
			'User' => array(
7069
				'id' => '1',
7070
				'user' => 'mariano'
7071
			),
7072
			'Article' => array(
7073
				array(
7074
					'id' => '1',
7075
					'user_id' => '1',
7076
					'title' => 'First Article',
7077
					'body' => 'First Article Body',
7078
					'published' => 'Y',
7079
					'created' => '2007-03-18 10:39:23',
7080
					'updated' => '2007-03-18 10:41:31'
7081
				),
7082
				array(
7083
					'id' => '3',
7084
					'user_id' => '1',
7085
					'title' => 'Third Article',
7086
					'body' => 'Third Article Body',
7087
					'published' => 'Y',
7088
					'created' => '2007-03-18 10:43:23',
7089
					'updated' => '2007-03-18 10:45:31'
7090
		)));
7091
		$this->assertEquals($expected, $result);
7092
	}
7093
 
7094
/**
7095
 * testRecursiveRead method
7096
 *
7097
 * @return void
7098
 */
7099
	public function testRecursiveRead() {
7100
		$this->loadFixtures(
7101
			'User',
7102
			'Article',
7103
			'Comment',
7104
			'Tag',
7105
			'ArticlesTag',
7106
			'Featured',
7107
			'ArticleFeatured'
7108
		);
7109
		$TestModel = new User();
7110
 
7111
		$result = $TestModel->bindModel(array('hasMany' => array('Article')), false);
7112
		$this->assertTrue($result);
7113
 
7114
		$TestModel->recursive = 0;
7115
		$result = $TestModel->read('id, user', 1);
7116
		$expected = array(
7117
			'User' => array('id' => '1', 'user' => 'mariano'),
7118
		);
7119
		$this->assertEquals($expected, $result);
7120
 
7121
		$TestModel->recursive = 1;
7122
		$result = $TestModel->read('id, user', 1);
7123
		$expected = array(
7124
			'User' => array(
7125
				'id' => '1',
7126
				'user' => 'mariano'
7127
			),
7128
			'Article' => array(
7129
				array(
7130
					'id' => '1',
7131
					'user_id' => '1',
7132
					'title' => 'First Article',
7133
					'body' => 'First Article Body',
7134
					'published' => 'Y',
7135
					'created' => '2007-03-18 10:39:23',
7136
					'updated' => '2007-03-18 10:41:31'
7137
				),
7138
				array(
7139
					'id' => '3',
7140
					'user_id' => '1',
7141
					'title' => 'Third Article',
7142
					'body' => 'Third Article Body',
7143
					'published' => 'Y',
7144
					'created' => '2007-03-18 10:43:23',
7145
					'updated' => '2007-03-18 10:45:31'
7146
		)));
7147
		$this->assertEquals($expected, $result);
7148
 
7149
		$TestModel->recursive = 2;
7150
		$result = $TestModel->read('id, user', 3);
7151
		$expected = array(
7152
			'User' => array(
7153
				'id' => '3',
7154
				'user' => 'larry'
7155
			),
7156
			'Article' => array(
7157
				array(
7158
					'id' => '2',
7159
					'user_id' => '3',
7160
					'title' => 'Second Article',
7161
					'body' => 'Second Article Body',
7162
					'published' => 'Y',
7163
					'created' => '2007-03-18 10:41:23',
7164
					'updated' => '2007-03-18 10:43:31',
7165
					'User' => array(
7166
						'id' => '3',
7167
						'user' => 'larry',
7168
						'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
7169
						'created' => '2007-03-17 01:20:23',
7170
						'updated' => '2007-03-17 01:22:31'
7171
					),
7172
					'Comment' => array(
7173
						array(
7174
							'id' => '5',
7175
							'article_id' => '2',
7176
							'user_id' => '1',
7177
							'comment' => 'First Comment for Second Article',
7178
							'published' => 'Y',
7179
							'created' => '2007-03-18 10:53:23',
7180
							'updated' => '2007-03-18 10:55:31'
7181
						),
7182
						array(
7183
							'id' => '6',
7184
							'article_id' => '2',
7185
							'user_id' => '2',
7186
							'comment' => 'Second Comment for Second Article',
7187
							'published' => 'Y',
7188
							'created' => '2007-03-18 10:55:23',
7189
							'updated' => '2007-03-18 10:57:31'
7190
					)),
7191
					'Tag' => array(
7192
						array(
7193
							'id' => '1',
7194
							'tag' => 'tag1',
7195
							'created' => '2007-03-18 12:22:23',
7196
							'updated' => '2007-03-18 12:24:31'
7197
						),
7198
						array(
7199
							'id' => '3',
7200
							'tag' => 'tag3',
7201
							'created' => '2007-03-18 12:26:23',
7202
							'updated' => '2007-03-18 12:28:31'
7203
		)))));
7204
		$this->assertEquals($expected, $result);
7205
	}
7206
 
7207
	public function testRecursiveFindAll() {
7208
		$this->loadFixtures(
7209
			'User',
7210
			'Article',
7211
			'Comment',
7212
			'Tag',
7213
			'ArticlesTag',
7214
			'Attachment',
7215
			'ArticleFeatured',
7216
			'ArticleFeaturedsTags',
7217
			'Featured',
7218
			'Category'
7219
		);
7220
		$TestModel = new Article();
7221
 
7222
		$result = $TestModel->find('all', array('conditions' => array('Article.user_id' => 1)));
7223
		$expected = array(
7224
			array(
7225
				'Article' => array(
7226
					'id' => '1',
7227
					'user_id' => '1',
7228
					'title' => 'First Article',
7229
					'body' => 'First Article Body',
7230
					'published' => 'Y',
7231
					'created' => '2007-03-18 10:39:23',
7232
					'updated' => '2007-03-18 10:41:31'
7233
				),
7234
				'User' => array(
7235
					'id' => '1',
7236
					'user' => 'mariano',
7237
					'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
7238
					'created' => '2007-03-17 01:16:23',
7239
					'updated' => '2007-03-17 01:18:31'
7240
				),
7241
				'Comment' => array(
7242
					array(
7243
						'id' => '1',
7244
						'article_id' => '1',
7245
						'user_id' => '2',
7246
						'comment' => 'First Comment for First Article',
7247
						'published' => 'Y',
7248
						'created' => '2007-03-18 10:45:23',
7249
						'updated' => '2007-03-18 10:47:31'
7250
					),
7251
					array(
7252
						'id' => '2',
7253
						'article_id' => '1',
7254
						'user_id' => '4',
7255
						'comment' => 'Second Comment for First Article',
7256
						'published' => 'Y',
7257
						'created' => '2007-03-18 10:47:23',
7258
						'updated' => '2007-03-18 10:49:31'
7259
					),
7260
					array(
7261
						'id' => '3',
7262
						'article_id' => '1',
7263
						'user_id' => '1',
7264
						'comment' => 'Third Comment for First Article',
7265
						'published' => 'Y',
7266
						'created' => '2007-03-18 10:49:23',
7267
						'updated' => '2007-03-18 10:51:31'
7268
					),
7269
					array(
7270
						'id' => '4',
7271
						'article_id' => '1',
7272
						'user_id' => '1',
7273
						'comment' => 'Fourth Comment for First Article',
7274
						'published' => 'N',
7275
						'created' => '2007-03-18 10:51:23',
7276
						'updated' => '2007-03-18 10:53:31'
7277
					)
7278
				),
7279
				'Tag' => array(
7280
					array(
7281
						'id' => '1',
7282
						'tag' => 'tag1',
7283
						'created' => '2007-03-18 12:22:23',
7284
						'updated' => '2007-03-18 12:24:31'
7285
					),
7286
					array(
7287
						'id' => '2',
7288
						'tag' => 'tag2',
7289
						'created' => '2007-03-18 12:24:23',
7290
						'updated' => '2007-03-18 12:26:31'
7291
			))),
7292
			array(
7293
				'Article' => array(
7294
					'id' => '3',
7295
					'user_id' => '1',
7296
					'title' => 'Third Article',
7297
					'body' => 'Third Article Body',
7298
					'published' => 'Y',
7299
					'created' => '2007-03-18 10:43:23',
7300
					'updated' => '2007-03-18 10:45:31'
7301
				),
7302
				'User' => array(
7303
					'id' => '1',
7304
					'user' => 'mariano',
7305
					'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
7306
					'created' => '2007-03-17 01:16:23',
7307
					'updated' => '2007-03-17 01:18:31'
7308
				),
7309
				'Comment' => array(),
7310
				'Tag' => array()
7311
			)
7312
		);
7313
		$this->assertEquals($expected, $result);
7314
 
7315
		$result = $TestModel->find('all', array(
7316
			'conditions' => array('Article.user_id' => 3),
7317
			'limit' => 1,
7318
			'recursive' => 2
7319
		));
7320
 
7321
		$expected = array(
7322
			array(
7323
				'Article' => array(
7324
					'id' => '2',
7325
					'user_id' => '3',
7326
					'title' => 'Second Article',
7327
					'body' => 'Second Article Body',
7328
					'published' => 'Y',
7329
					'created' => '2007-03-18 10:41:23',
7330
					'updated' => '2007-03-18 10:43:31'
7331
				),
7332
				'User' => array(
7333
					'id' => '3',
7334
					'user' => 'larry',
7335
					'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
7336
					'created' => '2007-03-17 01:20:23',
7337
					'updated' => '2007-03-17 01:22:31'
7338
				),
7339
				'Comment' => array(
7340
					array(
7341
						'id' => '5',
7342
						'article_id' => '2',
7343
						'user_id' => '1',
7344
						'comment' => 'First Comment for Second Article',
7345
						'published' => 'Y',
7346
						'created' => '2007-03-18 10:53:23',
7347
						'updated' => '2007-03-18 10:55:31',
7348
						'Article' => array(
7349
							'id' => '2',
7350
							'user_id' => '3',
7351
							'title' => 'Second Article',
7352
							'body' => 'Second Article Body',
7353
							'published' => 'Y',
7354
							'created' => '2007-03-18 10:41:23',
7355
							'updated' => '2007-03-18 10:43:31'
7356
						),
7357
						'User' => array(
7358
							'id' => '1',
7359
							'user' => 'mariano',
7360
							'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
7361
							'created' => '2007-03-17 01:16:23',
7362
							'updated' => '2007-03-17 01:18:31'
7363
						),
7364
						'Attachment' => array(
7365
							'id' => '1',
7366
							'comment_id' => 5,
7367
							'attachment' => 'attachment.zip',
7368
							'created' => '2007-03-18 10:51:23',
7369
							'updated' => '2007-03-18 10:53:31'
7370
						)
7371
					),
7372
					array(
7373
						'id' => '6',
7374
						'article_id' => '2',
7375
						'user_id' => '2',
7376
						'comment' => 'Second Comment for Second Article',
7377
						'published' => 'Y',
7378
						'created' => '2007-03-18 10:55:23',
7379
						'updated' => '2007-03-18 10:57:31',
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' => '2',
7391
							'user' => 'nate',
7392
							'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
7393
							'created' => '2007-03-17 01:18:23',
7394
							'updated' => '2007-03-17 01:20:31'
7395
						),
7396
						'Attachment' => array()
7397
					)
7398
				),
7399
				'Tag' => array(
7400
					array(
7401
						'id' => '1',
7402
						'tag' => 'tag1',
7403
						'created' => '2007-03-18 12:22:23',
7404
						'updated' => '2007-03-18 12:24:31'
7405
					),
7406
					array(
7407
						'id' => '3',
7408
						'tag' => 'tag3',
7409
						'created' => '2007-03-18 12:26:23',
7410
						'updated' => '2007-03-18 12:28:31'
7411
		))));
7412
 
7413
		$this->assertEquals($expected, $result);
7414
 
7415
		$Featured = new Featured();
7416
 
7417
		$Featured->recursive = 2;
7418
		$Featured->bindModel(array(
7419
			'belongsTo' => array(
7420
				'ArticleFeatured' => array(
7421
					'conditions' => "ArticleFeatured.published = 'Y'",
7422
					'fields' => 'id, title, user_id, published'
7423
				)
7424
			)
7425
		));
7426
 
7427
		$Featured->ArticleFeatured->unbindModel(array(
7428
			'hasMany' => array('Attachment', 'Comment'),
7429
			'hasAndBelongsToMany' => array('Tag'))
7430
		);
7431
 
7432
		$orderBy = 'ArticleFeatured.id ASC';
7433
		$result = $Featured->find('all', array(
7434
			'order' => $orderBy, 'limit' => 3
7435
		));
7436
 
7437
		$expected = array(
7438
			array(
7439
				'Featured' => array(
7440
					'id' => '1',
7441
					'article_featured_id' => '1',
7442
					'category_id' => '1',
7443
					'published_date' => '2007-03-31 10:39:23',
7444
					'end_date' => '2007-05-15 10:39:23',
7445
					'created' => '2007-03-18 10:39:23',
7446
					'updated' => '2007-03-18 10:41:31'
7447
				),
7448
				'ArticleFeatured' => array(
7449
					'id' => '1',
7450
					'title' => 'First Article',
7451
					'user_id' => '1',
7452
					'published' => 'Y',
7453
					'User' => array(
7454
						'id' => '1',
7455
						'user' => 'mariano',
7456
						'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
7457
						'created' => '2007-03-17 01:16:23',
7458
						'updated' => '2007-03-17 01:18:31'
7459
					),
7460
					'Category' => array(),
7461
					'Featured' => array(
7462
						'id' => '1',
7463
						'article_featured_id' => '1',
7464
						'category_id' => '1',
7465
						'published_date' => '2007-03-31 10:39:23',
7466
						'end_date' => '2007-05-15 10:39:23',
7467
						'created' => '2007-03-18 10:39:23',
7468
						'updated' => '2007-03-18 10:41:31'
7469
				)),
7470
				'Category' => array(
7471
					'id' => '1',
7472
					'parent_id' => '0',
7473
					'name' => 'Category 1',
7474
					'created' => '2007-03-18 15:30:23',
7475
					'updated' => '2007-03-18 15:32:31'
7476
				)),
7477
			array(
7478
				'Featured' => array(
7479
					'id' => '2',
7480
					'article_featured_id' => '2',
7481
					'category_id' => '1',
7482
					'published_date' => '2007-03-31 10:39:23',
7483
					'end_date' => '2007-05-15 10:39:23',
7484
					'created' => '2007-03-18 10:39:23',
7485
					'updated' => '2007-03-18 10:41:31'
7486
				),
7487
				'ArticleFeatured' => array(
7488
					'id' => '2',
7489
					'title' => 'Second Article',
7490
					'user_id' => '3',
7491
					'published' => 'Y',
7492
					'User' => array(
7493
						'id' => '3',
7494
						'user' => 'larry',
7495
						'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
7496
						'created' => '2007-03-17 01:20:23',
7497
						'updated' => '2007-03-17 01:22:31'
7498
					),
7499
					'Category' => array(),
7500
					'Featured' => array(
7501
						'id' => '2',
7502
						'article_featured_id' => '2',
7503
						'category_id' => '1',
7504
						'published_date' => '2007-03-31 10:39:23',
7505
						'end_date' => '2007-05-15 10:39:23',
7506
						'created' => '2007-03-18 10:39:23',
7507
						'updated' => '2007-03-18 10:41:31'
7508
				)),
7509
				'Category' => array(
7510
					'id' => '1',
7511
					'parent_id' => '0',
7512
					'name' => 'Category 1',
7513
					'created' => '2007-03-18 15:30:23',
7514
					'updated' => '2007-03-18 15:32:31'
7515
		)));
7516
		$this->assertEquals($expected, $result);
7517
	}
7518
 
7519
/**
7520
 * testRecursiveFindAllWithLimit method
7521
 *
7522
 * @return void
7523
 */
7524
	public function testRecursiveFindAllWithLimit() {
7525
		$this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag', 'Comment', 'Attachment');
7526
		$TestModel = new Article();
7527
 
7528
		$TestModel->hasMany['Comment']['limit'] = 2;
7529
 
7530
		$result = $TestModel->find('all', array(
7531
			'conditions' => array('Article.user_id' => 1)
7532
		));
7533
		$expected = array(
7534
			array(
7535
				'Article' => array(
7536
					'id' => '1',
7537
					'user_id' => '1',
7538
					'title' => 'First Article',
7539
					'body' => 'First Article Body',
7540
					'published' => 'Y',
7541
					'created' => '2007-03-18 10:39:23',
7542
					'updated' => '2007-03-18 10:41:31'
7543
				),
7544
				'User' => array(
7545
					'id' => '1',
7546
					'user' => 'mariano',
7547
					'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
7548
					'created' => '2007-03-17 01:16:23',
7549
					'updated' => '2007-03-17 01:18:31'
7550
				),
7551
				'Comment' => array(
7552
					array(
7553
						'id' => '1',
7554
						'article_id' => '1',
7555
						'user_id' => '2',
7556
						'comment' => 'First Comment for First Article',
7557
						'published' => 'Y',
7558
						'created' => '2007-03-18 10:45:23',
7559
						'updated' => '2007-03-18 10:47:31'
7560
					),
7561
					array(
7562
						'id' => '2',
7563
						'article_id' => '1',
7564
						'user_id' => '4',
7565
						'comment' => 'Second Comment for First Article',
7566
						'published' => 'Y',
7567
						'created' => '2007-03-18 10:47:23',
7568
						'updated' => '2007-03-18 10:49:31'
7569
					),
7570
				),
7571
				'Tag' => array(
7572
					array(
7573
						'id' => '1',
7574
						'tag' => 'tag1',
7575
						'created' => '2007-03-18 12:22:23',
7576
						'updated' => '2007-03-18 12:24:31'
7577
					),
7578
					array(
7579
						'id' => '2',
7580
						'tag' => 'tag2',
7581
						'created' => '2007-03-18 12:24:23',
7582
						'updated' => '2007-03-18 12:26:31'
7583
			))),
7584
			array(
7585
				'Article' => array(
7586
					'id' => '3',
7587
					'user_id' => '1',
7588
					'title' => 'Third Article',
7589
					'body' => 'Third Article Body',
7590
					'published' => 'Y',
7591
					'created' => '2007-03-18 10:43:23',
7592
					'updated' => '2007-03-18 10:45:31'
7593
				),
7594
				'User' => array(
7595
					'id' => '1',
7596
					'user' => 'mariano',
7597
					'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
7598
					'created' => '2007-03-17 01:16:23',
7599
					'updated' => '2007-03-17 01:18:31'
7600
				),
7601
				'Comment' => array(),
7602
				'Tag' => array()
7603
			)
7604
		);
7605
		$this->assertEquals($expected, $result);
7606
 
7607
		$TestModel->hasMany['Comment']['limit'] = 1;
7608
 
7609
		$result = $TestModel->find('all', array(
7610
			'conditions' => array('Article.user_id' => 3),
7611
			'limit' => 1,
7612
			'recursive' => 2
7613
		));
7614
		$expected = array(
7615
			array(
7616
				'Article' => array(
7617
					'id' => '2',
7618
					'user_id' => '3',
7619
					'title' => 'Second Article',
7620
					'body' => 'Second Article Body',
7621
					'published' => 'Y',
7622
					'created' => '2007-03-18 10:41:23',
7623
					'updated' => '2007-03-18 10:43:31'
7624
				),
7625
				'User' => array(
7626
					'id' => '3',
7627
					'user' => 'larry',
7628
					'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
7629
					'created' => '2007-03-17 01:20:23',
7630
					'updated' => '2007-03-17 01:22:31'
7631
				),
7632
				'Comment' => array(
7633
					array(
7634
						'id' => '5',
7635
						'article_id' => '2',
7636
						'user_id' => '1',
7637
						'comment' => 'First Comment for Second Article',
7638
						'published' => 'Y',
7639
						'created' => '2007-03-18 10:53:23',
7640
						'updated' => '2007-03-18 10:55:31',
7641
						'Article' => array(
7642
							'id' => '2',
7643
							'user_id' => '3',
7644
							'title' => 'Second Article',
7645
							'body' => 'Second Article Body',
7646
							'published' => 'Y',
7647
							'created' => '2007-03-18 10:41:23',
7648
							'updated' => '2007-03-18 10:43:31'
7649
						),
7650
						'User' => array(
7651
							'id' => '1',
7652
							'user' => 'mariano',
7653
							'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
7654
							'created' => '2007-03-17 01:16:23',
7655
							'updated' => '2007-03-17 01:18:31'
7656
						),
7657
						'Attachment' => array(
7658
							'id' => '1',
7659
							'comment_id' => 5,
7660
							'attachment' => 'attachment.zip',
7661
							'created' => '2007-03-18 10:51:23',
7662
							'updated' => '2007-03-18 10:53:31'
7663
						)
7664
					)
7665
				),
7666
				'Tag' => array(
7667
					array(
7668
						'id' => '1',
7669
						'tag' => 'tag1',
7670
						'created' => '2007-03-18 12:22:23',
7671
						'updated' => '2007-03-18 12:24:31'
7672
					),
7673
					array(
7674
						'id' => '3',
7675
						'tag' => 'tag3',
7676
						'created' => '2007-03-18 12:26:23',
7677
						'updated' => '2007-03-18 12:28:31'
7678
					)
7679
				)
7680
			)
7681
		);
7682
		$this->assertEquals($expected, $result);
7683
	}
7684
 
7685
/**
7686
 * Testing availability of $this->findQueryType in Model callbacks
7687
 *
7688
 * @return void
7689
 */
7690
	public function testFindQueryTypeInCallbacks() {
7691
		$this->loadFixtures('Comment');
7692
		$Comment = new AgainModifiedComment();
7693
		$comments = $Comment->find('all');
7694
		$this->assertEquals('all', $comments[0]['Comment']['querytype']);
7695
		$comments = $Comment->find('first');
7696
		$this->assertEquals('first', $comments['Comment']['querytype']);
7697
	}
7698
 
7699
/**
7700
 * testVirtualFields()
7701
 *
7702
 * Test correct fetching of virtual fields
7703
 * currently is not possible to do Relation.virtualField
7704
 *
7705
 * @return void
7706
 */
7707
	public function testVirtualFields() {
7708
		$this->loadFixtures('Post', 'Author');
7709
		$Post = ClassRegistry::init('Post');
7710
		$Post->virtualFields = array('two' => "1 + 1");
7711
		$result = $Post->find('first');
7712
		$this->assertEquals(2, $result['Post']['two']);
7713
 
7714
		// SQL Server does not support operators in expressions
7715
		if (!($this->db instanceof Sqlserver)) {
7716
			$Post->Author->virtualFields = array('false' => '1 = 2');
7717
			$result = $Post->find('first');
7718
			$this->assertEquals(2, $result['Post']['two']);
7719
			$this->assertFalse((bool)$result['Author']['false']);
7720
		}
7721
 
7722
		$result = $Post->find('first', array('fields' => array('author_id')));
7723
		$this->assertFalse(isset($result['Post']['two']));
7724
		$this->assertFalse(isset($result['Author']['false']));
7725
 
7726
		$result = $Post->find('first', array('fields' => array('author_id', 'two')));
7727
		$this->assertEquals(2, $result['Post']['two']);
7728
		$this->assertFalse(isset($result['Author']['false']));
7729
 
7730
		$result = $Post->find('first', array('fields' => array('two')));
7731
		$this->assertEquals(2, $result['Post']['two']);
7732
 
7733
		$Post->id = 1;
7734
		$result = $Post->field('two');
7735
		$this->assertEquals(2, $result);
7736
 
7737
		$result = $Post->find('first', array(
7738
			'conditions' => array('two' => 2),
7739
			'limit' => 1
7740
		));
7741
		$this->assertEquals(2, $result['Post']['two']);
7742
 
7743
		$result = $Post->find('first', array(
7744
			'conditions' => array('two <' => 3),
7745
			'limit' => 1
7746
		));
7747
		$this->assertEquals(2, $result['Post']['two']);
7748
 
7749
		$result = $Post->find('first', array(
7750
			'conditions' => array('NOT' => array('two >' => 3)),
7751
			'limit' => 1
7752
		));
7753
		$this->assertEquals(2, $result['Post']['two']);
7754
 
7755
		$dbo = $Post->getDataSource();
7756
		$Post->virtualFields = array('other_field' => 'Post.id + 1');
7757
		$result = $Post->find('first', array(
7758
			'conditions' => array('other_field' => 3),
7759
			'limit' => 1
7760
		));
7761
		$this->assertEquals(2, $result['Post']['id']);
7762
		$Post->order = null;
7763
 
7764
		$Post->virtualFields = array('other_field' => 'Post.id + 1');
7765
		$result = $Post->find('all', array(
7766
			'fields' => array($dbo->calculate($Post, 'max', array('other_field')))
7767
		));
7768
		$this->assertEquals(4, $result[0][0]['other_field']);
7769
 
7770
		ClassRegistry::flush();
7771
		$Writing = ClassRegistry::init(array('class' => 'Post', 'alias' => 'Writing'));
7772
		$Writing->virtualFields = array('two' => "1 + 1");
7773
		$result = $Writing->find('first');
7774
		$this->assertEquals(2, $result['Writing']['two']);
7775
 
7776
		$Post->create();
7777
		$Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1');
7778
		$result = $Post->field('other_field');
7779
		$this->assertEquals(4, $result);
7780
	}
7781
 
7782
/**
7783
 * testVirtualFieldsOrder()
7784
 *
7785
 * Test correct order on virtual fields
7786
 *
7787
 * @return void
7788
 */
7789
	public function testVirtualFieldsOrder() {
7790
		$this->loadFixtures('Post', 'Author');
7791
		$Post = ClassRegistry::init('Post');
7792
		$Post->virtualFields = array('other_field' => '10 - Post.id');
7793
		$result = $Post->find('list', array('order' => array('Post.other_field' => 'ASC')));
7794
		$expected = array(
7795
			'3' => 'Third Post',
7796
			'2' => 'Second Post',
7797
			'1' => 'First Post'
7798
		);
7799
		$this->assertEquals($expected, $result);
7800
 
7801
		$result = $Post->find('list', array('order' => array('Post.other_field' => 'DESC')));
7802
		$expected = array(
7803
			'1' => 'First Post',
7804
			'2' => 'Second Post',
7805
			'3' => 'Third Post'
7806
		);
7807
		$this->assertEquals($expected, $result);
7808
 
7809
		$Post->Author->virtualFields = array('joined' => 'Post.id * Author.id');
7810
		$result = $Post->find('all', array(
7811
			'order' => array('Post.id' => 'ASC')
7812
		));
7813
		$result = Hash::extract($result, '{n}.Author.joined');
7814
		$expected = array(1, 6, 3);
7815
		$this->assertEquals($expected, $result);
7816
 
7817
		$result = $Post->find('all', array('order' => array('Author.joined' => 'ASC')));
7818
		$result = Hash::extract($result, '{n}.Author.joined');
7819
		$expected = array(1, 3, 6);
7820
		$this->assertEquals($expected, $result);
7821
 
7822
		$result = $Post->find('all', array('order' => array('Author.joined' => 'DESC')));
7823
		$result = Hash::extract($result, '{n}.Author.joined');
7824
		$expected = array(6, 3, 1);
7825
		$this->assertEquals($expected, $result);
7826
	}
7827
 
7828
/**
7829
 * testVirtualFieldsMysql()
7830
 *
7831
 * Test correct fetching of virtual fields
7832
 * currently is not possible to do Relation.virtualField
7833
 *
7834
 * @return void
7835
 */
7836
	public function testVirtualFieldsMysql() {
7837
		$this->skipIf(!($this->db instanceof Mysql), 'The rest of virtualFields test only compatible with Mysql.');
7838
 
7839
		$this->loadFixtures('Post', 'Author');
7840
		$Post = ClassRegistry::init('Post');
7841
 
7842
		$Post->create();
7843
		$Post->virtualFields = array(
7844
			'low_title' => 'lower(Post.title)',
7845
			'unique_test_field' => 'COUNT(Post.id)'
7846
		);
7847
 
7848
		$expectation = array(
7849
			'Post' => array(
7850
				'low_title' => 'first post',
7851
				'unique_test_field' => 1
7852
			)
7853
		);
7854
 
7855
		$result = $Post->find('first', array(
7856
			'fields' => array_keys($Post->virtualFields),
7857
			'group' => array('low_title')
7858
		));
7859
 
7860
		$this->assertEquals($expectation, $result);
7861
 
7862
		$Author = ClassRegistry::init('Author');
7863
		$Author->virtualFields = array(
7864
			'full_name' => 'CONCAT(Author.user, " ", Author.id)'
7865
		);
7866
 
7867
		$result = $Author->find('first', array(
7868
			'conditions' => array('Author.user' => 'mariano'),
7869
			'fields' => array('Author.password', 'Author.full_name'),
7870
			'recursive' => -1
7871
		));
7872
		$this->assertTrue(isset($result['Author']['full_name']));
7873
 
7874
		$result = $Author->find('first', array(
7875
			'conditions' => array('Author.user' => 'mariano'),
7876
			'fields' => array('Author.full_name', 'Author.password'),
7877
			'recursive' => -1
7878
		));
7879
		$this->assertTrue(isset($result['Author']['full_name']));
7880
	}
7881
 
7882
/**
7883
 * test that virtual fields work when they don't contain functions.
7884
 *
7885
 * @return void
7886
 */
7887
	public function testVirtualFieldAsAString() {
7888
		$this->loadFixtures('Post', 'Author');
7889
		$Post = new Post();
7890
		$Post->virtualFields = array(
7891
			'writer' => 'Author.user'
7892
		);
7893
		$result = $Post->find('first');
7894
		$this->assertTrue(isset($result['Post']['writer']), 'virtual field not fetched %s');
7895
	}
7896
 
7897
/**
7898
 * test that isVirtualField will accept both aliased and non aliased fieldnames
7899
 *
7900
 * @return void
7901
 */
7902
	public function testIsVirtualField() {
7903
		$this->loadFixtures('Post');
7904
		$Post = ClassRegistry::init('Post');
7905
		$Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1');
7906
 
7907
		$this->assertTrue($Post->isVirtualField('other_field'));
7908
		$this->assertTrue($Post->isVirtualField('Post.other_field'));
7909
		$this->assertFalse($Post->isVirtualField('Comment.other_field'), 'Other models should not match.');
7910
		$this->assertFalse($Post->isVirtualField('id'));
7911
		$this->assertFalse($Post->isVirtualField('Post.id'));
7912
		$this->assertFalse($Post->isVirtualField(array()));
7913
	}
7914
 
7915
/**
7916
 * test that getting virtual fields works with and without model alias attached
7917
 *
7918
 * @return void
7919
 */
7920
	public function testGetVirtualField() {
7921
		$this->loadFixtures('Post');
7922
		$Post = ClassRegistry::init('Post');
7923
		$Post->virtualFields = array('other_field' => 'COUNT(Post.id) + 1');
7924
 
7925
		$this->assertEquals($Post->getVirtualField('other_field'), $Post->virtualFields['other_field']);
7926
		$this->assertEquals($Post->getVirtualField('Post.other_field'), $Post->virtualFields['other_field']);
7927
	}
7928
 
7929
/**
7930
 * test that checks for error when NOT condition passed in key and a 1 element array value
7931
 *
7932
 * @return void
7933
 */
7934
	public function testNotInArrayWithOneValue() {
7935
		$this->loadFixtures('Article');
7936
		$Article = new Article();
7937
		$Article->recursive = -1;
7938
 
7939
		$result = $Article->find(
7940
			'all',
7941
			array(
7942
				'conditions' => array(
7943
					'Article.id NOT' => array(1)
7944
				)
7945
			)
7946
		);
7947
		$this->assertTrue(is_array($result) && !empty($result));
7948
	}
7949
 
7950
/**
7951
 * test to assert that != in key together with a single element array will work
7952
 *
7953
 * @return void
7954
 */
7955
	public function testNotEqualsInArrayWithOneValue() {
7956
		$this->loadFixtures('Article');
7957
		$Article = new Article();
7958
		$Article->recursive = -1;
7959
 
7960
		$result = $Article->find(
7961
			'all',
7962
			array(
7963
				'conditions' => array(
7964
					'Article.id !=' => array(1)
7965
				)
7966
			)
7967
		);
7968
		$this->assertTrue(is_array($result) && !empty($result));
7969
	}
7970
 
7971
/**
7972
 * test custom find method
7973
 *
7974
 * @return void
7975
 */
7976
	public function testfindCustom() {
7977
		$this->loadFixtures('Article');
7978
		$Article = new CustomArticle();
7979
		$data = array('user_id' => 3, 'title' => 'Fourth Article', 'body' => 'Article Body, unpublished', 'published' => 'N');
7980
		$Article->create($data);
7981
		$Article->save(null, false);
7982
		$this->assertEquals(4, $Article->id);
7983
 
7984
		$result = $Article->find('published');
7985
		$this->assertEquals(3, count($result));
7986
 
7987
		$result = $Article->find('unPublished');
7988
		$this->assertEquals(1, count($result));
7989
	}
7990
 
7991
/**
7992
 * test after find callback on related model
7993
 * 
7994
 * @return void 
7995
 */
7996
	public function testRelatedAfterFindCallback() {
7997
		$this->loadFixtures('Something', 'SomethingElse', 'JoinThing');
7998
		$Something = new Something();
7999
 
8000
		$Something->bindModel(array(
8001
			'hasMany' => array(
8002
				'HasMany' => array(
8003
					'className' => 'JoinThing',
8004
					'foreignKey' => 'something_id'
8005
				)
8006
			),
8007
			'hasOne' => array(
8008
				'HasOne' => array(
8009
					'className' => 'JoinThing',
8010
					'foreignKey' => 'something_id'
8011
				)
8012
			)
8013
		));
8014
 
8015
		$results = $Something->find('all');
8016
 
8017
		$expected = array(
8018
			array(
8019
				'Something' => array(
8020
					'id' => '1',
8021
					'title' => 'First Post',
8022
					'body' => 'First Post Body',
8023
					'published' => 'Y',
8024
					'created' => '2007-03-18 10:39:23',
8025
					'updated' => '2007-03-18 10:41:31'
8026
				),
8027
				'HasOne' => array(
8028
					'id' => '1',
8029
					'something_id' => '1',
8030
					'something_else_id' => '2',
8031
					'doomed' => true,
8032
					'created' => '2007-03-18 10:39:23',
8033
					'updated' => '2007-03-18 10:41:31',
8034
					'afterFind' => 'Successfully added by AfterFind'
8035
				),
8036
				'HasMany' => array(
8037
					array(
8038
						'id' => '1',
8039
						'something_id' => '1',
8040
						'something_else_id' => '2',
8041
						'doomed' => true,
8042
						'created' => '2007-03-18 10:39:23',
8043
						'updated' => '2007-03-18 10:41:31',
8044
						'afterFind' => 'Successfully added by AfterFind'
8045
					)
8046
				),
8047
				'SomethingElse' => array(
8048
					array(
8049
						'id' => '2',
8050
						'title' => 'Second Post',
8051
						'body' => 'Second Post Body',
8052
						'published' => 'Y',
8053
						'created' => '2007-03-18 10:41:23',
8054
						'updated' => '2007-03-18 10:43:31',
8055
						'afterFind' => 'Successfully added by AfterFind',
8056
						'JoinThing' => array(
8057
							'doomed' => true,
8058
							'something_id' => '1',
8059
							'something_else_id' => '2',
8060
							'afterFind' => 'Successfully added by AfterFind'
8061
						)
8062
					)
8063
				)
8064
			),
8065
			array(
8066
				'Something' => array(
8067
					'id' => '2',
8068
					'title' => 'Second Post',
8069
					'body' => 'Second Post Body',
8070
					'published' => 'Y',
8071
					'created' => '2007-03-18 10:41:23',
8072
					'updated' => '2007-03-18 10:43:31'
8073
				),
8074
				'HasOne' => array(
8075
					'id' => '2',
8076
					'something_id' => '2',
8077
					'something_else_id' => '3',
8078
					'doomed' => false,
8079
					'created' => '2007-03-18 10:41:23',
8080
					'updated' => '2007-03-18 10:43:31',
8081
					'afterFind' => 'Successfully added by AfterFind'
8082
				),
8083
				'HasMany' => array(
8084
					array(
8085
						'id' => '2',
8086
						'something_id' => '2',
8087
						'something_else_id' => '3',
8088
						'doomed' => false,
8089
						'created' => '2007-03-18 10:41:23',
8090
						'updated' => '2007-03-18 10:43:31',
8091
						'afterFind' => 'Successfully added by AfterFind'
8092
					)
8093
				),
8094
				'SomethingElse' => array(
8095
					array(
8096
						'id' => '3',
8097
						'title' => 'Third Post',
8098
						'body' => 'Third Post Body',
8099
						'published' => 'Y',
8100
						'created' => '2007-03-18 10:43:23',
8101
						'updated' => '2007-03-18 10:45:31',
8102
						'afterFind' => 'Successfully added by AfterFind',
8103
						'JoinThing' => array(
8104
							'doomed' => false,
8105
							'something_id' => '2',
8106
							'something_else_id' => '3',
8107
							'afterFind' => 'Successfully added by AfterFind'
8108
						)
8109
					)
8110
				)
8111
			),
8112
			array(
8113
				'Something' => array(
8114
					'id' => '3',
8115
					'title' => 'Third Post',
8116
					'body' => 'Third Post Body',
8117
					'published' => 'Y',
8118
					'created' => '2007-03-18 10:43:23',
8119
					'updated' => '2007-03-18 10:45:31'
8120
				),
8121
				'HasOne' => array(
8122
					'id' => '3',
8123
					'something_id' => '3',
8124
					'something_else_id' => '1',
8125
					'doomed' => true,
8126
					'created' => '2007-03-18 10:43:23',
8127
					'updated' => '2007-03-18 10:45:31',
8128
					'afterFind' => 'Successfully added by AfterFind'
8129
				),
8130
				'HasMany' => array(
8131
					array(
8132
						'id' => '3',
8133
						'something_id' => '3',
8134
						'something_else_id' => '1',
8135
						'doomed' => true,
8136
						'created' => '2007-03-18 10:43:23',
8137
						'updated' => '2007-03-18 10:45:31',
8138
						'afterFind' => 'Successfully added by AfterFind'
8139
					)
8140
				),
8141
				'SomethingElse' => array(
8142
					array(
8143
						'id' => '1',
8144
						'title' => 'First Post',
8145
						'body' => 'First Post Body',
8146
						'published' => 'Y',
8147
						'created' => '2007-03-18 10:39:23',
8148
						'updated' => '2007-03-18 10:41:31',
8149
						'afterFind' => 'Successfully added by AfterFind',
8150
						'JoinThing' => array(
8151
							'doomed' => true,
8152
							'something_id' => '3',
8153
							'something_else_id' => '1',
8154
							'afterFind' => 'Successfully added by AfterFind'
8155
						)
8156
					)
8157
				)
8158
			)
8159
		);
8160
		$this->assertEquals($expected, $results, 'Model related with has* afterFind callback fails');
8161
 
8162
		$JoinThing = new JoinThing();
8163
		$JoinThing->unbindModel(array(
8164
			'belongsTo' => array(
8165
				'Something'
8166
			)
8167
		));
8168
		$results = $JoinThing->find('all');
8169
 
8170
		$expected = array(
8171
			array(
8172
				'JoinThing' => array(
8173
					'id' => '1',
8174
					'something_id' => '1',
8175
					'something_else_id' => '2',
8176
					'doomed' => true,
8177
					'created' => '2007-03-18 10:39:23',
8178
					'updated' => '2007-03-18 10:41:31',
8179
					'afterFind' => 'Successfully added by AfterFind'
8180
				),
8181
				'SomethingElse' => array(
8182
					'id' => '2',
8183
					'title' => 'Second Post',
8184
					'body' => 'Second Post Body',
8185
					'published' => 'Y',
8186
					'created' => '2007-03-18 10:41:23',
8187
					'updated' => '2007-03-18 10:43:31',
8188
					'afterFind' => 'Successfully added by AfterFind'
8189
				)
8190
			),
8191
			array(
8192
				'JoinThing' => array(
8193
					'id' => '2',
8194
					'something_id' => '2',
8195
					'something_else_id' => '3',
8196
					'doomed' => false,
8197
					'created' => '2007-03-18 10:41:23',
8198
					'updated' => '2007-03-18 10:43:31',
8199
					'afterFind' => 'Successfully added by AfterFind'
8200
				),
8201
				'SomethingElse' => array(
8202
					'id' => '3',
8203
					'title' => 'Third Post',
8204
					'body' => 'Third Post Body',
8205
					'published' => 'Y',
8206
					'created' => '2007-03-18 10:43:23',
8207
					'updated' => '2007-03-18 10:45:31',
8208
					'afterFind' => 'Successfully added by AfterFind'
8209
				)
8210
			),
8211
			array(
8212
				'JoinThing' => array(
8213
					'id' => '3',
8214
					'something_id' => '3',
8215
					'something_else_id' => '1',
8216
					'doomed' => true,
8217
					'created' => '2007-03-18 10:43:23',
8218
					'updated' => '2007-03-18 10:45:31',
8219
					'afterFind' => 'Successfully added by AfterFind'
8220
				),
8221
				'SomethingElse' => array(
8222
					'id' => '1',
8223
					'title' => 'First Post',
8224
					'body' => 'First Post Body',
8225
					'published' => 'Y',
8226
					'created' => '2007-03-18 10:39:23',
8227
					'updated' => '2007-03-18 10:41:31',
8228
					'afterFind' => 'Successfully added by AfterFind'
8229
				)
8230
			)
8231
		);
8232
		$this->assertEquals($expected, $results, 'Model related with belongsTo afterFind callback fails');
8233
	}
8234
}