Skip to content
This repository
Browse code

Splitting model tests into separate files to allow more fine-grained …

…test running.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8255 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information...
commit 9d7b5608178f2a0e690a74223e6b3f4ca0674305 1 parent 565cd96
Joel Perras authored July 24, 2009
13,427  cake/tests/cases/libs/model/model.test.php
2 additions, 13425 deletions not shown
571  cake/tests/cases/libs/model/model_delete.test.php
... ...
@@ -0,0 +1,571 @@
  1
+<?php
  2
+/* SVN FILE: $Id: model.test.php 8225 2009-07-08 03:25:30Z mark_story $ */
  3
+/**
  4
+ * ModelDeleteTest file
  5
+ *
  6
+ * Long description for file
  7
+ *
  8
+ * PHP versions 4 and 5
  9
+ *
  10
+ * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
  11
+ * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
  12
+ *
  13
+ *  Licensed under The Open Group Test Suite License
  14
+ *  Redistributions of files must retain the above copyright notice.
  15
+ *
  16
+ * @filesource
  17
+ * @copyright     Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
  18
+ * @link          https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
  19
+ * @package       cake
  20
+ * @subpackage    cake.tests.cases.libs.model
  21
+ * @since         CakePHP(tm) v 1.2.0.4206
  22
+ * @version       $Revision: 8225 $
  23
+ * @modifiedby    $LastChangedBy: mark_story $
  24
+ * @lastmodified  $Date: 2009-07-07 23:25:30 -0400 (Tue, 07 Jul 2009) $
  25
+ * @license       http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  26
+ */
  27
+require_once dirname(__FILE__) . DS . 'model.test.php';
  28
+require_once dirname(__FILE__) . DS . 'model_delete.test.php';
  29
+/**
  30
+ * ModelDeleteTest
  31
+ *
  32
+ * @package       cake
  33
+ * @subpackage    cake.tests.cases.libs.model.operations
  34
+ */
  35
+class ModelDeleteTest extends BaseModelTest {
  36
+/**
  37
+ * testDeleteHabtmReferenceWithConditions method
  38
+ *
  39
+ * @access public
  40
+ * @return void
  41
+ */
  42
+	function testDeleteHabtmReferenceWithConditions() {
  43
+		$this->loadFixtures('Portfolio', 'Item', 'ItemsPortfolio');
  44
+
  45
+		$Portfolio =& new Portfolio();
  46
+		$Portfolio->hasAndBelongsToMany['Item']['conditions'] = array('ItemsPortfolio.item_id >' => 1);
  47
+
  48
+		$result = $Portfolio->find('first', array(
  49
+			'conditions' => array('Portfolio.id' => 1)
  50
+		));
  51
+		$expected = array(
  52
+			array(
  53
+				'id' => 3,
  54
+				'syfile_id' => 3,
  55
+				'published' => 0,
  56
+				'name' => 'Item 3',
  57
+				'ItemsPortfolio' => array(
  58
+					'id' => 3,
  59
+					'item_id' => 3,
  60
+					'portfolio_id' => 1
  61
+			)),
  62
+			array(
  63
+				'id' => 4,
  64
+				'syfile_id' => 4,
  65
+				'published' => 0,
  66
+				'name' => 'Item 4',
  67
+				'ItemsPortfolio' => array(
  68
+					'id' => 4,
  69
+					'item_id' => 4,
  70
+					'portfolio_id' => 1
  71
+			)),
  72
+			array(
  73
+				'id' => 5,
  74
+				'syfile_id' => 5,
  75
+				'published' => 0,
  76
+				'name' => 'Item 5',
  77
+				'ItemsPortfolio' => array(
  78
+					'id' => 5,
  79
+					'item_id' => 5,
  80
+					'portfolio_id' => 1
  81
+		)));
  82
+		$this->assertEqual($result['Item'], $expected);
  83
+
  84
+		$result = $Portfolio->ItemsPortfolio->find('all', array(
  85
+			'conditions' => array('ItemsPortfolio.portfolio_id' => 1)
  86
+		));
  87
+		$expected = array(
  88
+			array(
  89
+				'ItemsPortfolio' => array(
  90
+					'id' => 1,
  91
+					'item_id' => 1,
  92
+					'portfolio_id' => 1
  93
+			)),
  94
+			array(
  95
+				'ItemsPortfolio' => array(
  96
+					'id' => 3,
  97
+					'item_id' => 3,
  98
+					'portfolio_id' => 1
  99
+			)),
  100
+			array(
  101
+				'ItemsPortfolio' => array(
  102
+					'id' => 4,
  103
+					'item_id' => 4,
  104
+					'portfolio_id' => 1
  105
+			)),
  106
+			array(
  107
+				'ItemsPortfolio' => array(
  108
+					'id' => 5,
  109
+					'item_id' => 5,
  110
+					'portfolio_id' => 1
  111
+		)));
  112
+		$this->assertEqual($result, $expected);
  113
+
  114
+		$Portfolio->delete(1);
  115
+
  116
+		$result = $Portfolio->find('first', array(
  117
+			'conditions' => array('Portfolio.id' => 1)
  118
+		));
  119
+		$this->assertFalse($result);
  120
+
  121
+		$result = $Portfolio->ItemsPortfolio->find('all', array(
  122
+			'conditions' => array('ItemsPortfolio.portfolio_id' => 1)
  123
+		));
  124
+		$this->assertFalse($result);
  125
+	}
  126
+/**
  127
+ * testDeleteArticleBLinks method
  128
+ *
  129
+ * @access public
  130
+ * @return void
  131
+ */
  132
+	function testDeleteArticleBLinks() {
  133
+		$this->loadFixtures('Article', 'ArticlesTag', 'Tag');
  134
+		$TestModel =& new ArticleB();
  135
+
  136
+		$result = $TestModel->ArticlesTag->find('all');
  137
+		$expected = array(
  138
+			array('ArticlesTag' => array('article_id' => '1', 'tag_id' => '1')),
  139
+			array('ArticlesTag' => array('article_id' => '1', 'tag_id' => '2')),
  140
+			array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '1')),
  141
+			array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '3'))
  142
+			);
  143
+		$this->assertEqual($result, $expected);
  144
+
  145
+		$TestModel->delete(1);
  146
+		$result = $TestModel->ArticlesTag->find('all');
  147
+
  148
+		$expected = array(
  149
+			array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '1')),
  150
+			array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '3'))
  151
+		);
  152
+		$this->assertEqual($result, $expected);
  153
+	}
  154
+/**
  155
+ * testDeleteDependentWithConditions method
  156
+ *
  157
+ * @access public
  158
+ * @return void
  159
+ */
  160
+	function testDeleteDependentWithConditions() {
  161
+		$this->loadFixtures('Cd','Book','OverallFavorite');
  162
+
  163
+		$Cd =& new Cd();
  164
+		$OverallFavorite =& new OverallFavorite();
  165
+
  166
+		$Cd->del(1);
  167
+
  168
+		$result = $OverallFavorite->find('all', array(
  169
+			'fields' => array('model_type', 'model_id', 'priority')
  170
+		));
  171
+		$expected = array(
  172
+			array(
  173
+				'OverallFavorite' => array(
  174
+					'model_type' => 'Book',
  175
+					'model_id' => 1,
  176
+					'priority' => 2
  177
+		)));
  178
+
  179
+		$this->assertTrue(is_array($result));
  180
+		$this->assertEqual($result, $expected);
  181
+	}
  182
+/**
  183
+ * testDel method
  184
+ *
  185
+ * @access public
  186
+ * @return void
  187
+ */
  188
+	function testDel() {
  189
+		$this->loadFixtures('Article');
  190
+		$TestModel =& new Article();
  191
+
  192
+		$result = $TestModel->del(2);
  193
+		$this->assertTrue($result);
  194
+
  195
+		$result = $TestModel->read(null, 2);
  196
+		$this->assertFalse($result);
  197
+
  198
+		$TestModel->recursive = -1;
  199
+		$result = $TestModel->find('all', array(
  200
+			'fields' => array('id', 'title')
  201
+		));
  202
+		$expected = array(
  203
+			array('Article' => array(
  204
+				'id' => 1,
  205
+				'title' => 'First Article'
  206
+			)),
  207
+			array('Article' => array(
  208
+				'id' => 3,
  209
+				'title' => 'Third Article'
  210
+		)));
  211
+		$this->assertEqual($result, $expected);
  212
+
  213
+		$result = $TestModel->del(3);
  214
+		$this->assertTrue($result);
  215
+
  216
+		$result = $TestModel->read(null, 3);
  217
+		$this->assertFalse($result);
  218
+
  219
+		$TestModel->recursive = -1;
  220
+		$result = $TestModel->find('all', array(
  221
+			'fields' => array('id', 'title')
  222
+		));
  223
+		$expected = array(
  224
+			array('Article' => array(
  225
+				'id' => 1,
  226
+				'title' => 'First Article'
  227
+		)));
  228
+
  229
+		$this->assertEqual($result, $expected);
  230
+
  231
+
  232
+		// make sure deleting a non-existent record doesn't break save()
  233
+		// ticket #6293
  234
+		$this->loadFixtures('Uuid');
  235
+		$Uuid =& new Uuid();
  236
+		$data = array(
  237
+			'B607DAB9-88A2-46CF-B57C-842CA9E3B3B3',
  238
+			'52C8865C-10EE-4302-AE6C-6E7D8E12E2C8',
  239
+			'8208C7FE-E89C-47C5-B378-DED6C271F9B8');
  240
+		foreach ($data as $id) {
  241
+			$Uuid->save(array('id' => $id));
  242
+		}
  243
+		$Uuid->del('52C8865C-10EE-4302-AE6C-6E7D8E12E2C8');
  244
+		$Uuid->del('52C8865C-10EE-4302-AE6C-6E7D8E12E2C8');
  245
+		foreach ($data as $id) {
  246
+			$Uuid->save(array('id' => $id));
  247
+		}
  248
+		$result = $Uuid->find('all', array(
  249
+			'conditions' => array('id' => $data),
  250
+			'fields' => array('id'),
  251
+			'order' => 'id'));
  252
+		$expected = array(
  253
+			array('Uuid' => array(
  254
+				'id' => '52C8865C-10EE-4302-AE6C-6E7D8E12E2C8')),
  255
+			array('Uuid' => array(
  256
+				'id' => '8208C7FE-E89C-47C5-B378-DED6C271F9B8')),
  257
+			array('Uuid' => array(
  258
+				'id' => 'B607DAB9-88A2-46CF-B57C-842CA9E3B3B3')));
  259
+		$this->assertEqual($result, $expected);
  260
+	}
  261
+/**
  262
+ * testDeleteAll method
  263
+ *
  264
+ * @access public
  265
+ * @return void
  266
+ */
  267
+	function testDeleteAll() {
  268
+		$this->loadFixtures('Article');
  269
+		$TestModel =& new Article();
  270
+
  271
+		$data = array('Article' => array(
  272
+			'user_id' => 2,
  273
+			'id' => 4,
  274
+			'title' => 'Fourth Article',
  275
+			'published' => 'N'
  276
+		));
  277
+		$result = $TestModel->set($data) && $TestModel->save();
  278
+		$this->assertTrue($result);
  279
+
  280
+		$data = array('Article' => array(
  281
+			'user_id' => 2,
  282
+			'id' => 5,
  283
+			'title' => 'Fifth Article',
  284
+			'published' => 'Y'
  285
+		));
  286
+		$result = $TestModel->set($data) && $TestModel->save();
  287
+		$this->assertTrue($result);
  288
+
  289
+		$data = array('Article' => array(
  290
+			'user_id' => 1,
  291
+			'id' => 6,
  292
+			'title' => 'Sixth Article',
  293
+			'published' => 'N'
  294
+		));
  295
+		$result = $TestModel->set($data) && $TestModel->save();
  296
+		$this->assertTrue($result);
  297
+
  298
+		$TestModel->recursive = -1;
  299
+		$result = $TestModel->find('all', array(
  300
+			'fields' => array('id', 'user_id', 'title', 'published')
  301
+		));
  302
+
  303
+		$expected = array(
  304
+			array('Article' => array(
  305
+				'id' => 1,
  306
+				'user_id' => 1,
  307
+				'title' => 'First Article',
  308
+				'published' => 'Y'
  309
+			)),
  310
+			array('Article' => array(
  311
+				'id' => 2,
  312
+				'user_id' => 3,
  313
+				'title' => 'Second Article',
  314
+				'published' => 'Y'
  315
+			)),
  316
+			array('Article' => array(
  317
+				'id' => 3,
  318
+				'user_id' => 1,
  319
+				'title' => 'Third Article',
  320
+				'published' => 'Y')),
  321
+			array('Article' => array(
  322
+				'id' => 4,
  323
+				'user_id' => 2,
  324
+				'title' => 'Fourth Article',
  325
+				'published' => 'N'
  326
+			)),
  327
+			array('Article' => array(
  328
+				'id' => 5,
  329
+				'user_id' => 2,
  330
+				'title' => 'Fifth Article',
  331
+				'published' => 'Y'
  332
+			)),
  333
+			array('Article' => array(
  334
+				'id' => 6,
  335
+				'user_id' => 1,
  336
+				'title' => 'Sixth Article',
  337
+				'published' => 'N'
  338
+		)));
  339
+
  340
+		$this->assertEqual($result, $expected);
  341
+
  342
+		$result = $TestModel->deleteAll(array('Article.published' => 'N'));
  343
+		$this->assertTrue($result);
  344
+
  345
+		$TestModel->recursive = -1;
  346
+		$result = $TestModel->find('all', array(
  347
+			'fields' => array('id', 'user_id', 'title', 'published')
  348
+		));
  349
+		$expected = array(
  350
+			array('Article' => array(
  351
+				'id' => 1,
  352
+				'user_id' => 1,
  353
+				'title' => 'First Article',
  354
+				'published' => 'Y'
  355
+			)),
  356
+			array('Article' => array(
  357
+				'id' => 2,
  358
+				'user_id' => 3,
  359
+				'title' => 'Second Article',
  360
+				'published' => 'Y'
  361
+			)),
  362
+			array('Article' => array(
  363
+				'id' => 3,
  364
+				'user_id' => 1,
  365
+				'title' => 'Third Article',
  366
+				'published' => 'Y'
  367
+			)),
  368
+			array('Article' => array(
  369
+				'id' => 5,
  370
+				'user_id' => 2,
  371
+				'title' => 'Fifth Article',
  372
+				'published' => 'Y'
  373
+		)));
  374
+		$this->assertEqual($result, $expected);
  375
+
  376
+		$data = array('Article.user_id' => array(2, 3));
  377
+		$result = $TestModel->deleteAll($data, true, true);
  378
+		$this->assertTrue($result);
  379
+
  380
+		$TestModel->recursive = -1;
  381
+		$result = $TestModel->find('all', array(
  382
+			'fields' => array('id', 'user_id', 'title', 'published')
  383
+		));
  384
+		$expected = array(
  385
+			array('Article' => array(
  386
+				'id' => 1,
  387
+				'user_id' => 1,
  388
+				'title' => 'First Article',
  389
+				'published' => 'Y'
  390
+			)),
  391
+			array('Article' => array(
  392
+				'id' => 3,
  393
+				'user_id' => 1,
  394
+				'title' => 'Third Article',
  395
+				'published' => 'Y'
  396
+		)));
  397
+		$this->assertEqual($result, $expected);
  398
+
  399
+		$result = $TestModel->deleteAll(array('Article.user_id' => 999));
  400
+		$this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s');
  401
+	}
  402
+/**
  403
+ * testRecursiveDel method
  404
+ *
  405
+ * @access public
  406
+ * @return void
  407
+ */
  408
+	function testRecursiveDel() {
  409
+		$this->loadFixtures('Article', 'Comment', 'Attachment');
  410
+		$TestModel =& new Article();
  411
+
  412
+		$result = $TestModel->del(2);
  413
+		$this->assertTrue($result);
  414
+
  415
+		$TestModel->recursive = 2;
  416
+		$result = $TestModel->read(null, 2);
  417
+		$this->assertFalse($result);
  418
+
  419
+		$result = $TestModel->Comment->read(null, 5);
  420
+		$this->assertFalse($result);
  421
+
  422
+		$result = $TestModel->Comment->read(null, 6);
  423
+		$this->assertFalse($result);
  424
+
  425
+		$result = $TestModel->Comment->Attachment->read(null, 1);
  426
+		$this->assertFalse($result);
  427
+
  428
+		$result = $TestModel->find('count');
  429
+		$this->assertEqual($result, 2);
  430
+
  431
+		$result = $TestModel->Comment->find('count');
  432
+		$this->assertEqual($result, 4);
  433
+
  434
+		$result = $TestModel->Comment->Attachment->find('count');
  435
+		$this->assertEqual($result, 0);
  436
+	}
  437
+/**
  438
+ * testDependentExclusiveDelete method
  439
+ *
  440
+ * @access public
  441
+ * @return void
  442
+ */
  443
+	function testDependentExclusiveDelete() {
  444
+		$this->loadFixtures('Article', 'Comment');
  445
+		$TestModel =& new Article10();
  446
+
  447
+		$result = $TestModel->find('all');
  448
+		$this->assertEqual(count($result[0]['Comment']), 4);
  449
+		$this->assertEqual(count($result[1]['Comment']), 2);
  450
+		$this->assertEqual($TestModel->Comment->find('count'), 6);
  451
+
  452
+		$TestModel->delete(1);
  453
+		$this->assertEqual($TestModel->Comment->find('count'), 2);
  454
+	}
  455
+/**
  456
+ * testDeleteLinks method
  457
+ *
  458
+ * @access public
  459
+ * @return void
  460
+ */
  461
+	function testDeleteLinks() {
  462
+		$this->loadFixtures('Article', 'ArticlesTag', 'Tag');
  463
+		$TestModel =& new Article();
  464
+
  465
+		$result = $TestModel->ArticlesTag->find('all');
  466
+		$expected = array(
  467
+			array('ArticlesTag' => array(
  468
+				'article_id' => '1',
  469
+				'tag_id' => '1'
  470
+			)),
  471
+			array('ArticlesTag' => array(
  472
+				'article_id' => '1',
  473
+				'tag_id' => '2'
  474
+			)),
  475
+			array('ArticlesTag' => array(
  476
+				'article_id' => '2',
  477
+				'tag_id' => '1'
  478
+			)),
  479
+			array('ArticlesTag' => array(
  480
+				'article_id' => '2',
  481
+				'tag_id' => '3'
  482
+		)));
  483
+		$this->assertEqual($result, $expected);
  484
+
  485
+		$TestModel->delete(1);
  486
+		$result = $TestModel->ArticlesTag->find('all');
  487
+
  488
+		$expected = array(
  489
+			array('ArticlesTag' => array(
  490
+				'article_id' => '2',
  491
+				'tag_id' => '1'
  492
+			)),
  493
+			array('ArticlesTag' => array(
  494
+				'article_id' => '2',
  495
+				'tag_id' => '3'
  496
+		)));
  497
+		$this->assertEqual($result, $expected);
  498
+
  499
+		$result = $TestModel->deleteAll(array('Article.user_id' => 999));
  500
+		$this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s');
  501
+	}
  502
+/**
  503
+ * testHabtmDeleteLinksWhenNoPrimaryKeyInJoinTable method
  504
+ *
  505
+ * @access public
  506
+ * @return void
  507
+ */
  508
+	function testHabtmDeleteLinksWhenNoPrimaryKeyInJoinTable() {
  509
+
  510
+		$this->loadFixtures('Apple', 'Device', 'ThePaperMonkies');
  511
+		$ThePaper =& new ThePaper();
  512
+		$ThePaper->id = 1;
  513
+		$ThePaper->save(array('Monkey' => array(2, 3)));
  514
+
  515
+		$result = $ThePaper->findById(1);
  516
+		$expected = array(
  517
+			array(
  518
+				'id' => '2',
  519
+				'device_type_id' => '1',
  520
+				'name' => 'Device 2',
  521
+				'typ' => '1'
  522
+			),
  523
+			array(
  524
+				'id' => '3',
  525
+				'device_type_id' => '1',
  526
+				'name' => 'Device 3',
  527
+				'typ' => '2'
  528
+		));
  529
+		$this->assertEqual($result['Monkey'], $expected);
  530
+
  531
+		$ThePaper =& new ThePaper();
  532
+		$ThePaper->id = 2;
  533
+		$ThePaper->save(array('Monkey' => array(2, 3)));
  534
+
  535
+		$result = $ThePaper->findById(2);
  536
+		$expected = array(
  537
+			array(
  538
+				'id' => '2',
  539
+				'device_type_id' => '1',
  540
+				'name' => 'Device 2',
  541
+				'typ' => '1'
  542
+			),
  543
+			array(
  544
+				'id' => '3',
  545
+				'device_type_id' => '1',
  546
+				'name' => 'Device 3',
  547
+				'typ' => '2'
  548
+		));
  549
+		$this->assertEqual($result['Monkey'], $expected);
  550
+
  551
+		$ThePaper->delete(1);
  552
+		$result = $ThePaper->findById(2);
  553
+		$expected = array(
  554
+			array(
  555
+				'id' => '2',
  556
+				'device_type_id' => '1',
  557
+				'name' => 'Device 2',
  558
+				'typ' => '1'
  559
+			),
  560
+			array(
  561
+				'id' => '3',
  562
+				'device_type_id' => '1',
  563
+				'name' => 'Device 3',
  564
+				'typ' => '2'
  565
+		));
  566
+		$this->assertEqual($result['Monkey'], $expected);
  567
+	}
  568
+
  569
+}
  570
+
  571
+?>
1,837  cake/tests/cases/libs/model/model_integration.test.php
... ...
@@ -0,0 +1,1837 @@
  1
+<?php
  2
+/* SVN FILE: $Id: model.test.php 8225 2009-07-08 03:25:30Z mark_story $ */
  3
+/**
  4
+ * ModelDeleteTest file
  5
+ *
  6
+ * Long description for file
  7
+ *
  8
+ * PHP versions 4 and 5
  9
+ *
  10
+ * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
  11
+ * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
  12
+ *
  13
+ *  Licensed under The Open Group Test Suite License
  14
+ *  Redistributions of files must retain the above copyright notice.
  15
+ *
  16
+ * @filesource
  17
+ * @copyright     Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
  18
+ * @link          https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
  19
+ * @package       cake
  20
+ * @subpackage    cake.tests.cases.libs.model
  21
+ * @since         CakePHP(tm) v 1.2.0.4206
  22
+ * @version       $Revision: 8225 $
  23
+ * @modifiedby    $LastChangedBy: mark_story $
  24
+ * @lastmodified  $Date: 2009-07-07 23:25:30 -0400 (Tue, 07 Jul 2009) $
  25
+ * @license       http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  26
+ */
  27
+require_once dirname(__FILE__) . DS . 'model.test.php';
  28
+require_once dirname(__FILE__) . DS . 'model_integration.test.php';
  29
+
  30
+/**
  31
+ * ModelIntegrationTest
  32
+ *
  33
+ * @package       cake
  34
+ * @subpackage    cake.tests.cases.libs.model.operations
  35
+ */
  36
+class ModelIntegrationTest extends BaseModelTest {
  37
+/**
  38
+ * testPkInHAbtmLinkModelArticleB
  39
+ *
  40
+ * @access public
  41
+ * @return void
  42
+ */
  43
+	function testPkInHabtmLinkModelArticleB() {
  44
+		$this->loadFixtures('Article', 'Tag');
  45
+		$TestModel2 =& new ArticleB();
  46
+		$this->assertEqual($TestModel2->ArticlesTag->primaryKey, 'article_id');
  47
+	}
  48
+/**
  49
+ * Tests that $cacheSources can only be disabled in the db using model settings, not enabled
  50
+ *
  51
+ * @access public
  52
+ * @return void
  53
+ */
  54
+	function testCacheSourcesDisabling() {
  55
+		$this->db->cacheSources = true;
  56
+		$TestModel = new JoinA();
  57
+		$TestModel->cacheSources = false;
  58
+		$TestModel->setSource('join_as');
  59
+		$this->assertFalse($this->db->cacheSources);
  60
+
  61
+		$this->db->cacheSources = false;
  62
+		$TestModel = new JoinA();
  63
+		$TestModel->cacheSources = true;
  64
+		$TestModel->setSource('join_as');
  65
+		$this->assertFalse($this->db->cacheSources);
  66
+	}
  67
+/**
  68
+ * testPkInHabtmLinkModel method
  69
+ *
  70
+ * @access public
  71
+	 * @return void
  72
+ */
  73
+	function testPkInHabtmLinkModel() {
  74
+		//Test Nonconformant Models
  75
+		$this->loadFixtures('Content', 'ContentAccount', 'Account');
  76
+		$TestModel =& new Content();
  77
+		$this->assertEqual($TestModel->ContentAccount->primaryKey, 'iContentAccountsId');
  78
+
  79
+		//test conformant models with no PK in the join table
  80
+		$this->loadFixtures('Article', 'Tag');
  81
+		$TestModel2 =& new Article();
  82
+		$this->assertEqual($TestModel2->ArticlesTag->primaryKey, 'article_id');
  83
+
  84
+		//test conformant models with PK in join table
  85
+		$this->loadFixtures('Item', 'Portfolio', 'ItemsPortfolio');
  86
+		$TestModel3 =& new Portfolio();
  87
+		$this->assertEqual($TestModel3->ItemsPortfolio->primaryKey, 'id');
  88
+
  89
+		//test conformant models with PK in join table - join table contains extra field
  90
+		$this->loadFixtures('JoinA', 'JoinB', 'JoinAB');
  91
+		$TestModel4 =& new JoinA();
  92
+		$this->assertEqual($TestModel4->JoinAsJoinB->primaryKey, 'id');
  93
+
  94
+	}
  95
+/**
  96
+ * testDynamicBehaviorAttachment method
  97
+ *
  98
+ * @access public
  99
+ * @return void
  100
+ */
  101
+	function testDynamicBehaviorAttachment() {
  102
+		$this->loadFixtures('Apple');
  103
+		$TestModel =& new Apple();
  104
+		$this->assertEqual($TestModel->Behaviors->attached(), array());
  105
+
  106
+		$TestModel->Behaviors->attach('Tree', array('left' => 'left_field', 'right' => 'right_field'));
  107
+		$this->assertTrue(is_object($TestModel->Behaviors->Tree));
  108
+		$this->assertEqual($TestModel->Behaviors->attached(), array('Tree'));
  109
+
  110
+		$expected = array(
  111
+			'parent' => 'parent_id',
  112
+			'left' => 'left_field',
  113
+			'right' => 'right_field',
  114
+			'scope' => '1 = 1',
  115
+			'type' => 'nested',
  116
+			'__parentChange' => false,
  117
+			'recursive' => -1
  118
+		);
  119
+
  120
+		$this->assertEqual($TestModel->Behaviors->Tree->settings['Apple'], $expected);
  121
+
  122
+		$expected['enabled'] = false;
  123
+		$TestModel->Behaviors->attach('Tree', array('enabled' => false));
  124
+		$this->assertEqual($TestModel->Behaviors->Tree->settings['Apple'], $expected);
  125
+		$this->assertEqual($TestModel->Behaviors->attached(), array('Tree'));
  126
+
  127
+		$TestModel->Behaviors->detach('Tree');
  128
+		$this->assertEqual($TestModel->Behaviors->attached(), array());
  129
+		$this->assertFalse(isset($TestModel->Behaviors->Tree));
  130
+	}
  131
+/**
  132
+ * Tests cross database joins.  Requires $test and $test2 to both be set in DATABASE_CONFIG
  133
+ * NOTE: When testing on MySQL, you must set 'persistent' => false on *both* database connections,
  134
+ * or one connection will step on the other.
  135
+ */
  136
+	function testCrossDatabaseJoins() {
  137
+		$config = new DATABASE_CONFIG();
  138
+
  139
+		$skip = $this->skipIf(
  140
+			!isset($config->test) || !isset($config->test2),
  141
+			 '%s Primary and secondary test databases not configured, skipping cross-database '
  142
+			.'join tests.'
  143
+			.' To run these tests, you must define $test and $test2 in your database configuration.'
  144
+		);
  145
+
  146
+		if ($skip) {
  147
+			return;
  148
+		}
  149
+
  150
+		$this->loadFixtures('Article', 'Tag', 'ArticlesTag', 'User', 'Comment');
  151
+		$TestModel =& new Article();
  152
+
  153
+		$expected = array(
  154
+			array(
  155
+				'Article' => array(
  156
+					'id' => '1',
  157
+					'user_id' => '1',
  158
+					'title' => 'First Article',
  159
+					'body' => 'First Article Body',
  160
+					'published' => 'Y',
  161
+					'created' => '2007-03-18 10:39:23',
  162
+					'updated' => '2007-03-18 10:41:31'
  163
+				),
  164
+				'User' => array(
  165
+					'id' => '1',
  166
+					'user' => 'mariano',
  167
+					'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  168
+					'created' => '2007-03-17 01:16:23',
  169
+					'updated' => '2007-03-17 01:18:31'
  170
+				),
  171
+				'Comment' => array(
  172
+					array(
  173
+						'id' => '1',
  174
+						'article_id' => '1',
  175
+						'user_id' => '2',
  176
+						'comment' => 'First Comment for First Article',
  177
+						'published' => 'Y',
  178
+						'created' => '2007-03-18 10:45:23',
  179
+						'updated' => '2007-03-18 10:47:31'
  180
+					),
  181
+					array(
  182
+						'id' => '2',
  183
+						'article_id' => '1',
  184
+						'user_id' => '4',
  185
+						'comment' => 'Second Comment for First Article',
  186
+						'published' => 'Y',
  187
+						'created' => '2007-03-18 10:47:23',
  188
+						'updated' => '2007-03-18 10:49:31'
  189
+					),
  190
+					array(
  191
+						'id' => '3',
  192
+						'article_id' => '1',
  193
+						'user_id' => '1',
  194
+						'comment' => 'Third Comment for First Article',
  195
+						'published' => 'Y',
  196
+						'created' => '2007-03-18 10:49:23',
  197
+						'updated' => '2007-03-18 10:51:31'
  198
+					),
  199
+					array(
  200
+						'id' => '4',
  201
+						'article_id' => '1',
  202
+						'user_id' => '1',
  203
+						'comment' => 'Fourth Comment for First Article',
  204
+						'published' => 'N',
  205
+						'created' => '2007-03-18 10:51:23',
  206
+						'updated' => '2007-03-18 10:53:31'
  207
+				)),
  208
+				'Tag' => array(
  209
+					array(
  210
+						'id' => '1',
  211
+						'tag' => 'tag1',
  212
+						'created' => '2007-03-18 12:22:23',
  213
+						'updated' => '2007-03-18 12:24:31'
  214
+					),
  215
+					array(
  216
+						'id' => '2',
  217
+						'tag' => 'tag2',
  218
+						'created' => '2007-03-18 12:24:23',
  219
+						'updated' => '2007-03-18 12:26:31'
  220
+			))),
  221
+			array(
  222
+				'Article' => array(
  223
+					'id' => '2',
  224
+					'user_id' => '3',
  225
+					'title' => 'Second Article',
  226
+					'body' => 'Second Article Body',
  227
+					'published' => 'Y',
  228
+					'created' => '2007-03-18 10:41:23',
  229
+					'updated' => '2007-03-18 10:43:31'
  230
+				),
  231
+				'User' => array(
  232
+					'id' => '3',
  233
+					'user' => 'larry',
  234
+					'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  235
+					'created' => '2007-03-17 01:20:23',
  236
+					'updated' => '2007-03-17 01:22:31'
  237
+				),
  238
+				'Comment' => array(
  239
+					array(
  240
+						'id' => '5',
  241
+						'article_id' => '2',
  242
+						'user_id' => '1',
  243
+						'comment' => 'First Comment for Second Article',
  244
+						'published' => 'Y',
  245
+						'created' => '2007-03-18 10:53:23',
  246
+						'updated' => '2007-03-18 10:55:31'
  247
+					),
  248
+					array(
  249
+						'id' => '6',
  250
+						'article_id' => '2',
  251
+						'user_id' => '2',
  252
+						'comment' => 'Second Comment for Second Article',
  253
+						'published' => 'Y',
  254
+						'created' => '2007-03-18 10:55:23',
  255
+						'updated' => '2007-03-18 10:57:31'
  256
+				)),
  257
+				'Tag' => array(
  258
+					array(
  259
+						'id' => '1',
  260
+						'tag' => 'tag1',
  261
+						'created' => '2007-03-18 12:22:23',
  262
+						'updated' => '2007-03-18 12:24:31'
  263
+					),
  264
+					array(
  265
+						'id' => '3',
  266
+						'tag' => 'tag3',
  267
+						'created' => '2007-03-18 12:26:23',
  268
+						'updated' => '2007-03-18 12:28:31'
  269
+			))),
  270
+			array(
  271
+				'Article' => array(
  272
+					'id' => '3',
  273
+					'user_id' => '1',
  274
+					'title' => 'Third Article',
  275
+					'body' => 'Third Article Body',
  276
+					'published' => 'Y',
  277
+					'created' => '2007-03-18 10:43:23',
  278
+					'updated' => '2007-03-18 10:45:31'
  279
+				),
  280
+				'User' => array(
  281
+					'id' => '1',
  282
+					'user' => 'mariano',
  283
+					'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  284
+					'created' => '2007-03-17 01:16:23',
  285
+					'updated' => '2007-03-17 01:18:31'
  286
+				),
  287
+				'Comment' => array(),
  288
+				'Tag' => array()
  289
+		));
  290
+		$this->assertEqual($TestModel->find('all'), $expected);
  291
+
  292
+		$db2 =& ConnectionManager::getDataSource('test2');
  293
+
  294
+		foreach (array('User', 'Comment') as $class) {
  295
+			$this->_fixtures[$this->_fixtureClassMap[$class]]->create($db2);
  296
+			$this->_fixtures[$this->_fixtureClassMap[$class]]->insert($db2);
  297
+			$this->db->truncate(Inflector::pluralize(Inflector::underscore($class)));
  298
+		}
  299
+
  300
+		$this->assertEqual($TestModel->User->find('all'), array());
  301
+		$this->assertEqual($TestModel->Comment->find('all'), array());
  302
+		$this->assertEqual($TestModel->find('count'), 3);
  303
+
  304
+		$TestModel->User->setDataSource('test2');
  305
+		$TestModel->Comment->setDataSource('test2');
  306
+
  307
+		foreach ($expected as $key => $value) {
  308
+			unset($value['Comment'], $value['Tag']);
  309
+			$expected[$key] = $value;
  310
+		}
  311
+
  312
+		$TestModel->recursive = 0;
  313
+		$result = $TestModel->find('all');
  314
+		$this->assertEqual($result, $expected);
  315
+
  316
+		foreach ($expected as $key => $value) {
  317
+			unset($value['Comment'], $value['Tag']);
  318
+			$expected[$key] = $value;
  319
+		}
  320
+
  321
+		$TestModel->recursive = 0;
  322
+		$result = $TestModel->find('all');
  323
+		$this->assertEqual($result, $expected);
  324
+
  325
+		$result = Set::extract($TestModel->User->find('all'), '{n}.User.id');
  326
+		$this->assertEqual($result, array('1', '2', '3', '4'));
  327
+		$this->assertEqual($TestModel->find('all'), $expected);
  328
+
  329
+		$TestModel->Comment->unbindModel(array('hasOne' => array('Attachment')));
  330
+		$expected = array(
  331
+			array(
  332
+				'Comment' => array(
  333
+					'id' => '1',
  334
+					'article_id' => '1',
  335
+					'user_id' => '2',
  336
+					'comment' => 'First Comment for First Article',
  337
+					'published' => 'Y',
  338
+					'created' => '2007-03-18 10:45:23',
  339
+					'updated' => '2007-03-18 10:47:31'
  340
+				),
  341
+				'User' => array(
  342
+					'id' => '2',
  343
+					'user' => 'nate',
  344
+					'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  345
+					'created' => '2007-03-17 01:18:23',
  346
+					'updated' => '2007-03-17 01:20:31'
  347
+				),
  348
+				'Article' => array(
  349
+					'id' => '1',
  350
+					'user_id' => '1',
  351
+					'title' => 'First Article',
  352
+					'body' => 'First Article Body',
  353
+					'published' => 'Y',
  354
+					'created' => '2007-03-18 10:39:23',
  355
+					'updated' => '2007-03-18 10:41:31'
  356
+			)),
  357
+			array(
  358
+				'Comment' => array(
  359
+					'id' => '2',
  360
+					'article_id' => '1',
  361
+					'user_id' => '4',
  362
+					'comment' => 'Second Comment for First Article',
  363
+					'published' => 'Y',
  364
+					'created' => '2007-03-18 10:47:23',
  365
+					'updated' => '2007-03-18 10:49:31'
  366
+				),
  367
+				'User' => array(
  368
+					'id' => '4',
  369
+					'user' => 'garrett',
  370
+					'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  371
+					'created' => '2007-03-17 01:22:23',
  372
+					'updated' => '2007-03-17 01:24:31'
  373
+				),
  374
+				'Article' => array(
  375
+					'id' => '1',
  376
+					'user_id' => '1',
  377
+					'title' => 'First Article',
  378
+					'body' => 'First Article Body',
  379
+					'published' => 'Y',
  380
+					'created' => '2007-03-18 10:39:23',
  381
+					'updated' => '2007-03-18 10:41:31'
  382
+			)),
  383
+			array(
  384
+				'Comment' => array(
  385
+					'id' => '3',
  386
+					'article_id' => '1',
  387
+					'user_id' => '1',
  388
+					'comment' => 'Third Comment for First Article',
  389
+					'published' => 'Y',
  390
+					'created' => '2007-03-18 10:49:23',
  391
+					'updated' => '2007-03-18 10:51:31'
  392
+				),
  393
+				'User' => array(
  394
+					'id' => '1',
  395
+					'user' => 'mariano',
  396
+					'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  397
+					'created' => '2007-03-17 01:16:23',
  398
+					'updated' => '2007-03-17 01:18:31'
  399
+				),
  400
+				'Article' => array(
  401
+					'id' => '1',
  402
+					'user_id' => '1',
  403
+					'title' => 'First Article',
  404
+					'body' => 'First Article Body',
  405
+					'published' => 'Y',
  406
+					'created' => '2007-03-18 10:39:23',
  407
+					'updated' => '2007-03-18 10:41:31'
  408
+			)),
  409
+			array(
  410
+				'Comment' => array(
  411
+					'id' => '4',
  412
+					'article_id' => '1',
  413
+					'user_id' => '1',
  414
+					'comment' => 'Fourth Comment for First Article',
  415
+					'published' => 'N',
  416
+					'created' => '2007-03-18 10:51:23',
  417
+					'updated' => '2007-03-18 10:53:31'
  418
+				),
  419
+				'User' => array(
  420
+					'id' => '1',
  421
+					'user' => 'mariano',
  422
+					'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  423
+					'created' => '2007-03-17 01:16:23',
  424
+					'updated' => '2007-03-17 01:18:31'
  425
+				),
  426
+				'Article' => array(
  427
+					'id' => '1',
  428
+					'user_id' => '1',
  429
+					'title' => 'First Article',
  430
+					'body' => 'First Article Body',
  431
+					'published' => 'Y',
  432
+					'created' => '2007-03-18 10:39:23',
  433
+					'updated' => '2007-03-18 10:41:31'
  434
+			)),
  435
+			array(
  436
+				'Comment' => array(
  437
+					'id' => '5',
  438
+					'article_id' => '2',
  439
+					'user_id' => '1',
  440
+					'comment' => 'First Comment for Second Article',
  441
+					'published' => 'Y',
  442
+					'created' => '2007-03-18 10:53:23',
  443
+					'updated' => '2007-03-18 10:55:31'
  444
+				),
  445
+				'User' => array(
  446
+					'id' => '1',
  447
+					'user' => 'mariano',
  448
+					'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  449
+					'created' => '2007-03-17 01:16:23',
  450
+					'updated' => '2007-03-17 01:18:31'
  451
+				),
  452
+				'Article' => array(
  453
+					'id' => '2',
  454
+					'user_id' => '3',
  455
+					'title' => 'Second Article',
  456
+					'body' => 'Second Article Body',
  457
+					'published' => 'Y',
  458
+					'created' => '2007-03-18 10:41:23',
  459
+					'updated' => '2007-03-18 10:43:31'
  460
+			)),
  461
+			array(
  462
+				'Comment' => array(
  463
+					'id' => '6',
  464
+					'article_id' => '2',
  465
+					'user_id' => '2',
  466
+					'comment' => 'Second Comment for Second Article',
  467
+					'published' => 'Y',
  468
+					'created' => '2007-03-18 10:55:23',
  469
+					'updated' => '2007-03-18 10:57:31'
  470
+				),
  471
+				'User' => array(
  472
+					'id' => '2',
  473
+					'user' => 'nate',
  474
+					'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
  475
+					'created' => '2007-03-17 01:18:23',
  476
+					'updated' => '2007-03-17 01:20:31'
  477
+				),
  478
+				'Article' => array(
  479
+					'id' => '2',
  480
+					'user_id' => '3',
  481
+					'title' => 'Second Article',
  482
+					'body' => 'Second Article Body',
  483
+					'published' => 'Y',
  484
+					'created' => '2007-03-18 10:41:23',
  485
+					'updated' => '2007-03-18 10:43:31'
  486
+		)));
  487
+		$this->assertEqual($TestModel->Comment->find('all'), $expected);
  488
+
  489
+		foreach (array('User', 'Comment') as $class) {
  490
+			$this->_fixtures[$this->_fixtureClassMap[$class]]->drop($db2);
  491
+		}
  492
+	}
  493
+/**
  494
+ * testDisplayField method
  495
+ *
  496
+ * @access public
  497
+ * @return void
  498
+ */
  499
+	function testDisplayField() {
  500
+		$this->loadFixtures('Post', 'Comment', 'Person');