Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

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