Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

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