From b055db19f7be0315a66d24b4aa7e14126229f1e9 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 4 Jun 2009 00:37:27 +0000 Subject: [PATCH 01/95] Increasing Model test compatibility with SQLite and Postgres git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8188 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/tests/cases/libs/model/model.test.php | 74 +++++++++++++++++----- cake/tests/cases/libs/model/models.php | 2 +- 2 files changed, 58 insertions(+), 18 deletions(-) diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 7ac8b0dd3..92db5fd57 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -266,6 +266,7 @@ class ModelTest extends CakeTestCase { $this->assertEqual($model->getColumnType('Tag.id'), 'integer'); $this->assertEqual($model->getColumnType('Article.id'), 'integer'); } + /** * testMultipleBelongsToWithSameClass method * @@ -410,6 +411,7 @@ class ModelTest extends CakeTestCase { ); $this->assertTrue($Fruit->save($data)); } + /** * testHabtmUuidWithNumericId method * @@ -1303,6 +1305,7 @@ class ModelTest extends CakeTestCase { // $result = $NumericArticle->find($data); // $this->assertTrue(empty($result)); } + /** * test find('all') method * @@ -1379,7 +1382,7 @@ class ModelTest extends CakeTestCase { $this->assertEqual($result, $expected); $ids = array(4 => 1, 5 => 3); - $result = $TestModel->find('all', array('conditions' => array('User.id' => $ids))); + $result = $TestModel->find('all', array('conditions' => array('User.id' => $ids), 'order' => 'User.id')); $expected = array( array('User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31')), array('User' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31')), @@ -1863,16 +1866,28 @@ class ModelTest extends CakeTestCase { $this->assertTrue(isset($this->db->_queriesLog[0]['query'])); $this->assertNoPattern('/ORDER\s+BY/', $this->db->_queriesLog[0]['query']); + } - $this->db->_queriesLog = array(); - $this->db->fullDebug = $fullDebug; - +/** + * test find with COUNT(DISTINCT field) + * + * @return void + **/ + function testFindCountDistinct() { + $skip = $this->skipIf( + $this->db->config['driver'] == 'sqlite', + 'SELECT COUNT(DISTINCT field) is not compatible with SQLite' + ); + if ($skip) { + return; + } + $this->loadFixtures('Project'); $TestModel =& new Project(); $TestModel->create(array('name' => 'project')) && $TestModel->save(); $TestModel->create(array('name' => 'project')) && $TestModel->save(); $TestModel->create(array('name' => 'project')) && $TestModel->save(); - - $result = $TestModel->find('count', array('fields' => 'DISTINCT Project.name')); + + $result = $TestModel->find('count', array('fields' => 'DISTINCT name')); $this->assertEqual($result, 4); } /** @@ -3695,6 +3710,7 @@ class ModelTest extends CakeTestCase { ); $this->assertEqual($result, $expected); } + /** * testSaveAllValidation method * @@ -3712,7 +3728,7 @@ class ModelTest extends CakeTestCase { ); $this->assertTrue($TestModel->saveAll($data)); - $result = $TestModel->find('all', array('recursive' => -1)); + $result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC')); $ts = date('Y-m-d H:i:s'); $expected = array( array('Post' => array('id' => '1', 'author_id' => '1', 'title' => 'Baleeted First Post', 'body' => 'Baleeted!', 'published' => 'N', 'created' => '2007-03-18 10:39:23', 'updated' => $ts)), @@ -3730,7 +3746,7 @@ class ModelTest extends CakeTestCase { $result = $TestModel->saveAll($data); $this->assertEqual($result, false); - $result = $TestModel->find('all', array('recursive' => -1)); + $result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC')); $errors = array(1 => array('title' => 'This field cannot be left blank')); $transactionWorked = Set::matches('/Post[1][title=Baleeted First Post]', $result); if (!$transactionWorked) { @@ -3747,7 +3763,7 @@ class ModelTest extends CakeTestCase { ); $result = $TestModel->saveAll($data, array('atomic' => false)); $this->assertEqual($result, array(true, false)); - $result = $TestModel->find('all', array('recursive' => -1)); + $result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC')); $errors = array(1 => array('title' => 'This field cannot be left blank')); $newTs = date('Y-m-d H:i:s'); $expected = array( @@ -3765,7 +3781,7 @@ class ModelTest extends CakeTestCase { ); $this->assertFalse($TestModel->saveAll($data, array('validate' => 'first'))); - $result = $TestModel->find('all', array('recursive' => -1)); + $result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC')); $this->assertEqual($result, $expected); $this->assertEqual($TestModel->validationErrors, $errors); @@ -4007,6 +4023,7 @@ class ModelTest extends CakeTestCase { $this->assertEqual($users[0]['User']['post_count'], 1); $this->assertEqual($users[1]['User']['post_count'], 2); } + /** * test Counter Cache With Self Joining table * @@ -4014,8 +4031,16 @@ class ModelTest extends CakeTestCase { * @access public */ function testCounterCacheWithSelfJoin() { + $skip = $this->skipIf( + ($this->db->config['driver'] == 'sqlite'), + 'SQLite 2.x does not support ALTER TABLE ADD COLUMN' + ); + if ($skip) { + return; + } + $this->loadFixtures('CategoryThread'); - $this->db->query('ALTER TABLE '. $this->db->fullTableName('category_threads') . " ADD column child_count INT(11) DEFAULT '0'"); + $this->db->query('ALTER TABLE '. $this->db->fullTableName('category_threads') . " ADD COLUMN child_count INTEGER"); $Category =& new CategoryThread(); $result = $Category->updateAll(array('CategoryThread.name' => "'updated'"), array('CategoryThread.parent_id' => 5)); $this->assertTrue($result); @@ -4931,6 +4956,7 @@ class ModelTest extends CakeTestCase { // $TestModel->set(array('title' => 'Hello', 'published' => 1, 'body' => '')); // $this->assertEqual($TestModel->invalidFields(), array('body' => 'This field cannot be left blank')); // } + /** * testFindAllWithConditionInChildQuery * @@ -4944,6 +4970,7 @@ class ModelTest extends CakeTestCase { $TestModel =& new Basket(); $recursive = 3; $result = $TestModel->find('all', compact('conditions', 'recursive')); + $expected = array( array( 'Basket' => array( @@ -4974,6 +5001,7 @@ class ModelTest extends CakeTestCase { ); $this->assertEqual($result, $expected); } + /** * testFindAllWithConditionsHavingMixedDataTypes method * @@ -5009,12 +5037,14 @@ class ModelTest extends CakeTestCase { ); $conditions = array('id' => array('1', 2)); $recursive = -1; - $result = $TestModel->find('all', compact('conditions', 'recursive')); + $order = 'Article.id ASC'; + $result = $TestModel->find('all', compact('conditions', 'recursive', 'order')); $this->assertEqual($result, $expected); $conditions = array('id' => array('1', 2, '3.0')); - $result = $TestModel->find('all', compact('recursive', 'conditions')); + $order = 'Article.id ASC'; + $result = $TestModel->find('all', compact('recursive', 'conditions', 'order')); $expected = array( array( 'Article' => array( @@ -6307,7 +6337,8 @@ class ModelTest extends CakeTestCase { $Product =& new Product(); $result = $Thread->find('all', array( - 'group' => 'Thread.project_id' + 'group' => 'Thread.project_id', + 'order' => 'Thread.id ASC' )); $expected = array( @@ -6338,7 +6369,9 @@ class ModelTest extends CakeTestCase { $this->assertEqual($result, $expected); $rows = $Thread->find('all', array( - 'group' => 'Thread.project_id', 'fields' => array('Thread.project_id', 'COUNT(*) AS total'), 'order'=> 'Thread.project_id' + 'group' => 'Thread.project_id', + 'fields' => array('Thread.project_id', 'COUNT(*) AS total'), + 'order'=> 'Thread.project_id' )); $result = array(); foreach($rows as $row) { @@ -6397,10 +6430,17 @@ class ModelTest extends CakeTestCase { array('Product' => array('type' => 'Music'), array( 'price' => 4)), array('Product' => array('type' => 'Toy'), array('price' => 3)) ); - $result = $Product->find('all',array('fields'=>array('Product.type','MIN(Product.price) as price'), 'group'=> 'Product.type')); + $result = $Product->find('all',array( + 'fields'=>array('Product.type','MIN(Product.price) as price'), + 'group'=> 'Product.type', + 'order' => 'Product.type ASC' + )); $this->assertEqual($result, $expected); - $result = $Product->find('all', array('fields'=>array('Product.type','MIN(Product.price) as price'), 'group'=> array('Product.type'))); + $result = $Product->find('all', array( + 'fields'=>array('Product.type','MIN(Product.price) as price'), + 'group'=> array('Product.type'), + 'order' => 'Product.type ASC')); $this->assertEqual($result, $expected); } /** diff --git a/cake/tests/cases/libs/model/models.php b/cake/tests/cases/libs/model/models.php index ea0a07643..620d2c71b 100644 --- a/cake/tests/cases/libs/model/models.php +++ b/cake/tests/cases/libs/model/models.php @@ -2543,7 +2543,7 @@ class Basket extends CakeTestModel { 'FilmFile' => array( 'className' => 'FilmFile', 'foreignKey' => 'object_id', - 'conditions' => 'Basket.type = "file"', + 'conditions' => "Basket.type = 'file'", 'fields' => '', 'order' => '' ) From 4a076b3e5fa1311a8547e227d875a1dda6de44c0 Mon Sep 17 00:00:00 2001 From: DarkAngelBGE Date: Thu, 4 Jun 2009 21:29:26 +0000 Subject: [PATCH 02/95] Small return-home-early refactoring for the File class git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8189 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/file.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cake/libs/file.php b/cake/libs/file.php index e22031749..b57cb4c72 100644 --- a/cake/libs/file.php +++ b/cake/libs/file.php @@ -366,12 +366,13 @@ class File extends Object { function md5($maxsize = 5) { if ($maxsize === true) { return md5_file($this->path); - } else { - $size = $this->size(); - if ($size && $size < ($maxsize * 1024) * 1024) { - return md5_file($this->path); - } } + + $size = $this->size(); + if ($size && $size < ($maxsize * 1024) * 1024) { + return md5_file($this->path); + } + return false; } /** From 2c1b7fc24ed0766975d9b7b461922d6435d6f72c Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 5 Jun 2009 02:43:08 +0000 Subject: [PATCH 03/95] Adding nullish value handling for date, datetime, and timestamp column types to DboPostgres. Empty string values now return instead of "". Fixes #6386 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8190 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/datasources/dbo/dbo_postgres.php | 3 +++ .../model/datasources/dbo/dbo_postgres.test.php | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/cake/libs/model/datasources/dbo/dbo_postgres.php b/cake/libs/model/datasources/dbo/dbo_postgres.php index bd6e984bb..2298fc019 100644 --- a/cake/libs/model/datasources/dbo/dbo_postgres.php +++ b/cake/libs/model/datasources/dbo/dbo_postgres.php @@ -275,6 +275,9 @@ class DboPostgres extends DboSource { case 'inet': case 'float': case 'integer': + case 'date': + case 'datetime': + case 'timestamp': if ($data === '') { return $read ? 'NULL' : 'DEFAULT'; } diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php index 6c387da43..aec59ba4c 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_postgres.test.php @@ -290,6 +290,21 @@ class DboPostgresTest extends CakeTestCase { $this->assertEqual($this->db2->value('1', 'boolean'), 'TRUE'); $this->assertEqual($this->db2->value(null, 'boolean'), "NULL"); } +/** + * test that date columns do not generate errors with null and nullish values. + * + * @return void + **/ + function testDateAsNull() { + $this->assertEqual($this->db2->value(null, 'date'), 'NULL'); + $this->assertEqual($this->db2->value('', 'date'), 'NULL'); + + $this->assertEqual($this->db2->value('', 'datetime'), 'NULL'); + $this->assertEqual($this->db2->value(null, 'datetime'), 'NULL'); + + $this->assertEqual($this->db2->value('', 'timestamp'), 'NULL'); + $this->assertEqual($this->db2->value(null, 'timestamp'), 'NULL'); + } /** * Tests that different Postgres boolean 'flavors' are properly returned as native PHP booleans * From d9489b942b30e1d0809798e9e96595740f181126 Mon Sep 17 00:00:00 2001 From: DarkAngelBGE Date: Sat, 6 Jun 2009 15:41:33 +0000 Subject: [PATCH 04/95] Removing duplicate START TRANSACTION sql execution in mysqli environment, fixes #6422 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8191 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/datasources/dbo/dbo_mysqli.php | 14 -------------- .../model/datasources/dbo/dbo_mysqli.test.php | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/cake/libs/model/datasources/dbo/dbo_mysqli.php b/cake/libs/model/datasources/dbo/dbo_mysqli.php index 12121a711..c0d238079 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysqli.php +++ b/cake/libs/model/datasources/dbo/dbo_mysqli.php @@ -232,20 +232,6 @@ class DboMysqli extends DboMysqlBase { return $data; } -/** - * Begin a transaction - * - * @param unknown_type $model - * @return boolean True on success, false on fail - * (i.e. if the database/model does not support transactions). - */ - function begin(&$model) { - if (parent::begin($model) && $this->execute('START TRANSACTION')) { - $this->_transactionStarted = true; - return true; - } - return false; - } /** * Returns a formatted error message from previous database operation. * diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php index a2d86a574..3b19174c4 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php @@ -297,5 +297,21 @@ class DboMysqliTest extends CakeTestCase { $expected = 'float'; $this->assertEqual($result, $expected); } +/** + * undocumented function + * + * @return void + * @access public + */ + function testTransactions() { + $this->db->begin($this->model); + $this->assertTrue($this->db->_transactionStarted); + + $beginSqlCalls = Set::extract('/.[query=START TRANSACTION]', $this->db->_queriesLog); + $this->assertEqual(1, count($beginSqlCalls)); + + $this->db->commit($this->model); + $this->assertFalse($this->db->_transactionStarted); + } } ?> \ No newline at end of file From 6064019339a0bbe1256ac4152fe82edd84c8dc08 Mon Sep 17 00:00:00 2001 From: jperras Date: Wed, 10 Jun 2009 03:00:38 +0000 Subject: [PATCH 05/95] Refactoring model.test.php for 100 col display. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8192 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/tests/cases/libs/model/model.test.php | 9305 ++++++++++++++++---- 1 file changed, 7801 insertions(+), 1504 deletions(-) diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 92db5fd57..240b27fce 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -189,10 +189,14 @@ class ModelTest extends CakeTestCase { $expected = array( 'Featured' => array( - 'className' => 'Featured', 'foreignKey' => 'article_featured_id', - 'conditions' => '', 'fields' => '', 'order' => '', 'dependent' => '' - ) - ); + 'className' => 'Featured', + 'foreignKey' => 'article_featured_id', + 'conditions' => '', + 'fields' => '', + 'order' => '', + 'dependent' => '' + )); + $this->assertIdentical($TestModel->hasOne, $expected); $this->assertIdentical($TestFakeModel->hasOne, $expected); @@ -201,12 +205,19 @@ class ModelTest extends CakeTestCase { $expected = array( 'Comment' => array( - 'className' => 'Comment', 'dependent' => true, - 'foreignKey' => 'article_featured_id', 'conditions' => '', 'fields' => '', - 'order' => '', 'limit' => '', 'offset' => '', 'exclusive' => '', - 'finderQuery' => '', 'counterQuery' => '' - ) - ); + 'className' => 'Comment', + 'dependent' => true, + 'foreignKey' => 'article_featured_id', + 'conditions' => '', + 'fields' => '', + 'order' => '', + 'limit' => '', + 'offset' => '', + 'exclusive' => '', + 'finderQuery' => '', + 'counterQuery' => '' + )); + $this->assertIdentical($TestModel->hasMany, $expected); $this->assertIdentical($TestFakeModel->hasMany, $expected); @@ -215,13 +226,22 @@ class ModelTest extends CakeTestCase { $expected = array( 'Tag' => array( - 'className' => 'Tag', 'joinTable' => 'article_featureds_tags', - 'with' => 'ArticleFeaturedsTag', 'foreignKey' => 'article_featured_id', - 'associationForeignKey' => 'tag_id', 'conditions' => '', 'fields' => '', - 'order' => '', 'limit' => '', 'offset' => '', 'unique' => true, 'finderQuery' => '', - 'deleteQuery' => '', 'insertQuery' => '' - ) - ); + 'className' => 'Tag', + 'joinTable' => 'article_featureds_tags', + 'with' => 'ArticleFeaturedsTag', + 'foreignKey' => 'article_featured_id', + 'associationForeignKey' => 'tag_id', + 'conditions' => '', + 'fields' => '', + 'order' => '', + 'limit' => '', + 'offset' => '', + 'unique' => true, + 'finderQuery' => '', + 'deleteQuery' => '', + 'insertQuery' => '' + )); + $this->assertIdentical($TestModel->hasAndBelongsToMany, $expected); $this->assertIdentical($TestFakeModel->hasAndBelongsToMany, $expected); @@ -275,9 +295,15 @@ class ModelTest extends CakeTestCase { */ function testMultipleBelongsToWithSameClass() { $this->loadFixtures( - 'DeviceType', 'DeviceTypeCategory', 'FeatureSet', 'ExteriorTypeCategory', - 'Document', 'Device', 'DocumentDirectory' + 'DeviceType', + 'DeviceTypeCategory', + 'FeatureSet', + 'ExteriorTypeCategory', + 'Document', + 'Device', + 'DocumentDirectory' ); + $DeviceType =& new DeviceType(); $DeviceType->recursive = 2; @@ -285,32 +311,78 @@ class ModelTest extends CakeTestCase { $expected = array( 'DeviceType' => array( - 'id' => 1, 'device_type_category_id' => 1, 'feature_set_id' => 1, - 'exterior_type_category_id' => 1, 'image_id' => 1, 'extra1_id' => 1, - 'extra2_id' => 1, 'name' => 'DeviceType 1', 'order' => 0 + 'id' => 1, + 'device_type_category_id' => 1, + 'feature_set_id' => 1, + 'exterior_type_category_id' => 1, + 'image_id' => 1, + 'extra1_id' => 1, + 'extra2_id' => 1, + 'name' => 'DeviceType 1', + 'order' => 0 ), - 'Image' => array('id' => 1, 'document_directory_id' => 1, 'name' => 'Document 1', - 'DocumentDirectory' => array('id' => 1, 'name' => 'DocumentDirectory 1')), + 'Image' => array( + 'id' => 1, + 'document_directory_id' => 1, + 'name' => 'Document 1', + 'DocumentDirectory' => array( + 'id' => 1, + 'name' => 'DocumentDirectory 1' + )), 'Extra1' => array( - 'id' => 1, 'document_directory_id' => 1, 'name' => 'Document 1', - 'DocumentDirectory' => array('id' => 1, 'name' => 'DocumentDirectory 1') - ), + 'id' => 1, + 'document_directory_id' => 1, + 'name' => 'Document 1', + 'DocumentDirectory' => array( + 'id' => 1, + 'name' => 'DocumentDirectory 1' + )), 'Extra2' => array( - 'id' => 1, 'document_directory_id' => 1, 'name' => 'Document 1', - 'DocumentDirectory' => array('id' => 1, 'name' => 'DocumentDirectory 1') + 'id' => 1, + 'document_directory_id' => 1, + 'name' => 'Document 1', + 'DocumentDirectory' => array( + 'id' => 1, + 'name' => 'DocumentDirectory 1' + )), + 'DeviceTypeCategory' => array( + 'id' => 1, + 'name' => 'DeviceTypeCategory 1' + ), + 'FeatureSet' => array( + 'id' => 1, + 'name' => 'FeatureSet 1' ), - 'DeviceTypeCategory' => array('id' => 1, 'name' => 'DeviceTypeCategory 1'), - 'FeatureSet' => array('id' => 1, 'name' => 'FeatureSet 1'), 'ExteriorTypeCategory' => array( - 'id' => 1, 'image_id' => 1, 'name' => 'ExteriorTypeCategory 1', - 'Image' => array('id' => 1, 'device_type_id' => 1, 'name' => 'Device 1', 'typ' => 1) - ), + 'id' => 1, + 'image_id' => 1, + 'name' => 'ExteriorTypeCategory 1', + 'Image' => array( + 'id' => 1, + 'device_type_id' => 1, + 'name' => 'Device 1', + 'typ' => 1 + )), 'Device' => array( - array('id' => 1, 'device_type_id' => 1, 'name' => 'Device 1', 'typ' => 1), - array('id' => 2, 'device_type_id' => 1, 'name' => 'Device 2', 'typ' => 1), - array('id' => 3, 'device_type_id' => 1, 'name' => 'Device 3', 'typ' => 2) - ) - ); + array( + 'id' => 1, + 'device_type_id' => 1, + 'name' => 'Device 1', + 'typ' => 1 + ), + array( + 'id' => 2, + 'device_type_id' => 1, + 'name' => 'Device 2', + 'typ' => 1 + ), + array( + 'id' => 3, + 'device_type_id' => 1, + 'name' => 'Device 3', + 'typ' => 2 + ))); + $this->assertEqual($result, $expected); } /** @@ -324,26 +396,51 @@ class ModelTest extends CakeTestCase { $Portfolio =& new Portfolio(); $result = $Portfolio->find(array('id' => 2), null, null, 3); - $expected = array('Portfolio' => array( - 'id' => 2, 'seller_id' => 1, 'name' => 'Portfolio 2'), - 'Item' => array( - array( - 'id' => 2, 'syfile_id' => 2, 'published' => 0, 'name' => 'Item 2', - 'ItemsPortfolio' => array('id' => 2, 'item_id' => 2, 'portfolio_id' => 2), - 'Syfile' => array( - 'id' => 2, 'image_id' => 2, 'name' => 'Syfile 2', 'item_count' => null, - 'Image' => array('id' => 2, 'name' => 'Image 2' - )) + $expected = array( + 'Portfolio' => array( + 'id' => 2, + 'seller_id' => 1, + 'name' => 'Portfolio 2' ), - array( - 'id' => 6, 'syfile_id' => 6, 'published' => 0, 'name' => 'Item 6', - 'ItemsPortfolio' => array('id' => 6, 'item_id' => 6, 'portfolio_id' => 2), - 'Syfile' => array( - 'id' => 6, 'image_id' => null, 'name' => 'Syfile 6', 'item_count' => null, - 'Image' => array() - ) - ) - )); + 'Item' => array( + array( + 'id' => 2, + 'syfile_id' => 2, + 'published' => 0, + 'name' => 'Item 2', + 'ItemsPortfolio' => array( + 'id' => 2, + 'item_id' => 2, + 'portfolio_id' => 2 + ), + 'Syfile' => array( + 'id' => 2, + 'image_id' => 2, + 'name' => 'Syfile 2', + 'item_count' => null, + 'Image' => array( + 'id' => 2, + 'name' => 'Image 2' + ) + )), + array( + 'id' => 6, + 'syfile_id' => 6, + 'published' => 0, + 'name' => 'Item 6', + 'ItemsPortfolio' => array( + 'id' => 6, + 'item_id' => 6, + 'portfolio_id' => 2 + ), + 'Syfile' => array( + 'id' => 6, + 'image_id' => null, + 'name' => 'Syfile 6', + 'item_count' => null, + 'Image' => array() + )))); + $this->assertEqual($result, $expected); } /** @@ -466,7 +563,16 @@ class ModelTest extends CakeTestCase { $Article->hasAndBelongsToMany['Tag']['finderQuery'] = $sql; $result = $Article->find('first'); - $expected = array(array('id' => '1', 'tag' => 'tag1'), array('id' => '2', 'tag' => 'tag2')); + $expected = array( + array( + 'id' => '1', + 'tag' => 'tag1' + ), + array( + 'id' => '2', + 'tag' => 'tag2' + )); + $this->assertEqual($result['Tag'], $expected); } /** @@ -482,22 +588,61 @@ class ModelTest extends CakeTestCase { $TestModel->hasAndBelongsToMany['Tag']['limit'] = 2; $result = $TestModel->read(null, 2); $expected = array( - 'Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), - 'User' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'), - 'Comment' => array( - array('id' => '5', 'article_id' => '2', 'user_id' => '1', 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'), - array('id' => '6', 'article_id' => '2', 'user_id' => '2', 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31') + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' ), + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), + 'Comment' => array( + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + )), 'Tag' => array( - array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), - array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31') - ) - ); + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))); + $this->assertEqual($result, $expected); $TestModel->hasAndBelongsToMany['Tag']['limit'] = 1; $result = $TestModel->read(null, 2); unset($expected['Tag'][1]); + $this->assertEqual($result, $expected); } /** @@ -523,65 +668,105 @@ class ModelTest extends CakeTestCase { $result = $Project->find('all'); $expected = array( - array('Project' => array('id' => 1, 'name' => 'Project 1'), - 'Thread' => array( - array( - 'id' => 1, 'project_id' => 1, 'name' => 'Project 1, Thread 1', - 'Project' => array( - 'id' => 1, 'name' => 'Project 1', - 'Thread' => array( - array('id' => 1, 'project_id' => 1, 'name' => 'Project 1, Thread 1'), - array('id' => 2, 'project_id' => 1, 'name' => 'Project 1, Thread 2') - ) + array( + 'Project' => array( + 'id' => 1, + 'name' => 'Project 1' + ), + 'Thread' => array( + array( + 'id' => 1, + 'project_id' => 1, + 'name' => 'Project 1, Thread 1', + 'Project' => array( + 'id' => 1, + 'name' => 'Project 1', + 'Thread' => array( + array( + 'id' => 1, + 'project_id' => 1, + 'name' => 'Project 1, Thread 1' ), - 'Message' => array( - array( - 'id' => 1, 'thread_id' => 1, 'name' => 'Thread 1, Message 1', - 'Bid' => array('id' => 1, 'message_id' => 1, 'name' => 'Bid 1.1') - ) - ) - ), - array( - 'id' => 2, 'project_id' => 1, 'name' => 'Project 1, Thread 2', - 'Project' => array( - 'id' => 1, 'name' => 'Project 1', - 'Thread' => array( - array('id' => 1, 'project_id' => 1, 'name' => 'Project 1, Thread 1'), - array('id' => 2, 'project_id' => 1, 'name' => 'Project 1, Thread 2') - ) - ), - 'Message' => array( array( - 'id' => 2, 'thread_id' => 2, 'name' => 'Thread 2, Message 1', - 'Bid' => array('id' => 4, 'message_id' => 2, 'name' => 'Bid 2.1') - ) - ) - ) - ) - ), - array('Project' => array('id' => 2, 'name' => 'Project 2'), - 'Thread' => array( - array( - 'id' => 3, 'project_id' => 2, 'name' => 'Project 2, Thread 1', - 'Project' => array( - 'id' => 2, 'name' => 'Project 2', - 'Thread' => array( - array('id' => 3, 'project_id' => 2, 'name' => 'Project 2, Thread 1'), - ) - ), - 'Message' => array( + 'id' => 2, + 'project_id' => 1, + 'name' => 'Project 1, Thread 2' + ))), + 'Message' => array( + array( + 'id' => 1, + 'thread_id' => 1, + 'name' => 'Thread 1, Message 1', + 'Bid' => array( + 'id' => 1, + 'message_id' => 1, + 'name' => 'Bid 1.1' + )))), + array( + 'id' => 2, + 'project_id' => 1, + 'name' => 'Project 1, Thread 2', + 'Project' => array( + 'id' => 1, + 'name' => 'Project 1', + 'Thread' => array( array( - 'id' => 3, 'thread_id' => 3, 'name' => 'Thread 3, Message 1', - 'Bid' => array('id' => 3, 'message_id' => 3, 'name' => 'Bid 3.1') - ) - ) - ) - ) - ), - array('Project' => array('id' => 3, 'name' => 'Project 3'), - 'Thread' => array() - ) - ); + 'id' => 1, + 'project_id' => 1, + 'name' => 'Project 1, Thread 1' + ), + array( + 'id' => 2, + 'project_id' => 1, + 'name' => 'Project 1, Thread 2' + ))), + 'Message' => array( + array( + 'id' => 2, + 'thread_id' => 2, + 'name' => 'Thread 2, Message 1', + 'Bid' => array( + 'id' => 4, + 'message_id' => 2, + 'name' => 'Bid 2.1' + )))))), + array( + 'Project' => array( + 'id' => 2, + 'name' => 'Project 2' + ), + 'Thread' => array( + array( + 'id' => 3, + 'project_id' => 2, + 'name' => 'Project 2, Thread 1', + 'Project' => array( + 'id' => 2, + 'name' => 'Project 2', + 'Thread' => array( + array( + 'id' => 3, + 'project_id' => 2, + 'name' => 'Project 2, Thread 1' + ))), + 'Message' => array( + array( + 'id' => 3, + 'thread_id' => 3, + 'name' => 'Thread 3, Message 1', + 'Bid' => array( + 'id' => 3, + 'message_id' => 3, + 'name' => 'Bid 3.1' + )))))), + array( + 'Project' => array( + 'id' => 3, + 'name' => 'Project 3' + ), + 'Thread' => array() + )); + $this->assertEqual($result, $expected); } /** @@ -639,22 +824,62 @@ class ModelTest extends CakeTestCase { $TestModel->hasAndBelongsToMany['SomethingElse']['unique'] = false; $TestModel->create(array( 'Something' => array('id' => 1), - 'SomethingElse' => array(3, array('something_else_id' => 1, 'doomed' => '1')) - )); + 'SomethingElse' => array(3, array( + 'something_else_id' => 1, + 'doomed' => '1' + )))); + $ts = date('Y-m-d H:i:s'); $TestModel->save(); $TestModel->hasAndBelongsToMany['SomethingElse']['order'] = 'SomethingElse.id ASC'; $result = $TestModel->findById(1); $expected = array( - 'Something' => array('id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => $ts), + 'Something' => array( + 'id' => '1', + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => $ts), 'SomethingElse' => array( - array('id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', - 'JoinThing' => array('doomed' => '1', 'something_id' => '1', 'something_else_id' => '1')), - array('id' => '2', 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', - 'JoinThing' => array('doomed' => '1', 'something_id' => '1', 'something_else_id' => '2')), - array('id' => '3', 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', - 'JoinThing' => array('doomed' => '0', 'something_id' => '1', 'something_else_id' => '3')))); + array( + 'id' => '1', + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31', + 'JoinThing' => array( + 'doomed' => '1', + 'something_id' => '1', + 'something_else_id' => '1' + )), + array( + 'id' => '2', + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31', + 'JoinThing' => array( + 'doomed' => '1', + 'something_id' => '1', + 'something_else_id' => '2' + )), + array( + 'id' => '3', + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31', + 'JoinThing' => array( + 'doomed' => '0', + 'something_id' => '1', + 'something_else_id' => '3' + )))); + $this->assertEqual($result, $expected); } /** @@ -675,27 +900,93 @@ class ModelTest extends CakeTestCase { $result = $TestModel->find('all'); $expected = array( array( - 'Article' => array('id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), + 'Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), 'Comment' => array( - array('id' => '1', 'article_id' => '1', 'user_id' => '2', 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'), - array('id' => '6', 'article_id' => '2', 'user_id' => '2', 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31') - ) - ), + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ))), array( - 'Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), 'Comment' => array( - array('id' => '1', 'article_id' => '1', 'user_id' => '2', 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'), - array('id' => '6', 'article_id' => '2', 'user_id' => '2', 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31') - ) - ), + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ))), array( - 'Article' => array('id' => '3', 'user_id' => '1', 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'), + 'Article' => array( + 'id' => '3', + 'user_id' => '1', + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ), 'Comment' => array( - array('id' => '1', 'article_id' => '1', 'user_id' => '2', 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'), - array('id' => '6', 'article_id' => '2', 'user_id' => '2', 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31') - ) - ) - ); + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + )))); + $this->assertEqual($result, $expected); } /** @@ -710,34 +1001,110 @@ class ModelTest extends CakeTestCase { $result = $TestModel->findById(1); $expected = array( - 'JoinA' => array('id' => 1, 'name' => 'Join A 1', 'body' => 'Join A 1 Body', 'created' => '2008-01-03 10:54:23', 'updated' => '2008-01-03 10:54:23'), - 'JoinB' => array( - 0 => array('id' => 2, 'name' => 'Join B 2', 'created' => '2008-01-03 10:55:02', 'updated' => '2008-01-03 10:55:02', - 'JoinAsJoinB' => array('id' => 1, 'join_a_id' => 1, 'join_b_id' => 2, 'other' => 'Data for Join A 1 Join B 2', 'created' => '2008-01-03 10:56:33', 'updated' => '2008-01-03 10:56:33'))), - 'JoinC' => array( - 0 => array('id' => 2, 'name' => 'Join C 2', 'created' => '2008-01-03 10:56:12', 'updated' => '2008-01-03 10:56:12', - 'JoinAsJoinC' => array('id' => 1, 'join_a_id' => 1, 'join_c_id' => 2, 'other' => 'Data for Join A 1 Join C 2', 'created' => '2008-01-03 10:57:22', 'updated' => '2008-01-03 10:57:22')))); + 'JoinA' => array( + 'id' => 1, + 'name' => 'Join A 1', + 'body' => 'Join A 1 Body', + 'created' => '2008-01-03 10:54:23', + 'updated' => '2008-01-03 10:54:23' + ), + 'JoinB' => array( + 0 => array( + 'id' => 2, + 'name' => 'Join B 2', + 'created' => '2008-01-03 10:55:02', + 'updated' => '2008-01-03 10:55:02', + 'JoinAsJoinB' => array( + 'id' => 1, + 'join_a_id' => 1, + 'join_b_id' => 2, + 'other' => 'Data for Join A 1 Join B 2', + 'created' => '2008-01-03 10:56:33', + 'updated' => '2008-01-03 10:56:33' + ))), + 'JoinC' => array( + 0 => array( + 'id' => 2, + 'name' => 'Join C 2', + 'created' => '2008-01-03 10:56:12', + 'updated' => '2008-01-03 10:56:12', + 'JoinAsJoinC' => array( + 'id' => 1, + 'join_a_id' => 1, + 'join_c_id' => 2, + 'other' => 'Data for Join A 1 Join C 2', + 'created' => '2008-01-03 10:57:22', + 'updated' => '2008-01-03 10:57:22' + )))); $this->assertEqual($result, $expected); $ts = date('Y-m-d H:i:s'); $TestModel->id = 1; $data = array( - 'JoinA' => array('id' => '1', 'name' => 'New name for Join A 1', 'updated' => $ts), - 'JoinB' => array(array('id' => 1, 'join_b_id' => 2, 'other' => 'New data for Join A 1 Join B 2', 'created' => $ts, 'updated' => $ts)), - 'JoinC' => array(array('id' => 1, 'join_c_id' => 2, 'other' => 'New data for Join A 1 Join C 2', 'created' => $ts, 'updated' => $ts))); + 'JoinA' => array( + 'id' => '1', + 'name' => 'New name for Join A 1', + 'updated' => $ts + ), + 'JoinB' => array( + array( + 'id' => 1, + 'join_b_id' => 2, + 'other' => 'New data for Join A 1 Join B 2', + 'created' => $ts, + 'updated' => $ts + )), + 'JoinC' => array( + array( + 'id' => 1, + 'join_c_id' => 2, + 'other' => 'New data for Join A 1 Join C 2', + 'created' => $ts, + 'updated' => $ts + ))); + $TestModel->set($data); $TestModel->save(); $result = $TestModel->findById(1); $expected = array( - 'JoinA' => array('id' => 1, 'name' => 'New name for Join A 1', 'body' => 'Join A 1 Body', 'created' => '2008-01-03 10:54:23', 'updated' => $ts), - 'JoinB' => array( - 0 => array('id' => 2, 'name' => 'Join B 2', 'created' => '2008-01-03 10:55:02', 'updated' => '2008-01-03 10:55:02', - 'JoinAsJoinB' => array('id' => 1, 'join_a_id' => 1, 'join_b_id' => 2, 'other' => 'New data for Join A 1 Join B 2', 'created' => $ts, 'updated' => $ts))), - 'JoinC' => array( - 0 => array('id' => 2, 'name' => 'Join C 2', 'created' => '2008-01-03 10:56:12', 'updated' => '2008-01-03 10:56:12', - 'JoinAsJoinC' => array('id' => 1, 'join_a_id' => 1, 'join_c_id' => 2, 'other' => 'New data for Join A 1 Join C 2', 'created' => $ts, 'updated' => $ts)))); + 'JoinA' => array( + 'id' => 1, + 'name' => 'New name for Join A 1', + 'body' => 'Join A 1 Body', + 'created' => '2008-01-03 10:54:23', + 'updated' => $ts + ), + 'JoinB' => array( + 0 => array( + 'id' => 2, + 'name' => 'Join B 2', + 'created' => '2008-01-03 10:55:02', + 'updated' => '2008-01-03 10:55:02', + 'JoinAsJoinB' => array( + 'id' => 1, + 'join_a_id' => 1, + 'join_b_id' => 2, + 'other' => 'New data for Join A 1 Join B 2', + 'created' => $ts, + 'updated' => $ts + ))), + 'JoinC' => array( + 0 => array( + 'id' => 2, + 'name' => 'Join C 2', + 'created' => '2008-01-03 10:56:12', + 'updated' => '2008-01-03 10:56:12', + 'JoinAsJoinC' => array( + 'id' => 1, + 'join_a_id' => 1, + 'join_c_id' => 2, + 'other' => 'New data for Join A 1 Join C 2', + 'created' => $ts, + 'updated' => $ts + )))); + $this->assertEqual($result, $expected); } /** @@ -752,20 +1119,98 @@ class ModelTest extends CakeTestCase { $TestModel->recursive = 2; $result = $TestModel->find('all'); - $expected = array(array('Home' => array( - 'id' => '1', 'another_article_id' => '1', 'advertisement_id' => '1', 'title' => 'First Home', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), - 'AnotherArticle' => array('id' => '1', 'title' => 'First Article', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', - 'Home' => array(array('id' => '1', 'another_article_id' => '1', 'advertisement_id' => '1', 'title' => 'First Home', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'))), - 'Advertisement' => array('id' => '1', 'title' => 'First Ad', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', - 'Home' => array(array('id' => '1', 'another_article_id' => '1', 'advertisement_id' => '1', 'title' => 'First Home', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), - array('id' => '2', 'another_article_id' => '3', 'advertisement_id' => '1', 'title' => 'Second Home', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31')))), - array('Home' => array( - 'id' => '2', 'another_article_id' => '3', 'advertisement_id' => '1', 'title' => 'Second Home', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), - 'AnotherArticle' => array('id' => '3', 'title' => 'Third Article', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', - 'Home' => array(array('id' => '2', 'another_article_id' => '3', 'advertisement_id' => '1', 'title' => 'Second Home', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'))), - 'Advertisement' => array('id' => '1', 'title' => 'First Ad', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', - 'Home' => array(array('id' => '1', 'another_article_id' => '1', 'advertisement_id' => '1', 'title' => 'First Home', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), - array('id' => '2', 'another_article_id' => '3', 'advertisement_id' => '1', 'title' => 'Second Home', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'))))); + $expected = array( + array( + 'Home' => array( + 'id' => '1', + 'another_article_id' => '1', + 'advertisement_id' => '1', + 'title' => 'First Home', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'AnotherArticle' => array( + 'id' => '1', + 'title' => 'First Article', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31', + 'Home' => array( + array( + 'id' => '1', + 'another_article_id' => '1', + 'advertisement_id' => '1', + 'title' => 'First Home', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ))), + 'Advertisement' => array( + 'id' => '1', + 'title' => 'First Ad', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31', + 'Home' => array( + array( + 'id' => '1', + 'another_article_id' => '1', + 'advertisement_id' => '1', + 'title' => 'First Home', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + array( + 'id' => '2', + 'another_article_id' => '3', + 'advertisement_id' => '1', + 'title' => 'Second Home', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + )))), + array( + 'Home' => array( + 'id' => '2', + 'another_article_id' => '3', + 'advertisement_id' => '1', + 'title' => 'Second Home', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'AnotherArticle' => array( + 'id' => '3', + 'title' => 'Third Article', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31', + 'Home' => array( + array( + 'id' => '2', + 'another_article_id' => '3', + 'advertisement_id' => '1', + 'title' => 'Second Home', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ))), + 'Advertisement' => array( + 'id' => '1', + 'title' => 'First Ad', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31', + 'Home' => array( + array( + 'id' => '1', + 'another_article_id' => '1', + 'advertisement_id' => '1', + 'title' => 'First Home', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + array( + 'id' => '2', + 'another_article_id' => '3', + 'advertisement_id' => '1', + 'title' => 'Second Home', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ))))); + $this->assertEqual($result, $expected); @@ -779,8 +1224,13 @@ class ModelTest extends CakeTestCase { */ function testFindAllRecursiveWithHabtm() { $this->loadFixtures( - 'MyCategoriesMyUsers', 'MyCategoriesMyProducts', 'MyCategory', 'MyUser', 'MyProduct' + 'MyCategoriesMyUsers', + 'MyCategoriesMyProducts', + 'MyCategory', + 'MyUser', + 'MyProduct' ); + $MyUser =& new MyUser(); $MyUser->recursive = 2; @@ -793,35 +1243,45 @@ class ModelTest extends CakeTestCase { 'id' => '1', 'name' => 'A', 'MyProduct' => array( - array('id' => '1', 'name' => 'book') - ) - ), + array( + 'id' => '1', + 'name' => 'book' + ))), array( 'id' => '3', 'name' => 'C', - 'MyProduct' => array(array('id' => '2', 'name' => 'computer')) - ) - ) - ), + 'MyProduct' => array( + array( + 'id' => '2', + 'name' => 'computer' + ))))), array( - 'MyUser' => array('id' => '2', 'firstname' => 'userB'), + 'MyUser' => array( + 'id' => '2', + 'firstname' => 'userB' + ), 'MyCategory' => array( array( 'id' => '1', 'name' => 'A', - 'MyProduct' => array(array('id' => '1', 'name' => 'book')) - ), + 'MyProduct' => array( + array( + 'id' => '1', + 'name' => 'book' + ))), array( 'id' => '2', 'name' => 'B', 'MyProduct' => array( - array('id' => '1', 'name' => 'book'), - array('id' => '2', 'name' => 'computer') - ) - ) - ) - ) - ); + array( + 'id' => '1', + 'name' => 'book' + ), + array( + 'id' => '2', + 'name' => 'computer' + )))))); + $this->assertIdentical($result, $expected); } /** @@ -837,33 +1297,100 @@ class ModelTest extends CakeTestCase { $TestModel->recursive = 2; $result = $TestModel->read(null, 1); $expected = array( - 'Person' => array('id' => 1, 'name' => 'person', 'mother_id' => 2, 'father_id' => 3), - 'Mother' => array('id' => 2, 'name' => 'mother', 'mother_id' => 4, 'father_id' => 5, - 'Mother' => array('id' => 4, 'name' => 'mother - grand mother', 'mother_id' => 0, 'father_id' => 0), - 'Father' => array('id' => 5, 'name' => 'mother - grand father', 'mother_id' => 0, 'father_id' => 0)), - 'Father' => array('id' => 3, 'name' => 'father', 'mother_id' => 6, 'father_id' => 7, - 'Father' => array('id' => 7, 'name' => 'father - grand father', 'mother_id' => 0, 'father_id' => 0), - 'Mother' => array('id' => 6, 'name' => 'father - grand mother', 'mother_id' => 0, 'father_id' => 0))); + 'Person' => array( + 'id' => 1, + 'name' => 'person', + 'mother_id' => 2, + 'father_id' => 3 + ), + 'Mother' => array( + 'id' => 2, + 'name' => 'mother', + 'mother_id' => 4, + 'father_id' => 5, + 'Mother' => array( + 'id' => 4, + 'name' => 'mother - grand mother', + 'mother_id' => 0, + 'father_id' => 0 + ), + 'Father' => array( + 'id' => 5, + 'name' => 'mother - grand father', + 'mother_id' => 0, + 'father_id' => 0 + )), + 'Father' => array( + 'id' => 3, + 'name' => 'father', + 'mother_id' => 6, + 'father_id' => 7, + 'Father' => array( + 'id' => 7, + 'name' => 'father - grand father', + 'mother_id' => 0, + 'father_id' => 0 + ), + 'Mother' => array( + 'id' => 6, + 'name' => 'father - grand mother', + 'mother_id' => 0, + 'father_id' => 0 + ))); + $this->assertEqual($result, $expected); $TestModel->recursive = 3; $result = $TestModel->read(null, 1); $expected = array( - 'Person' => array('id' => 1, 'name' => 'person', 'mother_id' => 2, 'father_id' => 3), - 'Mother' => array('id' => 2, 'name' => 'mother', 'mother_id' => 4, 'father_id' => 5, - 'Mother' => array('id' => 4, 'name' => 'mother - grand mother', 'mother_id' => 0, 'father_id' => 0, - 'Mother' => array(), - 'Father' => array()), - 'Father' => array('id' => 5, 'name' => 'mother - grand father', 'mother_id' => 0, 'father_id' => 0, - 'Father' => array(), - 'Mother' => array())), - 'Father' => array('id' => 3, 'name' => 'father', 'mother_id' => 6, 'father_id' => 7, - 'Father' => array('id' => 7, 'name' => 'father - grand father', 'mother_id' => 0, 'father_id' => 0, - 'Father' => array(), - 'Mother' => array()), - 'Mother' => array('id' => 6, 'name' => 'father - grand mother', 'mother_id' => 0, 'father_id' => 0, - 'Mother' => array(), - 'Father' => array()))); + 'Person' => array( + 'id' => 1, + 'name' => 'person', + 'mother_id' => 2, + 'father_id' => 3 + ), + 'Mother' => array( + 'id' => 2, + 'name' => 'mother', + 'mother_id' => 4, + 'father_id' => 5, + 'Mother' => array( + 'id' => 4, + 'name' => 'mother - grand mother', + 'mother_id' => 0, + 'father_id' => 0, + 'Mother' => array(), + 'Father' => array()), + 'Father' => array( + 'id' => 5, + 'name' => 'mother - grand father', + 'mother_id' => 0, + 'father_id' => 0, + 'Father' => array(), + 'Mother' => array() + )), + 'Father' => array( + 'id' => 3, + 'name' => 'father', + 'mother_id' => 6, + 'father_id' => 7, + 'Father' => array( + 'id' => 7, + 'name' => 'father - grand father', + 'mother_id' => 0, + 'father_id' => 0, + 'Father' => array(), + 'Mother' => array() + ), + 'Mother' => array( + 'id' => 6, + 'name' => 'father - grand mother', + 'mother_id' => 0, + 'father_id' => 0, + 'Mother' => array(), + 'Father' => array() + ))); + $this->assertEqual($result, $expected); } /** @@ -879,29 +1406,115 @@ class ModelTest extends CakeTestCase { $result = $TestModel->find('all'); $expected = array( array( - 'TestPluginArticle' => array('id' => 1, 'user_id' => 1, 'title' => 'First Plugin Article', 'body' => 'First Plugin Article Body', 'published' => 'Y', 'created' => '2008-09-24 10:39:23', 'updated' => '2008-09-24 10:41:31'), - 'User' => array('id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'), + 'TestPluginArticle' => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Plugin Article', + 'body' => 'First Plugin Article Body', + 'published' => 'Y', + 'created' => '2008-09-24 10:39:23', + 'updated' => '2008-09-24 10:41:31' + ), + 'User' => array( + 'id' => 1, + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), 'TestPluginComment' => array( - array('id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Plugin Article', 'published' => 'Y', 'created' => '2008-09-24 10:45:23', 'updated' => '2008-09-24 10:47:31'), - array('id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Plugin Article', 'published' => 'Y', 'created' => '2008-09-24 10:47:23', 'updated' => '2008-09-24 10:49:31'), - array('id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Plugin Article', 'published' => 'Y', 'created' => '2008-09-24 10:49:23', 'updated' => '2008-09-24 10:51:31'), - array('id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Plugin Article', 'published' => 'N', 'created' => '2008-09-24 10:51:23', 'updated' => '2008-09-24 10:53:31') - ) - ), + array( + 'id' => 1, + 'article_id' => 1, + 'user_id' => 2, + 'comment' => 'First Comment for First Plugin Article', + 'published' => 'Y', + 'created' => '2008-09-24 10:45:23', + 'updated' => '2008-09-24 10:47:31' + ), + array( + 'id' => 2, + 'article_id' => 1, + 'user_id' => 4, + 'comment' => 'Second Comment for First Plugin Article', + 'published' => 'Y', + 'created' => '2008-09-24 10:47:23', + 'updated' => '2008-09-24 10:49:31' + ), + array( + 'id' => 3, + 'article_id' => 1, + 'user_id' => 1, + 'comment' => 'Third Comment for First Plugin Article', + 'published' => 'Y', + 'created' => '2008-09-24 10:49:23', + 'updated' => '2008-09-24 10:51:31' + ), + array( + 'id' => 4, + 'article_id' => 1, + 'user_id' => 1, + 'comment' => 'Fourth Comment for First Plugin Article', + 'published' => 'N', + 'created' => '2008-09-24 10:51:23', + 'updated' => '2008-09-24 10:53:31' + ))), array( - 'TestPluginArticle' => array('id' => 2, 'user_id' => 3, 'title' => 'Second Plugin Article', 'body' => 'Second Plugin Article Body', 'published' => 'Y', 'created' => '2008-09-24 10:41:23', 'updated' => '2008-09-24 10:43:31'), - 'User' => array('id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'), + 'TestPluginArticle' => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Plugin Article', + 'body' => 'Second Plugin Article Body', + 'published' => 'Y', + 'created' => '2008-09-24 10:41:23', + 'updated' => '2008-09-24 10:43:31' + ), + 'User' => array( + 'id' => 3, + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), 'TestPluginComment' => array( - array('id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Plugin Article', 'published' => 'Y', 'created' => '2008-09-24 10:53:23', 'updated' => '2008-09-24 10:55:31'), - array('id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Plugin Article', 'published' => 'Y', 'created' => '2008-09-24 10:55:23', 'updated' => '2008-09-24 10:57:31') - ) - ), + array( + 'id' => 5, + 'article_id' => 2, + 'user_id' => 1, + 'comment' => 'First Comment for Second Plugin Article', + 'published' => 'Y', + 'created' => '2008-09-24 10:53:23', + 'updated' => '2008-09-24 10:55:31' + ), + array( + 'id' => 6, + 'article_id' => 2, + 'user_id' => 2, + 'comment' => 'Second Comment for Second Plugin Article', + 'published' => 'Y', + 'created' => '2008-09-24 10:55:23', + 'updated' => '2008-09-24 10:57:31' + ))), array( - 'TestPluginArticle' => array('id' => 3,'user_id' => 1, 'title' => 'Third Plugin Article', 'body' => 'Third Plugin Article Body', 'published' => 'Y', 'created' => '2008-09-24 10:43:23', 'updated' => '2008-09-24 10:45:31'), - 'User' => array('id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'), + 'TestPluginArticle' => array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Plugin Article', + 'body' => 'Third Plugin Article Body', + 'published' => 'Y', + 'created' => '2008-09-24 10:43:23', + 'updated' => '2008-09-24 10:45:31' + ), + 'User' => array( + 'id' => 1, + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), 'TestPluginComment' => array() - ) - ); + )); + $this->assertEqual($result, $expected); } /** @@ -954,11 +1567,38 @@ class ModelTest extends CakeTestCase { } $expected = array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => $intLength, 'key' => 'primary'), - 'user' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => 255), - 'password' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => 255), - 'created' => array('type' => 'datetime', 'null' => true, 'default' => null, 'length' => null), - 'updated'=> array('type' => 'datetime', 'null' => true, 'default' => null, 'length' => null)); + 'id' => array( + 'type' => 'integer', + 'null' => false, + 'default' => null, + 'length' => $intLength, + 'key' => 'primary' + ), + 'user' => array( + 'type' => 'string', + 'null' => false, + 'default' => '', + 'length' => 255 + ), + 'password' => array( + 'type' => 'string', + 'null' => false, + 'default' => '', + 'length' => 255 + ), + 'created' => array( + 'type' => 'datetime', + 'null' => true, + 'default' => null, + 'length' => null + ), + 'updated'=> array( + 'type' => 'datetime', + 'null' => true, + 'default' => null, + 'length' => null + )); + $this->assertEqual($result, $expected); $TestModel =& new Article(); @@ -968,25 +1608,52 @@ class ModelTest extends CakeTestCase { $FeaturedModel =& new Featured(); $data = array( - 'article_featured_id' => 1, 'category_id' => 1, - 'published_date' => array('year' => 2008, 'month' => 06, 'day' => 11), - 'end_date' => array('year' => 2008, 'month' => 06, 'day' => 20) - ); - $expected = array('Featured' => array( - 'article_featured_id' => 1, 'category_id' => 1, - 'published_date' => '2008-6-11 00:00:00', 'end_date' => '2008-6-20 00:00:00' + 'article_featured_id' => 1, + 'category_id' => 1, + 'published_date' => array( + 'year' => 2008, + 'month' => 06, + 'day' => 11 + ), + 'end_date' => array( + 'year' => 2008, + 'month' => 06, + 'day' => 20 )); + + $expected = array( + 'Featured' => array( + 'article_featured_id' => 1, + 'category_id' => 1, + 'published_date' => '2008-6-11 00:00:00', + 'end_date' => '2008-6-20 00:00:00' + )); + $this->assertEqual($FeaturedModel->create($data), $expected); $data = array( - 'published_date' => array('year' => 2008, 'month' => 06, 'day' => 11), - 'end_date' => array('year' => 2008, 'month' => 06, 'day' => 20), - 'article_featured_id' => 1, 'category_id' => 1 + 'published_date' => array( + 'year' => 2008, + 'month' => 06, + 'day' => 11 + ), + 'end_date' => array( + 'year' => 2008, + 'month' => 06, + 'day' => 20 + ), + 'article_featured_id' => 1, + 'category_id' => 1 ); - $expected = array('Featured' => array( - 'published_date' => '2008-6-11 00:00:00', 'end_date' => '2008-6-20 00:00:00', - 'article_featured_id' => 1, 'category_id' => 1 + + $expected = array( + 'Featured' => array( + 'published_date' => '2008-6-11 00:00:00', + 'end_date' => '2008-6-20 00:00:00', + 'article_featured_id' => 1, + 'category_id' => 1 )); + $this->assertEqual($FeaturedModel->create($data), $expected); } /** @@ -1037,32 +1704,91 @@ class ModelTest extends CakeTestCase { */ function testCreateWithPKFiltering() { $TestModel =& new Article(); - $data = array('id' => 5, 'user_id' => 2, 'title' => 'My article', 'body' => 'Some text'); + $data = array( + 'id' => 5, + 'user_id' => 2, + 'title' => 'My article', + 'body' => 'Some text' + ); $result = $TestModel->create($data); - $expected = array('Article' => array('published' => 'N', 'id' => 5, 'user_id' => 2, 'title' => 'My article', 'body' => 'Some text')); + $expected = array( + 'Article' => array( + 'published' => 'N', + 'id' => 5, + 'user_id' => 2, + 'title' => 'My article', + 'body' => 'Some text' + )); + $this->assertEqual($result, $expected); $this->assertEqual($TestModel->id, 5); $result = $TestModel->create($data, true); - $expected = array('Article' => array('published' => 'N', 'id' => false, 'user_id' => 2, 'title' => 'My article', 'body' => 'Some text')); + $expected = array( + 'Article' => array( + 'published' => 'N', + 'id' => false, + 'user_id' => 2, + 'title' => 'My article', + 'body' => 'Some text' + )); + $this->assertEqual($result, $expected); $this->assertFalse($TestModel->id); $result = $TestModel->create(array('Article' => $data), true); - $expected = array('Article' => array('published' => 'N', 'id' => false, 'user_id' => 2, 'title' => 'My article', 'body' => 'Some text')); + $expected = array( + 'Article' => array( + 'published' => 'N', + 'id' => false, + 'user_id' => 2, + 'title' => 'My article', + 'body' => 'Some text' + )); + $this->assertEqual($result, $expected); $this->assertFalse($TestModel->id); - $data = array('id' => 6, 'user_id' => 2, 'title' => 'My article', 'body' => 'Some text', 'created' => '1970-01-01 00:00:00', 'updated' => '1970-01-01 12:00:00', 'modified' => '1970-01-01 12:00:00'); + $data = array( + 'id' => 6, + 'user_id' => 2, + 'title' => 'My article', + 'body' => 'Some text', + 'created' => '1970-01-01 00:00:00', + 'updated' => '1970-01-01 12:00:00', + 'modified' => '1970-01-01 12:00:00' + ); $result = $TestModel->create($data); - $expected = array('Article' => array('published' => 'N', 'id' => 6, 'user_id' => 2, 'title' => 'My article', 'body' => 'Some text', 'created' => '1970-01-01 00:00:00', 'updated' => '1970-01-01 12:00:00', 'modified' => '1970-01-01 12:00:00')); + $expected = array( + 'Article' => array( + 'published' => 'N', + 'id' => 6, + 'user_id' => 2, + 'title' => 'My article', + 'body' => 'Some text', + 'created' => '1970-01-01 00:00:00', + 'updated' => '1970-01-01 12:00:00', + 'modified' => '1970-01-01 12:00:00' + )); $this->assertEqual($result, $expected); $this->assertEqual($TestModel->id, 6); - $result = $TestModel->create(array('Article' => array_diff_key($data, array('created' => true, 'updated' => true, 'modified' => true))), true); - $expected = array('Article' => array('published' => 'N', 'id' => false, 'user_id' => 2, 'title' => 'My article', 'body' => 'Some text')); + $result = $TestModel->create(array( + 'Article' => array_diff_key($data, array( + 'created' => true, + 'updated' => true, + 'modified' => true + ))), true); + $expected = array( + 'Article' => array( + 'published' => 'N', + 'id' => false, + 'user_id' => 2, + 'title' => 'My article', + 'body' => 'Some text' + )); $this->assertEqual($result, $expected); $this->assertFalse($TestModel->id); } @@ -1077,41 +1803,165 @@ class ModelTest extends CakeTestCase { $Article =& new Article(); $Comment =& new Comment(); - $articles = $Article->find('all', array('fields' => array('id','title'), 'recursive' => -1)); - $comments = $Comment->find('all', array('fields' => array('id','article_id','user_id','comment','published'), 'recursive' => -1)); - $this->assertEqual($articles, array( - array('Article' => array('id' => 1, 'title' => 'First Article')), - array('Article' => array('id' => 2, 'title' => 'Second Article')), - array('Article' => array('id' => 3, 'title' => 'Third Article')))); - $this->assertEqual($comments, array( - array('Comment' => array('id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y')), - array('Comment' => array('id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y')), - array('Comment' => array('id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y')), - array('Comment' => array('id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N')), - array('Comment' => array('id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y')), - array('Comment' => array('id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y')))); + $articles = $Article->find('all', array( + 'fields' => array('id','title'), + 'recursive' => -1 + )); + + $comments = $Comment->find('all', array( + 'fields' => array('id','article_id','user_id','comment','published'), 'recursive' => -1)); + + $this->assertEqual($articles, array( + array('Article' => array( + 'id' => 1, + 'title' => 'First Article' + )), + array('Article' => array( + 'id' => 2, + 'title' => 'Second Article' + )), + array('Article' => array( + 'id' => 3, + 'title' => 'Third Article' + )))); + + $this->assertEqual($comments, array( + array('Comment' => array( + 'id' => 1, + 'article_id' => 1, + 'user_id' => 2, + 'comment' => 'First Comment for First Article', + 'published' => 'Y' + )), + array('Comment' => array( + 'id' => 2, + 'article_id' => 1, + 'user_id' => 4, + 'comment' => 'Second Comment for First Article', + 'published' => 'Y' + )), + array('Comment' => array( + 'id' => 3, + 'article_id' => 1, + 'user_id' => 1, + 'comment' => 'Third Comment for First Article', + 'published' => 'Y' + )), + array('Comment' => array( + 'id' => 4, + 'article_id' => 1, + 'user_id' => 1, + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N' + )), + array('Comment' => array( + 'id' => 5, + 'article_id' => 2, + 'user_id' => 1, + 'comment' => 'First Comment for Second Article', + 'published' => 'Y' + )), + array('Comment' => array( + 'id' => 6, + 'article_id' => 2, + 'user_id' => 2, + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y' + )))); + + $data = array( + 'Comment' => array( + 'article_id' => 2, + 'user_id' => 4, + 'comment' => 'Brand New Comment', + 'published' => 'N' + ), + 'Article' => array( + 'id' => 2, + 'title' => 'Second Article Modified' + )); - $data = array('Comment' => array('article_id' => 2, 'user_id' => 4, 'comment' => 'Brand New Comment', 'published' => 'N'), - 'Article' => array('id' => 2, 'title' => 'Second Article Modified')); $result = $Comment->create($data); + $this->assertTrue($result); $result = $Comment->save(); $this->assertTrue($result); - $articles = $Article->find('all', array('fields' => array('id','title'), 'recursive' => -1)); - $comments = $Comment->find('all', array('fields' => array('id','article_id','user_id','comment','published'), 'recursive' => -1)); + $articles = $Article->find('all', array( + 'fields' => array('id','title'), + 'recursive' => -1 + )); + + $comments = $Comment->find('all', array( + 'fields' => array('id','article_id','user_id','comment','published'), + 'recursive' => -1 + )); + $this->assertEqual($articles, array( - array('Article' => array('id' => 1, 'title' => 'First Article')), - array('Article' => array('id' => 2, 'title' => 'Second Article')), - array('Article' => array('id' => 3, 'title' => 'Third Article')))); + array('Article' => array( + 'id' => 1, + 'title' => 'First Article' + )), + array('Article' => array( + 'id' => 2, + 'title' => 'Second Article' + )), + array('Article' => array( + 'id' => 3, + 'title' => 'Third Article' + )))); + $this->assertEqual($comments, array( - array('Comment' => array('id' => 1, 'article_id' => 1, 'user_id' => 2, 'comment' => 'First Comment for First Article', 'published' => 'Y')), - array('Comment' => array('id' => 2, 'article_id' => 1, 'user_id' => 4, 'comment' => 'Second Comment for First Article', 'published' => 'Y')), - array('Comment' => array('id' => 3, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Third Comment for First Article', 'published' => 'Y')), - array('Comment' => array('id' => 4, 'article_id' => 1, 'user_id' => 1, 'comment' => 'Fourth Comment for First Article', 'published' => 'N')), - array('Comment' => array('id' => 5, 'article_id' => 2, 'user_id' => 1, 'comment' => 'First Comment for Second Article', 'published' => 'Y')), - array('Comment' => array('id' => 6, 'article_id' => 2, 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y')), - array('Comment' => array('id' => 7, 'article_id' => 2, 'user_id' => 4, 'comment' => 'Brand New Comment', 'published' => 'N')))); + array('Comment' => array( + 'id' => 1, + 'article_id' => 1, + 'user_id' => 2, + 'comment' => 'First Comment for First Article', + 'published' => 'Y' + )), + array('Comment' => array( + 'id' => 2, + 'article_id' => 1, + 'user_id' => 4, + 'comment' => 'Second Comment for First Article', + 'published' => 'Y' + )), + array('Comment' => array( + 'id' => 3, + 'article_id' => 1, + 'user_id' => 1, + 'comment' => 'Third Comment for First Article', + 'published' => 'Y' + )), + array('Comment' => array( + 'id' => 4, + 'article_id' => 1, + 'user_id' => 1, + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N' + )), + array('Comment' => array( + 'id' => 5, + 'article_id' => 2, + 'user_id' => 1, + 'comment' => 'First Comment for Second Article', + 'published' => 'Y' + )), + array('Comment' => array( + 'id' => 6, + 'article_id' => 2, + 'user_id' => 2, 'comment' => + 'Second Comment for Second Article', + 'published' => 'Y' + )), + array('Comment' => array( + 'id' => 7, + 'article_id' => 2, + 'user_id' => 4, + 'comment' => 'Brand New Comment', + 'published' => 'N' + )))); + } /** * testCreationWithMultipleDataSameModel method @@ -1127,8 +1977,17 @@ class ModelTest extends CakeTestCase { $result = $Article->field('title', array('id' => 1)); $this->assertEqual($result, 'First Article'); - $data = array('Article' => array('user_id' => 2, 'title' => 'Brand New Article', 'body' => 'Brand New Article Body', 'published' => 'Y'), - 'SecondaryArticle' => array('id' => 1)); + $data = array( + 'Article' => array( + 'user_id' => 2, + 'title' => 'Brand New Article', + 'body' => 'Brand New Article Body', + 'published' => 'Y' + ), + 'SecondaryArticle' => array( + 'id' => 1 + )); + $Article->create(); $result = $Article->save($data); $this->assertTrue($result); @@ -1139,12 +1998,28 @@ class ModelTest extends CakeTestCase { $result = $Article->field('title', array('id' => 1)); $this->assertEqual($result, 'First Article'); - $articles = $Article->find('all', array('fields' => array('id','title'), 'recursive' => -1)); + $articles = $Article->find('all', array( + 'fields' => array('id','title'), + 'recursive' => -1 + )); + $this->assertEqual($articles, array( - array('Article' => array('id' => 1, 'title' => 'First Article')), - array('Article' => array('id' => 2, 'title' => 'Second Article')), - array('Article' => array('id' => 3, 'title' => 'Third Article')), - array('Article' => array('id' => 4, 'title' => 'Brand New Article')))); + array('Article' => array( + 'id' => 1, + 'title' => 'First Article' + )), + array('Article' => array( + 'id' => 2, + 'title' => 'Second Article' + )), + array('Article' => array( + 'id' => 3, + 'title' => 'Third Article' + )), + array('Article' => array( + 'id' => 4, + 'title' => 'Brand New Article' + )))); } /** * testCreationWithMultipleDataSameModelManualInstances method @@ -1160,8 +2035,14 @@ class ModelTest extends CakeTestCase { $result = $Primary->field('primary_name', array('id' => 1)); $this->assertEqual($result, 'Primary Name Existing'); - $data = array('PrimaryModel' => array('primary_name' => 'Primary Name New'), - 'SecondaryModel' => array('id' => array(1))); + $data = array( + 'PrimaryModel' => array( + 'primary_name' => 'Primary Name New' + ), + 'SecondaryModel' => array( + 'id' => array(1) + )); + $Primary->create(); $result = $Primary->save($data); $this->assertTrue($result); @@ -1194,15 +2075,51 @@ class ModelTest extends CakeTestCase { $TestModel->id = 7; $result = $TestModel->read(); $expected = array( - 'CategoryThread' => array('id' => 7, 'parent_id' => 6, 'name' => 'Category 2.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), - 'ParentCategory' => array('id' => 6, 'parent_id' => 5, 'name' => 'Category 2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 5, 'parent_id' => 4, 'name' => 'Category 1.1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 4, 'parent_id' => 3, 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 3, 'parent_id' => 2, 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'))))) - ) - ); + 'CategoryThread' => array( + 'id' => 7, + 'parent_id' => 6, + 'name' => 'Category 2.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 6, + 'parent_id' => 5, + 'name' => 'Category 2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 5, + 'parent_id' => 4, + 'name' => 'Category 1.1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ))))))); + $this->db->fullDebug = $fullDebug; $this->assertEqual($result, $expected); } @@ -1222,15 +2139,51 @@ class ModelTest extends CakeTestCase { $result = $TestModel->find(array('CategoryThread.id' => 7)); $expected = array( - 'CategoryThread' => array('id' => 7, 'parent_id' => 6, 'name' => 'Category 2.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), - 'ParentCategory' => array('id' => 6, 'parent_id' => 5, 'name' => 'Category 2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 5, 'parent_id' => 4, 'name' => 'Category 1.1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 4, 'parent_id' => 3, 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 3, 'parent_id' => 2, 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'))))) - ) - ); + 'CategoryThread' => array( + 'id' => 7, + 'parent_id' => 6, + 'name' => 'Category 2.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 6, + 'parent_id' => 5, + 'name' => 'Category 2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 5, + 'parent_id' => 4, + 'name' => 'Category 1.1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ))))))); + $this->db->fullDebug = $fullDebug; $this->assertEqual($result, $expected); } @@ -1249,40 +2202,208 @@ class ModelTest extends CakeTestCase { $TestModel->recursive = 6; $result = $TestModel->find('all', null, null, 'CategoryThread.id ASC'); $expected = array( - array('CategoryThread' => array('id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), - 'ParentCategory' => array('id' => null, 'parent_id' => null, 'name' => null, 'created' => null, 'updated' => null, 'ParentCategory' => array())), - array('CategoryThread' => array('id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), - 'ParentCategory' => array('id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array())), - array('CategoryThread' => array('id' => 3, 'parent_id' => 2, 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), - 'ParentCategory' => array('id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array()))), - array('CategoryThread' => array('id' => 4, 'parent_id' => 3, 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), - 'ParentCategory' => array('id' => 3, 'parent_id' => 2, 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array())))), - array('CategoryThread' => array('id' => 5, 'parent_id' => 4, 'name' => 'Category 1.1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), - 'ParentCategory' => array('id' => 4, 'parent_id' => 3, 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 3, 'parent_id' => 2, 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array()))))), - array('CategoryThread' => array('id' => 6, 'parent_id' => 5, 'name' => 'Category 2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), - 'ParentCategory' => array('id' => 5, 'parent_id' => 4, 'name' => 'Category 1.1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 4, 'parent_id' => 3, 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 3, 'parent_id' => 2, 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array())))))), - array('CategoryThread' => array('id' => 7, 'parent_id' => 6, 'name' => 'Category 2.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31'), - 'ParentCategory' => array('id' => 6, 'parent_id' => 5, 'name' => 'Category 2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 5, 'parent_id' => 4, 'name' => 'Category 1.1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 4, 'parent_id' => 3, 'name' => 'Category 1.1.2', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 3, 'parent_id' => 2, 'name' => 'Category 1.1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 2, 'parent_id' => 1, 'name' => 'Category 1.1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array('id' => 1, 'parent_id' => 0, 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31')))))))); + array( + 'CategoryThread' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => null, + 'parent_id' => null, + 'name' => null, + 'created' => null, + 'updated' => null, + 'ParentCategory' => array() + )), + array( + 'CategoryThread' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array() + )), + array( + 'CategoryThread' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array() + ))), + array( + 'CategoryThread' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array() + )))), + array( + 'CategoryThread' => array( + 'id' => 5, + 'parent_id' => 4, + 'name' => 'Category 1.1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array() + ))))), + array( + 'CategoryThread' => array( + 'id' => 6, + 'parent_id' => 5, + 'name' => 'Category 2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 5, + 'parent_id' => 4, + 'name' => 'Category 1.1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array() + )))))), + array( + 'CategoryThread' => array( + 'id' => 7, + 'parent_id' => 6, + 'name' => 'Category 2.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 6, + 'parent_id' => 5, + 'name' => 'Category 2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 5, + 'parent_id' => 4, + 'name' => 'Category 1.1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + )))))))); + $this->db->fullDebug = $fullDebug; $this->assertEqual($result, $expected); } @@ -1299,11 +2420,9 @@ class ModelTest extends CakeTestCase { $result = $NumericArticle->find($data); $this->assertTrue(!empty($result)); - // @TODO: make this pass in Cake 2.0 with passing the column around in db->value() - // SELECT * from articles WHERE title = 12345 // will find the article with title = 12345abcde, too : / - // $data = array('title' => '12345'); - // $result = $NumericArticle->find($data); - // $this->assertTrue(empty($result)); + $data = array('title' => '12345'); + $result = $NumericArticle->find($data); + $this->assertTrue(empty($result)); } /** @@ -1414,86 +2533,255 @@ class ModelTest extends CakeTestCase { $TestModel =& new Article(); $TestModel->displayField = 'title'; - $result = $TestModel->find('list', array('order' => 'Article.title ASC')); - $expected = array(1 => 'First Article', 2 => 'Second Article', 3 => 'Third Article'); + $result = $TestModel->find('list', array( + 'order' => 'Article.title ASC' + )); + + $expected = array( + 1 => 'First Article', + 2 => 'Second Article', + 3 => 'Third Article' + ); $this->assertEqual($result, $expected); $db =& ConnectionManager::getDataSource('test_suite'); if ($db->config['driver'] == 'mysql') { - $result = $TestModel->find('list', array('order' => array('FIELD(Article.id, 3, 2) ASC', 'Article.title ASC'))); - $expected = array(1 => 'First Article', 3 => 'Third Article', 2 => 'Second Article'); + $result = $TestModel->find('list', array( + 'order' => array('FIELD(Article.id, 3, 2) ASC', 'Article.title ASC') + )); + $expected = array( + 1 => 'First Article', + 3 => 'Third Article', + 2 => 'Second Article' + ); $this->assertEqual($result, $expected); } - $result = Set::combine($TestModel->find('all', array('order' => 'Article.title ASC', 'fields' => array('id', 'title'))), '{n}.Article.id', '{n}.Article.title'); - $expected = array(1 => 'First Article', 2 => 'Second Article', 3 => 'Third Article'); - $this->assertEqual($result, $expected); - - $result = Set::combine($TestModel->find('all', array('order' => 'Article.title ASC')), '{n}.Article.id', '{n}.Article'); + $result = Set::combine( + $TestModel->find('all', array( + 'order' => 'Article.title ASC', + 'fields' => array('id', 'title') + )), + '{n}.Article.id', '{n}.Article.title' + ); $expected = array( - 1 => array('id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), - 2 => array('id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), - 3 => array('id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31')); + 1 => 'First Article', + 2 => 'Second Article', + 3 => 'Third Article' + ); $this->assertEqual($result, $expected); - $result = Set::combine($TestModel->find('all', array('order' => 'Article.title ASC')), '{n}.Article.id', '{n}.Article', '{n}.Article.user_id'); - $expected = array(1 => array( - 1 => array('id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), - 3 => array('id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31')), - 3 => array(2 => array('id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'))); + $result = Set::combine( + $TestModel->find('all', array( + 'order' => 'Article.title ASC' + )), + '{n}.Article.id', '{n}.Article' + ); + $expected = array( + 1 => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 2 => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 3 => array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + )); + $this->assertEqual($result, $expected); - $result = Set::combine($TestModel->find('all', array('order' => 'Article.title ASC', 'fields' => array('id', 'title', 'user_id'))), '{n}.Article.id', '{n}.Article.title', '{n}.Article.user_id'); - $expected = array(1 => array(1 => 'First Article', 3 => 'Third Article'), 3 => array(2 => 'Second Article')); + $result = Set::combine( + $TestModel->find('all', array( + 'order' => 'Article.title ASC' + )), + '{n}.Article.id', '{n}.Article', '{n}.Article.user_id' + ); + $expected = array( + 1 => array( + 1 => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 3 => array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + )), + 3 => array( + 2 => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ))); + + $this->assertEqual($result, $expected); + + $result = Set::combine( + $TestModel->find('all', array( + 'order' => 'Article.title ASC', + 'fields' => array('id', 'title', 'user_id') + )), + '{n}.Article.id', '{n}.Article.title', '{n}.Article.user_id' + ); + + $expected = array( + 1 => array( + 1 => 'First Article', + 3 => 'Third Article' + ), + 3 => array( + 2 => 'Second Article' + )); $this->assertEqual($result, $expected); $TestModel =& new Apple(); - $expected = array(1 => 'Red Apple 1', 2 => 'Bright Red Apple', 3 => 'green blue', 4 => 'Test Name', 5 => 'Blue Green', 6 => 'My new apple', 7 => 'Some odd color'); + $expected = array( + 1 => 'Red Apple 1', + 2 => 'Bright Red Apple', + 3 => 'green blue', + 4 => 'Test Name', + 5 => 'Blue Green', + 6 => 'My new apple', + 7 => 'Some odd color' + ); $this->assertEqual($TestModel->find('list'), $expected); $this->assertEqual($TestModel->Parent->find('list'), $expected); $TestModel =& new Post(); - $result = $TestModel->find('list', array('fields' => 'Post.title')); - $expected = array(1 => 'First Post', 2 => 'Second Post', 3 => 'Third Post'); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('list', array('fields' => 'title')); - $expected = array(1 => 'First Post', 2 => 'Second Post', 3 => 'Third Post'); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('list', array('fields' => array('title', 'id'))); - $expected = array('First Post' => '1', 'Second Post' => '2', 'Third Post' => '3'); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('list', array('fields' => array('title', 'id', 'created'))); + $result = $TestModel->find('list', array( + 'fields' => 'Post.title' + )); $expected = array( - '2007-03-18 10:39:23' => array('First Post' => '1'), - '2007-03-18 10:41:23' => array('Second Post' => '2'), - '2007-03-18 10:43:23' => array('Third Post' => '3'), + 1 => 'First Post', + 2 => 'Second Post', + 3 => 'Third Post' ); $this->assertEqual($result, $expected); - $result = $TestModel->find('list', array('fields' => array('Post.body'))); - $expected = array(1 => 'First Post Body', 2 => 'Second Post Body', 3 => 'Third Post Body'); + $result = $TestModel->find('list', array( + 'fields' => 'title' + )); + $expected = array( + 1 => 'First Post', + 2 => 'Second Post', + 3 => 'Third Post' + ); $this->assertEqual($result, $expected); - $result = $TestModel->find('list', array('fields' => array('Post.title', 'Post.body'))); - $expected = array('First Post' => 'First Post Body', 'Second Post' => 'Second Post Body', 'Third Post' => 'Third Post Body'); + $result = $TestModel->find('list', array( + 'fields' => array('title', 'id') + )); + $expected = array( + 'First Post' => '1', + 'Second Post' => '2', + 'Third Post' => '3' + ); $this->assertEqual($result, $expected); - $result = $TestModel->find('list', array('fields' => array('Post.id', 'Post.title', 'Author.user'), 'recursive' => 1)); - $expected = array('mariano' => array(1 => 'First Post', 3 => 'Third Post'), 'larry' => array(2 => 'Second Post')); + $result = $TestModel->find('list', array( + 'fields' => array('title', 'id', 'created') + )); + $expected = array( + '2007-03-18 10:39:23' => array( + 'First Post' => '1' + ), + '2007-03-18 10:41:23' => array( + 'Second Post' => '2' + ), + '2007-03-18 10:43:23' => array( + 'Third Post' => '3' + ), + ); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('list', array( + 'fields' => array('Post.body') + )); + $expected = array( + 1 => 'First Post Body', + 2 => 'Second Post Body', + 3 => 'Third Post Body' + ); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('list', array( + 'fields' => array('Post.title', 'Post.body') + )); + $expected = array( + 'First Post' => 'First Post Body', + 'Second Post' => 'Second Post Body', + 'Third Post' => 'Third Post Body' + ); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('list', array( + 'fields' => array('Post.id', 'Post.title', 'Author.user'), + 'recursive' => 1 + )); + $expected = array( + 'mariano' => array( + 1 => 'First Post', + 3 => 'Third Post' + ), + 'larry' => array( + 2 => 'Second Post' + )); $this->assertEqual($result, $expected); $TestModel =& new User(); - $result = $TestModel->find('list', array('fields' => array('User.user', 'User.password'))); - $expected = array('mariano' => '5f4dcc3b5aa765d61d8327deb882cf99', 'nate' => '5f4dcc3b5aa765d61d8327deb882cf99', 'larry' => '5f4dcc3b5aa765d61d8327deb882cf99', 'garrett' => '5f4dcc3b5aa765d61d8327deb882cf99'); + $result = $TestModel->find('list', array( + 'fields' => array('User.user', 'User.password') + )); + $expected = array( + 'mariano' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'nate' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'larry' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'garrett' => '5f4dcc3b5aa765d61d8327deb882cf99' + ); $this->assertEqual($result, $expected); $TestModel =& new ModifiedAuthor(); - $result = $TestModel->find('list', array('fields' => array('Author.id', 'Author.user'))); - $expected = array(1 => 'mariano (CakePHP)', 2 => 'nate (CakePHP)', 3 => 'larry (CakePHP)', 4 => 'garrett (CakePHP)'); + $result = $TestModel->find('list', array( + 'fields' => array('Author.id', 'Author.user') + )); + $expected = array( + 1 => 'mariano (CakePHP)', + 2 => 'nate (CakePHP)', + 3 => 'larry (CakePHP)', + 4 => 'garrett (CakePHP)' + ); $this->assertEqual($result, $expected); } /** @@ -1537,7 +2825,9 @@ class ModelTest extends CakeTestCase { $this->assertEqual($result, 'mariano'); $TestModel->id = false; - $result = $TestModel->field('user', array('user' => 'mariano')); + $result = $TestModel->field('user', array( + 'user' => 'mariano' + )); $this->assertEqual($result, 'mariano'); $result = $TestModel->field('COUNT(*) AS count', true); @@ -1556,10 +2846,17 @@ class ModelTest extends CakeTestCase { $this->loadFixtures('User'); $TestModel =& new User(); - $this->assertFalse($TestModel->isUnique(array('user' => 'nate'))); + $this->assertFalse($TestModel->isUnique(array( + 'user' => 'nate' + ))); $TestModel->id = 2; - $this->assertTrue($TestModel->isUnique(array('user' => 'nate'))); - $this->assertFalse($TestModel->isUnique(array('user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99'))); + $this->assertTrue($TestModel->isUnique(array( + 'user' => 'nate' + ))); + $this->assertFalse($TestModel->isUnique(array( + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' + ))); } /** * testUpdateExisting method @@ -1572,11 +2869,18 @@ class ModelTest extends CakeTestCase { $TestModel =& new User(); $TestModel->create(); - $TestModel->save(array('User' => array('user' => 'some user', 'password' => 'some password'))); + $TestModel->save(array( + 'User' => array( + 'user' => 'some user', + 'password' => 'some password' + ))); $this->assertTrue(is_int($TestModel->id) || (intval($TestModel->id) === 5)); $id = $TestModel->id; - $TestModel->save(array('User' => array('user' => 'updated user'))); + $TestModel->save(array( + 'User' => array( + 'user' => 'updated user' + ))); $this->assertEqual($TestModel->id, $id); $result = $TestModel->findById($id); @@ -1585,8 +2889,15 @@ class ModelTest extends CakeTestCase { $Article =& new Article(); $Comment =& new Comment(); - $data = array('Comment' => array('id' => 1, 'comment' => 'First Comment for First Article'), - 'Article' => array('id' => 2, 'title' => 'Second Article')); + $data = array( + 'Comment' => array( + 'id' => 1, + 'comment' => 'First Comment for First Article' + ), + 'Article' => array( + 'id' => 2, + 'title' => 'Second Article' + )); $result = $Article->save($data); $this->assertTrue($result); @@ -1612,9 +2923,18 @@ class ModelTest extends CakeTestCase { $expected = array(1 => 5, 2 => 4, 3 => 1, 4 => 1, 5 => 1, 6 => 5); $this->assertEqual($result, $expected); - $result = $TestModel->updateAll(array('Comment.comment' => "'Updated today'"), array('Comment.user_id' => 5)); + $result = $TestModel->updateAll( + array('Comment.comment' => "'Updated today'"), + array('Comment.user_id' => 5) + ); $this->assertTrue($result); - $result = Set::extract($TestModel->find('all', array('conditions' => array('Comment.user_id' => 5))), '{n}.Comment.comment'); + $result = Set::extract( + $TestModel->find('all', array( + 'conditions' => array( + 'Comment.user_id' => 5 + ))), + '{n}.Comment.comment' + ); $expected = array_fill(0, 2, 'Updated today'); $this->assertEqual($result, $expected); } @@ -1663,18 +2983,90 @@ class ModelTest extends CakeTestCase { $result = $TestModel->bindModel(array('hasMany' => array('Comment'))); $this->assertTrue($result); - $result = $TestModel->find('all', array('fields' => 'User.id, User.user')); + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user' + )); $expected = array( - array('User' => array('id' => '1', 'user' => 'mariano'), 'Comment' => array( - array('id' => '3', 'article_id' => '1', 'user_id' => '1', 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'), - array('id' => '4', 'article_id' => '1', 'user_id' => '1', 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'), - array('id' => '5', 'article_id' => '2', 'user_id' => '1', 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'))), - array('User' => array('id' => '2', 'user' => 'nate'), 'Comment' => array( - array('id' => '1', 'article_id' => '1', 'user_id' => '2', 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'), - array('id' => '6', 'article_id' => '2', 'user_id' => '2', 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31'))), - array('User' => array('id' => '3', 'user' => 'larry'), 'Comment' => array()), - array('User' => array('id' => '4', 'user' => 'garrett'), 'Comment' => array( - array('id' => '2', 'article_id' => '1', 'user_id' => '4', 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31')))); + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Comment' => array( + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ), + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ))), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Comment' => array() + ), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett' + ), + 'Comment' => array( + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + )))); + $this->assertEqual($result, $expected); $TestModel->resetAssociations(); @@ -1684,22 +3076,108 @@ class ModelTest extends CakeTestCase { $result = $TestModel->bindModel(array('hasMany' => array('Comment')), false); $this->assertTrue($result); - $result = $TestModel->find('all', array('fields' => 'User.id, User.user')); + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user' + )); + $expected = array( - array('User' => array('id' => '1', 'user' => 'mariano'), 'Comment' => array( - array('id' => '3', 'article_id' => '1', 'user_id' => '1', 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'), - array('id' => '4', 'article_id' => '1', 'user_id' => '1', 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'), - array('id' => '5', 'article_id' => '2', 'user_id' => '1', 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'))), - array('User' => array('id' => '2', 'user' => 'nate'), 'Comment' => array( - array('id' => '1', 'article_id' => '1', 'user_id' => '2', 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'), - array('id' => '6', 'article_id' => '2', 'user_id' => '2', 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31'))), - array('User' => array('id' => '3', 'user' => 'larry'), 'Comment' => array()), - array('User' => array('id' => '4', 'user' => 'garrett'), 'Comment' => array( - array('id' => '2', 'article_id' => '1', 'user_id' => '4', 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31')))); + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Comment' => array( + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ), + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ))), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Comment' => array() + ), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett' + ), + 'Comment' => array( + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + )))); + $this->assertEqual($result, $expected); $result = $TestModel->hasMany; - $expected = array('Comment' => array('className' => 'Comment', 'foreignKey' => 'user_id', 'conditions' => null, 'fields' => null, 'order' => null, 'limit' => null, 'offset' => null, 'dependent' => null, 'exclusive' => null, 'finderQuery' => null, 'counterQuery' => null) ); + $expected = array( + 'Comment' => array( + 'className' => 'Comment', + 'foreignKey' => 'user_id', + 'conditions' => null, + 'fields' => null, + 'order' => null, + 'limit' => null, + 'offset' => null, + 'dependent' => null, + 'exclusive' => null, + 'finderQuery' => null, + 'counterQuery' => null + )); $this->assertEqual($result, $expected); $result = $TestModel->unbindModel(array('hasMany' => array('Comment'))); @@ -1709,7 +3187,9 @@ class ModelTest extends CakeTestCase { $expected = array(); $this->assertEqual($result, $expected); - $result = $TestModel->find('all', array('fields' => 'User.id, User.user')); + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user' + )); $expected = array( array('User' => array('id' => '1', 'user' => 'mariano')), array('User' => array('id' => '2', 'user' => 'nate')), @@ -1717,18 +3197,90 @@ class ModelTest extends CakeTestCase { array('User' => array('id' => '4', 'user' => 'garrett'))); $this->assertEqual($result, $expected); - $result = $TestModel->find('all', array('fields' => 'User.id, User.user')); + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user' + )); $expected = array( - array('User' => array('id' => '1', 'user' => 'mariano'), 'Comment' => array( - array('id' => '3', 'article_id' => '1', 'user_id' => '1', 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'), - array('id' => '4', 'article_id' => '1', 'user_id' => '1', 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'), - array('id' => '5', 'article_id' => '2', 'user_id' => '1', 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'))), - array('User' => array('id' => '2', 'user' => 'nate'), 'Comment' => array( - array('id' => '1', 'article_id' => '1', 'user_id' => '2', 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'), - array('id' => '6', 'article_id' => '2', 'user_id' => '2', 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31'))), - array('User' => array('id' => '3', 'user' => 'larry'), 'Comment' => array()), - array('User' => array('id' => '4', 'user' => 'garrett'), 'Comment' => array( - array('id' => '2', 'article_id' => '1', 'user_id' => '4', 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31')))); + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Comment' => array( + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ), + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ))), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Comment' => array() + ), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett' + ), + 'Comment' => array( + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => + 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + )))); $this->assertEqual($result, $expected); $result = $TestModel->unbindModel(array('hasMany' => array('Comment')), false); @@ -1746,38 +3298,130 @@ class ModelTest extends CakeTestCase { $expected = array(); $this->assertEqual($result, $expected); - $result = $TestModel->bindModel(array('hasMany' => array('Comment' => array('className' => 'Comment', 'conditions' => 'Comment.published = \'Y\'') ))); + $result = $TestModel->bindModel(array('hasMany' => array( + 'Comment' => array('className' => 'Comment', 'conditions' => 'Comment.published = \'Y\'') + ))); $this->assertTrue($result); $result = $TestModel->find('all', array('fields' => 'User.id, User.user')); $expected = array( - array('User' => array('id' => '1', 'user' => 'mariano'), 'Comment' => array( - array('id' => '3', 'article_id' => '1', 'user_id' => '1', 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'), - array('id' => '5', 'article_id' => '2', 'user_id' => '1', 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'))), - array('User' => array('id' => '2', 'user' => 'nate'), 'Comment' => array( - array('id' => '1', 'article_id' => '1', 'user_id' => '2', 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'), - array('id' => '6', 'article_id' => '2', 'user_id' => '2', 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31'))), - array('User' => array('id' => '3', 'user' => 'larry'), 'Comment' => array()), - array('User' => array('id' => '4', 'user' => 'garrett'), 'Comment' => array( - array('id' => '2', 'article_id' => '1', 'user_id' => '4', 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31')))); + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Comment' => array( + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ))), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Comment' => array() + ), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett' + ), + 'Comment' => array( + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + )))); + $this->assertEqual($result, $expected); $TestModel2 =& new DeviceType(); - $expected = array('className' => 'FeatureSet', 'foreignKey' => 'feature_set_id', 'conditions' => '', 'fields' => '', 'order' => '', 'counterCache' => ''); + $expected = array( + 'className' => 'FeatureSet', + 'foreignKey' => 'feature_set_id', + 'conditions' => '', + 'fields' => '', + 'order' => '', + 'counterCache' => '' + ); $this->assertEqual($TestModel2->belongsTo['FeatureSet'], $expected); - $TestModel2->bind('FeatureSet', array('conditions' => array('active' => true))); + $TestModel2->bind('FeatureSet', array( + 'conditions' => array('active' => true) + )); $expected['conditions'] = array('active' => true); $this->assertEqual($TestModel2->belongsTo['FeatureSet'], $expected); - $TestModel2->bind('FeatureSet', array('foreignKey' => false, 'conditions' => array('Feature.name' => 'DeviceType.name'))); + $TestModel2->bind('FeatureSet', array( + 'foreignKey' => false, + 'conditions' => array('Feature.name' => 'DeviceType.name') + )); $expected['conditions'] = array('Feature.name' => 'DeviceType.name'); $expected['foreignKey'] = false; $this->assertEqual($TestModel2->belongsTo['FeatureSet'], $expected); - $TestModel2->bind('NewFeatureSet', array('type' => 'hasMany', 'className' => 'FeatureSet', 'conditions' => array('active' => true))); - $expected = array('className' => 'FeatureSet', 'conditions' => array('active' => true), 'foreignKey' => 'device_type_id', 'fields' => '', 'order' => '', 'limit' => '', 'offset' => '', 'dependent' => '', 'exclusive' => '', 'finderQuery' => '', 'counterQuery' => ''); + $TestModel2->bind('NewFeatureSet', array( + 'type' => 'hasMany', + 'className' => 'FeatureSet', + 'conditions' => array('active' => true) + )); + $expected = array( + 'className' => 'FeatureSet', + 'conditions' => array('active' => true), + 'foreignKey' => 'device_type_id', + 'fields' => '', + 'order' => '', + 'limit' => '', + 'offset' => '', + 'dependent' => '', + 'exclusive' => '', + 'finderQuery' => '', + 'counterQuery' => '' + ); $this->assertEqual($TestModel2->hasMany['NewFeatureSet'], $expected); $this->assertTrue(is_object($TestModel2->NewFeatureSet)); } @@ -1795,35 +3439,158 @@ class ModelTest extends CakeTestCase { $expected = array(); $this->assertEqual($result, $expected); - $result = $TestModel->bindModel(array('hasMany' => array('Items' => array('className' => 'Comment')))); + $result = $TestModel->bindModel(array( + 'hasMany' => array( + 'Items' => array('className' => 'Comment') + ))); $this->assertTrue($result); - $result = $TestModel->find('all', array('fields' => 'User.id, User.user')); + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user' + )); $expected = array( - array('User' => array('id' => '1', 'user' => 'mariano'), 'Items' => array( - array('id' => '3', 'article_id' => '1', 'user_id' => '1', 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'), - array('id' => '4', 'article_id' => '1', 'user_id' => '1', 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'), - array('id' => '5', 'article_id' => '2', 'user_id' => '1', 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'))), - array('User' => array('id' => '2', 'user' => 'nate'), 'Items' => array( - array('id' => '1', 'article_id' => '1', 'user_id' => '2', 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'), - array('id' => '6', 'article_id' => '2', 'user_id' => '2', 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31'))), - array('User' => array('id' => '3', 'user' => 'larry'), 'Items' => array()), - array('User' => array('id' => '4', 'user' => 'garrett'), 'Items' => array( - array('id' => '2', 'article_id' => '1', 'user_id' => '4', 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31')))); + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Items' => array( + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ), + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Items' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ))), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Items' => array() + ), + array( + 'User' => array( + 'id' => '4', 'user' => 'garrett'), + 'Items' => array( + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + )))); $this->assertEqual($result, $expected); - $result = $TestModel->bindModel(array('hasMany' => array('Items' => array('className' => 'Article')))); + $result = $TestModel->bindModel(array( + 'hasMany' => array( + 'Items' => array('className' => 'Article') + ))); $this->assertTrue($result); - $result = $TestModel->find('all', array('fields' => 'User.id, User.user')); + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user' + )); $expected = array( - array('User' => array('id' => '1', 'user' => 'mariano'), 'Items' => array( - array('id' => 1, 'user_id' => 1, 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), - array('id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'))), - array('User' => array('id' => '2', 'user' => 'nate'), 'Items' => array()), - array('User' => array('id' => '3', 'user' => 'larry'), 'Items' => array( - array('id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'))), - array('User' => array('id' => '4', 'user' => 'garrett'), 'Items' => array())); + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Items' => array( + array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Items' => array() + ), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Items' => array( + array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ))), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett' + ), + 'Items' => array() + )); $this->assertEqual($result, $expected); } @@ -1837,9 +3604,11 @@ class ModelTest extends CakeTestCase { $Model =& ClassRegistry::init('StoriesTag'); $Model->bindModel(array( 'belongsTo' => array( - 'Tag' => array('className' => 'Tag', 'foreignKey' => 'story') - ) - )); + 'Tag' => array( + 'className' => 'Tag', + 'foreignKey' => 'story' + )))); + $result = $Model->find('all'); $this->assertFalse(empty($result)); } @@ -1925,11 +3694,24 @@ class ModelTest extends CakeTestCase { $TestModel =& new User(); $result = $TestModel->findByUser('mariano'); - $expected = array('User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31')); + $expected = array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + )); $this->assertEqual($result, $expected); $result = $TestModel->findByPassword('5f4dcc3b5aa765d61d8327deb882cf99'); - $expected = array('User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31')); + $expected = array('User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + )); $this->assertEqual($result, $expected); } /** @@ -1947,11 +3729,25 @@ class ModelTest extends CakeTestCase { $TestModel->id = 2; $result = $TestModel->read(); - $expected = array('User' => array('id' => '2', 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31')); + $expected = array( + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + )); $this->assertEqual($result, $expected); $result = $TestModel->read(null, 2); - $expected = array('User' => array('id' => '2', 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31')); + $expected = array( + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + )); $this->assertEqual($result, $expected); $TestModel->id = 2; @@ -1960,7 +3756,11 @@ class ModelTest extends CakeTestCase { $this->assertEqual($result, $expected); $result = $TestModel->read('id, user', 2); - $expected = array('User' => array('id' => '2', 'user' => 'nate')); + $expected = array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + )); $this->assertEqual($result, $expected); $result = $TestModel->bindModel(array('hasMany' => array('Article'))); @@ -1968,10 +3768,30 @@ class ModelTest extends CakeTestCase { $TestModel->id = 1; $result = $TestModel->read('id, user'); - $expected = array('User' => array('id' => '1', 'user' => 'mariano'), + $expected = array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), 'Article' => array( - array('id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), - array('id' => '3', 'user_id' => '1', 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ))); + array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + array( + 'id' => '3', + 'user_id' => '1', + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ))); $this->assertEqual($result, $expected); } /** @@ -1981,7 +3801,15 @@ class ModelTest extends CakeTestCase { * @return void */ function testRecursiveRead() { - $this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Featured', 'ArticleFeatured'); + $this->loadFixtures( + 'User', + 'Article', + 'Comment', + 'Tag', + 'ArticlesTag', + 'Featured', + 'ArticleFeatured' + ); $TestModel =& new User(); $result = $TestModel->bindModel(array('hasMany' => array('Article')), false); @@ -1996,85 +3824,297 @@ class ModelTest extends CakeTestCase { $TestModel->recursive = 1; $result = $TestModel->read('id, user', 1); - $expected = array('User' => array('id' => '1', 'user' => 'mariano'), + $expected = array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), 'Article' => array( - array('id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' ), - array('id' => '3', 'user_id' => '1', 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31' ))); + array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + array( + 'id' => '3', + 'user_id' => '1', + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ))); $this->assertEqual($result, $expected); $TestModel->recursive = 2; $result = $TestModel->read('id, user', 3); - $expected = array('User' => array('id' => '3', 'user' => 'larry'), - 'Article' => array(array('id' => '2', 'user_id' => '3', 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', - 'User' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'), - 'Comment' => array(array('id' => '5', 'article_id' => '2', 'user_id' => '1', 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'), - array('id' => '6', 'article_id' => '2', 'user_id' => '2', 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31')), + $expected = array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Article' => array( + array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31', + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), + 'Comment' => array( + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + )), 'Tag' => array( - array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), - array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31'))))); + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))))); $this->assertEqual($result, $expected); } -/** - * @todo Figure out why Featured is not getting truncated properly - */ + function testRecursiveFindAll() { $this->db->truncate(new Featured()); - $this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Attachment', 'ArticleFeatured', 'Featured', 'Category'); + $this->loadFixtures( + 'User', + 'Article', + 'Comment', + 'Tag', + 'ArticlesTag', + 'Attachment', + 'ArticleFeatured', + 'Featured', + 'Category' + ); $TestModel =& new Article(); $result = $TestModel->find('all', array('conditions' => array('Article.user_id' => 1))); $expected = array( array( - 'Article' => array('id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), - 'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'), + 'Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), 'Comment' => array( - array('id' => '1', 'article_id' => '1', 'user_id' => '2', 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'), - array('id' => '2', 'article_id' => '1', 'user_id' => '4', 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31'), - array('id' => '3', 'article_id' => '1', 'user_id' => '1', 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'), - array('id' => '4', 'article_id' => '1', 'user_id' => '1', 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31') + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + ), + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ) ), 'Tag' => array( - array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), - array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31') - ) - ), + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ))), array( - 'Article' => array('id' => '3', 'user_id' => '1', 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'), - 'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'), + 'Article' => array( + 'id' => '3', + 'user_id' => '1', + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), 'Comment' => array(), 'Tag' => array() ) ); $this->assertEqual($result, $expected); - $result = $TestModel->find('all', array('conditions' => array('Article.user_id' => 3), 'limit' => 1, 'recursive' => 2)); + $result = $TestModel->find('all', array( + 'conditions' => array('Article.user_id' => 3), + 'limit' => 1, + 'recursive' => 2 + )); + $expected = array( array( 'Article' => array( - 'id' => '2', 'user_id' => '3', 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31' + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' ), - 'User' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'), 'Comment' => array( array( - 'id' => '5', 'article_id' => '2', 'user_id' => '1', 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31', - 'Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), - 'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'), - 'Attachment' => array('id' => '1', 'comment_id' => 5, 'attachment' => 'attachment.zip', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31') + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31', + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Attachment' => array( + 'id' => '1', + 'comment_id' => 5, + 'attachment' => 'attachment.zip', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ) ), array( - 'id' => '6', 'article_id' => '2', 'user_id' => '2', 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31', - 'Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), - 'User' => array('id' => '2', 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'), + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31', + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + ), 'Attachment' => false ) ), 'Tag' => array( - array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), - array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31') - ) - ) - ); + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + )))); + $this->assertEqual($result, $expected); $Featured = new Featured(); @@ -2095,23 +4135,89 @@ class ModelTest extends CakeTestCase { ); $orderBy = 'ArticleFeatured.id ASC'; - $result = $Featured->find('all', array('order' => $orderBy, 'limit' => 3)); + $result = $Featured->find('all', array( + 'order' => $orderBy, 'limit' => 3 + )); $expected = array( - array('Featured' => array('id' => '1', 'article_featured_id' => '1', 'category_id' => '1', 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), - 'ArticleFeatured' => array('id' => '1', 'title' => 'First Article', 'user_id' => '1', 'published' => 'Y', - 'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'), + array( + 'Featured' => array( + 'id' => '1', + 'article_featured_id' => '1', + 'category_id' => '1', + 'published_date' => '2007-03-31 10:39:23', + 'end_date' => '2007-05-15 10:39:23', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'ArticleFeatured' => array( + 'id' => '1', + 'title' => 'First Article', + 'user_id' => '1', + 'published' => 'Y', + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), 'Category' => array(), - 'Featured' => array('id' => '1', 'article_featured_id' => '1', 'category_id' => '1', 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31')), - 'Category' => array('id' => '1', 'parent_id' => '0', 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31')), - array('Featured' => array('id' => '2', 'article_featured_id' => '2', 'category_id' => '1', 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), - 'ArticleFeatured' => array('id' => '2', 'title' => 'Second Article', 'user_id' => '3', 'published' => 'Y', - 'User' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'), + 'Featured' => array( + 'id' => '1', + 'article_featured_id' => '1', + 'category_id' => '1', + 'published_date' => '2007-03-31 10:39:23', + 'end_date' => '2007-05-15 10:39:23', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + )), + 'Category' => array( + 'id' => '1', + 'parent_id' => '0', + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + )), + array( + 'Featured' => array( + 'id' => '2', + 'article_featured_id' => '2', + 'category_id' => '1', + 'published_date' => '2007-03-31 10:39:23', + 'end_date' => '2007-05-15 10:39:23', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'ArticleFeatured' => array( + 'id' => '2', + 'title' => 'Second Article', + 'user_id' => '3', + 'published' => 'Y', + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), 'Category' => array(), - 'Featured' => array('id' => '2', 'article_featured_id' => '2', 'category_id' => '1', 'published_date' => '2007-03-31 10:39:23', 'end_date' => '2007-05-15 10:39:23', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31')), - 'Category' => array( 'id' => '1', 'parent_id' => '0', 'name' => 'Category 1', 'created' => '2007-03-18 15:30:23', 'updated' => '2007-03-18 15:32:31') - ) - ); + 'Featured' => array( + 'id' => '2', + 'article_featured_id' => '2', + 'category_id' => '1', + 'published_date' => '2007-03-31 10:39:23', + 'end_date' => '2007-05-15 10:39:23', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + )), + 'Category' => array( + 'id' => '1', + 'parent_id' => '0', + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ))); $this->assertEqual($result, $expected); } /** @@ -2126,23 +4232,77 @@ class ModelTest extends CakeTestCase { $TestModel->hasMany['Comment']['limit'] = 2; - $result = $TestModel->find('all', array('conditions' => array('Article.user_id' => 1))); + $result = $TestModel->find('all', array( + 'conditions' => array('Article.user_id' => 1) + )); $expected = array( array( - 'Article' => array('id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), - 'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'), + 'Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), 'Comment' => array( - array('id' => '1', 'article_id' => '1', 'user_id' => '2', 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'), - array('id' => '2', 'article_id' => '1', 'user_id' => '4', 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31'), + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + ), ), 'Tag' => array( - array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), - array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31') - ) - ), + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ))), array( - 'Article' => array('id' => '3', 'user_id' => '1', 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'), - 'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'), + 'Article' => array( + 'id' => '3', + 'user_id' => '1', + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), 'Comment' => array(), 'Tag' => array() ) @@ -2151,22 +4311,76 @@ class ModelTest extends CakeTestCase { $TestModel->hasMany['Comment']['limit'] = 1; - $result = $TestModel->find('all', array('conditions' => array('Article.user_id' => 3), 'limit' => 1, 'recursive' => 2)); + $result = $TestModel->find('all', array( + 'conditions' => array('Article.user_id' => 3), + 'limit' => 1, + 'recursive' => 2 + )); $expected = array( array( - 'Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), - 'User' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'), + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), 'Comment' => array( array( - 'id' => '5', 'article_id' => '2', 'user_id' => '1', 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31', - 'Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), - 'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'), - 'Attachment' => array('id' => '1', 'comment_id' => 5, 'attachment' => 'attachment.zip', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31') + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31', + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Attachment' => array( + 'id' => '1', + 'comment_id' => 5, + 'attachment' => 'attachment.zip', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ) ) ), 'Tag' => array( - array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), - array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31') + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ) ) ) ); @@ -2184,16 +4398,59 @@ class ModelTest extends CakeTestCase { $result = $TestModel->find('all'); $expected = array( array( - 'Post' => array('id' => '1', 'author_id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), - 'Author' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'test' => 'working'), - ), array( - 'Post' => array('id' => '2', 'author_id' => '3', 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), - 'Author' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31', 'test' => 'working'), - ), array( - 'Post' => array('id' => '3', 'author_id' => '1', 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'), - 'Author' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31', 'test' => 'working') - ) - ); + 'Post' => array( + 'id' => '1', + 'author_id' => '1', + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'Author' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31', + 'test' => 'working' + )), + array( + 'Post' => array( + 'id' => '2', + 'author_id' => '3', + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'Author' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31', + 'test' => 'working' + )), + array( + 'Post' => array( + 'id' => '3', + 'author_id' => '1', + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ), + 'Author' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31', + 'test' => 'working' + ))); $this->assertEqual($result, $expected); unset($TestModel); @@ -2262,31 +4519,51 @@ class ModelTest extends CakeTestCase { 'body' => VALID_NOT_EMPTY ); - $data = array('TestValidate' => array('user_id' => '1', 'title' => '', 'body' => '')); + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => '', + 'body' => '' + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); - $data = array('TestValidate' => array('user_id' => '1', 'title' => 'title', 'body' => '')); + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 'title', + 'body' => '' + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); - $data = array('TestValidate' => array('user_id' => '', 'title' => 'title', 'body' => 'body')); + $data = array('TestValidate' => array( + 'user_id' => '', + 'title' => 'title', + 'body' => 'body' + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); - $data = array('TestValidate' => array('user_id' => 'not a number', 'title' => 'title', 'body' => 'body')); + $data = array('TestValidate' => array( + 'user_id' => 'not a number', + 'title' => 'title', + 'body' => 'body' + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); - $data = array('TestValidate' => array('user_id' => '1', 'title' => 'title', 'body' => 'body')); + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 'title', + 'body' => 'body' + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); @@ -2307,23 +4584,39 @@ class ModelTest extends CakeTestCase { 'body' => 'notEmpty' ); - $data = array('TestValidate' => array('user_id' => '1', 'title' => '', 'body' => 'body')); + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => '', + 'body' => 'body' + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); - $data = array('TestValidate' => array('user_id' => '1', 'title' => 'title', 'body' => 'body')); + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 'title', + 'body' => 'body' + )); $result = $TestModel->create($data) && $TestModel->validates(); $this->assertTrue($result); - $data = array('TestValidate' => array('user_id' => '1', 'title' => '0', 'body' => 'body')); + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => '0', + 'body' => 'body' + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertTrue($result); - $data = array('TestValidate' => array('user_id' => '1', 'title' => 0, 'body' => 'body')); + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 0, + 'body' => 'body' + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); @@ -2331,31 +4624,56 @@ class ModelTest extends CakeTestCase { $TestModel->validate['modified'] = array('allowEmpty' => true, 'rule' => 'date'); - $data = array('TestValidate' => array('user_id' => '1', 'title' => 0, 'body' => 'body', 'modified' => '')); + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 0, + 'body' => 'body', + 'modified' => '' + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertTrue($result); - $data = array('TestValidate' => array('user_id' => '1', 'title' => 0, 'body' => 'body', 'modified' => '2007-05-01')); + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 0, + 'body' => 'body', + 'modified' => '2007-05-01' + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertTrue($result); - $data = array('TestValidate' => array('user_id' => '1', 'title' => 0, 'body' => 'body', 'modified' => 'invalid-date-here')); + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 0, + 'body' => 'body', + 'modified' => 'invalid-date-here' + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); - $data = array('TestValidate' => array('user_id' => '1', 'title' => 0, 'body' => 'body', 'modified' => 0)); + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 0, + 'body' => 'body', + 'modified' => 0 + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); - $data = array('TestValidate' => array('user_id' => '1', 'title' => 0, 'body' => 'body', 'modified' => '0')); + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 0, + 'body' => 'body', + 'modified' => '0' + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); @@ -2381,7 +4699,9 @@ class ModelTest extends CakeTestCase { $result = $TestModel->validates(); $this->assertFalse($result); - $data = array('TestValidate' => array('modified' => '2007-05-01')); + $data = array('TestValidate' => array( + 'modified' => '2007-05-01' + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); @@ -2389,73 +4709,120 @@ class ModelTest extends CakeTestCase { $TestModel->validate['slug'] = array('allowEmpty' => false, 'rule' => array('maxLength', 45)); - $data = array('TestValidate' => array('user_id' => '1', 'title' => 0, 'body' => 'body', 'slug' => '')); + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 0, + 'body' => 'body', + 'slug' => '' + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); - $data = array('TestValidate' => array('user_id' => '1', 'title' => 0, 'body' => 'body', 'slug' => 'slug-right-here')); + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 0, + 'body' => 'body', + 'slug' => 'slug-right-here' + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertTrue($result); - $data = array('TestValidate' => array('user_id' => '1', 'title' => 0, 'body' => 'body', 'slug' => 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz')); + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 0, + 'body' => 'body', + 'slug' => 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz' + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); $TestModel->validate = array( - 'number' => array('rule' => 'validateNumber', 'min' => 3, 'max' => 5), - 'title' => array('allowEmpty' => false, 'rule' => 'notEmpty') - ); + 'number' => array( + 'rule' => 'validateNumber', + 'min' => 3, + 'max' => 5 + ), + 'title' => array( + 'allowEmpty' => false, + 'rule' => 'notEmpty' + )); - $data = array('TestValidate' => array('title' => 'title', 'number' => '0')); + $data = array('TestValidate' => array( + 'title' => 'title', + 'number' => '0' + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); - $data = array('TestValidate' => array('title' => 'title', 'number' => 0)); + $data = array('TestValidate' => array( + 'title' => 'title', + 'number' => 0 + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); - $data = array('TestValidate' => array('title' => 'title', 'number' => '3')); + $data = array('TestValidate' => array( + 'title' => 'title', + 'number' => '3' + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertTrue($result); - $data = array('TestValidate' => array('title' => 'title', 'number' => 3)); + $data = array('TestValidate' => array( + 'title' => 'title', + 'number' => 3 + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertTrue($result); $TestModel->validate = array( - 'number' => array('rule' => 'validateNumber', 'min' => 5, 'max' => 10), - 'title' => array('allowEmpty' => false, 'rule' => 'notEmpty') - ); + 'number' => array( + 'rule' => 'validateNumber', + 'min' => 5, + 'max' => 10 + ), + 'title' => array( + 'allowEmpty' => false, + 'rule' => 'notEmpty' + )); - $data = array('TestValidate' => array('title' => 'title', 'number' => '3')); + $data = array('TestValidate' => array( + 'title' => 'title', + 'number' => '3' + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); - $data = array('TestValidate' => array('title' => 'title', 'number' => 3)); + $data = array('TestValidate' => array( + 'title' => 'title', + 'number' => 3 + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); $TestModel->validate = array( - 'title' => array('allowEmpty' => false, 'rule' => 'validateTitle') - ); + 'title' => array( + 'allowEmpty' => false, + 'rule' => 'validateTitle' + )); $data = array('TestValidate' => array('title' => '')); $result = $TestModel->create($data); @@ -2475,28 +4842,41 @@ class ModelTest extends CakeTestCase { $result = $TestModel->validates(); $this->assertTrue($result); - $TestModel->validate = array('title' => array('allowEmpty' => true, 'rule' => 'validateTitle')); + $TestModel->validate = array('title' => array( + 'allowEmpty' => true, + 'rule' => 'validateTitle' + )); $data = array('TestValidate' => array('title' => '')); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertTrue($result); - $TestModel->validate = array('title' => array('length' => array('allowEmpty' => true, 'rule' => array('maxLength', 10)))); + $TestModel->validate = array( + 'title' => array( + 'length' => array( + 'allowEmpty' => true, + 'rule' => array('maxLength', 10) + ))); $data = array('TestValidate' => array('title' => '')); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertTrue($result); - $TestModel->validate = array('title' => array('rule' => array('userDefined', 'Article', 'titleDuplicate'))); + $TestModel->validate = array( + 'title' => array( + 'rule' => array('userDefined', 'Article', 'titleDuplicate') + )); $data = array('TestValidate' => array('title' => 'My Article Title')); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); $this->assertFalse($result); - $data = array('TestValidate' => array('title' => 'My Article With a Different Title')); + $data = array('TestValidate' => array( + 'title' => 'My Article With a Different Title' + )); $result = $TestModel->create($data); $this->assertTrue($result); $result = $TestModel->validates(); @@ -2522,7 +4902,10 @@ class ModelTest extends CakeTestCase { $TestModel->validate = array( 'title' => array( - 'tooShort' => array('rule' => array('minLength', 50), 'last' => true), + 'tooShort' => array( + 'rule' => array('minLength', 50), + 'last' => true + ), 'onlyLetters' => array('rule' => '/^[a-z]+$/i') ), ); @@ -2555,7 +4938,10 @@ class ModelTest extends CakeTestCase { $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body'), 1); $expected = array('Article' => array( - 'id' => '1', 'user_id' => '1', 'title' => 'New First Article', 'body' => 'First Article Body' + 'id' => '1', + 'user_id' => '1', + 'title' => 'New First Article', + 'body' => 'First Article Body' )); $this->assertEqual($result, $expected); @@ -2566,7 +4952,10 @@ class ModelTest extends CakeTestCase { $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body'), 1); $expected = array('Article' => array( - 'id' => '1', 'user_id' => '1', 'title' => '', 'body' => 'First Article Body' + 'id' => '1', + 'user_id' => '1', + 'title' => '', + 'body' => 'First Article Body' )); $result['Article']['title'] = trim($result['Article']['title']); $this->assertEqual($result, $expected); @@ -2576,7 +4965,10 @@ class ModelTest extends CakeTestCase { $this->assertTrue($TestModel->saveField('title', 'First Article')); $result = $TestModel->read(array('id', 'user_id', 'title', 'body'), 1); $expected = array('Article' => array( - 'id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body' + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body' )); $this->assertEqual($result, $expected); @@ -2604,49 +4996,92 @@ class ModelTest extends CakeTestCase { * @return void */ function testSaveWithCreate() { - $this->loadFixtures('User', 'Article', 'User', 'Comment', 'Tag', 'ArticlesTag', 'Attachment'); + $this->loadFixtures( + 'User', + 'Article', + 'User', + 'Comment', + 'Tag', + 'ArticlesTag', + 'Attachment' + ); $TestModel =& new User(); - $data = array('User' => array('user' => 'user', 'password' => '')); + $data = array('User' => array( + 'user' => 'user', + 'password' => '' + )); $result = $TestModel->save($data); $this->assertFalse($result); $this->assertTrue(!empty($TestModel->validationErrors)); $TestModel =& new Article(); - $data = array('Article' => array('user_id' => '', 'title' => '', 'body' => '')); + $data = array('Article' => array( + 'user_id' => '', + 'title' => '', + 'body' => '' + )); $result = $TestModel->create($data) && $TestModel->save(); $this->assertFalse($result); $this->assertTrue(!empty($TestModel->validationErrors)); - $data = array('Article' => array('id' => 1, 'user_id' => '1', 'title' => 'New First Article', 'body' => '')); + $data = array('Article' => array( + 'id' => 1, + 'user_id' => '1', + 'title' => 'New First Article', + 'body' => '' + )); $result = $TestModel->create($data) && $TestModel->save(); $this->assertFalse($result); - $data = array('Article' => array('id' => 1, 'title' => 'New First Article')); + $data = array('Article' => array( + 'id' => 1, + 'title' => 'New First Article' + )); $result = $TestModel->create() && $TestModel->save($data, false); $this->assertTrue($result); $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 1); $expected = array('Article' => array( - 'id' => '1', 'user_id' => '1', 'title' => 'New First Article', 'body' => 'First Article Body', 'published' => 'N' + 'id' => '1', + 'user_id' => '1', + 'title' => 'New First Article', + 'body' => 'First Article Body', + 'published' => 'N' )); $this->assertEqual($result, $expected); - $data = array('Article' => array('id' => 1, 'user_id' => '2', 'title' => 'First Article', 'body' => 'New First Article Body', 'published' => 'Y')); + $data = array('Article' => array( + 'id' => 1, + 'user_id' => '2', + 'title' => 'First Article', + 'body' => 'New First Article Body', + 'published' => 'Y' + )); $result = $TestModel->create() && $TestModel->save($data, true, array('id', 'title', 'published')); $this->assertTrue($result); $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 1); $expected = array('Article' => array( - 'id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y' + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y' )); $this->assertEqual($result, $expected); $data = array( - 'Article' => array('user_id' => '2', 'title' => 'New Article', 'body' => 'New Article Body', 'created' => '2007-03-18 14:55:23', 'updated' => '2007-03-18 14:57:31'), + 'Article' => array( + 'user_id' => '2', + 'title' => 'New Article', + 'body' => 'New Article Body', + 'created' => '2007-03-18 14:55:23', + 'updated' => '2007-03-18 14:57:31' + ), 'Tag' => array('Tag' => array(1, 3)) ); $TestModel->create(); @@ -2656,42 +5091,123 @@ class ModelTest extends CakeTestCase { $TestModel->recursive = 2; $result = $TestModel->read(null, 4); $expected = array( - 'Article' => array('id' => '4', 'user_id' => '2', 'title' => 'New Article', 'body' => 'New Article Body', 'published' => 'N', 'created' => '2007-03-18 14:55:23', 'updated' => '2007-03-18 14:57:31'), - 'User' => array('id' => '2', 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'), + 'Article' => array( + 'id' => '4', + 'user_id' => '2', + 'title' => 'New Article', + 'body' => 'New Article Body', + 'published' => 'N', + 'created' => '2007-03-18 14:55:23', + 'updated' => '2007-03-18 14:57:31' + ), + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + ), 'Comment' => array(), 'Tag' => array( - array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), - array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31') - ) - ); + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))); $this->assertEqual($result, $expected); - $data = array('Comment' => array('article_id' => '4', 'user_id' => '1', 'comment' => 'Comment New Article', 'published' => 'Y', 'created' => '2007-03-18 14:57:23', 'updated' => '2007-03-18 14:59:31')); + $data = array('Comment' => array( + 'article_id' => '4', + 'user_id' => '1', + 'comment' => 'Comment New Article', + 'published' => 'Y', + 'created' => '2007-03-18 14:57:23', + 'updated' => '2007-03-18 14:59:31' + )); $result = $TestModel->Comment->create() && $TestModel->Comment->save($data); $this->assertTrue($result); - $data = array('Attachment' => array('comment_id' => '7', 'attachment' => 'newattachment.zip', 'created' => '2007-03-18 15:02:23', 'updated' => '2007-03-18 15:04:31')); + $data = array('Attachment' => array( + 'comment_id' => '7', + 'attachment' => 'newattachment.zip', + 'created' => '2007-03-18 15:02:23', + 'updated' => '2007-03-18 15:04:31' + )); $result = $TestModel->Comment->Attachment->save($data); $this->assertTrue($result); $TestModel->recursive = 2; $result = $TestModel->read(null, 4); $expected = array( - 'Article' => array('id' => '4', 'user_id' => '2', 'title' => 'New Article', 'body' => 'New Article Body', 'published' => 'N', 'created' => '2007-03-18 14:55:23', 'updated' => '2007-03-18 14:57:31'), - 'User' => array('id' => '2', 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'), + 'Article' => array( + 'id' => '4', + 'user_id' => '2', + 'title' => 'New Article', + 'body' => 'New Article Body', + 'published' => 'N', + 'created' => '2007-03-18 14:55:23', + 'updated' => '2007-03-18 14:57:31' + ), + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + ), 'Comment' => array( array( - 'id' => '7', 'article_id' => '4', 'user_id' => '1', 'comment' => 'Comment New Article', 'published' => 'Y', 'created' => '2007-03-18 14:57:23', 'updated' => '2007-03-18 14:59:31', - 'Article' => array('id' => '4', 'user_id' => '2', 'title' => 'New Article', 'body' => 'New Article Body', 'published' => 'N', 'created' => '2007-03-18 14:55:23', 'updated' => '2007-03-18 14:57:31'), - 'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'), - 'Attachment' => array('id' => '2', 'comment_id' => '7', 'attachment' => 'newattachment.zip', 'created' => '2007-03-18 15:02:23', 'updated' => '2007-03-18 15:04:31') - ) - ), + 'id' => '7', + 'article_id' => '4', + 'user_id' => '1', + 'comment' => 'Comment New Article', + 'published' => 'Y', + 'created' => '2007-03-18 14:57:23', + 'updated' => '2007-03-18 14:59:31', + 'Article' => array( + 'id' => '4', + 'user_id' => '2', + 'title' => 'New Article', + 'body' => 'New Article Body', + 'published' => 'N', + 'created' => '2007-03-18 14:55:23', + 'updated' => '2007-03-18 14:57:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Attachment' => array( + 'id' => '2', + 'comment_id' => '7', + 'attachment' => 'newattachment.zip', + 'created' => '2007-03-18 15:02:23', + 'updated' => '2007-03-18 15:04:31' + ))), 'Tag' => array( - array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), - array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31') - ) - ); + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))); + $this->assertEqual($result, $expected); } /** @@ -2706,7 +5222,12 @@ class ModelTest extends CakeTestCase { // Create record we will be updating later - $data = array('Article' => array('user_id' => '1', 'title' => 'Fourth Article', 'body' => 'Fourth Article Body', 'published' => 'Y')); + $data = array('Article' => array( + 'user_id' => '1', + 'title' => 'Fourth Article', + 'body' => 'Fourth Article Body', + 'published' => 'Y' + )); $result = $TestModel->create() && $TestModel->save($data); $this->assertTrue($result); @@ -2714,19 +5235,34 @@ class ModelTest extends CakeTestCase { $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 4); - $expected = array('Article' => array('id' => '4', 'user_id' => '1', 'title' => 'Fourth Article', 'body' => 'Fourth Article Body', 'published' => 'Y')); + $expected = array('Article' => array( + 'id' => '4', + 'user_id' => '1', + 'title' => 'Fourth Article', + 'body' => 'Fourth Article Body', + 'published' => 'Y' + )); $this->assertEqual($result, $expected); // Create new record just to overlap Model->id on previously created record - $data = array('Article' => array('user_id' => '4', 'title' => 'Fifth Article', 'body' => 'Fifth Article Body', 'published' => 'Y')); + $data = array('Article' => array( + 'user_id' => '4', + 'title' => 'Fifth Article', + 'body' => 'Fifth Article Body', + 'published' => 'Y' + )); $result = $TestModel->create() && $TestModel->save($data); $this->assertTrue($result); $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 5); $expected = array('Article' => array( - 'id' => '5', 'user_id' => '4', 'title' => 'Fifth Article', 'body' => 'Fifth Article Body', 'published' => 'Y' + 'id' => '5', + 'user_id' => '4', + 'title' => 'Fifth Article', + 'body' => 'Fifth Article Body', + 'published' => 'Y' )); $this->assertEqual($result, $expected); @@ -2734,24 +5270,44 @@ class ModelTest extends CakeTestCase { $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 4); - $expected = array('Article' => array('id' => '4', 'user_id' => '1', 'title' => 'Fourth Article', 'body' => 'Fourth Article Body', 'published' => 'Y')); + $expected = array('Article' => array( + 'id' => '4', + 'user_id' => '1', + 'title' => 'Fourth Article', + 'body' => 'Fourth Article Body', + 'published' => 'Y' + )); $this->assertEqual($result, $expected); // And now do the update with set() - $data = array('Article' => array('id' => '4', 'title' => 'Fourth Article - New Title', 'published' => 'N')); + $data = array('Article' => array( + 'id' => '4', + 'title' => 'Fourth Article - New Title', + 'published' => 'N' + )); $result = $TestModel->set($data) && $TestModel->save(); $this->assertTrue($result); $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 4); - $expected = array('Article' => array('id' => '4', 'user_id' => '1', 'title' => 'Fourth Article - New Title', 'body' => 'Fourth Article Body', 'published' => 'N')); + $expected = array('Article' => array( + 'id' => '4', + 'user_id' => '1', + 'title' => 'Fourth Article - New Title', + 'body' => 'Fourth Article Body', + 'published' => 'N' + )); $this->assertEqual($result, $expected); $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 5); $expected = array('Article' => array( - 'id' => '5', 'user_id' => '4', 'title' => 'Fifth Article', 'body' => 'Fifth Article Body', 'published' => 'Y' + 'id' => '5', + 'user_id' => '4', + 'title' => 'Fifth Article', + 'body' => 'Fifth Article Body', + 'published' => 'Y' )); $this->assertEqual($result, $expected); @@ -2761,7 +5317,13 @@ class ModelTest extends CakeTestCase { $TestModel->recursive = -1; $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 5); - $expected = array('Article' => array('id' => '5', 'user_id' => '4', 'title' => 'Fifth Article - New Title 5', 'body' => 'Fifth Article Body', 'published' => 'Y')); + $expected = array('Article' => array( + 'id' => '5', + 'user_id' => '4', + 'title' => 'Fifth Article - New Title 5', + 'body' => 'Fifth Article Body', + 'published' => 'Y' + )); $this->assertEqual($result, $expected); $TestModel->recursive = -1; @@ -2855,21 +5417,63 @@ class ModelTest extends CakeTestCase { $result = $TestModel->findById(2); $expected = array( - 'Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), - 'User' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'), - 'Comment' => array( - array('id' => '5', 'article_id' => '2', 'user_id' => '1', 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'), - array('id' => '6', 'article_id' => '2', 'user_id' => '2', 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31') + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' ), + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), + 'Comment' => array( + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + )), 'Tag' => array( - array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), - array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31') + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ) ) ); $this->assertEqual($result, $expected); $data = array( - 'Article' => array('id' => '2', 'title' => 'New Second Article'), + 'Article' => array( + 'id' => '2', + 'title' => 'New Second Article' + ), 'Tag' => array('Tag' => array(1, 2)) ); @@ -2879,12 +5483,25 @@ class ModelTest extends CakeTestCase { $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); $result = $TestModel->find(array('Article.id' => 2), array('id', 'user_id', 'title', 'body')); $expected = array( - 'Article' => array('id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body'), + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'New Second Article', + 'body' => 'Second Article Body' + ), 'Tag' => array( - array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), - array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31') - ) - ); + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ))); $this->assertEqual($result, $expected); $data = array('Article' => array('id' => '2'), 'Tag' => array('Tag' => array(2, 3))); @@ -2894,15 +5511,31 @@ class ModelTest extends CakeTestCase { $result = $TestModel->save(); $this->assertTrue($result); - $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); + $TestModel->unbindModel(array( + 'belongsTo' => array('User'), + 'hasMany' => array('Comment') + )); $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); $expected = array( - 'Article' => array('id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body'), + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'New Second Article', + 'body' => 'Second Article Body' + ), 'Tag' => array( - array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31'), - array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31') - ) - ); + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))); $this->assertEqual($result, $expected); $data = array('Tag' => array('Tag' => array(1, 2, 3))); @@ -2919,13 +5552,31 @@ class ModelTest extends CakeTestCase { )); $result = $TestModel->find(array('Article.id' => 2), array('id', 'user_id', 'title', 'body')); $expected = array( - 'Article' => array('id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body'), + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'New Second Article', + 'body' => 'Second Article Body' + ), 'Tag' => array( - array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), - array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31'), - array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31') - ) - ); + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))); $this->assertEqual($result, $expected); $data = array('Tag' => array('Tag' => array())); @@ -2948,7 +5599,12 @@ class ModelTest extends CakeTestCase { )); $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); $expected = array( - 'Article' => array('id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body'), + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'New Second Article', + 'body' => 'Second Article Body' + ), 'Tag' => array() ); $this->assertEqual($result, $expected); @@ -2967,16 +5623,34 @@ class ModelTest extends CakeTestCase { $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); $expected = array( 'Article' => array( - 'id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body' + 'id' => '2', + 'user_id' => '3', + 'title' => 'New Second Article', + 'body' => 'Second Article Body' ), 'Tag' => array( - array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31'), - array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31') - ) - ); + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))); $this->assertEqual($result, $expected); - $data = array('Tag' => array('Tag' => array(1, 2)), 'Article' => array('id' => '2', 'title' => 'New Second Article')); + $data = array( + 'Tag' => array( + 'Tag' => array(1, 2) + ), + 'Article' => array( + 'id' => '2', + 'title' => 'New Second Article' + )); $this->assertTrue($TestModel->set($data)); $this->assertTrue($TestModel->save()); @@ -2987,16 +5661,34 @@ class ModelTest extends CakeTestCase { $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); $expected = array( 'Article' => array( - 'id' => '2', 'user_id' => '3', 'title' => 'New Second Article', 'body' => 'Second Article Body' + 'id' => '2', + 'user_id' => '3', + 'title' => 'New Second Article', + 'body' => 'Second Article Body' ), 'Tag' => array( - array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), - array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31') - ) - ); + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ))); $this->assertEqual($result, $expected); - $data = array('Tag' => array('Tag' => array(1, 2)), 'Article' => array('id' => '2', 'title' => 'New Second Article Title')); + $data = array( + 'Tag' => array( + 'Tag' => array(1, 2) + ), + 'Article' => array( + 'id' => '2', + 'title' => 'New Second Article Title' + )); $result = $TestModel->set($data); $this->assertTrue($result); $this->assertTrue($TestModel->save()); @@ -3008,16 +5700,36 @@ class ModelTest extends CakeTestCase { $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); $expected = array( 'Article' => array( - 'id' => '2', 'user_id' => '3', 'title' => 'New Second Article Title', 'body' => 'Second Article Body' + 'id' => '2', + 'user_id' => '3', + 'title' => 'New Second Article Title', + 'body' => 'Second Article Body' ), 'Tag' => array( - array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), - array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31') + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ) ) ); $this->assertEqual($result, $expected); - $data = array('Tag' => array('Tag' => array(2, 3)), 'Article' => array('id' => '2', 'title' => 'Changed Second Article')); + $data = array( + 'Tag' => array( + 'Tag' => array(2, 3) + ), + 'Article' => array( + 'id' => '2', + 'title' => 'Changed Second Article' + )); $this->assertTrue($TestModel->set($data)); $this->assertTrue($TestModel->save()); @@ -3028,20 +5740,33 @@ class ModelTest extends CakeTestCase { $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); $expected = array( 'Article' => array( - 'id' => '2', 'user_id' => '3', 'title' => 'Changed Second Article', 'body' => 'Second Article Body' + 'id' => '2', + 'user_id' => '3', + 'title' => 'Changed Second Article', + 'body' => 'Second Article Body' ), 'Tag' => array( - array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31'), - array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31') + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ) ) ); $this->assertEqual($result, $expected); $data = array( 'Tag' => array( - 'Tag' => array( 1, 3 ) + 'Tag' => array(1, 3) ), - 'Article' => array('id' => '2' ), + 'Article' => array('id' => '2'), ); $result = $TestModel->set($data); @@ -3057,32 +5782,73 @@ class ModelTest extends CakeTestCase { $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); $expected = array( 'Article' => array( - 'id' => '2', 'user_id' => '3', 'title' => 'Changed Second Article', 'body' => 'Second Article Body' + 'id' => '2', + 'user_id' => '3', + 'title' => 'Changed Second Article', + 'body' => 'Second Article Body' ), 'Tag' => array( - array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), - array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31') - ) - ); + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))); $this->assertEqual($result, $expected); $data = array( - 'Article' => array('id' => 10, 'user_id' => '2', 'title' => 'New Article With Tags and fieldList', 'body' => 'New Article Body with Tags and fieldList', 'created' => '2007-03-18 14:55:23', 'updated' => '2007-03-18 14:57:31'), - 'Tag' => array('Tag' => array(1, 2, 3)) - ); - $result = $TestModel->create() && $TestModel->save($data, true, array('user_id', 'title', 'published')); + 'Article' => array( + 'id' => 10, + 'user_id' => '2', + 'title' => 'New Article With Tags and fieldList', + 'body' => 'New Article Body with Tags and fieldList', + 'created' => '2007-03-18 14:55:23', + 'updated' => '2007-03-18 14:57:31' + ), + 'Tag' => array( + 'Tag' => array(1, 2, 3) + )); + $result = $TestModel->create() + && $TestModel->save($data, true, array('user_id', 'title', 'published')); $this->assertTrue($result); $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); $result = $TestModel->read(); $expected = array( - 'Article' => array('id' => 4, 'user_id' => 2, 'title' => 'New Article With Tags and fieldList', 'body' => '', 'published' => 'N', 'created' => '', 'updated' => ''), + 'Article' => array( + 'id' => 4, + 'user_id' => 2, + 'title' => 'New Article With Tags and fieldList', + 'body' => '', + 'published' => 'N', + 'created' => '', + 'updated' => '' + ), 'Tag' => array( - 0 => array('id' => 1, 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), - 1 => array('id' => 2, 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31'), - 2 => array('id' => 3, 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31') - ) - ); + 0 => array( + 'id' => 1, + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + 1 => array( + 'id' => 2, + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ), + 2 => array( + 'id' => 3, + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))); $this->assertEqual($result, $expected); @@ -3120,7 +5886,11 @@ class ModelTest extends CakeTestCase { $this->loadFixtures('Story', 'StoriesTag', 'Tag'); $Story =& new Story(); - $data = array('Story' => array('story' => '1'), 'Tag' => array('Tag' => array(2, 3))); + $data = array( + 'Story' => array('story' => '1'), + 'Tag' => array( + 'Tag' => array(2, 3) + )); $result = $Story->set($data); $this->assertTrue($result); @@ -3130,17 +5900,30 @@ class ModelTest extends CakeTestCase { $result = $Story->find('all'); $expected = array( array( - 'Story' => array('story' => 1, 'title' => 'First Story'), + 'Story' => array( + 'story' => 1, + 'title' => 'First Story' + ), 'Tag' => array( - array('id' => 2, 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31'), - array('id' => 3, 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31') - ) - ), + array( + 'id' => 2, + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ), + array( + 'id' => 3, + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))), array( - 'Story' => array('story' => 2, 'title' => 'Second Story'), + 'Story' => array( + 'story' => 2, + 'title' => 'Second Story' + ), 'Tag' => array() - ) - ); + )); $this->assertEqual($result, $expected); } /** @@ -3158,9 +5941,18 @@ class ModelTest extends CakeTestCase { $result = $ThePaper->findById(1); $expected = array( - array('id' => '2', 'device_type_id' => '1', 'name' => 'Device 2', 'typ' => '1'), - array('id' => '3', 'device_type_id' => '1', 'name' => 'Device 3', 'typ' => '2') - ); + array( + 'id' => '2', + 'device_type_id' => '1', + 'name' => 'Device 2', + 'typ' => '1' + ), + array( + 'id' => '3', + 'device_type_id' => '1', + 'name' => 'Device 3', + 'typ' => '2' + )); $this->assertEqual($result['Monkey'], $expected); $ThePaper->id = 2; @@ -3168,10 +5960,24 @@ class ModelTest extends CakeTestCase { $result = $ThePaper->findById(2); $expected = array( - array('id' => '1', 'device_type_id' => '1', 'name' => 'Device 1', 'typ' => '1'), - array('id' => '2', 'device_type_id' => '1', 'name' => 'Device 2', 'typ' => '1'), - array('id' => '3', 'device_type_id' => '1', 'name' => 'Device 3', 'typ' => '2'), - ); + array( + 'id' => '1', + 'device_type_id' => '1', + 'name' => 'Device 1', + 'typ' => '1' + ), + array( + 'id' => '2', + 'device_type_id' => '1', + 'name' => 'Device 2', + 'typ' => '1' + ), + array( + 'id' => '3', + 'device_type_id' => '1', + 'name' => 'Device 3', + 'typ' => '2' + )); $this->assertEqual($result['Monkey'], $expected); $ThePaper->id = 2; @@ -3179,16 +5985,34 @@ class ModelTest extends CakeTestCase { $result = $ThePaper->findById(2); $expected = array( - array('id' => '1', 'device_type_id' => '1', 'name' => 'Device 1', 'typ' => '1'), - array('id' => '3', 'device_type_id' => '1', 'name' => 'Device 3', 'typ' => '2') - ); + array( + 'id' => '1', + 'device_type_id' => '1', + 'name' => 'Device 1', + 'typ' => '1' + ), + array( + 'id' => '3', + 'device_type_id' => '1', + 'name' => 'Device 3', + 'typ' => '2' + )); $this->assertEqual($result['Monkey'], $expected); $result = $ThePaper->findById(1); $expected = array( - array('id' => '2', 'device_type_id' => '1', 'name' => 'Device 2', 'typ' => '1'), - array('id' => '3', 'device_type_id' => '1', 'name' => 'Device 3', 'typ' => '2') - ); + array( + 'id' => '2', + 'device_type_id' => '1', + 'name' => 'Device 2', + 'typ' => '1' + ), + array( + 'id' => '3', + 'device_type_id' => '1', + 'name' => 'Device 3', + 'typ' => '2' + )); $this->assertEqual($result['Monkey'], $expected); } /** @@ -3206,9 +6030,18 @@ class ModelTest extends CakeTestCase { $result = $ThePaper->findById(1); $expected = array( - array('id' => '2', 'device_type_id' => '1', 'name' => 'Device 2', 'typ' => '1'), - array('id' => '3', 'device_type_id' => '1', 'name' => 'Device 3', 'typ' => '2') - ); + array( + 'id' => '2', + 'device_type_id' => '1', + 'name' => 'Device 2', + 'typ' => '1' + ), + array( + 'id' => '3', + 'device_type_id' => '1', + 'name' => 'Device 3', + 'typ' => '2' + )); $this->assertEqual($result['Monkey'], $expected); $ThePaper =& new ThePaper(); @@ -3217,17 +6050,35 @@ class ModelTest extends CakeTestCase { $result = $ThePaper->findById(2); $expected = array( - array('id' => '2', 'device_type_id' => '1', 'name' => 'Device 2', 'typ' => '1'), - array('id' => '3', 'device_type_id' => '1', 'name' => 'Device 3', 'typ' => '2') - ); + array( + 'id' => '2', + 'device_type_id' => '1', + 'name' => 'Device 2', + 'typ' => '1' + ), + array( + 'id' => '3', + 'device_type_id' => '1', + 'name' => 'Device 3', + 'typ' => '2' + )); $this->assertEqual($result['Monkey'], $expected); $ThePaper->delete(1); $result = $ThePaper->findById(2); $expected = array( - array('id' => '2', 'device_type_id' => '1', 'name' => 'Device 2', 'typ' => '1'), - array('id' => '3', 'device_type_id' => '1', 'name' => 'Device 3', 'typ' => '2') - ); + array( + 'id' => '2', + 'device_type_id' => '1', + 'name' => 'Device 2', + 'typ' => '1' + ), + array( + 'id' => '3', + 'device_type_id' => '1', + 'name' => 'Device 3', + 'typ' => '2' + )); $this->assertEqual($result['Monkey'], $expected); } /** @@ -3283,15 +6134,34 @@ class ModelTest extends CakeTestCase { $ts = date('Y-m-d H:i:s'); $TestModel->saveAll(array( - 'Post' => array('title' => 'Post with Author', 'body' => 'This post will be saved with an author'), - 'Author' => array('user' => 'bob', 'password' => '5f4dcc3b5aa765d61d8327deb882cf90') - )); + 'Post' => array( + 'title' => 'Post with Author', + 'body' => 'This post will be saved with an author' + ), + 'Author' => array( + 'user' => 'bob', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf90' + ))); $result = $TestModel->find('all'); $expected = array( - 'Post' => array('id' => '4', 'author_id' => '5', 'title' => 'Post with Author', 'body' => 'This post will be saved with an author', 'published' => 'N', 'created' => $ts, 'updated' => $ts), - 'Author' => array('id' => '5', 'user' => 'bob', 'password' => '5f4dcc3b5aa765d61d8327deb882cf90', 'created' => $ts, 'updated' => $ts, 'test' => 'working') - ); + 'Post' => array( + 'id' => '4', + 'author_id' => '5', + 'title' => 'Post with Author', + 'body' => 'This post will be saved with an author', + 'published' => 'N', + 'created' => $ts, + 'updated' => $ts + ), + 'Author' => array( + 'id' => '5', + 'user' => 'bob', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf90', + 'created' => $ts, + 'updated' => $ts, + 'test' => 'working' + )); $this->assertEqual($result[3], $expected); $this->assertEqual(count($result), 4); @@ -3303,33 +6173,88 @@ class ModelTest extends CakeTestCase { $ts = date('Y-m-d H:i:s'); $TestModel->saveAll(array( - array('title' => 'Multi-record post 1', 'body' => 'First multi-record post', 'author_id' => 2), - array('title' => 'Multi-record post 2', 'body' => 'Second multi-record post', 'author_id' => 2) - )); + array( + 'title' => 'Multi-record post 1', + 'body' => 'First multi-record post', + 'author_id' => 2 + ), + array( + 'title' => 'Multi-record post 2', + 'body' => 'Second multi-record post', + 'author_id' => 2 + ))); - $result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC')); + $result = $TestModel->find('all', array( + 'recursive' => -1, + 'order' => 'Post.id ASC' + )); $expected = array( - array('Post' => array('id' => '1', 'author_id' => '2', 'title' => 'Multi-record post 1', 'body' => 'First multi-record post', 'published' => 'N', 'created' => $ts, 'updated' => $ts)), - array('Post' => array('id' => '2', 'author_id' => '2', 'title' => 'Multi-record post 2', 'body' => 'Second multi-record post', 'published' => 'N', 'created' => $ts, 'updated' => $ts)) - ); + array( + 'Post' => array( + 'id' => '1', + 'author_id' => '2', + 'title' => 'Multi-record post 1', + 'body' => 'First multi-record post', + 'published' => 'N', + 'created' => $ts, + 'updated' => $ts + )), + array( + 'Post' => array( + 'id' => '2', + 'author_id' => '2', + 'title' => 'Multi-record post 2', + 'body' => 'Second multi-record post', + 'published' => 'N', + 'created' => $ts, + 'updated' => $ts + ))); $this->assertEqual($result, $expected); $TestModel =& new Comment(); $ts = date('Y-m-d H:i:s'); $result = $TestModel->saveAll(array( - 'Comment' => array('article_id' => 2, 'user_id' => 2, 'comment' => 'New comment with attachment', 'published' => 'Y'), - 'Attachment' => array('attachment' => 'some_file.tgz') - )); + 'Comment' => array( + 'article_id' => 2, + 'user_id' => 2, + 'comment' => 'New comment with attachment', + 'published' => 'Y' + ), + 'Attachment' => array( + 'attachment' => 'some_file.tgz' + ))); $this->assertTrue($result); $result = $TestModel->find('all'); - $expected = array('id' => '7', 'article_id' => '2', 'user_id' => '2', 'comment' => 'New comment with attachment', 'published' => 'Y', 'created' => $ts, 'updated' => $ts); + $expected = array( + 'id' => '7', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'New comment with attachment', + 'published' => 'Y', + 'created' => $ts, + 'updated' => $ts + ); $this->assertEqual($result[6]['Comment'], $expected); - $expected = array('id' => '7', 'article_id' => '2', 'user_id' => '2', 'comment' => 'New comment with attachment', 'published' => 'Y', 'created' => $ts, 'updated' => $ts); + $expected = array( + 'id' => '7', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'New comment with attachment', + 'published' => 'Y', + 'created' => $ts, + 'updated' => $ts + ); $this->assertEqual($result[6]['Comment'], $expected); - $expected = array('id' => '2', 'comment_id' => '7', 'attachment' => 'some_file.tgz', 'created' => $ts, 'updated' => $ts); + $expected = array( + 'id' => '2', + 'comment_id' => '7', + 'attachment' => 'some_file.tgz', + 'created' => $ts, + 'updated' => $ts + ); $this->assertEqual($result[6]['Attachment'], $expected); } /** @@ -3342,17 +6267,17 @@ class ModelTest extends CakeTestCase { $this->loadFixtures('Article', 'Tag', 'Comment', 'User'); $data = array( 'Article' => array( - 'user_id' => 1, 'title' => 'Article Has and belongs to Many Tags' + 'user_id' => 1, + 'title' => 'Article Has and belongs to Many Tags' ), 'Tag' => array( - 'Tag' => array( - 1, 2 - ) + 'Tag' => array(1, 2) ), 'Comment' => array( - array('comment' => 'Article comment', 'user_id' => 1), - ), - ); + array( + 'comment' => 'Article comment', + 'user_id' => 1 + ))); $Article =& new Article(); $result = $Article->saveAll($data); $this->assertTrue($result); @@ -3406,7 +6331,6 @@ class ModelTest extends CakeTestCase { $this->assertTrue(Set::matches('/SomethingElse[id=3]/JoinThing[something_else_id=3]', $result)); $this->assertTrue(Set::matches('/SomethingElse[id=3]/JoinThing[doomed=1]', $result)); } - /** * testSaveAllHasOne method * @@ -3422,16 +6346,28 @@ class ModelTest extends CakeTestCase { $this->assertEqual($model->Attachment->find('all'), array()); $this->assertTrue($model->saveAll(array( - 'Comment' => array('comment' => 'Comment with attachment', 'article_id' => 1, 'user_id' => 1), - 'Attachment' => array('attachment' => 'some_file.zip') - ))); + 'Comment' => array( + 'comment' => 'Comment with attachment', + 'article_id' => 1, + 'user_id' => 1 + ), + 'Attachment' => array( + 'attachment' => 'some_file.zip' + )))); $result = $model->find('all', array('fields' => array( - 'Comment.id', 'Comment.comment', 'Attachment.id', 'Attachment.comment_id', 'Attachment.attachment' + 'Comment.id', 'Comment.comment', 'Attachment.id', + 'Attachment.comment_id', 'Attachment.attachment' ))); $expected = array(array( - 'Comment' => array('id' => '1', 'comment' => 'Comment with attachment'), - 'Attachment' => array('id' => '1', 'comment_id' => '1', 'attachment' => 'some_file.zip') - )); + 'Comment' => array( + 'id' => '1', + 'comment' => 'Comment with attachment' + ), + 'Attachment' => array( + 'id' => '1', + 'comment_id' => '1', + 'attachment' => 'some_file.zip' + ))); $this->assertEqual($result, $expected); } /** @@ -3449,16 +6385,28 @@ class ModelTest extends CakeTestCase { $this->assertEqual($model->Article->find('all'), array()); $this->assertTrue($model->saveAll(array( - 'Comment' => array('comment' => 'Article comment', 'article_id' => 1, 'user_id' => 1), - 'Article' => array('title' => 'Model Associations 101', 'user_id' => 1) - ))); + 'Comment' => array( + 'comment' => 'Article comment', + 'article_id' => 1, + 'user_id' => 1 + ), + 'Article' => array( + 'title' => 'Model Associations 101', + 'user_id' => 1 + )))); $result = $model->find('all', array('fields' => array( 'Comment.id', 'Comment.comment', 'Comment.article_id', 'Article.id', 'Article.title' ))); $expected = array(array( - 'Comment' => array('id' => '1', 'article_id' => '1', 'comment' => 'Article comment'), - 'Article' => array('id' => '1', 'title' => 'Model Associations 101') - )); + 'Comment' => array( + 'id' => '1', + 'article_id' => '1', + 'comment' => 'Article comment' + ), + 'Article' => array( + 'id' => '1', + 'title' => 'Model Associations 101' + ))); $this->assertEqual($result, $expected); } /** @@ -3481,7 +6429,11 @@ class ModelTest extends CakeTestCase { $this->assertFalse($model->saveAll( array( - 'Comment' => array('comment' => '', 'article_id' => 1, 'user_id' => 1), + 'Comment' => array( + 'comment' => '', + 'article_id' => 1, + 'user_id' => 1 + ), 'Attachment' => array('attachment' => '') ), array('validate' => 'first') @@ -3514,31 +6466,65 @@ class ModelTest extends CakeTestCase { $TestModel =& new Article(); $result = $TestModel->saveAll(array( - 'Article' => array('title' => 'Post with Author', 'body' => 'This post will be saved with an author', 'user_id' => 2), - 'Comment' => array(array('comment' => 'First new comment', 'user_id' => 2)) + 'Article' => array( + 'title' => 'Post with Author', + 'body' => 'This post will be saved with an author', + 'user_id' => 2 + ), + 'Comment' => array( + array('comment' => 'First new comment', 'user_id' => 2)) ), array('atomic' => false)); + $this->assertIdentical($result, array('Article' => true, 'Comment' => array(true))); $result = $TestModel->saveAll(array( - array('id' => '1', 'title' => 'Baleeted First Post', 'body' => 'Baleeted!', 'published' => 'N'), - array('id' => '2', 'title' => 'Just update the title'), - array('title' => 'Creating a fourth post', 'body' => 'Fourth post body', 'user_id' => 2) + array( + 'id' => '1', + 'title' => 'Baleeted First Post', + 'body' => 'Baleeted!', + 'published' => 'N' + ), + array( + 'id' => '2', + 'title' => 'Just update the title' + ), + array( + 'title' => 'Creating a fourth post', + 'body' => 'Fourth post body', + 'user_id' => 2 + ) ), array('atomic' => false)); $this->assertIdentical($result, array(true, true, true)); $TestModel->validate = array('title' => 'notEmpty', 'author_id' => 'numeric'); $result = $TestModel->saveAll(array( - array('id' => '1', 'title' => 'Un-Baleeted First Post', 'body' => 'Not Baleeted!', 'published' => 'Y'), - array('id' => '2', 'title' => '', 'body' => 'Trying to get away with an empty title'), + array( + 'id' => '1', + 'title' => 'Un-Baleeted First Post', + 'body' => 'Not Baleeted!', + 'published' => 'Y' + ), + array( + 'id' => '2', + 'title' => '', + 'body' => 'Trying to get away with an empty title' + ) ), array('atomic' => false)); $this->assertIdentical($result, array(true, false)); $result = $TestModel->saveAll(array( 'Article' => array('id' => 2), 'Comment' => array( - array('comment' => 'First new comment', 'published' => 'Y', 'user_id' => 1), - array('comment' => 'Second new comment', 'published' => 'Y', 'user_id' => 2) - ) + array( + 'comment' => 'First new comment', + 'published' => 'Y', + 'user_id' => 1 + ), + array( + 'comment' => 'Second new comment', + 'published' => 'Y', + 'user_id' => 2 + )) ), array('atomic' => false)); $this->assertIdentical($result, array('Article' => true, 'Comment' => array(true, true))); } @@ -3563,22 +6549,35 @@ class ModelTest extends CakeTestCase { $this->assertTrue($result); $result = $TestModel->findById(2); - $expected = array('First Comment for Second Article', 'Second Comment for Second Article', 'First new comment', 'Second new comment'); + $expected = array( + 'First Comment for Second Article', + 'Second Comment for Second Article', + 'First new comment', + 'Second new comment' + ); $this->assertEqual(Set::extract($result['Comment'], '{n}.comment'), $expected); $result = $TestModel->saveAll( array( 'Article' => array('id' => 2), 'Comment' => array( - array('comment' => 'Third new comment', 'published' => 'Y', 'user_id' => 1), - ) - ), + array( + 'comment' => 'Third new comment', + 'published' => 'Y', + 'user_id' => 1 + ))), array('atomic' => false) ); $this->assertTrue($result); $result = $TestModel->findById(2); - $expected = array('First Comment for Second Article', 'Second Comment for Second Article', 'First new comment', 'Second new comment', 'Third new comment'); + $expected = array( + 'First Comment for Second Article', + 'Second Comment for Second Article', + 'First new comment', + 'Second new comment', + 'Third new comment' + ); $this->assertEqual(Set::extract($result['Comment'], '{n}.comment'), $expected); $TestModel->beforeSaveReturn = false; @@ -3586,15 +6585,23 @@ class ModelTest extends CakeTestCase { array( 'Article' => array('id' => 2), 'Comment' => array( - array('comment' => 'Fourth new comment', 'published' => 'Y', 'user_id' => 1), - ) - ), + array( + 'comment' => 'Fourth new comment', + 'published' => 'Y', + 'user_id' => 1 + ))), array('atomic' => false) ); $this->assertEqual($result, array('Article' => false)); $result = $TestModel->findById(2); - $expected = array('First Comment for Second Article', 'Second Comment for Second Article', 'First new comment', 'Second new comment', 'Third new comment'); + $expected = array( + 'First Comment for Second Article', + 'Second Comment for Second Article', + 'First new comment', + 'Second new comment', + 'Third new comment' + ); $this->assertEqual(Set::extract($result['Comment'], '{n}.comment'), $expected); } /** @@ -3630,8 +6637,11 @@ class ModelTest extends CakeTestCase { $result = $TestModel->saveAll(array( 'Article' => array('id' => 2), 'Comment' => array( - array('comment' => '', 'published' => 'Y', 'user_id' => 1), - ) + array( + 'comment' => '', + 'published' => 'Y', + 'user_id' => 1 + )) ), array('validate' => 'only')); } /** @@ -3655,14 +6665,58 @@ class ModelTest extends CakeTestCase { $result = $TestModel->find('all', array('recursive' => -1)); $expected = array( - array('Post' => array('id' => '1', 'author_id' => 1, 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31')), - array('Post' => array('id' => '2', 'author_id' => 3, 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31')), - array('Post' => array('id' => '3', 'author_id' => 1, 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31')) - ); + array('Post' => array( + 'id' => '1', + 'author_id' => 1, + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + )), + array('Post' => array( + 'id' => '2', + 'author_id' => 3, + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + )), + array('Post' => array( + 'id' => '3', + 'author_id' => 1, + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ))); + if (count($result) != 3) { // Database doesn't support transactions - $expected[] = array('Post' => array('id' => '4', 'author_id' => 1, 'title' => 'New Fourth Post', 'body' => null, 'published' => 'N', 'created' => $ts, 'updated' => $ts)); - $expected[] = array('Post' => array('id' => '5', 'author_id' => 1, 'title' => 'New Fifth Post', 'body' => null, 'published' => 'N', 'created' => $ts, 'updated' => $ts)); + $expected[] = array( + 'Post' => array( + 'id' => '4', + 'author_id' => 1, + 'title' => 'New Fourth Post', + 'body' => null, + 'published' => 'N', + 'created' => $ts, + 'updated' => $ts + )); + + $expected[] = array( + 'Post' => array( + 'id' => '5', + 'author_id' => 1, + 'title' => 'New Fifth Post', + 'body' => null, + 'published' => 'N', + 'created' => $ts, + 'updated' => $ts + )); + $this->assertEqual($result, $expected); // Skip the rest of the transactional tests return; @@ -3680,14 +6734,57 @@ class ModelTest extends CakeTestCase { $result = $TestModel->find('all', array('recursive' => -1)); $expected = array( - array('Post' => array('id' => '1', 'author_id' => 1, 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31')), - array('Post' => array('id' => '2', 'author_id' => 3, 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31')), - array('Post' => array('id' => '3', 'author_id' => 1, 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31')) - ); + array('Post' => array( + 'id' => '1', + 'author_id' => 1, + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + )), + array('Post' => array( + 'id' => '2', + 'author_id' => 3, + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + )), + array('Post' => array( + 'id' => '3', + 'author_id' => 1, + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ))); + if (count($result) != 3) { // Database doesn't support transactions - $expected[] = array('Post' => array('id' => '4', 'author_id' => 1, 'title' => 'New Fourth Post', 'body' => 'Third Post Body', 'published' => 'N', 'created' => $ts, 'updated' => $ts)); - $expected[] = array('Post' => array('id' => '5', 'author_id' => 1, 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'N', 'created' => $ts, 'updated' => $ts)); + $expected[] = array( + 'Post' => array( + 'id' => '4', + 'author_id' => 1, + 'title' => 'New Fourth Post', + 'body' => 'Third Post Body', + 'published' => 'N', + 'created' => $ts, + 'updated' => $ts + )); + + $expected[] = array( + 'Post' => array( + 'id' => '5', + 'author_id' => 1, + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'N', + 'created' => $ts, + 'updated' => $ts + )); } $this->assertEqual($result, $expected); @@ -3699,15 +6796,48 @@ class ModelTest extends CakeTestCase { ); $this->assertTrue($TestModel->saveAll($data)); - $result = $TestModel->find('all', array('recursive' => -1, 'fields' => array('author_id', 'title','body','published'))); + $result = $TestModel->find('all', array( + 'recursive' => -1, + 'fields' => array('author_id', 'title','body','published') + )); + $expected = array( - array('Post' => array('author_id' => 1, 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y')), - array('Post' => array('author_id' => 3, 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y')), - array('Post' => array('author_id' => 1, 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y')), - array('Post' => array('author_id' => 1, 'title' => 'New Fourth Post', 'body' => '', 'published' => 'N')), - array('Post' => array('author_id' => 1, 'title' => 'New Fifth Post', 'body' => '', 'published' => 'N')), - array('Post' => array('author_id' => 1, 'title' => 'New Sixth Post', 'body' => '', 'published' => 'N')) - ); + array('Post' => array( + 'author_id' => 1, + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y' + )), + array('Post' => array( + 'author_id' => 3, + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y' + )), + array('Post' => array( + 'author_id' => 1, + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y' + )), + array('Post' => array( + 'author_id' => 1, + 'title' => 'New Fourth Post', + 'body' => '', + 'published' => 'N' + )), + array('Post' => array( + 'author_id' => 1, + 'title' => 'New Fifth Post', + 'body' => '', + 'published' => 'N' + )), + array('Post' => array( + 'author_id' => 1, + 'title' => 'New Sixth Post', + 'body' => '', + 'published' => 'N' + ))); $this->assertEqual($result, $expected); } @@ -3786,9 +6916,16 @@ class ModelTest extends CakeTestCase { $this->assertEqual($TestModel->validationErrors, $errors); $data = array( - array('title' => 'First new post', 'body' => 'Woohoo!', 'published' => 'Y'), - array('title' => 'Empty body', 'body' => '') - ); + array( + 'title' => 'First new post', + 'body' => 'Woohoo!', + 'published' => 'Y' + ), + array( + 'title' => 'Empty body', + 'body' => '' + )); + $TestModel->validate['body'] = 'notEmpty'; } /** @@ -3855,17 +6992,23 @@ class ModelTest extends CakeTestCase { $model->Comment->validate = array('comment' => 'notEmpty'); $result = $model->saveAll(array( - 'Article' => array('title' => 'Post with Author', 'body' => 'This post will be saved author'), + 'Article' => array( + 'title' => 'Post with Author', + 'body' => 'This post will be saved author' + ), 'Comment' => array( array('comment' => 'First new comment'), array('comment' => '') ) ), array('validate' => 'first')); + $this->assertFalse($result); $result = $model->find('all'); $this->assertEqual($result, array()); - $expected = array('Comment' => array(1 => array('comment' => 'This field cannot be left blank'))); + $expected = array('Comment' => array( + 1 => array('comment' => 'This field cannot be left blank') + )); $this->assertEqual($model->Comment->validationErrors, $expected['Comment']); @@ -3873,11 +7016,19 @@ class ModelTest extends CakeTestCase { $result = $model->saveAll( array( - 'Article' => array('title' => 'Post with Author', 'body' => 'This post will be saved with an author', 'user_id' => 2), - 'Comment' => array(array('comment' => 'Only new comment', 'user_id' => 2)) - ), + 'Article' => array( + 'title' => 'Post with Author', + 'body' => 'This post will be saved with an author', + 'user_id' => 2 + ), + 'Comment' => array( + array( + 'comment' => 'Only new comment', + 'user_id' => 2 + ))), array('validate' => 'first') ); + $this->assertIdentical($result, true); $result = $model->Comment->find('all'); @@ -3895,8 +7046,8 @@ class ModelTest extends CakeTestCase { ), 'Comment' => array( 'comment' => 'Only new comment', 'user_id' => 2 - ) - ); + )); + $result = $model->Comment->saveAll($data, array('validate' => 'first')); $this->assertTrue($result); @@ -3918,7 +7069,12 @@ class ModelTest extends CakeTestCase { $result = $TestModel->findById(1); $this->assertIdentical($result['Syfile']['item_count'], null); - $TestModel2->save(array('name' => 'Item 7', 'syfile_id' => 1, 'published' => false)); + $TestModel2->save(array( + 'name' => 'Item 7', + 'syfile_id' => 1, + 'published' => false + )); + $result = $TestModel->findById(1); $this->assertIdentical($result['Syfile']['item_count'], '2'); @@ -3945,11 +7101,15 @@ class ModelTest extends CakeTestCase { $this->loadFixtures('CounterCacheUser', 'CounterCachePost'); $User = new CounterCacheUser(); $Post = new CounterCachePost(); - $data = array('Post' => array('title' => 'New Post', 'user_id' => 66)); + $data = array('Post' => array( + 'title' => 'New Post', + 'user_id' => 66 + )); $Post->save($data); $user = $User->find('first', array( - 'conditions' => array('id' => 66),'recursive' => -1 + 'conditions' => array('id' => 66), + 'recursive' => -1 )); $result = $user[$User->alias]['post_count']; @@ -3969,7 +7129,8 @@ class ModelTest extends CakeTestCase { $Post->del(2); $user = $User->find('first', array( - 'conditions' => array('id' => 66),'recursive' => -1 + 'conditions' => array('id' => 66), + 'recursive' => -1 )); $result = $user[$User->alias]['post_count']; @@ -3988,7 +7149,8 @@ class ModelTest extends CakeTestCase { $Post = new CounterCachePost(); $data = $Post->find('first', array( - 'conditions' => array('id' => 1),'recursive' => -1 + 'conditions' => array('id' => 1), + 'recursive' => -1 )); $data[$Post->alias]['user_id'] = 301; $Post->save($data); @@ -4014,7 +7176,8 @@ class ModelTest extends CakeTestCase { $Post = new CounterCachePostNonstandardPrimaryKey(); $data = $Post->find('first', array( - 'conditions' => array('pid' => 1),'recursive' => -1 + 'conditions' => array('pid' => 1), + 'recursive' => -1 )); $data[$Post->alias]['uid'] = 301; $Post->save($data); @@ -4068,7 +7231,12 @@ class ModelTest extends CakeTestCase { $result = $TestModel->findById(1); $this->assertIdentical($result['Syfile']['item_count'], null); - $TestModel2->save(array('name' => 'Item 7', 'syfile_id' => 1, 'published'=> true)); + $TestModel2->save(array( + 'name' => 'Item 7', + 'syfile_id' => 1, + 'published'=> true + )); + $result = $TestModel->findById(1); $this->assertIdentical($result['Syfile']['item_count'], '1'); @@ -4077,7 +7245,12 @@ class ModelTest extends CakeTestCase { $result = $TestModel->findById(1); $this->assertIdentical($result['Syfile']['item_count'], '2'); - $TestModel2->save(array('id' => 1, 'syfile_id' => 1, 'published'=> false)); + $TestModel2->save(array( + 'id' => 1, + 'syfile_id' => 1, + 'published'=> false + )); + $result = $TestModel->findById(1); $this->assertIdentical($result['Syfile']['item_count'], '1'); } @@ -4098,11 +7271,18 @@ class ModelTest extends CakeTestCase { $this->assertFalse($result); $TestModel->recursive = -1; - $result = $TestModel->find('all', array('fields' => array('id', 'title'))); + $result = $TestModel->find('all', array( + 'fields' => array('id', 'title') + )); $expected = array( - array('Article' => array('id' => 1, 'title' => 'First Article' )), - array('Article' => array('id' => 3, 'title' => 'Third Article' )) - ); + array('Article' => array( + 'id' => 1, + 'title' => 'First Article' + )), + array('Article' => array( + 'id' => 3, + 'title' => 'Third Article' + ))); $this->assertEqual($result, $expected); $result = $TestModel->del(3); @@ -4112,10 +7292,15 @@ class ModelTest extends CakeTestCase { $this->assertFalse($result); $TestModel->recursive = -1; - $result = $TestModel->find('all', array('fields' => array('id', 'title'))); + $result = $TestModel->find('all', array( + 'fields' => array('id', 'title') + )); $expected = array( - array('Article' => array('id' => 1, 'title' => 'First Article' )) - ); + array('Article' => array( + 'id' => 1, + 'title' => 'First Article' + ))); + $this->assertEqual($result, $expected); @@ -4158,52 +7343,132 @@ class ModelTest extends CakeTestCase { $this->loadFixtures('Article'); $TestModel =& new Article(); - $data = array('Article' => array('user_id' => 2, 'id' => 4, 'title' => 'Fourth Article', 'published' => 'N')); + $data = array('Article' => array( + 'user_id' => 2, + 'id' => 4, + 'title' => 'Fourth Article', + 'published' => 'N' + )); $result = $TestModel->set($data) && $TestModel->save(); $this->assertTrue($result); - $data = array('Article' => array('user_id' => 2, 'id' => 5, 'title' => 'Fifth Article', 'published' => 'Y')); + $data = array('Article' => array( + 'user_id' => 2, + 'id' => 5, + 'title' => 'Fifth Article', + 'published' => 'Y' + )); $result = $TestModel->set($data) && $TestModel->save(); $this->assertTrue($result); - $data = array('Article' => array('user_id' => 1, 'id' => 6, 'title' => 'Sixth Article', 'published' => 'N')); + $data = array('Article' => array( + 'user_id' => 1, + 'id' => 6, + 'title' => 'Sixth Article', + 'published' => 'N' + )); $result = $TestModel->set($data) && $TestModel->save(); $this->assertTrue($result); $TestModel->recursive = -1; - $result = $TestModel->find('all', array('fields' => array('id', 'user_id', 'title', 'published'))); + $result = $TestModel->find('all', array( + 'fields' => array('id', 'user_id', 'title', 'published') + )); + $expected = array( - array('Article' => array('id' => 1, 'user_id' => 1, 'title' => 'First Article', 'published' => 'Y' )), - array('Article' => array('id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'published' => 'Y' )), - array('Article' => array('id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'published' => 'Y' )), - array('Article' => array('id' => 4, 'user_id' => 2, 'title' => 'Fourth Article', 'published' => 'N' )), - array('Article' => array('id' => 5, 'user_id' => 2, 'title' => 'Fifth Article', 'published' => 'Y' )), - array('Article' => array('id' => 6, 'user_id' => 1, 'title' => 'Sixth Article', 'published' => 'N' )) - ); + array('Article' => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'published' => 'Y' + )), + array('Article' => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'published' => 'Y' + )), + array('Article' => array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'published' => 'Y')), + array('Article' => array( + 'id' => 4, + 'user_id' => 2, + 'title' => 'Fourth Article', + 'published' => 'N' + )), + array('Article' => array( + 'id' => 5, + 'user_id' => 2, + 'title' => 'Fifth Article', + 'published' => 'Y' + )), + array('Article' => array( + 'id' => 6, + 'user_id' => 1, + 'title' => 'Sixth Article', + 'published' => 'N' + ))); + $this->assertEqual($result, $expected); $result = $TestModel->deleteAll(array('Article.published' => 'N')); $this->assertTrue($result); $TestModel->recursive = -1; - $result = $TestModel->find('all', array('fields' => array('id', 'user_id', 'title', 'published'))); + $result = $TestModel->find('all', array( + 'fields' => array('id', 'user_id', 'title', 'published') + )); $expected = array( - array('Article' => array('id' => 1, 'user_id' => 1, 'title' => 'First Article', 'published' => 'Y' )), - array('Article' => array('id' => 2, 'user_id' => 3, 'title' => 'Second Article', 'published' => 'Y' )), - array('Article' => array('id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'published' => 'Y' )), - array('Article' => array('id' => 5, 'user_id' => 2, 'title' => 'Fifth Article', 'published' => 'Y' )) - ); + array('Article' => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'published' => 'Y' + )), + array('Article' => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'published' => 'Y' + )), + array('Article' => array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'published' => 'Y' + )), + array('Article' => array( + 'id' => 5, + 'user_id' => 2, + 'title' => 'Fifth Article', + 'published' => 'Y' + ))); $this->assertEqual($result, $expected); - $result = $TestModel->deleteAll(array('Article.user_id' => array(2, 3)), true, true); + $data = array('Article.user_id' => array(2, 3)); + $result = $TestModel->deleteAll($data, true, true); $this->assertTrue($result); $TestModel->recursive = -1; - $result = $TestModel->find('all', array('fields' => array('id', 'user_id', 'title', 'published'))); + $result = $TestModel->find('all', array( + 'fields' => array('id', 'user_id', 'title', 'published') + )); $expected = array( - array('Article' => array('id' => 1, 'user_id' => 1, 'title' => 'First Article', 'published' => 'Y' )), - array('Article' => array('id' => 3, 'user_id' => 1, 'title' => 'Third Article', 'published' => 'Y' )) - ); + array('Article' => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'published' => 'Y' + )), + array('Article' => array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'published' => 'Y' + ))); $this->assertEqual($result, $expected); } /** @@ -4271,20 +7536,36 @@ class ModelTest extends CakeTestCase { $result = $TestModel->ArticlesTag->find('all'); $expected = array( - array('ArticlesTag' => array('article_id' => '1', 'tag_id' => '1')), - array('ArticlesTag' => array('article_id' => '1', 'tag_id' => '2')), - array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '1')), - array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '3')) - ); + array('ArticlesTag' => array( + 'article_id' => '1', + 'tag_id' => '1' + )), + array('ArticlesTag' => array( + 'article_id' => '1', + 'tag_id' => '2' + )), + array('ArticlesTag' => array( + 'article_id' => '2', + 'tag_id' => '1' + )), + array('ArticlesTag' => array( + 'article_id' => '2', + 'tag_id' => '3' + ))); $this->assertEqual($result, $expected); $TestModel->delete(1); $result = $TestModel->ArticlesTag->find('all'); $expected = array( - array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '1')), - array('ArticlesTag' => array('article_id' => '2', 'tag_id' => '3')) - ); + array('ArticlesTag' => array( + 'article_id' => '2', + 'tag_id' => '1' + )), + array('ArticlesTag' => array( + 'article_id' => '2', + 'tag_id' => '3' + ))); $this->assertEqual($result, $expected); } /** @@ -4378,7 +7659,10 @@ class ModelTest extends CakeTestCase { ); $this->assertEqual($result, $expected); - $result = $TestModel->find('threaded', array('conditions' => array('Category.name LIKE' => 'Category 1%'))); + $result = $TestModel->find('threaded', array( + 'conditions' => array('Category.name LIKE' => 'Category 1%') + )); + $expected = array( array( 'Category' => array( @@ -4428,7 +7712,10 @@ class ModelTest extends CakeTestCase { ); $this->assertEqual($result, $expected); - $result = $TestModel->find('threaded', array('fields' => 'id, parent_id, name')); + $result = $TestModel->find('threaded', array( + 'fields' => 'id, parent_id, name' + )); + $expected = array( array( 'Category' => array( @@ -4575,7 +7862,9 @@ class ModelTest extends CakeTestCase { ); $this->assertEqual($result, $expected); - $result = $TestModel->find('threaded', array('conditions' => array('Category.name LIKE' => 'Category 3%'))); + $result = $TestModel->find('threaded', array( + 'conditions' => array('Category.name LIKE' => 'Category 3%') + )); $expected = array( array( 'Category' => array( @@ -4601,7 +7890,9 @@ class ModelTest extends CakeTestCase { ); $this->assertEqual($result, $expected); - $result = $TestModel->find('threaded', array('conditions' => array('Category.name LIKE' => 'Category 1.1%'))); + $result = $TestModel->find('threaded', array( + 'conditions' => array('Category.name LIKE' => 'Category 1.1%') + )); $expected = array( array('Category' => array( @@ -4627,7 +7918,10 @@ class ModelTest extends CakeTestCase { 'children' => array())))); $this->assertEqual($result, $expected); - $result = $TestModel->find('threaded', array('fields' => 'id, parent_id, name', 'conditions' => array('Category.id !=' => 2))); + $result = $TestModel->find('threaded', array( + 'fields' => 'id, parent_id, name', + 'conditions' => array('Category.id !=' => 2) + )); $expected = array( array( 'Category' => array( @@ -4674,19 +7968,52 @@ class ModelTest extends CakeTestCase { ); $this->assertEqual($result, $expected); - $result = $TestModel->find('all', array('fields' => 'id, name, parent_id', 'conditions' => array('Category.id !=' => 1))); + $result = $TestModel->find('all', array( + 'fields' => 'id, name, parent_id', + 'conditions' => array('Category.id !=' => 1) + )); $expected = array ( - array ('Category' => array('id' => '2', 'name' => 'Category 1.1', 'parent_id' => '1' )), - array ('Category' => array('id' => '3', 'name' => 'Category 1.2', 'parent_id' => '1' )), - array ('Category' => array('id' => '4', 'name' => 'Category 2', 'parent_id' => '0' )), - array ('Category' => array('id' => '5', 'name' => 'Category 3', 'parent_id' => '0' )), - array ('Category' => array('id' => '6', 'name' => 'Category 3.1', 'parent_id' => '5' )), - array ('Category' => array('id' => '7', 'name' => 'Category 1.1.1', 'parent_id' => '2' )), - array ('Category' => array('id' => '8', 'name' => 'Category 1.1.2', 'parent_id' => '2' )), - ); + array ('Category' => array( + 'id' => '2', + 'name' => 'Category 1.1', + 'parent_id' => '1' + )), + array ('Category' => array( + 'id' => '3', + 'name' => 'Category 1.2', + 'parent_id' => '1' + )), + array ('Category' => array( + 'id' => '4', + 'name' => 'Category 2', + 'parent_id' => '0' + )), + array ('Category' => array( + 'id' => '5', + 'name' => 'Category 3', + 'parent_id' => '0' + )), + array ('Category' => array( + 'id' => '6', + 'name' => 'Category 3.1', + 'parent_id' => '5' + )), + array ('Category' => array( + 'id' => '7', + 'name' => 'Category 1.1.1', + 'parent_id' => '2' + )), + array ('Category' => array( + 'id' => '8', + 'name' => 'Category 1.1.2', + 'parent_id' => '2' + ))); $this->assertEqual($result, $expected); - $result = $TestModel->find('threaded', array('fields' => 'id, parent_id, name', 'conditions' => array('Category.id !=' => 1))); + $result = $TestModel->find('threaded', array( + 'fields' => 'id, parent_id, name', + 'conditions' => array('Category.id !=' => 1) + )); $expected = array( array( 'Category' => array( @@ -4729,17 +8056,38 @@ class ModelTest extends CakeTestCase { $TestModel->id = 1; $result = $TestModel->find('neighbors', array('fields' => array('id'))); - $expected = array('prev' => null, 'next' => array('Article' => array('id' => 2))); + $expected = array( + 'prev' => null, + 'next' => array( + 'Article' => array('id' => 2) + )); $this->assertEqual($result, $expected); $TestModel->id = 2; - $result = $TestModel->find('neighbors', array('fields' => array('id'))); - $expected = array('prev' => array('Article' => array('id' => 1)), 'next' => array('Article' => array('id' => 3))); + $result = $TestModel->find('neighbors', array( + 'fields' => array('id') + )); + + $expected = array( + 'prev' => array( + 'Article' => array( + 'id' => 1 + )), + 'next' => array( + 'Article' => array( + 'id' => 3 + ))); $this->assertEqual($result, $expected); $TestModel->id = 3; $result = $TestModel->find('neighbors', array('fields' => array('id'))); - $expected = array('prev' => array('Article' => array('id' => 2)), 'next' => null); + $expected = array( + 'prev' => array( + 'Article' => array( + 'id' => 2 + )), + 'next' => null + ); $this->assertEqual($result, $expected); $TestModel->id = 1; @@ -4863,18 +8211,43 @@ class ModelTest extends CakeTestCase { $TestModel =& new Article(); $result = $TestModel->findNeighbours(null, 'Article.id', '2'); - $expected = array('prev' => array('Article' => array('id' => 1)), 'next' => array('Article' => array('id' => 3))); + $expected = array( + 'prev' => array( + 'Article' => array( + 'id' => 1 + )), + 'next' => array( + 'Article' => array( + 'id' => 3 + ))); $this->assertEqual($result, $expected); $result = $TestModel->findNeighbours(null, 'Article.id', '3'); - $expected = array('prev' => array('Article' => array('id' => 2)), 'next' => array()); + $expected = array( + 'prev' => array( + 'Article' => array( + 'id' => 2 + )), + 'next' => array() + ); $this->assertEqual($result, $expected); - $result = $TestModel->findNeighbours(array('User.id' => 1), array('Article.id', 'Article.title'), 2); - $expected = array( - 'prev' => array('Article' => array('id' => 1, 'title' => 'First Article')), - 'next' => array('Article' => array('id' => 3, 'title' => 'Third Article')), + $result = $TestModel->findNeighbours( + array('User.id' => 1), + array('Article.id', 'Article.title'), + 2 ); + $expected = array( + 'prev' => array( + 'Article' => array( + 'id' => 1, + 'title' => 'First Article' + )), + 'next' => array( + 'Article' => array( + 'id' => 3, + 'title' => 'Third Article' + ))); $this->assertEqual($result, $expected); } /** @@ -4890,43 +8263,267 @@ class ModelTest extends CakeTestCase { $result = $TestModel->find('all'); $expected = array( - array('Apple' => array( - 'id' => '1', 'apple_id' => '2', 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - 'Parent' => array('id' => '2', 'apple_id' => '1', 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'), - 'Sample' => array('id' => null, 'apple_id' => null, 'name' => null), - 'Child' => array(array('id' => '2', 'apple_id' => '1', 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'))), - array('Apple' => array( - 'id' => '2', 'apple_id' => '1', 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'), - 'Parent' => array('id' => '1', 'apple_id' => '2', 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - 'Sample' => array('id' => '2', 'apple_id' => '2', 'name' => 'sample2' ), - 'Child' => array(array('id' => '1', 'apple_id' => '2', 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - array('id' => '3', 'apple_id' => '2', 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - array('id' => '4', 'apple_id' => '2', 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'))), - array('Apple' => array( - 'id' => '3', 'apple_id' => '2', 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - 'Parent' => array('id' => '2', 'apple_id' => '1', 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'), - 'Sample' => array('id' => '1', 'apple_id' => '3', 'name' => 'sample1'), - 'Child' => array()), - array('Apple' => array( - 'id' => '4', 'apple_id' => '2', 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'), - 'Parent' => array('id' => '2', 'apple_id' => '1', 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'), - 'Sample' => array('id' => '3', 'apple_id' => '4', 'name' => 'sample3'), - 'Child' => array(array('id' => '6', 'apple_id' => '4', 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17'))), - array('Apple' => array( - 'id' => '5', 'apple_id' => '5', 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'), - 'Parent' => array('id' => '5', 'apple_id' => '5', 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'), - 'Sample' => array('id' => '4', 'apple_id' => '5', 'name' => 'sample4'), - 'Child' => array(array('id' => '5', 'apple_id' => '5', 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'))), - array('Apple' => array( - 'id' => '6', 'apple_id' => '4', 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17'), - 'Parent' => array('id' => '4', 'apple_id' => '2', 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'), - 'Sample' => array('id' => null, 'apple_id' => null, 'name' => null), - 'Child' => array(array('id' => '7', 'apple_id' => '6', 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17'))), - array('Apple' => array( - 'id' => '7', 'apple_id' => '6', 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17'), - 'Parent' => array('id' => '6', 'apple_id' => '4', 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17'), - 'Sample' => array('id' => null, 'apple_id' => null, 'name' => null), - 'Child' => array())); + array( + 'Apple' => array( + 'id' => '1', + 'apple_id' => '2', + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '2', + 'apple_id' => '1', + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => null, + 'apple_id' => null, + 'name' => null + ), + 'Child' => array( + array( + 'id' => '2', + 'apple_id' => '1', + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => '2', + 'apple_id' => '1', + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '1', + 'apple_id' => '2', + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => '2', + 'apple_id' => '2', + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => '1', + 'apple_id' => '2', + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => '3', + 'apple_id' => '2', + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => '4', + 'apple_id' => '2', + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => '3', + 'apple_id' => '2', + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '2', + 'apple_id' => '1', + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => '1', + 'apple_id' => '3', + 'name' => 'sample1' + ), + 'Child' => array() + ), + array( + 'Apple' => array( + 'id' => '4', + 'apple_id' => '2', + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '2', + 'apple_id' => '1', + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => '3', + 'apple_id' => '4', + 'name' => 'sample3' + ), + 'Child' => array( + array( + 'id' => '6', + 'apple_id' => '4', + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => '5', + 'apple_id' => '5', + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '5', + 'apple_id' => '5', + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => '4', + 'apple_id' => '5', + 'name' => 'sample4' + ), + 'Child' => array( + array( + 'id' => '5', + 'apple_id' => '5', + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => '6', + 'apple_id' => '4', + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '4', + 'apple_id' => '2', + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => null, + 'apple_id' => null, + 'name' => null + ), + 'Child' => array( + array( + 'id' => '7', + 'apple_id' => '6', + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => '7', + 'apple_id' => '6', + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '6', + 'apple_id' => '4', + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => null, + 'apple_id' => null, + 'name' => null + ), + 'Child' => array() + )); $this->assertEqual($result, $expected); } /** @@ -5082,15 +8679,6 @@ class ModelTest extends CakeTestCase { ); $this->assertEqual($result, $expected); } -/** - * testMultipleValidation method - * - * @access public - * @return void - */ - function testMultipleValidation() { - $TestModel =& new ValidationTest1(); - } /** * Tests validation parameter order in custom validation methods * @@ -5099,23 +8687,37 @@ class ModelTest extends CakeTestCase { */ function testValidationParams() { $TestModel =& new ValidationTest1(); - $TestModel->validate['title'] = array('rule' => 'customValidatorWithParams', 'required' => true); + $TestModel->validate['title'] = array( + 'rule' => 'customValidatorWithParams', + 'required' => true + ); $TestModel->create(array('title' => 'foo')); $TestModel->invalidFields(); $expected = array( - 'data' => array('title' => 'foo'), + 'data' => array( + 'title' => 'foo' + ), 'validator' => array( - 'rule' => 'customValidatorWithParams', 'on' => null, - 'last' => false, 'allowEmpty' => false, 'required' => true + 'rule' => 'customValidatorWithParams', + 'on' => null, + 'last' => false, + 'allowEmpty' => false, + 'required' => true ), 'or' => true, 'ignore_on_same' => 'id' ); $this->assertEqual($TestModel->validatorParams, $expected); - $TestModel->validate['title'] = array('rule' => 'customValidatorWithMessage', 'required' => true); - $expected = array('title' => 'This field will *never* validate! Muhahaha!'); + $TestModel->validate['title'] = array( + 'rule' => 'customValidatorWithMessage', + 'required' => true + ); + $expected = array( + 'title' => 'This field will *never* validate! Muhahaha!' + ); + $this->assertEqual($TestModel->invalidFields(), $expected); } /** @@ -5127,21 +8729,33 @@ class ModelTest extends CakeTestCase { function testInvalidFieldsWithFieldListParams() { $TestModel =& new ValidationTest1(); $TestModel->validate = $validate = array( - 'title' => array('rule' => 'customValidator', 'required' => true), - 'name' => array('rule' => 'allowEmpty', 'required' => true), - ); + 'title' => array( + 'rule' => 'customValidator', + 'required' => true + ), + 'name' => array( + 'rule' => 'allowEmpty', + 'required' => true + )); $TestModel->invalidFields(array('fieldList' => array('title'))); - $expected = array('title' => 'This field cannot be left blank'); + $expected = array( + 'title' => 'This field cannot be left blank' + ); $this->assertEqual($TestModel->validationErrors, $expected); $TestModel->validationErrors = array(); $TestModel->invalidFields(array('fieldList' => array('name'))); - $expected = array('name' => 'This field cannot be left blank'); + $expected = array( + 'name' => 'This field cannot be left blank' + ); $this->assertEqual($TestModel->validationErrors, $expected); $TestModel->validationErrors = array(); $TestModel->invalidFields(array('fieldList' => array('name', 'title'))); - $expected = array('name' => 'This field cannot be left blank', 'title' => 'This field cannot be left blank'); + $expected = array( + 'name' => 'This field cannot be left blank', + 'title' => 'This field cannot be left blank' + ); $this->assertEqual($TestModel->validationErrors, $expected); $TestModel->validationErrors = array(); @@ -5162,8 +8776,15 @@ class ModelTest extends CakeTestCase { function testAllowSimulatedFields() { $TestModel =& new ValidationTest1(); - $TestModel->create(array('title' => 'foo', 'bar' => 'baz')); - $expected = array('ValidationTest1' => array('title' => 'foo', 'bar' => 'baz')); + $TestModel->create(array( + 'title' => 'foo', + 'bar' => 'baz' + )); + $expected = array( + 'ValidationTest1' => array( + 'title' => 'foo', + 'bar' => 'baz' + )); $this->assertEqual($TestModel->data, $expected); } /** @@ -5205,113 +8826,686 @@ class ModelTest extends CakeTestCase { $result = $TestModel->find('all'); $expected = array( - array('Apple' => array ( - 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', - 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'), - 'Child' => array( - array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'))), - 'Sample' => array('id' =>'', 'apple_id' => '', 'name' => ''), + array( + 'Apple' => array ( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), 'Child' => array( - array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', - 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'), - 'Child' => array( - array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'))))), - array('Apple' => array( - 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17', - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'), + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' =>'', + 'apple_id' => '', + 'name' => '' + ), + 'Child' => array( + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))))), + array( + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), 'Sample' => array(), 'Child' => array( - array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2', - 'Apple' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17')), + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2', + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + )), 'Child' => array( - array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17', - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'), + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), 'Sample' => array(), 'Child' => array( - array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'))), - array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17', - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'), - 'Sample' => array('id' => 1, 'apple_id' => 3, 'name' => 'sample1')), - - array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17', - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'), - 'Sample' => array('id' => 3, 'apple_id' => 4, 'name' => 'sample3'), + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 1, + 'apple_id' => 3, + 'name' => 'sample1' + )), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3' + ), 'Child' => array( - array('id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17'))))), - array('Apple' => array( - 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', - 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ))))), + array( + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 1, + 'apple_id' => 3, + 'name' => 'sample1', + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + )), + 'Child' => array() + ), + array( + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'), 'Child' => array( - array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => 1, 'apple_id' => 3, 'name' => 'sample1', - 'Apple' => array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17')), - 'Child' => array()), - array('Apple' => array( - 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', - 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'), - 'Child' => array( - array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => 3, 'apple_id' => 4, 'name' => 'sample3', - 'Apple' => array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17')), - 'Child' => array( - array('id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17', - 'Parent' => array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'), - 'Sample' => array(), - 'Child' => array( - array('id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17'))))), - array('Apple' => array( - 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17', - 'Parent' => array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'), - 'Sample' => array('id' => 4, 'apple_id' => 5, 'name' => 'sample4'), - 'Child' => array( - array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => 4, 'apple_id' => 5, 'name' => 'sample4', - 'Apple' => array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17')), - 'Child' => array( - array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17', - 'Parent' => array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'), - 'Sample' => array('id' => 4, 'apple_id' => 5, 'name' => 'sample4'), - 'Child' => array( - array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'))))), - array('Apple' => array( - 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17', - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'), - 'Sample' => array('id' => 3, 'apple_id' => 4, 'name' => 'sample3'), - 'Child' => array( - array('id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => '', 'apple_id' => '', 'name' => ''), - 'Child' => array( - array('id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17', - 'Parent' => array('id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17'), - 'Sample' => array()))), - array('Apple' => array( - 'id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17', - 'Parent' => array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'), + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3', + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + )), + 'Child' => array( + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), 'Sample' => array(), 'Child' => array( - array('id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => '', 'apple_id' => '', 'name' => ''), - 'Child' => array())); + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))))), + array( + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4' + ), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4', + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + )), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4' + ), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))))), + array( + 'Apple' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3' + ), + 'Child' => array( + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ), + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Sample' => array() + ))), + array( + 'Apple' => array( + 'id' => 7, + 'apple_id' => 6, + 'color' => + 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ), + 'Child' => array())); $this->assertEqual($result, $expected); $result = $TestModel->Parent->unbindModel(array('hasOne' => array('Sample'))); @@ -5319,106 +9513,665 @@ class ModelTest extends CakeTestCase { $result = $TestModel->find('all'); $expected = array( - array('Apple' => array( - 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', - 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), + array( + 'Apple' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17'), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), 'Child' => array( - array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'))), - 'Sample' => array('id' =>'', 'apple_id' => '', 'name' => ''), + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' =>'', + 'apple_id' => '', + 'name' => '' + ), 'Child' => array( - array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', - 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'), - 'Child' => array( - array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'))))), - array('Apple' => array( - 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17', - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'), - 'Child' => array( - array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2', - 'Apple' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17')), - 'Child' => array( - array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17', - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'), - 'Sample' => array(), + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), 'Child' => array( - array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'))), - array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17', - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'), - 'Sample' => array('id' => 1, 'apple_id' => 3, 'name' => 'sample1')), + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))))), + array( + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2', + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + )), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', 'modified' => + '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 1, + 'apple_id' => 3, + 'name' => 'sample1' + )), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3' + ), + 'Child' => array( + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ))))), + array( + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 1, + 'apple_id' => 3, + 'name' => 'sample1', + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + )), + 'Child' => array() + ), + array( + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3', + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + )), + 'Child' => array( + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))))), + array( + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4', + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + )), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4' + ), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))))), + array( + 'Apple' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ), + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Sample' => array() + ))), + array( + 'Apple' => array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ), + 'Child' => array() + )); - array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17', - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'), - 'Sample' => array('id' => 3, 'apple_id' => 4, 'name' => 'sample3'), - 'Child' => array( - array('id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17'))))), - array('Apple' => array( - 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', - 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - 'Child' => array( - array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => 1, 'apple_id' => 3, 'name' => 'sample1', - 'Apple' => array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17')), - 'Child' => array()), - array('Apple' => array( - 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', - 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - 'Child' => array( - array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => 3, 'apple_id' => 4, 'name' => 'sample3', - 'Apple' => array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17')), - 'Child' => array( - array('id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17', - 'Parent' => array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'), - 'Sample' => array(), - 'Child' => array( - array('id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17'))))), - array('Apple' => array( - 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17', - 'Parent' => array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'), - 'Child' => array( - array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => 4, 'apple_id' => 5, 'name' => 'sample4', - 'Apple' => array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17')), - 'Child' => array( - array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17', - 'Parent' => array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'), - 'Sample' => array('id' => 4, 'apple_id' => 5, 'name' => 'sample4'), - 'Child' => array( - array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'))))), - array('Apple' => array( - 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17', - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'), - 'Child' => array( - array('id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => '', 'apple_id' => '', 'name' => ''), - 'Child' => array( - array('id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17', - 'Parent' => array('id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17'), - 'Sample' => array()))), - array('Apple' => array( - 'id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17', - 'Parent' => array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'), - 'Child' => array( - array('id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => '', 'apple_id' => '', 'name' => ''), - 'Child' => array())); $this->assertEqual($result, $expected); $result = $TestModel->Parent->unbindModel(array('hasOne' => array('Sample'))); @@ -5428,65 +10181,426 @@ class ModelTest extends CakeTestCase { $this->assertTrue($result); $result = $TestModel->find('all'); - $expected = array(array('Apple' => array ( - 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', - 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - 'Child' => array( - array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'))), - 'Sample' => array('id' =>'', 'apple_id' => '', 'name' => '')), - array('Apple' => array( - 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17', - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'), - 'Child' => array( - array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2', - 'Apple' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'))), - array('Apple' => array( - 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', - 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - 'Child' => array( - array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => 1, 'apple_id' => 3, 'name' => 'sample1', - 'Apple' => array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'))), - array('Apple' => array( - 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', - 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - 'Child' => array( - array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => 3, 'apple_id' => 4, 'name' => 'sample3', - 'Apple' => array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'))), - array('Apple' => array( - 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17', - 'Parent' => array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'), - 'Child' => array( - array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => 4, 'apple_id' => 5, 'name' => 'sample4', - 'Apple' => array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'))), - array('Apple' => array( - 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17', - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'), - 'Child' => array( - array('id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => '', 'apple_id' => '', 'name' => '')), - array('Apple' => array( - 'id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17', - 'Parent' => array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'), - 'Child' => array( - array('id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => '', 'apple_id' => '', 'name' => ''))); + $expected = array( + array( + 'Apple' => array ( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' =>'', + 'apple_id' => '', + 'name' => '' + )), + array( + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2', + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 1, + 'apple_id' => 3, + 'name' => 'sample1', + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3', + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4', + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + )), + array( + 'Apple' => array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ))); + $this->assertEqual($result, $expected); $result = $TestModel->unbindModel(array('hasMany' => array('Child'))); @@ -5497,68 +10611,415 @@ class ModelTest extends CakeTestCase { $result = $TestModel->find('all'); $expected = array( - array('Apple' => array( - 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', - 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'), - 'Child' => array( - array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'))), - 'Sample' => array('id' =>'', 'apple_id' => '', 'name' => '')), - array('Apple' => array( - 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17', - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'), - 'Sample' => array(), - 'Child' => array( - array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2')), - array('Apple' => array( - 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', - 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'), - 'Child' => array( - array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => 1, 'apple_id' => 3, 'name' => 'sample1')), - array('Apple' => array( - 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', - 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'), - 'Child' => array( - array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => 3, 'apple_id' => 4, 'name' => 'sample3')), - array('Apple' => array( - 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17', - 'Parent' => array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'), - 'Sample' => array('id' => 4, 'apple_id' => 5, 'name' => 'sample4'), - 'Child' => array( - array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => 4, 'apple_id' => 5, 'name' => 'sample4')), - array('Apple' => array( - 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17', - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'), - 'Sample' => array('id' => 3, 'apple_id' => 4, 'name' => 'sample3'), - 'Child' => array( - array('id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => '', 'apple_id' => '', 'name' => '')), - array('Apple' => array( - 'id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17', - 'Parent' => array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'), - 'Sample' => array(), - 'Child' => array( - array('id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => '', 'apple_id' => '', 'name' => ''))); + array( + 'Apple' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' =>'', + 'apple_id' => '', + 'name' => '' + )), + array( + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + )), + array( + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 1, + 'apple_id' => 3, + 'name' => 'sample1' + )), + array( + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3' + )), + array( + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4' + ), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4' + )), + array( + 'Apple' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3' + ), + 'Child' => array( + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + )), + array( + 'Apple' => array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17', + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ))); $this->assertEqual($result, $expected); $result = $TestModel->Parent->unbindModel(array('belongsTo' => array('Parent'))); @@ -5568,65 +11029,382 @@ class ModelTest extends CakeTestCase { $this->assertTrue($result); $result = $TestModel->find('all'); - $expected = array(array('Apple' => array ( - 'id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', - 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'), + $expected = array( + array( + 'Apple' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' =>'', + 'apple_id' => '', + 'name' => '' + )), + array( + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17', + 'Sample' => array(), 'Child' => array( - array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'))), - 'Sample' => array('id' =>'', 'apple_id' => '', 'name' => '')), - array('Apple' => array( - 'id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17', - 'Sample' => array(), + array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2', + 'Apple' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 1, + 'apple_id' => 3, + 'name' => 'sample1', + 'Apple' => array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 2, + 'apple_id' => 1, + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17', + 'Sample' => array( + 'id' => 2, + 'apple_id' => 2, + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => 1, + 'apple_id' => 2, + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => 3, + 'apple_id' => 2, + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3', + 'Apple' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => + '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17', + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4' + ), + 'Child' => array( + array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => 4, + 'apple_id' => 5, + 'name' => 'sample4', + 'Apple' => array( + 'id' => 5, + 'apple_id' => 5, + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17'), + 'Parent' => array( + 'id' => 4, + 'apple_id' => 2, + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17', + 'Sample' => array( + 'id' => 3, + 'apple_id' => 4, + 'name' => 'sample3' + ), 'Child' => array( - array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2', - 'Apple' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17'))), - array('Apple' => array( - 'id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', - 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'), - 'Child' => array( - array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => 1, 'apple_id' => 3, 'name' => 'sample1', - 'Apple' => array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'))), - array('Apple' => array( - 'id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 2, 'apple_id' => 1, 'color' => 'Bright Red 1', 'name' => 'Bright Red Apple', 'created' => '2006-11-22 10:43:13', 'date' => '2014-01-01', 'modified' => '2006-11-30 18:38:10', 'mytime' => '22:57:17', - 'Sample' => array('id' => 2, 'apple_id' => 2, 'name' => 'sample2'), - 'Child' => array( - array('id' => 1, 'apple_id' => 2, 'color' => 'Red 1', 'name' => 'Red Apple 1', 'created' => '2006-11-22 10:38:58', 'date' => '1951-01-04', 'modified' => '2006-12-01 13:31:26', 'mytime' => '22:57:17'), - array('id' => 3, 'apple_id' => 2, 'color' => 'blue green', 'name' => 'green blue', 'created' => '2006-12-25 05:13:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:24', 'mytime' => '22:57:17'), - array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => 3, 'apple_id' => 4, 'name' => 'sample3', - 'Apple' => array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17'))), - array('Apple' => array( - 'id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17', - 'Sample' => array('id' => 4, 'apple_id' => 5, 'name' => 'sample4'), - 'Child' => array( - array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => 4, 'apple_id' => 5, 'name' => 'sample4', - 'Apple' => array('id' => 5, 'apple_id' => 5, 'color' => 'Green', 'name' => 'Blue Green', 'created' => '2006-12-25 05:24:06', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:16', 'mytime' => '22:57:17'))), - array('Apple' => array( - 'id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 4, 'apple_id' => 2, 'color' => 'Blue Green', 'name' => 'Test Name', 'created' => '2006-12-25 05:23:36', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:23:36', 'mytime' => '22:57:17', - 'Sample' => array('id' => 3, 'apple_id' => 4, 'name' => 'sample3'), - 'Child' => array( - array('id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => '', 'apple_id' => '', 'name' => '')), - array('Apple' => array( - 'id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17'), - 'Parent' => array('id' => 6, 'apple_id' => 4, 'color' => 'My new appleOrange', 'name' => 'My new apple', 'created' => '2006-12-25 05:29:39', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:29:39', 'mytime' => '22:57:17', - 'Sample' => array(), - 'Child' => array( - array('id' => 7, 'apple_id' => 6, 'color' => 'Some wierd color', 'name' => 'Some odd color', 'created' => '2006-12-25 05:34:21', 'date' => '2006-12-25', 'modified' => '2006-12-25 05:34:21', 'mytime' => '22:57:17'))), - 'Sample' => array('id' => '', 'apple_id' => '', 'name' => ''))); + array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + )), + array( + 'Apple' => array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => 6, + 'apple_id' => 4, + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17', + 'Sample' => array(), + 'Child' => array( + array( + 'id' => 7, + 'apple_id' => 6, + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', 'modified' => + '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))), + 'Sample' => array( + 'id' => '', + 'apple_id' => '', + 'name' => '' + ))); $this->assertEqual($result, $expected); } /** @@ -5665,16 +11443,20 @@ class ModelTest extends CakeTestCase { function testAutoSaveUuid() { // SQLite does not support non-integer primary keys, and SQL Server // is still having problems with custom PK's - if ($this->db->config['driver'] == 'sqlite' || $this->db->config['driver'] == 'mssql') { - return; - } + $this->skipIf( + $this->db->config['driver'] == 'sqlite' + || $this->db->config['driver'] == 'mssql' + ); $this->loadFixtures('Uuid'); $TestModel =& new Uuid(); $TestModel->save(array('title' => 'Test record')); $result = $TestModel->findByTitle('Test record'); - $this->assertEqual(array_keys($result['Uuid']), array('id', 'title', 'count', 'created', 'updated')); + $this->assertEqual( + array_keys($result['Uuid']), + array('id', 'title', 'count', 'created', 'updated') + ); $this->assertEqual(strlen($result['Uuid']['id']), 36); } /** @@ -5712,27 +11494,87 @@ class ModelTest extends CakeTestCase { $result = $Post->find('all'); $expected = array( array( - 'Post' => array('id' => '1', 'author_id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), - 'Author' => array('id' => null, 'user' => null, 'password' => null, 'created' => null, 'updated' => null, 'test' => 'working'), + 'Post' => array( + 'id' => '1', + 'author_id' => '1', + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'Author' => array( + 'id' => null, + 'user' => null, + 'password' => null, + 'created' => null, + 'updated' => null, + 'test' => 'working' + ), 'Tag' => array( - array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), - array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31'), - ) - ), + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ))), array( - 'Post' => array('id' => '2', 'author_id' => '3', 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), - 'Author' => array('id' => null, 'user' => null, 'password' => null, 'created' => null, 'updated' => null, 'test' => 'working'), + 'Post' => array( + 'id' => '2', + 'author_id' => '3', + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'Author' => array( + 'id' => null, + 'user' => null, + 'password' => null, + 'created' => null, + 'updated' => null, + 'test' => 'working' + ), 'Tag' => array( - array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), - array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31') - ) - ), + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))), array( - 'Post' => array('id' => '3', 'author_id' => '1', 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'), - 'Author' => array('id' => null, 'user' => null, 'password' => null, 'created' => null, 'updated' => null, 'test' => 'working'), + 'Post' => array( + 'id' => '3', + 'author_id' => '1', + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ), + 'Author' => array( + 'id' => null, + 'user' => null, + 'password' => null, + 'created' => null, + 'updated' => null, + 'test' => 'working' + ), 'Tag' => array() - ) - ); + )); $this->assertEqual($result, $expected); } /** @@ -5846,7 +11688,11 @@ class ModelTest extends CakeTestCase { $TestModel->data = null; $TestModel->set($data); - $expected = array('Apple'=> array('created'=> '', 'date'=> '2006-12-25')); + $expected = array( + 'Apple'=> array( + 'created'=> '', + 'date'=> '2006-12-25' + )); $this->assertEqual($TestModel->data, $expected); $data = array(); @@ -5862,7 +11708,11 @@ class ModelTest extends CakeTestCase { $TestModel->data = null; $TestModel->set($data); - $expected = array('Apple'=> array('created'=> '2007-08-20 10:12:09', 'date'=> '2006-12-25')); + $expected = array( + 'Apple'=> array( + 'created'=> '2007-08-20 10:12:09', + 'date'=> '2006-12-25' + )); $this->assertEqual($TestModel->data, $expected); $data = array(); @@ -5957,8 +11807,12 @@ class ModelTest extends CakeTestCase { * @return void */ function testTablePrefixSwitching() { - ConnectionManager::create('database1', array_merge($this->db->config, array('prefix' => 'aaa_'))); - ConnectionManager::create('database2', array_merge($this->db->config, array('prefix' => 'bbb_'))); + ConnectionManager::create('database1', + array_merge($this->db->config, array('prefix' => 'aaa_') + )); + ConnectionManager::create('database2', + array_merge($this->db->config, array('prefix' => 'bbb_') + )); $db1 = ConnectionManager::getDataSource('database1'); $db2 = ConnectionManager::getDataSource('database2'); @@ -6015,9 +11869,15 @@ class ModelTest extends CakeTestCase { $this->assertEqual($TestModel->Behaviors->attached(), array('Tree')); $expected = array( - 'parent' => 'parent_id', 'left' => 'left_field', 'right' => 'right_field', 'scope' => '1 = 1', - 'type' => 'nested', '__parentChange' => false, 'recursive' => -1 + 'parent' => 'parent_id', + 'left' => 'left_field', + 'right' => 'right_field', + 'scope' => '1 = 1', + 'type' => 'nested', + '__parentChange' => false, + 'recursive' => -1 ); + $this->assertEqual($TestModel->Behaviors->Tree->settings['Apple'], $expected); $expected['enabled'] = false; @@ -6037,48 +11897,157 @@ class ModelTest extends CakeTestCase { function testCrossDatabaseJoins() { $config = new DATABASE_CONFIG(); - if (!isset($config->test) || !isset($config->test2)) { - echo "
Primary and secondary test databases not configured, skipping cross-database join tests
"; - echo "To run these tests, you must define \$test and \$test2 in your database configuration.
"; + $skip = $this->skipIf( + !isset($config->test) || !isset($config->test2), + '%s Primary and secondary test databases not configured, skipping cross-database ' + .'join tests.' + .' To run these tests, you must define $test and $test2 in your database configuration.' + ); + + if ($skip) { return; } + $this->loadFixtures('Article', 'Tag', 'ArticlesTag', 'User', 'Comment'); $TestModel =& new Article(); $expected = array( array( - 'Article' => array('id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), - 'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'), - 'Comment' => array( - array('id' => '1', 'article_id' => '1', 'user_id' => '2', 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'), - array('id' => '2', 'article_id' => '1', 'user_id' => '4', 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31'), - array('id' => '3', 'article_id' => '1', 'user_id' => '1', 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'), - array('id' => '4', 'article_id' => '1', 'user_id' => '1', 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31') + 'Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' ), - 'Tag' => array( - array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), - array('id' => '2', 'tag' => 'tag2', 'created' => '2007-03-18 12:24:23', 'updated' => '2007-03-18 12:26:31') - ) - ), - array( - 'Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), - 'User' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'), - 'Comment' => array( - array('id' => '5', 'article_id' => '2', 'user_id' => '1', 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'), - array('id' => '6', 'article_id' => '2', 'user_id' => '2', 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31') + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + ), + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + )), 'Tag' => array( - array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), - array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31') - ) - ), + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ))), array( - 'Article' => array('id' => '3', 'user_id' => '1', 'title' => 'Third Article', 'body' => 'Third Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'), - 'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'), + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), + 'Comment' => array( + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + )), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))), + array( + 'Article' => array( + 'id' => '3', + 'user_id' => '1', + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), 'Comment' => array(), 'Tag' => array() - ) - ); + )); $this->assertEqual($TestModel->find('all'), $expected); $db2 =& ConnectionManager::getDataSource('test2'); @@ -6103,36 +12072,161 @@ class ModelTest extends CakeTestCase { $TestModel->Comment->unbindModel(array('hasOne' => array('Attachment'))); $expected = array( array( - 'Comment' => array('id' => '1', 'article_id' => '1', 'user_id' => '2', 'comment' => 'First Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:45:23', 'updated' => '2007-03-18 10:47:31'), - 'User' => array('id' => '2', 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'), - 'Article' => array('id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31') - ), + 'Comment' => array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + ), + 'Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + )), array( - 'Comment' => array('id' => '2', 'article_id' => '1', 'user_id' => '4', 'comment' => 'Second Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:47:23', 'updated' => '2007-03-18 10:49:31'), - 'User' => array('id' => '4', 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'), - 'Article' => array('id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31') - ), + 'Comment' => array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + ), + 'User' => array( + 'id' => '4', + 'user' => 'garrett', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:22:23', + 'updated' => '2007-03-17 01:24:31' + ), + 'Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + )), array( - 'Comment' => array('id' => '3', 'article_id' => '1', 'user_id' => '1', 'comment' => 'Third Comment for First Article', 'published' => 'Y', 'created' => '2007-03-18 10:49:23', 'updated' => '2007-03-18 10:51:31'), - 'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'), - 'Article' => array('id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31') - ), + 'Comment' => array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + )), array( - 'Comment' => array('id' => '4', 'article_id' => '1', 'user_id' => '1', 'comment' => 'Fourth Comment for First Article', 'published' => 'N', 'created' => '2007-03-18 10:51:23', 'updated' => '2007-03-18 10:53:31'), - 'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'), - 'Article' => array('id' => '1', 'user_id' => '1', 'title' => 'First Article', 'body' => 'First Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31') - ), + 'Comment' => array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + )), array( - 'Comment' => array('id' => '5', 'article_id' => '2', 'user_id' => '1', 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'), - 'User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'), - 'Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31') - ), + 'Comment' => array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + )), array( - 'Comment' => array('id' => '6', 'article_id' => '2', 'user_id' => '2', 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31'), - 'User' => array('id' => '2', 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'), - 'Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31') - ) - ); + 'Comment' => array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ), + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + ), + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ))); $this->assertEqual($TestModel->Comment->find('all'), $expected); foreach (array('User', 'Comment') as $class) { @@ -6187,17 +12281,27 @@ class ModelTest extends CakeTestCase { $this->loadFixtures('Article'); $Article =& new Article(); - $query = 'SELECT title FROM ' . $this->db->fullTableName('articles') . ' WHERE ' . $this->db->fullTableName('articles') . '.id IN (1,2)'; + $query = 'SELECT title FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.id IN (1,2)'; + $results = $Article->query($query); $this->assertTrue(is_array($results)); $this->assertEqual(count($results), 2); - $query = 'SELECT title, body FROM ' . $this->db->fullTableName('articles') . ' WHERE ' . $this->db->fullTableName('articles') . '.id = 1'; + $query = 'SELECT title, body FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.id = 1'; + $results = $Article->query($query, false); $this->assertTrue(!isset($this->db->_queryCache[$query])); $this->assertTrue(is_array($results)); - $query = 'SELECT title, id FROM ' . $this->db->fullTableName('articles') . ' WHERE ' . $this->db->fullTableName('articles') . '.published = ' . $this->db->value('Y'); + $query = 'SELECT title, id FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles'); + $query .= '.published = ' . $this->db->value('Y'); + $results = $Article->query($query, true); $this->assertTrue(isset($this->db->_queryCache[$query])); $this->assertTrue(is_array($results)); @@ -6213,42 +12317,73 @@ class ModelTest extends CakeTestCase { $Article =& new Article(); $this->db->_queryCache = array(); - $finalQuery = 'SELECT title, published FROM ' . $this->db->fullTableName('articles') . ' WHERE ' . $this->db->fullTableName('articles') . '.id = ' . $this->db->value(1) . ' AND ' . $this->db->fullTableName('articles') . '.published = ' . $this->db->value('Y'); + $finalQuery = 'SELECT title, published FROM '; + $finalQuery .= $this->db->fullTableName('articles'); + $finalQuery .= ' WHERE ' . $this->db->fullTableName('articles'); + $finalQuery .= '.id = ' . $this->db->value(1); + $finalQuery .= ' AND ' . $this->db->fullTableName('articles'); + $finalQuery .= '.published = ' . $this->db->value('Y'); - $query = 'SELECT title, published FROM ' . $this->db->fullTableName('articles') . ' WHERE ' . $this->db->fullTableName('articles') . '.id = ? AND ' . $this->db->fullTableName('articles') . '.published = ?'; + $query = 'SELECT title, published FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles'); + $query .= '.id = ? AND ' . $this->db->fullTableName('articles') . '.published = ?'; $params = array(1, 'Y'); $result = $Article->query($query, $params); - $expected = array('0' => array($this->db->fullTableName('articles', false) => array('title' => 'First Article', 'published' => 'Y'))); + $expected = array( + '0' => array( + $this->db->fullTableName('articles', false) => array( + 'title' => 'First Article', 'published' => 'Y') + )); + if (isset($result[0][0])) { $expected[0][0] = $expected[0][$this->db->fullTableName('articles', false)]; unset($expected[0][$this->db->fullTableName('articles', false)]); } + $this->assertEqual($result, $expected); $this->assertTrue(isset($this->db->_queryCache[$finalQuery])); - $finalQuery = 'SELECT id, created FROM ' . $this->db->fullTableName('articles') . ' WHERE ' . $this->db->fullTableName('articles') . '.title = ' . $this->db->value('First Article'); - $query = 'SELECT id, created FROM ' . $this->db->fullTableName('articles') . ' WHERE ' . $this->db->fullTableName('articles') . '.title = ?'; + $finalQuery = 'SELECT id, created FROM '; + $finalQuery .= $this->db->fullTableName('articles'); + $finalQuery .= ' WHERE ' . $this->db->fullTableName('articles'); + $finalQuery .= '.title = ' . $this->db->value('First Article'); + + $query = 'SELECT id, created FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.title = ?'; + $params = array('First Article'); $result = $Article->query($query, $params, false); $this->assertTrue(is_array($result)); - $this->assertTrue(isset($result[0][$this->db->fullTableName('articles', false)]) || isset($result[0][0])); + $this->assertTrue( + isset($result[0][$this->db->fullTableName('articles', false)]) + || isset($result[0][0]) + ); $this->assertFalse(isset($this->db->_queryCache[$finalQuery])); - $query = 'SELECT title FROM ' . $this->db->fullTableName('articles') . ' WHERE ' . $this->db->fullTableName('articles') . '.title LIKE ?'; + $query = 'SELECT title FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.title LIKE ?'; + $params = array('%First%'); $result = $Article->query($query, $params); $this->assertTrue(is_array($result)); $this->assertTrue( - isset($result[0][$this->db->fullTableName('articles', false)]['title']) || - isset($result[0][0]['title']) + isset($result[0][$this->db->fullTableName('articles', false)]['title']) + || isset($result[0][0]['title']) ); //related to ticket #5035 - $query = 'SELECT title FROM ' . $this->db->fullTableName('articles') . ' WHERE title = ? AND published = ?'; + $query = 'SELECT title FROM '; + $query .= $this->db->fullTableName('articles') . ' WHERE title = ? AND published = ?'; $params = array('First? Article', 'Y'); $Article->query($query, $params); - $expected = 'SELECT title FROM ' . $this->db->fullTableName('articles') . " WHERE title = 'First? Article' AND published = 'Y'"; + + $expected = 'SELECT title FROM '; + $expected .= $this->db->fullTableName('articles'); + $expected .= " WHERE title = 'First? Article' AND published = 'Y'"; $this->assertTrue(isset($this->db->_queryCache[$expected])); } @@ -6262,9 +12397,12 @@ class ModelTest extends CakeTestCase { $this->loadFixtures('Article'); $Article =& new Article(); - $query = 'SELECT * FROM ' . $this->db->fullTableName('articles') . ' WHERE ' . $this->db->fullTableName('articles') . '.published = ? AND ' . $this->db->fullTableName('articles') . '.user_id = ?'; + $query = 'SELECT * FROM ' . $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles'); + $query .= '.published = ? AND ' . $this->db->fullTableName('articles') . '.user_id = ?'; $params = array('Y'); $this->expectError(); + ob_start(); $result = $Article->query($query, $params); ob_end_clean(); @@ -6277,7 +12415,10 @@ class ModelTest extends CakeTestCase { * @return void */ function testVeryStrangeUseCase() { - if ($this->db->config['driver'] == 'mssql') { + $message = "%s skipping SELECT * FROM ? WHERE ? = ? AND ? = ?; prepared query."; + $message .= " MSSQL is incompatible with this test."; + + if ($this->skipIf($this->db->config['driver'] == 'mssql', $message)) { return; } @@ -6285,8 +12426,13 @@ class ModelTest extends CakeTestCase { $Article =& new Article(); $query = 'SELECT * FROM ? WHERE ? = ? AND ? = ?'; - $param = array($this->db->fullTableName('articles'), $this->db->fullTableName('articles') . '.user_id', '3', $this->db->fullTableName('articles') . '.published', 'Y'); + $param = array( + $this->db->fullTableName('articles'), + $this->db->fullTableName('articles') . '.user_id', '3', + $this->db->fullTableName('articles') . '.published', 'Y' + ); $this->expectError(); + ob_start(); $result = $Article->query($query, $param); ob_end_clean(); @@ -6328,7 +12474,9 @@ class ModelTest extends CakeTestCase { function testGroupBy() { $db = ConnectionManager::getDataSource('test_suite'); $isStrictGroupBy = in_array($db->config['driver'], array('postgres', 'oracle')); - if ($this->skipIf($isStrictGroupBy, '%s Postgresql and Oracle have strict GROUP BY and are incompatible with this test.')) { + $message = '%s Postgresql and Oracle have strict GROUP BY and are incompatible with this test.'; + + if ($this->skipIf($isStrictGroupBy, $message )) { return; } @@ -6343,20 +12491,42 @@ class ModelTest extends CakeTestCase { $expected = array( array( - 'Thread' => array('id' => 1, 'project_id' => 1, 'name' => 'Project 1, Thread 1'), - 'Project' => array('id' => 1, 'name' => 'Project 1'), - 'Message' => array(array('id' => 1, 'thread_id' => 1, 'name' => 'Thread 1, Message 1')), - ), + 'Thread' => array( + 'id' => 1, + 'project_id' => 1, + 'name' => 'Project 1, Thread 1' + ), + 'Project' => array( + 'id' => 1, + 'name' => 'Project 1' + ), + 'Message' => array( + array( + 'id' => 1, + 'thread_id' => 1, + 'name' => 'Thread 1, Message 1' + ))), array( - 'Thread' => array('id' => 3, 'project_id' => 2, 'name' => 'Project 2, Thread 1'), - 'Project' => array('id' => 2, 'name' => 'Project 2'), - 'Message' => array(array('id' => 3, 'thread_id' => 3, 'name' => 'Thread 3, Message 1')), - ), - ); + 'Thread' => array( + 'id' => 3, + 'project_id' => 2, + 'name' => 'Project 2, Thread 1' + ), + 'Project' => array( + 'id' => 2, + 'name' => 'Project 2' + ), + 'Message' => array( + array( + 'id' => 3, + 'thread_id' => 3, + 'name' => 'Thread 3, Message 1' + )))); $this->assertEqual($result, $expected); $rows = $Thread->find('all', array( - 'group' => 'Thread.project_id', 'fields' => array('Thread.project_id', 'COUNT(*) AS total') + 'group' => 'Thread.project_id', + 'fields' => array('Thread.project_id', 'COUNT(*) AS total') )); $result = array(); foreach($rows as $row) { @@ -6384,43 +12554,59 @@ class ModelTest extends CakeTestCase { $this->assertEqual($result, $expected); $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), 'group' => 'Thread.project_id') - ); + 'conditions' => array('Thread.project_id' => 1), + 'group' => 'Thread.project_id' + )); $expected = array( array( - 'Thread' => array('id' => 1, 'project_id' => 1, 'name' => 'Project 1, Thread 1'), - 'Project' => array('id' => 1, 'name' => 'Project 1'), - 'Message' => array(array('id' => 1, 'thread_id' => 1, 'name' => 'Thread 1, Message 1')), - ) - ); + 'Thread' => array( + 'id' => 1, + 'project_id' => 1, + 'name' => 'Project 1, Thread 1' + ), + 'Project' => array( + 'id' => 1, + 'name' => 'Project 1' + ), + 'Message' => array( + array( + 'id' => 1, + 'thread_id' => 1, + 'name' => 'Thread 1, Message 1' + )))); $this->assertEqual($result, $expected); $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), 'group' => 'Thread.project_id, Project.id') - ); + 'conditions' => array('Thread.project_id' => 1), + 'group' => 'Thread.project_id, Project.id' + )); $this->assertEqual($result, $expected); $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), 'group' => 'project_id') - ); + 'conditions' => array('Thread.project_id' => 1), + 'group' => 'project_id' + )); $this->assertEqual($result, $expected); $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), 'group' => array('project_id')) - ); + 'conditions' => array('Thread.project_id' => 1), + 'group' => array('project_id') + )); $this->assertEqual($result, $expected); $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), 'group' => array('project_id', 'Project.id')) - ); + 'conditions' => array('Thread.project_id' => 1), + 'group' => array('project_id', 'Project.id') + )); $this->assertEqual($result, $expected); $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), 'group' => array('Thread.project_id', 'Project.id')) - ); + 'conditions' => array('Thread.project_id' => 1), + 'group' => array('Thread.project_id', 'Project.id') + )); $this->assertEqual($result, $expected); @@ -6454,13 +12640,15 @@ class ModelTest extends CakeTestCase { $Article =& new Article(); - $data = array('Article' => array( - 'created' => array( - 'day' => '1', 'month' => '1', 'year' => '2008' - ), - 'title' => 'Test Title', - // schreck - Jul 30, 2008 - should this be set to something else? - 'user_id' => 1 + $data = array( + 'Article' => array( + 'created' => array( + 'day' => '1', + 'month' => '1', + 'year' => '2008' + ), + 'title' => 'Test Title', + 'user_id' => 1 )); $Article->create(); $this->assertTrue($Article->save($data)); @@ -6485,8 +12673,16 @@ class ModelTest extends CakeTestCase { $Cd->del(1); - $result = $OverallFavorite->find('all', array('fields' => array('model_type', 'model_id', 'priority'))); - $expected = array(array('OverallFavorite' => array('model_type' => 'Book', 'model_id' => 1, 'priority' => 2))); + $result = $OverallFavorite->find('all', array( + 'fields' => array('model_type', 'model_id', 'priority') + )); + $expected = array( + array( + 'OverallFavorite' => array( + 'model_type' => 'Book', + 'model_id' => 1, + 'priority' => 2 + ))); $this->assertTrue(is_array($result)); $this->assertEqual($result, $expected); @@ -6507,10 +12703,18 @@ class ModelTest extends CakeTestCase { array( 'Article' => array('id' => 2), 'Comment' => array( - array('id' => 1, 'comment' => '', 'published' => 'Y', 'user_id' => 1), - array('id' => 2, 'comment' => 'comment', 'published' => 'Y', 'user_id' => 1), - ) - ), + array( + 'id' => 1, + 'comment' => '', + 'published' => 'Y', + 'user_id' => 1), + array( + 'id' => 2, + 'comment' => + 'comment', + 'published' => 'Y', + 'user_id' => 1 + ))), array('validate' => 'only') ); $this->assertFalse($result); @@ -6519,14 +12723,32 @@ class ModelTest extends CakeTestCase { array( 'Article' => array('id' => 2), 'Comment' => array( - array('id' => 1, 'comment' => '', 'published' => 'Y', 'user_id' => 1), - array('id' => 2, 'comment' => 'comment', 'published' => 'Y', 'user_id' => 1), - array('id' => 3, 'comment' => '', 'published' => 'Y', 'user_id' => 1), - ) - ), - array('validate' => 'only', 'atomic' => false) + array( + 'id' => 1, + 'comment' => '', + 'published' => 'Y', + 'user_id' => 1 + ), + array( + 'id' => 2, + 'comment' => 'comment', + 'published' => 'Y', + 'user_id' => 1 + ), + array( + 'id' => 3, + 'comment' => '', + 'published' => 'Y', + 'user_id' => 1 + ))), + array( + 'validate' => 'only', + 'atomic' => false + )); + $expected = array( + 'Article' => true, + 'Comment' => array(false, true, false) ); - $expected = array('Article' => true, 'Comment' => array(false, true, false)); $this->assertIdentical($result, $expected); $expected = array('Comment' => array( @@ -6580,17 +12802,39 @@ class ModelTest extends CakeTestCase { $TestModel = new JoinA(); $result = $TestModel->JoinAsJoinB->findById(1); - $expected = array('JoinAsJoinB' => array('id' => 1, 'join_a_id' => 1, 'join_b_id' => 2, 'other' => 'Data for Join A 1 Join B 2', 'created' => '2008-01-03 10:56:33', 'updated' => '2008-01-03 10:56:33')); + $expected = array( + 'JoinAsJoinB' => array( + 'id' => 1, + 'join_a_id' => 1, + 'join_b_id' => 2, + 'other' => 'Data for Join A 1 Join B 2', + 'created' => '2008-01-03 10:56:33', + 'updated' => '2008-01-03 10:56:33' + )); $this->assertEqual($result, $expected); $TestModel->JoinAsJoinB->create(); - $result = $TestModel->JoinAsJoinB->save(array('join_a_id' => 1, 'join_b_id' => 1, 'other' => 'Data for Join A 1 Join B 1', 'created' => '2008-01-03 10:56:44', 'updated' => '2008-01-03 10:56:44')); + $result = $TestModel->JoinAsJoinB->save(array( + 'join_a_id' => 1, + 'join_b_id' => 1, + 'other' => 'Data for Join A 1 Join B 1', + 'created' => '2008-01-03 10:56:44', + 'updated' => '2008-01-03 10:56:44' + )); $this->assertTrue($result); $lastInsertId = $TestModel->JoinAsJoinB->getLastInsertID(); $this->assertTrue($lastInsertId != null); $result = $TestModel->JoinAsJoinB->findById(1); - $expected = array('JoinAsJoinB' => array('id' => 1, 'join_a_id' => 1, 'join_b_id' => 2, 'other' => 'Data for Join A 1 Join B 2', 'created' => '2008-01-03 10:56:33', 'updated' => '2008-01-03 10:56:33')); + $expected = array( + 'JoinAsJoinB' => array( + 'id' => 1, + 'join_a_id' => 1, + 'join_b_id' => 2, + 'other' => 'Data for Join A 1 Join B 2', + 'created' => '2008-01-03 10:56:33', + 'updated' => '2008-01-03 10:56:33' + )); $this->assertEqual($result, $expected); $updatedValue = 'UPDATED Data for Join A 1 Join B 2'; @@ -6632,29 +12876,82 @@ class ModelTest extends CakeTestCase { $Portfolio =& new Portfolio(); $Portfolio->hasAndBelongsToMany['Item']['conditions'] = array('ItemsPortfolio.item_id >' => 1); - $result = $Portfolio->find('first', array('conditions' => array('Portfolio.id' => 1))); + $result = $Portfolio->find('first', array( + 'conditions' => array('Portfolio.id' => 1) + )); $expected = array( - array('id' => 3, 'syfile_id' => 3, 'published' => 0, 'name' => 'Item 3', 'ItemsPortfolio' => array('id' => 3, 'item_id' => 3, 'portfolio_id' => 1)), - array('id' => 4, 'syfile_id' => 4, 'published' => 0, 'name' => 'Item 4', 'ItemsPortfolio' => array('id' => 4, 'item_id' => 4, 'portfolio_id' => 1)), - array('id' => 5, 'syfile_id' => 5, 'published' => 0, 'name' => 'Item 5', 'ItemsPortfolio' => array('id' => 5, 'item_id' => 5, 'portfolio_id' => 1)), - ); + array( + 'id' => 3, + 'syfile_id' => 3, + 'published' => 0, + 'name' => 'Item 3', + 'ItemsPortfolio' => array( + 'id' => 3, + 'item_id' => 3, + 'portfolio_id' => 1 + )), + array( + 'id' => 4, + 'syfile_id' => 4, + 'published' => 0, + 'name' => 'Item 4', + 'ItemsPortfolio' => array( + 'id' => 4, + 'item_id' => 4, + 'portfolio_id' => 1 + )), + array( + 'id' => 5, + 'syfile_id' => 5, + 'published' => 0, + 'name' => 'Item 5', + 'ItemsPortfolio' => array( + 'id' => 5, + 'item_id' => 5, + 'portfolio_id' => 1 + ))); $this->assertEqual($result['Item'], $expected); - $result = $Portfolio->ItemsPortfolio->find('all', array('conditions' => array('ItemsPortfolio.portfolio_id' => 1))); + $result = $Portfolio->ItemsPortfolio->find('all', array( + 'conditions' => array('ItemsPortfolio.portfolio_id' => 1) + )); $expected = array( - array('ItemsPortfolio' => array('id' => 1, 'item_id' => 1, 'portfolio_id' => 1)), - array('ItemsPortfolio' => array('id' => 3, 'item_id' => 3, 'portfolio_id' => 1)), - array('ItemsPortfolio' => array('id' => 4, 'item_id' => 4, 'portfolio_id' => 1)), - array('ItemsPortfolio' => array('id' => 5, 'item_id' => 5, 'portfolio_id' => 1)) - ); + array( + 'ItemsPortfolio' => array( + 'id' => 1, + 'item_id' => 1, + 'portfolio_id' => 1 + )), + array( + 'ItemsPortfolio' => array( + 'id' => 3, + 'item_id' => 3, + 'portfolio_id' => 1 + )), + array( + 'ItemsPortfolio' => array( + 'id' => 4, + 'item_id' => 4, + 'portfolio_id' => 1 + )), + array( + 'ItemsPortfolio' => array( + 'id' => 5, + 'item_id' => 5, + 'portfolio_id' => 1 + ))); $this->assertEqual($result, $expected); $Portfolio->delete(1); - $result = $Portfolio->find('first', array('conditions' => array('Portfolio.id' => 1))); + $result = $Portfolio->find('first', array( + 'conditions' => array('Portfolio.id' => 1) + )); $this->assertFalse($result); - $result = $Portfolio->ItemsPortfolio->find('all', array('conditions' => array('ItemsPortfolio.portfolio_id' => 1))); + $result = $Portfolio->ItemsPortfolio->find('all', array( + 'conditions' => array('ItemsPortfolio.portfolio_id' => 1) + )); $this->assertFalse($result); } /** From e54dbd430f7f60f38d962cc27e9fe4811572e256 Mon Sep 17 00:00:00 2001 From: gwoo Date: Wed, 10 Jun 2009 17:11:17 +0000 Subject: [PATCH 06/95] fixes #6419, redirect with cached view page git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8193 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/helpers/cache.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cake/libs/view/helpers/cache.php b/cake/libs/view/helpers/cache.php index dd4f1b499..d8e60b12f 100644 --- a/cake/libs/view/helpers/cache.php +++ b/cake/libs/view/helpers/cache.php @@ -264,7 +264,8 @@ class CacheHelper extends AppHelper { $controller->params = $this->params = unserialize(stripslashes(\'' . addslashes(serialize($this->params)) . '\')); $controller->action = $this->action = unserialize(\'' . serialize($this->action) . '\'); $controller->data = $this->data = unserialize(stripslashes(\'' . addslashes(serialize($this->data)) . '\')); - $controller->themeWeb = $this->themeWeb = \'' . $this->themeWeb . '\';'; + $controller->themeWeb = $this->themeWeb = \'' . $this->themeWeb . '\'; + Router::setRequestInfo(array($this->params, array(\'base\' => $this->base, \'webroot\' => $this->webroot)));'; if ($useCallbacks == true) { $file .= ' @@ -275,7 +276,6 @@ class CacheHelper extends AppHelper { } $file .= ' - Router::setRequestInfo(array($this->params, array(\'base\' => $this->base, \'webroot\' => $this->webroot))); $loadedHelpers = array(); $loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers); foreach (array_keys($loadedHelpers) as $helper) { From d335fefbee819c18cba9b33d32e65f36824b7693 Mon Sep 17 00:00:00 2001 From: jperras Date: Thu, 11 Jun 2009 03:07:38 +0000 Subject: [PATCH 07/95] Adding a 'client' option to EmailComponent:: for specifying the host to be used in the SMTP HELO request; defaults to env('HTTP_HOST'). Fixes #6264. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8194 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/components/email.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php index 90dc72055..7fb016d00 100644 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -674,8 +674,8 @@ class EmailComponent extends Object{ return false; } - if (isset($this->smtpOptions['host'])) { - $host = $this->smtpOptions['host']; + if (isset($this->smtpOptions['client'])) { + $host = $this->smtpOptions['client']; } else { $host = env('HTTP_HOST'); } From 9caae67be18ff100152ab4b399443982382f74d5 Mon Sep 17 00:00:00 2001 From: gwoo Date: Tue, 16 Jun 2009 20:14:50 +0000 Subject: [PATCH 08/95] removing delete from cache write refs #5206 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8195 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/cache/file.php | 1 - 1 file changed, 1 deletion(-) diff --git a/cake/libs/cache/file.php b/cake/libs/cache/file.php index 29dde9249..abbd5a0e6 100644 --- a/cake/libs/cache/file.php +++ b/cake/libs/cache/file.php @@ -168,7 +168,6 @@ class FileEngine extends CacheEngine { if ($cachetime !== false && ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime)) { $this->__File->close(); - $this->__File->delete(); return false; } $data = $this->__File->read(true); From a903a4527f4567d5e42b551b06e46b0a1f46e512 Mon Sep 17 00:00:00 2001 From: gwoo Date: Tue, 16 Jun 2009 20:22:41 +0000 Subject: [PATCH 09/95] fixes #6359, array_intersect_key compatibility with php4 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8196 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/basics.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/basics.php b/cake/basics.php index 93bb05f24..cae6e65bd 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -830,7 +830,7 @@ if (!function_exists('file_put_contents')) { function array_intersect_key($arr1, $arr2) { $res = array(); foreach ($arr1 as $key => $value) { - if (isset($arr2[$key])) { + if (array_key_exists($key, $arr2)) { $res[$key] = $arr1[$key]; } } From 88e0cfa2f856a004d7ccb4a12d2bf4a5f5282f8f Mon Sep 17 00:00:00 2001 From: gwoo Date: Tue, 16 Jun 2009 21:35:21 +0000 Subject: [PATCH 10/95] fixes #6427, default datasource not loaded when ds is specified git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8197 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/model.php | 4 ++++ cake/tests/cases/libs/model/model.test.php | 27 ++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index ae19e51ef..c18d035e0 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -372,6 +372,10 @@ class Model extends Overloadable { } elseif ($table) { $this->useTable = $table; } + + if ($ds !== null) { + $this->useDbConfig = $ds; + } if (is_subclass_of($this, 'AppModel')) { $appVars = get_class_vars('AppModel'); diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 240b27fce..a4b75847b 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -268,6 +268,23 @@ class ModelTest extends CakeTestCase { $this->assertEqual($TestModel->actsAs, $expected); $this->assertTrue(isset($TestModel->Behaviors->Containable)); } +/** + * test Model::__construct + * + * ensure that $actsAS and $_findMethods are merged. + * + * @return void + **/ + function testConstructWithAlternateDataSource() { + $TestModel =& ClassRegistry::init(array( + 'class' => 'DoesntMatter', 'ds' => 'test_suite', 'table' => false + )); + $this->assertEqual('test_suite', $TestModel->useDbConfig); + + //deprecated but test it anyway + $NewVoid =& new TheVoid(null, false, 'other'); + $this->assertEqual('other', $NewVoid->useDbConfig); + } /** * testColumnTypeFetching method * @@ -3655,7 +3672,7 @@ class ModelTest extends CakeTestCase { $TestModel->create(array('name' => 'project')) && $TestModel->save(); $TestModel->create(array('name' => 'project')) && $TestModel->save(); $TestModel->create(array('name' => 'project')) && $TestModel->save(); - + $result = $TestModel->find('count', array('fields' => 'DISTINCT name')); $this->assertEqual($result, 4); } @@ -12539,8 +12556,8 @@ class ModelTest extends CakeTestCase { $this->assertEqual($result, $expected); $rows = $Thread->find('all', array( - 'group' => 'Thread.project_id', - 'fields' => array('Thread.project_id', 'COUNT(*) AS total'), + 'group' => 'Thread.project_id', + 'fields' => array('Thread.project_id', 'COUNT(*) AS total'), 'order'=> 'Thread.project_id' )); $result = array(); @@ -12617,14 +12634,14 @@ class ModelTest extends CakeTestCase { array('Product' => array('type' => 'Toy'), array('price' => 3)) ); $result = $Product->find('all',array( - 'fields'=>array('Product.type','MIN(Product.price) as price'), + 'fields'=>array('Product.type','MIN(Product.price) as price'), 'group'=> 'Product.type', 'order' => 'Product.type ASC' )); $this->assertEqual($result, $expected); $result = $Product->find('all', array( - 'fields'=>array('Product.type','MIN(Product.price) as price'), + 'fields'=>array('Product.type','MIN(Product.price) as price'), 'group'=> array('Product.type'), 'order' => 'Product.type ASC')); $this->assertEqual($result, $expected); From 1ea5f94c29befd858148630f8aa8629607829776 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 17 Jun 2009 01:59:41 +0000 Subject: [PATCH 11/95] Updating JavascriptHelper::escapeString to properly encode utf8 characters as per the JSON spec. Test cases added, with comparisons to json_encode() Fixes #6400 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8198 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/helpers/javascript.php | 100 +++++++++++++++++- .../libs/view/helpers/javascript.test.php | 57 +++++++++- 2 files changed, 153 insertions(+), 4 deletions(-) diff --git a/cake/libs/view/helpers/javascript.php b/cake/libs/view/helpers/javascript.php index 9a921deb9..bd1a804f0 100644 --- a/cake/libs/view/helpers/javascript.php +++ b/cake/libs/view/helpers/javascript.php @@ -319,8 +319,104 @@ class JavascriptHelper extends AppHelper { * @return string Escaped string. */ function escapeString($string) { - $escape = array('\n' => '\\\n', "\r\n" => '\n', "\r" => '\n', "\n" => '\n', '"' => '\"', "'" => "\\'"); - return str_replace(array_keys($escape), array_values($escape), $string); + App::import('Core', 'Multibyte'); + $escape = array("\r\n" => "\n", "\r" => "\n"); + $string = str_replace(array_keys($escape), array_values($escape), $string); + return $this->_utf8ToHex($string); + } +/** + * Encode a string into JSON. Converts and escapes necessary characters. + * + * @return void + **/ + function _utf8ToHex($string) { + $length = strlen($string); + $return = ''; + for ($i = 0; $i < $length; ++$i) { + $ord = ord($string{$i}); + switch (true) { + case $ord == 0x08: + $return .= '\b'; + break; + case $ord == 0x09: + $return .= '\t'; + break; + case $ord == 0x0A: + $return .= '\n'; + break; + case $ord == 0x0C: + $return .= '\f'; + break; + case $ord == 0x0D: + $return .= '\r'; + break; + case $ord == 0x22: + case $ord == 0x2F: + case $ord == 0x5C: + case $ord == 0x27: + $return .= '\\' . $string{$i}; + break; + case (($ord >= 0x20) && ($ord <= 0x7F)): + $return .= $string{$i}; + break; + case (($ord & 0xE0) == 0xC0): + if ($i + 1 >= $length) { + $i += 1; + $return .= '?'; + break; + } + $charbits = $string{$i} . $string{$i + 1}; + $char = Multibyte::utf8($charbits); + $return .= sprintf('\u%04s', dechex($char[0])); + $i += 1; + break; + case (($ord & 0xF0) == 0xE0): + if ($i + 2 >= $length) { + $i += 2; + $return .= '?'; + break; + } + $charbits = $string{$i} . $string{$i + 1} . $string{$i + 2}; + $char = Multibyte::utf8($charbits); + $return .= sprintf('\u%04s', dechex($char[0])); + $i += 2; + break; + case (($ord & 0xF8) == 0xF0): + if ($i + 3 >= $length) { + $i += 3; + $return .= '?'; + break; + } + $charbits = $string{$i} . $string{$i + 1} . $string{$i + 2} . $string{$i + 3}; + $char = Multibyte::utf8($charbits); + $return .= sprintf('\u%04s', dechex($char[0])); + $i += 3; + break; + case (($ord & 0xFC) == 0xF8): + if ($i + 4 >= $length) { + $i += 4; + $return .= '?'; + break; + } + $charbits = $string{$i} . $string{$i + 1} . $string{$i + 2} . $string{$i + 3} . $string{$i + 4}; + $char = Multibyte::utf8($charbits); + $return .= sprintf('\u%04s', dechex($char[0])); + $i += 4; + break; + case (($ord & 0xFE) == 0xFC): + if ($i + 5 >= $length) { + $i += 5; + $return .= '?'; + break; + } + $charbits = $string{$i} . $string{$i + 1} . $string{$i + 2} . $string{$i + 3} . $string{$i + 4} . $string{$i + 5}; + $char = Multibyte::utf8($charbits); + $return .= sprintf('\u%04s', dechex($char[0])); + $i += 5; + break; + } + } + return $return; } /** * Attach an event to an element. Used with the Prototype library. diff --git a/cake/tests/cases/libs/view/helpers/javascript.test.php b/cake/tests/cases/libs/view/helpers/javascript.test.php index 77425743b..124f8a092 100644 --- a/cake/tests/cases/libs/view/helpers/javascript.test.php +++ b/cake/tests/cases/libs/view/helpers/javascript.test.php @@ -402,6 +402,7 @@ class JavascriptTest extends CakeTestCase { $this->Javascript->useNative = $oldNative; } + /** * testScriptBlock method * @@ -653,11 +654,11 @@ class JavascriptTest extends CakeTestCase { $this->assertEqual($result, $expected); $result = $this->Javascript->escapeString('CakePHP: \'Rapid Development Framework\''); - $expected = 'CakePHP: \\\'Rapid Development Framework\\\''; + $expected = "CakePHP: \\'Rapid Development Framework\\'"; $this->assertEqual($result, $expected); $result = $this->Javascript->escapeString('my \\"string\\"'); - $expected = 'my \\\"string\\\"'; + $expected = 'my \\\\\\"string\\\\\\"'; $this->assertEqual($result, $expected); $result = $this->Javascript->escapeString('my string\nanother line'); @@ -672,6 +673,58 @@ class JavascriptTest extends CakeTestCase { $expected = 'String with \\\n string that looks like newline'; $this->assertEqual($result, $expected); } +/** + * test string escaping and compare to json_encode() + * + * @return void + **/ + function testStringJsonEncodeCompliance() { + if (!function_exists('json_encode')) { + return; + } + $this->Javascript->useNative = false; + $data = array(); + $data['mystring'] = "simple string"; + $this->assertEqual(json_encode($data), $this->Javascript->object($data)); + + $data['mystring'] = "strïng with spécial chârs"; + $this->assertEqual(json_encode($data), $this->Javascript->object($data)); + + $data['mystring'] = "a two lines\nstring"; + $this->assertEqual(json_encode($data), $this->Javascript->object($data)); + + $data['mystring'] = "a \t tabbed \t string"; + $this->assertEqual(json_encode($data), $this->Javascript->object($data)); + + $data['mystring'] = "a \"double-quoted\" string"; + $this->assertEqual(json_encode($data), $this->Javascript->object($data)); + + $data['mystring'] = 'a \\"double-quoted\\" string'; + $this->assertEqual(json_encode($data), $this->Javascript->object($data)); + } +/** + * test that text encoded with Javascript::object decodes properly + * + * @return void + **/ + function testObjectDecodeCompatibility() { + if (!function_exists('json_decode')) { + return; + } + $this->Javascript->useNative = false; + + $data = array("simple string"); + $result = $this->Javascript->object($data); + $this->assertEqual(json_decode($result), $data); + + $data = array('my \"string\"'); + $result = $this->Javascript->object($data); + $this->assertEqual(json_decode($result), $data); + + $data = array('my \\"string\\"'); + $result = $this->Javascript->object($data); + $this->assertEqual(json_decode($result), $data); + } /** * testAfterRender method * From a2a7727c00568c4f5a52ad9aaec0cc41cda55ee6 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 17 Jun 2009 02:17:18 +0000 Subject: [PATCH 12/95] Fixing plugin prefix handling when using plugin task to bake plugin controllers. Plugin Models are correctly found, allowing bake to work. Fixes #5069 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8199 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/console/libs/tasks/controller.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cake/console/libs/tasks/controller.php b/cake/console/libs/tasks/controller.php index aefe126ea..b4a98756d 100644 --- a/cake/console/libs/tasks/controller.php +++ b/cake/console/libs/tasks/controller.php @@ -243,8 +243,11 @@ class ControllerTask extends Shell { * @access private */ function bakeActions($controllerName, $admin = null, $wannaUseSession = true) { - $currentModelName = $this->_modelName($controllerName); - if (!App::import('Model', $currentModelName)) { + $currentModelName = $modelImport = $this->_modelName($controllerName); + if ($this->plugin) { + $modelImport = $this->plugin . '.' . $modelImport; + } + if (!App::import('Model', $modelImport)) { $this->err(__('You must have a model for this class to build scaffold methods. Please try again.', true)); exit; } From 3e8e7a2a6f7223242efd5bb0a993e1801fff7d1f Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 21 Jun 2009 15:24:09 +0000 Subject: [PATCH 13/95] Adding tests to Component.test. Disproves #6459 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8200 3807eeeb-6ff5-0310-8944-8be069107fe0 --- .../cases/libs/controller/component.test.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cake/tests/cases/libs/controller/component.test.php b/cake/tests/cases/libs/controller/component.test.php index cd99ec02c..e3f78b28c 100644 --- a/cake/tests/cases/libs/controller/component.test.php +++ b/cake/tests/cases/libs/controller/component.test.php @@ -436,6 +436,21 @@ class ComponentTest extends CakeTestCase { $this->assertEqual($Controller->Orange->settings, $expected); $this->assertEqual($Controller->ParamTest->test, 'value'); } + +/** + * Ensure that settings are not duplicated when passed into component initialize. + * + * @return void + **/ + function testComponentParamsNoDuplication() { + $Controller =& new ComponentTestController(); + $Controller->components = array('Orange' => array('setting' => array('itemx'))); + + $Controller->constructClasses(); + $Controller->Component->initialize($Controller); + $expected = array('setting' => array('itemx'), 'colour' => 'blood orange'); + $this->assertEqual($Controller->Orange->settings, $expected, 'Params duplication has occured %s'); + } /** * Test mutually referencing components. * From 16eb51e91c53c780c6089df397051516052467b1 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 24 Jun 2009 18:09:14 +0000 Subject: [PATCH 14/95] Adding ControllerMergeVarsTestCase to more extensively test merging of vars in Controller::__mergeVars. Fixing issue where components declared in AppController would get doubled settings if no components were declared in subclasses. Fixes #6459 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8201 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/controller.php | 8 +- .../controller/controller_merge_vars.test.php | 222 ++++++++++++++++++ 2 files changed, 228 insertions(+), 2 deletions(-) create mode 100644 cake/tests/cases/libs/controller/controller_merge_vars.test.php diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 5c33e1a49..e559cac78 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -393,7 +393,9 @@ class Controller extends Object { if ($var === 'components') { $normal = Set::normalize($this->{$var}); $app = Set::normalize($appVars[$var]); - $this->{$var} = Set::merge($app, $normal); + if ($app !== $normal) { + $this->{$var} = Set::merge($app, $normal); + } } else { $this->{$var} = Set::merge($this->{$var}, array_diff($appVars[$var], $this->{$var})); } @@ -415,7 +417,9 @@ class Controller extends Object { if ($var === 'components') { $normal = Set::normalize($this->{$var}); $app = Set::normalize($appVars[$var]); - $this->{$var} = Set::merge($normal, array_diff_assoc($app, $normal)); + if ($app !== $normal) { + $this->{$var} = Set::merge($app, $normal); + } } else { $this->{$var} = Set::merge($this->{$var}, array_diff($appVars[$var], $this->{$var})); } diff --git a/cake/tests/cases/libs/controller/controller_merge_vars.test.php b/cake/tests/cases/libs/controller/controller_merge_vars.test.php new file mode 100644 index 000000000..b405d3eca --- /dev/null +++ b/cake/tests/cases/libs/controller/controller_merge_vars.test.php @@ -0,0 +1,222 @@ + + * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) + * + * Licensed under The Open Group Test Suite License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) + * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests + * @package cake + * @subpackage cake.tests.cases.libs.controller + * @since CakePHP(tm) v 1.2.3 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License + */ +if (!class_exists('AppController')) { + /** + * Test case AppController requred + * + * @package cake.tests.cases.libs.controller + **/ + class AppController extends Controller { + /** + * components + * + * @var array + **/ + var $components = array('MergeVar' => array('flag', 'otherFlag', 'redirect' => false)); + /** + * helpers + * + * @var array + **/ + var $helpers = array('MergeVar' => array('format' => 'html', 'terse')); + } +} elseif (!defined('APP_CONTROLLER_EXISTS')) { + define('APP_CONTROLLER_EXISTS', true); +} + +/** + * MergeVar Component + * + * @package cake.tests.cases.libs.controller + **/ +class MergeVarComponent extends Object { + +} + +/** + * Additional controller for testing + * + * @package cake.tests.cases.libs.controller + **/ +class MergeVariablesController extends AppController { +/** + * name + * + * @var string + **/ + var $name = 'MergeVariables'; +/** + * uses + * + * @var arrays + **/ + var $uses = array(); +} + +/** + * MergeVarPlugin App Controller + * + * @package cake.tests.cases.libs.controller + **/ +class MergeVarPluginAppController extends AppController { +/** + * components + * + * @var array + **/ + var $components = array('Auth' => array('setting' => 'val', 'otherVal')); +/** + * helpers + * + * @var array + **/ + var $helpers = array('Javascript'); +} + +/** + * MergePostsController + * + * @package cake.tests.cases.libs.controller + **/ +class MergePostsController extends MergeVarPluginAppController { +/** + * name + * + * @var string + **/ + var $name = 'MergePosts'; +/** + * uses + * + * @var array + **/ + var $uses = array(); +} + + +/** + * Test Case for Controller Merging of Vars. + * + * @package cake.tests.cases.libs.controller + **/ +class ControllerMergeVarsTestCase extends CakeTestCase { + +/** + * end test + * + * @return void + **/ + function endTest() { + ClassRegistry::flush(); + } +/** + * test that component settings are not duplicated when merging component settings + * + * @return void + **/ + function testComponentParamMergingNoDuplication() { + $Controller =& new MergeVariablesController(); + $Controller->constructClasses(); + + $expected = array('MergeVar' => array('flag', 'otherFlag', 'redirect' => false)); + $this->assertEqual($Controller->components, $expected, 'Duplication of settings occured. %s'); + } +/** + * test component merges with redeclared components + * + * @return void + **/ + function testComponentMergingWithRedeclarations() { + $Controller =& new MergeVariablesController(); + $Controller->components['MergeVar'] = array('remote', 'redirect' => true); + $Controller->constructClasses(); + + $expected = array('MergeVar' => array('flag', 'otherFlag', 'redirect' => true, 'remote')); + $this->assertEqual($Controller->components, $expected, 'Merging of settings is wrong. %s'); + } +/** + * test merging of helpers array, ensure no duplication occurs + * + * @return void + **/ + function testHelperSettingMergingNoDuplication() { + $Controller =& new MergeVariablesController(); + $Controller->constructClasses(); + + $expected = array('MergeVar' => array('format' => 'html', 'terse')); + $this->assertEqual($Controller->helpers, $expected, 'Duplication of settings occured. %s'); + } +/** + * test merging of vars with plugin + * + * @return void + **/ + function testMergeVarsWithPlugin() { + $Controller =& new MergePostsController(); + $Controller->components = array('Email' => array('ports' => 'open')); + $Controller->plugin = 'MergeVarPlugin'; + $Controller->constructClasses(); + + $expected = array( + 'MergeVar' => array('flag', 'otherFlag', 'redirect' => false), + 'Auth' => array('setting' => 'val', 'otherVal'), + 'Email' => array('ports' => 'open') + ); + $this->assertEqual($Controller->components, $expected, 'Components are unexpected %s'); + + $expected = array( + 'Javascript', + 'MergeVar' => array('format' => 'html', 'terse') + ); + $this->assertEqual($Controller->helpers, $expected, 'Helpers are unexpected %s'); + + $Controller =& new MergePostsController(); + $Controller->components = array(); + $Controller->plugin = 'MergeVarPlugin'; + $Controller->constructClasses(); + + $expected = array( + 'MergeVar' => array('flag', 'otherFlag', 'redirect' => false), + 'Auth' => array('setting' => 'val', 'otherVal'), + ); + $this->assertEqual($Controller->components, $expected, 'Components are unexpected %s'); + } +/** + * Ensure that __mergeVars is not being greedy and merging with + * AppController when you make an instance of Controller + * + * @return void + **/ + function testMergeVarsNotGreedy() { + $Controller =& new Controller(); + $Controller->components = array(); + $Controller->uses = array(); + $Controller->constructClasses(); + + $this->assertTrue(isset($Controller->Session)); + } +} \ No newline at end of file From fd818bc493baee508ea032900623e2083cc74b33 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 24 Jun 2009 22:02:00 +0000 Subject: [PATCH 15/95] Applying patch from 'mulleto'. Fixes plugin view file location with CamelCase plugin names. Test cases added. Fixes #6334 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8202 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/view.php | 4 ++-- cake/tests/cases/libs/view/view.test.php | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index d0ad82bdf..80b29d21c 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -800,7 +800,7 @@ class View extends Object { } } - $paths = $this->_paths($this->plugin); + $paths = $this->_paths(Inflector::underscore($this->plugin)); foreach ($paths as $path) { if (file_exists($path . $name . $this->ext)) { @@ -840,7 +840,7 @@ class View extends Object { if (!is_null($this->layoutPath)) { $subDir = $this->layoutPath . DS; } - $paths = $this->_paths($this->plugin); + $paths = $this->_paths(Inflector::underscore($this->plugin)); $file = 'layouts' . DS . $subDir . $name; $exts = array($this->ext, '.ctp', '.thtml'); diff --git a/cake/tests/cases/libs/view/view.test.php b/cake/tests/cases/libs/view/view.test.php index a3bc87803..50dbc4260 100644 --- a/cake/tests/cases/libs/view/view.test.php +++ b/cake/tests/cases/libs/view/view.test.php @@ -248,6 +248,29 @@ class ViewTest extends CakeTestCase { $this->assertEqual($result, $expected); } /** + * test that CamelCase plugins still find their view files. + * + * @return void + **/ + function testCamelCasePluginGetTemplate() { + $this->Controller->plugin = 'TestPlugin'; + $this->Controller->name = 'TestPlugin'; + $this->Controller->viewPath = 'tests'; + $this->Controller->action = 'index'; + + $View = new TestView($this->Controller); + Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)); + Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)); + + $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS .'test_plugin' . DS . 'views' . DS .'tests' . DS .'index.ctp'; + $result = $View->getViewFileName('index'); + $this->assertEqual($result, $expected); + + $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS .'test_plugin' . DS . 'views' . DS . 'layouts' . DS .'default.ctp'; + $result = $View->getLayoutFileName(); + $this->assertEqual($result, $expected); + } +/** * testGetTemplate method * * @access public From 285fdc22c6f1dc25a91e21ebd2e4d6dae41fbaa0 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 25 Jun 2009 13:34:28 +0000 Subject: [PATCH 16/95] Adding test case for api console. Fixing issue where methods with no parameters were omitted from api method lists. Fixes #6474 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8203 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/console/libs/api.php | 30 +++--- cake/tests/cases/console/libs/api.test.php | 118 +++++++++++++++++++++ 2 files changed, 133 insertions(+), 15 deletions(-) create mode 100644 cake/tests/cases/console/libs/api.test.php diff --git a/cake/console/libs/api.php b/cake/console/libs/api.php index 741f2f66f..95897c0c2 100644 --- a/cake/console/libs/api.php +++ b/cake/console/libs/api.php @@ -151,17 +151,17 @@ class ApiShell extends Shell { $commands = array( 'path' => "\t\n" . - "\t\tEither a full path or type of class (model, behavior, controller, component, view, helper).\n". - "\t\tAvailable values:\n\n". - "\t\tbehavior\tLook for class in CakePHP behavior path\n". - "\t\tcache\tLook for class in CakePHP cache path\n". - "\t\tcontroller\tLook for class in CakePHP controller path\n". - "\t\tcomponent\tLook for class in CakePHP component path\n". - "\t\thelper\tLook for class in CakePHP helper path\n". - "\t\tmodel\tLook for class in CakePHP model path\n". - "\t\tview\tLook for class in CakePHP view path\n", + "\t\tEither a full path or type of class (model, behavior, controller, component, view, helper).\n". + "\t\tAvailable values:\n\n". + "\t\tbehavior\tLook for class in CakePHP behavior path\n". + "\t\tcache\tLook for class in CakePHP cache path\n". + "\t\tcontroller\tLook for class in CakePHP controller path\n". + "\t\tcomponent\tLook for class in CakePHP component path\n". + "\t\thelper\tLook for class in CakePHP helper path\n". + "\t\tmodel\tLook for class in CakePHP model path\n". + "\t\tview\tLook for class in CakePHP view path\n", 'className' => "\t\n" . - "\t\tA CakePHP core class name (e.g: Component, HtmlHelper).\n" + "\t\tA CakePHP core class name (e.g: Component, HtmlHelper).\n" ); $this->out($head); @@ -196,16 +196,16 @@ class ApiShell extends Shell { $contents = $File->read(); - if (preg_match_all('%(/\\*\\*[\\s\\S]*?\\*/)(\\s+function\\s+\\w+)(\\(.+\\))%', $contents, $result, PREG_PATTERN_ORDER)) { + if (preg_match_all('%(/\\*\\*[\\s\\S]*?\\*/)(\\s+function\\s+\\w+)(\\(.*\\))%', $contents, $result, PREG_PATTERN_ORDER)) { foreach ($result[2] as $key => $method) { $method = str_replace('function ', '', trim($method)); if (strpos($method, '__') === false && $method[0] != '_') { $parsed[$method] = array( - 'comment' => r(array('/*', '*/', '*'), '', trim($result[1][$key])), - 'method' => $method, - 'parameters' => trim($result[3][$key]), - ); + 'comment' => r(array('/*', '*/', '*'), '', trim($result[1][$key])), + 'method' => $method, + 'parameters' => trim($result[3][$key]) + ); } } } diff --git a/cake/tests/cases/console/libs/api.test.php b/cake/tests/cases/console/libs/api.test.php new file mode 100644 index 000000000..80a83f586 --- /dev/null +++ b/cake/tests/cases/console/libs/api.test.php @@ -0,0 +1,118 @@ +Dispatcher =& new ApiShellMockShellDispatcher(); + $this->Shell =& new MockApiShell($this->Dispatcher); + $this->Shell->Dispatch = new $this->Dispatcher; + } +/** + * tearDown method + * + * @return void + * @access public + */ + function endTest() { + ClassRegistry::flush(); + } +/** + * Test that method names are detected properly including those with no arguments. + * + * @access public + * @return void + */ + function testMethodNameDetection () { + $this->Shell->setReturnValueAt(0, 'in', 'q'); + $this->Shell->expectAt(0, 'out', array('Controller')); + $expected = array( + array( + '1. afterFilter()', + '2. beforeFilter()', + '3. beforeRender()', + '4. constructClasses()', + '5. disableCache()', + '6. flash($message, $url, $pause = 1)', + '7. header($status)', + '8. isAuthorized()', + '9. loadModel($modelClass = null, $id = null)', + '10. paginate($object = null, $scope = array(), $whitelist = array())', + '11. postConditions($data = array(), $op = null, $bool = \'AND\', $exclusive = false)', + '12. redirect($url, $status = null, $exit = true)', + '13. referer($default = null, $local = false)', + '14. render($action = null, $layout = null, $file = null)', + '15. set($one, $two = null)', + '16. setAction($action)', + '17. validate()', + '18. validateErrors()' + )A + ); + $this->Shell->expectAt(1, 'out', $expected); + + $this->Shell->args = array('controller'); + $this->Shell->paths['controller'] = CAKE_CORE_INCLUDE_PATH . DS . LIBS . 'controller' . DS; + $this->Shell->main(); + } +} +?> \ No newline at end of file From 6a34c9ef3152b442dc2d24babcbfefeb1eb8dc51 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 27 Jun 2009 15:25:07 +0000 Subject: [PATCH 17/95] Fixing Model::saveAll() PHP4 compatibility. Minor API change in __save(). __save() no longer takes a model instance as the first parameter. Because of Model implementation details in PHP4 this caused broken references. Fixes #6389, #6223 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8204 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/model.php | 14 +++++++------- cake/tests/cases/libs/model/models.php | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index c18d035e0..102041086 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1475,7 +1475,7 @@ class Model extends Overloadable { if (Set::numeric(array_keys($data))) { while ($validates) { foreach ($data as $key => $record) { - if (!$currentValidates = $this->__save($this, $record, $options)) { + if (!$currentValidates = $this->__save($record, $options)) { $validationErrors[$key] = $this->validationErrors; } @@ -1528,7 +1528,7 @@ class Model extends Overloadable { if (isset($associations[$association])) { switch ($associations[$association]) { case 'belongsTo': - if ($this->__save($this->{$association}, $values, $options)) { + if ($this->{$association}->__save($values, $options)) { $data[$this->alias][$this->belongsTo[$association]['foreignKey']] = $this->{$association}->id; } else { $validationErrors[$association] = $this->{$association}->validationErrors; @@ -1541,7 +1541,7 @@ class Model extends Overloadable { } } } - if (!$this->__save($this, $data, $options)) { + if (!$this->__save($data, $options)) { $validationErrors[$this->alias] = $this->validationErrors; $validates = false; } @@ -1559,7 +1559,7 @@ class Model extends Overloadable { switch ($type) { case 'hasOne': $values[$this->{$type}[$association]['foreignKey']] = $this->id; - if (!$this->__save($this->{$association}, $values, $options)) { + if (!$this->{$association}->__save($values, $options)) { $validationErrors[$association] = $this->{$association}->validationErrors; $validates = false; } @@ -1632,12 +1632,12 @@ class Model extends Overloadable { * @access private * @see Model::saveAll() */ - function __save(&$model, $data, $options) { + function __save($data, $options) { if ($options['validate'] === 'first' || $options['validate'] === 'only') { - if (!($model->create($data) && $model->validates($options))) { + if (!($this->create($data) && $this->validates($options))) { return false; } - } elseif (!($model->create(null) !== null && $model->save($data, $options))) { + } elseif (!($this->create(null) !== null && $this->save($data, $options))) { return false; } return true; diff --git a/cake/tests/cases/libs/model/models.php b/cake/tests/cases/libs/model/models.php index 620d2c71b..20e5b6ba1 100644 --- a/cake/tests/cases/libs/model/models.php +++ b/cake/tests/cases/libs/model/models.php @@ -1864,6 +1864,7 @@ class ValidationTest1 extends CakeTestModel { */ function customValidatorWithParams($data, $validator, $or = true, $ignore_on_same = 'id') { $this->validatorParams = get_defined_vars(); + unset($this->validatorParams['this']); return true; } /** From 8c7883fe3efa87941b239e377b59933299e641a7 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 30 Jun 2009 00:25:09 +0000 Subject: [PATCH 18/95] Fixing camel cased methods in checks for allowedActions in AuthComponent under PHP5. Normalizes to lowercase method name. Fixes #6142 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8205 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/components/auth.php | 6 +++-- .../libs/controller/components/auth.test.php | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index a638fd567..15991d4eb 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -263,6 +263,8 @@ class AuthComponent extends Object { */ function startup(&$controller) { $methods = array_flip($controller->methods); + $controllerAction = strtolower($controller->params['action']); + $isErrorOrTests = ( strtolower($controller->name) == 'cakeerror' || (strtolower($controller->name) == 'tests' && Configure::read() > 0) @@ -273,7 +275,7 @@ class AuthComponent extends Object { $isMissingAction = ( $controller->scaffold === false && - !isset($methods[strtolower($controller->params['action'])]) + !isset($methods[$controllerAction]) ); if ($isMissingAction) { @@ -295,7 +297,7 @@ class AuthComponent extends Object { $isAllowed = ( $this->allowedActions == array('*') || - in_array($controller->params['action'], $this->allowedActions) + isset($methods[$controllerAction]) ); if ($loginAction != $url && $isAllowed) { diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index 00bf8a9c6..b8cbf0b13 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -728,7 +728,32 @@ class AuthTest extends CakeTestCase { $this->Controller->params['action'] = 'Add'; $this->assertFalse($this->Controller->Auth->startup($this->Controller)); } +/** + * test that allow() and allowedActions work with camelCase method names. + * + * @return void + **/ + function testAllowedActionsWithCamelCaseMethods() { + $url = '/auth_test/camelCase'; + $this->Controller->params = Router::parse($url); + $this->Controller->params['url']['url'] = Router::normalize($url); + $this->Controller->Auth->initialize($this->Controller); + $this->Controller->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login'); + $this->Controller->Auth->userModel = 'AuthUser'; + $this->Controller->Auth->allow('*'); + $result = $this->Controller->Auth->startup($this->Controller); + $this->assertTrue($result, 'startup() should return true, as action is allowed. %s'); + $url = '/auth_test/camelCase'; + $this->Controller->params = Router::parse($url); + $this->Controller->params['url']['url'] = Router::normalize($url); + $this->Controller->Auth->initialize($this->Controller); + $this->Controller->Auth->loginAction = array('controller' => 'AuthTest', 'action' => 'login'); + $this->Controller->Auth->userModel = 'AuthUser'; + $this->Controller->Auth->allowedActions = array('delete', 'camelCase', 'add'); + $result = $this->Controller->Auth->startup($this->Controller); + $this->assertTrue($result, 'startup() should return true, as action is allowed. %s'); + } /** * testLoginRedirect method * From fd7cf5e5e601b17bedf7e74b30905cd286fa3671 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 30 Jun 2009 01:14:20 +0000 Subject: [PATCH 19/95] Adding test cases for boolean and boolean-ish values. Fixes false being converted to '' when using Xml::toString(). Fixes #6478 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8206 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/xml.php | 3 +++ cake/tests/cases/libs/xml.test.php | 32 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/cake/libs/xml.php b/cake/libs/xml.php index 845068514..509d916b0 100644 --- a/cake/libs/xml.php +++ b/cake/libs/xml.php @@ -607,6 +607,9 @@ class XmlNode extends Object { if (is_array($this->attributes) && count($this->attributes) > 0) { foreach ($this->attributes as $key => $val) { + if (is_bool($val) && $val === false) { + $val = 0; + } $d .= ' ' . $key . '="' . htmlspecialchars($val, ENT_QUOTES, Configure::read('App.encoding')) . '"'; } } diff --git a/cake/tests/cases/libs/xml.test.php b/cake/tests/cases/libs/xml.test.php index eec558641..9cbf5e87b 100644 --- a/cake/tests/cases/libs/xml.test.php +++ b/cake/tests/cases/libs/xml.test.php @@ -97,6 +97,38 @@ class XmlTest extends CakeTestCase { $result = preg_replace("/\n/",'', $xml->toString(false)); $this->assertEqual($result, $expected); } + +/** + * test serialization of boolean and null values. false = 0, true = 1, null = '' + * + * @return void + **/ + function testSerializationOfBooleanAndBooleanishValues() { + $xml =& new Xml(array('data' => array('example' => false))); + $result = $xml->toString(false); + $expected = ''; + $this->assertEqual($result, $expected, 'Boolean values incorrectly handled. %s'); + + $xml =& new Xml(array('data' => array('example' => true))); + $result = $xml->toString(false); + $expected = ''; + $this->assertEqual($result, $expected, 'Boolean values incorrectly handled. %s'); + + $xml =& new Xml(array('data' => array('example' => null))); + $result = $xml->toString(false); + $expected = ''; + $this->assertEqual($result, $expected, 'Boolean values incorrectly handled. %s'); + + $xml =& new Xml(array('data' => array('example' => 0))); + $result = $xml->toString(false); + $expected = ''; + $this->assertEqual($result, $expected, 'Boolean-ish values incorrectly handled. %s'); + + $xml =& new Xml(array('data' => array('example' => 1))); + $result = $xml->toString(false); + $expected = ''; + $this->assertEqual($result, $expected, 'Boolean-ish values incorrectly handled. %s'); + } /** * testSimpleArray method * From fb6b2aecde4ed596d7dec47dfcebb4bc64169f45 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 30 Jun 2009 01:37:33 +0000 Subject: [PATCH 20/95] Renaming {{{SimpleTestOptions::ignore()}}} to {{{SimpleTest::ignore()}}} Refs #6425 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8207 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/tests/lib/cake_web_test_case.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/cake/tests/lib/cake_web_test_case.php b/cake/tests/lib/cake_web_test_case.php index c9760d1b9..b12f2e426 100644 --- a/cake/tests/lib/cake_web_test_case.php +++ b/cake/tests/lib/cake_web_test_case.php @@ -1,9 +1,7 @@ Date: Wed, 1 Jul 2009 03:56:16 +0000 Subject: [PATCH 21/95] Fixing issues created in [8205] where allowedActions check was done incorrectly. Fixes #6482 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8208 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/components/auth.php | 3 ++- cake/tests/cases/libs/controller/components/auth.test.php | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index 15991d4eb..a76c877ad 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -264,6 +264,7 @@ class AuthComponent extends Object { function startup(&$controller) { $methods = array_flip($controller->methods); $controllerAction = strtolower($controller->params['action']); + $lowerAllowedActions = array_map('strtolower', $this->allowedActions); $isErrorOrTests = ( strtolower($controller->name) == 'cakeerror' || @@ -297,7 +298,7 @@ class AuthComponent extends Object { $isAllowed = ( $this->allowedActions == array('*') || - isset($methods[$controllerAction]) + in_array($controllerAction, $lowerAllowedActions) ); if ($loginAction != $url && $isAllowed) { diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index b8cbf0b13..481b2dd5f 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -753,6 +753,10 @@ class AuthTest extends CakeTestCase { $this->Controller->Auth->allowedActions = array('delete', 'camelCase', 'add'); $result = $this->Controller->Auth->startup($this->Controller); $this->assertTrue($result, 'startup() should return true, as action is allowed. %s'); + + $this->Controller->Auth->allowedActions = array('delete', 'add'); + $result = $this->Controller->Auth->startup($this->Controller); + $this->assertFalse($result, 'startup() should return false, as action is not allowed. %s'); } /** * testLoginRedirect method From 975e4452d2934168a9140b8744325cf265185316 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 1 Jul 2009 18:58:05 +0000 Subject: [PATCH 22/95] Fixing Xml parsing where multiple child elements of the same name, with no value are collapsed causing data errors when Xml object was converted to an array. Test cases from 'burzum' added. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8209 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/xml.php | 13 +++++++ cake/tests/cases/libs/xml.test.php | 61 ++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/cake/libs/xml.php b/cake/libs/xml.php index 509d916b0..3c79eb630 100644 --- a/cake/libs/xml.php +++ b/cake/libs/xml.php @@ -685,6 +685,19 @@ class XmlNode extends Object { $out[$child->name] = $value; } continue; + } elseif (count($child->children) === 0 && $child->value == '') { + $value = $child->attributes; + + if (isset($out[$child->name]) || isset($multi[$key])) { + if (!isset($multi[$key])) { + $multi[$key] = array($out[$child->name]); + unset($out[$child->name]); + } + $multi[$key][] = $value; + } else { + $out[$key] = $value; + } + continue; } else { $value = $child->toArray($camelize); } diff --git a/cake/tests/cases/libs/xml.test.php b/cake/tests/cases/libs/xml.test.php index 9cbf5e87b..386a9d94b 100644 --- a/cake/tests/cases/libs/xml.test.php +++ b/cake/tests/cases/libs/xml.test.php @@ -679,6 +679,67 @@ class XmlTest extends CakeTestCase { $result = $xml->toString(); $this->assertEqual($source, $result); } +/** + * test that elements with empty tag values do not collapse and corrupt data structures + * + * @access public + * @return void + **/ + function testElementCollapsing() { + $xmlDataThatFails = ' + + + + + + + + + + '; + + $Xml = new Xml(); + $Xml->load('' . $xmlDataThatFails); + $result = $Xml->toArray(false); + + $this->assertTrue(is_array($result)); + $expected = array( + 'resultpackage' => array( + 'result' => array( + 0 => array( + 'value' => '46b1c46ed3af9', + 'qid' => '46b1c46ed6208'), + 1 => array( + 'qid' => '46b1c46ed332a'), + 2 => array( + 'value' => '46b1c46ed69d8', + 'qid' => '46b1c46ed90e6'), + 3 => array( + 'value' => '46b1c46ed5a38', + 'qid' => '46b1c46ed71a7'), + 4 => array( + 'value' => '46b1c46ed98b6', + 'qid' => '46b1c46ed8146'), + 5 => array( + 'qid' => '46b1c46ed7978'), + 6 => array( + 'qid' => '46b1c46ed4a98'), + 7 => array( + 'qid' => '46b1c46ed42c8'), + 8 => array( + 'value' => '46b1c46ed8917', + 'qid' => '46b1c46ed5268'), + ) + )); + $this->assertEqual( + count($result['resultpackage']['result']), count($expected['resultpackage']['result']), + 'Incorrect array length %s'); + + $this->assertFalse( + isset($result['resultpackage']['result'][0][0]['qid']), 'Nested array exists, data is corrupt. %s'); + + $this->assertEqual($result, $expected); + } /** * testMixedParsing method * From c30dd48e2a55d3460826cfad40cc14c2b3909c65 Mon Sep 17 00:00:00 2001 From: jperras Date: Wed, 1 Jul 2009 22:25:22 +0000 Subject: [PATCH 23/95] Updating doc block for Set::combine first parameter - may accept an object as first param, in addition to arrays. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8210 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/set.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cake/libs/set.php b/cake/libs/set.php index bed03379a..d48adc7de 100644 --- a/cake/libs/set.php +++ b/cake/libs/set.php @@ -918,7 +918,7 @@ class Set extends Object { * to null (useful for Set::merge). You can optionally group the values by what is obtained when * following the path specified in $groupPath. * - * @param array $data Array from where to extract keys and values + * @param mixed $data Array or object from where to extract keys and values * @param mixed $path1 As an array, or as a dot-separated string. * @param mixed $path2 As an array, or as a dot-separated string. * @param string $groupPath As an array, or as a dot-separated string. From a6d3193a6dcff4450b1555c89405bdcc3575576a Mon Sep 17 00:00:00 2001 From: jperras Date: Thu, 2 Jul 2009 02:58:43 +0000 Subject: [PATCH 24/95] Updated EmailComponent::__strip regex for mailto: links. Fixes #6464. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8211 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/components/email.php | 4 +++- .../libs/controller/components/email.test.php | 23 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php index 7fb016d00..30daf1669 100644 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -632,7 +632,9 @@ class EmailComponent extends Object{ * @access private */ function __strip($value, $message = false) { - $search = '%0a|%0d|Content-(?:Type|Transfer-Encoding)\:|charset\=|mime-version\:|multipart/mixed|(?:to|b?cc)\:.*'; + $search = '%0a|%0d|Content-(?:Type|Transfer-Encoding)\:'; + $search .= '|charset\=|mime-version\:|multipart/mixed|(?:[^a-z]to|b?cc)\:.*'; + if ($message !== true) { $search .= '|\r|\n'; } diff --git a/cake/tests/cases/libs/controller/components/email.test.php b/cake/tests/cases/libs/controller/components/email.test.php index 08f033aac..318ce6b5f 100644 --- a/cake/tests/cases/libs/controller/components/email.test.php +++ b/cake/tests/cases/libs/controller/components/email.test.php @@ -104,6 +104,15 @@ class EmailTestComponent extends EmailComponent { function getMessage() { return $this->__message; } +/** + * Convenience method for testing. + * + * @access public + * @return string + */ + function strip($content, $message = false) { + return parent::__strip($content, $message); + } } /** * EmailTestController class @@ -499,9 +508,21 @@ TEXTBLOC; $content = "Previous content\n--alt-\nContent-TypeContent-Type:: text/html; charsetcharset==utf-8\nContent-Transfer-Encoding: 7bit"; $content .= "\n\n

My own html content

"; - $result = $this->Controller->EmailTest->__strip($content, true); + $result = $this->Controller->EmailTest->strip($content, true); $expected = "Previous content\n--alt-\n text/html; utf-8\n 7bit\n\n

My own html content

"; $this->assertEqual($result, $expected); + + $content = '

Some HTML content with an email link'; + $result = $this->Controller->EmailTest->strip($content, true); + $expected = $content; + $this->assertEqual($result, $expected); + + $content = '

Some HTML content with an '; + $content .= 'email link'; + $result = $this->Controller->EmailTest->strip($content, true); + $expected = $content; + $this->assertEqual($result, $expected); + } /** * testMultibyte method From 92b8e87ed720a0b37d2c98c0cfe35ca0ecc2a752 Mon Sep 17 00:00:00 2001 From: gwoo Date: Thu, 2 Jul 2009 23:14:38 +0000 Subject: [PATCH 25/95] fix for cross database joins when recursive < 1 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8212 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/datasources/dbo_source.php | 30 +++++++++++++--------- cake/tests/cases/libs/model/model.test.php | 9 +++++++ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index f2aa64ebc..1aa56f73d 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -627,16 +627,22 @@ class DboSource extends DataSource { $queryData['fields'] = $this->fields($model); } - foreach ($model->__associations as $type) { - foreach ($model->{$type} as $assoc => $assocData) { - if ($model->recursive > -1) { - $linkModel =& $model->{$assoc}; - $external = isset($assocData['external']); + $_associations = $model->__associations; - if ($model->useDbConfig == $linkModel->useDbConfig) { - if (true === $this->generateAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null)) { - $linkedModels[] = $type . '/' . $assoc; - } + if ($model->recursive == -1) { + $_associations = array(); + } else if ($model->recursive == 0) { + unset($_associations[2], $_associations[3]); + } + + foreach ($_associations as $type) { + foreach ($model->{$type} as $assoc => $assocData) { + $linkModel =& $model->{$assoc}; + $external = isset($assocData['external']); + + if ($model->useDbConfig == $linkModel->useDbConfig) { + if (true === $this->generateAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null)) { + $linkedModels[$type . '/' . $assoc] = true; } } } @@ -653,12 +659,12 @@ class DboSource extends DataSource { $filtered = $this->__filterResults($resultSet, $model); - if ($model->recursive > 0) { - foreach ($model->__associations as $type) { + if ($model->recursive > -1) { + foreach ($_associations as $type) { foreach ($model->{$type} as $assoc => $assocData) { $linkModel =& $model->{$assoc}; - if (!in_array($type . '/' . $assoc, $linkedModels)) { + if (empty($linkedModels[$type . '/' . $assoc])) { if ($model->useDbConfig == $linkModel->useDbConfig) { $db =& $this; } else { diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index a4b75847b..c8e84769f 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -12082,6 +12082,15 @@ class ModelTest extends CakeTestCase { $TestModel->User->setDataSource('test2'); $TestModel->Comment->setDataSource('test2'); + foreach ($expected as $key => $value) { + unset($value['Comment'], $value['Tag']); + $expected[$key] = $value; + } + + $TestModel->recursive = 0; + $result = $TestModel->find('all'); + $this->assertEqual($result, $expected); + $result = Set::extract($TestModel->User->find('all'), '{n}.User.id'); $this->assertEqual($result, array('1', '2', '3', '4')); $this->assertEqual($TestModel->find('all'), $expected); From 9e143bc3351d4cf03328e7446bdd9bfa8d517ef4 Mon Sep 17 00:00:00 2001 From: gwoo Date: Thu, 2 Jul 2009 23:48:10 +0000 Subject: [PATCH 26/95] fixes #6473, dot notation for sort in next/prev git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8213 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/helpers/paginator.php | 13 ++++---- .../libs/view/helpers/paginator.test.php | 30 ++++++++++++++++++- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php index f5e197a05..8dd83a144 100644 --- a/cake/libs/view/helpers/paginator.php +++ b/cake/libs/view/helpers/paginator.php @@ -140,7 +140,9 @@ class PaginatorHelper extends AppHelper { if (isset($options['sort']) && !empty($options['sort'])) { if (preg_match('/(?:\w+\.)?(\w+)/', $options['sort'], $result) && isset($result[1])) { - return $result[1]; + if ($result[0] == $this->defaultModel()) { + return $result[1]; + } } return $options['sort']; } elseif (isset($options['order']) && is_array($options['order'])) { @@ -149,6 +151,7 @@ class PaginatorHelper extends AppHelper { if (preg_match('/(?:\w+\.)?(\w+)/', $options['order'], $result) && isset($result[1])) { return $result[1]; } + return $options['order']; } return null; } @@ -223,13 +226,7 @@ class PaginatorHelper extends AppHelper { } $dir = 'asc'; $sortKey = $this->sortKey($options['model']); - $defaultModel = $this->defaultModel(); - - if (strpos($sortKey, $defaultModel) !== false && strpos($key, $defaultModel) === false) { - $isSorted = ($sortKey === $defaultModel . '.' . $key); - } else { - $isSorted = ($sortKey === $key); - } + $isSorted = ($sortKey === $key); if ($isSorted && $this->sortDir($options['model']) === 'asc') { $dir = 'desc'; diff --git a/cake/tests/cases/libs/view/helpers/paginator.test.php b/cake/tests/cases/libs/view/helpers/paginator.test.php index 6939f00b5..69095f1d8 100644 --- a/cake/tests/cases/libs/view/helpers/paginator.test.php +++ b/cake/tests/cases/libs/view/helpers/paginator.test.php @@ -911,5 +911,33 @@ class PaginatorHelperTest extends CakeTestCase { $result = $this->Paginator->link('Page 3', array('page' => 3)); $this->assertPattern('/["\']\/issues\/index\/page:3["\']/', $result); } + +/** + * testNextLinkUsingDotNotation method + * + * @access public + * @return void + */ + function testNextLinkUsingDotNotation() { + Router::reload(); + Router::parse('/'); + Router::setRequestInfo(array( + array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true'), 'bare' => 0), + array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/', 'passedArgs' => array()) + )); + + $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc'); + $this->Paginator->params['paging']['Article']['page'] = 1; + + $test = array('url'=> array( + 'page'=> '1', + 'sort'=>'Article.title', + 'direction'=>'asc', + )); + $this->Paginator->options($test); + + $result = $this->Paginator->next('Next'); + $this->assertPattern('/\/accounts\/index\/page:2\/sort:Article.title\/direction:asc">Next<\/a>$/', $result); + } } -?> +?> \ No newline at end of file From 8971aad8bf87528dec994b627e0cb57de59ad6f7 Mon Sep 17 00:00:00 2001 From: gwoo Date: Fri, 3 Jul 2009 00:14:36 +0000 Subject: [PATCH 27/95] closes #6413, scaffoldFields not working with add/edit methods git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8214 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/scaffolds/edit.ctp | 2 +- .../cases/libs/controller/scaffold.test.php | 63 +++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/cake/libs/view/scaffolds/edit.ctp b/cake/libs/view/scaffolds/edit.ctp index b9ea9a24d..fd537d239 100644 --- a/cake/libs/view/scaffolds/edit.ctp +++ b/cake/libs/view/scaffolds/edit.ctp @@ -25,7 +25,7 @@

create(); - echo $form->inputs(null, array('created', 'modified', 'updated')); + echo $form->inputs($scaffoldFields, array('created', 'modified', 'updated')); echo $form->end(__('Submit', true)); ?>
diff --git a/cake/tests/cases/libs/controller/scaffold.test.php b/cake/tests/cases/libs/controller/scaffold.test.php index 78dca4ee3..d0813a419 100644 --- a/cake/tests/cases/libs/controller/scaffold.test.php +++ b/cake/tests/cases/libs/controller/scaffold.test.php @@ -47,6 +47,37 @@ class ScaffoldMockController extends Controller { */ var $scaffold; } +/** + * ScaffoldMockControllerWithFields class + * + * @package cake + * @subpackage cake.tests.cases.libs.controller + */ +class ScaffoldMockControllerWithFields extends Controller { +/** + * name property + * + * @var string 'ScaffoldMock' + * @access public + */ + var $name = 'ScaffoldMock'; +/** + * scaffold property + * + * @var mixed + * @access public + */ + var $scaffold; +/** + * function _beforeScaffold + * + * @param string method + */ + function _beforeScaffold($method) { + $this->set('scaffoldFields', array('title')); + return true; + } +} /** * TestScaffoldMock class * @@ -619,5 +650,37 @@ class ScaffoldTest extends CakeTestCase { $this->assertEqual($result['pluralVar'], 'scaffoldMock'); $this->assertEqual($result['scaffoldFields'], array('id', 'user_id', 'title', 'body', 'published', 'created', 'updated')); } +/** + * test that the proper names and variable values are set by Scaffold + * + * @return void + **/ + function testEditScaffoldWithScaffoldFields() { + $this->Controller = new ScaffoldMockControllerWithFields(); + $this->Controller->action = 'edit'; + $this->Controller->here = '/scaffold_mock'; + $this->Controller->webroot = '/'; + $params = array( + 'plugin' => null, + 'pass' => array(1), + 'form' => array(), + 'named' => array(), + 'url' => array('url' =>'scaffold_mock'), + 'controller' => 'scaffold_mock', + 'action' => 'edit', + ); + //set router. + Router::reload(); + Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/scaffold_mock', 'webroot' => '/'))); + $this->Controller->params = $params; + $this->Controller->controller = 'scaffold_mock'; + $this->Controller->base = '/'; + $this->Controller->constructClasses(); + ob_start(); + new Scaffold($this->Controller, $params); + $result = ob_get_clean(); + + $this->assertNoPattern('/textarea name="data\[ScaffoldMock\]\[body\]" cols="30" rows="6" id="ScaffoldMockBody"/', $result); + } } ?> \ No newline at end of file From f79a68b2a60bdec3e86c17b1c8f769bcc1a5b843 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 3 Jul 2009 00:20:54 +0000 Subject: [PATCH 28/95] Minor refactor of variable names. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8215 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/components/auth.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index a76c877ad..a68e5b6f2 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -263,8 +263,8 @@ class AuthComponent extends Object { */ function startup(&$controller) { $methods = array_flip($controller->methods); - $controllerAction = strtolower($controller->params['action']); - $lowerAllowedActions = array_map('strtolower', $this->allowedActions); + $action = strtolower($controller->params['action']); + $allowedActions = array_map('strtolower', $this->allowedActions); $isErrorOrTests = ( strtolower($controller->name) == 'cakeerror' || @@ -276,7 +276,7 @@ class AuthComponent extends Object { $isMissingAction = ( $controller->scaffold === false && - !isset($methods[$controllerAction]) + !isset($methods[$action]) ); if ($isMissingAction) { @@ -298,7 +298,7 @@ class AuthComponent extends Object { $isAllowed = ( $this->allowedActions == array('*') || - in_array($controllerAction, $lowerAllowedActions) + in_array($action, $allowedActions) ); if ($loginAction != $url && $isAllowed) { From 45a51ed80930144865fa97c27302eb4db0b738b9 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 3 Jul 2009 00:26:58 +0000 Subject: [PATCH 29/95] Changing return of Model::deleteAll(). When no records are matched by the delete conditions return is now (bool)true as no records matching those conditions exist. Test case added. Fixes #6453 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8216 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/model.php | 2 +- cake/tests/cases/libs/model/model.test.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 102041086..fbf2e360b 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1811,7 +1811,7 @@ class Model extends Overloadable { ); if (empty($ids)) { - return false; + return true; } if ($callbacks) { diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index c8e84769f..72e1d381c 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -7487,6 +7487,9 @@ class ModelTest extends CakeTestCase { 'published' => 'Y' ))); $this->assertEqual($result, $expected); + + $result = $TestModel->deleteAll(array('Article.user_id' => 999)); + $this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s'); } /** * testRecursiveDel method From f2b7a26be8d125fc46fb4f816ae3b0fd5e6e53bf Mon Sep 17 00:00:00 2001 From: gwoo Date: Fri, 3 Jul 2009 03:31:05 +0000 Subject: [PATCH 30/95] fixes #5710, HABTM - constraining unique ids, but removing non-unique git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8217 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/datasources/dbo_source.php | 5 +-- cake/tests/cases/libs/model/model.test.php | 37 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 1aa56f73d..1ad21c115 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -858,11 +858,8 @@ class DboSource extends DataSource { foreach ($fetch as $j => $data) { if ( - (isset($data[$with]) && $data[$with][$foreignKey] === $row[$model->alias][$model->primaryKey]) && - (!in_array($data[$with][$joinKeys[1]], $uniqueIds)) + (isset($data[$with]) && $data[$with][$foreignKey] === $row[$model->alias][$model->primaryKey]) ) { - $uniqueIds[] = $data[$with][$joinKeys[1]]; - if ($habtmFieldsCount <= 2) { unset($data[$with]); } diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 72e1d381c..01f5159dd 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -13022,5 +13022,42 @@ class ModelTest extends CakeTestCase { $TestModel2 =& new ArticleB(); $this->assertEqual($TestModel2->ArticlesTag->primaryKey, 'article_id'); } +/** + * testFetchingNonUniqueFKJoinTableRecords() + * + * Tests if the results are properly returned in the case there are non-unique FK's + * in the join table but another fields value is different. For example: + * something_id | something_else_id | doomed = 1 + * something_id | something_else_id | doomed = 0 + * Should return both records and not just one. + * + * @access public + * @return void + */ + function testFetchingNonUniqueFKJoinTableRecords() { + $this->loadFixtures('Something', 'SomethingElse', 'JoinThing'); + $Something = new Something(); + + $joinThingData = array( + 'JoinThing' => array( + 'something_id' => 1, + 'something_else_id' => 2, + 'doomed' => '0', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ) + ); + $Something->JoinThing->create($joinThingData); + $Something->JoinThing->save(); + + $result = $Something->JoinThing->find('all', array('conditions' => array('something_else_id' => 2))); + $this->assertEqual($result[0]['JoinThing']['doomed'], 1); + $this->assertEqual($result[1]['JoinThing']['doomed'], 0); + + $result = $Something->find('first'); + $this->assertEqual(count($result['SomethingElse']), 2); + $this->assertEqual($result['SomethingElse'][0]['JoinThing']['doomed'], 1); + $this->assertEqual($result['SomethingElse'][1]['JoinThing']['doomed'], 0); + } } ?> \ No newline at end of file From 7818eae206143db5948068a610d678333e099136 Mon Sep 17 00:00:00 2001 From: gwoo Date: Fri, 3 Jul 2009 15:54:26 +0000 Subject: [PATCH 31/95] fixes #6455, i18n locale message category bug git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8218 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/basics.php | 22 ++--- cake/libs/i18n.php | 10 +- cake/tests/cases/libs/i18n.test.php | 95 ++++++++++++++++++- .../test_app/locale/po/LC_MONETARY/default.po | 18 ++++ .../locale/po/LC_MONETARY/test_plugin.po | 22 +++++ 5 files changed, 147 insertions(+), 20 deletions(-) create mode 100644 cake/tests/test_app/locale/po/LC_MONETARY/default.po create mode 100644 cake/tests/test_app/plugins/test_plugin/locale/po/LC_MONETARY/test_plugin.po diff --git a/cake/basics.php b/cake/basics.php index cae6e65bd..bb3f22cb1 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -624,9 +624,9 @@ if (!function_exists('file_put_contents')) { } if ($return === false) { - echo I18n::translate($singular, $plural, null, 5, $count); + echo I18n::translate($singular, $plural, null, LC_MESSAGES, $count); } else { - return I18n::translate($singular, $plural, null, 5, $count); + return I18n::translate($singular, $plural, null, LC_MESSAGES, $count); } } /** @@ -672,9 +672,9 @@ if (!function_exists('file_put_contents')) { } if ($return === false) { - echo I18n::translate($singular, $plural, $domain, 5, $count); + echo I18n::translate($singular, $plural, $domain, LC_MESSAGES, $count); } else { - return I18n::translate($singular, $plural, $domain, 5, $count); + return I18n::translate($singular, $plural, $domain, LC_MESSAGES, $count); } } /** @@ -723,13 +723,13 @@ if (!function_exists('file_put_contents')) { * Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL. * * Note that the category must be specified with a numeric value, instead of the constant name. The values are: - * LC_CTYPE 0 - * LC_NUMERIC 1 - * LC_TIME 2 - * LC_COLLATE 3 - * LC_MONETARY 4 - * LC_MESSAGES 5 - * LC_ALL 6 + * LC_ALL 0 + * LC_COLLATE 1 + * LC_CTYPE 2 + * LC_MONETARY 3 + * LC_NUMERIC 4 + * LC_TIME 5 + * LC_MESSAGES 6 * * @param string $domain Domain * @param string $singular Singular string to translate diff --git a/cake/libs/i18n.php b/cake/libs/i18n.php index 850ac5782..d987842b0 100644 --- a/cake/libs/i18n.php +++ b/cake/libs/i18n.php @@ -62,7 +62,7 @@ class I18n extends Object { * Current language used for translations * * @var string - * @access private; + * @access private */ var $__lang = null; /** @@ -94,7 +94,9 @@ class I18n extends Object { * @var array * @access private */ - var $__categories = array('LC_CTYPE', 'LC_NUMERIC', 'LC_TIME', 'LC_COLLATE', 'LC_MONETARY', 'LC_MESSAGES', 'LC_ALL'); + var $__categories = array( + 'LC_ALL', 'LC_COLLATE', 'LC_CTYPE', 'LC_MONETARY', 'LC_NUMERIC', 'LC_TIME', 'LC_MESSAGES' + ); /** * Return a static instance of the I18n class * @@ -111,7 +113,7 @@ class I18n extends Object { } /** * Used by the translation functions in basics.php - * Can also be used like I18n::translate(); but only if the uses('i18n'); has been used to load the class. + * Can also be used like I18n::translate(); but only if the App::import('I18n'); has been used to load the class. * * @param string $singular String to translate * @param string $plural Plural string (if any) @@ -121,7 +123,7 @@ class I18n extends Object { * @return string translated strings. * @access public */ - function translate($singular, $plural = null, $domain = null, $category = null, $count = null) { + function translate($singular, $plural = null, $domain = null, $category = LC_MESSAGES, $count = null) { $_this =& I18n::getInstance(); if (strpos($singular, "\r\n") !== false) { diff --git a/cake/tests/cases/libs/i18n.test.php b/cake/tests/cases/libs/i18n.test.php index 4a1183036..e570bc6f5 100644 --- a/cake/tests/cases/libs/i18n.test.php +++ b/cake/tests/cases/libs/i18n.test.php @@ -39,8 +39,15 @@ class I18nTest extends CakeTestCase { * @return void */ function setUp() { + $this->_objects = Configure::read('__objects'); + Configure::write('__objects', array()); + $this->_localePaths = Configure::read('localePaths'); Configure::write('localePaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'locale')); + + $this->_pluginPaths = Configure::read('pluginPaths'); + Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins')); + } /** * tearDown method @@ -50,6 +57,9 @@ class I18nTest extends CakeTestCase { */ function tearDown() { Configure::write('localePaths', $this->_localePaths); + Configure::write('pluginPaths', $this->_pluginPaths); + Configure::write('__objects', $this->_objects); + } /** * testDefaultStrings method @@ -2353,9 +2363,6 @@ class I18nTest extends CakeTestCase { * @return void */ function testPluginTranslation() { - $pluginPaths = Configure::read('pluginPaths'); - Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins')); - Configure::write('Config.language', 'po'); $singular = $this->__domainSingular(); $this->assertEqual('Plural Rule 1 (from plugin)', $singular); @@ -2387,8 +2394,6 @@ class I18nTest extends CakeTestCase { $this->assertTrue(in_array('23 = 0 or > 1 (from plugin)', $plurals)); $this->assertTrue(in_array('24 = 0 or > 1 (from plugin)', $plurals)); $this->assertTrue(in_array('25 = 0 or > 1 (from plugin)', $plurals)); - - Configure::write('pluginPaths', $pluginPaths); } /** * testPoMultipleLineTranslation method @@ -2484,6 +2489,12 @@ class I18nTest extends CakeTestCase { $expected = 'this is a "quoted string" (translated)'; $this->assertEqual(__('this is a "quoted string"', true), $expected); } +/** + * testFloatValue method + * + * @access public + * @return void + */ function testFloatValue() { Configure::write('Config.language', 'rule_9_po'); @@ -2499,6 +2510,70 @@ class I18nTest extends CakeTestCase { $expected = "%d everything else (translated)"; $this->assertEqual($result, $expected); } +/** + * testCategory method + * + * @access public + * @return void + */ + function testCategory() { + Configure::write('Config.language', 'po'); + $category = $this->__category(); + $this->assertEqual('Monetary Po (translated)', $category); + } +/** + * testPluginCategory method + * + * @access public + * @return void + */ + function testPluginCategory() { + Configure::write('Config.language', 'po'); + + $singular = $this->__domainCategorySingular(); + $this->assertEqual('Monetary Plural Rule 1 (from plugin)', $singular); + + $plurals = $this->__domainCategoryPlural(); + $this->assertTrue(in_array('Monetary 0 = 0 or > 1 (from plugin)', $plurals)); + $this->assertTrue(in_array('Monetary 1 = 1 (from plugin)', $plurals)); + } +/** + * testCategoryThenSingular method + * + * @access public + * @return void + */ + function testCategoryThenSingular() { + Configure::write('Config.language', 'po'); + $category = $this->__category(); + $this->assertEqual('Monetary Po (translated)', $category); + + $singular = $this->__singular(); + $this->assertEqual('Po (translated)', $singular); + } +/** + * Singular method + * + * @access private + * @return void + */ + function __domainCategorySingular($domain = 'test_plugin', $category = LC_MONETARY) { + $singular = __dc($domain, 'Plural Rule 1', $category, true); + return $singular; + } +/** + * Plural method + * + * @access private + * @return void + */ + function __domainCategoryPlural($domain = 'test_plugin', $category = LC_MONETARY) { + $plurals = array(); + for ($number = 0; $number <= 25; $number++) { + $plurals[] = sprintf(__dcn($domain, '%d = 1', '%d = 0 or > 1', (float)$number, $category, true), (float)$number); + } + return $plurals; + } /** * Singular method * @@ -2522,6 +2597,16 @@ class I18nTest extends CakeTestCase { } return $plurals; } +/** + * category method + * + * @access private + * @return void + */ + function __category($category = LC_MONETARY) { + $singular = __c('Plural Rule 1', $category, true); + return $singular; + } /** * Singular method * diff --git a/cake/tests/test_app/locale/po/LC_MONETARY/default.po b/cake/tests/test_app/locale/po/LC_MONETARY/default.po new file mode 100644 index 000000000..e2a3c3a05 --- /dev/null +++ b/cake/tests/test_app/locale/po/LC_MONETARY/default.po @@ -0,0 +1,18 @@ +msgid "" +msgstr "" +"Project-Id-Version: CakePHP Testsuite\n" +"POT-Creation-Date: 2008-05-15 02:51-0700\n" +"PO-Revision-Date: \n" +"Last-Translator: CakePHP I18N & I10N Team \n" +"Language-Team: CakePHP I18N & I10N Team \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n" +"X-Poedit-Language: Three Forms of Plurals\n" +"X-Poedit-SourceCharset: utf-8\n" +msgid "" +msgstr "header" + +msgid "Plural Rule 1" +msgstr "Monetary Po (translated)" \ No newline at end of file diff --git a/cake/tests/test_app/plugins/test_plugin/locale/po/LC_MONETARY/test_plugin.po b/cake/tests/test_app/plugins/test_plugin/locale/po/LC_MONETARY/test_plugin.po new file mode 100644 index 000000000..d1079d311 --- /dev/null +++ b/cake/tests/test_app/plugins/test_plugin/locale/po/LC_MONETARY/test_plugin.po @@ -0,0 +1,22 @@ +msgid "" +msgstr "" +"Project-Id-Version: CakePHP Testsuite\n" +"POT-Creation-Date: 2008-05-15 02:51-0700\n" +"PO-Revision-Date: \n" +"Last-Translator: CakePHP I18N & I10N Team \n" +"Language-Team: CakePHP I18N & I10N Team \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Poedit-Language: Two Forms of Plurals\n" +"X-Poedit-SourceCharset: utf-8\n" + +msgid "Plural Rule 1" +msgstr "Monetary Plural Rule 1 (from plugin)" + +msgid "%d = 1" +msgid_plural "%d = 0 or > 1" +msgstr[0] "Monetary %d = 1 (from plugin)" +msgstr[1] "Monetary %d = 0 or > 1 (from plugin)" + From d2a6be21ef91ea837008c957998efe3316c88241 Mon Sep 17 00:00:00 2001 From: jperras Date: Sat, 4 Jul 2009 19:23:22 +0000 Subject: [PATCH 32/95] Splitting Model test into several classes for ease of testing. Creating new 'Database' test group for schema, db_acl and datasource tests. Model group test now only encompasses model & behavior test cases. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8219 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/tests/cases/libs/model/model.test.php | 18932 ++++++++++--------- cake/tests/groups/database.group.php | 56 + cake/tests/groups/model.group.php | 7 +- 3 files changed, 9736 insertions(+), 9259 deletions(-) create mode 100644 cake/tests/groups/database.group.php diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 01f5159dd..4594d397a 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -27,12 +27,12 @@ App::import('Core', array('AppModel', 'Model')); require_once dirname(__FILE__) . DS . 'models.php'; /** - * ModelTest + * ModelBaseTest * * @package cake * @subpackage cake.tests.cases.libs.model */ -class ModelTest extends CakeTestCase { +class BaseModelTest extends CakeTestCase { /** * autoFixtures property * @@ -100,6 +100,955 @@ class ModelTest extends CakeTestCase { ClassRegistry::flush(); } +} +/** + * ModelGeneralTest + * + * @package cake + * @subpackage cake.tests.cases.libs.model + */ +class ModelTest extends BaseModelTest { +/** + * testPkInHAbtmLinkModelArticleB + * + * @access public + * @return void + */ + function testPkInHabtmLinkModelArticleB() { + $this->loadFixtures('Article', 'Tag'); + $TestModel2 =& new ArticleB(); + $this->assertEqual($TestModel2->ArticlesTag->primaryKey, 'article_id'); + } +/** + * Tests that $cacheSources can only be disabled in the db using model settings, not enabled + * + * @access public + * @return void + */ + function testCacheSourcesDisabling() { + $this->db->cacheSources = true; + $TestModel = new JoinA(); + $TestModel->cacheSources = false; + $TestModel->setSource('join_as'); + $this->assertFalse($this->db->cacheSources); + + $this->db->cacheSources = false; + $TestModel = new JoinA(); + $TestModel->cacheSources = true; + $TestModel->setSource('join_as'); + $this->assertFalse($this->db->cacheSources); + } +/** + * testPkInHabtmLinkModel method + * + * @access public + * @return void + */ + function testPkInHabtmLinkModel() { + //Test Nonconformant Models + $this->loadFixtures('Content', 'ContentAccount', 'Account'); + $TestModel =& new Content(); + $this->assertEqual($TestModel->ContentAccount->primaryKey, 'iContentAccountsId'); + + //test conformant models with no PK in the join table + $this->loadFixtures('Article', 'Tag'); + $TestModel2 =& new Article(); + $this->assertEqual($TestModel2->ArticlesTag->primaryKey, 'article_id'); + + //test conformant models with PK in join table + $this->loadFixtures('Item', 'Portfolio', 'ItemsPortfolio'); + $TestModel3 =& new Portfolio(); + $this->assertEqual($TestModel3->ItemsPortfolio->primaryKey, 'id'); + + //test conformant models with PK in join table - join table contains extra field + $this->loadFixtures('JoinA', 'JoinB', 'JoinAB'); + $TestModel4 =& new JoinA(); + $this->assertEqual($TestModel4->JoinAsJoinB->primaryKey, 'id'); + + } +/** + * testDynamicBehaviorAttachment method + * + * @access public + * @return void + */ + function testDynamicBehaviorAttachment() { + $this->loadFixtures('Apple'); + $TestModel =& new Apple(); + $this->assertEqual($TestModel->Behaviors->attached(), array()); + + $TestModel->Behaviors->attach('Tree', array('left' => 'left_field', 'right' => 'right_field')); + $this->assertTrue(is_object($TestModel->Behaviors->Tree)); + $this->assertEqual($TestModel->Behaviors->attached(), array('Tree')); + + $expected = array( + 'parent' => 'parent_id', + 'left' => 'left_field', + 'right' => 'right_field', + 'scope' => '1 = 1', + 'type' => 'nested', + '__parentChange' => false, + 'recursive' => -1 + ); + + $this->assertEqual($TestModel->Behaviors->Tree->settings['Apple'], $expected); + + $expected['enabled'] = false; + $TestModel->Behaviors->attach('Tree', array('enabled' => false)); + $this->assertEqual($TestModel->Behaviors->Tree->settings['Apple'], $expected); + $this->assertEqual($TestModel->Behaviors->attached(), array('Tree')); + + $TestModel->Behaviors->detach('Tree'); + $this->assertEqual($TestModel->Behaviors->attached(), array()); + $this->assertFalse(isset($TestModel->Behaviors->Tree)); + } +/** + * Tests cross database joins. Requires $test and $test2 to both be set in DATABASE_CONFIG + * NOTE: When testing on MySQL, you must set 'persistent' => false on *both* database connections, + * or one connection will step on the other. + */ + function testCrossDatabaseJoins() { + $config = new DATABASE_CONFIG(); + + $skip = $this->skipIf( + !isset($config->test) || !isset($config->test2), + '%s Primary and secondary test databases not configured, skipping cross-database ' + .'join tests.' + .' To run these tests, you must define $test and $test2 in your database configuration.' + ); + + if ($skip) { + return; + } + + $this->loadFixtures('Article', 'Tag', 'ArticlesTag', 'User', 'Comment'); + $TestModel =& new Article(); + + $expected = array( + array( + 'Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + ), + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + )), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ))), + array( + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), + 'Comment' => array( + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + )), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))), + array( + 'Article' => array( + 'id' => '3', + 'user_id' => '1', + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Comment' => array(), + 'Tag' => array() + )); + $this->assertEqual($TestModel->find('all'), $expected); + + $db2 =& ConnectionManager::getDataSource('test2'); + + foreach (array('User', 'Comment') as $class) { + $this->_fixtures[$this->_fixtureClassMap[$class]]->create($db2); + $this->_fixtures[$this->_fixtureClassMap[$class]]->insert($db2); + $this->db->truncate(Inflector::pluralize(Inflector::underscore($class))); + } + + $this->assertEqual($TestModel->User->find('all'), array()); + $this->assertEqual($TestModel->Comment->find('all'), array()); + $this->assertEqual($TestModel->find('count'), 3); + + $TestModel->User->setDataSource('test2'); + $TestModel->Comment->setDataSource('test2'); + + foreach ($expected as $key => $value) { + unset($value['Comment'], $value['Tag']); + $expected[$key] = $value; + } + + $TestModel->recursive = 0; + $result = $TestModel->find('all'); + $this->assertEqual($result, $expected); + + foreach ($expected as $key => $value) { + unset($value['Comment'], $value['Tag']); + $expected[$key] = $value; + } + + $TestModel->recursive = 0; + $result = $TestModel->find('all'); + $this->assertEqual($result, $expected); + + $result = Set::extract($TestModel->User->find('all'), '{n}.User.id'); + $this->assertEqual($result, array('1', '2', '3', '4')); + $this->assertEqual($TestModel->find('all'), $expected); + + $TestModel->Comment->unbindModel(array('hasOne' => array('Attachment'))); + $expected = array( + array( + 'Comment' => array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + ), + 'Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + )), + array( + 'Comment' => array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + ), + 'User' => array( + 'id' => '4', + 'user' => 'garrett', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:22:23', + 'updated' => '2007-03-17 01:24:31' + ), + 'Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + )), + array( + 'Comment' => array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + )), + array( + 'Comment' => array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + )), + array( + 'Comment' => array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + )), + array( + 'Comment' => array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ), + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + ), + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ))); + $this->assertEqual($TestModel->Comment->find('all'), $expected); + + foreach (array('User', 'Comment') as $class) { + $this->_fixtures[$this->_fixtureClassMap[$class]]->drop($db2); + } + } +/** + * testDisplayField method + * + * @access public + * @return void + */ + function testDisplayField() { + $this->loadFixtures('Post', 'Comment', 'Person'); + $Post = new Post(); + $Comment = new Comment(); + $Person = new Person(); + + $this->assertEqual($Post->displayField, 'title'); + $this->assertEqual($Person->displayField, 'name'); + $this->assertEqual($Comment->displayField, 'id'); + } +/** + * testSchema method + * + * @access public + * @return void + */ + function testSchema() { + $Post = new Post(); + + $result = $Post->schema(); + $columns = array('id', 'author_id', 'title', 'body', 'published', 'created', 'updated'); + $this->assertEqual(array_keys($result), $columns); + + $types = array('integer', 'integer', 'string', 'text', 'string', 'datetime', 'datetime'); + $this->assertEqual(Set::extract(array_values($result), '{n}.type'), $types); + + $result = $Post->schema('body'); + $this->assertEqual($result['type'], 'text'); + $this->assertNull($Post->schema('foo')); + + $this->assertEqual($Post->getColumnTypes(), array_combine($columns, $types)); + } +/** + * testDeconstructFields method + * + * @access public + * @return void + */ + function testDeconstructFields() { + $this->loadFixtures('Apple'); + $TestModel =& new Apple(); + + //test null/empty values first + $data['Apple']['created']['year'] = ''; + $data['Apple']['created']['month'] = ''; + $data['Apple']['created']['day'] = ''; + $data['Apple']['created']['hour'] = ''; + $data['Apple']['created']['min'] = ''; + $data['Apple']['created']['sec'] = ''; + + $TestModel->data = null; + $TestModel->set($data); + $expected = array('Apple'=> array('created'=> '')); + $this->assertEqual($TestModel->data, $expected); + + $data = array(); + $data['Apple']['date']['year'] = ''; + $data['Apple']['date']['month'] = ''; + $data['Apple']['date']['day'] = ''; + + $TestModel->data = null; + $TestModel->set($data); + $expected = array('Apple'=> array('date'=> '')); + $this->assertEqual($TestModel->data, $expected); + + $data = array(); + $data['Apple']['mytime']['hour'] = ''; + $data['Apple']['mytime']['min'] = ''; + $data['Apple']['mytime']['sec'] = ''; + + $TestModel->data = null; + $TestModel->set($data); + $expected = array('Apple'=> array('mytime'=> '')); + $this->assertEqual($TestModel->data, $expected); + + //test other data variations + $data = array(); + $data['Apple']['created']['year'] = '2007'; + $data['Apple']['created']['month'] = '08'; + $data['Apple']['created']['day'] = '20'; + $data['Apple']['created']['hour'] = ''; + $data['Apple']['created']['min'] = ''; + $data['Apple']['created']['sec'] = ''; + + $TestModel->data = null; + $TestModel->set($data); + $expected = array('Apple'=> array('created'=> '2007-08-20 00:00:00')); + $this->assertEqual($TestModel->data, $expected); + + $data = array(); + $data['Apple']['created']['year'] = '2007'; + $data['Apple']['created']['month'] = '08'; + $data['Apple']['created']['day'] = '20'; + $data['Apple']['created']['hour'] = '10'; + $data['Apple']['created']['min'] = '12'; + $data['Apple']['created']['sec'] = ''; + + $TestModel->data = null; + $TestModel->set($data); + $expected = array('Apple'=> array('created'=> '2007-08-20 10:12:00')); + $this->assertEqual($TestModel->data, $expected); + + $data = array(); + $data['Apple']['created']['year'] = '2007'; + $data['Apple']['created']['month'] = ''; + $data['Apple']['created']['day'] = '12'; + $data['Apple']['created']['hour'] = '20'; + $data['Apple']['created']['min'] = ''; + $data['Apple']['created']['sec'] = ''; + + $TestModel->data = null; + $TestModel->set($data); + $expected = array('Apple'=> array('created'=> '')); + $this->assertEqual($TestModel->data, $expected); + + $data = array(); + $data['Apple']['created']['hour'] = '20'; + $data['Apple']['created']['min'] = '33'; + + $TestModel->data = null; + $TestModel->set($data); + $expected = array('Apple'=> array('created'=> '')); + $this->assertEqual($TestModel->data, $expected); + + $data = array(); + $data['Apple']['created']['hour'] = '20'; + $data['Apple']['created']['min'] = '33'; + $data['Apple']['created']['sec'] = '33'; + + $TestModel->data = null; + $TestModel->set($data); + $expected = array('Apple'=> array('created'=> '')); + $this->assertEqual($TestModel->data, $expected); + + $data = array(); + $data['Apple']['created']['hour'] = '13'; + $data['Apple']['created']['min'] = '00'; + $data['Apple']['date']['year'] = '2006'; + $data['Apple']['date']['month'] = '12'; + $data['Apple']['date']['day'] = '25'; + + $TestModel->data = null; + $TestModel->set($data); + $expected = array( + 'Apple'=> array( + 'created'=> '', + 'date'=> '2006-12-25' + )); + $this->assertEqual($TestModel->data, $expected); + + $data = array(); + $data['Apple']['created']['year'] = '2007'; + $data['Apple']['created']['month'] = '08'; + $data['Apple']['created']['day'] = '20'; + $data['Apple']['created']['hour'] = '10'; + $data['Apple']['created']['min'] = '12'; + $data['Apple']['created']['sec'] = '09'; + $data['Apple']['date']['year'] = '2006'; + $data['Apple']['date']['month'] = '12'; + $data['Apple']['date']['day'] = '25'; + + $TestModel->data = null; + $TestModel->set($data); + $expected = array( + 'Apple'=> array( + 'created'=> '2007-08-20 10:12:09', + 'date'=> '2006-12-25' + )); + $this->assertEqual($TestModel->data, $expected); + + $data = array(); + $data['Apple']['created']['year'] = '--'; + $data['Apple']['created']['month'] = '--'; + $data['Apple']['created']['day'] = '--'; + $data['Apple']['created']['hour'] = '--'; + $data['Apple']['created']['min'] = '--'; + $data['Apple']['created']['sec'] = '--'; + $data['Apple']['date']['year'] = '--'; + $data['Apple']['date']['month'] = '--'; + $data['Apple']['date']['day'] = '--'; + + $TestModel->data = null; + $TestModel->set($data); + $expected = array('Apple'=> array('created'=> '', 'date'=> '')); + $this->assertEqual($TestModel->data, $expected); + + $data = array(); + $data['Apple']['created']['year'] = '2007'; + $data['Apple']['created']['month'] = '--'; + $data['Apple']['created']['day'] = '20'; + $data['Apple']['created']['hour'] = '10'; + $data['Apple']['created']['min'] = '12'; + $data['Apple']['created']['sec'] = '09'; + $data['Apple']['date']['year'] = '2006'; + $data['Apple']['date']['month'] = '12'; + $data['Apple']['date']['day'] = '25'; + + $TestModel->data = null; + $TestModel->set($data); + $expected = array('Apple'=> array('created'=> '', 'date'=> '2006-12-25')); + $this->assertEqual($TestModel->data, $expected); + + $data = array(); + $data['Apple']['date']['year'] = '2006'; + $data['Apple']['date']['month'] = '12'; + $data['Apple']['date']['day'] = '25'; + + $TestModel->data = null; + $TestModel->set($data); + $expected = array('Apple'=> array('date'=> '2006-12-25')); + $this->assertEqual($TestModel->data, $expected); + + $data = array(); + $data['Apple']['mytime']['hour'] = '03'; + $data['Apple']['mytime']['min'] = '04'; + $data['Apple']['mytime']['sec'] = '04'; + + $TestModel->data = null; + $TestModel->set($data); + $expected = array('Apple'=> array('mytime'=> '03:04:04')); + $this->assertEqual($TestModel->data, $expected); + + $data = array(); + $data['Apple']['mytime']['hour'] = '3'; + $data['Apple']['mytime']['min'] = '4'; + $data['Apple']['mytime']['sec'] = '4'; + + $TestModel->data = null; + $TestModel->set($data); + $expected = array('Apple' => array('mytime'=> '03:04:04')); + $this->assertEqual($TestModel->data, $expected); + + $data = array(); + $data['Apple']['mytime']['hour'] = '03'; + $data['Apple']['mytime']['min'] = '4'; + $data['Apple']['mytime']['sec'] = '4'; + + $TestModel->data = null; + $TestModel->set($data); + $expected = array('Apple'=> array('mytime'=> '03:04:04')); + $this->assertEqual($TestModel->data, $expected); + + $db = ConnectionManager::getDataSource('test_suite'); + $data = array(); + $data['Apple']['modified'] = $db->expression('NOW()'); + $TestModel->data = null; + $TestModel->set($data); + $this->assertEqual($TestModel->data, $data); + + $data = array(); + $data['Apple']['mytime'] = $db->expression('NOW()'); + $TestModel->data = null; + $TestModel->set($data); + $this->assertEqual($TestModel->data, $data); + } +/** + * testTablePrefixSwitching method + * + * @access public + * @return void + */ + function testTablePrefixSwitching() { + ConnectionManager::create('database1', + array_merge($this->db->config, array('prefix' => 'aaa_') + )); + ConnectionManager::create('database2', + array_merge($this->db->config, array('prefix' => 'bbb_') + )); + + $db1 = ConnectionManager::getDataSource('database1'); + $db2 = ConnectionManager::getDataSource('database2'); + + $TestModel = new Apple(); + $TestModel->setDataSource('database1'); + $this->assertEqual($this->db->fullTableName($TestModel, false), 'aaa_apples'); + $this->assertEqual($db1->fullTableName($TestModel, false), 'aaa_apples'); + $this->assertEqual($db2->fullTableName($TestModel, false), 'aaa_apples'); + + $TestModel->setDataSource('database2'); + $this->assertEqual($this->db->fullTableName($TestModel, false), 'bbb_apples'); + $this->assertEqual($db1->fullTableName($TestModel, false), 'bbb_apples'); + $this->assertEqual($db2->fullTableName($TestModel, false), 'bbb_apples'); + + $TestModel = new Apple(); + $TestModel->tablePrefix = 'custom_'; + $this->assertEqual($this->db->fullTableName($TestModel, false), 'custom_apples'); + $TestModel->setDataSource('database1'); + $this->assertEqual($this->db->fullTableName($TestModel, false), 'custom_apples'); + $this->assertEqual($db1->fullTableName($TestModel, false), 'custom_apples'); + + $TestModel = new Apple(); + $TestModel->setDataSource('database1'); + $this->assertEqual($this->db->fullTableName($TestModel, false), 'aaa_apples'); + $TestModel->tablePrefix = ''; + $TestModel->setDataSource('database2'); + $this->assertEqual($db2->fullTableName($TestModel, false), 'apples'); + $this->assertEqual($db1->fullTableName($TestModel, false), 'apples'); + + $TestModel->tablePrefix = null; + $TestModel->setDataSource('database1'); + $this->assertEqual($db2->fullTableName($TestModel, false), 'aaa_apples'); + $this->assertEqual($db1->fullTableName($TestModel, false), 'aaa_apples'); + + $TestModel->tablePrefix = false; + $TestModel->setDataSource('database2'); + $this->assertEqual($db2->fullTableName($TestModel, false), 'apples'); + $this->assertEqual($db1->fullTableName($TestModel, false), 'apples'); + } +/** + * Tests validation parameter order in custom validation methods + * + * @access public + * @return void + */ + function testInvalidAssociation() { + $TestModel =& new ValidationTest1(); + $this->assertNull($TestModel->getAssociated('Foo')); + } +/** + * testLoadModelSecondIteration method + * + * @access public + * @return void + */ + function testLoadModelSecondIteration() { + $model = new ModelA(); + $this->assertIsA($model,'ModelA'); + + $this->assertIsA($model->ModelB, 'ModelB'); + $this->assertIsA($model->ModelB->ModelD, 'ModelD'); + + $this->assertIsA($model->ModelC, 'ModelC'); + $this->assertIsA($model->ModelC->ModelD, 'ModelD'); + } +/** + * ensure that __exists is reset on create + * + * @return void + **/ + function testResetOfExistsOnCreate() { + $this->loadFixtures('Article'); + $Article =& new Article(); + $Article->id = 1; + $Article->saveField('title', 'Reset me'); + $Article->delete(); + $Article->id = 1; + $this->assertFalse($Article->exists()); + + $Article->create(); + $this->assertFalse($Article->exists()); + $Article->id = 2; + $Article->saveField('title', 'Staying alive'); + $result = $Article->read(null, 2); + $this->assertEqual($result['Article']['title'], 'Staying alive'); + } +/** + * testPluginAssociations method + * + * @access public + * @return void + */ + function testPluginAssociations() { + $this->loadFixtures('TestPluginArticle', 'User', 'TestPluginComment'); + $TestModel =& new TestPluginArticle(); + + $result = $TestModel->find('all'); + $expected = array( + array( + 'TestPluginArticle' => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Plugin Article', + 'body' => 'First Plugin Article Body', + 'published' => 'Y', + 'created' => '2008-09-24 10:39:23', + 'updated' => '2008-09-24 10:41:31' + ), + 'User' => array( + 'id' => 1, + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'TestPluginComment' => array( + array( + 'id' => 1, + 'article_id' => 1, + 'user_id' => 2, + 'comment' => 'First Comment for First Plugin Article', + 'published' => 'Y', + 'created' => '2008-09-24 10:45:23', + 'updated' => '2008-09-24 10:47:31' + ), + array( + 'id' => 2, + 'article_id' => 1, + 'user_id' => 4, + 'comment' => 'Second Comment for First Plugin Article', + 'published' => 'Y', + 'created' => '2008-09-24 10:47:23', + 'updated' => '2008-09-24 10:49:31' + ), + array( + 'id' => 3, + 'article_id' => 1, + 'user_id' => 1, + 'comment' => 'Third Comment for First Plugin Article', + 'published' => 'Y', + 'created' => '2008-09-24 10:49:23', + 'updated' => '2008-09-24 10:51:31' + ), + array( + 'id' => 4, + 'article_id' => 1, + 'user_id' => 1, + 'comment' => 'Fourth Comment for First Plugin Article', + 'published' => 'N', + 'created' => '2008-09-24 10:51:23', + 'updated' => '2008-09-24 10:53:31' + ))), + array( + 'TestPluginArticle' => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Plugin Article', + 'body' => 'Second Plugin Article Body', + 'published' => 'Y', + 'created' => '2008-09-24 10:41:23', + 'updated' => '2008-09-24 10:43:31' + ), + 'User' => array( + 'id' => 3, + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), + 'TestPluginComment' => array( + array( + 'id' => 5, + 'article_id' => 2, + 'user_id' => 1, + 'comment' => 'First Comment for Second Plugin Article', + 'published' => 'Y', + 'created' => '2008-09-24 10:53:23', + 'updated' => '2008-09-24 10:55:31' + ), + array( + 'id' => 6, + 'article_id' => 2, + 'user_id' => 2, + 'comment' => 'Second Comment for Second Plugin Article', + 'published' => 'Y', + 'created' => '2008-09-24 10:55:23', + 'updated' => '2008-09-24 10:57:31' + ))), + array( + 'TestPluginArticle' => array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Plugin Article', + 'body' => 'Third Plugin Article Body', + 'published' => 'Y', + 'created' => '2008-09-24 10:43:23', + 'updated' => '2008-09-24 10:45:31' + ), + 'User' => array( + 'id' => 1, + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'TestPluginComment' => array() + )); + + $this->assertEqual($result, $expected); + } /** * Tests getAssociated method * @@ -303,365 +1252,6 @@ class ModelTest extends CakeTestCase { $this->assertEqual($model->getColumnType('Tag.id'), 'integer'); $this->assertEqual($model->getColumnType('Article.id'), 'integer'); } - -/** - * testMultipleBelongsToWithSameClass method - * - * @access public - * @return void - */ - function testMultipleBelongsToWithSameClass() { - $this->loadFixtures( - 'DeviceType', - 'DeviceTypeCategory', - 'FeatureSet', - 'ExteriorTypeCategory', - 'Document', - 'Device', - 'DocumentDirectory' - ); - - $DeviceType =& new DeviceType(); - - $DeviceType->recursive = 2; - $result = $DeviceType->read(null, 1); - - $expected = array( - 'DeviceType' => array( - 'id' => 1, - 'device_type_category_id' => 1, - 'feature_set_id' => 1, - 'exterior_type_category_id' => 1, - 'image_id' => 1, - 'extra1_id' => 1, - 'extra2_id' => 1, - 'name' => 'DeviceType 1', - 'order' => 0 - ), - 'Image' => array( - 'id' => 1, - 'document_directory_id' => 1, - 'name' => 'Document 1', - 'DocumentDirectory' => array( - 'id' => 1, - 'name' => 'DocumentDirectory 1' - )), - 'Extra1' => array( - 'id' => 1, - 'document_directory_id' => 1, - 'name' => 'Document 1', - 'DocumentDirectory' => array( - 'id' => 1, - 'name' => 'DocumentDirectory 1' - )), - 'Extra2' => array( - 'id' => 1, - 'document_directory_id' => 1, - 'name' => 'Document 1', - 'DocumentDirectory' => array( - 'id' => 1, - 'name' => 'DocumentDirectory 1' - )), - 'DeviceTypeCategory' => array( - 'id' => 1, - 'name' => 'DeviceTypeCategory 1' - ), - 'FeatureSet' => array( - 'id' => 1, - 'name' => 'FeatureSet 1' - ), - 'ExteriorTypeCategory' => array( - 'id' => 1, - 'image_id' => 1, - 'name' => 'ExteriorTypeCategory 1', - 'Image' => array( - 'id' => 1, - 'device_type_id' => 1, - 'name' => 'Device 1', - 'typ' => 1 - )), - 'Device' => array( - array( - 'id' => 1, - 'device_type_id' => 1, - 'name' => 'Device 1', - 'typ' => 1 - ), - array( - 'id' => 2, - 'device_type_id' => 1, - 'name' => 'Device 2', - 'typ' => 1 - ), - array( - 'id' => 3, - 'device_type_id' => 1, - 'name' => 'Device 3', - 'typ' => 2 - ))); - - $this->assertEqual($result, $expected); - } -/** - * testHabtmRecursiveBelongsTo method - * - * @access public - * @return void - */ - function testHabtmRecursiveBelongsTo() { - $this->loadFixtures('Portfolio', 'Item', 'ItemsPortfolio', 'Syfile', 'Image'); - $Portfolio =& new Portfolio(); - - $result = $Portfolio->find(array('id' => 2), null, null, 3); - $expected = array( - 'Portfolio' => array( - 'id' => 2, - 'seller_id' => 1, - 'name' => 'Portfolio 2' - ), - 'Item' => array( - array( - 'id' => 2, - 'syfile_id' => 2, - 'published' => 0, - 'name' => 'Item 2', - 'ItemsPortfolio' => array( - 'id' => 2, - 'item_id' => 2, - 'portfolio_id' => 2 - ), - 'Syfile' => array( - 'id' => 2, - 'image_id' => 2, - 'name' => 'Syfile 2', - 'item_count' => null, - 'Image' => array( - 'id' => 2, - 'name' => 'Image 2' - ) - )), - array( - 'id' => 6, - 'syfile_id' => 6, - 'published' => 0, - 'name' => 'Item 6', - 'ItemsPortfolio' => array( - 'id' => 6, - 'item_id' => 6, - 'portfolio_id' => 2 - ), - 'Syfile' => array( - 'id' => 6, - 'image_id' => null, - 'name' => 'Syfile 6', - 'item_count' => null, - 'Image' => array() - )))); - - $this->assertEqual($result, $expected); - } -/** - * testHabtmUuidWithUuidId method - * - * @access public - * @return void - */ - function testHabtmUuidWithUuidId() { - $this->loadFixtures('Uuidportfolio', 'Uuiditem', 'UuiditemsUuidportfolio'); - $TestModel =& new Uuidportfolio(); - - $data = array('Uuidportfolio' => array('name' => 'Portfolio 3')); - $data['Uuiditem']['Uuiditem'] = array('483798c8-c7cc-430e-8cf9-4fcc40cf8569'); - $TestModel->create($data); - $TestModel->save(); - $id = $TestModel->id; - $result = $TestModel->read(null, $id); - $this->assertEqual(1, count($result['Uuiditem'])); - $this->assertEqual(strlen($result['Uuiditem'][0]['UuiditemsUuidportfolio']['id']), 36); - } -/** - * test HABTM saving when join table has no primary key and only 2 columns. - * - * @return void - **/ - function testHabtmSavingWithNoPrimaryKeyUuidJoinTable() { - $this->loadFixtures('UuidTag', 'Fruit', 'FruitsUuidTag'); - $Fruit =& new Fruit(); - $data = array( - 'Fruit' => array( - 'color' => 'Red', - 'shape' => 'Heart-shaped', - 'taste' => 'sweet', - 'name' => 'Strawberry', - ), - 'UuidTag' => array( - 'UuidTag' => array( - '481fc6d0-b920-43e0-e50f-6d1740cf8569' - ) - ) - ); - $this->assertTrue($Fruit->save($data)); - } -/** - * test HABTM saving when join table has no primary key and only 2 columns, no with model is used. - * - * @return void - **/ - function testHabtmSavingWithNoPrimaryKeyUuidJoinTableNoWith() { - $this->loadFixtures('UuidTag', 'Fruit', 'FruitsUuidTag'); - $Fruit =& new FruitNoWith(); - $data = array( - 'Fruit' => array( - 'color' => 'Red', - 'shape' => 'Heart-shaped', - 'taste' => 'sweet', - 'name' => 'Strawberry', - ), - 'UuidTag' => array( - 'UuidTag' => array( - '481fc6d0-b920-43e0-e50f-6d1740cf8569' - ) - ) - ); - $this->assertTrue($Fruit->save($data)); - } - -/** - * testHabtmUuidWithNumericId method - * - * @access public - * @return void - */ - function testHabtmUuidWithNumericId() { - $this->loadFixtures('Uuidportfolio', 'Uuiditem', 'UuiditemsUuidportfolioNumericid'); - $TestModel =& new Uuiditem(); - - $data = array('Uuiditem' => array('name' => 'Item 7', 'published' => 0)); - $data['Uuidportfolio']['Uuidportfolio'] = array('480af662-eb8c-47d3-886b-230540cf8569'); - $TestModel->create($data); - $TestModel->save(); - $id = $TestModel->id; - $result = $TestModel->read(null, $id); - $this->assertEqual(1, count($result['Uuidportfolio'])); - } -/** - * testHabtmFinderQuery method - * - * @access public - * @return void - */ - function testHabtmFinderQuery() { - $this->loadFixtures('Article', 'Tag', 'ArticlesTag'); - $Article =& new Article(); - - $sql = $this->db->buildStatement( - array( - 'fields' => $this->db->fields($Article->Tag, null, array( - 'Tag.id', 'Tag.tag', 'ArticlesTag.article_id', 'ArticlesTag.tag_id' - )), - 'table' => $this->db->fullTableName('tags'), - 'alias' => 'Tag', - 'limit' => null, - 'offset' => null, - 'group' => null, - 'joins' => array(array( - 'alias' => 'ArticlesTag', - 'table' => $this->db->fullTableName('articles_tags'), - 'conditions' => array( - array("ArticlesTag.article_id" => '{$__cakeID__$}'), - array("ArticlesTag.tag_id" => $this->db->identifier('Tag.id')) - ) - )), - 'conditions' => array(), - 'order' => null - ), - $Article - ); - - $Article->hasAndBelongsToMany['Tag']['finderQuery'] = $sql; - $result = $Article->find('first'); - $expected = array( - array( - 'id' => '1', - 'tag' => 'tag1' - ), - array( - 'id' => '2', - 'tag' => 'tag2' - )); - - $this->assertEqual($result['Tag'], $expected); - } -/** - * testHabtmLimitOptimization method - * - * @access public - * @return void - */ - function testHabtmLimitOptimization() { - $this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'ArticlesTag'); - $TestModel =& new Article(); - - $TestModel->hasAndBelongsToMany['Tag']['limit'] = 2; - $result = $TestModel->read(null, 2); - $expected = array( - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - ), - 'Comment' => array( - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - )), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - ))); - - $this->assertEqual($result, $expected); - - $TestModel->hasAndBelongsToMany['Tag']['limit'] = 1; - $result = $TestModel->read(null, 2); - unset($expected['Tag'][1]); - - $this->assertEqual($result, $expected); - } /** * testHabtmUniqueKey method * @@ -673,117 +1263,25 @@ class ModelTest extends CakeTestCase { $this->assertFalse($model->hasAndBelongsToMany['Portfolio']['unique']); } /** - * testHasManyLimitOptimization method + * testIdentity method * * @access public * @return void */ - function testHasManyLimitOptimization() { - $this->loadFixtures('Project', 'Thread', 'Message', 'Bid'); - $Project =& new Project(); - $Project->recursive = 3; + function testIdentity() { + $TestModel =& new Test(); + $result = $TestModel->alias; + $expected = 'Test'; + $this->assertEqual($result, $expected); - $result = $Project->find('all'); - $expected = array( - array( - 'Project' => array( - 'id' => 1, - 'name' => 'Project 1' - ), - 'Thread' => array( - array( - 'id' => 1, - 'project_id' => 1, - 'name' => 'Project 1, Thread 1', - 'Project' => array( - 'id' => 1, - 'name' => 'Project 1', - 'Thread' => array( - array( - 'id' => 1, - 'project_id' => 1, - 'name' => 'Project 1, Thread 1' - ), - array( - 'id' => 2, - 'project_id' => 1, - 'name' => 'Project 1, Thread 2' - ))), - 'Message' => array( - array( - 'id' => 1, - 'thread_id' => 1, - 'name' => 'Thread 1, Message 1', - 'Bid' => array( - 'id' => 1, - 'message_id' => 1, - 'name' => 'Bid 1.1' - )))), - array( - 'id' => 2, - 'project_id' => 1, - 'name' => 'Project 1, Thread 2', - 'Project' => array( - 'id' => 1, - 'name' => 'Project 1', - 'Thread' => array( - array( - 'id' => 1, - 'project_id' => 1, - 'name' => 'Project 1, Thread 1' - ), - array( - 'id' => 2, - 'project_id' => 1, - 'name' => 'Project 1, Thread 2' - ))), - 'Message' => array( - array( - 'id' => 2, - 'thread_id' => 2, - 'name' => 'Thread 2, Message 1', - 'Bid' => array( - 'id' => 4, - 'message_id' => 2, - 'name' => 'Bid 2.1' - )))))), - array( - 'Project' => array( - 'id' => 2, - 'name' => 'Project 2' - ), - 'Thread' => array( - array( - 'id' => 3, - 'project_id' => 2, - 'name' => 'Project 2, Thread 1', - 'Project' => array( - 'id' => 2, - 'name' => 'Project 2', - 'Thread' => array( - array( - 'id' => 3, - 'project_id' => 2, - 'name' => 'Project 2, Thread 1' - ))), - 'Message' => array( - array( - 'id' => 3, - 'thread_id' => 3, - 'name' => 'Thread 3, Message 1', - 'Bid' => array( - 'id' => 3, - 'message_id' => 3, - 'name' => 'Bid 3.1' - )))))), - array( - 'Project' => array( - 'id' => 3, - 'name' => 'Project 3' - ), - 'Thread' => array() - )); + $TestModel =& new TestAlias(); + $result = $TestModel->alias; + $expected = 'TestAlias'; + $this->assertEqual($result, $expected); + $TestModel =& new Test(array('alias' => 'AnotherTest')); + $result = $TestModel->alias; + $expected = 'AnotherTest'; $this->assertEqual($result, $expected); } /** @@ -798,38 +1296,176 @@ class ModelTest extends CakeTestCase { $result = $TestModel->SomethingElse->find('all'); $expected = array( - array('SomethingElse' => array('id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), - 'Something' => array(array('id' => '3', 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', - 'JoinThing' => array('id' => '3', 'something_id' => '3', 'something_else_id' => '1', 'doomed' => '1', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31')))), - array('SomethingElse' => array('id' => '2', 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), - 'Something' => array(array('id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', - 'JoinThing' => array('id' => '1', 'something_id' => '1', 'something_else_id' => '2', 'doomed' => '1', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31')))), - array('SomethingElse' => array('id' => '3', 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'), - 'Something' => array (array('id' => '2', 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', - 'JoinThing' => array('id' => '2', 'something_id' => '2', 'something_else_id' => '3', 'doomed' => '0', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'))))); + array( + 'SomethingElse' => array( + 'id' => '1', + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'Something' => array( + array( + 'id' => '3', + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31', + 'JoinThing' => array( + 'id' => '3', + 'something_id' => '3', + 'something_else_id' => '1', + 'doomed' => '1', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + )))), + array( + 'SomethingElse' => array( + 'id' => '2', + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'Something' => array( + array( + 'id' => '1', + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31', + 'JoinThing' => array( + 'id' => '1', + 'something_id' => '1', + 'something_else_id' => '2', + 'doomed' => '1', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + )))), + array( + 'SomethingElse' => array( + 'id' => '3', + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ), + 'Something' => array( + array( + 'id' => '2', + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31', + 'JoinThing' => array( + 'id' => '2', + 'something_id' => '2', + 'something_else_id' => '3', + 'doomed' => '0', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ))))); $this->assertEqual($result, $expected); $result = $TestModel->find('all'); $expected = array( - array('Something' => array('id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), + array( + 'Something' => array( + 'id' => '1', + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), 'SomethingElse' => array( - array('id' => '2', 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', - 'JoinThing' => array('doomed' => '1', 'something_id' => '1', 'something_else_id' => '2')))), - array('Something' => array('id' => '2', 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), - 'SomethingElse' => array( - array('id' => '3', 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31', - 'JoinThing' => array('doomed' => '0', 'something_id' => '2', 'something_else_id' => '3')))), - array('Something' => array('id' => '3', 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31'), - 'SomethingElse' => array( - array('id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31', - 'JoinThing' => array('doomed' => '1', 'something_id' => '3', 'something_else_id' => '1'))))); + array( + 'id' => '2', + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31', + 'JoinThing' => array( + 'doomed' => '1', + 'something_id' => '1', + 'something_else_id' => '2' + )))), + array( + 'Something' => array( + 'id' => '2', + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'SomethingElse' => array( + array( + 'id' => '3', + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31', + 'JoinThing' => array( + 'doomed' => '0', + 'something_id' => '2', + 'something_else_id' => '3' + )))), + array( + 'Something' => array( + 'id' => '3', + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ), + 'SomethingElse' => array( + array( + 'id' => '1', + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31', + 'JoinThing' => array( + 'doomed' => '1', + 'something_id' => '3', + 'something_else_id' => '1' + ))))); $this->assertEqual($result, $expected); $result = $TestModel->findById(1); $expected = array( - 'Something' => array('id' => '1', 'title' => 'First Post', 'body' => 'First Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31'), - 'SomethingElse' => array(array('id' => '2', 'title' => 'Second Post', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31', - 'JoinThing' => array('doomed' => '1', 'something_id' => '1', 'something_else_id' => '2')))); + 'Something' => array( + 'id' => '1', + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'SomethingElse' => array( + array( + 'id' => '2', + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31', + 'JoinThing' => array( + 'doomed' => '1', + 'something_id' => '1', + 'something_else_id' => '2' + )))); $this->assertEqual($result, $expected); $expected = $TestModel->findById(1); @@ -899,408 +1535,6 @@ class ModelTest extends CakeTestCase { $this->assertEqual($result, $expected); } -/** - * testDynamicAssociations method - * - * @access public - * @return void - */ - function testDynamicAssociations() { - $this->loadFixtures('Article', 'Comment'); - $TestModel =& new Article(); - - $TestModel->belongsTo = $TestModel->hasAndBelongsToMany = $TestModel->hasOne = array(); - $TestModel->hasMany['Comment'] = array_merge($TestModel->hasMany['Comment'], array( - 'foreignKey' => false, - 'conditions' => array('Comment.user_id =' => '2') - )); - $result = $TestModel->find('all'); - $expected = array( - array( - 'Article' => array( - 'id' => '1', - 'user_id' => '1', - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'Comment' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - ))), - array( - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'Comment' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - ))), - array( - 'Article' => array( - 'id' => '3', - 'user_id' => '1', - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ), - 'Comment' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - )))); - - $this->assertEqual($result, $expected); - } -/** - * testSaveMultipleHabtm method - * - * @access public - * @return void - */ - function testSaveMultipleHabtm() { - $this->loadFixtures('JoinA', 'JoinB', 'JoinC', 'JoinAB', 'JoinAC'); - $TestModel = new JoinA(); - $result = $TestModel->findById(1); - - $expected = array( - 'JoinA' => array( - 'id' => 1, - 'name' => 'Join A 1', - 'body' => 'Join A 1 Body', - 'created' => '2008-01-03 10:54:23', - 'updated' => '2008-01-03 10:54:23' - ), - 'JoinB' => array( - 0 => array( - 'id' => 2, - 'name' => 'Join B 2', - 'created' => '2008-01-03 10:55:02', - 'updated' => '2008-01-03 10:55:02', - 'JoinAsJoinB' => array( - 'id' => 1, - 'join_a_id' => 1, - 'join_b_id' => 2, - 'other' => 'Data for Join A 1 Join B 2', - 'created' => '2008-01-03 10:56:33', - 'updated' => '2008-01-03 10:56:33' - ))), - 'JoinC' => array( - 0 => array( - 'id' => 2, - 'name' => 'Join C 2', - 'created' => '2008-01-03 10:56:12', - 'updated' => '2008-01-03 10:56:12', - 'JoinAsJoinC' => array( - 'id' => 1, - 'join_a_id' => 1, - 'join_c_id' => 2, - 'other' => 'Data for Join A 1 Join C 2', - 'created' => '2008-01-03 10:57:22', - 'updated' => '2008-01-03 10:57:22' - )))); - - $this->assertEqual($result, $expected); - - $ts = date('Y-m-d H:i:s'); - $TestModel->id = 1; - $data = array( - 'JoinA' => array( - 'id' => '1', - 'name' => 'New name for Join A 1', - 'updated' => $ts - ), - 'JoinB' => array( - array( - 'id' => 1, - 'join_b_id' => 2, - 'other' => 'New data for Join A 1 Join B 2', - 'created' => $ts, - 'updated' => $ts - )), - 'JoinC' => array( - array( - 'id' => 1, - 'join_c_id' => 2, - 'other' => 'New data for Join A 1 Join C 2', - 'created' => $ts, - 'updated' => $ts - ))); - - $TestModel->set($data); - $TestModel->save(); - - $result = $TestModel->findById(1); - $expected = array( - 'JoinA' => array( - 'id' => 1, - 'name' => 'New name for Join A 1', - 'body' => 'Join A 1 Body', - 'created' => '2008-01-03 10:54:23', - 'updated' => $ts - ), - 'JoinB' => array( - 0 => array( - 'id' => 2, - 'name' => 'Join B 2', - 'created' => '2008-01-03 10:55:02', - 'updated' => '2008-01-03 10:55:02', - 'JoinAsJoinB' => array( - 'id' => 1, - 'join_a_id' => 1, - 'join_b_id' => 2, - 'other' => 'New data for Join A 1 Join B 2', - 'created' => $ts, - 'updated' => $ts - ))), - 'JoinC' => array( - 0 => array( - 'id' => 2, - 'name' => 'Join C 2', - 'created' => '2008-01-03 10:56:12', - 'updated' => '2008-01-03 10:56:12', - 'JoinAsJoinC' => array( - 'id' => 1, - 'join_a_id' => 1, - 'join_c_id' => 2, - 'other' => 'New data for Join A 1 Join C 2', - 'created' => $ts, - 'updated' => $ts - )))); - - $this->assertEqual($result, $expected); - } -/** - * testFindAllRecursiveSelfJoin method - * - * @access public - * @return void - */ - function testFindAllRecursiveSelfJoin() { - $this->loadFixtures('Home', 'AnotherArticle', 'Advertisement'); - $TestModel =& new Home(); - $TestModel->recursive = 2; - - $result = $TestModel->find('all'); - $expected = array( - array( - 'Home' => array( - 'id' => '1', - 'another_article_id' => '1', - 'advertisement_id' => '1', - 'title' => 'First Home', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'AnotherArticle' => array( - 'id' => '1', - 'title' => 'First Article', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31', - 'Home' => array( - array( - 'id' => '1', - 'another_article_id' => '1', - 'advertisement_id' => '1', - 'title' => 'First Home', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ))), - 'Advertisement' => array( - 'id' => '1', - 'title' => 'First Ad', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31', - 'Home' => array( - array( - 'id' => '1', - 'another_article_id' => '1', - 'advertisement_id' => '1', - 'title' => 'First Home', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - array( - 'id' => '2', - 'another_article_id' => '3', - 'advertisement_id' => '1', - 'title' => 'Second Home', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - )))), - array( - 'Home' => array( - 'id' => '2', - 'another_article_id' => '3', - 'advertisement_id' => '1', - 'title' => 'Second Home', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'AnotherArticle' => array( - 'id' => '3', - 'title' => 'Third Article', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31', - 'Home' => array( - array( - 'id' => '2', - 'another_article_id' => '3', - 'advertisement_id' => '1', - 'title' => 'Second Home', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ))), - 'Advertisement' => array( - 'id' => '1', - 'title' => 'First Ad', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31', - 'Home' => array( - array( - 'id' => '1', - 'another_article_id' => '1', - 'advertisement_id' => '1', - 'title' => 'First Home', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - array( - 'id' => '2', - 'another_article_id' => '3', - 'advertisement_id' => '1', - 'title' => 'Second Home', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ))))); - - $this->assertEqual($result, $expected); - - - - } -/** - * testFindAllRecursiveWithHabtm method - * - * @return void - * @access public - */ - function testFindAllRecursiveWithHabtm() { - $this->loadFixtures( - 'MyCategoriesMyUsers', - 'MyCategoriesMyProducts', - 'MyCategory', - 'MyUser', - 'MyProduct' - ); - - $MyUser =& new MyUser(); - $MyUser->recursive = 2; - - $result = $MyUser->find('all'); - $expected = array( - array( - 'MyUser' => array('id' => '1', 'firstname' => 'userA'), - 'MyCategory' => array( - array( - 'id' => '1', - 'name' => 'A', - 'MyProduct' => array( - array( - 'id' => '1', - 'name' => 'book' - ))), - array( - 'id' => '3', - 'name' => 'C', - 'MyProduct' => array( - array( - 'id' => '2', - 'name' => 'computer' - ))))), - array( - 'MyUser' => array( - 'id' => '2', - 'firstname' => 'userB' - ), - 'MyCategory' => array( - array( - 'id' => '1', - 'name' => 'A', - 'MyProduct' => array( - array( - 'id' => '1', - 'name' => 'book' - ))), - array( - 'id' => '2', - 'name' => 'B', - 'MyProduct' => array( - array( - 'id' => '1', - 'name' => 'book' - ), - array( - 'id' => '2', - 'name' => 'computer' - )))))); - - $this->assertIdentical($result, $expected); - } /** * testFindSelfAssociations method * @@ -1411,152 +1645,113 @@ class ModelTest extends CakeTestCase { $this->assertEqual($result, $expected); } /** - * testPluginAssociations method + * testDynamicAssociations method * * @access public * @return void */ - function testPluginAssociations() { - $this->loadFixtures('TestPluginArticle', 'User', 'TestPluginComment'); - $TestModel =& new TestPluginArticle(); + function testDynamicAssociations() { + $this->loadFixtures('Article', 'Comment'); + $TestModel =& new Article(); + $TestModel->belongsTo = $TestModel->hasAndBelongsToMany = $TestModel->hasOne = array(); + $TestModel->hasMany['Comment'] = array_merge($TestModel->hasMany['Comment'], array( + 'foreignKey' => false, + 'conditions' => array('Comment.user_id =' => '2') + )); $result = $TestModel->find('all'); $expected = array( array( - 'TestPluginArticle' => array( - 'id' => 1, - 'user_id' => 1, - 'title' => 'First Plugin Article', - 'body' => 'First Plugin Article Body', + 'Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', 'published' => 'Y', - 'created' => '2008-09-24 10:39:23', - 'updated' => '2008-09-24 10:41:31' + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' ), - 'User' => array( - 'id' => 1, - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'TestPluginComment' => array( + 'Comment' => array( array( - 'id' => 1, - 'article_id' => 1, - 'user_id' => 2, - 'comment' => 'First Comment for First Plugin Article', + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', 'published' => 'Y', - 'created' => '2008-09-24 10:45:23', - 'updated' => '2008-09-24 10:47:31' + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' ), array( - 'id' => 2, - 'article_id' => 1, - 'user_id' => 4, - 'comment' => 'Second Comment for First Plugin Article', + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', 'published' => 'Y', - 'created' => '2008-09-24 10:47:23', - 'updated' => '2008-09-24 10:49:31' - ), - array( - 'id' => 3, - 'article_id' => 1, - 'user_id' => 1, - 'comment' => 'Third Comment for First Plugin Article', - 'published' => 'Y', - 'created' => '2008-09-24 10:49:23', - 'updated' => '2008-09-24 10:51:31' - ), - array( - 'id' => 4, - 'article_id' => 1, - 'user_id' => 1, - 'comment' => 'Fourth Comment for First Plugin Article', - 'published' => 'N', - 'created' => '2008-09-24 10:51:23', - 'updated' => '2008-09-24 10:53:31' + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' ))), array( - 'TestPluginArticle' => array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Plugin Article', - 'body' => 'Second Plugin Article Body', + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', 'published' => 'Y', - 'created' => '2008-09-24 10:41:23', - 'updated' => '2008-09-24 10:43:31' + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' ), - 'User' => array( - 'id' => 3, - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - ), - 'TestPluginComment' => array( + 'Comment' => array( array( - 'id' => 5, - 'article_id' => 2, - 'user_id' => 1, - 'comment' => 'First Comment for Second Plugin Article', + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', 'published' => 'Y', - 'created' => '2008-09-24 10:53:23', - 'updated' => '2008-09-24 10:55:31' + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' ), array( - 'id' => 6, - 'article_id' => 2, - 'user_id' => 2, - 'comment' => 'Second Comment for Second Plugin Article', + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', 'published' => 'Y', - 'created' => '2008-09-24 10:55:23', - 'updated' => '2008-09-24 10:57:31' + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' ))), array( - 'TestPluginArticle' => array( - 'id' => 3, - 'user_id' => 1, - 'title' => 'Third Plugin Article', - 'body' => 'Third Plugin Article Body', + 'Article' => array( + 'id' => '3', + 'user_id' => '1', + 'title' => 'Third Article', + 'body' => 'Third Article Body', 'published' => 'Y', - 'created' => '2008-09-24 10:43:23', - 'updated' => '2008-09-24 10:45:31' + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' ), - 'User' => array( - 'id' => 1, - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'TestPluginComment' => array() - )); + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + )))); $this->assertEqual($result, $expected); } /** - * testIdentity method - * - * @access public - * @return void - */ - function testIdentity() { - $TestModel =& new Test(); - $result = $TestModel->alias; - $expected = 'Test'; - $this->assertEqual($result, $expected); - - $TestModel =& new TestAlias(); - $result = $TestModel->alias; - $expected = 'TestAlias'; - $this->assertEqual($result, $expected); - - $TestModel =& new Test(array('alias' => 'AnotherTest')); - $result = $TestModel->alias; - $expected = 'AnotherTest'; - $this->assertEqual($result, $expected); - } -/** * testCreation method * * @access public @@ -1673,7165 +1868,383 @@ class ModelTest extends CakeTestCase { $this->assertEqual($FeaturedModel->create($data), $expected); } +} /** - * ensure that __exists is reset on create + * ModelFindTest * - * @return void - **/ - function testResetOfExistsOnCreate() { - $this->loadFixtures('Article'); - $Article =& new Article(); - $Article->id = 1; - $Article->saveField('title', 'Reset me'); - $Article->delete(); - $Article->id = 1; - $this->assertFalse($Article->exists()); - - $Article->create(); - $this->assertFalse($Article->exists()); - $Article->id = 2; - $Article->saveField('title', 'Staying alive'); - $result = $Article->read(null, 2); - $this->assertEqual($result['Article']['title'], 'Staying alive'); - } + * @package cake + * @subpackage cake.tests.cases.libs.model + */ +class ModelReadTest extends BaseModelTest { /** - * testCreationOfEmptyRecord method + * testFetchingNonUniqueFKJoinTableRecords() + * + * Tests if the results are properly returned in the case there are non-unique FK's + * in the join table but another fields value is different. For example: + * something_id | something_else_id | doomed = 1 + * something_id | something_else_id | doomed = 0 + * Should return both records and not just one. * * @access public * @return void */ - function testCreationOfEmptyRecord() { - $this->loadFixtures('Author'); - $TestModel =& new Author(); - $this->assertEqual($TestModel->find('count'), 4); - - $TestModel->deleteAll(true, false, false); - $this->assertEqual($TestModel->find('count'), 0); - - $result = $TestModel->save(); - $this->assertTrue(isset($result['Author']['created'])); - $this->assertTrue(isset($result['Author']['updated'])); - $this->assertEqual($TestModel->find('count'), 1); - } -/** - * testCreateWithPKFiltering method - * - * @access public - * @return void - */ - function testCreateWithPKFiltering() { - $TestModel =& new Article(); - $data = array( - 'id' => 5, - 'user_id' => 2, - 'title' => 'My article', - 'body' => 'Some text' - ); - - $result = $TestModel->create($data); - $expected = array( - 'Article' => array( - 'published' => 'N', - 'id' => 5, - 'user_id' => 2, - 'title' => 'My article', - 'body' => 'Some text' - )); - - $this->assertEqual($result, $expected); - $this->assertEqual($TestModel->id, 5); - - $result = $TestModel->create($data, true); - $expected = array( - 'Article' => array( - 'published' => 'N', - 'id' => false, - 'user_id' => 2, - 'title' => 'My article', - 'body' => 'Some text' - )); - - $this->assertEqual($result, $expected); - $this->assertFalse($TestModel->id); - - $result = $TestModel->create(array('Article' => $data), true); - $expected = array( - 'Article' => array( - 'published' => 'N', - 'id' => false, - 'user_id' => 2, - 'title' => 'My article', - 'body' => 'Some text' - )); - - $this->assertEqual($result, $expected); - $this->assertFalse($TestModel->id); - - $data = array( - 'id' => 6, - 'user_id' => 2, - 'title' => 'My article', - 'body' => 'Some text', - 'created' => '1970-01-01 00:00:00', - 'updated' => '1970-01-01 12:00:00', - 'modified' => '1970-01-01 12:00:00' - ); - - $result = $TestModel->create($data); - $expected = array( - 'Article' => array( - 'published' => 'N', - 'id' => 6, - 'user_id' => 2, - 'title' => 'My article', - 'body' => 'Some text', - 'created' => '1970-01-01 00:00:00', - 'updated' => '1970-01-01 12:00:00', - 'modified' => '1970-01-01 12:00:00' - )); - $this->assertEqual($result, $expected); - $this->assertEqual($TestModel->id, 6); - - $result = $TestModel->create(array( - 'Article' => array_diff_key($data, array( - 'created' => true, - 'updated' => true, - 'modified' => true - ))), true); - $expected = array( - 'Article' => array( - 'published' => 'N', - 'id' => false, - 'user_id' => 2, - 'title' => 'My article', - 'body' => 'Some text' - )); - $this->assertEqual($result, $expected); - $this->assertFalse($TestModel->id); - } -/** - * testCreationWithMultipleData method - * - * @access public - * @return void - */ - function testCreationWithMultipleData() { - $this->loadFixtures('Article', 'Comment'); - $Article =& new Article(); - $Comment =& new Comment(); - - $articles = $Article->find('all', array( - 'fields' => array('id','title'), - 'recursive' => -1 - )); - - $comments = $Comment->find('all', array( - 'fields' => array('id','article_id','user_id','comment','published'), 'recursive' => -1)); - - $this->assertEqual($articles, array( - array('Article' => array( - 'id' => 1, - 'title' => 'First Article' - )), - array('Article' => array( - 'id' => 2, - 'title' => 'Second Article' - )), - array('Article' => array( - 'id' => 3, - 'title' => 'Third Article' - )))); - - $this->assertEqual($comments, array( - array('Comment' => array( - 'id' => 1, - 'article_id' => 1, - 'user_id' => 2, - 'comment' => 'First Comment for First Article', - 'published' => 'Y' - )), - array('Comment' => array( - 'id' => 2, - 'article_id' => 1, - 'user_id' => 4, - 'comment' => 'Second Comment for First Article', - 'published' => 'Y' - )), - array('Comment' => array( - 'id' => 3, - 'article_id' => 1, - 'user_id' => 1, - 'comment' => 'Third Comment for First Article', - 'published' => 'Y' - )), - array('Comment' => array( - 'id' => 4, - 'article_id' => 1, - 'user_id' => 1, - 'comment' => 'Fourth Comment for First Article', - 'published' => 'N' - )), - array('Comment' => array( - 'id' => 5, - 'article_id' => 2, - 'user_id' => 1, - 'comment' => 'First Comment for Second Article', - 'published' => 'Y' - )), - array('Comment' => array( - 'id' => 6, - 'article_id' => 2, - 'user_id' => 2, - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y' - )))); - - $data = array( - 'Comment' => array( - 'article_id' => 2, - 'user_id' => 4, - 'comment' => 'Brand New Comment', - 'published' => 'N' - ), - 'Article' => array( - 'id' => 2, - 'title' => 'Second Article Modified' - )); - - $result = $Comment->create($data); - - $this->assertTrue($result); - $result = $Comment->save(); - $this->assertTrue($result); - - $articles = $Article->find('all', array( - 'fields' => array('id','title'), - 'recursive' => -1 - )); - - $comments = $Comment->find('all', array( - 'fields' => array('id','article_id','user_id','comment','published'), - 'recursive' => -1 - )); - - $this->assertEqual($articles, array( - array('Article' => array( - 'id' => 1, - 'title' => 'First Article' - )), - array('Article' => array( - 'id' => 2, - 'title' => 'Second Article' - )), - array('Article' => array( - 'id' => 3, - 'title' => 'Third Article' - )))); - - $this->assertEqual($comments, array( - array('Comment' => array( - 'id' => 1, - 'article_id' => 1, - 'user_id' => 2, - 'comment' => 'First Comment for First Article', - 'published' => 'Y' - )), - array('Comment' => array( - 'id' => 2, - 'article_id' => 1, - 'user_id' => 4, - 'comment' => 'Second Comment for First Article', - 'published' => 'Y' - )), - array('Comment' => array( - 'id' => 3, - 'article_id' => 1, - 'user_id' => 1, - 'comment' => 'Third Comment for First Article', - 'published' => 'Y' - )), - array('Comment' => array( - 'id' => 4, - 'article_id' => 1, - 'user_id' => 1, - 'comment' => 'Fourth Comment for First Article', - 'published' => 'N' - )), - array('Comment' => array( - 'id' => 5, - 'article_id' => 2, - 'user_id' => 1, - 'comment' => 'First Comment for Second Article', - 'published' => 'Y' - )), - array('Comment' => array( - 'id' => 6, - 'article_id' => 2, - 'user_id' => 2, 'comment' => - 'Second Comment for Second Article', - 'published' => 'Y' - )), - array('Comment' => array( - 'id' => 7, - 'article_id' => 2, - 'user_id' => 4, - 'comment' => 'Brand New Comment', - 'published' => 'N' - )))); - - } -/** - * testCreationWithMultipleDataSameModel method - * - * @access public - * @return void - */ - function testCreationWithMultipleDataSameModel() { - $this->loadFixtures('Article'); - $Article =& new Article(); - $SecondaryArticle =& new Article(); - - $result = $Article->field('title', array('id' => 1)); - $this->assertEqual($result, 'First Article'); - - $data = array( - 'Article' => array( - 'user_id' => 2, - 'title' => 'Brand New Article', - 'body' => 'Brand New Article Body', - 'published' => 'Y' - ), - 'SecondaryArticle' => array( - 'id' => 1 - )); - - $Article->create(); - $result = $Article->save($data); - $this->assertTrue($result); - - $result = $Article->getInsertID(); - $this->assertTrue(!empty($result)); - - $result = $Article->field('title', array('id' => 1)); - $this->assertEqual($result, 'First Article'); - - $articles = $Article->find('all', array( - 'fields' => array('id','title'), - 'recursive' => -1 - )); - - $this->assertEqual($articles, array( - array('Article' => array( - 'id' => 1, - 'title' => 'First Article' - )), - array('Article' => array( - 'id' => 2, - 'title' => 'Second Article' - )), - array('Article' => array( - 'id' => 3, - 'title' => 'Third Article' - )), - array('Article' => array( - 'id' => 4, - 'title' => 'Brand New Article' - )))); - } -/** - * testCreationWithMultipleDataSameModelManualInstances method - * - * @access public - * @return void - */ - function testCreationWithMultipleDataSameModelManualInstances() { - $this->loadFixtures('PrimaryModel'); - $Primary =& new PrimaryModel(); - $Secondary =& new PrimaryModel(); - - $result = $Primary->field('primary_name', array('id' => 1)); - $this->assertEqual($result, 'Primary Name Existing'); - - $data = array( - 'PrimaryModel' => array( - 'primary_name' => 'Primary Name New' - ), - 'SecondaryModel' => array( - 'id' => array(1) - )); - - $Primary->create(); - $result = $Primary->save($data); - $this->assertTrue($result); - - $result = $Primary->field('primary_name', array('id' => 1)); - $this->assertEqual($result, 'Primary Name Existing'); - - $result = $Primary->getInsertID(); - $this->assertTrue(!empty($result)); - - $result = $Primary->field('primary_name', array('id' => $result)); - $this->assertEqual($result, 'Primary Name New'); - - $result = $Primary->find('count'); - $this->assertEqual($result, 2); - } -/** - * testReadFakeThread method - * - * @access public - * @return void - */ - function testReadFakeThread() { - $this->loadFixtures('CategoryThread'); - $TestModel =& new CategoryThread(); - - $fullDebug = $this->db->fullDebug; - $this->db->fullDebug = true; - $TestModel->recursive = 6; - $TestModel->id = 7; - $result = $TestModel->read(); - $expected = array( - 'CategoryThread' => array( - 'id' => 7, - 'parent_id' => 6, - 'name' => 'Category 2.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'ParentCategory' => array( - 'id' => 6, - 'parent_id' => 5, - 'name' => 'Category 2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 5, - 'parent_id' => 4, - 'name' => 'Category 1.1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 4, - 'parent_id' => 3, - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 3, - 'parent_id' => 2, - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ))))))); - - $this->db->fullDebug = $fullDebug; - $this->assertEqual($result, $expected); - } -/** - * testFindFakeThread method - * - * @access public - * @return void - */ - function testFindFakeThread() { - $this->loadFixtures('CategoryThread'); - $TestModel =& new CategoryThread(); - - $fullDebug = $this->db->fullDebug; - $this->db->fullDebug = true; - $TestModel->recursive = 6; - $result = $TestModel->find(array('CategoryThread.id' => 7)); - - $expected = array( - 'CategoryThread' => array( - 'id' => 7, - 'parent_id' => 6, - 'name' => 'Category 2.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'ParentCategory' => array( - 'id' => 6, - 'parent_id' => 5, - 'name' => 'Category 2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 5, - 'parent_id' => 4, - 'name' => 'Category 1.1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 4, - 'parent_id' => 3, - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 3, - 'parent_id' => 2, - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ))))))); - - $this->db->fullDebug = $fullDebug; - $this->assertEqual($result, $expected); - } -/** - * testFindAllFakeThread method - * - * @access public - * @return void - */ - function testFindAllFakeThread() { - $this->loadFixtures('CategoryThread'); - $TestModel =& new CategoryThread(); - - $fullDebug = $this->db->fullDebug; - $this->db->fullDebug = true; - $TestModel->recursive = 6; - $result = $TestModel->find('all', null, null, 'CategoryThread.id ASC'); - $expected = array( - array( - 'CategoryThread' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'ParentCategory' => array( - 'id' => null, - 'parent_id' => null, - 'name' => null, - 'created' => null, - 'updated' => null, - 'ParentCategory' => array() - )), - array( - 'CategoryThread' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'ParentCategory' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array() - )), - array( - 'CategoryThread' => array( - 'id' => 3, - 'parent_id' => 2, - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'ParentCategory' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array() - ))), - array( - 'CategoryThread' => array( - 'id' => 4, - 'parent_id' => 3, - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'ParentCategory' => array( - 'id' => 3, - 'parent_id' => 2, - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array() - )))), - array( - 'CategoryThread' => array( - 'id' => 5, - 'parent_id' => 4, - 'name' => 'Category 1.1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'ParentCategory' => array( - 'id' => 4, - 'parent_id' => 3, - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 3, - 'parent_id' => 2, - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array() - ))))), - array( - 'CategoryThread' => array( - 'id' => 6, - 'parent_id' => 5, - 'name' => 'Category 2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'ParentCategory' => array( - 'id' => 5, - 'parent_id' => 4, - 'name' => 'Category 1.1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 4, - 'parent_id' => 3, - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 3, - 'parent_id' => 2, - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array() - )))))), - array( - 'CategoryThread' => array( - 'id' => 7, - 'parent_id' => 6, - 'name' => 'Category 2.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'ParentCategory' => array( - 'id' => 6, - 'parent_id' => 5, - 'name' => 'Category 2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 5, - 'parent_id' => 4, - 'name' => 'Category 1.1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 4, - 'parent_id' => 3, - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 3, - 'parent_id' => 2, - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31', - 'ParentCategory' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - )))))))); - - $this->db->fullDebug = $fullDebug; - $this->assertEqual($result, $expected); - } -/** - * testConditionalNumerics method - * - * @access public - * @return void - */ - function testConditionalNumerics() { - $this->loadFixtures('NumericArticle'); - $NumericArticle =& new NumericArticle(); - $data = array('title' => '12345abcde'); - $result = $NumericArticle->find($data); - $this->assertTrue(!empty($result)); - - $data = array('title' => '12345'); - $result = $NumericArticle->find($data); - $this->assertTrue(empty($result)); - } - -/** - * test find('all') method - * - * @access public - * @return void - */ - function testFindAll() { - $this->loadFixtures('User'); - $TestModel =& new User(); - $TestModel->cacheQueries = false; - - $result = $TestModel->find('all'); - $expected = array( - array('User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31')), - array('User' => array('id' => '2', 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31')), - array('User' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31')), - array('User' => array('id' => '4', 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'))); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('all', array('conditions' => 'User.id > 2')); - $expected = array( - array('User' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31')), - array('User' => array('id' => '4', 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'))); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('all', array('conditions' => array('User.id !=' => '0', 'User.user LIKE' => '%arr%'))); - $expected = array( - array('User' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31')), - array('User' => array('id' => '4', 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'))); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('all', array('conditions' => array('User.id' => '0'))); - $expected = array(); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('all', array('conditions' => array('or' => array('User.id' => '0', 'User.user LIKE' => '%a%')))); - $expected = array( - array('User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31')), - array('User' => array('id' => '2', 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31')), - array('User' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31')), - array('User' => array('id' => '4', 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'))); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('all', array('fields' => 'User.id, User.user')); - $expected = array( - array('User' => array('id' => '1', 'user' => 'mariano')), - array('User' => array('id' => '2', 'user' => 'nate')), - array('User' => array('id' => '3', 'user' => 'larry')), - array('User' => array('id' => '4', 'user' => 'garrett'))); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('all', array('fields' => 'User.user', 'order' => 'User.user ASC')); - $expected = array( - array('User' => array('user' => 'garrett')), - array('User' => array('user' => 'larry')), - array('User' => array('user' => 'mariano')), - array('User' => array('user' => 'nate'))); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('all', array('fields' => 'User.user', 'order' => 'User.user DESC')); - $expected = array( - array('User' => array('user' => 'nate')), - array('User' => array('user' => 'mariano')), - array('User' => array('user' => 'larry')), - array('User' => array('user' => 'garrett'))); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('all', array('limit' => 3, 'page' => 1)); - - $expected = array( - array('User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31')), - array('User' => array('id' => '2', 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31')), - array('User' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'))); - $this->assertEqual($result, $expected); - - $ids = array(4 => 1, 5 => 3); - $result = $TestModel->find('all', array('conditions' => array('User.id' => $ids), 'order' => 'User.id')); - $expected = array( - array('User' => array('id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31')), - array('User' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31')), - ); - $this->assertEqual($result, $expected); - - // These tests are expected to fail on SQL Server since the LIMIT/OFFSET - // hack can't handle small record counts. - if ($this->db->config['driver'] != 'mssql') { - $result = $TestModel->find('all', array('limit' => 3, 'page' => 2)); - $expected = array( - array('User' => array('id' => '4', 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'))); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('all', array('limit' => 3, 'page' => 3)); - $expected = array(); - $this->assertEqual($result, $expected); - } - } -/** - * test find('list') method - * - * @access public - * @return void - */ - function testGenerateFindList() { - $this->loadFixtures('Article', 'Apple', 'Post', 'Author', 'User'); - - $TestModel =& new Article(); - $TestModel->displayField = 'title'; - - $result = $TestModel->find('list', array( - 'order' => 'Article.title ASC' - )); - - $expected = array( - 1 => 'First Article', - 2 => 'Second Article', - 3 => 'Third Article' - ); - $this->assertEqual($result, $expected); - - $db =& ConnectionManager::getDataSource('test_suite'); - if ($db->config['driver'] == 'mysql') { - $result = $TestModel->find('list', array( - 'order' => array('FIELD(Article.id, 3, 2) ASC', 'Article.title ASC') - )); - $expected = array( - 1 => 'First Article', - 3 => 'Third Article', - 2 => 'Second Article' - ); - $this->assertEqual($result, $expected); - } - - $result = Set::combine( - $TestModel->find('all', array( - 'order' => 'Article.title ASC', - 'fields' => array('id', 'title') - )), - '{n}.Article.id', '{n}.Article.title' - ); - $expected = array( - 1 => 'First Article', - 2 => 'Second Article', - 3 => 'Third Article' - ); - $this->assertEqual($result, $expected); - - $result = Set::combine( - $TestModel->find('all', array( - 'order' => 'Article.title ASC' - )), - '{n}.Article.id', '{n}.Article' - ); - $expected = array( - 1 => array( - 'id' => 1, - 'user_id' => 1, - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 2 => array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 3 => array( - 'id' => 3, - 'user_id' => 1, - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - )); - - $this->assertEqual($result, $expected); - - $result = Set::combine( - $TestModel->find('all', array( - 'order' => 'Article.title ASC' - )), - '{n}.Article.id', '{n}.Article', '{n}.Article.user_id' - ); - $expected = array( - 1 => array( - 1 => array( - 'id' => 1, - 'user_id' => 1, - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 3 => array( - 'id' => 3, - 'user_id' => 1, - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - )), - 3 => array( - 2 => array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ))); - - $this->assertEqual($result, $expected); - - $result = Set::combine( - $TestModel->find('all', array( - 'order' => 'Article.title ASC', - 'fields' => array('id', 'title', 'user_id') - )), - '{n}.Article.id', '{n}.Article.title', '{n}.Article.user_id' - ); - - $expected = array( - 1 => array( - 1 => 'First Article', - 3 => 'Third Article' - ), - 3 => array( - 2 => 'Second Article' - )); - $this->assertEqual($result, $expected); - - $TestModel =& new Apple(); - $expected = array( - 1 => 'Red Apple 1', - 2 => 'Bright Red Apple', - 3 => 'green blue', - 4 => 'Test Name', - 5 => 'Blue Green', - 6 => 'My new apple', - 7 => 'Some odd color' - ); - - $this->assertEqual($TestModel->find('list'), $expected); - $this->assertEqual($TestModel->Parent->find('list'), $expected); - - $TestModel =& new Post(); - $result = $TestModel->find('list', array( - 'fields' => 'Post.title' - )); - $expected = array( - 1 => 'First Post', - 2 => 'Second Post', - 3 => 'Third Post' - ); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('list', array( - 'fields' => 'title' - )); - $expected = array( - 1 => 'First Post', - 2 => 'Second Post', - 3 => 'Third Post' - ); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('list', array( - 'fields' => array('title', 'id') - )); - $expected = array( - 'First Post' => '1', - 'Second Post' => '2', - 'Third Post' => '3' - ); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('list', array( - 'fields' => array('title', 'id', 'created') - )); - $expected = array( - '2007-03-18 10:39:23' => array( - 'First Post' => '1' - ), - '2007-03-18 10:41:23' => array( - 'Second Post' => '2' - ), - '2007-03-18 10:43:23' => array( - 'Third Post' => '3' - ), - ); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('list', array( - 'fields' => array('Post.body') - )); - $expected = array( - 1 => 'First Post Body', - 2 => 'Second Post Body', - 3 => 'Third Post Body' - ); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('list', array( - 'fields' => array('Post.title', 'Post.body') - )); - $expected = array( - 'First Post' => 'First Post Body', - 'Second Post' => 'Second Post Body', - 'Third Post' => 'Third Post Body' - ); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('list', array( - 'fields' => array('Post.id', 'Post.title', 'Author.user'), - 'recursive' => 1 - )); - $expected = array( - 'mariano' => array( - 1 => 'First Post', - 3 => 'Third Post' - ), - 'larry' => array( - 2 => 'Second Post' - )); - $this->assertEqual($result, $expected); - - $TestModel =& new User(); - $result = $TestModel->find('list', array( - 'fields' => array('User.user', 'User.password') - )); - $expected = array( - 'mariano' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'nate' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'larry' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'garrett' => '5f4dcc3b5aa765d61d8327deb882cf99' - ); - $this->assertEqual($result, $expected); - - $TestModel =& new ModifiedAuthor(); - $result = $TestModel->find('list', array( - 'fields' => array('Author.id', 'Author.user') - )); - $expected = array( - 1 => 'mariano (CakePHP)', - 2 => 'nate (CakePHP)', - 3 => 'larry (CakePHP)', - 4 => 'garrett (CakePHP)' - ); - $this->assertEqual($result, $expected); - } -/** - * testRecordExists method - * - * @access public - * @return void - */ - function testRecordExists() { - $this->loadFixtures('User'); - $TestModel =& new User(); - - $this->assertFalse($TestModel->exists()); - $TestModel->read(null, 1); - $this->assertTrue($TestModel->exists()); - $TestModel->create(); - $this->assertFalse($TestModel->exists()); - $TestModel->id = 4; - $this->assertTrue($TestModel->exists()); - - $TestModel =& new TheVoid(); - $this->assertFalse($TestModel->exists()); - $TestModel->id = 5; - $this->assertFalse($TestModel->exists()); - } -/** - * testFindField method - * - * @access public - * @return void - */ - function testFindField() { - $this->loadFixtures('User'); - $TestModel =& new User(); - - $TestModel->id = 1; - $result = $TestModel->field('user'); - $this->assertEqual($result, 'mariano'); - - $result = $TestModel->field('User.user'); - $this->assertEqual($result, 'mariano'); - - $TestModel->id = false; - $result = $TestModel->field('user', array( - 'user' => 'mariano' - )); - $this->assertEqual($result, 'mariano'); - - $result = $TestModel->field('COUNT(*) AS count', true); - $this->assertEqual($result, 4); - - $result = $TestModel->field('COUNT(*)', true); - $this->assertEqual($result, 4); - } -/** - * testFindUnique method - * - * @access public - * @return void - */ - function testFindUnique() { - $this->loadFixtures('User'); - $TestModel =& new User(); - - $this->assertFalse($TestModel->isUnique(array( - 'user' => 'nate' - ))); - $TestModel->id = 2; - $this->assertTrue($TestModel->isUnique(array( - 'user' => 'nate' - ))); - $this->assertFalse($TestModel->isUnique(array( - 'user' => 'nate', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' - ))); - } -/** - * testUpdateExisting method - * - * @access public - * @return void - */ - function testUpdateExisting() { - $this->loadFixtures('User', 'Article', 'Comment'); - $TestModel =& new User(); - $TestModel->create(); - - $TestModel->save(array( - 'User' => array( - 'user' => 'some user', - 'password' => 'some password' - ))); - $this->assertTrue(is_int($TestModel->id) || (intval($TestModel->id) === 5)); - $id = $TestModel->id; - - $TestModel->save(array( - 'User' => array( - 'user' => 'updated user' - ))); - $this->assertEqual($TestModel->id, $id); - - $result = $TestModel->findById($id); - $this->assertEqual($result['User']['user'], 'updated user'); - $this->assertEqual($result['User']['password'], 'some password'); - - $Article =& new Article(); - $Comment =& new Comment(); - $data = array( - 'Comment' => array( - 'id' => 1, - 'comment' => 'First Comment for First Article' - ), - 'Article' => array( - 'id' => 2, - 'title' => 'Second Article' - )); - - $result = $Article->save($data); - $this->assertTrue($result); - - $result = $Comment->save($data); - $this->assertTrue($result); - } -/** - * testUpdateMultiple method - * - * @access public - * @return void - */ - function testUpdateMultiple() { - $this->loadFixtures('Comment', 'Article', 'User', 'CategoryThread'); - $TestModel =& new Comment(); - $result = Set::extract($TestModel->find('all'), '{n}.Comment.user_id'); - $expected = array('2', '4', '1', '1', '1', '2'); - $this->assertEqual($result, $expected); - - $TestModel->updateAll(array('Comment.user_id' => 5), array('Comment.user_id' => 2)); - $result = Set::combine($TestModel->find('all'), '{n}.Comment.id', '{n}.Comment.user_id'); - $expected = array(1 => 5, 2 => 4, 3 => 1, 4 => 1, 5 => 1, 6 => 5); - $this->assertEqual($result, $expected); - - $result = $TestModel->updateAll( - array('Comment.comment' => "'Updated today'"), - array('Comment.user_id' => 5) - ); - $this->assertTrue($result); - $result = Set::extract( - $TestModel->find('all', array( - 'conditions' => array( - 'Comment.user_id' => 5 - ))), - '{n}.Comment.comment' - ); - $expected = array_fill(0, 2, 'Updated today'); - $this->assertEqual($result, $expected); - } -/** - * testUpdateWithCalculation method - * - * @access public - * @return void - */ - function testUpdateWithCalculation() { - $this->loadFixtures('DataTest'); - $model =& new DataTest(); - $result = $model->saveAll(array( - array('count' => 5, 'float' => 1.1), - array('count' => 3, 'float' => 1.2), - array('count' => 4, 'float' => 1.3), - array('count' => 1, 'float' => 2.0), - )); - $this->assertTrue($result); - - $result = Set::extract('/DataTest/count', $model->find('all', array('fields' => 'count'))); - $this->assertEqual($result, array(5, 3, 4, 1)); - - $this->assertTrue($model->updateAll(array('count' => 'count + 2'))); - $result = Set::extract('/DataTest/count', $model->find('all', array('fields' => 'count'))); - $this->assertEqual($result, array(7, 5, 6, 3)); - - $this->assertTrue($model->updateAll(array('DataTest.count' => 'DataTest.count - 1'))); - $result = Set::extract('/DataTest/count', $model->find('all', array('fields' => 'count'))); - $this->assertEqual($result, array(6, 4, 5, 2)); - } -/** - * testBindUnbind method - * - * @access public - * @return void - */ - function testBindUnbind() { - $this->loadFixtures('User', 'Comment', 'FeatureSet'); - $TestModel =& new User(); - - $result = $TestModel->hasMany; - $expected = array(); - $this->assertEqual($result, $expected); - - $result = $TestModel->bindModel(array('hasMany' => array('Comment'))); - $this->assertTrue($result); - - $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user' - )); - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' - ), - 'Comment' => array( - array( - 'id' => '3', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Third Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:49:23', - 'updated' => '2007-03-18 10:51:31' - ), - array( - 'id' => '4', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Fourth Comment for First Article', - 'published' => 'N', - 'created' => '2007-03-18 10:51:23', - 'updated' => '2007-03-18 10:53:31' - ), - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31' - ))), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate' - ), - 'Comment' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - ))), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry' - ), - 'Comment' => array() - ), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett' - ), - 'Comment' => array( - array( - 'id' => '2', - 'article_id' => '1', - 'user_id' => '4', - 'comment' => 'Second Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:47:23', - 'updated' => '2007-03-18 10:49:31' - )))); - - $this->assertEqual($result, $expected); - - $TestModel->resetAssociations(); - $result = $TestModel->hasMany; - $this->assertEqual($result, array()); - - $result = $TestModel->bindModel(array('hasMany' => array('Comment')), false); - $this->assertTrue($result); - - $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user' - )); - - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' - ), - 'Comment' => array( - array( - 'id' => '3', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Third Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:49:23', - 'updated' => '2007-03-18 10:51:31' - ), - array( - 'id' => '4', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Fourth Comment for First Article', - 'published' => 'N', - 'created' => '2007-03-18 10:51:23', - 'updated' => '2007-03-18 10:53:31' - ), - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31' - ))), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate' - ), - 'Comment' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - ))), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry' - ), - 'Comment' => array() - ), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett' - ), - 'Comment' => array( - array( - 'id' => '2', - 'article_id' => '1', - 'user_id' => '4', - 'comment' => 'Second Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:47:23', - 'updated' => '2007-03-18 10:49:31' - )))); - - $this->assertEqual($result, $expected); - - $result = $TestModel->hasMany; - $expected = array( - 'Comment' => array( - 'className' => 'Comment', - 'foreignKey' => 'user_id', - 'conditions' => null, - 'fields' => null, - 'order' => null, - 'limit' => null, - 'offset' => null, - 'dependent' => null, - 'exclusive' => null, - 'finderQuery' => null, - 'counterQuery' => null - )); - $this->assertEqual($result, $expected); - - $result = $TestModel->unbindModel(array('hasMany' => array('Comment'))); - $this->assertTrue($result); - - $result = $TestModel->hasMany; - $expected = array(); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user' - )); - $expected = array( - array('User' => array('id' => '1', 'user' => 'mariano')), - array('User' => array('id' => '2', 'user' => 'nate')), - array('User' => array('id' => '3', 'user' => 'larry')), - array('User' => array('id' => '4', 'user' => 'garrett'))); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user' - )); - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' - ), - 'Comment' => array( - array( - 'id' => '3', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Third Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:49:23', - 'updated' => '2007-03-18 10:51:31' - ), - array( - 'id' => '4', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Fourth Comment for First Article', - 'published' => 'N', - 'created' => '2007-03-18 10:51:23', - 'updated' => '2007-03-18 10:53:31' - ), - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31' - ))), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate' - ), - 'Comment' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - ))), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry' - ), - 'Comment' => array() - ), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett' - ), - 'Comment' => array( - array( - 'id' => '2', - 'article_id' => '1', - 'user_id' => '4', - 'comment' => - 'Second Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:47:23', - 'updated' => '2007-03-18 10:49:31' - )))); - $this->assertEqual($result, $expected); - - $result = $TestModel->unbindModel(array('hasMany' => array('Comment')), false); - $this->assertTrue($result); - - $result = $TestModel->find('all', array('fields' => 'User.id, User.user')); - $expected = array( - array('User' => array('id' => '1', 'user' => 'mariano')), - array('User' => array('id' => '2', 'user' => 'nate')), - array('User' => array('id' => '3', 'user' => 'larry')), - array('User' => array('id' => '4', 'user' => 'garrett'))); - $this->assertEqual($result, $expected); - - $result = $TestModel->hasMany; - $expected = array(); - $this->assertEqual($result, $expected); - - $result = $TestModel->bindModel(array('hasMany' => array( - 'Comment' => array('className' => 'Comment', 'conditions' => 'Comment.published = \'Y\'') - ))); - $this->assertTrue($result); - - $result = $TestModel->find('all', array('fields' => 'User.id, User.user')); - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' - ), - 'Comment' => array( - array( - 'id' => '3', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Third Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:49:23', - 'updated' => '2007-03-18 10:51:31' - ), - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31' - ))), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate' - ), - 'Comment' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - ))), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry' - ), - 'Comment' => array() - ), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett' - ), - 'Comment' => array( - array( - 'id' => '2', - 'article_id' => '1', - 'user_id' => '4', - 'comment' => 'Second Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:47:23', - 'updated' => '2007-03-18 10:49:31' - )))); - - $this->assertEqual($result, $expected); - - $TestModel2 =& new DeviceType(); - - $expected = array( - 'className' => 'FeatureSet', - 'foreignKey' => 'feature_set_id', - 'conditions' => '', - 'fields' => '', - 'order' => '', - 'counterCache' => '' - ); - $this->assertEqual($TestModel2->belongsTo['FeatureSet'], $expected); - - $TestModel2->bind('FeatureSet', array( - 'conditions' => array('active' => true) - )); - $expected['conditions'] = array('active' => true); - $this->assertEqual($TestModel2->belongsTo['FeatureSet'], $expected); - - $TestModel2->bind('FeatureSet', array( - 'foreignKey' => false, - 'conditions' => array('Feature.name' => 'DeviceType.name') - )); - $expected['conditions'] = array('Feature.name' => 'DeviceType.name'); - $expected['foreignKey'] = false; - $this->assertEqual($TestModel2->belongsTo['FeatureSet'], $expected); - - $TestModel2->bind('NewFeatureSet', array( - 'type' => 'hasMany', - 'className' => 'FeatureSet', - 'conditions' => array('active' => true) - )); - $expected = array( - 'className' => 'FeatureSet', - 'conditions' => array('active' => true), - 'foreignKey' => 'device_type_id', - 'fields' => '', - 'order' => '', - 'limit' => '', - 'offset' => '', - 'dependent' => '', - 'exclusive' => '', - 'finderQuery' => '', - 'counterQuery' => '' - ); - $this->assertEqual($TestModel2->hasMany['NewFeatureSet'], $expected); - $this->assertTrue(is_object($TestModel2->NewFeatureSet)); - } -/** - * testBindMultipleTimes method - * - * @access public - * @return void - */ - function testBindMultipleTimes() { - $this->loadFixtures('User', 'Comment', 'Article'); - $TestModel =& new User(); - - $result = $TestModel->hasMany; - $expected = array(); - $this->assertEqual($result, $expected); - - $result = $TestModel->bindModel(array( - 'hasMany' => array( - 'Items' => array('className' => 'Comment') - ))); - $this->assertTrue($result); - - $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user' - )); - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' - ), - 'Items' => array( - array( - 'id' => '3', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Third Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:49:23', - 'updated' => '2007-03-18 10:51:31' - ), - array( - 'id' => '4', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Fourth Comment for First Article', - 'published' => 'N', - 'created' => '2007-03-18 10:51:23', - 'updated' => '2007-03-18 10:53:31' - ), - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31' - ))), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate' - ), - 'Items' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - ))), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry' - ), - 'Items' => array() - ), - array( - 'User' => array( - 'id' => '4', 'user' => 'garrett'), - 'Items' => array( - array( - 'id' => '2', - 'article_id' => '1', - 'user_id' => '4', - 'comment' => 'Second Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:47:23', - 'updated' => '2007-03-18 10:49:31' - )))); - $this->assertEqual($result, $expected); - - $result = $TestModel->bindModel(array( - 'hasMany' => array( - 'Items' => array('className' => 'Article') - ))); - $this->assertTrue($result); - - $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user' - )); - $expected = array( - array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' - ), - 'Items' => array( - array( - 'id' => 1, - 'user_id' => 1, - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - array( - 'id' => 3, - 'user_id' => 1, - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ))), - array( - 'User' => array( - 'id' => '2', - 'user' => 'nate' - ), - 'Items' => array() - ), - array( - 'User' => array( - 'id' => '3', - 'user' => 'larry' - ), - 'Items' => array( - array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ))), - array( - 'User' => array( - 'id' => '4', - 'user' => 'garrett' - ), - 'Items' => array() - )); - $this->assertEqual($result, $expected); - } - -/** - * test that bindModel behaves with Custom primary Key associations - * - * @return void - **/ - function bindWithCustomPrimaryKey() { - $this->loadFixtures('Story', 'StoriesTag', 'Tag'); - $Model =& ClassRegistry::init('StoriesTag'); - $Model->bindModel(array( - 'belongsTo' => array( - 'Tag' => array( - 'className' => 'Tag', - 'foreignKey' => 'story' - )))); - - $result = $Model->find('all'); - $this->assertFalse(empty($result)); - } - -/** - * test find('count') method - * - * @access public - * @return void - */ - function testFindCount() { - $this->loadFixtures('User', 'Project'); - - $TestModel =& new User(); - $result = $TestModel->find('count'); - $this->assertEqual($result, 4); - - $fullDebug = $this->db->fullDebug; - $this->db->fullDebug = true; - $TestModel->order = 'User.id'; - $this->db->_queriesLog = array(); - $result = $TestModel->find('count'); - $this->assertEqual($result, 4); - - $this->assertTrue(isset($this->db->_queriesLog[0]['query'])); - $this->assertNoPattern('/ORDER\s+BY/', $this->db->_queriesLog[0]['query']); - } - -/** - * test find with COUNT(DISTINCT field) - * - * @return void - **/ - function testFindCountDistinct() { - $skip = $this->skipIf( - $this->db->config['driver'] == 'sqlite', - 'SELECT COUNT(DISTINCT field) is not compatible with SQLite' - ); - if ($skip) { - return; - } - $this->loadFixtures('Project'); - $TestModel =& new Project(); - $TestModel->create(array('name' => 'project')) && $TestModel->save(); - $TestModel->create(array('name' => 'project')) && $TestModel->save(); - $TestModel->create(array('name' => 'project')) && $TestModel->save(); - - $result = $TestModel->find('count', array('fields' => 'DISTINCT name')); - $this->assertEqual($result, 4); - } -/** - * Test find(count) with Db::expression - * - * @access public - * @return void - */ - function testFindCountWithDbExpressions() { - if ($this->skipIf($this->db->config['driver'] == 'postgres', '%s testFindCountWithExpressions is not compatible with Postgres')) { - return; - } - $this->loadFixtures('Project'); - $db = ConnectionManager::getDataSource('test_suite'); - $TestModel =& new Project(); - - $result = $TestModel->find('count', array('conditions' => array( - $db->expression('Project.name = \'Project 3\'') - ))); - $this->assertEqual($result, 1); - - $result = $TestModel->find('count', array('conditions' => array( - 'Project.name' => $db->expression('\'Project 3\'') - ))); - $this->assertEqual($result, 1); - } -/** - * testFindMagic method - * - * @access public - * @return void - */ - function testFindMagic() { - $this->loadFixtures('User'); - $TestModel =& new User(); - - $result = $TestModel->findByUser('mariano'); - $expected = array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - )); - $this->assertEqual($result, $expected); - - $result = $TestModel->findByPassword('5f4dcc3b5aa765d61d8327deb882cf99'); - $expected = array('User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - )); - $this->assertEqual($result, $expected); - } -/** - * testRead method - * - * @access public - * @return void - */ - function testRead() { - $this->loadFixtures('User', 'Article'); - $TestModel =& new User(); - - $result = $TestModel->read(); - $this->assertFalse($result); - - $TestModel->id = 2; - $result = $TestModel->read(); - $expected = array( - 'User' => array( - 'id' => '2', - 'user' => 'nate', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:18:23', - 'updated' => '2007-03-17 01:20:31' - )); - $this->assertEqual($result, $expected); - - $result = $TestModel->read(null, 2); - $expected = array( - 'User' => array( - 'id' => '2', - 'user' => 'nate', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:18:23', - 'updated' => '2007-03-17 01:20:31' - )); - $this->assertEqual($result, $expected); - - $TestModel->id = 2; - $result = $TestModel->read(array('id', 'user')); - $expected = array('User' => array('id' => '2', 'user' => 'nate')); - $this->assertEqual($result, $expected); - - $result = $TestModel->read('id, user', 2); - $expected = array( - 'User' => array( - 'id' => '2', - 'user' => 'nate' - )); - $this->assertEqual($result, $expected); - - $result = $TestModel->bindModel(array('hasMany' => array('Article'))); - $this->assertTrue($result); - - $TestModel->id = 1; - $result = $TestModel->read('id, user'); - $expected = array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' - ), - 'Article' => array( - array( - 'id' => '1', - 'user_id' => '1', - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - array( - 'id' => '3', - 'user_id' => '1', - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ))); - $this->assertEqual($result, $expected); - } -/** - * testRecursiveRead method - * - * @access public - * @return void - */ - function testRecursiveRead() { - $this->loadFixtures( - 'User', - 'Article', - 'Comment', - 'Tag', - 'ArticlesTag', - 'Featured', - 'ArticleFeatured' - ); - $TestModel =& new User(); - - $result = $TestModel->bindModel(array('hasMany' => array('Article')), false); - $this->assertTrue($result); - - $TestModel->recursive = 0; - $result = $TestModel->read('id, user', 1); - $expected = array( - 'User' => array('id' => '1', 'user' => 'mariano'), - ); - $this->assertEqual($result, $expected); - - $TestModel->recursive = 1; - $result = $TestModel->read('id, user', 1); - $expected = array( - 'User' => array( - 'id' => '1', - 'user' => 'mariano' - ), - 'Article' => array( - array( - 'id' => '1', - 'user_id' => '1', - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - array( - 'id' => '3', - 'user_id' => '1', - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ))); - $this->assertEqual($result, $expected); - - $TestModel->recursive = 2; - $result = $TestModel->read('id, user', 3); - $expected = array( - 'User' => array( - 'id' => '3', - 'user' => 'larry' - ), - 'Article' => array( - array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31', - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - ), - 'Comment' => array( - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - )), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - ))))); - $this->assertEqual($result, $expected); - } - - function testRecursiveFindAll() { - $this->db->truncate(new Featured()); - - $this->loadFixtures( - 'User', - 'Article', - 'Comment', - 'Tag', - 'ArticlesTag', - 'Attachment', - 'ArticleFeatured', - 'Featured', - 'Category' - ); - $TestModel =& new Article(); - - $result = $TestModel->find('all', array('conditions' => array('Article.user_id' => 1))); - $expected = array( - array( - 'Article' => array( - 'id' => '1', - 'user_id' => '1', - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Comment' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '2', - 'article_id' => '1', - 'user_id' => '4', - 'comment' => 'Second Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:47:23', - 'updated' => '2007-03-18 10:49:31' - ), - array( - 'id' => '3', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Third Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:49:23', - 'updated' => '2007-03-18 10:51:31' - ), - array( - 'id' => '4', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Fourth Comment for First Article', - 'published' => 'N', - 'created' => '2007-03-18 10:51:23', - 'updated' => '2007-03-18 10:53:31' - ) - ), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '2', - 'tag' => 'tag2', - 'created' => '2007-03-18 12:24:23', - 'updated' => '2007-03-18 12:26:31' - ))), - array( - 'Article' => array( - 'id' => '3', - 'user_id' => '1', - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ), - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Comment' => array(), - 'Tag' => array() - ) - ); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('all', array( - 'conditions' => array('Article.user_id' => 3), - 'limit' => 1, - 'recursive' => 2 - )); - - $expected = array( - array( - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - ), - 'Comment' => array( - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31', - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Attachment' => array( - 'id' => '1', - 'comment_id' => 5, - 'attachment' => 'attachment.zip', - 'created' => '2007-03-18 10:51:23', - 'updated' => '2007-03-18 10:53:31' - ) - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31', - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'User' => array( - 'id' => '2', - 'user' => 'nate', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:18:23', - 'updated' => '2007-03-17 01:20:31' - ), - 'Attachment' => false - ) - ), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - )))); - - $this->assertEqual($result, $expected); - - $Featured = new Featured(); - - $Featured->recursive = 2; - $Featured->bindModel(array( - 'belongsTo' => array( - 'ArticleFeatured' => array( - 'conditions' => "ArticleFeatured.published = 'Y'", - 'fields' => 'id, title, user_id, published' - ) - ) - )); - - $Featured->ArticleFeatured->unbindModel(array( - 'hasMany' => array('Attachment', 'Comment'), - 'hasAndBelongsToMany' => array('Tag')) - ); - - $orderBy = 'ArticleFeatured.id ASC'; - $result = $Featured->find('all', array( - 'order' => $orderBy, 'limit' => 3 - )); - - $expected = array( - array( - 'Featured' => array( - 'id' => '1', - 'article_featured_id' => '1', - 'category_id' => '1', - 'published_date' => '2007-03-31 10:39:23', - 'end_date' => '2007-05-15 10:39:23', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'ArticleFeatured' => array( - 'id' => '1', - 'title' => 'First Article', - 'user_id' => '1', - 'published' => 'Y', - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Category' => array(), - 'Featured' => array( - 'id' => '1', - 'article_featured_id' => '1', - 'category_id' => '1', - 'published_date' => '2007-03-31 10:39:23', - 'end_date' => '2007-05-15 10:39:23', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - )), - 'Category' => array( - 'id' => '1', - 'parent_id' => '0', - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - )), - array( - 'Featured' => array( - 'id' => '2', - 'article_featured_id' => '2', - 'category_id' => '1', - 'published_date' => '2007-03-31 10:39:23', - 'end_date' => '2007-05-15 10:39:23', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'ArticleFeatured' => array( - 'id' => '2', - 'title' => 'Second Article', - 'user_id' => '3', - 'published' => 'Y', - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - ), - 'Category' => array(), - 'Featured' => array( - 'id' => '2', - 'article_featured_id' => '2', - 'category_id' => '1', - 'published_date' => '2007-03-31 10:39:23', - 'end_date' => '2007-05-15 10:39:23', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - )), - 'Category' => array( - 'id' => '1', - 'parent_id' => '0', - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ))); - $this->assertEqual($result, $expected); - } -/** - * testRecursiveFindAllWithLimit method - * - * @access public - * @return void - */ - function testRecursiveFindAllWithLimit() { - $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag', 'Comment', 'Attachment'); - $TestModel =& new Article(); - - $TestModel->hasMany['Comment']['limit'] = 2; - - $result = $TestModel->find('all', array( - 'conditions' => array('Article.user_id' => 1) - )); - $expected = array( - array( - 'Article' => array( - 'id' => '1', - 'user_id' => '1', - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Comment' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '2', - 'article_id' => '1', - 'user_id' => '4', - 'comment' => 'Second Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:47:23', - 'updated' => '2007-03-18 10:49:31' - ), - ), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '2', - 'tag' => 'tag2', - 'created' => '2007-03-18 12:24:23', - 'updated' => '2007-03-18 12:26:31' - ))), - array( - 'Article' => array( - 'id' => '3', - 'user_id' => '1', - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ), - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Comment' => array(), - 'Tag' => array() - ) - ); - $this->assertEqual($result, $expected); - - $TestModel->hasMany['Comment']['limit'] = 1; - - $result = $TestModel->find('all', array( - 'conditions' => array('Article.user_id' => 3), - 'limit' => 1, - 'recursive' => 2 - )); - $expected = array( - array( - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - ), - 'Comment' => array( - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31', - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Attachment' => array( - 'id' => '1', - 'comment_id' => 5, - 'attachment' => 'attachment.zip', - 'created' => '2007-03-18 10:51:23', - 'updated' => '2007-03-18 10:53:31' - ) - ) - ), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - ) - ) - ) - ); - $this->assertEqual($result, $expected); - } -/** - * testAssociationAfterFind method - * - * @access public - * @return void - */ - function testAssociationAfterFind() { - $this->loadFixtures('Post', 'Author', 'Comment'); - $TestModel =& new Post(); - $result = $TestModel->find('all'); - $expected = array( - array( - 'Post' => array( - 'id' => '1', - 'author_id' => '1', - 'title' => 'First Post', - 'body' => 'First Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'Author' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31', - 'test' => 'working' - )), - array( - 'Post' => array( - 'id' => '2', - 'author_id' => '3', - 'title' => 'Second Post', - 'body' => 'Second Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'Author' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31', - 'test' => 'working' - )), - array( - 'Post' => array( - 'id' => '3', - 'author_id' => '1', - 'title' => 'Third Post', - 'body' => 'Third Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ), - 'Author' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31', - 'test' => 'working' - ))); - $this->assertEqual($result, $expected); - unset($TestModel); - - $Author =& new Author(); - $Author->Post->bindModel(array( - 'hasMany' => array( - 'Comment' => array( - 'className' => 'ModifiedComment', - 'foreignKey' => 'article_id', - ) - ))); - $result = $Author->find('all', array( - 'conditions' => array('Author.id' => 1), - 'recursive' => 2 - )); - $expected = array( - 'id' => 1, - 'article_id' => 1, - 'user_id' => 2, - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31', - 'callback' => 'Fire' - ); - $this->assertEqual($result[0]['Post'][0]['Comment'][0], $expected); - } -/** - * Tests that callbacks can be properly disabled - * - * @access public - * @return void - */ - function testCallbackDisabling() { - $this->loadFixtures('Author'); - $TestModel = new ModifiedAuthor(); - - $result = Set::extract($TestModel->find('all'), '/Author/user'); - $expected = array('mariano (CakePHP)', 'nate (CakePHP)', 'larry (CakePHP)', 'garrett (CakePHP)'); - $this->assertEqual($result, $expected); - - $result = Set::extract($TestModel->find('all', array('callbacks' => 'after')), '/Author/user'); - $expected = array('mariano (CakePHP)', 'nate (CakePHP)', 'larry (CakePHP)', 'garrett (CakePHP)'); - $this->assertEqual($result, $expected); - - $result = Set::extract($TestModel->find('all', array('callbacks' => 'before')), '/Author/user'); - $expected = array('mariano', 'nate', 'larry', 'garrett'); - $this->assertEqual($result, $expected); - - $result = Set::extract($TestModel->find('all', array('callbacks' => false)), '/Author/user'); - $expected = array('mariano', 'nate', 'larry', 'garrett'); - $this->assertEqual($result, $expected); - } -/** - * testValidatesBackwards method - * - * @access public - * @return void - */ - function testValidatesBackwards() { - $TestModel =& new TestValidate(); - - $TestModel->validate = array( - 'user_id' => VALID_NUMBER, - 'title' => VALID_NOT_EMPTY, - 'body' => VALID_NOT_EMPTY - ); - - $data = array('TestValidate' => array( - 'user_id' => '1', - 'title' => '', - 'body' => '' - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertFalse($result); - - $data = array('TestValidate' => array( - 'user_id' => '1', - 'title' => 'title', - 'body' => '' - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertFalse($result); - - $data = array('TestValidate' => array( - 'user_id' => '', - 'title' => 'title', - 'body' => 'body' - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertFalse($result); - - $data = array('TestValidate' => array( - 'user_id' => 'not a number', - 'title' => 'title', - 'body' => 'body' - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertFalse($result); - - $data = array('TestValidate' => array( - 'user_id' => '1', - 'title' => 'title', - 'body' => 'body' - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertTrue($result); - } -/** - * testValidates method - * - * @access public - * @return void - */ - function testValidates() { - $TestModel =& new TestValidate(); - - $TestModel->validate = array( - 'user_id' => 'numeric', - 'title' => array('allowEmpty' => false, 'rule' => 'notEmpty'), - 'body' => 'notEmpty' - ); - - $data = array('TestValidate' => array( - 'user_id' => '1', - 'title' => '', - 'body' => 'body' - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertFalse($result); - - $data = array('TestValidate' => array( - 'user_id' => '1', - 'title' => 'title', - 'body' => 'body' - )); - $result = $TestModel->create($data) && $TestModel->validates(); - $this->assertTrue($result); - - $data = array('TestValidate' => array( - 'user_id' => '1', - 'title' => '0', - 'body' => 'body' - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertTrue($result); - - $data = array('TestValidate' => array( - 'user_id' => '1', - 'title' => 0, - 'body' => 'body' - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertTrue($result); - - $TestModel->validate['modified'] = array('allowEmpty' => true, 'rule' => 'date'); - - $data = array('TestValidate' => array( - 'user_id' => '1', - 'title' => 0, - 'body' => 'body', - 'modified' => '' - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertTrue($result); - - $data = array('TestValidate' => array( - 'user_id' => '1', - 'title' => 0, - 'body' => 'body', - 'modified' => '2007-05-01' - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertTrue($result); - - $data = array('TestValidate' => array( - 'user_id' => '1', - 'title' => 0, - 'body' => 'body', - 'modified' => 'invalid-date-here' - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertFalse($result); - - $data = array('TestValidate' => array( - 'user_id' => '1', - 'title' => 0, - 'body' => 'body', - 'modified' => 0 - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertFalse($result); - - $data = array('TestValidate' => array( - 'user_id' => '1', - 'title' => 0, - 'body' => 'body', - 'modified' => '0' - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertFalse($result); - - $TestModel->validate['modified'] = array('allowEmpty' => false, 'rule' => 'date'); - - $data = array('TestValidate' => array('modified' => null)); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertFalse($result); - - $data = array('TestValidate' => array('modified' => false)); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertFalse($result); - - $data = array('TestValidate' => array('modified' => '')); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertFalse($result); - - $data = array('TestValidate' => array( - 'modified' => '2007-05-01' - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertTrue($result); - - $TestModel->validate['slug'] = array('allowEmpty' => false, 'rule' => array('maxLength', 45)); - - $data = array('TestValidate' => array( - 'user_id' => '1', - 'title' => 0, - 'body' => 'body', - 'slug' => '' - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertFalse($result); - - $data = array('TestValidate' => array( - 'user_id' => '1', - 'title' => 0, - 'body' => 'body', - 'slug' => 'slug-right-here' - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertTrue($result); - - $data = array('TestValidate' => array( - 'user_id' => '1', - 'title' => 0, - 'body' => 'body', - 'slug' => 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz' - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertFalse($result); - - $TestModel->validate = array( - 'number' => array( - 'rule' => 'validateNumber', - 'min' => 3, - 'max' => 5 - ), - 'title' => array( - 'allowEmpty' => false, - 'rule' => 'notEmpty' - )); - - $data = array('TestValidate' => array( - 'title' => 'title', - 'number' => '0' - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertFalse($result); - - $data = array('TestValidate' => array( - 'title' => 'title', - 'number' => 0 - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertFalse($result); - - $data = array('TestValidate' => array( - 'title' => 'title', - 'number' => '3' - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertTrue($result); - - $data = array('TestValidate' => array( - 'title' => 'title', - 'number' => 3 - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertTrue($result); - - $TestModel->validate = array( - 'number' => array( - 'rule' => 'validateNumber', - 'min' => 5, - 'max' => 10 - ), - 'title' => array( - 'allowEmpty' => false, - 'rule' => 'notEmpty' - )); - - $data = array('TestValidate' => array( - 'title' => 'title', - 'number' => '3' - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertFalse($result); - - $data = array('TestValidate' => array( - 'title' => 'title', - 'number' => 3 - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertFalse($result); - - $TestModel->validate = array( - 'title' => array( - 'allowEmpty' => false, - 'rule' => 'validateTitle' - )); - - $data = array('TestValidate' => array('title' => '')); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertFalse($result); - - $data = array('TestValidate' => array('title' => 'new title')); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertFalse($result); - - $data = array('TestValidate' => array('title' => 'title-new')); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertTrue($result); - - $TestModel->validate = array('title' => array( - 'allowEmpty' => true, - 'rule' => 'validateTitle' - )); - $data = array('TestValidate' => array('title' => '')); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertTrue($result); - - $TestModel->validate = array( - 'title' => array( - 'length' => array( - 'allowEmpty' => true, - 'rule' => array('maxLength', 10) - ))); - $data = array('TestValidate' => array('title' => '')); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertTrue($result); - - $TestModel->validate = array( - 'title' => array( - 'rule' => array('userDefined', 'Article', 'titleDuplicate') - )); - $data = array('TestValidate' => array('title' => 'My Article Title')); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertFalse($result); - - $data = array('TestValidate' => array( - 'title' => 'My Article With a Different Title' - )); - $result = $TestModel->create($data); - $this->assertTrue($result); - $result = $TestModel->validates(); - $this->assertTrue($result); - - $TestModel->validate = array( - 'title' => array( - 'tooShort' => array('rule' => array('minLength', 50)), - 'onlyLetters' => array('rule' => '/^[a-z]+$/i') - ), - ); - $data = array('TestValidate' => array( - 'title' => 'I am a short string' - )); - $TestModel->create($data); - $result = $TestModel->validates(); - $this->assertFalse($result); - $result = $TestModel->validationErrors; - $expected = array( - 'title' => 'onlyLetters' - ); - $this->assertEqual($result, $expected); - - $TestModel->validate = array( - 'title' => array( - 'tooShort' => array( - 'rule' => array('minLength', 50), - 'last' => true - ), - 'onlyLetters' => array('rule' => '/^[a-z]+$/i') - ), - ); - $data = array('TestValidate' => array( - 'title' => 'I am a short string' - )); - $TestModel->create($data); - $result = $TestModel->validates(); - $this->assertFalse($result); - $result = $TestModel->validationErrors; - $expected = array( - 'title' => 'tooShort' - ); - $this->assertEqual($result, $expected); - } -/** - * testSaveField method - * - * @access public - * @return void - */ - function testSaveField() { - $this->loadFixtures('Article'); - $TestModel =& new Article(); - - $TestModel->id = 1; - $result = $TestModel->saveField('title', 'New First Article'); - $this->assertTrue($result); - - $TestModel->recursive = -1; - $result = $TestModel->read(array('id', 'user_id', 'title', 'body'), 1); - $expected = array('Article' => array( - 'id' => '1', - 'user_id' => '1', - 'title' => 'New First Article', - 'body' => 'First Article Body' - )); - $this->assertEqual($result, $expected); - - $TestModel->id = 1; - $result = $TestModel->saveField('title', ''); - $this->assertTrue($result); - - $TestModel->recursive = -1; - $result = $TestModel->read(array('id', 'user_id', 'title', 'body'), 1); - $expected = array('Article' => array( - 'id' => '1', - 'user_id' => '1', - 'title' => '', - 'body' => 'First Article Body' - )); - $result['Article']['title'] = trim($result['Article']['title']); - $this->assertEqual($result, $expected); - - $TestModel->id = 1; - $TestModel->set('body', 'Messed up data'); - $this->assertTrue($TestModel->saveField('title', 'First Article')); - $result = $TestModel->read(array('id', 'user_id', 'title', 'body'), 1); - $expected = array('Article' => array( - 'id' => '1', - 'user_id' => '1', - 'title' => 'First Article', - 'body' => 'First Article Body' - )); - $this->assertEqual($result, $expected); - - $TestModel->recursive = -1; - $result = $TestModel->read(array('id', 'user_id', 'title', 'body'), 1); - - $TestModel->id = 1; - $result = $TestModel->saveField('title', '', true); - $this->assertFalse($result); - - $this->loadFixtures('Node', 'Dependency'); - $Node =& new Node(); - $Node->set('id', 1); - $result = $Node->read(); - $this->assertEqual(Set::extract('/ParentNode/name', $result), array('Second')); - - $Node->saveField('state', 10); - $result = $Node->read(); - $this->assertEqual(Set::extract('/ParentNode/name', $result), array('Second')); - } -/** - * testSaveWithCreate method - * - * @access public - * @return void - */ - function testSaveWithCreate() { - $this->loadFixtures( - 'User', - 'Article', - 'User', - 'Comment', - 'Tag', - 'ArticlesTag', - 'Attachment' - ); - $TestModel =& new User(); - - $data = array('User' => array( - 'user' => 'user', - 'password' => '' - )); - $result = $TestModel->save($data); - $this->assertFalse($result); - $this->assertTrue(!empty($TestModel->validationErrors)); - - $TestModel =& new Article(); - - $data = array('Article' => array( - 'user_id' => '', - 'title' => '', - 'body' => '' - )); - $result = $TestModel->create($data) && $TestModel->save(); - $this->assertFalse($result); - $this->assertTrue(!empty($TestModel->validationErrors)); - - $data = array('Article' => array( - 'id' => 1, - 'user_id' => '1', - 'title' => 'New First Article', - 'body' => '' - )); - $result = $TestModel->create($data) && $TestModel->save(); - $this->assertFalse($result); - - $data = array('Article' => array( - 'id' => 1, - 'title' => 'New First Article' - )); - $result = $TestModel->create() && $TestModel->save($data, false); - $this->assertTrue($result); - - $TestModel->recursive = -1; - $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 1); - $expected = array('Article' => array( - 'id' => '1', - 'user_id' => '1', - 'title' => 'New First Article', - 'body' => 'First Article Body', - 'published' => 'N' - )); - $this->assertEqual($result, $expected); - - $data = array('Article' => array( - 'id' => 1, - 'user_id' => '2', - 'title' => 'First Article', - 'body' => 'New First Article Body', - 'published' => 'Y' - )); - $result = $TestModel->create() && $TestModel->save($data, true, array('id', 'title', 'published')); - $this->assertTrue($result); - - $TestModel->recursive = -1; - $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 1); - $expected = array('Article' => array( - 'id' => '1', - 'user_id' => '1', - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y' - )); - $this->assertEqual($result, $expected); - - $data = array( - 'Article' => array( - 'user_id' => '2', - 'title' => 'New Article', - 'body' => 'New Article Body', - 'created' => '2007-03-18 14:55:23', - 'updated' => '2007-03-18 14:57:31' - ), - 'Tag' => array('Tag' => array(1, 3)) - ); - $TestModel->create(); - $result = $TestModel->create() && $TestModel->save($data); - $this->assertTrue($result); - - $TestModel->recursive = 2; - $result = $TestModel->read(null, 4); - $expected = array( - 'Article' => array( - 'id' => '4', - 'user_id' => '2', - 'title' => 'New Article', - 'body' => 'New Article Body', - 'published' => 'N', - 'created' => '2007-03-18 14:55:23', - 'updated' => '2007-03-18 14:57:31' - ), - 'User' => array( - 'id' => '2', - 'user' => 'nate', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:18:23', - 'updated' => '2007-03-17 01:20:31' - ), - 'Comment' => array(), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - ))); - $this->assertEqual($result, $expected); - - $data = array('Comment' => array( - 'article_id' => '4', - 'user_id' => '1', - 'comment' => 'Comment New Article', - 'published' => 'Y', - 'created' => '2007-03-18 14:57:23', - 'updated' => '2007-03-18 14:59:31' - )); - $result = $TestModel->Comment->create() && $TestModel->Comment->save($data); - $this->assertTrue($result); - - $data = array('Attachment' => array( - 'comment_id' => '7', - 'attachment' => 'newattachment.zip', - 'created' => '2007-03-18 15:02:23', - 'updated' => '2007-03-18 15:04:31' - )); - $result = $TestModel->Comment->Attachment->save($data); - $this->assertTrue($result); - - $TestModel->recursive = 2; - $result = $TestModel->read(null, 4); - $expected = array( - 'Article' => array( - 'id' => '4', - 'user_id' => '2', - 'title' => 'New Article', - 'body' => 'New Article Body', - 'published' => 'N', - 'created' => '2007-03-18 14:55:23', - 'updated' => '2007-03-18 14:57:31' - ), - 'User' => array( - 'id' => '2', - 'user' => 'nate', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:18:23', - 'updated' => '2007-03-17 01:20:31' - ), - 'Comment' => array( - array( - 'id' => '7', - 'article_id' => '4', - 'user_id' => '1', - 'comment' => 'Comment New Article', - 'published' => 'Y', - 'created' => '2007-03-18 14:57:23', - 'updated' => '2007-03-18 14:59:31', - 'Article' => array( - 'id' => '4', - 'user_id' => '2', - 'title' => 'New Article', - 'body' => 'New Article Body', - 'published' => 'N', - 'created' => '2007-03-18 14:55:23', - 'updated' => '2007-03-18 14:57:31' - ), - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Attachment' => array( - 'id' => '2', - 'comment_id' => '7', - 'attachment' => 'newattachment.zip', - 'created' => '2007-03-18 15:02:23', - 'updated' => '2007-03-18 15:04:31' - ))), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - ))); - - $this->assertEqual($result, $expected); - } -/** - * testSaveWithSet method - * - * @access public - * @return void - */ - function testSaveWithSet() { - $this->loadFixtures('Article'); - $TestModel =& new Article(); - - // Create record we will be updating later - - $data = array('Article' => array( - 'user_id' => '1', - 'title' => 'Fourth Article', - 'body' => 'Fourth Article Body', - 'published' => 'Y' - )); - $result = $TestModel->create() && $TestModel->save($data); - $this->assertTrue($result); - - // Check record we created - - $TestModel->recursive = -1; - $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 4); - $expected = array('Article' => array( - 'id' => '4', - 'user_id' => '1', - 'title' => 'Fourth Article', - 'body' => 'Fourth Article Body', - 'published' => 'Y' - )); - $this->assertEqual($result, $expected); - - // Create new record just to overlap Model->id on previously created record - - $data = array('Article' => array( - 'user_id' => '4', - 'title' => 'Fifth Article', - 'body' => 'Fifth Article Body', - 'published' => 'Y' - )); - $result = $TestModel->create() && $TestModel->save($data); - $this->assertTrue($result); - - $TestModel->recursive = -1; - $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 5); - $expected = array('Article' => array( - 'id' => '5', - 'user_id' => '4', - 'title' => 'Fifth Article', - 'body' => 'Fifth Article Body', - 'published' => 'Y' - )); - $this->assertEqual($result, $expected); - - // Go back and edit the first article we created, starting by checking it's still there - - $TestModel->recursive = -1; - $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 4); - $expected = array('Article' => array( - 'id' => '4', - 'user_id' => '1', - 'title' => 'Fourth Article', - 'body' => 'Fourth Article Body', - 'published' => 'Y' - )); - $this->assertEqual($result, $expected); - - // And now do the update with set() - - $data = array('Article' => array( - 'id' => '4', - 'title' => 'Fourth Article - New Title', - 'published' => 'N' - )); - $result = $TestModel->set($data) && $TestModel->save(); - $this->assertTrue($result); - - $TestModel->recursive = -1; - $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 4); - $expected = array('Article' => array( - 'id' => '4', - 'user_id' => '1', - 'title' => 'Fourth Article - New Title', - 'body' => 'Fourth Article Body', - 'published' => 'N' - )); - $this->assertEqual($result, $expected); - - $TestModel->recursive = -1; - $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 5); - $expected = array('Article' => array( - 'id' => '5', - 'user_id' => '4', - 'title' => 'Fifth Article', - 'body' => 'Fifth Article Body', - 'published' => 'Y' - )); - $this->assertEqual($result, $expected); - - $data = array('Article' => array('id' => '5', 'title' => 'Fifth Article - New Title 5')); - $result = ($TestModel->set($data) && $TestModel->save()); - $this->assertTrue($result); - - $TestModel->recursive = -1; - $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 5); - $expected = array('Article' => array( - 'id' => '5', - 'user_id' => '4', - 'title' => 'Fifth Article - New Title 5', - 'body' => 'Fifth Article Body', - 'published' => 'Y' - )); - $this->assertEqual($result, $expected); - - $TestModel->recursive = -1; - $result = $TestModel->find('all', array('fields' => array('id', 'title'))); - $expected = array( - array('Article' => array('id' => 1, 'title' => 'First Article' )), - array('Article' => array('id' => 2, 'title' => 'Second Article' )), - array('Article' => array('id' => 3, 'title' => 'Third Article' )), - array('Article' => array('id' => 4, 'title' => 'Fourth Article - New Title' )), - array('Article' => array('id' => 5, 'title' => 'Fifth Article - New Title 5' )) - ); - $this->assertEqual($result, $expected); - } -/** - * testSaveWithNonExistentFields method - * - * @access public - * @return void - */ - function testSaveWithNonExistentFields() { - $this->loadFixtures('Article'); - $TestModel =& new Article(); - $TestModel->recursive = -1; - - $data = array( - 'non_existent' => 'This field does not exist', - 'user_id' => '1', - 'title' => 'Fourth Article - New Title', - 'body' => 'Fourth Article Body', - 'published' => 'N' - ); - $result = $TestModel->create() && $TestModel->save($data); - $this->assertTrue($result); - - $expected = array('Article' => array( - 'id' => '4', - 'user_id' => '1', - 'title' => 'Fourth Article - New Title', - 'body' => 'Fourth Article Body', - 'published' => 'N' - )); - $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 4); - $this->assertEqual($result, $expected); - - $data = array( - 'user_id' => '1', - 'non_existent' => 'This field does not exist', - 'title' => 'Fiveth Article - New Title', - 'body' => 'Fiveth Article Body', - 'published' => 'N' - ); - $result = $TestModel->create() && $TestModel->save($data); - $this->assertTrue($result); - - $expected = array('Article' => array( - 'id' => '5', - 'user_id' => '1', - 'title' => 'Fiveth Article - New Title', - 'body' => 'Fiveth Article Body', - 'published' => 'N' - )); - $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 5); - $this->assertEqual($result, $expected); - } -/** - * testSaveFromXml method - * - * @access public - * @return void - */ - function testSaveFromXml() { - $this->loadFixtures('Article'); - App::import('Core', 'Xml'); - - $Article = new Article(); - $Article->save(new Xml('
')); - $this->assertTrue($Article->save(new Xml('
'))); - - $results = $Article->find(array('Article.title' => 'test xml')); - $this->assertTrue($results); - } -/** - * testSaveHabtm method - * - * @access public - * @return void - */ - function testSaveHabtm() { - $this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'ArticlesTag'); - $TestModel =& new Article(); - - $result = $TestModel->findById(2); - $expected = array( - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - ), - 'Comment' => array( - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - )), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - ) - ) - ); - $this->assertEqual($result, $expected); - - $data = array( - 'Article' => array( - 'id' => '2', - 'title' => 'New Second Article' - ), - 'Tag' => array('Tag' => array(1, 2)) - ); - - $this->assertTrue($TestModel->set($data)); - $this->assertTrue($TestModel->save()); - - $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); - $result = $TestModel->find(array('Article.id' => 2), array('id', 'user_id', 'title', 'body')); - $expected = array( - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'New Second Article', - 'body' => 'Second Article Body' - ), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '2', - 'tag' => 'tag2', - 'created' => '2007-03-18 12:24:23', - 'updated' => '2007-03-18 12:26:31' - ))); - $this->assertEqual($result, $expected); - - $data = array('Article' => array('id' => '2'), 'Tag' => array('Tag' => array(2, 3))); - $result = $TestModel->set($data); - $this->assertTrue($result); - - $result = $TestModel->save(); - $this->assertTrue($result); - - $TestModel->unbindModel(array( - 'belongsTo' => array('User'), - 'hasMany' => array('Comment') - )); - $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); - $expected = array( - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'New Second Article', - 'body' => 'Second Article Body' - ), - 'Tag' => array( - array( - 'id' => '2', - 'tag' => 'tag2', - 'created' => '2007-03-18 12:24:23', - 'updated' => '2007-03-18 12:26:31' - ), - array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - ))); - $this->assertEqual($result, $expected); - - $data = array('Tag' => array('Tag' => array(1, 2, 3))); - - $result = $TestModel->set($data); - $this->assertTrue($result); - - $result = $TestModel->save(); - $this->assertTrue($result); - - $TestModel->unbindModel(array( - 'belongsTo' => array('User'), - 'hasMany' => array('Comment') - )); - $result = $TestModel->find(array('Article.id' => 2), array('id', 'user_id', 'title', 'body')); - $expected = array( - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'New Second Article', - 'body' => 'Second Article Body' - ), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '2', - 'tag' => 'tag2', - 'created' => '2007-03-18 12:24:23', - 'updated' => '2007-03-18 12:26:31' - ), - array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - ))); - $this->assertEqual($result, $expected); - - $data = array('Tag' => array('Tag' => array())); - $result = $TestModel->set($data); - $this->assertTrue($result); - - $result = $TestModel->save(); - $this->assertTrue($result); - - $data = array('Tag' => array('Tag' => '')); - $result = $TestModel->set($data); - $this->assertTrue($result); - - $result = $TestModel->save(); - $this->assertTrue($result); - - $TestModel->unbindModel(array( - 'belongsTo' => array('User'), - 'hasMany' => array('Comment') - )); - $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); - $expected = array( - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'New Second Article', - 'body' => 'Second Article Body' - ), - 'Tag' => array() - ); - $this->assertEqual($result, $expected); - - $data = array('Tag' => array('Tag' => array(2, 3))); - $result = $TestModel->set($data); - $this->assertTrue($result); - - $result = $TestModel->save(); - $this->assertTrue($result); - - $TestModel->unbindModel(array( - 'belongsTo' => array('User'), - 'hasMany' => array('Comment') - )); - $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); - $expected = array( - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'New Second Article', - 'body' => 'Second Article Body' - ), - 'Tag' => array( - array( - 'id' => '2', - 'tag' => 'tag2', - 'created' => '2007-03-18 12:24:23', - 'updated' => '2007-03-18 12:26:31' - ), - array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - ))); - $this->assertEqual($result, $expected); - - $data = array( - 'Tag' => array( - 'Tag' => array(1, 2) - ), - 'Article' => array( - 'id' => '2', - 'title' => 'New Second Article' - )); - $this->assertTrue($TestModel->set($data)); - $this->assertTrue($TestModel->save()); - - $TestModel->unbindModel(array( - 'belongsTo' => array('User'), - 'hasMany' => array('Comment') - )); - $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); - $expected = array( - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'New Second Article', - 'body' => 'Second Article Body' - ), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '2', - 'tag' => 'tag2', - 'created' => '2007-03-18 12:24:23', - 'updated' => '2007-03-18 12:26:31' - ))); - $this->assertEqual($result, $expected); - - $data = array( - 'Tag' => array( - 'Tag' => array(1, 2) - ), - 'Article' => array( - 'id' => '2', - 'title' => 'New Second Article Title' - )); - $result = $TestModel->set($data); - $this->assertTrue($result); - $this->assertTrue($TestModel->save()); - - $TestModel->unbindModel(array( - 'belongsTo' => array('User'), - 'hasMany' => array('Comment') - )); - $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); - $expected = array( - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'New Second Article Title', - 'body' => 'Second Article Body' - ), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '2', - 'tag' => 'tag2', - 'created' => '2007-03-18 12:24:23', - 'updated' => '2007-03-18 12:26:31' - ) - ) - ); - $this->assertEqual($result, $expected); - - $data = array( - 'Tag' => array( - 'Tag' => array(2, 3) - ), - 'Article' => array( - 'id' => '2', - 'title' => 'Changed Second Article' - )); - $this->assertTrue($TestModel->set($data)); - $this->assertTrue($TestModel->save()); - - $TestModel->unbindModel(array( - 'belongsTo' => array('User'), - 'hasMany' => array('Comment') - )); - $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); - $expected = array( - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Changed Second Article', - 'body' => 'Second Article Body' - ), - 'Tag' => array( - array( - 'id' => '2', - 'tag' => 'tag2', - 'created' => '2007-03-18 12:24:23', - 'updated' => '2007-03-18 12:26:31' - ), - array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - ) - ) - ); - $this->assertEqual($result, $expected); - - $data = array( - 'Tag' => array( - 'Tag' => array(1, 3) - ), - 'Article' => array('id' => '2'), - ); - - $result = $TestModel->set($data); - $this->assertTrue($result); - - $result = $TestModel->save(); - $this->assertTrue($result); - - $TestModel->unbindModel(array( - 'belongsTo' => array('User'), - 'hasMany' => array('Comment') - )); - $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); - $expected = array( - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Changed Second Article', - 'body' => 'Second Article Body' - ), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - ))); - $this->assertEqual($result, $expected); - - $data = array( - 'Article' => array( - 'id' => 10, - 'user_id' => '2', - 'title' => 'New Article With Tags and fieldList', - 'body' => 'New Article Body with Tags and fieldList', - 'created' => '2007-03-18 14:55:23', - 'updated' => '2007-03-18 14:57:31' - ), - 'Tag' => array( - 'Tag' => array(1, 2, 3) - )); - $result = $TestModel->create() - && $TestModel->save($data, true, array('user_id', 'title', 'published')); - $this->assertTrue($result); - - $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); - $result = $TestModel->read(); - $expected = array( - 'Article' => array( - 'id' => 4, - 'user_id' => 2, - 'title' => 'New Article With Tags and fieldList', - 'body' => '', - 'published' => 'N', - 'created' => '', - 'updated' => '' - ), - 'Tag' => array( - 0 => array( - 'id' => 1, - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - 1 => array( - 'id' => 2, - 'tag' => 'tag2', - 'created' => '2007-03-18 12:24:23', - 'updated' => '2007-03-18 12:26:31' - ), - 2 => array( - 'id' => 3, - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - ))); - $this->assertEqual($result, $expected); - - - $this->loadFixtures('JoinA', 'JoinC', 'JoinAC', 'JoinB', 'JoinAB'); - $TestModel = new JoinA(); - $TestModel->hasBelongsToMany['JoinC']['unique'] = true; - $data = array( - 'JoinA' => array( - 'id' => 1, - 'name' => 'Join A 1', - 'body' => 'Join A 1 Body', - ), - 'JoinC' => array( - 'JoinC' => array( - array('join_c_id' => 2, 'other' => 'new record'), - array('join_c_id' => 3, 'other' => 'new record') - ) - ) - ); - $TestModel->save($data); - $result = $TestModel->read(null, 1); - $time = date('Y-M-D H:i:s'); - $expected = array(4, 5); - $this->assertEqual(Set::extract('/JoinC/JoinAsJoinC/id', $result), $expected); - $expected = array('new record', 'new record'); - $this->assertEqual(Set::extract('/JoinC/JoinAsJoinC/other', $result), $expected); - } -/** - * testSaveHabtmCustomKeys method - * - * @access public - * @return void - */ - function testSaveHabtmCustomKeys() { - $this->loadFixtures('Story', 'StoriesTag', 'Tag'); - $Story =& new Story(); - - $data = array( - 'Story' => array('story' => '1'), - 'Tag' => array( - 'Tag' => array(2, 3) - )); - $result = $Story->set($data); - $this->assertTrue($result); - - $result = $Story->save(); - $this->assertTrue($result); - - $result = $Story->find('all'); - $expected = array( - array( - 'Story' => array( - 'story' => 1, - 'title' => 'First Story' - ), - 'Tag' => array( - array( - 'id' => 2, - 'tag' => 'tag2', - 'created' => '2007-03-18 12:24:23', - 'updated' => '2007-03-18 12:26:31' - ), - array( - 'id' => 3, - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - ))), - array( - 'Story' => array( - 'story' => 2, - 'title' => 'Second Story' - ), - 'Tag' => array() - )); - $this->assertEqual($result, $expected); - } -/** - * testHabtmSaveKeyResolution method - * - * @access public - * @return void - */ - function testHabtmSaveKeyResolution() { - $this->loadFixtures('Apple', 'Device', 'ThePaperMonkies'); - $ThePaper =& new ThePaper(); - - $ThePaper->id = 1; - $ThePaper->save(array('Monkey' => array(2, 3))); - - $result = $ThePaper->findById(1); - $expected = array( - array( - 'id' => '2', - 'device_type_id' => '1', - 'name' => 'Device 2', - 'typ' => '1' - ), - array( - 'id' => '3', - 'device_type_id' => '1', - 'name' => 'Device 3', - 'typ' => '2' - )); - $this->assertEqual($result['Monkey'], $expected); - - $ThePaper->id = 2; - $ThePaper->save(array('Monkey' => array(1, 2, 3))); - - $result = $ThePaper->findById(2); - $expected = array( - array( - 'id' => '1', - 'device_type_id' => '1', - 'name' => 'Device 1', - 'typ' => '1' - ), - array( - 'id' => '2', - 'device_type_id' => '1', - 'name' => 'Device 2', - 'typ' => '1' - ), - array( - 'id' => '3', - 'device_type_id' => '1', - 'name' => 'Device 3', - 'typ' => '2' - )); - $this->assertEqual($result['Monkey'], $expected); - - $ThePaper->id = 2; - $ThePaper->save(array('Monkey' => array(1, 3))); - - $result = $ThePaper->findById(2); - $expected = array( - array( - 'id' => '1', - 'device_type_id' => '1', - 'name' => 'Device 1', - 'typ' => '1' - ), - array( - 'id' => '3', - 'device_type_id' => '1', - 'name' => 'Device 3', - 'typ' => '2' - )); - $this->assertEqual($result['Monkey'], $expected); - - $result = $ThePaper->findById(1); - $expected = array( - array( - 'id' => '2', - 'device_type_id' => '1', - 'name' => 'Device 2', - 'typ' => '1' - ), - array( - 'id' => '3', - 'device_type_id' => '1', - 'name' => 'Device 3', - 'typ' => '2' - )); - $this->assertEqual($result['Monkey'], $expected); - } -/** - * testHabtmDeleteLinksWhenNoPrimaryKeyInJoinTable method - * - * @access public - * @return void - */ - function testHabtmDeleteLinksWhenNoPrimaryKeyInJoinTable() { - - $this->loadFixtures('Apple', 'Device', 'ThePaperMonkies'); - $ThePaper =& new ThePaper(); - $ThePaper->id = 1; - $ThePaper->save(array('Monkey' => array(2, 3))); - - $result = $ThePaper->findById(1); - $expected = array( - array( - 'id' => '2', - 'device_type_id' => '1', - 'name' => 'Device 2', - 'typ' => '1' - ), - array( - 'id' => '3', - 'device_type_id' => '1', - 'name' => 'Device 3', - 'typ' => '2' - )); - $this->assertEqual($result['Monkey'], $expected); - - $ThePaper =& new ThePaper(); - $ThePaper->id = 2; - $ThePaper->save(array('Monkey' => array(2, 3))); - - $result = $ThePaper->findById(2); - $expected = array( - array( - 'id' => '2', - 'device_type_id' => '1', - 'name' => 'Device 2', - 'typ' => '1' - ), - array( - 'id' => '3', - 'device_type_id' => '1', - 'name' => 'Device 3', - 'typ' => '2' - )); - $this->assertEqual($result['Monkey'], $expected); - - $ThePaper->delete(1); - $result = $ThePaper->findById(2); - $expected = array( - array( - 'id' => '2', - 'device_type_id' => '1', - 'name' => 'Device 2', - 'typ' => '1' - ), - array( - 'id' => '3', - 'device_type_id' => '1', - 'name' => 'Device 3', - 'typ' => '2' - )); - $this->assertEqual($result['Monkey'], $expected); - } -/** - * test that Caches are getting cleared on save(). - * ensure that both inflections of controller names are getting cleared - * as url for controller could be either overallFavorites/index or overall_favorites/index - * - * @return void - **/ - function testCacheClearOnSave() { - $_back = array( - 'check' => Configure::read('Cache.check'), - 'disable' => Configure::read('Cache.disable'), - ); - Configure::write('Cache.check', true); - Configure::write('Cache.disable', false); - - $this->loadFixtures('OverallFavorite'); - $OverallFavorite =& new OverallFavorite(); - - touch(CACHE . 'views' . DS . 'some_dir_overallfavorites_index.php'); - touch(CACHE . 'views' . DS . 'some_dir_overall_favorites_index.php'); - - $data = array( - 'OverallFavorite' => array( - 'model_type' => '8-track', - 'model_id' => '3', - 'priority' => '1' - ) - ); - $OverallFavorite->create($data); - $OverallFavorite->save(); - - $this->assertFalse(file_exists(CACHE . 'views' . DS . 'some_dir_overallfavorites_index.php')); - $this->assertFalse(file_exists(CACHE . 'views' . DS . 'some_dir_overall_favorites_index.php')); - - Configure::write('Cache.check', $_back['check']); - Configure::write('Cache.disable', $_back['disable']); - } -/** - * testSaveAll method - * - * @access public - * @return void - */ - function testSaveAll() { - $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment'); - $TestModel =& new Post(); - - $result = $TestModel->find('all'); - $this->assertEqual(count($result), 3); - $this->assertFalse(isset($result[3])); - $ts = date('Y-m-d H:i:s'); - - $TestModel->saveAll(array( - 'Post' => array( - 'title' => 'Post with Author', - 'body' => 'This post will be saved with an author' - ), - 'Author' => array( - 'user' => 'bob', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf90' - ))); - - $result = $TestModel->find('all'); - $expected = array( - 'Post' => array( - 'id' => '4', - 'author_id' => '5', - 'title' => 'Post with Author', - 'body' => 'This post will be saved with an author', - 'published' => 'N', - 'created' => $ts, - 'updated' => $ts - ), - 'Author' => array( - 'id' => '5', - 'user' => 'bob', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf90', - 'created' => $ts, - 'updated' => $ts, - 'test' => 'working' - )); - $this->assertEqual($result[3], $expected); - $this->assertEqual(count($result), 4); - - $TestModel->deleteAll(true); - $this->assertEqual($TestModel->find('all'), array()); - - // SQLite seems to reset the PK counter when that happens, so we need this to make the tests pass - $this->db->truncate($TestModel); - - $ts = date('Y-m-d H:i:s'); - $TestModel->saveAll(array( - array( - 'title' => 'Multi-record post 1', - 'body' => 'First multi-record post', - 'author_id' => 2 - ), - array( - 'title' => 'Multi-record post 2', - 'body' => 'Second multi-record post', - 'author_id' => 2 - ))); - - $result = $TestModel->find('all', array( - 'recursive' => -1, - 'order' => 'Post.id ASC' - )); - $expected = array( - array( - 'Post' => array( - 'id' => '1', - 'author_id' => '2', - 'title' => 'Multi-record post 1', - 'body' => 'First multi-record post', - 'published' => 'N', - 'created' => $ts, - 'updated' => $ts - )), - array( - 'Post' => array( - 'id' => '2', - 'author_id' => '2', - 'title' => 'Multi-record post 2', - 'body' => 'Second multi-record post', - 'published' => 'N', - 'created' => $ts, - 'updated' => $ts - ))); - $this->assertEqual($result, $expected); - - $TestModel =& new Comment(); - $ts = date('Y-m-d H:i:s'); - $result = $TestModel->saveAll(array( - 'Comment' => array( - 'article_id' => 2, - 'user_id' => 2, - 'comment' => 'New comment with attachment', - 'published' => 'Y' - ), - 'Attachment' => array( - 'attachment' => 'some_file.tgz' - ))); - $this->assertTrue($result); - - $result = $TestModel->find('all'); - $expected = array( - 'id' => '7', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'New comment with attachment', - 'published' => 'Y', - 'created' => $ts, - 'updated' => $ts - ); - $this->assertEqual($result[6]['Comment'], $expected); - - $expected = array( - 'id' => '7', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'New comment with attachment', - 'published' => 'Y', - 'created' => $ts, - 'updated' => $ts - ); - $this->assertEqual($result[6]['Comment'], $expected); - - $expected = array( - 'id' => '2', - 'comment_id' => '7', - 'attachment' => 'some_file.tgz', - 'created' => $ts, - 'updated' => $ts - ); - $this->assertEqual($result[6]['Attachment'], $expected); - } -/** - * Test SaveAll with Habtm relations - * - * @access public - * @return void - */ - function testSaveAllHabtm() { - $this->loadFixtures('Article', 'Tag', 'Comment', 'User'); - $data = array( - 'Article' => array( - 'user_id' => 1, - 'title' => 'Article Has and belongs to Many Tags' - ), - 'Tag' => array( - 'Tag' => array(1, 2) - ), - 'Comment' => array( - array( - 'comment' => 'Article comment', - 'user_id' => 1 - ))); - $Article =& new Article(); - $result = $Article->saveAll($data); - $this->assertTrue($result); - - $result = $Article->read(); - $this->assertEqual(count($result['Tag']), 2); - $this->assertEqual($result['Tag'][0]['tag'], 'tag1'); - $this->assertEqual(count($result['Comment']), 1); - $this->assertEqual(count($result['Comment'][0]['comment']['Article comment']), 1); - } -/** - * Test SaveAll with Habtm relations and extra join table fields - * - * @access public - * @return void - */ - function testSaveAllHabtmWithExtraJoinTableFields() { + function testFetchingNonUniqueFKJoinTableRecords() { $this->loadFixtures('Something', 'SomethingElse', 'JoinThing'); + $Something = new Something(); - $data = array( - 'Something' => array( - 'id' => 4, - 'title' => 'Extra Fields', - 'body' => 'Extra Fields Body', - 'published' => '1' - ), - 'SomethingElse' => array( - array('something_else_id' => 1, 'doomed' => '1'), - array('something_else_id' => 2, 'doomed' => '0'), - array('something_else_id' => 3, 'doomed' => '1') - ) - ); - - $Something =& new Something(); - $result = $Something->saveAll($data); - $this->assertTrue($result); - $result = $Something->read(); - - $this->assertEqual(count($result['SomethingElse']), 3); - $this->assertTrue(Set::matches('/Something[id=4]', $result)); - - $this->assertTrue(Set::matches('/SomethingElse[id=1]', $result)); - $this->assertTrue(Set::matches('/SomethingElse[id=1]/JoinThing[something_else_id=1]', $result)); - $this->assertTrue(Set::matches('/SomethingElse[id=1]/JoinThing[doomed=1]', $result)); - - $this->assertTrue(Set::matches('/SomethingElse[id=2]', $result)); - $this->assertTrue(Set::matches('/SomethingElse[id=2]/JoinThing[something_else_id=2]', $result)); - $this->assertTrue(Set::matches('/SomethingElse[id=2]/JoinThing[doomed=0]', $result)); - - $this->assertTrue(Set::matches('/SomethingElse[id=3]', $result)); - $this->assertTrue(Set::matches('/SomethingElse[id=3]/JoinThing[something_else_id=3]', $result)); - $this->assertTrue(Set::matches('/SomethingElse[id=3]/JoinThing[doomed=1]', $result)); - } -/** - * testSaveAllHasOne method - * - * @access public - * @return void - */ - function testSaveAllHasOne() { - $model = new Comment(); - $model->deleteAll(true); - $this->assertEqual($model->find('all'), array()); - - $model->Attachment->deleteAll(true); - $this->assertEqual($model->Attachment->find('all'), array()); - - $this->assertTrue($model->saveAll(array( - 'Comment' => array( - 'comment' => 'Comment with attachment', - 'article_id' => 1, - 'user_id' => 1 - ), - 'Attachment' => array( - 'attachment' => 'some_file.zip' - )))); - $result = $model->find('all', array('fields' => array( - 'Comment.id', 'Comment.comment', 'Attachment.id', - 'Attachment.comment_id', 'Attachment.attachment' - ))); - $expected = array(array( - 'Comment' => array( - 'id' => '1', - 'comment' => 'Comment with attachment' - ), - 'Attachment' => array( - 'id' => '1', - 'comment_id' => '1', - 'attachment' => 'some_file.zip' - ))); - $this->assertEqual($result, $expected); - } -/** - * testSaveAllBelongsTo method - * - * @access public - * @return void - */ - function testSaveAllBelongsTo() { - $model = new Comment(); - $model->deleteAll(true); - $this->assertEqual($model->find('all'), array()); - - $model->Article->deleteAll(true); - $this->assertEqual($model->Article->find('all'), array()); - - $this->assertTrue($model->saveAll(array( - 'Comment' => array( - 'comment' => 'Article comment', - 'article_id' => 1, - 'user_id' => 1 - ), - 'Article' => array( - 'title' => 'Model Associations 101', - 'user_id' => 1 - )))); - $result = $model->find('all', array('fields' => array( - 'Comment.id', 'Comment.comment', 'Comment.article_id', 'Article.id', 'Article.title' - ))); - $expected = array(array( - 'Comment' => array( - 'id' => '1', - 'article_id' => '1', - 'comment' => 'Article comment' - ), - 'Article' => array( - 'id' => '1', - 'title' => 'Model Associations 101' - ))); - $this->assertEqual($result, $expected); - } -/** - * testSaveAllHasOneValidation method - * - * @access public - * @return void - */ - function testSaveAllHasOneValidation() { - $model = new Comment(); - $model->deleteAll(true); - $this->assertEqual($model->find('all'), array()); - - $model->Attachment->deleteAll(true); - $this->assertEqual($model->Attachment->find('all'), array()); - - $model->validate = array('comment' => 'notEmpty'); - $model->Attachment->validate = array('attachment' => 'notEmpty'); - $model->Attachment->bind('Comment'); - - $this->assertFalse($model->saveAll( - array( - 'Comment' => array( - 'comment' => '', - 'article_id' => 1, - 'user_id' => 1 - ), - 'Attachment' => array('attachment' => '') - ), - array('validate' => 'first') - )); - $expected = array( - 'Comment' => array('comment' => 'This field cannot be left blank'), - 'Attachment' => array('attachment' => 'This field cannot be left blank') - ); - $this->assertEqual($model->validationErrors, $expected['Comment']); - $this->assertEqual($model->Attachment->validationErrors, $expected['Attachment']); - - $this->assertFalse($model->saveAll( - array( - 'Comment' => array('comment' => '', 'article_id' => 1, 'user_id' => 1), - 'Attachment' => array('attachment' => '') - ), - array('validate' => 'only') - )); - $this->assertEqual($model->validationErrors, $expected['Comment']); - $this->assertEqual($model->Attachment->validationErrors, $expected['Attachment']); - } -/** - * testSaveAllAtomic method - * - * @access public - * @return void - */ - function testSaveAllAtomic() { - $this->loadFixtures('Article', 'User'); - $TestModel =& new Article(); - - $result = $TestModel->saveAll(array( - 'Article' => array( - 'title' => 'Post with Author', - 'body' => 'This post will be saved with an author', - 'user_id' => 2 - ), - 'Comment' => array( - array('comment' => 'First new comment', 'user_id' => 2)) - ), array('atomic' => false)); - - $this->assertIdentical($result, array('Article' => true, 'Comment' => array(true))); - - $result = $TestModel->saveAll(array( - array( - 'id' => '1', - 'title' => 'Baleeted First Post', - 'body' => 'Baleeted!', - 'published' => 'N' - ), - array( - 'id' => '2', - 'title' => 'Just update the title' - ), - array( - 'title' => 'Creating a fourth post', - 'body' => 'Fourth post body', - 'user_id' => 2 - ) - ), array('atomic' => false)); - $this->assertIdentical($result, array(true, true, true)); - - $TestModel->validate = array('title' => 'notEmpty', 'author_id' => 'numeric'); - $result = $TestModel->saveAll(array( - array( - 'id' => '1', - 'title' => 'Un-Baleeted First Post', - 'body' => 'Not Baleeted!', - 'published' => 'Y' - ), - array( - 'id' => '2', - 'title' => '', - 'body' => 'Trying to get away with an empty title' - ) - ), array('atomic' => false)); - $this->assertIdentical($result, array(true, false)); - - $result = $TestModel->saveAll(array( - 'Article' => array('id' => 2), - 'Comment' => array( - array( - 'comment' => 'First new comment', - 'published' => 'Y', - 'user_id' => 1 - ), - array( - 'comment' => 'Second new comment', - 'published' => 'Y', - 'user_id' => 2 - )) - ), array('atomic' => false)); - $this->assertIdentical($result, array('Article' => true, 'Comment' => array(true, true))); - } -/** - * testSaveAllHasMany method - * - * @access public - * @return void - */ - function testSaveAllHasMany() { - $this->loadFixtures('Article', 'Comment'); - $TestModel =& new Article(); - $TestModel->belongsTo = $TestModel->hasAndBelongsToMany = array(); - - $result = $TestModel->saveAll(array( - 'Article' => array('id' => 2), - 'Comment' => array( - array('comment' => 'First new comment', 'published' => 'Y', 'user_id' => 1), - array('comment' => 'Second new comment', 'published' => 'Y', 'user_id' => 2) - ) - )); - $this->assertTrue($result); - - $result = $TestModel->findById(2); - $expected = array( - 'First Comment for Second Article', - 'Second Comment for Second Article', - 'First new comment', - 'Second new comment' - ); - $this->assertEqual(Set::extract($result['Comment'], '{n}.comment'), $expected); - - $result = $TestModel->saveAll( - array( - 'Article' => array('id' => 2), - 'Comment' => array( - array( - 'comment' => 'Third new comment', - 'published' => 'Y', - 'user_id' => 1 - ))), - array('atomic' => false) - ); - $this->assertTrue($result); - - $result = $TestModel->findById(2); - $expected = array( - 'First Comment for Second Article', - 'Second Comment for Second Article', - 'First new comment', - 'Second new comment', - 'Third new comment' - ); - $this->assertEqual(Set::extract($result['Comment'], '{n}.comment'), $expected); - - $TestModel->beforeSaveReturn = false; - $result = $TestModel->saveAll( - array( - 'Article' => array('id' => 2), - 'Comment' => array( - array( - 'comment' => 'Fourth new comment', - 'published' => 'Y', - 'user_id' => 1 - ))), - array('atomic' => false) - ); - $this->assertEqual($result, array('Article' => false)); - - $result = $TestModel->findById(2); - $expected = array( - 'First Comment for Second Article', - 'Second Comment for Second Article', - 'First new comment', - 'Second new comment', - 'Third new comment' - ); - $this->assertEqual(Set::extract($result['Comment'], '{n}.comment'), $expected); - } -/** - * testSaveAllHasManyValidation method - * - * @access public - * @return void - */ - function testSaveAllHasManyValidation() { - $this->loadFixtures('Article', 'Comment'); - $TestModel =& new Article(); - $TestModel->belongsTo = $TestModel->hasAndBelongsToMany = array(); - $TestModel->Comment->validate = array('comment' => 'notEmpty'); - - $result = $TestModel->saveAll(array( - 'Article' => array('id' => 2), - 'Comment' => array( - array('comment' => '', 'published' => 'Y', 'user_id' => 1), - ) - )); - $expected = array('Comment' => array(false)); - $this->assertEqual($result, $expected); - - $expected = array('Comment' => array( - array('comment' => 'This field cannot be left blank') - )); - $this->assertEqual($TestModel->validationErrors, $expected); - $expected = array( - array('comment' => 'This field cannot be left blank') - ); - $this->assertEqual($TestModel->Comment->validationErrors, $expected); - - $result = $TestModel->saveAll(array( - 'Article' => array('id' => 2), - 'Comment' => array( - array( - 'comment' => '', - 'published' => 'Y', - 'user_id' => 1 - )) - ), array('validate' => 'only')); - } -/** - * testSaveAllTransaction method - * - * @access public - * @return void - */ - function testSaveAllTransaction() { - $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment'); - $TestModel =& new Post(); - - $TestModel->validate = array('title' => 'notEmpty'); - $data = array( - array('author_id' => 1, 'title' => 'New Fourth Post'), - array('author_id' => 1, 'title' => 'New Fifth Post'), - array('author_id' => 1, 'title' => '') - ); - $ts = date('Y-m-d H:i:s'); - $this->assertFalse($TestModel->saveAll($data)); - - $result = $TestModel->find('all', array('recursive' => -1)); - $expected = array( - array('Post' => array( - 'id' => '1', - 'author_id' => 1, - 'title' => 'First Post', - 'body' => 'First Post Body', - 'published' => 'Y', + $joinThingData = array( + 'JoinThing' => array( + 'something_id' => 1, + 'something_else_id' => 2, + 'doomed' => '0', 'created' => '2007-03-18 10:39:23', 'updated' => '2007-03-18 10:41:31' - )), - array('Post' => array( - 'id' => '2', - 'author_id' => 3, - 'title' => 'Second Post', - 'body' => 'Second Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - )), - array('Post' => array( - 'id' => '3', - 'author_id' => 1, - 'title' => 'Third Post', - 'body' => 'Third Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ))); + ) + ); + $Something->JoinThing->create($joinThingData); + $Something->JoinThing->save(); - if (count($result) != 3) { - // Database doesn't support transactions - $expected[] = array( - 'Post' => array( - 'id' => '4', - 'author_id' => 1, - 'title' => 'New Fourth Post', - 'body' => null, - 'published' => 'N', - 'created' => $ts, - 'updated' => $ts - )); + $result = $Something->JoinThing->find('all', array('conditions' => array('something_else_id' => 2))); + $this->assertEqual($result[0]['JoinThing']['doomed'], 1); + $this->assertEqual($result[1]['JoinThing']['doomed'], 0); - $expected[] = array( - 'Post' => array( - 'id' => '5', - 'author_id' => 1, - 'title' => 'New Fifth Post', - 'body' => null, - 'published' => 'N', - 'created' => $ts, - 'updated' => $ts - )); + $result = $Something->find('first'); + $this->assertEqual(count($result['SomethingElse']), 2); + $this->assertEqual($result['SomethingElse'][0]['JoinThing']['doomed'], 1); + $this->assertEqual($result['SomethingElse'][1]['JoinThing']['doomed'], 0); + } +/** + * testGroupBy method + * + * These tests will never pass with Postgres or Oracle as all fields in a select must be + * part of an aggregate function or in the GROUP BY statement. + * + * @access public + * @return void + */ + function testGroupBy() { + $db = ConnectionManager::getDataSource('test_suite'); + $isStrictGroupBy = in_array($db->config['driver'], array('postgres', 'oracle')); + $message = '%s Postgresql and Oracle have strict GROUP BY and are incompatible with this test.'; - $this->assertEqual($result, $expected); - // Skip the rest of the transactional tests + if ($this->skipIf($isStrictGroupBy, $message )) { return; } - $this->assertEqual($result, $expected); + $this->loadFixtures('Project', 'Product', 'Thread', 'Message', 'Bid'); + $Thread =& new Thread(); + $Product =& new Product(); - $data = array( - array('author_id' => 1, 'title' => 'New Fourth Post'), - array('author_id' => 1, 'title' => ''), - array('author_id' => 1, 'title' => 'New Sixth Post') - ); - $ts = date('Y-m-d H:i:s'); - $this->assertFalse($TestModel->saveAll($data)); - - $result = $TestModel->find('all', array('recursive' => -1)); - $expected = array( - array('Post' => array( - 'id' => '1', - 'author_id' => 1, - 'title' => 'First Post', - 'body' => 'First Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - )), - array('Post' => array( - 'id' => '2', - 'author_id' => 3, - 'title' => 'Second Post', - 'body' => 'Second Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - )), - array('Post' => array( - 'id' => '3', - 'author_id' => 1, - 'title' => 'Third Post', - 'body' => 'Third Post Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ))); - - if (count($result) != 3) { - // Database doesn't support transactions - $expected[] = array( - 'Post' => array( - 'id' => '4', - 'author_id' => 1, - 'title' => 'New Fourth Post', - 'body' => 'Third Post Body', - 'published' => 'N', - 'created' => $ts, - 'updated' => $ts - )); - - $expected[] = array( - 'Post' => array( - 'id' => '5', - 'author_id' => 1, - 'title' => 'Third Post', - 'body' => 'Third Post Body', - 'published' => 'N', - 'created' => $ts, - 'updated' => $ts - )); - } - $this->assertEqual($result, $expected); - - $TestModel->validate = array('title' => 'notEmpty'); - $data = array( - array('author_id' => 1, 'title' => 'New Fourth Post'), - array('author_id' => 1, 'title' => 'New Fifth Post'), - array('author_id' => 1, 'title' => 'New Sixth Post') - ); - $this->assertTrue($TestModel->saveAll($data)); - - $result = $TestModel->find('all', array( - 'recursive' => -1, - 'fields' => array('author_id', 'title','body','published') + $result = $Thread->find('all', array( + 'group' => 'Thread.project_id', + 'order' => 'Thread.id ASC' )); $expected = array( - array('Post' => array( - 'author_id' => 1, - 'title' => 'First Post', - 'body' => 'First Post Body', - 'published' => 'Y' - )), - array('Post' => array( - 'author_id' => 3, - 'title' => 'Second Post', - 'body' => 'Second Post Body', - 'published' => 'Y' - )), - array('Post' => array( - 'author_id' => 1, - 'title' => 'Third Post', - 'body' => 'Third Post Body', - 'published' => 'Y' - )), - array('Post' => array( - 'author_id' => 1, - 'title' => 'New Fourth Post', - 'body' => '', - 'published' => 'N' - )), - array('Post' => array( - 'author_id' => 1, - 'title' => 'New Fifth Post', - 'body' => '', - 'published' => 'N' - )), - array('Post' => array( - 'author_id' => 1, - 'title' => 'New Sixth Post', - 'body' => '', - 'published' => 'N' - ))); - $this->assertEqual($result, $expected); - } - -/** - * testSaveAllValidation method - * - * @access public - * @return void - */ - function testSaveAllValidation() { - $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment'); - $TestModel =& new Post(); - - $data = array( - array('id' => '1', 'title' => 'Baleeted First Post', 'body' => 'Baleeted!', 'published' => 'N'), - array('id' => '2', 'title' => 'Just update the title'), - array('title' => 'Creating a fourth post', 'body' => 'Fourth post body', 'author_id' => 2) - ); - $this->assertTrue($TestModel->saveAll($data)); - - $result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC')); - $ts = date('Y-m-d H:i:s'); - $expected = array( - array('Post' => array('id' => '1', 'author_id' => '1', 'title' => 'Baleeted First Post', 'body' => 'Baleeted!', 'published' => 'N', 'created' => '2007-03-18 10:39:23', 'updated' => $ts)), - array('Post' => array('id' => '2', 'author_id' => '3', 'title' => 'Just update the title', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => $ts)), - array('Post' => array('id' => '3', 'author_id' => '1', 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31')), - array('Post' => array('id' => '4', 'author_id' => '2', 'title' => 'Creating a fourth post', 'body' => 'Fourth post body', 'published' => 'N', 'created' => $ts, 'updated' => $ts)) - ); - $this->assertEqual($result, $expected); - - $TestModel->validate = array('title' => 'notEmpty', 'author_id' => 'numeric'); - $data = array( - array('id' => '1', 'title' => 'Un-Baleeted First Post', 'body' => 'Not Baleeted!', 'published' => 'Y'), - array('id' => '2', 'title' => '', 'body' => 'Trying to get away with an empty title'), - ); - $result = $TestModel->saveAll($data); - $this->assertEqual($result, false); - - $result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC')); - $errors = array(1 => array('title' => 'This field cannot be left blank')); - $transactionWorked = Set::matches('/Post[1][title=Baleeted First Post]', $result); - if (!$transactionWorked) { - $this->assertTrue(Set::matches('/Post[1][title=Un-Baleeted First Post]', $result)); - $this->assertTrue(Set::matches('/Post[2][title=Just update the title]', $result)); - } - - $this->assertEqual($TestModel->validationErrors, $errors); - - $TestModel->validate = array('title' => 'notEmpty', 'author_id' => 'numeric'); - $data = array( - array('id' => '1', 'title' => 'Un-Baleeted First Post', 'body' => 'Not Baleeted!', 'published' => 'Y'), - array('id' => '2', 'title' => '', 'body' => 'Trying to get away with an empty title'), - ); - $result = $TestModel->saveAll($data, array('atomic' => false)); - $this->assertEqual($result, array(true, false)); - $result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC')); - $errors = array(1 => array('title' => 'This field cannot be left blank')); - $newTs = date('Y-m-d H:i:s'); - $expected = array( - array('Post' => array('id' => '1', 'author_id' => '1', 'title' => 'Un-Baleeted First Post', 'body' => 'Not Baleeted!', 'published' => 'Y', 'created' => '2007-03-18 10:39:23', 'updated' => $newTs)), - array('Post' => array('id' => '2', 'author_id' => '3', 'title' => 'Just update the title', 'body' => 'Second Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => $ts)), - array('Post' => array('id' => '3', 'author_id' => '1', 'title' => 'Third Post', 'body' => 'Third Post Body', 'published' => 'Y', 'created' => '2007-03-18 10:43:23', 'updated' => '2007-03-18 10:45:31')), - array('Post' => array('id' => '4', 'author_id' => '2', 'title' => 'Creating a fourth post', 'body' => 'Fourth post body', 'published' => 'N', 'created' => $ts, 'updated' => $ts)) - ); - $this->assertEqual($result, $expected); - $this->assertEqual($TestModel->validationErrors, $errors); - - $data = array( - array('id' => '1', 'title' => 'Re-Baleeted First Post', 'body' => 'Baleeted!', 'published' => 'N'), - array('id' => '2', 'title' => '', 'body' => 'Trying to get away with an empty title'), - ); - $this->assertFalse($TestModel->saveAll($data, array('validate' => 'first'))); - - $result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC')); - $this->assertEqual($result, $expected); - $this->assertEqual($TestModel->validationErrors, $errors); - - $data = array( array( - 'title' => 'First new post', - 'body' => 'Woohoo!', - 'published' => 'Y' - ), - array( - 'title' => 'Empty body', - 'body' => '' - )); - - $TestModel->validate['body'] = 'notEmpty'; - } -/** - * testSaveAllValidationOnly method - * - * @access public - * @return void - */ - function testSaveAllValidationOnly() { - $TestModel =& new Comment(); - $TestModel->Attachment->validate = array('attachment' => 'notEmpty'); - - $data = array( - 'Comment' => array( - 'comment' => 'This is the comment' - ), - 'Attachment' => array( - 'attachment' => '' - ) - ); - - $result = $TestModel->saveAll($data, array('validate' => 'only')); - $this->assertFalse($result); - - $TestModel =& new Article(); - $TestModel->validate = array('title' => 'notEmpty'); - $result = $TestModel->saveAll( - array( - 0 => array('title' => ''), - 1 => array('title' => 'title 1'), - 2 => array('title' => 'title 2'), - ), - array('validate'=>'only') - ); - $this->assertFalse($result); - $expected = array( - 0 => array('title' => 'This field cannot be left blank'), - ); - $this->assertEqual($TestModel->validationErrors, $expected); - - $result = $TestModel->saveAll( - array( - 0 => array('title' => 'title 0'), - 1 => array('title' => ''), - 2 => array('title' => 'title 2'), - ), - array('validate'=>'only') - ); - $this->assertFalse($result); - $expected = array( - 1 => array('title' => 'This field cannot be left blank'), - ); - $this->assertEqual($TestModel->validationErrors, $expected); - } -/** - * testSaveAllValidateFirst method - * - * @access public - * @return void - */ - function testSaveAllValidateFirst() { - $model =& new Article(); - $model->deleteAll(true); - - $model->Comment->validate = array('comment' => 'notEmpty'); - $result = $model->saveAll(array( - 'Article' => array( - 'title' => 'Post with Author', - 'body' => 'This post will be saved author' - ), - 'Comment' => array( - array('comment' => 'First new comment'), - array('comment' => '') - ) - ), array('validate' => 'first')); - - $this->assertFalse($result); - - $result = $model->find('all'); - $this->assertEqual($result, array()); - $expected = array('Comment' => array( - 1 => array('comment' => 'This field cannot be left blank') - )); - - $this->assertEqual($model->Comment->validationErrors, $expected['Comment']); - - $this->assertIdentical($model->Comment->find('count'), 0); - - $result = $model->saveAll( - array( - 'Article' => array( - 'title' => 'Post with Author', - 'body' => 'This post will be saved with an author', - 'user_id' => 2 + 'Thread' => array( + 'id' => 1, + 'project_id' => 1, + 'name' => 'Project 1, Thread 1' ), - 'Comment' => array( + 'Project' => array( + 'id' => 1, + 'name' => 'Project 1' + ), + 'Message' => array( array( - 'comment' => 'Only new comment', - 'user_id' => 2 + 'id' => 1, + 'thread_id' => 1, + 'name' => 'Thread 1, Message 1' ))), - array('validate' => 'first') + array( + 'Thread' => array( + 'id' => 3, + 'project_id' => 2, + 'name' => 'Project 2, Thread 1' + ), + 'Project' => array( + 'id' => 2, + 'name' => 'Project 2' + ), + 'Message' => array( + array( + 'id' => 3, + 'thread_id' => 3, + 'name' => 'Thread 3, Message 1' + )))); + $this->assertEqual($result, $expected); + + $rows = $Thread->find('all', array( + 'group' => 'Thread.project_id', + 'fields' => array('Thread.project_id', 'COUNT(*) AS total') + )); + $result = array(); + foreach($rows as $row) { + $result[$row['Thread']['project_id']] = $row[0]['total']; + } + $expected = array( + 1 => 2, + 2 => 1 ); + $this->assertEqual($result, $expected); - $this->assertIdentical($result, true); - - $result = $model->Comment->find('all'); - $this->assertIdentical(count($result), 1); - $result = Set::extract('/Comment/article_id', $result); - $this->assertTrue($result[0] === 1 || $result[0] === '1'); - - - $model->deleteAll(true); - $data = array( - 'Article' => array( - 'title' => 'Post with Author saveAlled from comment', - 'body' => 'This post will be saved with an author', - 'user_id' => 2 - ), - 'Comment' => array( - 'comment' => 'Only new comment', 'user_id' => 2 + $rows = $Thread->find('all', array( + 'group' => 'Thread.project_id', + 'fields' => array('Thread.project_id', 'COUNT(*) AS total'), + 'order'=> 'Thread.project_id' )); + $result = array(); + foreach($rows as $row) { + $result[$row['Thread']['project_id']] = $row[0]['total']; + } + $expected = array( + 1 => 2, + 2 => 1 + ); + $this->assertEqual($result, $expected); - $result = $model->Comment->saveAll($data, array('validate' => 'first')); - $this->assertTrue($result); - - $result = $model->find('all'); - $this->assertEqual($result[0]['Article']['title'], 'Post with Author saveAlled from comment'); - $this->assertEqual($result[0]['Comment'][0]['comment'], 'Only new comment'); - } -/** - * testSaveWithCounterCache method - * - * @access public - * @return void - */ - function testSaveWithCounterCache() { - $this->loadFixtures('Syfile', 'Item'); - $TestModel =& new Syfile(); - $TestModel2 =& new Item(); - - $result = $TestModel->findById(1); - $this->assertIdentical($result['Syfile']['item_count'], null); - - $TestModel2->save(array( - 'name' => 'Item 7', - 'syfile_id' => 1, - 'published' => false + $result = $Thread->find('all', array( + 'conditions' => array('Thread.project_id' => 1), + 'group' => 'Thread.project_id' )); + $expected = array( + array( + 'Thread' => array( + 'id' => 1, + 'project_id' => 1, + 'name' => 'Project 1, Thread 1' + ), + 'Project' => array( + 'id' => 1, + 'name' => 'Project 1' + ), + 'Message' => array( + array( + 'id' => 1, + 'thread_id' => 1, + 'name' => 'Thread 1, Message 1' + )))); + $this->assertEqual($result, $expected); - $result = $TestModel->findById(1); - $this->assertIdentical($result['Syfile']['item_count'], '2'); - - $TestModel2->delete(1); - $result = $TestModel->findById(1); - $this->assertIdentical($result['Syfile']['item_count'], '1'); - - $TestModel2->id = 2; - $TestModel2->saveField('syfile_id', 1); - - $result = $TestModel->findById(1); - $this->assertIdentical($result['Syfile']['item_count'], '2'); - - $result = $TestModel->findById(2); - $this->assertIdentical($result['Syfile']['item_count'], '0'); - } -/** - * Tests that counter caches are updated when records are added - * - * @access public - * @return void - */ - function testCounterCacheIncrease() { - $this->loadFixtures('CounterCacheUser', 'CounterCachePost'); - $User = new CounterCacheUser(); - $Post = new CounterCachePost(); - $data = array('Post' => array( - 'title' => 'New Post', - 'user_id' => 66 + $result = $Thread->find('all', array( + 'conditions' => array('Thread.project_id' => 1), + 'group' => 'Thread.project_id, Project.id' )); + $this->assertEqual($result, $expected); - $Post->save($data); - $user = $User->find('first', array( - 'conditions' => array('id' => 66), - 'recursive' => -1 + $result = $Thread->find('all', array( + 'conditions' => array('Thread.project_id' => 1), + 'group' => 'project_id' )); + $this->assertEqual($result, $expected); - $result = $user[$User->alias]['post_count']; - $expected = 3; + + $result = $Thread->find('all', array( + 'conditions' => array('Thread.project_id' => 1), + 'group' => array('project_id') + )); + $this->assertEqual($result, $expected); + + + $result = $Thread->find('all', array( + 'conditions' => array('Thread.project_id' => 1), + 'group' => array('project_id', 'Project.id') + )); + $this->assertEqual($result, $expected); + + + $result = $Thread->find('all', array( + 'conditions' => array('Thread.project_id' => 1), + 'group' => array('Thread.project_id', 'Project.id') + )); + $this->assertEqual($result, $expected); + + + $expected = array( + array('Product' => array('type' => 'Clothing'), array('price' => 32)), + array('Product' => array('type' => 'Food'), array('price' => 9)), + array('Product' => array('type' => 'Music'), array( 'price' => 4)), + array('Product' => array('type' => 'Toy'), array('price' => 3)) + ); + $result = $Product->find('all',array( + 'fields'=>array('Product.type','MIN(Product.price) as price'), + 'group'=> 'Product.type', + 'order' => 'Product.type ASC' + )); + $this->assertEqual($result, $expected); + + $result = $Product->find('all', array( + 'fields'=>array('Product.type','MIN(Product.price) as price'), + 'group'=> array('Product.type'), + 'order' => 'Product.type ASC')); $this->assertEqual($result, $expected); } /** - * Tests that counter caches are updated when records are deleted + * testOldQuery method * * @access public * @return void */ - function testCounterCacheDecrease() { - $this->loadFixtures('CounterCacheUser', 'CounterCachePost'); - $User = new CounterCacheUser(); - $Post = new CounterCachePost(); + function testOldQuery() { + $this->loadFixtures('Article'); + $Article =& new Article(); - $Post->del(2); - $user = $User->find('first', array( - 'conditions' => array('id' => 66), - 'recursive' => -1 + $query = 'SELECT title FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.id IN (1,2)'; + + $results = $Article->query($query); + $this->assertTrue(is_array($results)); + $this->assertEqual(count($results), 2); + + $query = 'SELECT title, body FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.id = 1'; + + $results = $Article->query($query, false); + $this->assertTrue(!isset($this->db->_queryCache[$query])); + $this->assertTrue(is_array($results)); + + $query = 'SELECT title, id FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles'); + $query .= '.published = ' . $this->db->value('Y'); + + $results = $Article->query($query, true); + $this->assertTrue(isset($this->db->_queryCache[$query])); + $this->assertTrue(is_array($results)); + } +/** + * testPreparedQuery method + * + * @access public + * @return void + */ + function testPreparedQuery() { + $this->loadFixtures('Article'); + $Article =& new Article(); + $this->db->_queryCache = array(); + + $finalQuery = 'SELECT title, published FROM '; + $finalQuery .= $this->db->fullTableName('articles'); + $finalQuery .= ' WHERE ' . $this->db->fullTableName('articles'); + $finalQuery .= '.id = ' . $this->db->value(1); + $finalQuery .= ' AND ' . $this->db->fullTableName('articles'); + $finalQuery .= '.published = ' . $this->db->value('Y'); + + $query = 'SELECT title, published FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles'); + $query .= '.id = ? AND ' . $this->db->fullTableName('articles') . '.published = ?'; + + $params = array(1, 'Y'); + $result = $Article->query($query, $params); + $expected = array( + '0' => array( + $this->db->fullTableName('articles', false) => array( + 'title' => 'First Article', 'published' => 'Y') )); - $result = $user[$User->alias]['post_count']; - $expected = 1; + if (isset($result[0][0])) { + $expected[0][0] = $expected[0][$this->db->fullTableName('articles', false)]; + unset($expected[0][$this->db->fullTableName('articles', false)]); + } + $this->assertEqual($result, $expected); - } -/** - * Tests that counter caches are updated when foreign keys of counted records change - * - * @access public - * @return void - */ - function testCounterCacheUpdated() { - $this->loadFixtures('CounterCacheUser', 'CounterCachePost'); - $User = new CounterCacheUser(); - $Post = new CounterCachePost(); + $this->assertTrue(isset($this->db->_queryCache[$finalQuery])); - $data = $Post->find('first', array( - 'conditions' => array('id' => 1), - 'recursive' => -1 - )); - $data[$Post->alias]['user_id'] = 301; - $Post->save($data); + $finalQuery = 'SELECT id, created FROM '; + $finalQuery .= $this->db->fullTableName('articles'); + $finalQuery .= ' WHERE ' . $this->db->fullTableName('articles'); + $finalQuery .= '.title = ' . $this->db->value('First Article'); - $users = $User->find('all',array('order' => 'User.id')); - $this->assertEqual($users[0]['User']['post_count'], 1); - $this->assertEqual($users[1]['User']['post_count'], 2); - } -/** - * Test counter cache with models that use a non-standard (i.e. not using 'id') - * as their primary key. - * - * @access public - * @return void - */ - function testCounterCacheWithNonstandardPrimaryKey() { - $this->loadFixtures( - 'CounterCacheUserNonstandardPrimaryKey', - 'CounterCachePostNonstandardPrimaryKey' + $query = 'SELECT id, created FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.title = ?'; + + $params = array('First Article'); + $result = $Article->query($query, $params, false); + $this->assertTrue(is_array($result)); + $this->assertTrue( + isset($result[0][$this->db->fullTableName('articles', false)]) + || isset($result[0][0]) + ); + $this->assertFalse(isset($this->db->_queryCache[$finalQuery])); + + $query = 'SELECT title FROM '; + $query .= $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.title LIKE ?'; + + $params = array('%First%'); + $result = $Article->query($query, $params); + $this->assertTrue(is_array($result)); + $this->assertTrue( + isset($result[0][$this->db->fullTableName('articles', false)]['title']) + || isset($result[0][0]['title']) ); - $User = new CounterCacheUserNonstandardPrimaryKey(); - $Post = new CounterCachePostNonstandardPrimaryKey(); + //related to ticket #5035 + $query = 'SELECT title FROM '; + $query .= $this->db->fullTableName('articles') . ' WHERE title = ? AND published = ?'; + $params = array('First? Article', 'Y'); + $Article->query($query, $params); - $data = $Post->find('first', array( - 'conditions' => array('pid' => 1), - 'recursive' => -1 - )); - $data[$Post->alias]['uid'] = 301; - $Post->save($data); - - $users = $User->find('all',array('order' => 'User.uid')); - $this->assertEqual($users[0]['User']['post_count'], 1); - $this->assertEqual($users[1]['User']['post_count'], 2); - } + $expected = 'SELECT title FROM '; + $expected .= $this->db->fullTableName('articles'); + $expected .= " WHERE title = 'First? Article' AND published = 'Y'"; + $this->assertTrue(isset($this->db->_queryCache[$expected])); + } /** - * test Counter Cache With Self Joining table + * testParameterMismatch method * - * @return void * @access public + * @return void */ - function testCounterCacheWithSelfJoin() { - $skip = $this->skipIf( - ($this->db->config['driver'] == 'sqlite'), - 'SQLite 2.x does not support ALTER TABLE ADD COLUMN' - ); - if ($skip) { + function testParameterMismatch() { + $this->loadFixtures('Article'); + $Article =& new Article(); + + $query = 'SELECT * FROM ' . $this->db->fullTableName('articles'); + $query .= ' WHERE ' . $this->db->fullTableName('articles'); + $query .= '.published = ? AND ' . $this->db->fullTableName('articles') . '.user_id = ?'; + $params = array('Y'); + $this->expectError(); + + ob_start(); + $result = $Article->query($query, $params); + ob_end_clean(); + $this->assertEqual($result, null); + } +/** + * testVeryStrangeUseCase method + * + * @access public + * @return void + */ + function testVeryStrangeUseCase() { + $message = "%s skipping SELECT * FROM ? WHERE ? = ? AND ? = ?; prepared query."; + $message .= " MSSQL is incompatible with this test."; + + if ($this->skipIf($this->db->config['driver'] == 'mssql', $message)) { return; } - $this->loadFixtures('CategoryThread'); - $this->db->query('ALTER TABLE '. $this->db->fullTableName('category_threads') . " ADD COLUMN child_count INTEGER"); - $Category =& new CategoryThread(); - $result = $Category->updateAll(array('CategoryThread.name' => "'updated'"), array('CategoryThread.parent_id' => 5)); - $this->assertTrue($result); - - $Category =& new CategoryThread(); - $Category->belongsTo['ParentCategory']['counterCache'] = 'child_count'; - $Category->updateCounterCache(array('parent_id' => 5)); - $result = Set::extract($Category->find('all', array('conditions' => array('CategoryThread.id' => 5))), '{n}.CategoryThread.child_count'); - $expected = array_fill(0, 1, 1); - $this->assertEqual($result, $expected); - } -/** - * testSaveWithCounterCacheScope method - * - * @access public - * @return void - */ - function testSaveWithCounterCacheScope() { - $this->loadFixtures('Syfile', 'Item'); - $TestModel =& new Syfile(); - $TestModel2 =& new Item(); - $TestModel2->belongsTo['Syfile']['counterCache'] = true; - $TestModel2->belongsTo['Syfile']['counterScope'] = array('published' => true); - - $result = $TestModel->findById(1); - $this->assertIdentical($result['Syfile']['item_count'], null); - - $TestModel2->save(array( - 'name' => 'Item 7', - 'syfile_id' => 1, - 'published'=> true - )); - - $result = $TestModel->findById(1); - $this->assertIdentical($result['Syfile']['item_count'], '1'); - - $TestModel2->id = 1; - $TestModel2->saveField('published', true); - $result = $TestModel->findById(1); - $this->assertIdentical($result['Syfile']['item_count'], '2'); - - $TestModel2->save(array( - 'id' => 1, - 'syfile_id' => 1, - 'published'=> false - )); - - $result = $TestModel->findById(1); - $this->assertIdentical($result['Syfile']['item_count'], '1'); - } -/** - * testDel method - * - * @access public - * @return void - */ - function testDel() { $this->loadFixtures('Article'); - $TestModel =& new Article(); + $Article =& new Article(); - $result = $TestModel->del(2); - $this->assertTrue($result); - - $result = $TestModel->read(null, 2); - $this->assertFalse($result); - - $TestModel->recursive = -1; - $result = $TestModel->find('all', array( - 'fields' => array('id', 'title') - )); - $expected = array( - array('Article' => array( - 'id' => 1, - 'title' => 'First Article' - )), - array('Article' => array( - 'id' => 3, - 'title' => 'Third Article' - ))); - $this->assertEqual($result, $expected); - - $result = $TestModel->del(3); - $this->assertTrue($result); - - $result = $TestModel->read(null, 3); - $this->assertFalse($result); - - $TestModel->recursive = -1; - $result = $TestModel->find('all', array( - 'fields' => array('id', 'title') - )); - $expected = array( - array('Article' => array( - 'id' => 1, - 'title' => 'First Article' - ))); - - $this->assertEqual($result, $expected); - - - // make sure deleting a non-existent record doesn't break save() - // ticket #6293 - $this->loadFixtures('Uuid'); - $Uuid =& new Uuid(); - $data = array( - 'B607DAB9-88A2-46CF-B57C-842CA9E3B3B3', - '52C8865C-10EE-4302-AE6C-6E7D8E12E2C8', - '8208C7FE-E89C-47C5-B378-DED6C271F9B8'); - foreach ($data as $id) { - $Uuid->save(array('id' => $id)); - } - $Uuid->del('52C8865C-10EE-4302-AE6C-6E7D8E12E2C8'); - $Uuid->del('52C8865C-10EE-4302-AE6C-6E7D8E12E2C8'); - foreach ($data as $id) { - $Uuid->save(array('id' => $id)); - } - $result = $Uuid->find('all', array( - 'conditions' => array('id' => $data), - 'fields' => array('id'), - 'order' => 'id')); - $expected = array( - array('Uuid' => array( - 'id' => '52C8865C-10EE-4302-AE6C-6E7D8E12E2C8')), - array('Uuid' => array( - 'id' => '8208C7FE-E89C-47C5-B378-DED6C271F9B8')), - array('Uuid' => array( - 'id' => 'B607DAB9-88A2-46CF-B57C-842CA9E3B3B3'))); - $this->assertEqual($result, $expected); - } -/** - * testDeleteAll method - * - * @access public - * @return void - */ - function testDeleteAll() { - $this->loadFixtures('Article'); - $TestModel =& new Article(); - - $data = array('Article' => array( - 'user_id' => 2, - 'id' => 4, - 'title' => 'Fourth Article', - 'published' => 'N' - )); - $result = $TestModel->set($data) && $TestModel->save(); - $this->assertTrue($result); - - $data = array('Article' => array( - 'user_id' => 2, - 'id' => 5, - 'title' => 'Fifth Article', - 'published' => 'Y' - )); - $result = $TestModel->set($data) && $TestModel->save(); - $this->assertTrue($result); - - $data = array('Article' => array( - 'user_id' => 1, - 'id' => 6, - 'title' => 'Sixth Article', - 'published' => 'N' - )); - $result = $TestModel->set($data) && $TestModel->save(); - $this->assertTrue($result); - - $TestModel->recursive = -1; - $result = $TestModel->find('all', array( - 'fields' => array('id', 'user_id', 'title', 'published') - )); - - $expected = array( - array('Article' => array( - 'id' => 1, - 'user_id' => 1, - 'title' => 'First Article', - 'published' => 'Y' - )), - array('Article' => array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Article', - 'published' => 'Y' - )), - array('Article' => array( - 'id' => 3, - 'user_id' => 1, - 'title' => 'Third Article', - 'published' => 'Y')), - array('Article' => array( - 'id' => 4, - 'user_id' => 2, - 'title' => 'Fourth Article', - 'published' => 'N' - )), - array('Article' => array( - 'id' => 5, - 'user_id' => 2, - 'title' => 'Fifth Article', - 'published' => 'Y' - )), - array('Article' => array( - 'id' => 6, - 'user_id' => 1, - 'title' => 'Sixth Article', - 'published' => 'N' - ))); - - $this->assertEqual($result, $expected); - - $result = $TestModel->deleteAll(array('Article.published' => 'N')); - $this->assertTrue($result); - - $TestModel->recursive = -1; - $result = $TestModel->find('all', array( - 'fields' => array('id', 'user_id', 'title', 'published') - )); - $expected = array( - array('Article' => array( - 'id' => 1, - 'user_id' => 1, - 'title' => 'First Article', - 'published' => 'Y' - )), - array('Article' => array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Article', - 'published' => 'Y' - )), - array('Article' => array( - 'id' => 3, - 'user_id' => 1, - 'title' => 'Third Article', - 'published' => 'Y' - )), - array('Article' => array( - 'id' => 5, - 'user_id' => 2, - 'title' => 'Fifth Article', - 'published' => 'Y' - ))); - $this->assertEqual($result, $expected); - - $data = array('Article.user_id' => array(2, 3)); - $result = $TestModel->deleteAll($data, true, true); - $this->assertTrue($result); - - $TestModel->recursive = -1; - $result = $TestModel->find('all', array( - 'fields' => array('id', 'user_id', 'title', 'published') - )); - $expected = array( - array('Article' => array( - 'id' => 1, - 'user_id' => 1, - 'title' => 'First Article', - 'published' => 'Y' - )), - array('Article' => array( - 'id' => 3, - 'user_id' => 1, - 'title' => 'Third Article', - 'published' => 'Y' - ))); - $this->assertEqual($result, $expected); - - $result = $TestModel->deleteAll(array('Article.user_id' => 999)); - $this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s'); - } -/** - * testRecursiveDel method - * - * @access public - * @return void - */ - function testRecursiveDel() { - $this->loadFixtures('Article', 'Comment', 'Attachment'); - $TestModel =& new Article(); - - $result = $TestModel->del(2); - $this->assertTrue($result); - - $TestModel->recursive = 2; - $result = $TestModel->read(null, 2); - $this->assertFalse($result); - - $result = $TestModel->Comment->read(null, 5); - $this->assertFalse($result); - - $result = $TestModel->Comment->read(null, 6); - $this->assertFalse($result); - - $result = $TestModel->Comment->Attachment->read(null, 1); - $this->assertFalse($result); - - $result = $TestModel->find('count'); - $this->assertEqual($result, 2); - - $result = $TestModel->Comment->find('count'); - $this->assertEqual($result, 4); - - $result = $TestModel->Comment->Attachment->find('count'); - $this->assertEqual($result, 0); - } -/** - * testDependentExclusiveDelete method - * - * @access public - * @return void - */ - function testDependentExclusiveDelete() { - $this->loadFixtures('Article', 'Comment'); - $TestModel =& new Article10(); - - $result = $TestModel->find('all'); - $this->assertEqual(count($result[0]['Comment']), 4); - $this->assertEqual(count($result[1]['Comment']), 2); - $this->assertEqual($TestModel->Comment->find('count'), 6); - - $TestModel->delete(1); - $this->assertEqual($TestModel->Comment->find('count'), 2); - } -/** - * testDeleteLinks method - * - * @access public - * @return void - */ - function testDeleteLinks() { - $this->loadFixtures('Article', 'ArticlesTag', 'Tag'); - $TestModel =& new Article(); - - $result = $TestModel->ArticlesTag->find('all'); - $expected = array( - array('ArticlesTag' => array( - 'article_id' => '1', - 'tag_id' => '1' - )), - array('ArticlesTag' => array( - 'article_id' => '1', - 'tag_id' => '2' - )), - array('ArticlesTag' => array( - 'article_id' => '2', - 'tag_id' => '1' - )), - array('ArticlesTag' => array( - 'article_id' => '2', - 'tag_id' => '3' - ))); - $this->assertEqual($result, $expected); - - $TestModel->delete(1); - $result = $TestModel->ArticlesTag->find('all'); - - $expected = array( - array('ArticlesTag' => array( - 'article_id' => '2', - 'tag_id' => '1' - )), - array('ArticlesTag' => array( - 'article_id' => '2', - 'tag_id' => '3' - ))); - $this->assertEqual($result, $expected); - } -/** - * testFindAllThreaded method - * - * @access public - * @return void - */ - function testFindAllThreaded() { - $this->loadFixtures('Category'); - $TestModel =& new Category(); - - $result = $TestModel->find('threaded'); - $expected = array( - array( - 'Category' => array( - 'id' => '1', - 'parent_id' => '0', - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '2', - 'parent_id' => '1', - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array('Category' => array( - 'id' => '7', - 'parent_id' => '2', - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array()), - array('Category' => array( - 'id' => '8', - 'parent_id' => '2', - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array())) - ), - array( - 'Category' => array( - 'id' => '3', - 'parent_id' => '1', - 'name' => 'Category 1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ) - ) - ), - array( - 'Category' => array( - 'id' => '4', - 'parent_id' => '0', - 'name' => 'Category 2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ), - array( - 'Category' => array( - 'id' => '5', - 'parent_id' => '0', - 'name' => 'Category 3', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '6', - 'parent_id' => '5', - 'name' => 'Category 3.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ) - ) - ) + $query = 'SELECT * FROM ? WHERE ? = ? AND ? = ?'; + $param = array( + $this->db->fullTableName('articles'), + $this->db->fullTableName('articles') . '.user_id', '3', + $this->db->fullTableName('articles') . '.published', 'Y' ); - $this->assertEqual($result, $expected); + $this->expectError(); - $result = $TestModel->find('threaded', array( - 'conditions' => array('Category.name LIKE' => 'Category 1%') - )); - - $expected = array( - array( - 'Category' => array( - 'id' => '1', - 'parent_id' => '0', - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '2', - 'parent_id' => '1', - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array('Category' => array( - 'id' => '7', - 'parent_id' => '2', - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array()), - array('Category' => array( - 'id' => '8', - 'parent_id' => '2', - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array())) - ), - array( - 'Category' => array( - 'id' => '3', - 'parent_id' => '1', - 'name' => 'Category 1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ) - ) - ) - ); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('threaded', array( - 'fields' => 'id, parent_id, name' - )); - - $expected = array( - array( - 'Category' => array( - 'id' => '1', - 'parent_id' => '0', - 'name' => 'Category 1' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '2', - 'parent_id' => '1', - 'name' => 'Category 1.1' - ), - 'children' => array( - array('Category' => array( - 'id' => '7', - 'parent_id' => '2', - 'name' => 'Category 1.1.1'), - 'children' => array()), - array('Category' => array( - 'id' => '8', - 'parent_id' => '2', - 'name' => 'Category 1.1.2'), - 'children' => array())) - ), - array( - 'Category' => array( - 'id' => '3', - 'parent_id' => '1', - 'name' => 'Category 1.2' - ), - 'children' => array() - ) - ) - ), - array( - 'Category' => array( - 'id' => '4', - 'parent_id' => '0', - 'name' => 'Category 2' - ), - 'children' => array() - ), - array( - 'Category' => array( - 'id' => '5', - 'parent_id' => '0', - 'name' => 'Category 3' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '6', - 'parent_id' => '5', - 'name' => 'Category 3.1' - ), - 'children' => array() - ) - ) - ) - ); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('threaded', array('order' => 'id DESC')); - - $expected = array( - array( - 'Category' => array( - 'id' => 5, - 'parent_id' => 0, - 'name' => 'Category 3', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => 6, - 'parent_id' => 5, - 'name' => 'Category 3.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ) - ) - ), - array( - 'Category' => array( - 'id' => 4, - 'parent_id' => 0, - 'name' => 'Category 2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ), - array( - 'Category' => array( - 'id' => 1, - 'parent_id' => 0, - 'name' => 'Category 1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => 3, - 'parent_id' => 1, - 'name' => 'Category 1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ), - array( - 'Category' => array( - 'id' => 2, - 'parent_id' => 1, - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array('Category' => array( - 'id' => '8', - 'parent_id' => '2', - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array()), - array('Category' => array( - 'id' => '7', - 'parent_id' => '2', - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array())) - ) - ) - ) - ); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('threaded', array( - 'conditions' => array('Category.name LIKE' => 'Category 3%') - )); - $expected = array( - array( - 'Category' => array( - 'id' => '5', - 'parent_id' => '0', - 'name' => 'Category 3', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '6', - 'parent_id' => '5', - 'name' => 'Category 3.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31' - ), - 'children' => array() - ) - ) - ) - ); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('threaded', array( - 'conditions' => array('Category.name LIKE' => 'Category 1.1%') - )); - $expected = array( - array('Category' => - array( - 'id' => '2', - 'parent_id' => '1', - 'name' => 'Category 1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array( - array('Category' => array( - 'id' => '7', - 'parent_id' => '2', - 'name' => 'Category 1.1.1', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array()), - array('Category' => array( - 'id' => '8', - 'parent_id' => '2', - 'name' => 'Category 1.1.2', - 'created' => '2007-03-18 15:30:23', - 'updated' => '2007-03-18 15:32:31'), - 'children' => array())))); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('threaded', array( - 'fields' => 'id, parent_id, name', - 'conditions' => array('Category.id !=' => 2) - )); - $expected = array( - array( - 'Category' => array( - 'id' => '1', - 'parent_id' => '0', - 'name' => 'Category 1' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '3', - 'parent_id' => '1', - 'name' => 'Category 1.2' - ), - 'children' => array() - ) - ) - ), - array( - 'Category' => array( - 'id' => '4', - 'parent_id' => '0', - 'name' => 'Category 2' - ), - 'children' => array() - ), - array( - 'Category' => array( - 'id' => '5', - 'parent_id' => '0', - 'name' => 'Category 3' - ), - 'children' => array( - array( - 'Category' => array( - 'id' => '6', - 'parent_id' => '5', - 'name' => 'Category 3.1' - ), - 'children' => array() - ) - ) - ) - ); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('all', array( - 'fields' => 'id, name, parent_id', - 'conditions' => array('Category.id !=' => 1) - )); - $expected = array ( - array ('Category' => array( - 'id' => '2', - 'name' => 'Category 1.1', - 'parent_id' => '1' - )), - array ('Category' => array( - 'id' => '3', - 'name' => 'Category 1.2', - 'parent_id' => '1' - )), - array ('Category' => array( - 'id' => '4', - 'name' => 'Category 2', - 'parent_id' => '0' - )), - array ('Category' => array( - 'id' => '5', - 'name' => 'Category 3', - 'parent_id' => '0' - )), - array ('Category' => array( - 'id' => '6', - 'name' => 'Category 3.1', - 'parent_id' => '5' - )), - array ('Category' => array( - 'id' => '7', - 'name' => 'Category 1.1.1', - 'parent_id' => '2' - )), - array ('Category' => array( - 'id' => '8', - 'name' => 'Category 1.1.2', - 'parent_id' => '2' - ))); - $this->assertEqual($result, $expected); - - $result = $TestModel->find('threaded', array( - 'fields' => 'id, parent_id, name', - 'conditions' => array('Category.id !=' => 1) - )); - $expected = array( - array( - 'Category' => array( - 'id' => '2', - 'parent_id' => '1', - 'name' => 'Category 1.1' - ), - 'children' => array( - array('Category' => array( - 'id' => '7', - 'parent_id' => '2', - 'name' => 'Category 1.1.1'), - 'children' => array()), - array('Category' => array( - 'id' => '8', - 'parent_id' => '2', - 'name' => 'Category 1.1.2'), - 'children' => array())) - ), - array( - 'Category' => array( - 'id' => '3', - 'parent_id' => '1', - 'name' => 'Category 1.2' - ), - 'children' => array() - ) - ); - $this->assertEqual($result, $expected); - } -/** - * test find('neighbors') - * - * @return void - * @access public - */ - function testFindNeighbors() { - $this->loadFixtures('User', 'Article'); - $TestModel =& new Article(); - - $TestModel->id = 1; - $result = $TestModel->find('neighbors', array('fields' => array('id'))); - $expected = array( - 'prev' => null, - 'next' => array( - 'Article' => array('id' => 2) - )); - $this->assertEqual($result, $expected); - - $TestModel->id = 2; - $result = $TestModel->find('neighbors', array( - 'fields' => array('id') - )); - - $expected = array( - 'prev' => array( - 'Article' => array( - 'id' => 1 - )), - 'next' => array( - 'Article' => array( - 'id' => 3 - ))); - $this->assertEqual($result, $expected); - - $TestModel->id = 3; - $result = $TestModel->find('neighbors', array('fields' => array('id'))); - $expected = array( - 'prev' => array( - 'Article' => array( - 'id' => 2 - )), - 'next' => null - ); - $this->assertEqual($result, $expected); - - $TestModel->id = 1; - $result = $TestModel->find('neighbors', array('recursive' => -1)); - $expected = array( - 'prev' => null, - 'next' => array( - 'Article' => array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ) - ) - ); - $this->assertEqual($result, $expected); - - $TestModel->id = 2; - $result = $TestModel->find('neighbors', array('recursive' => -1)); - $expected = array( - 'prev' => array( - 'Article' => array( - 'id' => 1, - 'user_id' => 1, - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ) - ), - 'next' => array( - 'Article' => array( - 'id' => 3, - 'user_id' => 1, - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ) - ) - ); - $this->assertEqual($result, $expected); - - $TestModel->id = 3; - $result = $TestModel->find('neighbors', array('recursive' => -1)); - $expected = array( - 'prev' => array( - 'Article' => array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ) - ), - 'next' => null - ); - $this->assertEqual($result, $expected); - - $TestModel->recursive = 0; - $TestModel->id = 1; - $one = $TestModel->read(); - $TestModel->id = 2; - $two = $TestModel->read(); - $TestModel->id = 3; - $three = $TestModel->read(); - - $TestModel->id = 1; - $result = $TestModel->find('neighbors'); - $expected = array('prev' => null, 'next' => $two); - $this->assertEqual($result, $expected); - - $TestModel->id = 2; - $result = $TestModel->find('neighbors'); - $expected = array('prev' => $one, 'next' => $three); - $this->assertEqual($result, $expected); - - $TestModel->id = 3; - $result = $TestModel->find('neighbors'); - $expected = array('prev' => $two, 'next' => null); - $this->assertEqual($result, $expected); - - $TestModel->recursive = 2; - $TestModel->id = 1; - $one = $TestModel->read(); - $TestModel->id = 2; - $two = $TestModel->read(); - $TestModel->id = 3; - $three = $TestModel->read(); - - $TestModel->id = 1; - $result = $TestModel->find('neighbors', array('recursive' => 2)); - $expected = array('prev' => null, 'next' => $two); - $this->assertEqual($result, $expected); - - $TestModel->id = 2; - $result = $TestModel->find('neighbors', array('recursive' => 2)); - $expected = array('prev' => $one, 'next' => $three); - $this->assertEqual($result, $expected); - - $TestModel->id = 3; - $result = $TestModel->find('neighbors', array('recursive' => 2)); - $expected = array('prev' => $two, 'next' => null); - $this->assertEqual($result, $expected); - } -/** - * test findNeighbours() method - * - * @return void - * @access public - */ - function testFindNeighboursLegacy() { - $this->loadFixtures('User', 'Article'); - $TestModel =& new Article(); - - $result = $TestModel->findNeighbours(null, 'Article.id', '2'); - $expected = array( - 'prev' => array( - 'Article' => array( - 'id' => 1 - )), - 'next' => array( - 'Article' => array( - 'id' => 3 - ))); - $this->assertEqual($result, $expected); - - $result = $TestModel->findNeighbours(null, 'Article.id', '3'); - $expected = array( - 'prev' => array( - 'Article' => array( - 'id' => 2 - )), - 'next' => array() - ); - $this->assertEqual($result, $expected); - - $result = $TestModel->findNeighbours( - array('User.id' => 1), - array('Article.id', 'Article.title'), - 2 - ); - $expected = array( - 'prev' => array( - 'Article' => array( - 'id' => 1, - 'title' => 'First Article' - )), - 'next' => array( - 'Article' => array( - 'id' => 3, - 'title' => 'Third Article' - ))); - $this->assertEqual($result, $expected); - } -/** - * testFindCombinedRelations method - * - * @access public - * @return void - */ - function testFindCombinedRelations() { - $this->loadFixtures('Apple', 'Sample'); - $TestModel =& new Apple(); - - $result = $TestModel->find('all'); - - $expected = array( - array( - 'Apple' => array( - 'id' => '1', - 'apple_id' => '2', - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => '2', - 'apple_id' => '1', - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => null, - 'apple_id' => null, - 'name' => null - ), - 'Child' => array( - array( - 'id' => '2', - 'apple_id' => '1', - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => '2', - 'apple_id' => '1', - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => '1', - 'apple_id' => '2', - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => '2', - 'apple_id' => '2', - 'name' => 'sample2' - ), - 'Child' => array( - array( - 'id' => '1', - 'apple_id' => '2', - 'color' => 'Red 1', - 'name' => 'Red Apple 1', - 'created' => '2006-11-22 10:38:58', - 'date' => '1951-01-04', - 'modified' => '2006-12-01 13:31:26', - 'mytime' => '22:57:17' - ), - array( - 'id' => '3', - 'apple_id' => '2', - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - array( - 'id' => '4', - 'apple_id' => '2', - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => '3', - 'apple_id' => '2', - 'color' => 'blue green', - 'name' => 'green blue', - 'created' => '2006-12-25 05:13:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:24', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => '2', - 'apple_id' => '1', - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => '1', - 'apple_id' => '3', - 'name' => 'sample1' - ), - 'Child' => array() - ), - array( - 'Apple' => array( - 'id' => '4', - 'apple_id' => '2', - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => '2', - 'apple_id' => '1', - 'color' => 'Bright Red 1', - 'name' => 'Bright Red Apple', - 'created' => '2006-11-22 10:43:13', - 'date' => '2014-01-01', - 'modified' => '2006-11-30 18:38:10', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => '3', - 'apple_id' => '4', - 'name' => 'sample3' - ), - 'Child' => array( - array( - 'id' => '6', - 'apple_id' => '4', - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => '5', - 'apple_id' => '5', - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => '5', - 'apple_id' => '5', - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => '4', - 'apple_id' => '5', - 'name' => 'sample4' - ), - 'Child' => array( - array( - 'id' => '5', - 'apple_id' => '5', - 'color' => 'Green', - 'name' => 'Blue Green', - 'created' => '2006-12-25 05:24:06', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:16', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => '6', - 'apple_id' => '4', - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => '4', - 'apple_id' => '2', - 'color' => 'Blue Green', - 'name' => 'Test Name', - 'created' => '2006-12-25 05:23:36', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:23:36', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => null, - 'apple_id' => null, - 'name' => null - ), - 'Child' => array( - array( - 'id' => '7', - 'apple_id' => '6', - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ))), - array( - 'Apple' => array( - 'id' => '7', - 'apple_id' => '6', - 'color' => 'Some wierd color', - 'name' => 'Some odd color', - 'created' => '2006-12-25 05:34:21', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:34:21', - 'mytime' => '22:57:17' - ), - 'Parent' => array( - 'id' => '6', - 'apple_id' => '4', - 'color' => 'My new appleOrange', - 'name' => 'My new apple', - 'created' => '2006-12-25 05:29:39', - 'date' => '2006-12-25', - 'modified' => '2006-12-25 05:29:39', - 'mytime' => '22:57:17' - ), - 'Sample' => array( - 'id' => null, - 'apple_id' => null, - 'name' => null - ), - 'Child' => array() - )); - $this->assertEqual($result, $expected); - } -/** - * testSaveEmpty method - * - * @access public - * @return void - */ - function testSaveEmpty() { - $this->loadFixtures('Thread'); - $TestModel =& new Thread(); - $data = array(); - $expected = $TestModel->save($data); - $this->assertFalse($expected); - } - // function testBasicValidation() { - // $TestModel =& new ValidationTest1(); - // $TestModel->testing = true; - // $TestModel->set(array('title' => '', 'published' => 1)); - // $this->assertEqual($TestModel->invalidFields(), array('title' => 'This field cannot be left blank')); - // - // $TestModel->create(); - // $TestModel->set(array('title' => 'Hello', 'published' => 0)); - // $this->assertEqual($TestModel->invalidFields(), array('published' => 'This field cannot be left blank')); - // - // $TestModel->create(); - // $TestModel->set(array('title' => 'Hello', 'published' => 1, 'body' => '')); - // $this->assertEqual($TestModel->invalidFields(), array('body' => 'This field cannot be left blank')); - // } - -/** - * testFindAllWithConditionInChildQuery - * - * @todo external conditions like this are going to need to be revisited at some point - * @access public - * @return void - */ - function testFindAllWithConditionInChildQuery() { - $this->loadFixtures('Basket', 'FilmFile'); - - $TestModel =& new Basket(); - $recursive = 3; - $result = $TestModel->find('all', compact('conditions', 'recursive')); - - $expected = array( - array( - 'Basket' => array( - 'id' => 1, - 'type' => 'nonfile', - 'name' => 'basket1', - 'object_id' => 1, - 'user_id' => 1, - ), - 'FilmFile' => array( - 'id' => '', - 'name' => '', - ) - ), - array( - 'Basket' => array( - 'id' => 2, - 'type' => 'file', - 'name' => 'basket2', - 'object_id' => 2, - 'user_id' => 1, - ), - 'FilmFile' => array( - 'id' => 2, - 'name' => 'two', - ) - ), - ); - $this->assertEqual($result, $expected); - } - -/** - * testFindAllWithConditionsHavingMixedDataTypes method - * - * @access public - * @return void - */ - function testFindAllWithConditionsHavingMixedDataTypes() { - $this->loadFixtures('Article'); - $TestModel =& new Article(); - $expected = array( - array( - 'Article' => array( - 'id' => 1, - 'user_id' => 1, - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ) - ), - array( - 'Article' => array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ) - ) - ); - $conditions = array('id' => array('1', 2)); - $recursive = -1; - $order = 'Article.id ASC'; - $result = $TestModel->find('all', compact('conditions', 'recursive', 'order')); - $this->assertEqual($result, $expected); - - - $conditions = array('id' => array('1', 2, '3.0')); - $order = 'Article.id ASC'; - $result = $TestModel->find('all', compact('recursive', 'conditions', 'order')); - $expected = array( - array( - 'Article' => array( - 'id' => 1, - 'user_id' => 1, - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ) - ), - array( - 'Article' => array( - 'id' => 2, - 'user_id' => 3, - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ) - ), - array( - 'Article' => array( - 'id' => 3, - 'user_id' => 1, - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ) - ) - ); - $this->assertEqual($result, $expected); - } -/** - * Tests validation parameter order in custom validation methods - * - * @access public - * @return void - */ - function testValidationParams() { - $TestModel =& new ValidationTest1(); - $TestModel->validate['title'] = array( - 'rule' => 'customValidatorWithParams', - 'required' => true - ); - $TestModel->create(array('title' => 'foo')); - $TestModel->invalidFields(); - - $expected = array( - 'data' => array( - 'title' => 'foo' - ), - 'validator' => array( - 'rule' => 'customValidatorWithParams', - 'on' => null, - 'last' => false, - 'allowEmpty' => false, - 'required' => true - ), - 'or' => true, - 'ignore_on_same' => 'id' - ); - $this->assertEqual($TestModel->validatorParams, $expected); - - $TestModel->validate['title'] = array( - 'rule' => 'customValidatorWithMessage', - 'required' => true - ); - $expected = array( - 'title' => 'This field will *never* validate! Muhahaha!' - ); - - $this->assertEqual($TestModel->invalidFields(), $expected); - } -/** - * Tests validation parameter fieldList in invalidFields - * - * @access public - * @return void - */ - function testInvalidFieldsWithFieldListParams() { - $TestModel =& new ValidationTest1(); - $TestModel->validate = $validate = array( - 'title' => array( - 'rule' => 'customValidator', - 'required' => true - ), - 'name' => array( - 'rule' => 'allowEmpty', - 'required' => true - )); - $TestModel->invalidFields(array('fieldList' => array('title'))); - $expected = array( - 'title' => 'This field cannot be left blank' - ); - $this->assertEqual($TestModel->validationErrors, $expected); - $TestModel->validationErrors = array(); - - $TestModel->invalidFields(array('fieldList' => array('name'))); - $expected = array( - 'name' => 'This field cannot be left blank' - ); - $this->assertEqual($TestModel->validationErrors, $expected); - $TestModel->validationErrors = array(); - - $TestModel->invalidFields(array('fieldList' => array('name', 'title'))); - $expected = array( - 'name' => 'This field cannot be left blank', - 'title' => 'This field cannot be left blank' - ); - $this->assertEqual($TestModel->validationErrors, $expected); - $TestModel->validationErrors = array(); - - $TestModel->whitelist = array('name'); - $TestModel->invalidFields(); - $expected = array('name' => 'This field cannot be left blank'); - $this->assertEqual($TestModel->validationErrors, $expected); - $TestModel->validationErrors = array(); - - $this->assertEqual($TestModel->validate, $validate); - } -/** - * Tests validation parameter order in custom validation methods - * - * @access public - * @return void - */ - function testAllowSimulatedFields() { - $TestModel =& new ValidationTest1(); - - $TestModel->create(array( - 'title' => 'foo', - 'bar' => 'baz' - )); - $expected = array( - 'ValidationTest1' => array( - 'title' => 'foo', - 'bar' => 'baz' - )); - $this->assertEqual($TestModel->data, $expected); - } -/** - * Tests validation parameter order in custom validation methods - * - * @access public - * @return void - */ - function testInvalidAssociation() { - $TestModel =& new ValidationTest1(); - $this->assertNull($TestModel->getAssociated('Foo')); - } -/** - * testLoadModelSecondIteration method - * - * @access public - * @return void - */ - function testLoadModelSecondIteration() { - $model = new ModelA(); - $this->assertIsA($model,'ModelA'); - - $this->assertIsA($model->ModelB, 'ModelB'); - $this->assertIsA($model->ModelB->ModelD, 'ModelD'); - - $this->assertIsA($model->ModelC, 'ModelC'); - $this->assertIsA($model->ModelC->ModelD, 'ModelD'); + ob_start(); + $result = $Article->query($query, $param); + ob_end_clean(); } /** * testRecursiveUnbind method @@ -11454,6 +4867,4247 @@ class ModelTest extends CakeTestCase { } $this->assertEqual($afterFindData, $noAfterFindData); } +/** + * testFindAllThreaded method + * + * @access public + * @return void + */ + function testFindAllThreaded() { + $this->loadFixtures('Category'); + $TestModel =& new Category(); + + $result = $TestModel->find('threaded'); + $expected = array( + array( + 'Category' => array( + 'id' => '1', + 'parent_id' => '0', + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '2', + 'parent_id' => '1', + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array('Category' => array( + 'id' => '7', + 'parent_id' => '2', + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array()), + array('Category' => array( + 'id' => '8', + 'parent_id' => '2', + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array())) + ), + array( + 'Category' => array( + 'id' => '3', + 'parent_id' => '1', + 'name' => 'Category 1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ) + ) + ), + array( + 'Category' => array( + 'id' => '4', + 'parent_id' => '0', + 'name' => 'Category 2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ), + array( + 'Category' => array( + 'id' => '5', + 'parent_id' => '0', + 'name' => 'Category 3', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '6', + 'parent_id' => '5', + 'name' => 'Category 3.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ) + ) + ) + ); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('threaded', array( + 'conditions' => array('Category.name LIKE' => 'Category 1%') + )); + + $expected = array( + array( + 'Category' => array( + 'id' => '1', + 'parent_id' => '0', + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '2', + 'parent_id' => '1', + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array('Category' => array( + 'id' => '7', + 'parent_id' => '2', + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array()), + array('Category' => array( + 'id' => '8', + 'parent_id' => '2', + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array())) + ), + array( + 'Category' => array( + 'id' => '3', + 'parent_id' => '1', + 'name' => 'Category 1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ) + ) + ) + ); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('threaded', array( + 'fields' => 'id, parent_id, name' + )); + + $expected = array( + array( + 'Category' => array( + 'id' => '1', + 'parent_id' => '0', + 'name' => 'Category 1' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '2', + 'parent_id' => '1', + 'name' => 'Category 1.1' + ), + 'children' => array( + array('Category' => array( + 'id' => '7', + 'parent_id' => '2', + 'name' => 'Category 1.1.1'), + 'children' => array()), + array('Category' => array( + 'id' => '8', + 'parent_id' => '2', + 'name' => 'Category 1.1.2'), + 'children' => array())) + ), + array( + 'Category' => array( + 'id' => '3', + 'parent_id' => '1', + 'name' => 'Category 1.2' + ), + 'children' => array() + ) + ) + ), + array( + 'Category' => array( + 'id' => '4', + 'parent_id' => '0', + 'name' => 'Category 2' + ), + 'children' => array() + ), + array( + 'Category' => array( + 'id' => '5', + 'parent_id' => '0', + 'name' => 'Category 3' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '6', + 'parent_id' => '5', + 'name' => 'Category 3.1' + ), + 'children' => array() + ) + ) + ) + ); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('threaded', array('order' => 'id DESC')); + + $expected = array( + array( + 'Category' => array( + 'id' => 5, + 'parent_id' => 0, + 'name' => 'Category 3', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => 6, + 'parent_id' => 5, + 'name' => 'Category 3.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ) + ) + ), + array( + 'Category' => array( + 'id' => 4, + 'parent_id' => 0, + 'name' => 'Category 2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ), + array( + 'Category' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => 3, + 'parent_id' => 1, + 'name' => 'Category 1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ), + array( + 'Category' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array('Category' => array( + 'id' => '8', + 'parent_id' => '2', + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array()), + array('Category' => array( + 'id' => '7', + 'parent_id' => '2', + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array())) + ) + ) + ) + ); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('threaded', array( + 'conditions' => array('Category.name LIKE' => 'Category 3%') + )); + $expected = array( + array( + 'Category' => array( + 'id' => '5', + 'parent_id' => '0', + 'name' => 'Category 3', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '6', + 'parent_id' => '5', + 'name' => 'Category 3.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'children' => array() + ) + ) + ) + ); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('threaded', array( + 'conditions' => array('Category.name LIKE' => 'Category 1.1%') + )); + $expected = array( + array('Category' => + array( + 'id' => '2', + 'parent_id' => '1', + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array( + array('Category' => array( + 'id' => '7', + 'parent_id' => '2', + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array()), + array('Category' => array( + 'id' => '8', + 'parent_id' => '2', + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31'), + 'children' => array())))); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('threaded', array( + 'fields' => 'id, parent_id, name', + 'conditions' => array('Category.id !=' => 2) + )); + $expected = array( + array( + 'Category' => array( + 'id' => '1', + 'parent_id' => '0', + 'name' => 'Category 1' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '3', + 'parent_id' => '1', + 'name' => 'Category 1.2' + ), + 'children' => array() + ) + ) + ), + array( + 'Category' => array( + 'id' => '4', + 'parent_id' => '0', + 'name' => 'Category 2' + ), + 'children' => array() + ), + array( + 'Category' => array( + 'id' => '5', + 'parent_id' => '0', + 'name' => 'Category 3' + ), + 'children' => array( + array( + 'Category' => array( + 'id' => '6', + 'parent_id' => '5', + 'name' => 'Category 3.1' + ), + 'children' => array() + ) + ) + ) + ); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('all', array( + 'fields' => 'id, name, parent_id', + 'conditions' => array('Category.id !=' => 1) + )); + $expected = array ( + array ('Category' => array( + 'id' => '2', + 'name' => 'Category 1.1', + 'parent_id' => '1' + )), + array ('Category' => array( + 'id' => '3', + 'name' => 'Category 1.2', + 'parent_id' => '1' + )), + array ('Category' => array( + 'id' => '4', + 'name' => 'Category 2', + 'parent_id' => '0' + )), + array ('Category' => array( + 'id' => '5', + 'name' => 'Category 3', + 'parent_id' => '0' + )), + array ('Category' => array( + 'id' => '6', + 'name' => 'Category 3.1', + 'parent_id' => '5' + )), + array ('Category' => array( + 'id' => '7', + 'name' => 'Category 1.1.1', + 'parent_id' => '2' + )), + array ('Category' => array( + 'id' => '8', + 'name' => 'Category 1.1.2', + 'parent_id' => '2' + ))); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('threaded', array( + 'fields' => 'id, parent_id, name', + 'conditions' => array('Category.id !=' => 1) + )); + $expected = array( + array( + 'Category' => array( + 'id' => '2', + 'parent_id' => '1', + 'name' => 'Category 1.1' + ), + 'children' => array( + array('Category' => array( + 'id' => '7', + 'parent_id' => '2', + 'name' => 'Category 1.1.1'), + 'children' => array()), + array('Category' => array( + 'id' => '8', + 'parent_id' => '2', + 'name' => 'Category 1.1.2'), + 'children' => array())) + ), + array( + 'Category' => array( + 'id' => '3', + 'parent_id' => '1', + 'name' => 'Category 1.2' + ), + 'children' => array() + ) + ); + $this->assertEqual($result, $expected); + } +/** + * test find('neighbors') + * + * @return void + * @access public + */ + function testFindNeighbors() { + $this->loadFixtures('User', 'Article'); + $TestModel =& new Article(); + + $TestModel->id = 1; + $result = $TestModel->find('neighbors', array('fields' => array('id'))); + $expected = array( + 'prev' => null, + 'next' => array( + 'Article' => array('id' => 2) + )); + $this->assertEqual($result, $expected); + + $TestModel->id = 2; + $result = $TestModel->find('neighbors', array( + 'fields' => array('id') + )); + + $expected = array( + 'prev' => array( + 'Article' => array( + 'id' => 1 + )), + 'next' => array( + 'Article' => array( + 'id' => 3 + ))); + $this->assertEqual($result, $expected); + + $TestModel->id = 3; + $result = $TestModel->find('neighbors', array('fields' => array('id'))); + $expected = array( + 'prev' => array( + 'Article' => array( + 'id' => 2 + )), + 'next' => null + ); + $this->assertEqual($result, $expected); + + $TestModel->id = 1; + $result = $TestModel->find('neighbors', array('recursive' => -1)); + $expected = array( + 'prev' => null, + 'next' => array( + 'Article' => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ) + ) + ); + $this->assertEqual($result, $expected); + + $TestModel->id = 2; + $result = $TestModel->find('neighbors', array('recursive' => -1)); + $expected = array( + 'prev' => array( + 'Article' => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ) + ), + 'next' => array( + 'Article' => array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ) + ) + ); + $this->assertEqual($result, $expected); + + $TestModel->id = 3; + $result = $TestModel->find('neighbors', array('recursive' => -1)); + $expected = array( + 'prev' => array( + 'Article' => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ) + ), + 'next' => null + ); + $this->assertEqual($result, $expected); + + $TestModel->recursive = 0; + $TestModel->id = 1; + $one = $TestModel->read(); + $TestModel->id = 2; + $two = $TestModel->read(); + $TestModel->id = 3; + $three = $TestModel->read(); + + $TestModel->id = 1; + $result = $TestModel->find('neighbors'); + $expected = array('prev' => null, 'next' => $two); + $this->assertEqual($result, $expected); + + $TestModel->id = 2; + $result = $TestModel->find('neighbors'); + $expected = array('prev' => $one, 'next' => $three); + $this->assertEqual($result, $expected); + + $TestModel->id = 3; + $result = $TestModel->find('neighbors'); + $expected = array('prev' => $two, 'next' => null); + $this->assertEqual($result, $expected); + + $TestModel->recursive = 2; + $TestModel->id = 1; + $one = $TestModel->read(); + $TestModel->id = 2; + $two = $TestModel->read(); + $TestModel->id = 3; + $three = $TestModel->read(); + + $TestModel->id = 1; + $result = $TestModel->find('neighbors', array('recursive' => 2)); + $expected = array('prev' => null, 'next' => $two); + $this->assertEqual($result, $expected); + + $TestModel->id = 2; + $result = $TestModel->find('neighbors', array('recursive' => 2)); + $expected = array('prev' => $one, 'next' => $three); + $this->assertEqual($result, $expected); + + $TestModel->id = 3; + $result = $TestModel->find('neighbors', array('recursive' => 2)); + $expected = array('prev' => $two, 'next' => null); + $this->assertEqual($result, $expected); + } +/** + * test findNeighbours() method + * + * @return void + * @access public + */ + function testFindNeighboursLegacy() { + $this->loadFixtures('User', 'Article'); + $TestModel =& new Article(); + + $result = $TestModel->findNeighbours(null, 'Article.id', '2'); + $expected = array( + 'prev' => array( + 'Article' => array( + 'id' => 1 + )), + 'next' => array( + 'Article' => array( + 'id' => 3 + ))); + $this->assertEqual($result, $expected); + + $result = $TestModel->findNeighbours(null, 'Article.id', '3'); + $expected = array( + 'prev' => array( + 'Article' => array( + 'id' => 2 + )), + 'next' => array() + ); + $this->assertEqual($result, $expected); + + $result = $TestModel->findNeighbours( + array('User.id' => 1), + array('Article.id', 'Article.title'), + 2 + ); + $expected = array( + 'prev' => array( + 'Article' => array( + 'id' => 1, + 'title' => 'First Article' + )), + 'next' => array( + 'Article' => array( + 'id' => 3, + 'title' => 'Third Article' + ))); + $this->assertEqual($result, $expected); + } +/** + * testFindCombinedRelations method + * + * @access public + * @return void + */ + function testFindCombinedRelations() { + $this->loadFixtures('Apple', 'Sample'); + $TestModel =& new Apple(); + + $result = $TestModel->find('all'); + + $expected = array( + array( + 'Apple' => array( + 'id' => '1', + 'apple_id' => '2', + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '2', + 'apple_id' => '1', + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => null, + 'apple_id' => null, + 'name' => null + ), + 'Child' => array( + array( + 'id' => '2', + 'apple_id' => '1', + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => '2', + 'apple_id' => '1', + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '1', + 'apple_id' => '2', + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => '2', + 'apple_id' => '2', + 'name' => 'sample2' + ), + 'Child' => array( + array( + 'id' => '1', + 'apple_id' => '2', + 'color' => 'Red 1', + 'name' => 'Red Apple 1', + 'created' => '2006-11-22 10:38:58', + 'date' => '1951-01-04', + 'modified' => '2006-12-01 13:31:26', + 'mytime' => '22:57:17' + ), + array( + 'id' => '3', + 'apple_id' => '2', + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + array( + 'id' => '4', + 'apple_id' => '2', + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => '3', + 'apple_id' => '2', + 'color' => 'blue green', + 'name' => 'green blue', + 'created' => '2006-12-25 05:13:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:24', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '2', + 'apple_id' => '1', + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => '1', + 'apple_id' => '3', + 'name' => 'sample1' + ), + 'Child' => array() + ), + array( + 'Apple' => array( + 'id' => '4', + 'apple_id' => '2', + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '2', + 'apple_id' => '1', + 'color' => 'Bright Red 1', + 'name' => 'Bright Red Apple', + 'created' => '2006-11-22 10:43:13', + 'date' => '2014-01-01', + 'modified' => '2006-11-30 18:38:10', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => '3', + 'apple_id' => '4', + 'name' => 'sample3' + ), + 'Child' => array( + array( + 'id' => '6', + 'apple_id' => '4', + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => '5', + 'apple_id' => '5', + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '5', + 'apple_id' => '5', + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => '4', + 'apple_id' => '5', + 'name' => 'sample4' + ), + 'Child' => array( + array( + 'id' => '5', + 'apple_id' => '5', + 'color' => 'Green', + 'name' => 'Blue Green', + 'created' => '2006-12-25 05:24:06', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:16', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => '6', + 'apple_id' => '4', + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '4', + 'apple_id' => '2', + 'color' => 'Blue Green', + 'name' => 'Test Name', + 'created' => '2006-12-25 05:23:36', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:23:36', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => null, + 'apple_id' => null, + 'name' => null + ), + 'Child' => array( + array( + 'id' => '7', + 'apple_id' => '6', + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ))), + array( + 'Apple' => array( + 'id' => '7', + 'apple_id' => '6', + 'color' => 'Some wierd color', + 'name' => 'Some odd color', + 'created' => '2006-12-25 05:34:21', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:34:21', + 'mytime' => '22:57:17' + ), + 'Parent' => array( + 'id' => '6', + 'apple_id' => '4', + 'color' => 'My new appleOrange', + 'name' => 'My new apple', + 'created' => '2006-12-25 05:29:39', + 'date' => '2006-12-25', + 'modified' => '2006-12-25 05:29:39', + 'mytime' => '22:57:17' + ), + 'Sample' => array( + 'id' => null, + 'apple_id' => null, + 'name' => null + ), + 'Child' => array() + )); + $this->assertEqual($result, $expected); + } +/** + * testSaveEmpty method + * + * @access public + * @return void + */ + function testSaveEmpty() { + $this->loadFixtures('Thread'); + $TestModel =& new Thread(); + $data = array(); + $expected = $TestModel->save($data); + $this->assertFalse($expected); + } + // function testBasicValidation() { + // $TestModel =& new ValidationTest1(); + // $TestModel->testing = true; + // $TestModel->set(array('title' => '', 'published' => 1)); + // $this->assertEqual($TestModel->invalidFields(), array('title' => 'This field cannot be left blank')); + // + // $TestModel->create(); + // $TestModel->set(array('title' => 'Hello', 'published' => 0)); + // $this->assertEqual($TestModel->invalidFields(), array('published' => 'This field cannot be left blank')); + // + // $TestModel->create(); + // $TestModel->set(array('title' => 'Hello', 'published' => 1, 'body' => '')); + // $this->assertEqual($TestModel->invalidFields(), array('body' => 'This field cannot be left blank')); + // } + +/** + * testFindAllWithConditionInChildQuery + * + * @todo external conditions like this are going to need to be revisited at some point + * @access public + * @return void + */ + function testFindAllWithConditionInChildQuery() { + $this->loadFixtures('Basket', 'FilmFile'); + + $TestModel =& new Basket(); + $recursive = 3; + $result = $TestModel->find('all', compact('conditions', 'recursive')); + + $expected = array( + array( + 'Basket' => array( + 'id' => 1, + 'type' => 'nonfile', + 'name' => 'basket1', + 'object_id' => 1, + 'user_id' => 1, + ), + 'FilmFile' => array( + 'id' => '', + 'name' => '', + ) + ), + array( + 'Basket' => array( + 'id' => 2, + 'type' => 'file', + 'name' => 'basket2', + 'object_id' => 2, + 'user_id' => 1, + ), + 'FilmFile' => array( + 'id' => 2, + 'name' => 'two', + ) + ), + ); + $this->assertEqual($result, $expected); + } + +/** + * testFindAllWithConditionsHavingMixedDataTypes method + * + * @access public + * @return void + */ + function testFindAllWithConditionsHavingMixedDataTypes() { + $this->loadFixtures('Article'); + $TestModel =& new Article(); + $expected = array( + array( + 'Article' => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ) + ), + array( + 'Article' => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ) + ) + ); + $conditions = array('id' => array('1', 2)); + $recursive = -1; + $order = 'Article.id ASC'; + $result = $TestModel->find('all', compact('conditions', 'recursive', 'order')); + $this->assertEqual($result, $expected); + + + $conditions = array('id' => array('1', 2, '3.0')); + $order = 'Article.id ASC'; + $result = $TestModel->find('all', compact('recursive', 'conditions', 'order')); + $expected = array( + array( + 'Article' => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ) + ), + array( + 'Article' => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ) + ), + array( + 'Article' => array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ) + ) + ); + $this->assertEqual($result, $expected); + } +/** + * testBindUnbind method + * + * @access public + * @return void + */ + function testBindUnbind() { + $this->loadFixtures('User', 'Comment', 'FeatureSet'); + $TestModel =& new User(); + + $result = $TestModel->hasMany; + $expected = array(); + $this->assertEqual($result, $expected); + + $result = $TestModel->bindModel(array('hasMany' => array('Comment'))); + $this->assertTrue($result); + + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user' + )); + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Comment' => array( + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ), + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ))), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Comment' => array() + ), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett' + ), + 'Comment' => array( + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + )))); + + $this->assertEqual($result, $expected); + + $TestModel->resetAssociations(); + $result = $TestModel->hasMany; + $this->assertEqual($result, array()); + + $result = $TestModel->bindModel(array('hasMany' => array('Comment')), false); + $this->assertTrue($result); + + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user' + )); + + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Comment' => array( + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ), + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ))), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Comment' => array() + ), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett' + ), + 'Comment' => array( + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + )))); + + $this->assertEqual($result, $expected); + + $result = $TestModel->hasMany; + $expected = array( + 'Comment' => array( + 'className' => 'Comment', + 'foreignKey' => 'user_id', + 'conditions' => null, + 'fields' => null, + 'order' => null, + 'limit' => null, + 'offset' => null, + 'dependent' => null, + 'exclusive' => null, + 'finderQuery' => null, + 'counterQuery' => null + )); + $this->assertEqual($result, $expected); + + $result = $TestModel->unbindModel(array('hasMany' => array('Comment'))); + $this->assertTrue($result); + + $result = $TestModel->hasMany; + $expected = array(); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user' + )); + $expected = array( + array('User' => array('id' => '1', 'user' => 'mariano')), + array('User' => array('id' => '2', 'user' => 'nate')), + array('User' => array('id' => '3', 'user' => 'larry')), + array('User' => array('id' => '4', 'user' => 'garrett'))); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user' + )); + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Comment' => array( + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ), + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ))), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Comment' => array() + ), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett' + ), + 'Comment' => array( + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => + 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + )))); + $this->assertEqual($result, $expected); + + $result = $TestModel->unbindModel(array('hasMany' => array('Comment')), false); + $this->assertTrue($result); + + $result = $TestModel->find('all', array('fields' => 'User.id, User.user')); + $expected = array( + array('User' => array('id' => '1', 'user' => 'mariano')), + array('User' => array('id' => '2', 'user' => 'nate')), + array('User' => array('id' => '3', 'user' => 'larry')), + array('User' => array('id' => '4', 'user' => 'garrett'))); + $this->assertEqual($result, $expected); + + $result = $TestModel->hasMany; + $expected = array(); + $this->assertEqual($result, $expected); + + $result = $TestModel->bindModel(array('hasMany' => array( + 'Comment' => array('className' => 'Comment', 'conditions' => 'Comment.published = \'Y\'') + ))); + $this->assertTrue($result); + + $result = $TestModel->find('all', array('fields' => 'User.id, User.user')); + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Comment' => array( + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ))), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Comment' => array() + ), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett' + ), + 'Comment' => array( + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + )))); + + $this->assertEqual($result, $expected); + + $TestModel2 =& new DeviceType(); + + $expected = array( + 'className' => 'FeatureSet', + 'foreignKey' => 'feature_set_id', + 'conditions' => '', + 'fields' => '', + 'order' => '', + 'counterCache' => '' + ); + $this->assertEqual($TestModel2->belongsTo['FeatureSet'], $expected); + + $TestModel2->bind('FeatureSet', array( + 'conditions' => array('active' => true) + )); + $expected['conditions'] = array('active' => true); + $this->assertEqual($TestModel2->belongsTo['FeatureSet'], $expected); + + $TestModel2->bind('FeatureSet', array( + 'foreignKey' => false, + 'conditions' => array('Feature.name' => 'DeviceType.name') + )); + $expected['conditions'] = array('Feature.name' => 'DeviceType.name'); + $expected['foreignKey'] = false; + $this->assertEqual($TestModel2->belongsTo['FeatureSet'], $expected); + + $TestModel2->bind('NewFeatureSet', array( + 'type' => 'hasMany', + 'className' => 'FeatureSet', + 'conditions' => array('active' => true) + )); + $expected = array( + 'className' => 'FeatureSet', + 'conditions' => array('active' => true), + 'foreignKey' => 'device_type_id', + 'fields' => '', + 'order' => '', + 'limit' => '', + 'offset' => '', + 'dependent' => '', + 'exclusive' => '', + 'finderQuery' => '', + 'counterQuery' => '' + ); + $this->assertEqual($TestModel2->hasMany['NewFeatureSet'], $expected); + $this->assertTrue(is_object($TestModel2->NewFeatureSet)); + } +/** + * testBindMultipleTimes method + * + * @access public + * @return void + */ + function testBindMultipleTimes() { + $this->loadFixtures('User', 'Comment', 'Article'); + $TestModel =& new User(); + + $result = $TestModel->hasMany; + $expected = array(); + $this->assertEqual($result, $expected); + + $result = $TestModel->bindModel(array( + 'hasMany' => array( + 'Items' => array('className' => 'Comment') + ))); + $this->assertTrue($result); + + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user' + )); + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Items' => array( + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ), + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Items' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + ))), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Items' => array() + ), + array( + 'User' => array( + 'id' => '4', 'user' => 'garrett'), + 'Items' => array( + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + )))); + $this->assertEqual($result, $expected); + + $result = $TestModel->bindModel(array( + 'hasMany' => array( + 'Items' => array('className' => 'Article') + ))); + $this->assertTrue($result); + + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user' + )); + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Items' => array( + array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ))), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + ), + 'Items' => array() + ), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Items' => array( + array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ))), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett' + ), + 'Items' => array() + )); + $this->assertEqual($result, $expected); + } + +/** + * test that bindModel behaves with Custom primary Key associations + * + * @return void + **/ + function bindWithCustomPrimaryKey() { + $this->loadFixtures('Story', 'StoriesTag', 'Tag'); + $Model =& ClassRegistry::init('StoriesTag'); + $Model->bindModel(array( + 'belongsTo' => array( + 'Tag' => array( + 'className' => 'Tag', + 'foreignKey' => 'story' + )))); + + $result = $Model->find('all'); + $this->assertFalse(empty($result)); + } + +/** + * testAssociationAfterFind method + * + * @access public + * @return void + */ + function testAssociationAfterFind() { + $this->loadFixtures('Post', 'Author', 'Comment'); + $TestModel =& new Post(); + $result = $TestModel->find('all'); + $expected = array( + array( + 'Post' => array( + 'id' => '1', + 'author_id' => '1', + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'Author' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31', + 'test' => 'working' + )), + array( + 'Post' => array( + 'id' => '2', + 'author_id' => '3', + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'Author' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31', + 'test' => 'working' + )), + array( + 'Post' => array( + 'id' => '3', + 'author_id' => '1', + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ), + 'Author' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31', + 'test' => 'working' + ))); + $this->assertEqual($result, $expected); + unset($TestModel); + + $Author =& new Author(); + $Author->Post->bindModel(array( + 'hasMany' => array( + 'Comment' => array( + 'className' => 'ModifiedComment', + 'foreignKey' => 'article_id', + ) + ))); + $result = $Author->find('all', array( + 'conditions' => array('Author.id' => 1), + 'recursive' => 2 + )); + $expected = array( + 'id' => 1, + 'article_id' => 1, + 'user_id' => 2, + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31', + 'callback' => 'Fire' + ); + $this->assertEqual($result[0]['Post'][0]['Comment'][0], $expected); + } +/** + * Tests that callbacks can be properly disabled + * + * @access public + * @return void + */ + function testCallbackDisabling() { + $this->loadFixtures('Author'); + $TestModel = new ModifiedAuthor(); + + $result = Set::extract($TestModel->find('all'), '/Author/user'); + $expected = array('mariano (CakePHP)', 'nate (CakePHP)', 'larry (CakePHP)', 'garrett (CakePHP)'); + $this->assertEqual($result, $expected); + + $result = Set::extract($TestModel->find('all', array('callbacks' => 'after')), '/Author/user'); + $expected = array('mariano (CakePHP)', 'nate (CakePHP)', 'larry (CakePHP)', 'garrett (CakePHP)'); + $this->assertEqual($result, $expected); + + $result = Set::extract($TestModel->find('all', array('callbacks' => 'before')), '/Author/user'); + $expected = array('mariano', 'nate', 'larry', 'garrett'); + $this->assertEqual($result, $expected); + + $result = Set::extract($TestModel->find('all', array('callbacks' => false)), '/Author/user'); + $expected = array('mariano', 'nate', 'larry', 'garrett'); + $this->assertEqual($result, $expected); + } +/** + * testMultipleBelongsToWithSameClass method + * + * @access public + * @return void + */ + function testMultipleBelongsToWithSameClass() { + $this->loadFixtures( + 'DeviceType', + 'DeviceTypeCategory', + 'FeatureSet', + 'ExteriorTypeCategory', + 'Document', + 'Device', + 'DocumentDirectory' + ); + + $DeviceType =& new DeviceType(); + + $DeviceType->recursive = 2; + $result = $DeviceType->read(null, 1); + + $expected = array( + 'DeviceType' => array( + 'id' => 1, + 'device_type_category_id' => 1, + 'feature_set_id' => 1, + 'exterior_type_category_id' => 1, + 'image_id' => 1, + 'extra1_id' => 1, + 'extra2_id' => 1, + 'name' => 'DeviceType 1', + 'order' => 0 + ), + 'Image' => array( + 'id' => 1, + 'document_directory_id' => 1, + 'name' => 'Document 1', + 'DocumentDirectory' => array( + 'id' => 1, + 'name' => 'DocumentDirectory 1' + )), + 'Extra1' => array( + 'id' => 1, + 'document_directory_id' => 1, + 'name' => 'Document 1', + 'DocumentDirectory' => array( + 'id' => 1, + 'name' => 'DocumentDirectory 1' + )), + 'Extra2' => array( + 'id' => 1, + 'document_directory_id' => 1, + 'name' => 'Document 1', + 'DocumentDirectory' => array( + 'id' => 1, + 'name' => 'DocumentDirectory 1' + )), + 'DeviceTypeCategory' => array( + 'id' => 1, + 'name' => 'DeviceTypeCategory 1' + ), + 'FeatureSet' => array( + 'id' => 1, + 'name' => 'FeatureSet 1' + ), + 'ExteriorTypeCategory' => array( + 'id' => 1, + 'image_id' => 1, + 'name' => 'ExteriorTypeCategory 1', + 'Image' => array( + 'id' => 1, + 'device_type_id' => 1, + 'name' => 'Device 1', + 'typ' => 1 + )), + 'Device' => array( + array( + 'id' => 1, + 'device_type_id' => 1, + 'name' => 'Device 1', + 'typ' => 1 + ), + array( + 'id' => 2, + 'device_type_id' => 1, + 'name' => 'Device 2', + 'typ' => 1 + ), + array( + 'id' => 3, + 'device_type_id' => 1, + 'name' => 'Device 3', + 'typ' => 2 + ))); + + $this->assertEqual($result, $expected); + } +/** + * testHabtmRecursiveBelongsTo method + * + * @access public + * @return void + */ + function testHabtmRecursiveBelongsTo() { + $this->loadFixtures('Portfolio', 'Item', 'ItemsPortfolio', 'Syfile', 'Image'); + $Portfolio =& new Portfolio(); + + $result = $Portfolio->find(array('id' => 2), null, null, 3); + $expected = array( + 'Portfolio' => array( + 'id' => 2, + 'seller_id' => 1, + 'name' => 'Portfolio 2' + ), + 'Item' => array( + array( + 'id' => 2, + 'syfile_id' => 2, + 'published' => 0, + 'name' => 'Item 2', + 'ItemsPortfolio' => array( + 'id' => 2, + 'item_id' => 2, + 'portfolio_id' => 2 + ), + 'Syfile' => array( + 'id' => 2, + 'image_id' => 2, + 'name' => 'Syfile 2', + 'item_count' => null, + 'Image' => array( + 'id' => 2, + 'name' => 'Image 2' + ) + )), + array( + 'id' => 6, + 'syfile_id' => 6, + 'published' => 0, + 'name' => 'Item 6', + 'ItemsPortfolio' => array( + 'id' => 6, + 'item_id' => 6, + 'portfolio_id' => 2 + ), + 'Syfile' => array( + 'id' => 6, + 'image_id' => null, + 'name' => 'Syfile 6', + 'item_count' => null, + 'Image' => array() + )))); + + $this->assertEqual($result, $expected); + } +/** + * testHabtmFinderQuery method + * + * @access public + * @return void + */ + function testHabtmFinderQuery() { + $this->loadFixtures('Article', 'Tag', 'ArticlesTag'); + $Article =& new Article(); + + $sql = $this->db->buildStatement( + array( + 'fields' => $this->db->fields($Article->Tag, null, array( + 'Tag.id', 'Tag.tag', 'ArticlesTag.article_id', 'ArticlesTag.tag_id' + )), + 'table' => $this->db->fullTableName('tags'), + 'alias' => 'Tag', + 'limit' => null, + 'offset' => null, + 'group' => null, + 'joins' => array(array( + 'alias' => 'ArticlesTag', + 'table' => $this->db->fullTableName('articles_tags'), + 'conditions' => array( + array("ArticlesTag.article_id" => '{$__cakeID__$}'), + array("ArticlesTag.tag_id" => $this->db->identifier('Tag.id')) + ) + )), + 'conditions' => array(), + 'order' => null + ), + $Article + ); + + $Article->hasAndBelongsToMany['Tag']['finderQuery'] = $sql; + $result = $Article->find('first'); + $expected = array( + array( + 'id' => '1', + 'tag' => 'tag1' + ), + array( + 'id' => '2', + 'tag' => 'tag2' + )); + + $this->assertEqual($result['Tag'], $expected); + } +/** + * testHabtmLimitOptimization method + * + * @access public + * @return void + */ + function testHabtmLimitOptimization() { + $this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'ArticlesTag'); + $TestModel =& new Article(); + + $TestModel->hasAndBelongsToMany['Tag']['limit'] = 2; + $result = $TestModel->read(null, 2); + $expected = array( + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), + 'Comment' => array( + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + )), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))); + + $this->assertEqual($result, $expected); + + $TestModel->hasAndBelongsToMany['Tag']['limit'] = 1; + $result = $TestModel->read(null, 2); + unset($expected['Tag'][1]); + + $this->assertEqual($result, $expected); + } +/** + * testHasManyLimitOptimization method + * + * @access public + * @return void + */ + function testHasManyLimitOptimization() { + $this->loadFixtures('Project', 'Thread', 'Message', 'Bid'); + $Project =& new Project(); + $Project->recursive = 3; + + $result = $Project->find('all'); + $expected = array( + array( + 'Project' => array( + 'id' => 1, + 'name' => 'Project 1' + ), + 'Thread' => array( + array( + 'id' => 1, + 'project_id' => 1, + 'name' => 'Project 1, Thread 1', + 'Project' => array( + 'id' => 1, + 'name' => 'Project 1', + 'Thread' => array( + array( + 'id' => 1, + 'project_id' => 1, + 'name' => 'Project 1, Thread 1' + ), + array( + 'id' => 2, + 'project_id' => 1, + 'name' => 'Project 1, Thread 2' + ))), + 'Message' => array( + array( + 'id' => 1, + 'thread_id' => 1, + 'name' => 'Thread 1, Message 1', + 'Bid' => array( + 'id' => 1, + 'message_id' => 1, + 'name' => 'Bid 1.1' + )))), + array( + 'id' => 2, + 'project_id' => 1, + 'name' => 'Project 1, Thread 2', + 'Project' => array( + 'id' => 1, + 'name' => 'Project 1', + 'Thread' => array( + array( + 'id' => 1, + 'project_id' => 1, + 'name' => 'Project 1, Thread 1' + ), + array( + 'id' => 2, + 'project_id' => 1, + 'name' => 'Project 1, Thread 2' + ))), + 'Message' => array( + array( + 'id' => 2, + 'thread_id' => 2, + 'name' => 'Thread 2, Message 1', + 'Bid' => array( + 'id' => 4, + 'message_id' => 2, + 'name' => 'Bid 2.1' + )))))), + array( + 'Project' => array( + 'id' => 2, + 'name' => 'Project 2' + ), + 'Thread' => array( + array( + 'id' => 3, + 'project_id' => 2, + 'name' => 'Project 2, Thread 1', + 'Project' => array( + 'id' => 2, + 'name' => 'Project 2', + 'Thread' => array( + array( + 'id' => 3, + 'project_id' => 2, + 'name' => 'Project 2, Thread 1' + ))), + 'Message' => array( + array( + 'id' => 3, + 'thread_id' => 3, + 'name' => 'Thread 3, Message 1', + 'Bid' => array( + 'id' => 3, + 'message_id' => 3, + 'name' => 'Bid 3.1' + )))))), + array( + 'Project' => array( + 'id' => 3, + 'name' => 'Project 3' + ), + 'Thread' => array() + )); + + $this->assertEqual($result, $expected); + } +/** + * testFindAllRecursiveSelfJoin method + * + * @access public + * @return void + */ + function testFindAllRecursiveSelfJoin() { + $this->loadFixtures('Home', 'AnotherArticle', 'Advertisement'); + $TestModel =& new Home(); + $TestModel->recursive = 2; + + $result = $TestModel->find('all'); + $expected = array( + array( + 'Home' => array( + 'id' => '1', + 'another_article_id' => '1', + 'advertisement_id' => '1', + 'title' => 'First Home', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'AnotherArticle' => array( + 'id' => '1', + 'title' => 'First Article', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31', + 'Home' => array( + array( + 'id' => '1', + 'another_article_id' => '1', + 'advertisement_id' => '1', + 'title' => 'First Home', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ))), + 'Advertisement' => array( + 'id' => '1', + 'title' => 'First Ad', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31', + 'Home' => array( + array( + 'id' => '1', + 'another_article_id' => '1', + 'advertisement_id' => '1', + 'title' => 'First Home', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + array( + 'id' => '2', + 'another_article_id' => '3', + 'advertisement_id' => '1', + 'title' => 'Second Home', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + )))), + array( + 'Home' => array( + 'id' => '2', + 'another_article_id' => '3', + 'advertisement_id' => '1', + 'title' => 'Second Home', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'AnotherArticle' => array( + 'id' => '3', + 'title' => 'Third Article', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31', + 'Home' => array( + array( + 'id' => '2', + 'another_article_id' => '3', + 'advertisement_id' => '1', + 'title' => 'Second Home', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ))), + 'Advertisement' => array( + 'id' => '1', + 'title' => 'First Ad', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31', + 'Home' => array( + array( + 'id' => '1', + 'another_article_id' => '1', + 'advertisement_id' => '1', + 'title' => 'First Home', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + array( + 'id' => '2', + 'another_article_id' => '3', + 'advertisement_id' => '1', + 'title' => 'Second Home', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ))))); + + $this->assertEqual($result, $expected); + + + + } +/** + * testFindAllRecursiveWithHabtm method + * + * @return void + * @access public + */ + function testFindAllRecursiveWithHabtm() { + $this->loadFixtures( + 'MyCategoriesMyUsers', + 'MyCategoriesMyProducts', + 'MyCategory', + 'MyUser', + 'MyProduct' + ); + + $MyUser =& new MyUser(); + $MyUser->recursive = 2; + + $result = $MyUser->find('all'); + $expected = array( + array( + 'MyUser' => array('id' => '1', 'firstname' => 'userA'), + 'MyCategory' => array( + array( + 'id' => '1', + 'name' => 'A', + 'MyProduct' => array( + array( + 'id' => '1', + 'name' => 'book' + ))), + array( + 'id' => '3', + 'name' => 'C', + 'MyProduct' => array( + array( + 'id' => '2', + 'name' => 'computer' + ))))), + array( + 'MyUser' => array( + 'id' => '2', + 'firstname' => 'userB' + ), + 'MyCategory' => array( + array( + 'id' => '1', + 'name' => 'A', + 'MyProduct' => array( + array( + 'id' => '1', + 'name' => 'book' + ))), + array( + 'id' => '2', + 'name' => 'B', + 'MyProduct' => array( + array( + 'id' => '1', + 'name' => 'book' + ), + array( + 'id' => '2', + 'name' => 'computer' + )))))); + + $this->assertIdentical($result, $expected); + } +/** + * testReadFakeThread method + * + * @access public + * @return void + */ + function testReadFakeThread() { + $this->loadFixtures('CategoryThread'); + $TestModel =& new CategoryThread(); + + $fullDebug = $this->db->fullDebug; + $this->db->fullDebug = true; + $TestModel->recursive = 6; + $TestModel->id = 7; + $result = $TestModel->read(); + $expected = array( + 'CategoryThread' => array( + 'id' => 7, + 'parent_id' => 6, + 'name' => 'Category 2.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 6, + 'parent_id' => 5, + 'name' => 'Category 2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 5, + 'parent_id' => 4, + 'name' => 'Category 1.1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ))))))); + + $this->db->fullDebug = $fullDebug; + $this->assertEqual($result, $expected); + } +/** + * testFindFakeThread method + * + * @access public + * @return void + */ + function testFindFakeThread() { + $this->loadFixtures('CategoryThread'); + $TestModel =& new CategoryThread(); + + $fullDebug = $this->db->fullDebug; + $this->db->fullDebug = true; + $TestModel->recursive = 6; + $result = $TestModel->find(array('CategoryThread.id' => 7)); + + $expected = array( + 'CategoryThread' => array( + 'id' => 7, + 'parent_id' => 6, + 'name' => 'Category 2.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 6, + 'parent_id' => 5, + 'name' => 'Category 2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 5, + 'parent_id' => 4, + 'name' => 'Category 1.1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ))))))); + + $this->db->fullDebug = $fullDebug; + $this->assertEqual($result, $expected); + } +/** + * testFindAllFakeThread method + * + * @access public + * @return void + */ + function testFindAllFakeThread() { + $this->loadFixtures('CategoryThread'); + $TestModel =& new CategoryThread(); + + $fullDebug = $this->db->fullDebug; + $this->db->fullDebug = true; + $TestModel->recursive = 6; + $result = $TestModel->find('all', null, null, 'CategoryThread.id ASC'); + $expected = array( + array( + 'CategoryThread' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => null, + 'parent_id' => null, + 'name' => null, + 'created' => null, + 'updated' => null, + 'ParentCategory' => array() + )), + array( + 'CategoryThread' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array() + )), + array( + 'CategoryThread' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array() + ))), + array( + 'CategoryThread' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array() + )))), + array( + 'CategoryThread' => array( + 'id' => 5, + 'parent_id' => 4, + 'name' => 'Category 1.1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array() + ))))), + array( + 'CategoryThread' => array( + 'id' => 6, + 'parent_id' => 5, + 'name' => 'Category 2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 5, + 'parent_id' => 4, + 'name' => 'Category 1.1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array() + )))))), + array( + 'CategoryThread' => array( + 'id' => 7, + 'parent_id' => 6, + 'name' => 'Category 2.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ), + 'ParentCategory' => array( + 'id' => 6, + 'parent_id' => 5, + 'name' => 'Category 2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 5, + 'parent_id' => 4, + 'name' => 'Category 1.1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 4, + 'parent_id' => 3, + 'name' => 'Category 1.1.2', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 3, + 'parent_id' => 2, + 'name' => 'Category 1.1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 2, + 'parent_id' => 1, + 'name' => 'Category 1.1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31', + 'ParentCategory' => array( + 'id' => 1, + 'parent_id' => 0, + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + )))))))); + + $this->db->fullDebug = $fullDebug; + $this->assertEqual($result, $expected); + } +/** + * testConditionalNumerics method + * + * @access public + * @return void + */ + function testConditionalNumerics() { + $this->loadFixtures('NumericArticle'); + $NumericArticle =& new NumericArticle(); + $data = array('title' => '12345abcde'); + $result = $NumericArticle->find($data); + $this->assertTrue(!empty($result)); + + $data = array('title' => '12345'); + $result = $NumericArticle->find($data); + $this->assertTrue(empty($result)); + } + +/** + * test find('all') method + * + * @access public + * @return void + */ + function testFindAll() { + $this->loadFixtures('User'); + $TestModel =& new User(); + $TestModel->cacheQueries = false; + + $result = $TestModel->find('all'); + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + )), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + )), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + )), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:22:23', + 'updated' => '2007-03-17 01:24:31' + ))); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('all', array('conditions' => 'User.id > 2')); + $expected = array( + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + )), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:22:23', + 'updated' => '2007-03-17 01:24:31' + ))); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('all', array( + 'conditions' => array('User.id !=' => '0', 'User.user LIKE' => '%arr%') + )); + $expected = array( + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + )), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:22:23', + 'updated' => '2007-03-17 01:24:31' + ))); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('all', array('conditions' => array('User.id' => '0'))); + $expected = array(); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('all', array( + 'conditions' => array('or' => array('User.id' => '0', 'User.user LIKE' => '%a%') + ))); + + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + )), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + )), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + )), + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:22:23', + 'updated' => '2007-03-17 01:24:31' + ))); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('all', array('fields' => 'User.id, User.user')); + $expected = array( + array('User' => array('id' => '1', 'user' => 'mariano')), + array('User' => array('id' => '2', 'user' => 'nate')), + array('User' => array('id' => '3', 'user' => 'larry')), + array('User' => array('id' => '4', 'user' => 'garrett'))); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('all', array('fields' => 'User.user', 'order' => 'User.user ASC')); + $expected = array( + array('User' => array('user' => 'garrett')), + array('User' => array('user' => 'larry')), + array('User' => array('user' => 'mariano')), + array('User' => array('user' => 'nate'))); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('all', array('fields' => 'User.user', 'order' => 'User.user DESC')); + $expected = array( + array('User' => array('user' => 'nate')), + array('User' => array('user' => 'mariano')), + array('User' => array('user' => 'larry')), + array('User' => array('user' => 'garrett'))); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('all', array('limit' => 3, 'page' => 1)); + + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + )), + array( + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + )), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ))); + $this->assertEqual($result, $expected); + + $ids = array(4 => 1, 5 => 3); + $result = $TestModel->find('all', array( + 'conditions' => array('User.id' => $ids), + 'order' => 'User.id' + )); + $expected = array( + array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + )), + array( + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ))); + $this->assertEqual($result, $expected); + + // These tests are expected to fail on SQL Server since the LIMIT/OFFSET + // hack can't handle small record counts. + if ($this->db->config['driver'] != 'mssql') { + $result = $TestModel->find('all', array('limit' => 3, 'page' => 2)); + $expected = array( + array( + 'User' => array( + 'id' => '4', + 'user' => 'garrett', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:22:23', + 'updated' => '2007-03-17 01:24:31' + ))); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('all', array('limit' => 3, 'page' => 3)); + $expected = array(); + $this->assertEqual($result, $expected); + } + } +/** + * test find('list') method + * + * @access public + * @return void + */ + function testGenerateFindList() { + $this->loadFixtures('Article', 'Apple', 'Post', 'Author', 'User'); + + $TestModel =& new Article(); + $TestModel->displayField = 'title'; + + $result = $TestModel->find('list', array( + 'order' => 'Article.title ASC' + )); + + $expected = array( + 1 => 'First Article', + 2 => 'Second Article', + 3 => 'Third Article' + ); + $this->assertEqual($result, $expected); + + $db =& ConnectionManager::getDataSource('test_suite'); + if ($db->config['driver'] == 'mysql') { + $result = $TestModel->find('list', array( + 'order' => array('FIELD(Article.id, 3, 2) ASC', 'Article.title ASC') + )); + $expected = array( + 1 => 'First Article', + 3 => 'Third Article', + 2 => 'Second Article' + ); + $this->assertEqual($result, $expected); + } + + $result = Set::combine( + $TestModel->find('all', array( + 'order' => 'Article.title ASC', + 'fields' => array('id', 'title') + )), + '{n}.Article.id', '{n}.Article.title' + ); + $expected = array( + 1 => 'First Article', + 2 => 'Second Article', + 3 => 'Third Article' + ); + $this->assertEqual($result, $expected); + + $result = Set::combine( + $TestModel->find('all', array( + 'order' => 'Article.title ASC' + )), + '{n}.Article.id', '{n}.Article' + ); + $expected = array( + 1 => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 2 => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 3 => array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + )); + + $this->assertEqual($result, $expected); + + $result = Set::combine( + $TestModel->find('all', array( + 'order' => 'Article.title ASC' + )), + '{n}.Article.id', '{n}.Article', '{n}.Article.user_id' + ); + $expected = array( + 1 => array( + 1 => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 3 => array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + )), + 3 => array( + 2 => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ))); + + $this->assertEqual($result, $expected); + + $result = Set::combine( + $TestModel->find('all', array( + 'order' => 'Article.title ASC', + 'fields' => array('id', 'title', 'user_id') + )), + '{n}.Article.id', '{n}.Article.title', '{n}.Article.user_id' + ); + + $expected = array( + 1 => array( + 1 => 'First Article', + 3 => 'Third Article' + ), + 3 => array( + 2 => 'Second Article' + )); + $this->assertEqual($result, $expected); + + $TestModel =& new Apple(); + $expected = array( + 1 => 'Red Apple 1', + 2 => 'Bright Red Apple', + 3 => 'green blue', + 4 => 'Test Name', + 5 => 'Blue Green', + 6 => 'My new apple', + 7 => 'Some odd color' + ); + + $this->assertEqual($TestModel->find('list'), $expected); + $this->assertEqual($TestModel->Parent->find('list'), $expected); + + $TestModel =& new Post(); + $result = $TestModel->find('list', array( + 'fields' => 'Post.title' + )); + $expected = array( + 1 => 'First Post', + 2 => 'Second Post', + 3 => 'Third Post' + ); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('list', array( + 'fields' => 'title' + )); + $expected = array( + 1 => 'First Post', + 2 => 'Second Post', + 3 => 'Third Post' + ); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('list', array( + 'fields' => array('title', 'id') + )); + $expected = array( + 'First Post' => '1', + 'Second Post' => '2', + 'Third Post' => '3' + ); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('list', array( + 'fields' => array('title', 'id', 'created') + )); + $expected = array( + '2007-03-18 10:39:23' => array( + 'First Post' => '1' + ), + '2007-03-18 10:41:23' => array( + 'Second Post' => '2' + ), + '2007-03-18 10:43:23' => array( + 'Third Post' => '3' + ), + ); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('list', array( + 'fields' => array('Post.body') + )); + $expected = array( + 1 => 'First Post Body', + 2 => 'Second Post Body', + 3 => 'Third Post Body' + ); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('list', array( + 'fields' => array('Post.title', 'Post.body') + )); + $expected = array( + 'First Post' => 'First Post Body', + 'Second Post' => 'Second Post Body', + 'Third Post' => 'Third Post Body' + ); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('list', array( + 'fields' => array('Post.id', 'Post.title', 'Author.user'), + 'recursive' => 1 + )); + $expected = array( + 'mariano' => array( + 1 => 'First Post', + 3 => 'Third Post' + ), + 'larry' => array( + 2 => 'Second Post' + )); + $this->assertEqual($result, $expected); + + $TestModel =& new User(); + $result = $TestModel->find('list', array( + 'fields' => array('User.user', 'User.password') + )); + $expected = array( + 'mariano' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'nate' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'larry' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'garrett' => '5f4dcc3b5aa765d61d8327deb882cf99' + ); + $this->assertEqual($result, $expected); + + $TestModel =& new ModifiedAuthor(); + $result = $TestModel->find('list', array( + 'fields' => array('Author.id', 'Author.user') + )); + $expected = array( + 1 => 'mariano (CakePHP)', + 2 => 'nate (CakePHP)', + 3 => 'larry (CakePHP)', + 4 => 'garrett (CakePHP)' + ); + $this->assertEqual($result, $expected); + } +/** + * testFindField method + * + * @access public + * @return void + */ + function testFindField() { + $this->loadFixtures('User'); + $TestModel =& new User(); + + $TestModel->id = 1; + $result = $TestModel->field('user'); + $this->assertEqual($result, 'mariano'); + + $result = $TestModel->field('User.user'); + $this->assertEqual($result, 'mariano'); + + $TestModel->id = false; + $result = $TestModel->field('user', array( + 'user' => 'mariano' + )); + $this->assertEqual($result, 'mariano'); + + $result = $TestModel->field('COUNT(*) AS count', true); + $this->assertEqual($result, 4); + + $result = $TestModel->field('COUNT(*)', true); + $this->assertEqual($result, 4); + } +/** + * testFindUnique method + * + * @access public + * @return void + */ + function testFindUnique() { + $this->loadFixtures('User'); + $TestModel =& new User(); + + $this->assertFalse($TestModel->isUnique(array( + 'user' => 'nate' + ))); + $TestModel->id = 2; + $this->assertTrue($TestModel->isUnique(array( + 'user' => 'nate' + ))); + $this->assertFalse($TestModel->isUnique(array( + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' + ))); + } +/** + * test find('count') method + * + * @access public + * @return void + */ + function testFindCount() { + $this->loadFixtures('User', 'Project'); + + $TestModel =& new User(); + $result = $TestModel->find('count'); + $this->assertEqual($result, 4); + + $fullDebug = $this->db->fullDebug; + $this->db->fullDebug = true; + $TestModel->order = 'User.id'; + $this->db->_queriesLog = array(); + $result = $TestModel->find('count'); + $this->assertEqual($result, 4); + + $this->assertTrue(isset($this->db->_queriesLog[0]['query'])); + $this->assertNoPattern('/ORDER\s+BY/', $this->db->_queriesLog[0]['query']); + } + +/** + * test find with COUNT(DISTINCT field) + * + * @return void + **/ + function testFindCountDistinct() { + $skip = $this->skipIf( + $this->db->config['driver'] == 'sqlite', + 'SELECT COUNT(DISTINCT field) is not compatible with SQLite' + ); + if ($skip) { + return; + } + $this->loadFixtures('Project'); + $TestModel =& new Project(); + $TestModel->create(array('name' => 'project')) && $TestModel->save(); + $TestModel->create(array('name' => 'project')) && $TestModel->save(); + $TestModel->create(array('name' => 'project')) && $TestModel->save(); + + $result = $TestModel->find('count', array('fields' => 'DISTINCT name')); + $this->assertEqual($result, 4); + } +/** + * Test find(count) with Db::expression + * + * @access public + * @return void + */ + function testFindCountWithDbExpressions() { + if ($this->skipIf($this->db->config['driver'] == 'postgres', '%s testFindCountWithExpressions is not compatible with Postgres')) { + return; + } + $this->loadFixtures('Project'); + $db = ConnectionManager::getDataSource('test_suite'); + $TestModel =& new Project(); + + $result = $TestModel->find('count', array('conditions' => array( + $db->expression('Project.name = \'Project 3\'') + ))); + $this->assertEqual($result, 1); + + $result = $TestModel->find('count', array('conditions' => array( + 'Project.name' => $db->expression('\'Project 3\'') + ))); + $this->assertEqual($result, 1); + } +/** + * testFindMagic method + * + * @access public + * @return void + */ + function testFindMagic() { + $this->loadFixtures('User'); + $TestModel =& new User(); + + $result = $TestModel->findByUser('mariano'); + $expected = array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + )); + $this->assertEqual($result, $expected); + + $result = $TestModel->findByPassword('5f4dcc3b5aa765d61d8327deb882cf99'); + $expected = array('User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + )); + $this->assertEqual($result, $expected); + } +/** + * testRead method + * + * @access public + * @return void + */ + function testRead() { + $this->loadFixtures('User', 'Article'); + $TestModel =& new User(); + + $result = $TestModel->read(); + $this->assertFalse($result); + + $TestModel->id = 2; + $result = $TestModel->read(); + $expected = array( + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + )); + $this->assertEqual($result, $expected); + + $result = $TestModel->read(null, 2); + $expected = array( + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + )); + $this->assertEqual($result, $expected); + + $TestModel->id = 2; + $result = $TestModel->read(array('id', 'user')); + $expected = array('User' => array('id' => '2', 'user' => 'nate')); + $this->assertEqual($result, $expected); + + $result = $TestModel->read('id, user', 2); + $expected = array( + 'User' => array( + 'id' => '2', + 'user' => 'nate' + )); + $this->assertEqual($result, $expected); + + $result = $TestModel->bindModel(array('hasMany' => array('Article'))); + $this->assertTrue($result); + + $TestModel->id = 1; + $result = $TestModel->read('id, user'); + $expected = array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Article' => array( + array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + array( + 'id' => '3', + 'user_id' => '1', + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ))); + $this->assertEqual($result, $expected); + } +/** + * testRecursiveRead method + * + * @access public + * @return void + */ + function testRecursiveRead() { + $this->loadFixtures( + 'User', + 'Article', + 'Comment', + 'Tag', + 'ArticlesTag', + 'Featured', + 'ArticleFeatured' + ); + $TestModel =& new User(); + + $result = $TestModel->bindModel(array('hasMany' => array('Article')), false); + $this->assertTrue($result); + + $TestModel->recursive = 0; + $result = $TestModel->read('id, user', 1); + $expected = array( + 'User' => array('id' => '1', 'user' => 'mariano'), + ); + $this->assertEqual($result, $expected); + + $TestModel->recursive = 1; + $result = $TestModel->read('id, user', 1); + $expected = array( + 'User' => array( + 'id' => '1', + 'user' => 'mariano' + ), + 'Article' => array( + array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + array( + 'id' => '3', + 'user_id' => '1', + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ))); + $this->assertEqual($result, $expected); + + $TestModel->recursive = 2; + $result = $TestModel->read('id, user', 3); + $expected = array( + 'User' => array( + 'id' => '3', + 'user' => 'larry' + ), + 'Article' => array( + array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31', + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), + 'Comment' => array( + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31' + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31' + )), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))))); + $this->assertEqual($result, $expected); + } + + function testRecursiveFindAll() { + $this->db->truncate(new Featured()); + + $this->loadFixtures( + 'User', + 'Article', + 'Comment', + 'Tag', + 'ArticlesTag', + 'Attachment', + 'ArticleFeatured', + 'Featured', + 'Category' + ); + $TestModel =& new Article(); + + $result = $TestModel->find('all', array('conditions' => array('Article.user_id' => 1))); + $expected = array( + array( + 'Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + ), + array( + 'id' => '3', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Third Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:49:23', + 'updated' => '2007-03-18 10:51:31' + ), + array( + 'id' => '4', + 'article_id' => '1', + 'user_id' => '1', + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ) + ), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ))), + array( + 'Article' => array( + 'id' => '3', + 'user_id' => '1', + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Comment' => array(), + 'Tag' => array() + ) + ); + $this->assertEqual($result, $expected); + + $result = $TestModel->find('all', array( + 'conditions' => array('Article.user_id' => 3), + 'limit' => 1, + 'recursive' => 2 + )); + + $expected = array( + array( + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), + 'Comment' => array( + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31', + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Attachment' => array( + 'id' => '1', + 'comment_id' => 5, + 'attachment' => 'attachment.zip', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ) + ), + array( + 'id' => '6', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:55:23', + 'updated' => '2007-03-18 10:57:31', + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + ), + 'Attachment' => false + ) + ), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + )))); + + $this->assertEqual($result, $expected); + + $Featured = new Featured(); + + $Featured->recursive = 2; + $Featured->bindModel(array( + 'belongsTo' => array( + 'ArticleFeatured' => array( + 'conditions' => "ArticleFeatured.published = 'Y'", + 'fields' => 'id, title, user_id, published' + ) + ) + )); + + $Featured->ArticleFeatured->unbindModel(array( + 'hasMany' => array('Attachment', 'Comment'), + 'hasAndBelongsToMany' => array('Tag')) + ); + + $orderBy = 'ArticleFeatured.id ASC'; + $result = $Featured->find('all', array( + 'order' => $orderBy, 'limit' => 3 + )); + + $expected = array( + array( + 'Featured' => array( + 'id' => '1', + 'article_featured_id' => '1', + 'category_id' => '1', + 'published_date' => '2007-03-31 10:39:23', + 'end_date' => '2007-05-15 10:39:23', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'ArticleFeatured' => array( + 'id' => '1', + 'title' => 'First Article', + 'user_id' => '1', + 'published' => 'Y', + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Category' => array(), + 'Featured' => array( + 'id' => '1', + 'article_featured_id' => '1', + 'category_id' => '1', + 'published_date' => '2007-03-31 10:39:23', + 'end_date' => '2007-05-15 10:39:23', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + )), + 'Category' => array( + 'id' => '1', + 'parent_id' => '0', + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + )), + array( + 'Featured' => array( + 'id' => '2', + 'article_featured_id' => '2', + 'category_id' => '1', + 'published_date' => '2007-03-31 10:39:23', + 'end_date' => '2007-05-15 10:39:23', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'ArticleFeatured' => array( + 'id' => '2', + 'title' => 'Second Article', + 'user_id' => '3', + 'published' => 'Y', + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), + 'Category' => array(), + 'Featured' => array( + 'id' => '2', + 'article_featured_id' => '2', + 'category_id' => '1', + 'published_date' => '2007-03-31 10:39:23', + 'end_date' => '2007-05-15 10:39:23', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + )), + 'Category' => array( + 'id' => '1', + 'parent_id' => '0', + 'name' => 'Category 1', + 'created' => '2007-03-18 15:30:23', + 'updated' => '2007-03-18 15:32:31' + ))); + $this->assertEqual($result, $expected); + } +/** + * testRecursiveFindAllWithLimit method + * + * @access public + * @return void + */ + function testRecursiveFindAllWithLimit() { + $this->loadFixtures('Article', 'User', 'Tag', 'ArticlesTag', 'Comment', 'Attachment'); + $TestModel =& new Article(); + + $TestModel->hasMany['Comment']['limit'] = 2; + + $result = $TestModel->find('all', array( + 'conditions' => array('Article.user_id' => 1) + )); + $expected = array( + array( + 'Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Comment' => array( + array( + 'id' => '1', + 'article_id' => '1', + 'user_id' => '2', + 'comment' => 'First Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:45:23', + 'updated' => '2007-03-18 10:47:31' + ), + array( + 'id' => '2', + 'article_id' => '1', + 'user_id' => '4', + 'comment' => 'Second Comment for First Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:47:23', + 'updated' => '2007-03-18 10:49:31' + ), + ), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ))), + array( + 'Article' => array( + 'id' => '3', + 'user_id' => '1', + 'title' => 'Third Article', + 'body' => 'Third Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Comment' => array(), + 'Tag' => array() + ) + ); + $this->assertEqual($result, $expected); + + $TestModel->hasMany['Comment']['limit'] = 1; + + $result = $TestModel->find('all', array( + 'conditions' => array('Article.user_id' => 3), + 'limit' => 1, + 'recursive' => 2 + )); + $expected = array( + array( + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), + 'Comment' => array( + array( + 'id' => '5', + 'article_id' => '2', + 'user_id' => '1', + 'comment' => 'First Comment for Second Article', + 'published' => 'Y', + 'created' => '2007-03-18 10:53:23', + 'updated' => '2007-03-18 10:55:31', + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Attachment' => array( + 'id' => '1', + 'comment_id' => 5, + 'attachment' => 'attachment.zip', + 'created' => '2007-03-18 10:51:23', + 'updated' => '2007-03-18 10:53:31' + ) + ) + ), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ) + ) + ) + ); + $this->assertEqual($result, $expected); + } +} + +/** + * ModelSaveAllTest + * + * @package cake + * @subpackage cake.tests.cases.libs.model + */ +class ModelWriteTest extends BaseModelTest { +/** + * testInsertAnotherHabtmRecordWithSameForeignKey method + * + * @access public + * @return void + */ + function testInsertAnotherHabtmRecordWithSameForeignKey() { + $this->loadFixtures('JoinA', 'JoinB', 'JoinAB'); + $TestModel = new JoinA(); + + $result = $TestModel->JoinAsJoinB->findById(1); + $expected = array( + 'JoinAsJoinB' => array( + 'id' => 1, + 'join_a_id' => 1, + 'join_b_id' => 2, + 'other' => 'Data for Join A 1 Join B 2', + 'created' => '2008-01-03 10:56:33', + 'updated' => '2008-01-03 10:56:33' + )); + $this->assertEqual($result, $expected); + + $TestModel->JoinAsJoinB->create(); + $result = $TestModel->JoinAsJoinB->save(array( + 'join_a_id' => 1, + 'join_b_id' => 1, + 'other' => 'Data for Join A 1 Join B 1', + 'created' => '2008-01-03 10:56:44', + 'updated' => '2008-01-03 10:56:44' + )); + $this->assertTrue($result); + $lastInsertId = $TestModel->JoinAsJoinB->getLastInsertID(); + $this->assertTrue($lastInsertId != null); + + $result = $TestModel->JoinAsJoinB->findById(1); + $expected = array( + 'JoinAsJoinB' => array( + 'id' => 1, + 'join_a_id' => 1, + 'join_b_id' => 2, + 'other' => 'Data for Join A 1 Join B 2', + 'created' => '2008-01-03 10:56:33', + 'updated' => '2008-01-03 10:56:33' + )); + $this->assertEqual($result, $expected); + + $updatedValue = 'UPDATED Data for Join A 1 Join B 2'; + $TestModel->JoinAsJoinB->id = 1; + $result = $TestModel->JoinAsJoinB->saveField('other', $updatedValue, false); + $this->assertTrue($result); + + $result = $TestModel->JoinAsJoinB->findById(1); + $this->assertEqual($result['JoinAsJoinB']['other'], $updatedValue); + } +/** + * testSaveDateAsFirstEntry method + * + * @access public + * @return void + */ + function testSaveDateAsFirstEntry() { + $this->loadFixtures('Article'); + + $Article =& new Article(); + + $data = array( + 'Article' => array( + 'created' => array( + 'day' => '1', + 'month' => '1', + 'year' => '2008' + ), + 'title' => 'Test Title', + 'user_id' => 1 + )); + $Article->create(); + $this->assertTrue($Article->save($data)); + + $testResult = $Article->find(array('Article.title' => 'Test Title')); + + $this->assertEqual($testResult['Article']['title'], $data['Article']['title']); + $this->assertEqual($testResult['Article']['created'], '2008-01-01 00:00:00'); + + } +/** + * testUnderscoreFieldSave method + * + * @access public + * @return void + */ + function testUnderscoreFieldSave() { + $this->loadFixtures('UnderscoreField'); + $UnderscoreField =& new UnderscoreField(); + + $currentCount = $UnderscoreField->find('count'); + $this->assertEqual($currentCount, 3); + $data = array('UnderscoreField' => array( + 'user_id' => '1', + 'my_model_has_a_field' => 'Content here', + 'body' => 'Body', + 'published' => 'Y', + 'another_field' => 4 + )); + $ret = $UnderscoreField->save($data); + $this->assertTrue($ret); + + $currentCount = $UnderscoreField->find('count'); + $this->assertEqual($currentCount, 4); + } /** * testAutoSaveUuid method * @@ -11598,614 +9252,1192 @@ class ModelTest extends CakeTestCase { $this->assertEqual($result, $expected); } /** - * testDeconstructFields method + * Tests validation parameter order in custom validation methods * * @access public * @return void */ - function testDeconstructFields() { - $this->loadFixtures('Apple'); - $TestModel =& new Apple(); + function testAllowSimulatedFields() { + $TestModel =& new ValidationTest1(); - //test null/empty values first - $data['Apple']['created']['year'] = ''; - $data['Apple']['created']['month'] = ''; - $data['Apple']['created']['day'] = ''; - $data['Apple']['created']['hour'] = ''; - $data['Apple']['created']['min'] = ''; - $data['Apple']['created']['sec'] = ''; - - $TestModel->data = null; - $TestModel->set($data); - $expected = array('Apple'=> array('created'=> '')); - $this->assertEqual($TestModel->data, $expected); - - $data = array(); - $data['Apple']['date']['year'] = ''; - $data['Apple']['date']['month'] = ''; - $data['Apple']['date']['day'] = ''; - - $TestModel->data = null; - $TestModel->set($data); - $expected = array('Apple'=> array('date'=> '')); - $this->assertEqual($TestModel->data, $expected); - - $data = array(); - $data['Apple']['mytime']['hour'] = ''; - $data['Apple']['mytime']['min'] = ''; - $data['Apple']['mytime']['sec'] = ''; - - $TestModel->data = null; - $TestModel->set($data); - $expected = array('Apple'=> array('mytime'=> '')); - $this->assertEqual($TestModel->data, $expected); - - //test other data variations - $data = array(); - $data['Apple']['created']['year'] = '2007'; - $data['Apple']['created']['month'] = '08'; - $data['Apple']['created']['day'] = '20'; - $data['Apple']['created']['hour'] = ''; - $data['Apple']['created']['min'] = ''; - $data['Apple']['created']['sec'] = ''; - - $TestModel->data = null; - $TestModel->set($data); - $expected = array('Apple'=> array('created'=> '2007-08-20 00:00:00')); - $this->assertEqual($TestModel->data, $expected); - - $data = array(); - $data['Apple']['created']['year'] = '2007'; - $data['Apple']['created']['month'] = '08'; - $data['Apple']['created']['day'] = '20'; - $data['Apple']['created']['hour'] = '10'; - $data['Apple']['created']['min'] = '12'; - $data['Apple']['created']['sec'] = ''; - - $TestModel->data = null; - $TestModel->set($data); - $expected = array('Apple'=> array('created'=> '2007-08-20 10:12:00')); - $this->assertEqual($TestModel->data, $expected); - - $data = array(); - $data['Apple']['created']['year'] = '2007'; - $data['Apple']['created']['month'] = ''; - $data['Apple']['created']['day'] = '12'; - $data['Apple']['created']['hour'] = '20'; - $data['Apple']['created']['min'] = ''; - $data['Apple']['created']['sec'] = ''; - - $TestModel->data = null; - $TestModel->set($data); - $expected = array('Apple'=> array('created'=> '')); - $this->assertEqual($TestModel->data, $expected); - - $data = array(); - $data['Apple']['created']['hour'] = '20'; - $data['Apple']['created']['min'] = '33'; - - $TestModel->data = null; - $TestModel->set($data); - $expected = array('Apple'=> array('created'=> '')); - $this->assertEqual($TestModel->data, $expected); - - $data = array(); - $data['Apple']['created']['hour'] = '20'; - $data['Apple']['created']['min'] = '33'; - $data['Apple']['created']['sec'] = '33'; - - $TestModel->data = null; - $TestModel->set($data); - $expected = array('Apple'=> array('created'=> '')); - $this->assertEqual($TestModel->data, $expected); - - $data = array(); - $data['Apple']['created']['hour'] = '13'; - $data['Apple']['created']['min'] = '00'; - $data['Apple']['date']['year'] = '2006'; - $data['Apple']['date']['month'] = '12'; - $data['Apple']['date']['day'] = '25'; - - $TestModel->data = null; - $TestModel->set($data); + $TestModel->create(array( + 'title' => 'foo', + 'bar' => 'baz' + )); $expected = array( - 'Apple'=> array( - 'created'=> '', - 'date'=> '2006-12-25' + 'ValidationTest1' => array( + 'title' => 'foo', + 'bar' => 'baz' )); $this->assertEqual($TestModel->data, $expected); - - $data = array(); - $data['Apple']['created']['year'] = '2007'; - $data['Apple']['created']['month'] = '08'; - $data['Apple']['created']['day'] = '20'; - $data['Apple']['created']['hour'] = '10'; - $data['Apple']['created']['min'] = '12'; - $data['Apple']['created']['sec'] = '09'; - $data['Apple']['date']['year'] = '2006'; - $data['Apple']['date']['month'] = '12'; - $data['Apple']['date']['day'] = '25'; - - $TestModel->data = null; - $TestModel->set($data); - $expected = array( - 'Apple'=> array( - 'created'=> '2007-08-20 10:12:09', - 'date'=> '2006-12-25' - )); - $this->assertEqual($TestModel->data, $expected); - - $data = array(); - $data['Apple']['created']['year'] = '--'; - $data['Apple']['created']['month'] = '--'; - $data['Apple']['created']['day'] = '--'; - $data['Apple']['created']['hour'] = '--'; - $data['Apple']['created']['min'] = '--'; - $data['Apple']['created']['sec'] = '--'; - $data['Apple']['date']['year'] = '--'; - $data['Apple']['date']['month'] = '--'; - $data['Apple']['date']['day'] = '--'; - - $TestModel->data = null; - $TestModel->set($data); - $expected = array('Apple'=> array('created'=> '', 'date'=> '')); - $this->assertEqual($TestModel->data, $expected); - - $data = array(); - $data['Apple']['created']['year'] = '2007'; - $data['Apple']['created']['month'] = '--'; - $data['Apple']['created']['day'] = '20'; - $data['Apple']['created']['hour'] = '10'; - $data['Apple']['created']['min'] = '12'; - $data['Apple']['created']['sec'] = '09'; - $data['Apple']['date']['year'] = '2006'; - $data['Apple']['date']['month'] = '12'; - $data['Apple']['date']['day'] = '25'; - - $TestModel->data = null; - $TestModel->set($data); - $expected = array('Apple'=> array('created'=> '', 'date'=> '2006-12-25')); - $this->assertEqual($TestModel->data, $expected); - - $data = array(); - $data['Apple']['date']['year'] = '2006'; - $data['Apple']['date']['month'] = '12'; - $data['Apple']['date']['day'] = '25'; - - $TestModel->data = null; - $TestModel->set($data); - $expected = array('Apple'=> array('date'=> '2006-12-25')); - $this->assertEqual($TestModel->data, $expected); - - $data = array(); - $data['Apple']['mytime']['hour'] = '03'; - $data['Apple']['mytime']['min'] = '04'; - $data['Apple']['mytime']['sec'] = '04'; - - $TestModel->data = null; - $TestModel->set($data); - $expected = array('Apple'=> array('mytime'=> '03:04:04')); - $this->assertEqual($TestModel->data, $expected); - - $data = array(); - $data['Apple']['mytime']['hour'] = '3'; - $data['Apple']['mytime']['min'] = '4'; - $data['Apple']['mytime']['sec'] = '4'; - - $TestModel->data = null; - $TestModel->set($data); - $expected = array('Apple' => array('mytime'=> '03:04:04')); - $this->assertEqual($TestModel->data, $expected); - - $data = array(); - $data['Apple']['mytime']['hour'] = '03'; - $data['Apple']['mytime']['min'] = '4'; - $data['Apple']['mytime']['sec'] = '4'; - - $TestModel->data = null; - $TestModel->set($data); - $expected = array('Apple'=> array('mytime'=> '03:04:04')); - $this->assertEqual($TestModel->data, $expected); - - $db = ConnectionManager::getDataSource('test_suite'); - $data = array(); - $data['Apple']['modified'] = $db->expression('NOW()'); - $TestModel->data = null; - $TestModel->set($data); - $this->assertEqual($TestModel->data, $data); - - $data = array(); - $data['Apple']['mytime'] = $db->expression('NOW()'); - $TestModel->data = null; - $TestModel->set($data); - $this->assertEqual($TestModel->data, $data); } /** - * testTablePrefixSwitching method + * test that Caches are getting cleared on save(). + * ensure that both inflections of controller names are getting cleared + * as url for controller could be either overallFavorites/index or overall_favorites/index * - * @access public * @return void - */ - function testTablePrefixSwitching() { - ConnectionManager::create('database1', - array_merge($this->db->config, array('prefix' => 'aaa_') - )); - ConnectionManager::create('database2', - array_merge($this->db->config, array('prefix' => 'bbb_') - )); + **/ + function testCacheClearOnSave() { + $_back = array( + 'check' => Configure::read('Cache.check'), + 'disable' => Configure::read('Cache.disable'), + ); + Configure::write('Cache.check', true); + Configure::write('Cache.disable', false); - $db1 = ConnectionManager::getDataSource('database1'); - $db2 = ConnectionManager::getDataSource('database2'); + $this->loadFixtures('OverallFavorite'); + $OverallFavorite =& new OverallFavorite(); - $TestModel = new Apple(); - $TestModel->setDataSource('database1'); - $this->assertEqual($this->db->fullTableName($TestModel, false), 'aaa_apples'); - $this->assertEqual($db1->fullTableName($TestModel, false), 'aaa_apples'); - $this->assertEqual($db2->fullTableName($TestModel, false), 'aaa_apples'); + touch(CACHE . 'views' . DS . 'some_dir_overallfavorites_index.php'); + touch(CACHE . 'views' . DS . 'some_dir_overall_favorites_index.php'); - $TestModel->setDataSource('database2'); - $this->assertEqual($this->db->fullTableName($TestModel, false), 'bbb_apples'); - $this->assertEqual($db1->fullTableName($TestModel, false), 'bbb_apples'); - $this->assertEqual($db2->fullTableName($TestModel, false), 'bbb_apples'); + $data = array( + 'OverallFavorite' => array( + 'model_type' => '8-track', + 'model_id' => '3', + 'priority' => '1' + ) + ); + $OverallFavorite->create($data); + $OverallFavorite->save(); - $TestModel = new Apple(); - $TestModel->tablePrefix = 'custom_'; - $this->assertEqual($this->db->fullTableName($TestModel, false), 'custom_apples'); - $TestModel->setDataSource('database1'); - $this->assertEqual($this->db->fullTableName($TestModel, false), 'custom_apples'); - $this->assertEqual($db1->fullTableName($TestModel, false), 'custom_apples'); + $this->assertFalse(file_exists(CACHE . 'views' . DS . 'some_dir_overallfavorites_index.php')); + $this->assertFalse(file_exists(CACHE . 'views' . DS . 'some_dir_overall_favorites_index.php')); - $TestModel = new Apple(); - $TestModel->setDataSource('database1'); - $this->assertEqual($this->db->fullTableName($TestModel, false), 'aaa_apples'); - $TestModel->tablePrefix = ''; - $TestModel->setDataSource('database2'); - $this->assertEqual($db2->fullTableName($TestModel, false), 'apples'); - $this->assertEqual($db1->fullTableName($TestModel, false), 'apples'); - - $TestModel->tablePrefix = null; - $TestModel->setDataSource('database1'); - $this->assertEqual($db2->fullTableName($TestModel, false), 'aaa_apples'); - $this->assertEqual($db1->fullTableName($TestModel, false), 'aaa_apples'); - - $TestModel->tablePrefix = false; - $TestModel->setDataSource('database2'); - $this->assertEqual($db2->fullTableName($TestModel, false), 'apples'); - $this->assertEqual($db1->fullTableName($TestModel, false), 'apples'); + Configure::write('Cache.check', $_back['check']); + Configure::write('Cache.disable', $_back['disable']); } /** - * testDynamicBehaviorAttachment method + * testSaveWithCounterCache method * * @access public * @return void */ - function testDynamicBehaviorAttachment() { - $this->loadFixtures('Apple'); - $TestModel =& new Apple(); - $this->assertEqual($TestModel->Behaviors->attached(), array()); + function testSaveWithCounterCache() { + $this->loadFixtures('Syfile', 'Item'); + $TestModel =& new Syfile(); + $TestModel2 =& new Item(); - $TestModel->Behaviors->attach('Tree', array('left' => 'left_field', 'right' => 'right_field')); - $this->assertTrue(is_object($TestModel->Behaviors->Tree)); - $this->assertEqual($TestModel->Behaviors->attached(), array('Tree')); + $result = $TestModel->findById(1); + $this->assertIdentical($result['Syfile']['item_count'], null); - $expected = array( - 'parent' => 'parent_id', - 'left' => 'left_field', - 'right' => 'right_field', - 'scope' => '1 = 1', - 'type' => 'nested', - '__parentChange' => false, + $TestModel2->save(array( + 'name' => 'Item 7', + 'syfile_id' => 1, + 'published' => false + )); + + $result = $TestModel->findById(1); + $this->assertIdentical($result['Syfile']['item_count'], '2'); + + $TestModel2->delete(1); + $result = $TestModel->findById(1); + $this->assertIdentical($result['Syfile']['item_count'], '1'); + + $TestModel2->id = 2; + $TestModel2->saveField('syfile_id', 1); + + $result = $TestModel->findById(1); + $this->assertIdentical($result['Syfile']['item_count'], '2'); + + $result = $TestModel->findById(2); + $this->assertIdentical($result['Syfile']['item_count'], '0'); + } +/** + * Tests that counter caches are updated when records are added + * + * @access public + * @return void + */ + function testCounterCacheIncrease() { + $this->loadFixtures('CounterCacheUser', 'CounterCachePost'); + $User = new CounterCacheUser(); + $Post = new CounterCachePost(); + $data = array('Post' => array( + 'title' => 'New Post', + 'user_id' => 66 + )); + + $Post->save($data); + $user = $User->find('first', array( + 'conditions' => array('id' => 66), 'recursive' => -1 - ); + )); - $this->assertEqual($TestModel->Behaviors->Tree->settings['Apple'], $expected); - - $expected['enabled'] = false; - $TestModel->Behaviors->attach('Tree', array('enabled' => false)); - $this->assertEqual($TestModel->Behaviors->Tree->settings['Apple'], $expected); - $this->assertEqual($TestModel->Behaviors->attached(), array('Tree')); - - $TestModel->Behaviors->detach('Tree'); - $this->assertEqual($TestModel->Behaviors->attached(), array()); - $this->assertFalse(isset($TestModel->Behaviors->Tree)); + $result = $user[$User->alias]['post_count']; + $expected = 3; + $this->assertEqual($result, $expected); } /** - * Tests cross database joins. Requires $test and $test2 to both be set in DATABASE_CONFIG - * NOTE: When testing on MySQL, you must set 'persistent' => false on *both* database connections, - * or one connection will step on the other. + * Tests that counter caches are updated when records are deleted + * + * @access public + * @return void */ - function testCrossDatabaseJoins() { - $config = new DATABASE_CONFIG(); + function testCounterCacheDecrease() { + $this->loadFixtures('CounterCacheUser', 'CounterCachePost'); + $User = new CounterCacheUser(); + $Post = new CounterCachePost(); - $skip = $this->skipIf( - !isset($config->test) || !isset($config->test2), - '%s Primary and secondary test databases not configured, skipping cross-database ' - .'join tests.' - .' To run these tests, you must define $test and $test2 in your database configuration.' + $Post->del(2); + $user = $User->find('first', array( + 'conditions' => array('id' => 66), + 'recursive' => -1 + )); + + $result = $user[$User->alias]['post_count']; + $expected = 1; + $this->assertEqual($result, $expected); + } +/** + * Tests that counter caches are updated when foreign keys of counted records change + * + * @access public + * @return void + */ + function testCounterCacheUpdated() { + $this->loadFixtures('CounterCacheUser', 'CounterCachePost'); + $User = new CounterCacheUser(); + $Post = new CounterCachePost(); + + $data = $Post->find('first', array( + 'conditions' => array('id' => 1), + 'recursive' => -1 + )); + $data[$Post->alias]['user_id'] = 301; + $Post->save($data); + + $users = $User->find('all',array('order' => 'User.id')); + $this->assertEqual($users[0]['User']['post_count'], 1); + $this->assertEqual($users[1]['User']['post_count'], 2); + } +/** + * Test counter cache with models that use a non-standard (i.e. not using 'id') + * as their primary key. + * + * @access public + * @return void + */ + function testCounterCacheWithNonstandardPrimaryKey() { + $this->loadFixtures( + 'CounterCacheUserNonstandardPrimaryKey', + 'CounterCachePostNonstandardPrimaryKey' ); + $User = new CounterCacheUserNonstandardPrimaryKey(); + $Post = new CounterCachePostNonstandardPrimaryKey(); + + $data = $Post->find('first', array( + 'conditions' => array('pid' => 1), + 'recursive' => -1 + )); + $data[$Post->alias]['uid'] = 301; + $Post->save($data); + + $users = $User->find('all',array('order' => 'User.uid')); + $this->assertEqual($users[0]['User']['post_count'], 1); + $this->assertEqual($users[1]['User']['post_count'], 2); + } + +/** + * test Counter Cache With Self Joining table + * + * @return void + * @access public + */ + function testCounterCacheWithSelfJoin() { + $skip = $this->skipIf( + ($this->db->config['driver'] == 'sqlite'), + 'SQLite 2.x does not support ALTER TABLE ADD COLUMN' + ); if ($skip) { return; } - $this->loadFixtures('Article', 'Tag', 'ArticlesTag', 'User', 'Comment'); - $TestModel =& new Article(); + $this->loadFixtures('CategoryThread'); + $this->db->query('ALTER TABLE '. $this->db->fullTableName('category_threads') . " ADD COLUMN child_count INTEGER"); + $Category =& new CategoryThread(); + $result = $Category->updateAll(array('CategoryThread.name' => "'updated'"), array('CategoryThread.parent_id' => 5)); + $this->assertTrue($result); - $expected = array( - array( - 'Article' => array( - 'id' => '1', - 'user_id' => '1', - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ), - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Comment' => array( - array( - 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' - ), - array( - 'id' => '2', - 'article_id' => '1', - 'user_id' => '4', - 'comment' => 'Second Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:47:23', - 'updated' => '2007-03-18 10:49:31' - ), - array( - 'id' => '3', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Third Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:49:23', - 'updated' => '2007-03-18 10:51:31' - ), - array( - 'id' => '4', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Fourth Comment for First Article', - 'published' => 'N', - 'created' => '2007-03-18 10:51:23', - 'updated' => '2007-03-18 10:53:31' - )), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '2', - 'tag' => 'tag2', - 'created' => '2007-03-18 12:24:23', - 'updated' => '2007-03-18 12:26:31' - ))), - array( - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ), - 'User' => array( - 'id' => '3', - 'user' => 'larry', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:20:23', - 'updated' => '2007-03-17 01:22:31' - ), - 'Comment' => array( - array( - 'id' => '5', - 'article_id' => '2', - 'user_id' => '1', - 'comment' => 'First Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:53:23', - 'updated' => '2007-03-18 10:55:31' - ), - array( - 'id' => '6', - 'article_id' => '2', - 'user_id' => '2', - 'comment' => 'Second Comment for Second Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:55:23', - 'updated' => '2007-03-18 10:57:31' - )), - 'Tag' => array( - array( - 'id' => '1', - 'tag' => 'tag1', - 'created' => '2007-03-18 12:22:23', - 'updated' => '2007-03-18 12:24:31' - ), - array( - 'id' => '3', - 'tag' => 'tag3', - 'created' => '2007-03-18 12:26:23', - 'updated' => '2007-03-18 12:28:31' - ))), - array( - 'Article' => array( - 'id' => '3', - 'user_id' => '1', - 'title' => 'Third Article', - 'body' => 'Third Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:43:23', - 'updated' => '2007-03-18 10:45:31' - ), - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Comment' => array(), - 'Tag' => array() + $Category =& new CategoryThread(); + $Category->belongsTo['ParentCategory']['counterCache'] = 'child_count'; + $Category->updateCounterCache(array('parent_id' => 5)); + $result = Set::extract($Category->find('all', array('conditions' => array('CategoryThread.id' => 5))), '{n}.CategoryThread.child_count'); + $expected = array_fill(0, 1, 1); + $this->assertEqual($result, $expected); + } +/** + * testSaveWithCounterCacheScope method + * + * @access public + * @return void + */ + function testSaveWithCounterCacheScope() { + $this->loadFixtures('Syfile', 'Item'); + $TestModel =& new Syfile(); + $TestModel2 =& new Item(); + $TestModel2->belongsTo['Syfile']['counterCache'] = true; + $TestModel2->belongsTo['Syfile']['counterScope'] = array('published' => true); + + $result = $TestModel->findById(1); + $this->assertIdentical($result['Syfile']['item_count'], null); + + $TestModel2->save(array( + 'name' => 'Item 7', + 'syfile_id' => 1, + 'published'=> true )); - $this->assertEqual($TestModel->find('all'), $expected); - $db2 =& ConnectionManager::getDataSource('test2'); + $result = $TestModel->findById(1); + $this->assertIdentical($result['Syfile']['item_count'], '1'); - foreach (array('User', 'Comment') as $class) { - $this->_fixtures[$this->_fixtureClassMap[$class]]->create($db2); - $this->_fixtures[$this->_fixtureClassMap[$class]]->insert($db2); - $this->db->truncate(Inflector::pluralize(Inflector::underscore($class))); - } + $TestModel2->id = 1; + $TestModel2->saveField('published', true); + $result = $TestModel->findById(1); + $this->assertIdentical($result['Syfile']['item_count'], '2'); - $this->assertEqual($TestModel->User->find('all'), array()); - $this->assertEqual($TestModel->Comment->find('all'), array()); - $this->assertEqual($TestModel->find('count'), 3); + $TestModel2->save(array( + 'id' => 1, + 'syfile_id' => 1, + 'published'=> false + )); - $TestModel->User->setDataSource('test2'); - $TestModel->Comment->setDataSource('test2'); + $result = $TestModel->findById(1); + $this->assertIdentical($result['Syfile']['item_count'], '1'); + } +/** + * testValidatesBackwards method + * + * @access public + * @return void + */ + function testValidatesBackwards() { + $TestModel =& new TestValidate(); - foreach ($expected as $key => $value) { - unset($value['Comment'], $value['Tag']); - $expected[$key] = $value; - } + $TestModel->validate = array( + 'user_id' => VALID_NUMBER, + 'title' => VALID_NOT_EMPTY, + 'body' => VALID_NOT_EMPTY + ); - $TestModel->recursive = 0; - $result = $TestModel->find('all'); + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => '', + 'body' => '' + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertFalse($result); + + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 'title', + 'body' => '' + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertFalse($result); + + $data = array('TestValidate' => array( + 'user_id' => '', + 'title' => 'title', + 'body' => 'body' + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertFalse($result); + + $data = array('TestValidate' => array( + 'user_id' => 'not a number', + 'title' => 'title', + 'body' => 'body' + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertFalse($result); + + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 'title', + 'body' => 'body' + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertTrue($result); + } +/** + * testValidates method + * + * @access public + * @return void + */ + function testValidates() { + $TestModel =& new TestValidate(); + + $TestModel->validate = array( + 'user_id' => 'numeric', + 'title' => array('allowEmpty' => false, 'rule' => 'notEmpty'), + 'body' => 'notEmpty' + ); + + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => '', + 'body' => 'body' + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertFalse($result); + + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 'title', + 'body' => 'body' + )); + $result = $TestModel->create($data) && $TestModel->validates(); + $this->assertTrue($result); + + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => '0', + 'body' => 'body' + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertTrue($result); + + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 0, + 'body' => 'body' + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertTrue($result); + + $TestModel->validate['modified'] = array('allowEmpty' => true, 'rule' => 'date'); + + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 0, + 'body' => 'body', + 'modified' => '' + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertTrue($result); + + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 0, + 'body' => 'body', + 'modified' => '2007-05-01' + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertTrue($result); + + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 0, + 'body' => 'body', + 'modified' => 'invalid-date-here' + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertFalse($result); + + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 0, + 'body' => 'body', + 'modified' => 0 + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertFalse($result); + + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 0, + 'body' => 'body', + 'modified' => '0' + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertFalse($result); + + $TestModel->validate['modified'] = array('allowEmpty' => false, 'rule' => 'date'); + + $data = array('TestValidate' => array('modified' => null)); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertFalse($result); + + $data = array('TestValidate' => array('modified' => false)); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertFalse($result); + + $data = array('TestValidate' => array('modified' => '')); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertFalse($result); + + $data = array('TestValidate' => array( + 'modified' => '2007-05-01' + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertTrue($result); + + $TestModel->validate['slug'] = array('allowEmpty' => false, 'rule' => array('maxLength', 45)); + + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 0, + 'body' => 'body', + 'slug' => '' + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertFalse($result); + + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 0, + 'body' => 'body', + 'slug' => 'slug-right-here' + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertTrue($result); + + $data = array('TestValidate' => array( + 'user_id' => '1', + 'title' => 0, + 'body' => 'body', + 'slug' => 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz' + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertFalse($result); + + $TestModel->validate = array( + 'number' => array( + 'rule' => 'validateNumber', + 'min' => 3, + 'max' => 5 + ), + 'title' => array( + 'allowEmpty' => false, + 'rule' => 'notEmpty' + )); + + $data = array('TestValidate' => array( + 'title' => 'title', + 'number' => '0' + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertFalse($result); + + $data = array('TestValidate' => array( + 'title' => 'title', + 'number' => 0 + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertFalse($result); + + $data = array('TestValidate' => array( + 'title' => 'title', + 'number' => '3' + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertTrue($result); + + $data = array('TestValidate' => array( + 'title' => 'title', + 'number' => 3 + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertTrue($result); + + $TestModel->validate = array( + 'number' => array( + 'rule' => 'validateNumber', + 'min' => 5, + 'max' => 10 + ), + 'title' => array( + 'allowEmpty' => false, + 'rule' => 'notEmpty' + )); + + $data = array('TestValidate' => array( + 'title' => 'title', + 'number' => '3' + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertFalse($result); + + $data = array('TestValidate' => array( + 'title' => 'title', + 'number' => 3 + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertFalse($result); + + $TestModel->validate = array( + 'title' => array( + 'allowEmpty' => false, + 'rule' => 'validateTitle' + )); + + $data = array('TestValidate' => array('title' => '')); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertFalse($result); + + $data = array('TestValidate' => array('title' => 'new title')); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertFalse($result); + + $data = array('TestValidate' => array('title' => 'title-new')); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertTrue($result); + + $TestModel->validate = array('title' => array( + 'allowEmpty' => true, + 'rule' => 'validateTitle' + )); + $data = array('TestValidate' => array('title' => '')); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertTrue($result); + + $TestModel->validate = array( + 'title' => array( + 'length' => array( + 'allowEmpty' => true, + 'rule' => array('maxLength', 10) + ))); + $data = array('TestValidate' => array('title' => '')); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertTrue($result); + + $TestModel->validate = array( + 'title' => array( + 'rule' => array('userDefined', 'Article', 'titleDuplicate') + )); + $data = array('TestValidate' => array('title' => 'My Article Title')); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertFalse($result); + + $data = array('TestValidate' => array( + 'title' => 'My Article With a Different Title' + )); + $result = $TestModel->create($data); + $this->assertTrue($result); + $result = $TestModel->validates(); + $this->assertTrue($result); + + $TestModel->validate = array( + 'title' => array( + 'tooShort' => array('rule' => array('minLength', 50)), + 'onlyLetters' => array('rule' => '/^[a-z]+$/i') + ), + ); + $data = array('TestValidate' => array( + 'title' => 'I am a short string' + )); + $TestModel->create($data); + $result = $TestModel->validates(); + $this->assertFalse($result); + $result = $TestModel->validationErrors; + $expected = array( + 'title' => 'onlyLetters' + ); $this->assertEqual($result, $expected); - $result = Set::extract($TestModel->User->find('all'), '{n}.User.id'); - $this->assertEqual($result, array('1', '2', '3', '4')); - $this->assertEqual($TestModel->find('all'), $expected); - - $TestModel->Comment->unbindModel(array('hasOne' => array('Attachment'))); + $TestModel->validate = array( + 'title' => array( + 'tooShort' => array( + 'rule' => array('minLength', 50), + 'last' => true + ), + 'onlyLetters' => array('rule' => '/^[a-z]+$/i') + ), + ); + $data = array('TestValidate' => array( + 'title' => 'I am a short string' + )); + $TestModel->create($data); + $result = $TestModel->validates(); + $this->assertFalse($result); + $result = $TestModel->validationErrors; $expected = array( - array( - 'Comment' => array( + 'title' => 'tooShort' + ); + $this->assertEqual($result, $expected); + } +/** + * testSaveField method + * + * @access public + * @return void + */ + function testSaveField() { + $this->loadFixtures('Article'); + $TestModel =& new Article(); + + $TestModel->id = 1; + $result = $TestModel->saveField('title', 'New First Article'); + $this->assertTrue($result); + + $TestModel->recursive = -1; + $result = $TestModel->read(array('id', 'user_id', 'title', 'body'), 1); + $expected = array('Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'New First Article', + 'body' => 'First Article Body' + )); + $this->assertEqual($result, $expected); + + $TestModel->id = 1; + $result = $TestModel->saveField('title', ''); + $this->assertTrue($result); + + $TestModel->recursive = -1; + $result = $TestModel->read(array('id', 'user_id', 'title', 'body'), 1); + $expected = array('Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => '', + 'body' => 'First Article Body' + )); + $result['Article']['title'] = trim($result['Article']['title']); + $this->assertEqual($result, $expected); + + $TestModel->id = 1; + $TestModel->set('body', 'Messed up data'); + $this->assertTrue($TestModel->saveField('title', 'First Article')); + $result = $TestModel->read(array('id', 'user_id', 'title', 'body'), 1); + $expected = array('Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body' + )); + $this->assertEqual($result, $expected); + + $TestModel->recursive = -1; + $result = $TestModel->read(array('id', 'user_id', 'title', 'body'), 1); + + $TestModel->id = 1; + $result = $TestModel->saveField('title', '', true); + $this->assertFalse($result); + + $this->loadFixtures('Node', 'Dependency'); + $Node =& new Node(); + $Node->set('id', 1); + $result = $Node->read(); + $this->assertEqual(Set::extract('/ParentNode/name', $result), array('Second')); + + $Node->saveField('state', 10); + $result = $Node->read(); + $this->assertEqual(Set::extract('/ParentNode/name', $result), array('Second')); + } +/** + * testSaveWithCreate method + * + * @access public + * @return void + */ + function testSaveWithCreate() { + $this->loadFixtures( + 'User', + 'Article', + 'User', + 'Comment', + 'Tag', + 'ArticlesTag', + 'Attachment' + ); + $TestModel =& new User(); + + $data = array('User' => array( + 'user' => 'user', + 'password' => '' + )); + $result = $TestModel->save($data); + $this->assertFalse($result); + $this->assertTrue(!empty($TestModel->validationErrors)); + + $TestModel =& new Article(); + + $data = array('Article' => array( + 'user_id' => '', + 'title' => '', + 'body' => '' + )); + $result = $TestModel->create($data) && $TestModel->save(); + $this->assertFalse($result); + $this->assertTrue(!empty($TestModel->validationErrors)); + + $data = array('Article' => array( + 'id' => 1, + 'user_id' => '1', + 'title' => 'New First Article', + 'body' => '' + )); + $result = $TestModel->create($data) && $TestModel->save(); + $this->assertFalse($result); + + $data = array('Article' => array( + 'id' => 1, + 'title' => 'New First Article' + )); + $result = $TestModel->create() && $TestModel->save($data, false); + $this->assertTrue($result); + + $TestModel->recursive = -1; + $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 1); + $expected = array('Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'New First Article', + 'body' => 'First Article Body', + 'published' => 'N' + )); + $this->assertEqual($result, $expected); + + $data = array('Article' => array( + 'id' => 1, + 'user_id' => '2', + 'title' => 'First Article', + 'body' => 'New First Article Body', + 'published' => 'Y' + )); + $result = $TestModel->create() && $TestModel->save($data, true, array('id', 'title', 'published')); + $this->assertTrue($result); + + $TestModel->recursive = -1; + $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 1); + $expected = array('Article' => array( + 'id' => '1', + 'user_id' => '1', + 'title' => 'First Article', + 'body' => 'First Article Body', + 'published' => 'Y' + )); + $this->assertEqual($result, $expected); + + $data = array( + 'Article' => array( + 'user_id' => '2', + 'title' => 'New Article', + 'body' => 'New Article Body', + 'created' => '2007-03-18 14:55:23', + 'updated' => '2007-03-18 14:57:31' + ), + 'Tag' => array('Tag' => array(1, 3)) + ); + $TestModel->create(); + $result = $TestModel->create() && $TestModel->save($data); + $this->assertTrue($result); + + $TestModel->recursive = 2; + $result = $TestModel->read(null, 4); + $expected = array( + 'Article' => array( + 'id' => '4', + 'user_id' => '2', + 'title' => 'New Article', + 'body' => 'New Article Body', + 'published' => 'N', + 'created' => '2007-03-18 14:55:23', + 'updated' => '2007-03-18 14:57:31' + ), + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + ), + 'Comment' => array(), + 'Tag' => array( + array( 'id' => '1', - 'article_id' => '1', - 'user_id' => '2', - 'comment' => 'First Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:45:23', - 'updated' => '2007-03-18 10:47:31' + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' ), - 'User' => array( - 'id' => '2', - 'user' => 'nate', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:18:23', - 'updated' => '2007-03-17 01:20:31' - ), - 'Article' => array( - 'id' => '1', - 'user_id' => '1', - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - )), - array( - 'Comment' => array( - 'id' => '2', - 'article_id' => '1', - 'user_id' => '4', - 'comment' => 'Second Comment for First Article', - 'published' => 'Y', - 'created' => '2007-03-18 10:47:23', - 'updated' => '2007-03-18 10:49:31' - ), - 'User' => array( - 'id' => '4', - 'user' => 'garrett', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:22:23', - 'updated' => '2007-03-17 01:24:31' - ), - 'Article' => array( - 'id' => '1', - 'user_id' => '1', - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - )), - array( - 'Comment' => array( + array( 'id' => '3', - 'article_id' => '1', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))); + $this->assertEqual($result, $expected); + + $data = array('Comment' => array( + 'article_id' => '4', + 'user_id' => '1', + 'comment' => 'Comment New Article', + 'published' => 'Y', + 'created' => '2007-03-18 14:57:23', + 'updated' => '2007-03-18 14:59:31' + )); + $result = $TestModel->Comment->create() && $TestModel->Comment->save($data); + $this->assertTrue($result); + + $data = array('Attachment' => array( + 'comment_id' => '7', + 'attachment' => 'newattachment.zip', + 'created' => '2007-03-18 15:02:23', + 'updated' => '2007-03-18 15:04:31' + )); + $result = $TestModel->Comment->Attachment->save($data); + $this->assertTrue($result); + + $TestModel->recursive = 2; + $result = $TestModel->read(null, 4); + $expected = array( + 'Article' => array( + 'id' => '4', + 'user_id' => '2', + 'title' => 'New Article', + 'body' => 'New Article Body', + 'published' => 'N', + 'created' => '2007-03-18 14:55:23', + 'updated' => '2007-03-18 14:57:31' + ), + 'User' => array( + 'id' => '2', + 'user' => 'nate', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:18:23', + 'updated' => '2007-03-17 01:20:31' + ), + 'Comment' => array( + array( + 'id' => '7', + 'article_id' => '4', 'user_id' => '1', - 'comment' => 'Third Comment for First Article', + 'comment' => 'Comment New Article', 'published' => 'Y', - 'created' => '2007-03-18 10:49:23', - 'updated' => '2007-03-18 10:51:31' - ), - 'User' => array( + 'created' => '2007-03-18 14:57:23', + 'updated' => '2007-03-18 14:59:31', + 'Article' => array( + 'id' => '4', + 'user_id' => '2', + 'title' => 'New Article', + 'body' => 'New Article Body', + 'published' => 'N', + 'created' => '2007-03-18 14:55:23', + 'updated' => '2007-03-18 14:57:31' + ), + 'User' => array( + 'id' => '1', + 'user' => 'mariano', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ), + 'Attachment' => array( + 'id' => '2', + 'comment_id' => '7', + 'attachment' => 'newattachment.zip', + 'created' => '2007-03-18 15:02:23', + 'updated' => '2007-03-18 15:04:31' + ))), + 'Tag' => array( + array( 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' ), - 'Article' => array( - 'id' => '1', - 'user_id' => '1', - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - )), - array( - 'Comment' => array( - 'id' => '4', - 'article_id' => '1', - 'user_id' => '1', - 'comment' => 'Fourth Comment for First Article', - 'published' => 'N', - 'created' => '2007-03-18 10:51:23', - 'updated' => '2007-03-18 10:53:31' - ), - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Article' => array( - 'id' => '1', - 'user_id' => '1', - 'title' => 'First Article', - 'body' => 'First Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - )), - array( - 'Comment' => array( + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))); + + $this->assertEqual($result, $expected); + } +/** + * testSaveWithSet method + * + * @access public + * @return void + */ + function testSaveWithSet() { + $this->loadFixtures('Article'); + $TestModel =& new Article(); + + // Create record we will be updating later + + $data = array('Article' => array( + 'user_id' => '1', + 'title' => 'Fourth Article', + 'body' => 'Fourth Article Body', + 'published' => 'Y' + )); + $result = $TestModel->create() && $TestModel->save($data); + $this->assertTrue($result); + + // Check record we created + + $TestModel->recursive = -1; + $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 4); + $expected = array('Article' => array( + 'id' => '4', + 'user_id' => '1', + 'title' => 'Fourth Article', + 'body' => 'Fourth Article Body', + 'published' => 'Y' + )); + $this->assertEqual($result, $expected); + + // Create new record just to overlap Model->id on previously created record + + $data = array('Article' => array( + 'user_id' => '4', + 'title' => 'Fifth Article', + 'body' => 'Fifth Article Body', + 'published' => 'Y' + )); + $result = $TestModel->create() && $TestModel->save($data); + $this->assertTrue($result); + + $TestModel->recursive = -1; + $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 5); + $expected = array('Article' => array( + 'id' => '5', + 'user_id' => '4', + 'title' => 'Fifth Article', + 'body' => 'Fifth Article Body', + 'published' => 'Y' + )); + $this->assertEqual($result, $expected); + + // Go back and edit the first article we created, starting by checking it's still there + + $TestModel->recursive = -1; + $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 4); + $expected = array('Article' => array( + 'id' => '4', + 'user_id' => '1', + 'title' => 'Fourth Article', + 'body' => 'Fourth Article Body', + 'published' => 'Y' + )); + $this->assertEqual($result, $expected); + + // And now do the update with set() + + $data = array('Article' => array( + 'id' => '4', + 'title' => 'Fourth Article - New Title', + 'published' => 'N' + )); + $result = $TestModel->set($data) && $TestModel->save(); + $this->assertTrue($result); + + $TestModel->recursive = -1; + $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 4); + $expected = array('Article' => array( + 'id' => '4', + 'user_id' => '1', + 'title' => 'Fourth Article - New Title', + 'body' => 'Fourth Article Body', + 'published' => 'N' + )); + $this->assertEqual($result, $expected); + + $TestModel->recursive = -1; + $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 5); + $expected = array('Article' => array( + 'id' => '5', + 'user_id' => '4', + 'title' => 'Fifth Article', + 'body' => 'Fifth Article Body', + 'published' => 'Y' + )); + $this->assertEqual($result, $expected); + + $data = array('Article' => array('id' => '5', 'title' => 'Fifth Article - New Title 5')); + $result = ($TestModel->set($data) && $TestModel->save()); + $this->assertTrue($result); + + $TestModel->recursive = -1; + $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 5); + $expected = array('Article' => array( + 'id' => '5', + 'user_id' => '4', + 'title' => 'Fifth Article - New Title 5', + 'body' => 'Fifth Article Body', + 'published' => 'Y' + )); + $this->assertEqual($result, $expected); + + $TestModel->recursive = -1; + $result = $TestModel->find('all', array('fields' => array('id', 'title'))); + $expected = array( + array('Article' => array('id' => 1, 'title' => 'First Article' )), + array('Article' => array('id' => 2, 'title' => 'Second Article' )), + array('Article' => array('id' => 3, 'title' => 'Third Article' )), + array('Article' => array('id' => 4, 'title' => 'Fourth Article - New Title' )), + array('Article' => array('id' => 5, 'title' => 'Fifth Article - New Title 5' )) + ); + $this->assertEqual($result, $expected); + } +/** + * testSaveWithNonExistentFields method + * + * @access public + * @return void + */ + function testSaveWithNonExistentFields() { + $this->loadFixtures('Article'); + $TestModel =& new Article(); + $TestModel->recursive = -1; + + $data = array( + 'non_existent' => 'This field does not exist', + 'user_id' => '1', + 'title' => 'Fourth Article - New Title', + 'body' => 'Fourth Article Body', + 'published' => 'N' + ); + $result = $TestModel->create() && $TestModel->save($data); + $this->assertTrue($result); + + $expected = array('Article' => array( + 'id' => '4', + 'user_id' => '1', + 'title' => 'Fourth Article - New Title', + 'body' => 'Fourth Article Body', + 'published' => 'N' + )); + $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 4); + $this->assertEqual($result, $expected); + + $data = array( + 'user_id' => '1', + 'non_existent' => 'This field does not exist', + 'title' => 'Fiveth Article - New Title', + 'body' => 'Fiveth Article Body', + 'published' => 'N' + ); + $result = $TestModel->create() && $TestModel->save($data); + $this->assertTrue($result); + + $expected = array('Article' => array( + 'id' => '5', + 'user_id' => '1', + 'title' => 'Fiveth Article - New Title', + 'body' => 'Fiveth Article Body', + 'published' => 'N' + )); + $result = $TestModel->read(array('id', 'user_id', 'title', 'body', 'published'), 5); + $this->assertEqual($result, $expected); + } +/** + * testSaveFromXml method + * + * @access public + * @return void + */ + function testSaveFromXml() { + $this->loadFixtures('Article'); + App::import('Core', 'Xml'); + + $Article = new Article(); + $Article->save(new Xml('
')); + $this->assertTrue($Article->save(new Xml('
'))); + + $results = $Article->find(array('Article.title' => 'test xml')); + $this->assertTrue($results); + } +/** + * testSaveHabtm method + * + * @access public + * @return void + */ + function testSaveHabtm() { + $this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'ArticlesTag'); + $TestModel =& new Article(); + + $result = $TestModel->findById(2); + $expected = array( + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Second Article', + 'body' => 'Second Article Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + ), + 'User' => array( + 'id' => '3', + 'user' => 'larry', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', + 'created' => '2007-03-17 01:20:23', + 'updated' => '2007-03-17 01:22:31' + ), + 'Comment' => array( + array( 'id' => '5', 'article_id' => '2', 'user_id' => '1', @@ -12214,24 +10446,7 @@ class ModelTest extends CakeTestCase { 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31' ), - 'User' => array( - 'id' => '1', - 'user' => 'mariano', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:16:23', - 'updated' => '2007-03-17 01:18:31' - ), - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - )), - array( - 'Comment' => array( + array( 'id' => '6', 'article_id' => '2', 'user_id' => '2', @@ -12239,482 +10454,2329 @@ class ModelTest extends CakeTestCase { 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31' + )), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' ), - 'User' => array( - 'id' => '2', - 'user' => 'nate', - 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', - 'created' => '2007-03-17 01:18:23', - 'updated' => '2007-03-17 01:20:31' - ), - 'Article' => array( - 'id' => '2', - 'user_id' => '3', - 'title' => 'Second Article', - 'body' => 'Second Article Body', - 'published' => 'Y', - 'created' => '2007-03-18 10:41:23', - 'updated' => '2007-03-18 10:43:31' - ))); - $this->assertEqual($TestModel->Comment->find('all'), $expected); - - foreach (array('User', 'Comment') as $class) { - $this->_fixtures[$this->_fixtureClassMap[$class]]->drop($db2); - } - } -/** - * testDisplayField method - * - * @access public - * @return void - */ - function testDisplayField() { - $this->loadFixtures('Post', 'Comment', 'Person'); - $Post = new Post(); - $Comment = new Comment(); - $Person = new Person(); - - $this->assertEqual($Post->displayField, 'title'); - $this->assertEqual($Person->displayField, 'name'); - $this->assertEqual($Comment->displayField, 'id'); - } -/** - * testSchema method - * - * @access public - * @return void - */ - function testSchema() { - $Post = new Post(); - - $result = $Post->schema(); - $columns = array('id', 'author_id', 'title', 'body', 'published', 'created', 'updated'); - $this->assertEqual(array_keys($result), $columns); - - $types = array('integer', 'integer', 'string', 'text', 'string', 'datetime', 'datetime'); - $this->assertEqual(Set::extract(array_values($result), '{n}.type'), $types); - - $result = $Post->schema('body'); - $this->assertEqual($result['type'], 'text'); - $this->assertNull($Post->schema('foo')); - - $this->assertEqual($Post->getColumnTypes(), array_combine($columns, $types)); - } -/** - * testOldQuery method - * - * @access public - * @return void - */ - function testOldQuery() { - $this->loadFixtures('Article'); - $Article =& new Article(); - - $query = 'SELECT title FROM '; - $query .= $this->db->fullTableName('articles'); - $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.id IN (1,2)'; - - $results = $Article->query($query); - $this->assertTrue(is_array($results)); - $this->assertEqual(count($results), 2); - - $query = 'SELECT title, body FROM '; - $query .= $this->db->fullTableName('articles'); - $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.id = 1'; - - $results = $Article->query($query, false); - $this->assertTrue(!isset($this->db->_queryCache[$query])); - $this->assertTrue(is_array($results)); - - $query = 'SELECT title, id FROM '; - $query .= $this->db->fullTableName('articles'); - $query .= ' WHERE ' . $this->db->fullTableName('articles'); - $query .= '.published = ' . $this->db->value('Y'); - - $results = $Article->query($query, true); - $this->assertTrue(isset($this->db->_queryCache[$query])); - $this->assertTrue(is_array($results)); - } -/** - * testPreparedQuery method - * - * @access public - * @return void - */ - function testPreparedQuery() { - $this->loadFixtures('Article'); - $Article =& new Article(); - $this->db->_queryCache = array(); - - $finalQuery = 'SELECT title, published FROM '; - $finalQuery .= $this->db->fullTableName('articles'); - $finalQuery .= ' WHERE ' . $this->db->fullTableName('articles'); - $finalQuery .= '.id = ' . $this->db->value(1); - $finalQuery .= ' AND ' . $this->db->fullTableName('articles'); - $finalQuery .= '.published = ' . $this->db->value('Y'); - - $query = 'SELECT title, published FROM '; - $query .= $this->db->fullTableName('articles'); - $query .= ' WHERE ' . $this->db->fullTableName('articles'); - $query .= '.id = ? AND ' . $this->db->fullTableName('articles') . '.published = ?'; - - $params = array(1, 'Y'); - $result = $Article->query($query, $params); - $expected = array( - '0' => array( - $this->db->fullTableName('articles', false) => array( - 'title' => 'First Article', 'published' => 'Y') - )); - - if (isset($result[0][0])) { - $expected[0][0] = $expected[0][$this->db->fullTableName('articles', false)]; - unset($expected[0][$this->db->fullTableName('articles', false)]); - } - - $this->assertEqual($result, $expected); - $this->assertTrue(isset($this->db->_queryCache[$finalQuery])); - - $finalQuery = 'SELECT id, created FROM '; - $finalQuery .= $this->db->fullTableName('articles'); - $finalQuery .= ' WHERE ' . $this->db->fullTableName('articles'); - $finalQuery .= '.title = ' . $this->db->value('First Article'); - - $query = 'SELECT id, created FROM '; - $query .= $this->db->fullTableName('articles'); - $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.title = ?'; - - $params = array('First Article'); - $result = $Article->query($query, $params, false); - $this->assertTrue(is_array($result)); - $this->assertTrue( - isset($result[0][$this->db->fullTableName('articles', false)]) - || isset($result[0][0]) - ); - $this->assertFalse(isset($this->db->_queryCache[$finalQuery])); - - $query = 'SELECT title FROM '; - $query .= $this->db->fullTableName('articles'); - $query .= ' WHERE ' . $this->db->fullTableName('articles') . '.title LIKE ?'; - - $params = array('%First%'); - $result = $Article->query($query, $params); - $this->assertTrue(is_array($result)); - $this->assertTrue( - isset($result[0][$this->db->fullTableName('articles', false)]['title']) - || isset($result[0][0]['title']) - ); - - //related to ticket #5035 - $query = 'SELECT title FROM '; - $query .= $this->db->fullTableName('articles') . ' WHERE title = ? AND published = ?'; - $params = array('First? Article', 'Y'); - $Article->query($query, $params); - - $expected = 'SELECT title FROM '; - $expected .= $this->db->fullTableName('articles'); - $expected .= " WHERE title = 'First? Article' AND published = 'Y'"; - $this->assertTrue(isset($this->db->_queryCache[$expected])); - - } -/** - * testParameterMismatch method - * - * @access public - * @return void - */ - function testParameterMismatch() { - $this->loadFixtures('Article'); - $Article =& new Article(); - - $query = 'SELECT * FROM ' . $this->db->fullTableName('articles'); - $query .= ' WHERE ' . $this->db->fullTableName('articles'); - $query .= '.published = ? AND ' . $this->db->fullTableName('articles') . '.user_id = ?'; - $params = array('Y'); - $this->expectError(); - - ob_start(); - $result = $Article->query($query, $params); - ob_end_clean(); - $this->assertEqual($result, null); - } -/** - * testVeryStrangeUseCase method - * - * @access public - * @return void - */ - function testVeryStrangeUseCase() { - $message = "%s skipping SELECT * FROM ? WHERE ? = ? AND ? = ?; prepared query."; - $message .= " MSSQL is incompatible with this test."; - - if ($this->skipIf($this->db->config['driver'] == 'mssql', $message)) { - return; - } - - $this->loadFixtures('Article'); - $Article =& new Article(); - - $query = 'SELECT * FROM ? WHERE ? = ? AND ? = ?'; - $param = array( - $this->db->fullTableName('articles'), - $this->db->fullTableName('articles') . '.user_id', '3', - $this->db->fullTableName('articles') . '.published', 'Y' - ); - $this->expectError(); - - ob_start(); - $result = $Article->query($query, $param); - ob_end_clean(); - } -/** - * testUnderscoreFieldSave method - * - * @access public - * @return void - */ - function testUnderscoreFieldSave() { - $this->loadFixtures('UnderscoreField'); - $UnderscoreField =& new UnderscoreField(); - - $currentCount = $UnderscoreField->find('count'); - $this->assertEqual($currentCount, 3); - $data = array('UnderscoreField' => array( - 'user_id' => '1', - 'my_model_has_a_field' => 'Content here', - 'body' => 'Body', - 'published' => 'Y', - 'another_field' => 4 - )); - $ret = $UnderscoreField->save($data); - $this->assertTrue($ret); - - $currentCount = $UnderscoreField->find('count'); - $this->assertEqual($currentCount, 4); - } -/** - * testGroupBy method - * - * These tests will never pass with Postgres or Oracle as all fields in a select must be - * part of an aggregate function or in the GROUP BY statement. - * - * @access public - * @return void - */ - function testGroupBy() { - $db = ConnectionManager::getDataSource('test_suite'); - $isStrictGroupBy = in_array($db->config['driver'], array('postgres', 'oracle')); - $message = '%s Postgresql and Oracle have strict GROUP BY and are incompatible with this test.'; - - if ($this->skipIf($isStrictGroupBy, $message )) { - return; - } - - $this->loadFixtures('Project', 'Product', 'Thread', 'Message', 'Bid'); - $Thread =& new Thread(); - $Product =& new Product(); - - $result = $Thread->find('all', array( - 'group' => 'Thread.project_id', - 'order' => 'Thread.id ASC' - )); - - $expected = array( - array( - 'Thread' => array( - 'id' => 1, - 'project_id' => 1, - 'name' => 'Project 1, Thread 1' - ), - 'Project' => array( - 'id' => 1, - 'name' => 'Project 1' - ), - 'Message' => array( - array( - 'id' => 1, - 'thread_id' => 1, - 'name' => 'Thread 1, Message 1' - ))), - array( - 'Thread' => array( - 'id' => 3, - 'project_id' => 2, - 'name' => 'Project 2, Thread 1' - ), - 'Project' => array( - 'id' => 2, - 'name' => 'Project 2' - ), - 'Message' => array( - array( - 'id' => 3, - 'thread_id' => 3, - 'name' => 'Thread 3, Message 1' - )))); - $this->assertEqual($result, $expected); - - $rows = $Thread->find('all', array( - 'group' => 'Thread.project_id', - 'fields' => array('Thread.project_id', 'COUNT(*) AS total') - )); - $result = array(); - foreach($rows as $row) { - $result[$row['Thread']['project_id']] = $row[0]['total']; - } - $expected = array( - 1 => 2, - 2 => 1 + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ) + ) ); $this->assertEqual($result, $expected); - $rows = $Thread->find('all', array( - 'group' => 'Thread.project_id', - 'fields' => array('Thread.project_id', 'COUNT(*) AS total'), - 'order'=> 'Thread.project_id' - )); - $result = array(); - foreach($rows as $row) { - $result[$row['Thread']['project_id']] = $row[0]['total']; - } - $expected = array( - 1 => 2, - 2 => 1 - ); - $this->assertEqual($result, $expected); - - $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), - 'group' => 'Thread.project_id' - )); - $expected = array( - array( - 'Thread' => array( - 'id' => 1, - 'project_id' => 1, - 'name' => 'Project 1, Thread 1' - ), - 'Project' => array( - 'id' => 1, - 'name' => 'Project 1' - ), - 'Message' => array( - array( - 'id' => 1, - 'thread_id' => 1, - 'name' => 'Thread 1, Message 1' - )))); - $this->assertEqual($result, $expected); - - $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), - 'group' => 'Thread.project_id, Project.id' - )); - $this->assertEqual($result, $expected); - - $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), - 'group' => 'project_id' - )); - $this->assertEqual($result, $expected); - - - $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), - 'group' => array('project_id') - )); - $this->assertEqual($result, $expected); - - - $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), - 'group' => array('project_id', 'Project.id') - )); - $this->assertEqual($result, $expected); - - - $result = $Thread->find('all', array( - 'conditions' => array('Thread.project_id' => 1), - 'group' => array('Thread.project_id', 'Project.id') - )); - $this->assertEqual($result, $expected); - - - $expected = array( - array('Product' => array('type' => 'Clothing'), array('price' => 32)), - array('Product' => array('type' => 'Food'), array('price' => 9)), - array('Product' => array('type' => 'Music'), array( 'price' => 4)), - array('Product' => array('type' => 'Toy'), array('price' => 3)) - ); - $result = $Product->find('all',array( - 'fields'=>array('Product.type','MIN(Product.price) as price'), - 'group'=> 'Product.type', - 'order' => 'Product.type ASC' - )); - $this->assertEqual($result, $expected); - - $result = $Product->find('all', array( - 'fields'=>array('Product.type','MIN(Product.price) as price'), - 'group'=> array('Product.type'), - 'order' => 'Product.type ASC')); - $this->assertEqual($result, $expected); - } - /** - * testSaveDateAsFirstEntry method - * - * @access public - * @return void - */ - function testSaveDateAsFirstEntry() { - $this->loadFixtures('Article'); - - $Article =& new Article(); - $data = array( 'Article' => array( - 'created' => array( - 'day' => '1', - 'month' => '1', - 'year' => '2008' + 'id' => '2', + 'title' => 'New Second Article' + ), + 'Tag' => array('Tag' => array(1, 2)) + ); + + $this->assertTrue($TestModel->set($data)); + $this->assertTrue($TestModel->save()); + + $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); + $result = $TestModel->find(array('Article.id' => 2), array('id', 'user_id', 'title', 'body')); + $expected = array( + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'New Second Article', + 'body' => 'Second Article Body' + ), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' ), - 'title' => 'Test Title', - 'user_id' => 1 + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ))); + $this->assertEqual($result, $expected); + + $data = array('Article' => array('id' => '2'), 'Tag' => array('Tag' => array(2, 3))); + $result = $TestModel->set($data); + $this->assertTrue($result); + + $result = $TestModel->save(); + $this->assertTrue($result); + + $TestModel->unbindModel(array( + 'belongsTo' => array('User'), + 'hasMany' => array('Comment') )); - $Article->create(); - $this->assertTrue($Article->save($data)); + $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); + $expected = array( + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'New Second Article', + 'body' => 'Second Article Body' + ), + 'Tag' => array( + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))); + $this->assertEqual($result, $expected); - $testResult = $Article->find(array('Article.title' => 'Test Title')); + $data = array('Tag' => array('Tag' => array(1, 2, 3))); - $this->assertEqual($testResult['Article']['title'], $data['Article']['title']); - $this->assertEqual($testResult['Article']['created'], '2008-01-01 00:00:00'); + $result = $TestModel->set($data); + $this->assertTrue($result); + $result = $TestModel->save(); + $this->assertTrue($result); + + $TestModel->unbindModel(array( + 'belongsTo' => array('User'), + 'hasMany' => array('Comment') + )); + $result = $TestModel->find(array('Article.id' => 2), array('id', 'user_id', 'title', 'body')); + $expected = array( + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'New Second Article', + 'body' => 'Second Article Body' + ), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))); + $this->assertEqual($result, $expected); + + $data = array('Tag' => array('Tag' => array())); + $result = $TestModel->set($data); + $this->assertTrue($result); + + $result = $TestModel->save(); + $this->assertTrue($result); + + $data = array('Tag' => array('Tag' => '')); + $result = $TestModel->set($data); + $this->assertTrue($result); + + $result = $TestModel->save(); + $this->assertTrue($result); + + $TestModel->unbindModel(array( + 'belongsTo' => array('User'), + 'hasMany' => array('Comment') + )); + $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); + $expected = array( + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'New Second Article', + 'body' => 'Second Article Body' + ), + 'Tag' => array() + ); + $this->assertEqual($result, $expected); + + $data = array('Tag' => array('Tag' => array(2, 3))); + $result = $TestModel->set($data); + $this->assertTrue($result); + + $result = $TestModel->save(); + $this->assertTrue($result); + + $TestModel->unbindModel(array( + 'belongsTo' => array('User'), + 'hasMany' => array('Comment') + )); + $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); + $expected = array( + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'New Second Article', + 'body' => 'Second Article Body' + ), + 'Tag' => array( + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))); + $this->assertEqual($result, $expected); + + $data = array( + 'Tag' => array( + 'Tag' => array(1, 2) + ), + 'Article' => array( + 'id' => '2', + 'title' => 'New Second Article' + )); + $this->assertTrue($TestModel->set($data)); + $this->assertTrue($TestModel->save()); + + $TestModel->unbindModel(array( + 'belongsTo' => array('User'), + 'hasMany' => array('Comment') + )); + $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); + $expected = array( + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'New Second Article', + 'body' => 'Second Article Body' + ), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ))); + $this->assertEqual($result, $expected); + + $data = array( + 'Tag' => array( + 'Tag' => array(1, 2) + ), + 'Article' => array( + 'id' => '2', + 'title' => 'New Second Article Title' + )); + $result = $TestModel->set($data); + $this->assertTrue($result); + $this->assertTrue($TestModel->save()); + + $TestModel->unbindModel(array( + 'belongsTo' => array('User'), + 'hasMany' => array('Comment') + )); + $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); + $expected = array( + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'New Second Article Title', + 'body' => 'Second Article Body' + ), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ) + ) + ); + $this->assertEqual($result, $expected); + + $data = array( + 'Tag' => array( + 'Tag' => array(2, 3) + ), + 'Article' => array( + 'id' => '2', + 'title' => 'Changed Second Article' + )); + $this->assertTrue($TestModel->set($data)); + $this->assertTrue($TestModel->save()); + + $TestModel->unbindModel(array( + 'belongsTo' => array('User'), + 'hasMany' => array('Comment') + )); + $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); + $expected = array( + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Changed Second Article', + 'body' => 'Second Article Body' + ), + 'Tag' => array( + array( + 'id' => '2', + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ) + ) + ); + $this->assertEqual($result, $expected); + + $data = array( + 'Tag' => array( + 'Tag' => array(1, 3) + ), + 'Article' => array('id' => '2'), + ); + + $result = $TestModel->set($data); + $this->assertTrue($result); + + $result = $TestModel->save(); + $this->assertTrue($result); + + $TestModel->unbindModel(array( + 'belongsTo' => array('User'), + 'hasMany' => array('Comment') + )); + $result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body')); + $expected = array( + 'Article' => array( + 'id' => '2', + 'user_id' => '3', + 'title' => 'Changed Second Article', + 'body' => 'Second Article Body' + ), + 'Tag' => array( + array( + 'id' => '1', + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + array( + 'id' => '3', + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))); + $this->assertEqual($result, $expected); + + $data = array( + 'Article' => array( + 'id' => 10, + 'user_id' => '2', + 'title' => 'New Article With Tags and fieldList', + 'body' => 'New Article Body with Tags and fieldList', + 'created' => '2007-03-18 14:55:23', + 'updated' => '2007-03-18 14:57:31' + ), + 'Tag' => array( + 'Tag' => array(1, 2, 3) + )); + $result = $TestModel->create() + && $TestModel->save($data, true, array('user_id', 'title', 'published')); + $this->assertTrue($result); + + $TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment'))); + $result = $TestModel->read(); + $expected = array( + 'Article' => array( + 'id' => 4, + 'user_id' => 2, + 'title' => 'New Article With Tags and fieldList', + 'body' => '', + 'published' => 'N', + 'created' => '', + 'updated' => '' + ), + 'Tag' => array( + 0 => array( + 'id' => 1, + 'tag' => 'tag1', + 'created' => '2007-03-18 12:22:23', + 'updated' => '2007-03-18 12:24:31' + ), + 1 => array( + 'id' => 2, + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ), + 2 => array( + 'id' => 3, + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))); + $this->assertEqual($result, $expected); + + + $this->loadFixtures('JoinA', 'JoinC', 'JoinAC', 'JoinB', 'JoinAB'); + $TestModel = new JoinA(); + $TestModel->hasBelongsToMany['JoinC']['unique'] = true; + $data = array( + 'JoinA' => array( + 'id' => 1, + 'name' => 'Join A 1', + 'body' => 'Join A 1 Body', + ), + 'JoinC' => array( + 'JoinC' => array( + array('join_c_id' => 2, 'other' => 'new record'), + array('join_c_id' => 3, 'other' => 'new record') + ) + ) + ); + $TestModel->save($data); + $result = $TestModel->read(null, 1); + $time = date('Y-M-D H:i:s'); + $expected = array(4, 5); + $this->assertEqual(Set::extract('/JoinC/JoinAsJoinC/id', $result), $expected); + $expected = array('new record', 'new record'); + $this->assertEqual(Set::extract('/JoinC/JoinAsJoinC/other', $result), $expected); } /** - * testDeleteDependentWithConditions method + * testSaveHabtmCustomKeys method * * @access public * @return void */ - function testDeleteDependentWithConditions() { - $this->loadFixtures('Cd','Book','OverallFavorite'); + function testSaveHabtmCustomKeys() { + $this->loadFixtures('Story', 'StoriesTag', 'Tag'); + $Story =& new Story(); - $Cd =& new Cd(); - $OverallFavorite =& new OverallFavorite(); + $data = array( + 'Story' => array('story' => '1'), + 'Tag' => array( + 'Tag' => array(2, 3) + )); + $result = $Story->set($data); + $this->assertTrue($result); - $Cd->del(1); + $result = $Story->save(); + $this->assertTrue($result); - $result = $OverallFavorite->find('all', array( - 'fields' => array('model_type', 'model_id', 'priority') + $result = $Story->find('all'); + $expected = array( + array( + 'Story' => array( + 'story' => 1, + 'title' => 'First Story' + ), + 'Tag' => array( + array( + 'id' => 2, + 'tag' => 'tag2', + 'created' => '2007-03-18 12:24:23', + 'updated' => '2007-03-18 12:26:31' + ), + array( + 'id' => 3, + 'tag' => 'tag3', + 'created' => '2007-03-18 12:26:23', + 'updated' => '2007-03-18 12:28:31' + ))), + array( + 'Story' => array( + 'story' => 2, + 'title' => 'Second Story' + ), + 'Tag' => array() + )); + $this->assertEqual($result, $expected); + } +/** + * testHabtmSaveKeyResolution method + * + * @access public + * @return void + */ + function testHabtmSaveKeyResolution() { + $this->loadFixtures('Apple', 'Device', 'ThePaperMonkies'); + $ThePaper =& new ThePaper(); + + $ThePaper->id = 1; + $ThePaper->save(array('Monkey' => array(2, 3))); + + $result = $ThePaper->findById(1); + $expected = array( + array( + 'id' => '2', + 'device_type_id' => '1', + 'name' => 'Device 2', + 'typ' => '1' + ), + array( + 'id' => '3', + 'device_type_id' => '1', + 'name' => 'Device 3', + 'typ' => '2' + )); + $this->assertEqual($result['Monkey'], $expected); + + $ThePaper->id = 2; + $ThePaper->save(array('Monkey' => array(1, 2, 3))); + + $result = $ThePaper->findById(2); + $expected = array( + array( + 'id' => '1', + 'device_type_id' => '1', + 'name' => 'Device 1', + 'typ' => '1' + ), + array( + 'id' => '2', + 'device_type_id' => '1', + 'name' => 'Device 2', + 'typ' => '1' + ), + array( + 'id' => '3', + 'device_type_id' => '1', + 'name' => 'Device 3', + 'typ' => '2' + )); + $this->assertEqual($result['Monkey'], $expected); + + $ThePaper->id = 2; + $ThePaper->save(array('Monkey' => array(1, 3))); + + $result = $ThePaper->findById(2); + $expected = array( + array( + 'id' => '1', + 'device_type_id' => '1', + 'name' => 'Device 1', + 'typ' => '1' + ), + array( + 'id' => '3', + 'device_type_id' => '1', + 'name' => 'Device 3', + 'typ' => '2' + )); + $this->assertEqual($result['Monkey'], $expected); + + $result = $ThePaper->findById(1); + $expected = array( + array( + 'id' => '2', + 'device_type_id' => '1', + 'name' => 'Device 2', + 'typ' => '1' + ), + array( + 'id' => '3', + 'device_type_id' => '1', + 'name' => 'Device 3', + 'typ' => '2' + )); + $this->assertEqual($result['Monkey'], $expected); + } +/** + * testCreationOfEmptyRecord method + * + * @access public + * @return void + */ + function testCreationOfEmptyRecord() { + $this->loadFixtures('Author'); + $TestModel =& new Author(); + $this->assertEqual($TestModel->find('count'), 4); + + $TestModel->deleteAll(true, false, false); + $this->assertEqual($TestModel->find('count'), 0); + + $result = $TestModel->save(); + $this->assertTrue(isset($result['Author']['created'])); + $this->assertTrue(isset($result['Author']['updated'])); + $this->assertEqual($TestModel->find('count'), 1); + } +/** + * testCreateWithPKFiltering method + * + * @access public + * @return void + */ + function testCreateWithPKFiltering() { + $TestModel =& new Article(); + $data = array( + 'id' => 5, + 'user_id' => 2, + 'title' => 'My article', + 'body' => 'Some text' + ); + + $result = $TestModel->create($data); + $expected = array( + 'Article' => array( + 'published' => 'N', + 'id' => 5, + 'user_id' => 2, + 'title' => 'My article', + 'body' => 'Some text' + )); + + $this->assertEqual($result, $expected); + $this->assertEqual($TestModel->id, 5); + + $result = $TestModel->create($data, true); + $expected = array( + 'Article' => array( + 'published' => 'N', + 'id' => false, + 'user_id' => 2, + 'title' => 'My article', + 'body' => 'Some text' + )); + + $this->assertEqual($result, $expected); + $this->assertFalse($TestModel->id); + + $result = $TestModel->create(array('Article' => $data), true); + $expected = array( + 'Article' => array( + 'published' => 'N', + 'id' => false, + 'user_id' => 2, + 'title' => 'My article', + 'body' => 'Some text' + )); + + $this->assertEqual($result, $expected); + $this->assertFalse($TestModel->id); + + $data = array( + 'id' => 6, + 'user_id' => 2, + 'title' => 'My article', + 'body' => 'Some text', + 'created' => '1970-01-01 00:00:00', + 'updated' => '1970-01-01 12:00:00', + 'modified' => '1970-01-01 12:00:00' + ); + + $result = $TestModel->create($data); + $expected = array( + 'Article' => array( + 'published' => 'N', + 'id' => 6, + 'user_id' => 2, + 'title' => 'My article', + 'body' => 'Some text', + 'created' => '1970-01-01 00:00:00', + 'updated' => '1970-01-01 12:00:00', + 'modified' => '1970-01-01 12:00:00' + )); + $this->assertEqual($result, $expected); + $this->assertEqual($TestModel->id, 6); + + $result = $TestModel->create(array( + 'Article' => array_diff_key($data, array( + 'created' => true, + 'updated' => true, + 'modified' => true + ))), true); + $expected = array( + 'Article' => array( + 'published' => 'N', + 'id' => false, + 'user_id' => 2, + 'title' => 'My article', + 'body' => 'Some text' + )); + $this->assertEqual($result, $expected); + $this->assertFalse($TestModel->id); + } +/** + * testCreationWithMultipleData method + * + * @access public + * @return void + */ + function testCreationWithMultipleData() { + $this->loadFixtures('Article', 'Comment'); + $Article =& new Article(); + $Comment =& new Comment(); + + $articles = $Article->find('all', array( + 'fields' => array('id','title'), + 'recursive' => -1 + )); + + $comments = $Comment->find('all', array( + 'fields' => array('id','article_id','user_id','comment','published'), 'recursive' => -1)); + + $this->assertEqual($articles, array( + array('Article' => array( + 'id' => 1, + 'title' => 'First Article' + )), + array('Article' => array( + 'id' => 2, + 'title' => 'Second Article' + )), + array('Article' => array( + 'id' => 3, + 'title' => 'Third Article' + )))); + + $this->assertEqual($comments, array( + array('Comment' => array( + 'id' => 1, + 'article_id' => 1, + 'user_id' => 2, + 'comment' => 'First Comment for First Article', + 'published' => 'Y' + )), + array('Comment' => array( + 'id' => 2, + 'article_id' => 1, + 'user_id' => 4, + 'comment' => 'Second Comment for First Article', + 'published' => 'Y' + )), + array('Comment' => array( + 'id' => 3, + 'article_id' => 1, + 'user_id' => 1, + 'comment' => 'Third Comment for First Article', + 'published' => 'Y' + )), + array('Comment' => array( + 'id' => 4, + 'article_id' => 1, + 'user_id' => 1, + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N' + )), + array('Comment' => array( + 'id' => 5, + 'article_id' => 2, + 'user_id' => 1, + 'comment' => 'First Comment for Second Article', + 'published' => 'Y' + )), + array('Comment' => array( + 'id' => 6, + 'article_id' => 2, + 'user_id' => 2, + 'comment' => 'Second Comment for Second Article', + 'published' => 'Y' + )))); + + $data = array( + 'Comment' => array( + 'article_id' => 2, + 'user_id' => 4, + 'comment' => 'Brand New Comment', + 'published' => 'N' + ), + 'Article' => array( + 'id' => 2, + 'title' => 'Second Article Modified' + )); + + $result = $Comment->create($data); + + $this->assertTrue($result); + $result = $Comment->save(); + $this->assertTrue($result); + + $articles = $Article->find('all', array( + 'fields' => array('id','title'), + 'recursive' => -1 + )); + + $comments = $Comment->find('all', array( + 'fields' => array('id','article_id','user_id','comment','published'), + 'recursive' => -1 + )); + + $this->assertEqual($articles, array( + array('Article' => array( + 'id' => 1, + 'title' => 'First Article' + )), + array('Article' => array( + 'id' => 2, + 'title' => 'Second Article' + )), + array('Article' => array( + 'id' => 3, + 'title' => 'Third Article' + )))); + + $this->assertEqual($comments, array( + array('Comment' => array( + 'id' => 1, + 'article_id' => 1, + 'user_id' => 2, + 'comment' => 'First Comment for First Article', + 'published' => 'Y' + )), + array('Comment' => array( + 'id' => 2, + 'article_id' => 1, + 'user_id' => 4, + 'comment' => 'Second Comment for First Article', + 'published' => 'Y' + )), + array('Comment' => array( + 'id' => 3, + 'article_id' => 1, + 'user_id' => 1, + 'comment' => 'Third Comment for First Article', + 'published' => 'Y' + )), + array('Comment' => array( + 'id' => 4, + 'article_id' => 1, + 'user_id' => 1, + 'comment' => 'Fourth Comment for First Article', + 'published' => 'N' + )), + array('Comment' => array( + 'id' => 5, + 'article_id' => 2, + 'user_id' => 1, + 'comment' => 'First Comment for Second Article', + 'published' => 'Y' + )), + array('Comment' => array( + 'id' => 6, + 'article_id' => 2, + 'user_id' => 2, 'comment' => + 'Second Comment for Second Article', + 'published' => 'Y' + )), + array('Comment' => array( + 'id' => 7, + 'article_id' => 2, + 'user_id' => 4, + 'comment' => 'Brand New Comment', + 'published' => 'N' + )))); + + } +/** + * testCreationWithMultipleDataSameModel method + * + * @access public + * @return void + */ + function testCreationWithMultipleDataSameModel() { + $this->loadFixtures('Article'); + $Article =& new Article(); + $SecondaryArticle =& new Article(); + + $result = $Article->field('title', array('id' => 1)); + $this->assertEqual($result, 'First Article'); + + $data = array( + 'Article' => array( + 'user_id' => 2, + 'title' => 'Brand New Article', + 'body' => 'Brand New Article Body', + 'published' => 'Y' + ), + 'SecondaryArticle' => array( + 'id' => 1 + )); + + $Article->create(); + $result = $Article->save($data); + $this->assertTrue($result); + + $result = $Article->getInsertID(); + $this->assertTrue(!empty($result)); + + $result = $Article->field('title', array('id' => 1)); + $this->assertEqual($result, 'First Article'); + + $articles = $Article->find('all', array( + 'fields' => array('id','title'), + 'recursive' => -1 + )); + + $this->assertEqual($articles, array( + array('Article' => array( + 'id' => 1, + 'title' => 'First Article' + )), + array('Article' => array( + 'id' => 2, + 'title' => 'Second Article' + )), + array('Article' => array( + 'id' => 3, + 'title' => 'Third Article' + )), + array('Article' => array( + 'id' => 4, + 'title' => 'Brand New Article' + )))); + } +/** + * testCreationWithMultipleDataSameModelManualInstances method + * + * @access public + * @return void + */ + function testCreationWithMultipleDataSameModelManualInstances() { + $this->loadFixtures('PrimaryModel'); + $Primary =& new PrimaryModel(); + $Secondary =& new PrimaryModel(); + + $result = $Primary->field('primary_name', array('id' => 1)); + $this->assertEqual($result, 'Primary Name Existing'); + + $data = array( + 'PrimaryModel' => array( + 'primary_name' => 'Primary Name New' + ), + 'SecondaryModel' => array( + 'id' => array(1) + )); + + $Primary->create(); + $result = $Primary->save($data); + $this->assertTrue($result); + + $result = $Primary->field('primary_name', array('id' => 1)); + $this->assertEqual($result, 'Primary Name Existing'); + + $result = $Primary->getInsertID(); + $this->assertTrue(!empty($result)); + + $result = $Primary->field('primary_name', array('id' => $result)); + $this->assertEqual($result, 'Primary Name New'); + + $result = $Primary->find('count'); + $this->assertEqual($result, 2); + } +/** + * testRecordExists method + * + * @access public + * @return void + */ + function testRecordExists() { + $this->loadFixtures('User'); + $TestModel =& new User(); + + $this->assertFalse($TestModel->exists()); + $TestModel->read(null, 1); + $this->assertTrue($TestModel->exists()); + $TestModel->create(); + $this->assertFalse($TestModel->exists()); + $TestModel->id = 4; + $this->assertTrue($TestModel->exists()); + + $TestModel =& new TheVoid(); + $this->assertFalse($TestModel->exists()); + $TestModel->id = 5; + $this->assertFalse($TestModel->exists()); + } +/** + * testUpdateExisting method + * + * @access public + * @return void + */ + function testUpdateExisting() { + $this->loadFixtures('User', 'Article', 'Comment'); + $TestModel =& new User(); + $TestModel->create(); + + $TestModel->save(array( + 'User' => array( + 'user' => 'some user', + 'password' => 'some password' + ))); + $this->assertTrue(is_int($TestModel->id) || (intval($TestModel->id) === 5)); + $id = $TestModel->id; + + $TestModel->save(array( + 'User' => array( + 'user' => 'updated user' + ))); + $this->assertEqual($TestModel->id, $id); + + $result = $TestModel->findById($id); + $this->assertEqual($result['User']['user'], 'updated user'); + $this->assertEqual($result['User']['password'], 'some password'); + + $Article =& new Article(); + $Comment =& new Comment(); + $data = array( + 'Comment' => array( + 'id' => 1, + 'comment' => 'First Comment for First Article' + ), + 'Article' => array( + 'id' => 2, + 'title' => 'Second Article' + )); + + $result = $Article->save($data); + $this->assertTrue($result); + + $result = $Comment->save($data); + $this->assertTrue($result); + } +/** + * testUpdateMultiple method + * + * @access public + * @return void + */ + function testUpdateMultiple() { + $this->loadFixtures('Comment', 'Article', 'User', 'CategoryThread'); + $TestModel =& new Comment(); + $result = Set::extract($TestModel->find('all'), '{n}.Comment.user_id'); + $expected = array('2', '4', '1', '1', '1', '2'); + $this->assertEqual($result, $expected); + + $TestModel->updateAll(array('Comment.user_id' => 5), array('Comment.user_id' => 2)); + $result = Set::combine($TestModel->find('all'), '{n}.Comment.id', '{n}.Comment.user_id'); + $expected = array(1 => 5, 2 => 4, 3 => 1, 4 => 1, 5 => 1, 6 => 5); + $this->assertEqual($result, $expected); + + $result = $TestModel->updateAll( + array('Comment.comment' => "'Updated today'"), + array('Comment.user_id' => 5) + ); + $this->assertTrue($result); + $result = Set::extract( + $TestModel->find('all', array( + 'conditions' => array( + 'Comment.user_id' => 5 + ))), + '{n}.Comment.comment' + ); + $expected = array_fill(0, 2, 'Updated today'); + $this->assertEqual($result, $expected); + } +/** + * testHabtmUuidWithUuidId method + * + * @access public + * @return void + */ + function testHabtmUuidWithUuidId() { + $this->loadFixtures('Uuidportfolio', 'Uuiditem', 'UuiditemsUuidportfolio'); + $TestModel =& new Uuidportfolio(); + + $data = array('Uuidportfolio' => array('name' => 'Portfolio 3')); + $data['Uuiditem']['Uuiditem'] = array('483798c8-c7cc-430e-8cf9-4fcc40cf8569'); + $TestModel->create($data); + $TestModel->save(); + $id = $TestModel->id; + $result = $TestModel->read(null, $id); + $this->assertEqual(1, count($result['Uuiditem'])); + $this->assertEqual(strlen($result['Uuiditem'][0]['UuiditemsUuidportfolio']['id']), 36); + } +/** + * test HABTM saving when join table has no primary key and only 2 columns. + * + * @return void + **/ + function testHabtmSavingWithNoPrimaryKeyUuidJoinTable() { + $this->loadFixtures('UuidTag', 'Fruit', 'FruitsUuidTag'); + $Fruit =& new Fruit(); + $data = array( + 'Fruit' => array( + 'color' => 'Red', + 'shape' => 'Heart-shaped', + 'taste' => 'sweet', + 'name' => 'Strawberry', + ), + 'UuidTag' => array( + 'UuidTag' => array( + '481fc6d0-b920-43e0-e50f-6d1740cf8569' + ) + ) + ); + $this->assertTrue($Fruit->save($data)); + } +/** + * test HABTM saving when join table has no primary key and only 2 columns, no with model is used. + * + * @return void + **/ + function testHabtmSavingWithNoPrimaryKeyUuidJoinTableNoWith() { + $this->loadFixtures('UuidTag', 'Fruit', 'FruitsUuidTag'); + $Fruit =& new FruitNoWith(); + $data = array( + 'Fruit' => array( + 'color' => 'Red', + 'shape' => 'Heart-shaped', + 'taste' => 'sweet', + 'name' => 'Strawberry', + ), + 'UuidTag' => array( + 'UuidTag' => array( + '481fc6d0-b920-43e0-e50f-6d1740cf8569' + ) + ) + ); + $this->assertTrue($Fruit->save($data)); + } + +/** + * testHabtmUuidWithNumericId method + * + * @access public + * @return void + */ + function testHabtmUuidWithNumericId() { + $this->loadFixtures('Uuidportfolio', 'Uuiditem', 'UuiditemsUuidportfolioNumericid'); + $TestModel =& new Uuiditem(); + + $data = array('Uuiditem' => array('name' => 'Item 7', 'published' => 0)); + $data['Uuidportfolio']['Uuidportfolio'] = array('480af662-eb8c-47d3-886b-230540cf8569'); + $TestModel->create($data); + $TestModel->save(); + $id = $TestModel->id; + $result = $TestModel->read(null, $id); + $this->assertEqual(1, count($result['Uuidportfolio'])); + } +/** + * testSaveMultipleHabtm method + * + * @access public + * @return void + */ + function testSaveMultipleHabtm() { + $this->loadFixtures('JoinA', 'JoinB', 'JoinC', 'JoinAB', 'JoinAC'); + $TestModel = new JoinA(); + $result = $TestModel->findById(1); + + $expected = array( + 'JoinA' => array( + 'id' => 1, + 'name' => 'Join A 1', + 'body' => 'Join A 1 Body', + 'created' => '2008-01-03 10:54:23', + 'updated' => '2008-01-03 10:54:23' + ), + 'JoinB' => array( + 0 => array( + 'id' => 2, + 'name' => 'Join B 2', + 'created' => '2008-01-03 10:55:02', + 'updated' => '2008-01-03 10:55:02', + 'JoinAsJoinB' => array( + 'id' => 1, + 'join_a_id' => 1, + 'join_b_id' => 2, + 'other' => 'Data for Join A 1 Join B 2', + 'created' => '2008-01-03 10:56:33', + 'updated' => '2008-01-03 10:56:33' + ))), + 'JoinC' => array( + 0 => array( + 'id' => 2, + 'name' => 'Join C 2', + 'created' => '2008-01-03 10:56:12', + 'updated' => '2008-01-03 10:56:12', + 'JoinAsJoinC' => array( + 'id' => 1, + 'join_a_id' => 1, + 'join_c_id' => 2, + 'other' => 'Data for Join A 1 Join C 2', + 'created' => '2008-01-03 10:57:22', + 'updated' => '2008-01-03 10:57:22' + )))); + + $this->assertEqual($result, $expected); + + $ts = date('Y-m-d H:i:s'); + $TestModel->id = 1; + $data = array( + 'JoinA' => array( + 'id' => '1', + 'name' => 'New name for Join A 1', + 'updated' => $ts + ), + 'JoinB' => array( + array( + 'id' => 1, + 'join_b_id' => 2, + 'other' => 'New data for Join A 1 Join B 2', + 'created' => $ts, + 'updated' => $ts + )), + 'JoinC' => array( + array( + 'id' => 1, + 'join_c_id' => 2, + 'other' => 'New data for Join A 1 Join C 2', + 'created' => $ts, + 'updated' => $ts + ))); + + $TestModel->set($data); + $TestModel->save(); + + $result = $TestModel->findById(1); + $expected = array( + 'JoinA' => array( + 'id' => 1, + 'name' => 'New name for Join A 1', + 'body' => 'Join A 1 Body', + 'created' => '2008-01-03 10:54:23', + 'updated' => $ts + ), + 'JoinB' => array( + 0 => array( + 'id' => 2, + 'name' => 'Join B 2', + 'created' => '2008-01-03 10:55:02', + 'updated' => '2008-01-03 10:55:02', + 'JoinAsJoinB' => array( + 'id' => 1, + 'join_a_id' => 1, + 'join_b_id' => 2, + 'other' => 'New data for Join A 1 Join B 2', + 'created' => $ts, + 'updated' => $ts + ))), + 'JoinC' => array( + 0 => array( + 'id' => 2, + 'name' => 'Join C 2', + 'created' => '2008-01-03 10:56:12', + 'updated' => '2008-01-03 10:56:12', + 'JoinAsJoinC' => array( + 'id' => 1, + 'join_a_id' => 1, + 'join_c_id' => 2, + 'other' => 'New data for Join A 1 Join C 2', + 'created' => $ts, + 'updated' => $ts + )))); + + $this->assertEqual($result, $expected); + } +/** + * testSaveAll method + * + * @access public + * @return void + */ + function testSaveAll() { + $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment'); + $TestModel =& new Post(); + + $result = $TestModel->find('all'); + $this->assertEqual(count($result), 3); + $this->assertFalse(isset($result[3])); + $ts = date('Y-m-d H:i:s'); + + $TestModel->saveAll(array( + 'Post' => array( + 'title' => 'Post with Author', + 'body' => 'This post will be saved with an author' + ), + 'Author' => array( + 'user' => 'bob', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf90' + ))); + + $result = $TestModel->find('all'); + $expected = array( + 'Post' => array( + 'id' => '4', + 'author_id' => '5', + 'title' => 'Post with Author', + 'body' => 'This post will be saved with an author', + 'published' => 'N', + 'created' => $ts, + 'updated' => $ts + ), + 'Author' => array( + 'id' => '5', + 'user' => 'bob', + 'password' => '5f4dcc3b5aa765d61d8327deb882cf90', + 'created' => $ts, + 'updated' => $ts, + 'test' => 'working' + )); + $this->assertEqual($result[3], $expected); + $this->assertEqual(count($result), 4); + + $TestModel->deleteAll(true); + $this->assertEqual($TestModel->find('all'), array()); + + // SQLite seems to reset the PK counter when that happens, so we need this to make the tests pass + $this->db->truncate($TestModel); + + $ts = date('Y-m-d H:i:s'); + $TestModel->saveAll(array( + array( + 'title' => 'Multi-record post 1', + 'body' => 'First multi-record post', + 'author_id' => 2 + ), + array( + 'title' => 'Multi-record post 2', + 'body' => 'Second multi-record post', + 'author_id' => 2 + ))); + + $result = $TestModel->find('all', array( + 'recursive' => -1, + 'order' => 'Post.id ASC' )); $expected = array( array( - 'OverallFavorite' => array( - 'model_type' => 'Book', - 'model_id' => 1, - 'priority' => 2 + 'Post' => array( + 'id' => '1', + 'author_id' => '2', + 'title' => 'Multi-record post 1', + 'body' => 'First multi-record post', + 'published' => 'N', + 'created' => $ts, + 'updated' => $ts + )), + array( + 'Post' => array( + 'id' => '2', + 'author_id' => '2', + 'title' => 'Multi-record post 2', + 'body' => 'Second multi-record post', + 'published' => 'N', + 'created' => $ts, + 'updated' => $ts + ))); + $this->assertEqual($result, $expected); + + $TestModel =& new Comment(); + $ts = date('Y-m-d H:i:s'); + $result = $TestModel->saveAll(array( + 'Comment' => array( + 'article_id' => 2, + 'user_id' => 2, + 'comment' => 'New comment with attachment', + 'published' => 'Y' + ), + 'Attachment' => array( + 'attachment' => 'some_file.tgz' + ))); + $this->assertTrue($result); + + $result = $TestModel->find('all'); + $expected = array( + 'id' => '7', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'New comment with attachment', + 'published' => 'Y', + 'created' => $ts, + 'updated' => $ts + ); + $this->assertEqual($result[6]['Comment'], $expected); + + $expected = array( + 'id' => '7', + 'article_id' => '2', + 'user_id' => '2', + 'comment' => 'New comment with attachment', + 'published' => 'Y', + 'created' => $ts, + 'updated' => $ts + ); + $this->assertEqual($result[6]['Comment'], $expected); + + $expected = array( + 'id' => '2', + 'comment_id' => '7', + 'attachment' => 'some_file.tgz', + 'created' => $ts, + 'updated' => $ts + ); + $this->assertEqual($result[6]['Attachment'], $expected); + } +/** + * Test SaveAll with Habtm relations + * + * @access public + * @return void + */ + function testSaveAllHabtm() { + $this->loadFixtures('Article', 'Tag', 'Comment', 'User'); + $data = array( + 'Article' => array( + 'user_id' => 1, + 'title' => 'Article Has and belongs to Many Tags' + ), + 'Tag' => array( + 'Tag' => array(1, 2) + ), + 'Comment' => array( + array( + 'comment' => 'Article comment', + 'user_id' => 1 + ))); + $Article =& new Article(); + $result = $Article->saveAll($data); + $this->assertTrue($result); + + $result = $Article->read(); + $this->assertEqual(count($result['Tag']), 2); + $this->assertEqual($result['Tag'][0]['tag'], 'tag1'); + $this->assertEqual(count($result['Comment']), 1); + $this->assertEqual(count($result['Comment'][0]['comment']['Article comment']), 1); + } +/** + * Test SaveAll with Habtm relations and extra join table fields + * + * @access public + * @return void + */ + function testSaveAllHabtmWithExtraJoinTableFields() { + $this->loadFixtures('Something', 'SomethingElse', 'JoinThing'); + + $data = array( + 'Something' => array( + 'id' => 4, + 'title' => 'Extra Fields', + 'body' => 'Extra Fields Body', + 'published' => '1' + ), + 'SomethingElse' => array( + array('something_else_id' => 1, 'doomed' => '1'), + array('something_else_id' => 2, 'doomed' => '0'), + array('something_else_id' => 3, 'doomed' => '1') + ) + ); + + $Something =& new Something(); + $result = $Something->saveAll($data); + $this->assertTrue($result); + $result = $Something->read(); + + $this->assertEqual(count($result['SomethingElse']), 3); + $this->assertTrue(Set::matches('/Something[id=4]', $result)); + + $this->assertTrue(Set::matches('/SomethingElse[id=1]', $result)); + $this->assertTrue(Set::matches('/SomethingElse[id=1]/JoinThing[something_else_id=1]', $result)); + $this->assertTrue(Set::matches('/SomethingElse[id=1]/JoinThing[doomed=1]', $result)); + + $this->assertTrue(Set::matches('/SomethingElse[id=2]', $result)); + $this->assertTrue(Set::matches('/SomethingElse[id=2]/JoinThing[something_else_id=2]', $result)); + $this->assertTrue(Set::matches('/SomethingElse[id=2]/JoinThing[doomed=0]', $result)); + + $this->assertTrue(Set::matches('/SomethingElse[id=3]', $result)); + $this->assertTrue(Set::matches('/SomethingElse[id=3]/JoinThing[something_else_id=3]', $result)); + $this->assertTrue(Set::matches('/SomethingElse[id=3]/JoinThing[doomed=1]', $result)); + } +/** + * testSaveAllHasOne method + * + * @access public + * @return void + */ + function testSaveAllHasOne() { + $model = new Comment(); + $model->deleteAll(true); + $this->assertEqual($model->find('all'), array()); + + $model->Attachment->deleteAll(true); + $this->assertEqual($model->Attachment->find('all'), array()); + + $this->assertTrue($model->saveAll(array( + 'Comment' => array( + 'comment' => 'Comment with attachment', + 'article_id' => 1, + 'user_id' => 1 + ), + 'Attachment' => array( + 'attachment' => 'some_file.zip' + )))); + $result = $model->find('all', array('fields' => array( + 'Comment.id', 'Comment.comment', 'Attachment.id', + 'Attachment.comment_id', 'Attachment.attachment' + ))); + $expected = array(array( + 'Comment' => array( + 'id' => '1', + 'comment' => 'Comment with attachment' + ), + 'Attachment' => array( + 'id' => '1', + 'comment_id' => '1', + 'attachment' => 'some_file.zip' + ))); + $this->assertEqual($result, $expected); + } +/** + * testSaveAllBelongsTo method + * + * @access public + * @return void + */ + function testSaveAllBelongsTo() { + $model = new Comment(); + $model->deleteAll(true); + $this->assertEqual($model->find('all'), array()); + + $model->Article->deleteAll(true); + $this->assertEqual($model->Article->find('all'), array()); + + $this->assertTrue($model->saveAll(array( + 'Comment' => array( + 'comment' => 'Article comment', + 'article_id' => 1, + 'user_id' => 1 + ), + 'Article' => array( + 'title' => 'Model Associations 101', + 'user_id' => 1 + )))); + $result = $model->find('all', array('fields' => array( + 'Comment.id', 'Comment.comment', 'Comment.article_id', 'Article.id', 'Article.title' + ))); + $expected = array(array( + 'Comment' => array( + 'id' => '1', + 'article_id' => '1', + 'comment' => 'Article comment' + ), + 'Article' => array( + 'id' => '1', + 'title' => 'Model Associations 101' + ))); + $this->assertEqual($result, $expected); + } +/** + * testSaveAllHasOneValidation method + * + * @access public + * @return void + */ + function testSaveAllHasOneValidation() { + $model = new Comment(); + $model->deleteAll(true); + $this->assertEqual($model->find('all'), array()); + + $model->Attachment->deleteAll(true); + $this->assertEqual($model->Attachment->find('all'), array()); + + $model->validate = array('comment' => 'notEmpty'); + $model->Attachment->validate = array('attachment' => 'notEmpty'); + $model->Attachment->bind('Comment'); + + $this->assertFalse($model->saveAll( + array( + 'Comment' => array( + 'comment' => '', + 'article_id' => 1, + 'user_id' => 1 + ), + 'Attachment' => array('attachment' => '') + ), + array('validate' => 'first') + )); + $expected = array( + 'Comment' => array('comment' => 'This field cannot be left blank'), + 'Attachment' => array('attachment' => 'This field cannot be left blank') + ); + $this->assertEqual($model->validationErrors, $expected['Comment']); + $this->assertEqual($model->Attachment->validationErrors, $expected['Attachment']); + + $this->assertFalse($model->saveAll( + array( + 'Comment' => array('comment' => '', 'article_id' => 1, 'user_id' => 1), + 'Attachment' => array('attachment' => '') + ), + array('validate' => 'only') + )); + $this->assertEqual($model->validationErrors, $expected['Comment']); + $this->assertEqual($model->Attachment->validationErrors, $expected['Attachment']); + } +/** + * testSaveAllAtomic method + * + * @access public + * @return void + */ + function testSaveAllAtomic() { + $this->loadFixtures('Article', 'User'); + $TestModel =& new Article(); + + $result = $TestModel->saveAll(array( + 'Article' => array( + 'title' => 'Post with Author', + 'body' => 'This post will be saved with an author', + 'user_id' => 2 + ), + 'Comment' => array( + array('comment' => 'First new comment', 'user_id' => 2)) + ), array('atomic' => false)); + + $this->assertIdentical($result, array('Article' => true, 'Comment' => array(true))); + + $result = $TestModel->saveAll(array( + array( + 'id' => '1', + 'title' => 'Baleeted First Post', + 'body' => 'Baleeted!', + 'published' => 'N' + ), + array( + 'id' => '2', + 'title' => 'Just update the title' + ), + array( + 'title' => 'Creating a fourth post', + 'body' => 'Fourth post body', + 'user_id' => 2 + ) + ), array('atomic' => false)); + $this->assertIdentical($result, array(true, true, true)); + + $TestModel->validate = array('title' => 'notEmpty', 'author_id' => 'numeric'); + $result = $TestModel->saveAll(array( + array( + 'id' => '1', + 'title' => 'Un-Baleeted First Post', + 'body' => 'Not Baleeted!', + 'published' => 'Y' + ), + array( + 'id' => '2', + 'title' => '', + 'body' => 'Trying to get away with an empty title' + ) + ), array('atomic' => false)); + $this->assertIdentical($result, array(true, false)); + + $result = $TestModel->saveAll(array( + 'Article' => array('id' => 2), + 'Comment' => array( + array( + 'comment' => 'First new comment', + 'published' => 'Y', + 'user_id' => 1 + ), + array( + 'comment' => 'Second new comment', + 'published' => 'Y', + 'user_id' => 2 + )) + ), array('atomic' => false)); + $this->assertIdentical($result, array('Article' => true, 'Comment' => array(true, true))); + } +/** + * testSaveAllHasMany method + * + * @access public + * @return void + */ + function testSaveAllHasMany() { + $this->loadFixtures('Article', 'Comment'); + $TestModel =& new Article(); + $TestModel->belongsTo = $TestModel->hasAndBelongsToMany = array(); + + $result = $TestModel->saveAll(array( + 'Article' => array('id' => 2), + 'Comment' => array( + array('comment' => 'First new comment', 'published' => 'Y', 'user_id' => 1), + array('comment' => 'Second new comment', 'published' => 'Y', 'user_id' => 2) + ) + )); + $this->assertTrue($result); + + $result = $TestModel->findById(2); + $expected = array( + 'First Comment for Second Article', + 'Second Comment for Second Article', + 'First new comment', + 'Second new comment' + ); + $this->assertEqual(Set::extract($result['Comment'], '{n}.comment'), $expected); + + $result = $TestModel->saveAll( + array( + 'Article' => array('id' => 2), + 'Comment' => array( + array( + 'comment' => 'Third new comment', + 'published' => 'Y', + 'user_id' => 1 + ))), + array('atomic' => false) + ); + $this->assertTrue($result); + + $result = $TestModel->findById(2); + $expected = array( + 'First Comment for Second Article', + 'Second Comment for Second Article', + 'First new comment', + 'Second new comment', + 'Third new comment' + ); + $this->assertEqual(Set::extract($result['Comment'], '{n}.comment'), $expected); + + $TestModel->beforeSaveReturn = false; + $result = $TestModel->saveAll( + array( + 'Article' => array('id' => 2), + 'Comment' => array( + array( + 'comment' => 'Fourth new comment', + 'published' => 'Y', + 'user_id' => 1 + ))), + array('atomic' => false) + ); + $this->assertEqual($result, array('Article' => false)); + + $result = $TestModel->findById(2); + $expected = array( + 'First Comment for Second Article', + 'Second Comment for Second Article', + 'First new comment', + 'Second new comment', + 'Third new comment' + ); + $this->assertEqual(Set::extract($result['Comment'], '{n}.comment'), $expected); + } +/** + * testSaveAllHasManyValidation method + * + * @access public + * @return void + */ + function testSaveAllHasManyValidation() { + $this->loadFixtures('Article', 'Comment'); + $TestModel =& new Article(); + $TestModel->belongsTo = $TestModel->hasAndBelongsToMany = array(); + $TestModel->Comment->validate = array('comment' => 'notEmpty'); + + $result = $TestModel->saveAll(array( + 'Article' => array('id' => 2), + 'Comment' => array( + array('comment' => '', 'published' => 'Y', 'user_id' => 1), + ) + )); + $expected = array('Comment' => array(false)); + $this->assertEqual($result, $expected); + + $expected = array('Comment' => array( + array('comment' => 'This field cannot be left blank') + )); + $this->assertEqual($TestModel->validationErrors, $expected); + $expected = array( + array('comment' => 'This field cannot be left blank') + ); + $this->assertEqual($TestModel->Comment->validationErrors, $expected); + + $result = $TestModel->saveAll(array( + 'Article' => array('id' => 2), + 'Comment' => array( + array( + 'comment' => '', + 'published' => 'Y', + 'user_id' => 1 + )) + ), array('validate' => 'only')); + } +/** + * testSaveAllTransaction method + * + * @access public + * @return void + */ + function testSaveAllTransaction() { + $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment'); + $TestModel =& new Post(); + + $TestModel->validate = array('title' => 'notEmpty'); + $data = array( + array('author_id' => 1, 'title' => 'New Fourth Post'), + array('author_id' => 1, 'title' => 'New Fifth Post'), + array('author_id' => 1, 'title' => '') + ); + $ts = date('Y-m-d H:i:s'); + $this->assertFalse($TestModel->saveAll($data)); + + $result = $TestModel->find('all', array('recursive' => -1)); + $expected = array( + array('Post' => array( + 'id' => '1', + 'author_id' => 1, + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + )), + array('Post' => array( + 'id' => '2', + 'author_id' => 3, + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + )), + array('Post' => array( + 'id' => '3', + 'author_id' => 1, + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' ))); - $this->assertTrue(is_array($result)); + if (count($result) != 3) { + // Database doesn't support transactions + $expected[] = array( + 'Post' => array( + 'id' => '4', + 'author_id' => 1, + 'title' => 'New Fourth Post', + 'body' => null, + 'published' => 'N', + 'created' => $ts, + 'updated' => $ts + )); + + $expected[] = array( + 'Post' => array( + 'id' => '5', + 'author_id' => 1, + 'title' => 'New Fifth Post', + 'body' => null, + 'published' => 'N', + 'created' => $ts, + 'updated' => $ts + )); + + $this->assertEqual($result, $expected); + // Skip the rest of the transactional tests + return; + } + $this->assertEqual($result, $expected); + + $data = array( + array('author_id' => 1, 'title' => 'New Fourth Post'), + array('author_id' => 1, 'title' => ''), + array('author_id' => 1, 'title' => 'New Sixth Post') + ); + $ts = date('Y-m-d H:i:s'); + $this->assertFalse($TestModel->saveAll($data)); + + $result = $TestModel->find('all', array('recursive' => -1)); + $expected = array( + array('Post' => array( + 'id' => '1', + 'author_id' => 1, + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => '2007-03-18 10:41:31' + )), + array('Post' => array( + 'id' => '2', + 'author_id' => 3, + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => '2007-03-18 10:43:31' + )), + array('Post' => array( + 'id' => '3', + 'author_id' => 1, + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + ))); + + if (count($result) != 3) { + // Database doesn't support transactions + $expected[] = array( + 'Post' => array( + 'id' => '4', + 'author_id' => 1, + 'title' => 'New Fourth Post', + 'body' => 'Third Post Body', + 'published' => 'N', + 'created' => $ts, + 'updated' => $ts + )); + + $expected[] = array( + 'Post' => array( + 'id' => '5', + 'author_id' => 1, + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'N', + 'created' => $ts, + 'updated' => $ts + )); + } + $this->assertEqual($result, $expected); + + $TestModel->validate = array('title' => 'notEmpty'); + $data = array( + array('author_id' => 1, 'title' => 'New Fourth Post'), + array('author_id' => 1, 'title' => 'New Fifth Post'), + array('author_id' => 1, 'title' => 'New Sixth Post') + ); + $this->assertTrue($TestModel->saveAll($data)); + + $result = $TestModel->find('all', array( + 'recursive' => -1, + 'fields' => array('author_id', 'title','body','published') + )); + + $expected = array( + array('Post' => array( + 'author_id' => 1, + 'title' => 'First Post', + 'body' => 'First Post Body', + 'published' => 'Y' + )), + array('Post' => array( + 'author_id' => 3, + 'title' => 'Second Post', + 'body' => 'Second Post Body', + 'published' => 'Y' + )), + array('Post' => array( + 'author_id' => 1, + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y' + )), + array('Post' => array( + 'author_id' => 1, + 'title' => 'New Fourth Post', + 'body' => '', + 'published' => 'N' + )), + array('Post' => array( + 'author_id' => 1, + 'title' => 'New Fifth Post', + 'body' => '', + 'published' => 'N' + )), + array('Post' => array( + 'author_id' => 1, + 'title' => 'New Sixth Post', + 'body' => '', + 'published' => 'N' + ))); + $this->assertEqual($result, $expected); + } + +/** + * testSaveAllValidation method + * + * @access public + * @return void + */ + function testSaveAllValidation() { + $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment'); + $TestModel =& new Post(); + + $data = array( + array( + 'id' => '1', + 'title' => 'Baleeted First Post', + 'body' => 'Baleeted!', + 'published' => 'N' + ), + array( + 'id' => '2', + 'title' => 'Just update the title' + ), + array( + 'title' => 'Creating a fourth post', + 'body' => 'Fourth post body', + 'author_id' => 2 + )); + + $this->assertTrue($TestModel->saveAll($data)); + + $result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC')); + $ts = date('Y-m-d H:i:s'); + $expected = array( + array( + 'Post' => array( + 'id' => '1', + 'author_id' => '1', + 'title' => 'Baleeted First Post', + 'body' => 'Baleeted!', + 'published' => 'N', + 'created' => '2007-03-18 10:39:23', + 'updated' => $ts + )), + array( + 'Post' => array( + 'id' => '2', + 'author_id' => '3', + 'title' => 'Just update the title', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', 'updated' => $ts + )), + array( + 'Post' => array( + 'id' => '3', + 'author_id' => '1', + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + )), + array( + 'Post' => array( + 'id' => '4', + 'author_id' => '2', + 'title' => 'Creating a fourth post', + 'body' => 'Fourth post body', + 'published' => 'N', + 'created' => $ts, + 'updated' => $ts + ))); + $this->assertEqual($result, $expected); + + $TestModel->validate = array('title' => 'notEmpty', 'author_id' => 'numeric'); + $data = array( + array( + 'id' => '1', + 'title' => 'Un-Baleeted First Post', + 'body' => 'Not Baleeted!', + 'published' => 'Y' + ), + array( + 'id' => '2', + 'title' => '', + 'body' => 'Trying to get away with an empty title' + )); + $result = $TestModel->saveAll($data); + $this->assertEqual($result, false); + + $result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC')); + $errors = array(1 => array('title' => 'This field cannot be left blank')); + $transactionWorked = Set::matches('/Post[1][title=Baleeted First Post]', $result); + if (!$transactionWorked) { + $this->assertTrue(Set::matches('/Post[1][title=Un-Baleeted First Post]', $result)); + $this->assertTrue(Set::matches('/Post[2][title=Just update the title]', $result)); + } + + $this->assertEqual($TestModel->validationErrors, $errors); + + $TestModel->validate = array('title' => 'notEmpty', 'author_id' => 'numeric'); + $data = array( + array( + 'id' => '1', + 'title' => 'Un-Baleeted First Post', + 'body' => 'Not Baleeted!', + 'published' => 'Y' + ), + array( + 'id' => '2', + 'title' => '', + 'body' => 'Trying to get away with an empty title' + )); + $result = $TestModel->saveAll($data, array('atomic' => false)); + $this->assertEqual($result, array(true, false)); + $result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC')); + $errors = array(1 => array('title' => 'This field cannot be left blank')); + $newTs = date('Y-m-d H:i:s'); + $expected = array( + array( + 'Post' => array( + 'id' => '1', + 'author_id' => '1', + 'title' => 'Un-Baleeted First Post', + 'body' => 'Not Baleeted!', + 'published' => 'Y', + 'created' => '2007-03-18 10:39:23', + 'updated' => $newTs + )), + array( + 'Post' => array( + 'id' => '2', + 'author_id' => '3', + 'title' => 'Just update the title', + 'body' => 'Second Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:41:23', + 'updated' => $ts + )), + array( + 'Post' => array( + 'id' => '3', + 'author_id' => '1', + 'title' => 'Third Post', + 'body' => 'Third Post Body', + 'published' => 'Y', + 'created' => '2007-03-18 10:43:23', + 'updated' => '2007-03-18 10:45:31' + )), + array( + 'Post' => array( + 'id' => '4', + 'author_id' => '2', + 'title' => 'Creating a fourth post', + 'body' => 'Fourth post body', + 'published' => 'N', + 'created' => $ts, + 'updated' => $ts + ))); + $this->assertEqual($result, $expected); + $this->assertEqual($TestModel->validationErrors, $errors); + + $data = array( + array( + 'id' => '1', + 'title' => 'Re-Baleeted First Post', + 'body' => 'Baleeted!', + 'published' => 'N' + ), + array( + 'id' => '2', + 'title' => '', + 'body' => 'Trying to get away with an empty title' + )); + $this->assertFalse($TestModel->saveAll($data, array('validate' => 'first'))); + + $result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC')); + $this->assertEqual($result, $expected); + $this->assertEqual($TestModel->validationErrors, $errors); + + $data = array( + array( + 'title' => 'First new post', + 'body' => 'Woohoo!', + 'published' => 'Y' + ), + array( + 'title' => 'Empty body', + 'body' => '' + )); + + $TestModel->validate['body'] = 'notEmpty'; + } +/** + * testSaveAllValidationOnly method + * + * @access public + * @return void + */ + function testSaveAllValidationOnly() { + $TestModel =& new Comment(); + $TestModel->Attachment->validate = array('attachment' => 'notEmpty'); + + $data = array( + 'Comment' => array( + 'comment' => 'This is the comment' + ), + 'Attachment' => array( + 'attachment' => '' + ) + ); + + $result = $TestModel->saveAll($data, array('validate' => 'only')); + $this->assertFalse($result); + + $TestModel =& new Article(); + $TestModel->validate = array('title' => 'notEmpty'); + $result = $TestModel->saveAll( + array( + 0 => array('title' => ''), + 1 => array('title' => 'title 1'), + 2 => array('title' => 'title 2'), + ), + array('validate'=>'only') + ); + $this->assertFalse($result); + $expected = array( + 0 => array('title' => 'This field cannot be left blank'), + ); + $this->assertEqual($TestModel->validationErrors, $expected); + + $result = $TestModel->saveAll( + array( + 0 => array('title' => 'title 0'), + 1 => array('title' => ''), + 2 => array('title' => 'title 2'), + ), + array('validate'=>'only') + ); + $this->assertFalse($result); + $expected = array( + 1 => array('title' => 'This field cannot be left blank'), + ); + $this->assertEqual($TestModel->validationErrors, $expected); + } +/** + * testSaveAllValidateFirst method + * + * @access public + * @return void + */ + function testSaveAllValidateFirst() { + $model =& new Article(); + $model->deleteAll(true); + + $model->Comment->validate = array('comment' => 'notEmpty'); + $result = $model->saveAll(array( + 'Article' => array( + 'title' => 'Post with Author', + 'body' => 'This post will be saved author' + ), + 'Comment' => array( + array('comment' => 'First new comment'), + array('comment' => '') + ) + ), array('validate' => 'first')); + + $this->assertFalse($result); + + $result = $model->find('all'); + $this->assertEqual($result, array()); + $expected = array('Comment' => array( + 1 => array('comment' => 'This field cannot be left blank') + )); + + $this->assertEqual($model->Comment->validationErrors, $expected['Comment']); + + $this->assertIdentical($model->Comment->find('count'), 0); + + $result = $model->saveAll( + array( + 'Article' => array( + 'title' => 'Post with Author', + 'body' => 'This post will be saved with an author', + 'user_id' => 2 + ), + 'Comment' => array( + array( + 'comment' => 'Only new comment', + 'user_id' => 2 + ))), + array('validate' => 'first') + ); + + $this->assertIdentical($result, true); + + $result = $model->Comment->find('all'); + $this->assertIdentical(count($result), 1); + $result = Set::extract('/Comment/article_id', $result); + $this->assertTrue($result[0] === 1 || $result[0] === '1'); + + + $model->deleteAll(true); + $data = array( + 'Article' => array( + 'title' => 'Post with Author saveAlled from comment', + 'body' => 'This post will be saved with an author', + 'user_id' => 2 + ), + 'Comment' => array( + 'comment' => 'Only new comment', 'user_id' => 2 + )); + + $result = $model->Comment->saveAll($data, array('validate' => 'first')); + $this->assertTrue($result); + + $result = $model->find('all'); + $this->assertEqual( + $result[0]['Article']['title'], + 'Post with Author saveAlled from comment' + ); + $this->assertEqual($result[0]['Comment'][0]['comment'], 'Only new comment'); + } +/** + * testUpdateWithCalculation method + * + * @access public + * @return void + */ + function testUpdateWithCalculation() { + $this->loadFixtures('DataTest'); + $model =& new DataTest(); + $result = $model->saveAll(array( + array('count' => 5, 'float' => 1.1), + array('count' => 3, 'float' => 1.2), + array('count' => 4, 'float' => 1.3), + array('count' => 1, 'float' => 2.0), + )); + $this->assertTrue($result); + + $result = Set::extract('/DataTest/count', $model->find('all', array('fields' => 'count'))); + $this->assertEqual($result, array(5, 3, 4, 1)); + + $this->assertTrue($model->updateAll(array('count' => 'count + 2'))); + $result = Set::extract('/DataTest/count', $model->find('all', array('fields' => 'count'))); + $this->assertEqual($result, array(7, 5, 6, 3)); + + $this->assertTrue($model->updateAll(array('DataTest.count' => 'DataTest.count - 1'))); + $result = Set::extract('/DataTest/count', $model->find('all', array('fields' => 'count'))); + $this->assertEqual($result, array(6, 4, 5, 2)); } /** * testSaveAllHasManyValidationOnly method @@ -12792,107 +12854,10 @@ class ModelTest extends CakeTestCase { ); $this->assertEqual($TestModel->Comment->validationErrors, $expected); } -/** - * testPkInHabtmLinkModel method - * - * @access public - * @return void - */ - function testPkInHabtmLinkModel() { - //Test Nonconformant Models - $this->loadFixtures('Content', 'ContentAccount', 'Account'); - $TestModel =& new Content(); - $this->assertEqual($TestModel->ContentAccount->primaryKey, 'iContentAccountsId'); - //test conformant models with no PK in the join table - $this->loadFixtures('Article', 'Tag'); - $TestModel2 =& new Article(); - $this->assertEqual($TestModel2->ArticlesTag->primaryKey, 'article_id'); +} - //test conformant models with PK in join table - $this->loadFixtures('Item', 'Portfolio', 'ItemsPortfolio'); - $TestModel3 =& new Portfolio(); - $this->assertEqual($TestModel3->ItemsPortfolio->primaryKey, 'id'); - - //test conformant models with PK in join table - join table contains extra field - $this->loadFixtures('JoinA', 'JoinB', 'JoinAB'); - $TestModel4 =& new JoinA(); - $this->assertEqual($TestModel4->JoinAsJoinB->primaryKey, 'id'); - - } -/** - * testInsertAnotherHabtmRecordWithSameForeignKey method - * - * @access public - * @return void - */ - function testInsertAnotherHabtmRecordWithSameForeignKey() { - $this->loadFixtures('JoinA', 'JoinB', 'JoinAB'); - $TestModel = new JoinA(); - - $result = $TestModel->JoinAsJoinB->findById(1); - $expected = array( - 'JoinAsJoinB' => array( - 'id' => 1, - 'join_a_id' => 1, - 'join_b_id' => 2, - 'other' => 'Data for Join A 1 Join B 2', - 'created' => '2008-01-03 10:56:33', - 'updated' => '2008-01-03 10:56:33' - )); - $this->assertEqual($result, $expected); - - $TestModel->JoinAsJoinB->create(); - $result = $TestModel->JoinAsJoinB->save(array( - 'join_a_id' => 1, - 'join_b_id' => 1, - 'other' => 'Data for Join A 1 Join B 1', - 'created' => '2008-01-03 10:56:44', - 'updated' => '2008-01-03 10:56:44' - )); - $this->assertTrue($result); - $lastInsertId = $TestModel->JoinAsJoinB->getLastInsertID(); - $this->assertTrue($lastInsertId != null); - - $result = $TestModel->JoinAsJoinB->findById(1); - $expected = array( - 'JoinAsJoinB' => array( - 'id' => 1, - 'join_a_id' => 1, - 'join_b_id' => 2, - 'other' => 'Data for Join A 1 Join B 2', - 'created' => '2008-01-03 10:56:33', - 'updated' => '2008-01-03 10:56:33' - )); - $this->assertEqual($result, $expected); - - $updatedValue = 'UPDATED Data for Join A 1 Join B 2'; - $TestModel->JoinAsJoinB->id = 1; - $result = $TestModel->JoinAsJoinB->saveField('other', $updatedValue, false); - $this->assertTrue($result); - - $result = $TestModel->JoinAsJoinB->findById(1); - $this->assertEqual($result['JoinAsJoinB']['other'], $updatedValue); - } -/** - * Tests that $cacheSources can only be disabled in the db using model settings, not enabled - * - * @access public - * @return void - */ - function testCacheSourcesDisabling() { - $this->db->cacheSources = true; - $TestModel = new JoinA(); - $TestModel->cacheSources = false; - $TestModel->setSource('join_as'); - $this->assertFalse($this->db->cacheSources); - - $this->db->cacheSources = false; - $TestModel = new JoinA(); - $TestModel->cacheSources = true; - $TestModel->setSource('join_as'); - $this->assertFalse($this->db->cacheSources); - } +class ModelDeleteTest extends BaseModelTest { /** * testDeleteHabtmReferenceWithConditions method * @@ -13012,52 +12977,511 @@ class ModelTest extends CakeTestCase { $this->assertEqual($result, $expected); } /** - * testPkInHAbtmLinkModelArticleB + * testDeleteDependentWithConditions method * * @access public * @return void */ - function testPkInHabtmLinkModelArticleB() { - $this->loadFixtures('Article', 'Tag'); - $TestModel2 =& new ArticleB(); - $this->assertEqual($TestModel2->ArticlesTag->primaryKey, 'article_id'); + function testDeleteDependentWithConditions() { + $this->loadFixtures('Cd','Book','OverallFavorite'); + + $Cd =& new Cd(); + $OverallFavorite =& new OverallFavorite(); + + $Cd->del(1); + + $result = $OverallFavorite->find('all', array( + 'fields' => array('model_type', 'model_id', 'priority') + )); + $expected = array( + array( + 'OverallFavorite' => array( + 'model_type' => 'Book', + 'model_id' => 1, + 'priority' => 2 + ))); + + $this->assertTrue(is_array($result)); + $this->assertEqual($result, $expected); } /** - * testFetchingNonUniqueFKJoinTableRecords() - * - * Tests if the results are properly returned in the case there are non-unique FK's - * in the join table but another fields value is different. For example: - * something_id | something_else_id | doomed = 1 - * something_id | something_else_id | doomed = 0 - * Should return both records and not just one. + * testDel method * * @access public * @return void */ - function testFetchingNonUniqueFKJoinTableRecords() { - $this->loadFixtures('Something', 'SomethingElse', 'JoinThing'); - $Something = new Something(); + function testDel() { + $this->loadFixtures('Article'); + $TestModel =& new Article(); - $joinThingData = array( - 'JoinThing' => array( - 'something_id' => 1, - 'something_else_id' => 2, - 'doomed' => '0', - 'created' => '2007-03-18 10:39:23', - 'updated' => '2007-03-18 10:41:31' - ) - ); - $Something->JoinThing->create($joinThingData); - $Something->JoinThing->save(); + $result = $TestModel->del(2); + $this->assertTrue($result); - $result = $Something->JoinThing->find('all', array('conditions' => array('something_else_id' => 2))); - $this->assertEqual($result[0]['JoinThing']['doomed'], 1); - $this->assertEqual($result[1]['JoinThing']['doomed'], 0); + $result = $TestModel->read(null, 2); + $this->assertFalse($result); - $result = $Something->find('first'); - $this->assertEqual(count($result['SomethingElse']), 2); - $this->assertEqual($result['SomethingElse'][0]['JoinThing']['doomed'], 1); - $this->assertEqual($result['SomethingElse'][1]['JoinThing']['doomed'], 0); + $TestModel->recursive = -1; + $result = $TestModel->find('all', array( + 'fields' => array('id', 'title') + )); + $expected = array( + array('Article' => array( + 'id' => 1, + 'title' => 'First Article' + )), + array('Article' => array( + 'id' => 3, + 'title' => 'Third Article' + ))); + $this->assertEqual($result, $expected); + + $result = $TestModel->del(3); + $this->assertTrue($result); + + $result = $TestModel->read(null, 3); + $this->assertFalse($result); + + $TestModel->recursive = -1; + $result = $TestModel->find('all', array( + 'fields' => array('id', 'title') + )); + $expected = array( + array('Article' => array( + 'id' => 1, + 'title' => 'First Article' + ))); + + $this->assertEqual($result, $expected); + + + // make sure deleting a non-existent record doesn't break save() + // ticket #6293 + $this->loadFixtures('Uuid'); + $Uuid =& new Uuid(); + $data = array( + 'B607DAB9-88A2-46CF-B57C-842CA9E3B3B3', + '52C8865C-10EE-4302-AE6C-6E7D8E12E2C8', + '8208C7FE-E89C-47C5-B378-DED6C271F9B8'); + foreach ($data as $id) { + $Uuid->save(array('id' => $id)); + } + $Uuid->del('52C8865C-10EE-4302-AE6C-6E7D8E12E2C8'); + $Uuid->del('52C8865C-10EE-4302-AE6C-6E7D8E12E2C8'); + foreach ($data as $id) { + $Uuid->save(array('id' => $id)); + } + $result = $Uuid->find('all', array( + 'conditions' => array('id' => $data), + 'fields' => array('id'), + 'order' => 'id')); + $expected = array( + array('Uuid' => array( + 'id' => '52C8865C-10EE-4302-AE6C-6E7D8E12E2C8')), + array('Uuid' => array( + 'id' => '8208C7FE-E89C-47C5-B378-DED6C271F9B8')), + array('Uuid' => array( + 'id' => 'B607DAB9-88A2-46CF-B57C-842CA9E3B3B3'))); + $this->assertEqual($result, $expected); } +/** + * testDeleteAll method + * + * @access public + * @return void + */ + function testDeleteAll() { + $this->loadFixtures('Article'); + $TestModel =& new Article(); + + $data = array('Article' => array( + 'user_id' => 2, + 'id' => 4, + 'title' => 'Fourth Article', + 'published' => 'N' + )); + $result = $TestModel->set($data) && $TestModel->save(); + $this->assertTrue($result); + + $data = array('Article' => array( + 'user_id' => 2, + 'id' => 5, + 'title' => 'Fifth Article', + 'published' => 'Y' + )); + $result = $TestModel->set($data) && $TestModel->save(); + $this->assertTrue($result); + + $data = array('Article' => array( + 'user_id' => 1, + 'id' => 6, + 'title' => 'Sixth Article', + 'published' => 'N' + )); + $result = $TestModel->set($data) && $TestModel->save(); + $this->assertTrue($result); + + $TestModel->recursive = -1; + $result = $TestModel->find('all', array( + 'fields' => array('id', 'user_id', 'title', 'published') + )); + + $expected = array( + array('Article' => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'published' => 'Y' + )), + array('Article' => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'published' => 'Y' + )), + array('Article' => array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'published' => 'Y')), + array('Article' => array( + 'id' => 4, + 'user_id' => 2, + 'title' => 'Fourth Article', + 'published' => 'N' + )), + array('Article' => array( + 'id' => 5, + 'user_id' => 2, + 'title' => 'Fifth Article', + 'published' => 'Y' + )), + array('Article' => array( + 'id' => 6, + 'user_id' => 1, + 'title' => 'Sixth Article', + 'published' => 'N' + ))); + + $this->assertEqual($result, $expected); + + $result = $TestModel->deleteAll(array('Article.published' => 'N')); + $this->assertTrue($result); + + $TestModel->recursive = -1; + $result = $TestModel->find('all', array( + 'fields' => array('id', 'user_id', 'title', 'published') + )); + $expected = array( + array('Article' => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'published' => 'Y' + )), + array('Article' => array( + 'id' => 2, + 'user_id' => 3, + 'title' => 'Second Article', + 'published' => 'Y' + )), + array('Article' => array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'published' => 'Y' + )), + array('Article' => array( + 'id' => 5, + 'user_id' => 2, + 'title' => 'Fifth Article', + 'published' => 'Y' + ))); + $this->assertEqual($result, $expected); + + $data = array('Article.user_id' => array(2, 3)); + $result = $TestModel->deleteAll($data, true, true); + $this->assertTrue($result); + + $TestModel->recursive = -1; + $result = $TestModel->find('all', array( + 'fields' => array('id', 'user_id', 'title', 'published') + )); + $expected = array( + array('Article' => array( + 'id' => 1, + 'user_id' => 1, + 'title' => 'First Article', + 'published' => 'Y' + )), + array('Article' => array( + 'id' => 3, + 'user_id' => 1, + 'title' => 'Third Article', + 'published' => 'Y' + ))); + $this->assertEqual($result, $expected); + + $result = $TestModel->deleteAll(array('Article.user_id' => 999)); + $this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s'); + } +/** + * testRecursiveDel method + * + * @access public + * @return void + */ + function testRecursiveDel() { + $this->loadFixtures('Article', 'Comment', 'Attachment'); + $TestModel =& new Article(); + + $result = $TestModel->del(2); + $this->assertTrue($result); + + $TestModel->recursive = 2; + $result = $TestModel->read(null, 2); + $this->assertFalse($result); + + $result = $TestModel->Comment->read(null, 5); + $this->assertFalse($result); + + $result = $TestModel->Comment->read(null, 6); + $this->assertFalse($result); + + $result = $TestModel->Comment->Attachment->read(null, 1); + $this->assertFalse($result); + + $result = $TestModel->find('count'); + $this->assertEqual($result, 2); + + $result = $TestModel->Comment->find('count'); + $this->assertEqual($result, 4); + + $result = $TestModel->Comment->Attachment->find('count'); + $this->assertEqual($result, 0); + } +/** + * testDependentExclusiveDelete method + * + * @access public + * @return void + */ + function testDependentExclusiveDelete() { + $this->loadFixtures('Article', 'Comment'); + $TestModel =& new Article10(); + + $result = $TestModel->find('all'); + $this->assertEqual(count($result[0]['Comment']), 4); + $this->assertEqual(count($result[1]['Comment']), 2); + $this->assertEqual($TestModel->Comment->find('count'), 6); + + $TestModel->delete(1); + $this->assertEqual($TestModel->Comment->find('count'), 2); + } +/** + * testDeleteLinks method + * + * @access public + * @return void + */ + function testDeleteLinks() { + $this->loadFixtures('Article', 'ArticlesTag', 'Tag'); + $TestModel =& new Article(); + + $result = $TestModel->ArticlesTag->find('all'); + $expected = array( + array('ArticlesTag' => array( + 'article_id' => '1', + 'tag_id' => '1' + )), + array('ArticlesTag' => array( + 'article_id' => '1', + 'tag_id' => '2' + )), + array('ArticlesTag' => array( + 'article_id' => '2', + 'tag_id' => '1' + )), + array('ArticlesTag' => array( + 'article_id' => '2', + 'tag_id' => '3' + ))); + $this->assertEqual($result, $expected); + + $TestModel->delete(1); + $result = $TestModel->ArticlesTag->find('all'); + + $expected = array( + array('ArticlesTag' => array( + 'article_id' => '2', + 'tag_id' => '1' + )), + array('ArticlesTag' => array( + 'article_id' => '2', + 'tag_id' => '3' + ))); + $this->assertEqual($result, $expected); + + $result = $TestModel->deleteAll(array('Article.user_id' => 999)); + $this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s'); + } +/** + * testHabtmDeleteLinksWhenNoPrimaryKeyInJoinTable method + * + * @access public + * @return void + */ + function testHabtmDeleteLinksWhenNoPrimaryKeyInJoinTable() { + + $this->loadFixtures('Apple', 'Device', 'ThePaperMonkies'); + $ThePaper =& new ThePaper(); + $ThePaper->id = 1; + $ThePaper->save(array('Monkey' => array(2, 3))); + + $result = $ThePaper->findById(1); + $expected = array( + array( + 'id' => '2', + 'device_type_id' => '1', + 'name' => 'Device 2', + 'typ' => '1' + ), + array( + 'id' => '3', + 'device_type_id' => '1', + 'name' => 'Device 3', + 'typ' => '2' + )); + $this->assertEqual($result['Monkey'], $expected); + + $ThePaper =& new ThePaper(); + $ThePaper->id = 2; + $ThePaper->save(array('Monkey' => array(2, 3))); + + $result = $ThePaper->findById(2); + $expected = array( + array( + 'id' => '2', + 'device_type_id' => '1', + 'name' => 'Device 2', + 'typ' => '1' + ), + array( + 'id' => '3', + 'device_type_id' => '1', + 'name' => 'Device 3', + 'typ' => '2' + )); + $this->assertEqual($result['Monkey'], $expected); + + $ThePaper->delete(1); + $result = $ThePaper->findById(2); + $expected = array( + array( + 'id' => '2', + 'device_type_id' => '1', + 'name' => 'Device 2', + 'typ' => '1' + ), + array( + 'id' => '3', + 'device_type_id' => '1', + 'name' => 'Device 3', + 'typ' => '2' + )); + $this->assertEqual($result['Monkey'], $expected); + } + +} + +class ModelValidationTest extends BaseModelTest { +/** + * Tests validation parameter order in custom validation methods + * + * @access public + * @return void + */ + function testValidationParams() { + $TestModel =& new ValidationTest1(); + $TestModel->validate['title'] = array( + 'rule' => 'customValidatorWithParams', + 'required' => true + ); + $TestModel->create(array('title' => 'foo')); + $TestModel->invalidFields(); + + $expected = array( + 'data' => array( + 'title' => 'foo' + ), + 'validator' => array( + 'rule' => 'customValidatorWithParams', + 'on' => null, + 'last' => false, + 'allowEmpty' => false, + 'required' => true + ), + 'or' => true, + 'ignore_on_same' => 'id' + ); + $this->assertEqual($TestModel->validatorParams, $expected); + + $TestModel->validate['title'] = array( + 'rule' => 'customValidatorWithMessage', + 'required' => true + ); + $expected = array( + 'title' => 'This field will *never* validate! Muhahaha!' + ); + + $this->assertEqual($TestModel->invalidFields(), $expected); + } +/** + * Tests validation parameter fieldList in invalidFields + * + * @access public + * @return void + */ + function testInvalidFieldsWithFieldListParams() { + $TestModel =& new ValidationTest1(); + $TestModel->validate = $validate = array( + 'title' => array( + 'rule' => 'customValidator', + 'required' => true + ), + 'name' => array( + 'rule' => 'allowEmpty', + 'required' => true + )); + $TestModel->invalidFields(array('fieldList' => array('title'))); + $expected = array( + 'title' => 'This field cannot be left blank' + ); + $this->assertEqual($TestModel->validationErrors, $expected); + $TestModel->validationErrors = array(); + + $TestModel->invalidFields(array('fieldList' => array('name'))); + $expected = array( + 'name' => 'This field cannot be left blank' + ); + $this->assertEqual($TestModel->validationErrors, $expected); + $TestModel->validationErrors = array(); + + $TestModel->invalidFields(array('fieldList' => array('name', 'title'))); + $expected = array( + 'name' => 'This field cannot be left blank', + 'title' => 'This field cannot be left blank' + ); + $this->assertEqual($TestModel->validationErrors, $expected); + $TestModel->validationErrors = array(); + + $TestModel->whitelist = array('name'); + $TestModel->invalidFields(); + $expected = array('name' => 'This field cannot be left blank'); + $this->assertEqual($TestModel->validationErrors, $expected); + $TestModel->validationErrors = array(); + + $this->assertEqual($TestModel->validate, $validate); + } + } ?> \ No newline at end of file diff --git a/cake/tests/groups/database.group.php b/cake/tests/groups/database.group.php new file mode 100644 index 000000000..2ecf3b64d --- /dev/null +++ b/cake/tests/groups/database.group.php @@ -0,0 +1,56 @@ + + * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) + * + * Licensed under The Open Group Test Suite License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) + * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests + * @package cake + * @subpackage cake.tests.groups + * @since CakePHP(tm) v 1.2.0.5517 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License + */ +/** + * DatabaseGroupTest class + * + * This test group will run all behavior, schema and datasource tests excluding database + * driver-specific tests + * + * @package cake + * @subpackage cake.tests.groups + */ +class DatabaseGroupTest extends GroupTest { +/** + * label property + * + * @var string 'All model tests' + * @access public + */ + var $label = 'Datasources, Schema and DbAcl tests'; +/** + * ModelGroupTest method + * + * @access public + * @return void + */ + function DatabaseGroupTest() { + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'model' . DS . 'db_acl'); + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'model' . DS . 'schema'); + TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'model' . DS . 'datasources' . DS . 'dbo_source'); + } +} +?> \ No newline at end of file diff --git a/cake/tests/groups/model.group.php b/cake/tests/groups/model.group.php index 867b1ba50..6cf32d93a 100644 --- a/cake/tests/groups/model.group.php +++ b/cake/tests/groups/model.group.php @@ -37,10 +37,10 @@ class ModelGroupTest extends GroupTest { /** * label property * - * @var string 'All model tests' + * @var string * @access public */ - var $label = 'Model, all Behaviors and Datasources'; + var $label = 'Model & Behavior tests'; /** * ModelGroupTest method * @@ -49,9 +49,6 @@ class ModelGroupTest extends GroupTest { */ function ModelGroupTest() { TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'model' . DS . 'model'); - TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'model' . DS . 'db_acl'); - TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'model' . DS . 'schema'); - TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'model' . DS . 'datasources' . DS . 'dbo_source'); TestManager::addTestCasesFromDirectory($this, CORE_TEST_CASES . DS . 'libs' . DS . 'model' . DS . 'behaviors'); } } From 68d333d0883428748457e1cca0e5bd937ee0085e Mon Sep 17 00:00:00 2001 From: davidpersson Date: Sat, 4 Jul 2009 22:04:40 +0000 Subject: [PATCH 33/95] Applying patches by ADMad updating HtmlHelper and adding test. Adding missing properties in test case. Preventing bleed through in test case. Fixes #6490 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8220 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/helpers/html.php | 11 ++-- .../cases/libs/view/helpers/html.test.php | 58 ++++++++++++++++--- 2 files changed, 56 insertions(+), 13 deletions(-) diff --git a/cake/libs/view/helpers/html.php b/cake/libs/view/helpers/html.php index ce6ea9302..cb9408998 100644 --- a/cake/libs/view/helpers/html.php +++ b/cake/libs/view/helpers/html.php @@ -316,7 +316,7 @@ class HtmlHelper extends AppHelper { /** * Creates a link element for CSS stylesheets. * - * @param mixed $path The name of a CSS style sheet or an array containing names of + * @param mixed $path The name of a CSS style sheet or an array containing names of * CSS stylesheets. If `$path` is prefixed with '/', the path will be relative to the webroot * of your application. Otherwise, the path will be relative to your CSS path, usually webroot/css. * @param string $rel Rel attribute. Defaults to "stylesheet". If equal to 'import' the stylesheet will be imported. @@ -437,10 +437,11 @@ class HtmlHelper extends AppHelper { } elseif ($path[0] === '/') { $path = $this->webroot($path); } elseif (strpos($path, '://') === false) { - if ((Configure::read('Asset.timestamp') == true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force') { - $path .= '?' . @filemtime(str_replace('/', DS, WWW_ROOT . IMAGES_URL . $path)); - } $path = $this->webroot(IMAGES_URL . $path); + + if ((Configure::read('Asset.timestamp') == true && Configure::read() > 0) || Configure::read('Asset.timestamp') === 'force') { + $path .= '?' . @filemtime(str_replace('/', DS, WWW_ROOT . $path)); + } } if (!isset($options['alt'])) { @@ -639,4 +640,4 @@ class HtmlHelper extends AppHelper { return $out; } } -?> +?> \ No newline at end of file diff --git a/cake/tests/cases/libs/view/helpers/html.test.php b/cake/tests/cases/libs/view/helpers/html.test.php index efdbdafcc..52dd5cbaf 100644 --- a/cake/tests/cases/libs/view/helpers/html.test.php +++ b/cake/tests/cases/libs/view/helpers/html.test.php @@ -56,12 +56,33 @@ class TheHtmlTestController extends Controller { */ class HtmlHelperTest extends CakeTestCase { /** - * html property + * Html property * - * @var mixed null + * @var object * @access public */ - var $html = null; + var $Html = null; +/** + * Backup of app encoding configuration setting + * + * @var string + * @access protected + */ + var $_appEncoding; +/** + * Backup of asset configuration settings + * + * @var string + * @access protected + */ + var $_asset; +/** + * Backup of debug configuration setting + * + * @var integer + * @access protected + */ + var $_debug; /** * setUp method * @@ -73,6 +94,8 @@ class HtmlHelperTest extends CakeTestCase { $view =& new View(new TheHtmlTestController()); ClassRegistry::addObject('view', $view); $this->_appEncoding = Configure::read('App.encoding'); + $this->_asset = Configure::read('Asset'); + $this->_debug = Configure::read('debug'); } /** * tearDown method @@ -82,6 +105,8 @@ class HtmlHelperTest extends CakeTestCase { */ function tearDown() { Configure::write('App.encoding', $this->_appEncoding); + Configure::write('Asset', $this->_asset); + Configure::write('debug', $this->_debug); ClassRegistry::flush(); } /** @@ -254,14 +279,34 @@ class HtmlHelperTest extends CakeTestCase { $result = $this->Html->image('cake.icon.gif'); $this->assertTags($result, array('img' => array('src' => 'preg:/img\/cake\.icon\.gif\?\d+/', 'alt' => ''))); - $back = Configure::read('debug'); Configure::write('debug', 0); Configure::write('Asset.timestamp', 'force'); $result = $this->Html->image('cake.icon.gif'); $this->assertTags($result, array('img' => array('src' => 'preg:/img\/cake\.icon\.gif\?\d+/', 'alt' => ''))); + } +/** + * Tests creation of an image tag using a theme and asset timestamping + * + * @access public + * @return void + * @link https://trac.cakephp.org/ticket/6490 + */ + function testImageTagWithTheme() { + $file = WWW_ROOT . 'themed' . DS . 'default' . DS . 'img' . DS . 'cake.power.gif'; + $message = "File '{$file}' not present. %s"; + $this->skipUnless(file_exists($file), $message); - Configure::write('debug', $back); + Configure::write('Asset.timestamp', true); + Configure::write('debug', 1); + $this->Html->themeWeb = 'themed/default/'; + + $result = $this->Html->image('cake.power.gif'); + $this->assertTags($result, array( + 'img' => array( + 'src' => 'preg:/themed\/default\/img\/cake\.power\.gif\?\d+/', + 'alt' => '' + ))); } /** * testStyle method @@ -331,7 +376,6 @@ class HtmlHelperTest extends CakeTestCase { $expected['link']['href'] = 'preg:/.*css\/cake\.generic\.css\?[0-9]+/'; $this->assertTags($result, $expected); - $debug = Configure::read('debug'); Configure::write('debug', 0); $result = $this->Html->css('cake.generic'); @@ -357,8 +401,6 @@ class HtmlHelperTest extends CakeTestCase { $expected['link']['href'] = 'preg:/\/testing\/longer\/css\/cake\.generic\.css\?/'; $this->assertTags($result, $expected); $this->Html->webroot = $webroot; - - Configure::write('debug', $debug); } /** * testCharsetTag method From 72546f3839bc9c3ccd0c3c29854523a296409360 Mon Sep 17 00:00:00 2001 From: gwoo Date: Sun, 5 Jul 2009 15:02:03 +0000 Subject: [PATCH 34/95] fixes #6455, adding define for LC_MESSAGES git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8221 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/basics.php | 7 +++++++ cake/tests/cases/basics.test.php | 24 ++++++++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/cake/basics.php b/cake/basics.php index bb3f22cb1..56934baee 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -34,6 +34,13 @@ define('WEEK', 7 * DAY); define('MONTH', 30 * DAY); define('YEAR', 365 * DAY); +/** + * Add constant for LC_MESSAGES because it is not defined on windows + */ + if (!defined('LC_MESSAGES')) { + define('LC_MESSAGES', 6); + } + /** * Patch for PHP < 5.0 */ diff --git a/cake/tests/cases/basics.test.php b/cake/tests/cases/basics.test.php index 3526a7ca2..5fb05837b 100644 --- a/cake/tests/cases/basics.test.php +++ b/cake/tests/cases/basics.test.php @@ -388,16 +388,16 @@ class BasicsTest extends CakeTestCase { function test__c() { Configure::write('Config.language', 'rule_1_po'); - $result = __c('Plural Rule 1', 5, true); + $result = __c('Plural Rule 1', LC_MESSAGES, true); $expected = 'Plural Rule 1 (translated)'; $this->assertEqual($result, $expected); - $result = __c('Plural Rule 1 (from core)', 5, true); + $result = __c('Plural Rule 1 (from core)', LC_MESSAGES, true); $expected = 'Plural Rule 1 (from core translated)'; $this->assertEqual($result, $expected); ob_start(); - __c('Plural Rule 1 (from core)', 5); + __c('Plural Rule 1 (from core)', LC_MESSAGES); $result = ob_get_clean(); $expected = 'Plural Rule 1 (from core translated)'; $this->assertEqual($result, $expected); @@ -411,24 +411,24 @@ class BasicsTest extends CakeTestCase { function test__dc() { Configure::write('Config.language', 'rule_1_po'); - $result = __dc('default', 'Plural Rule 1', 5, true); + $result = __dc('default', 'Plural Rule 1', LC_MESSAGES, true); $expected = 'Plural Rule 1 (translated)'; $this->assertEqual($result, $expected); - $result = __dc('default', 'Plural Rule 1 (from core)', 5, true); + $result = __dc('default', 'Plural Rule 1 (from core)', LC_MESSAGES, true); $expected = 'Plural Rule 1 (from core translated)'; $this->assertEqual($result, $expected); - $result = __dc('core', 'Plural Rule 1', 5, true); + $result = __dc('core', 'Plural Rule 1', LC_MESSAGES, true); $expected = 'Plural Rule 1'; $this->assertEqual($result, $expected); - $result = __dc('core', 'Plural Rule 1 (from core)', 5, true); + $result = __dc('core', 'Plural Rule 1 (from core)', LC_MESSAGES, true); $expected = 'Plural Rule 1 (from core translated)'; $this->assertEqual($result, $expected); ob_start(); - __dc('default', 'Plural Rule 1 (from core)', 5); + __dc('default', 'Plural Rule 1 (from core)', LC_MESSAGES); $result = ob_get_clean(); $expected = 'Plural Rule 1 (from core translated)'; $this->assertEqual($result, $expected); @@ -442,20 +442,20 @@ class BasicsTest extends CakeTestCase { function test__dcn() { Configure::write('Config.language', 'rule_1_po'); - $result = __dcn('default', '%d = 1', '%d = 0 or > 1', 0, 5, true); + $result = __dcn('default', '%d = 1', '%d = 0 or > 1', 0, LC_MESSAGES, true); $expected = '%d = 0 or > 1 (translated)'; $this->assertEqual($result, $expected); - $result = __dcn('default', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 1, 5, true); + $result = __dcn('default', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 1, LC_MESSAGES, true); $expected = '%d = 1 (from core translated)'; $this->assertEqual($result, $expected); - $result = __dcn('core', '%d = 1', '%d = 0 or > 1', 0, 5, true); + $result = __dcn('core', '%d = 1', '%d = 0 or > 1', 0, LC_MESSAGES, true); $expected = '%d = 0 or > 1'; $this->assertEqual($result, $expected); ob_start(); - __dcn('default', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 1, 5); + __dcn('default', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 1, LC_MESSAGES); $result = ob_get_clean(); $expected = '%d = 1 (from core translated)'; $this->assertEqual($result, $expected); From bc5de16b6cabc53d56955d16cafe86b45989df83 Mon Sep 17 00:00:00 2001 From: "mariano.iglesias" Date: Mon, 6 Jul 2009 07:38:03 +0000 Subject: [PATCH 35/95] Fixing bug introduced in r5219 that was preventing model save operations from working in Console shell git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8222 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/console/libs/console.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cake/console/libs/console.php b/cake/console/libs/console.php index 9d7f9aa49..19b075092 100644 --- a/cake/console/libs/console.php +++ b/cake/console/libs/console.php @@ -252,8 +252,7 @@ class ConsoleShell extends Shell { if ($this->__isValidModel($modelToSave)) { // Extract the array of data we are trying to build list($foo, $data) = explode("->save", $command); - $badChars = array("(", ")"); - $data = str_replace($badChars, "", $data); + $data = preg_replace('/^\(*(array)?\(*(.+?)\)*$/i', '\\2', $data); $saveCommand = "\$this->{$modelToSave}->save(array('{$modelToSave}' => array({$data})));"; @eval($saveCommand); $this->out('Saved record for ' . $modelToSave); @@ -336,4 +335,4 @@ class ConsoleShell extends Shell { return true; } } -?> \ No newline at end of file +?> From 508f0651a4f1d958a2dac0599cb81af15cbef19f Mon Sep 17 00:00:00 2001 From: gwoo Date: Mon, 6 Jul 2009 15:30:04 +0000 Subject: [PATCH 36/95] fixes #6492, removing use of define LC_MESSAGES due to inconsistency on different operating systems git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8223 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/basics.php | 15 ++++----------- cake/libs/i18n.php | 2 +- cake/tests/cases/basics.test.php | 24 ++++++++++++------------ 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/cake/basics.php b/cake/basics.php index 56934baee..aaf1124d4 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -34,13 +34,6 @@ define('WEEK', 7 * DAY); define('MONTH', 30 * DAY); define('YEAR', 365 * DAY); -/** - * Add constant for LC_MESSAGES because it is not defined on windows - */ - if (!defined('LC_MESSAGES')) { - define('LC_MESSAGES', 6); - } - /** * Patch for PHP < 5.0 */ @@ -631,9 +624,9 @@ if (!function_exists('file_put_contents')) { } if ($return === false) { - echo I18n::translate($singular, $plural, null, LC_MESSAGES, $count); + echo I18n::translate($singular, $plural, null, 6, $count); } else { - return I18n::translate($singular, $plural, null, LC_MESSAGES, $count); + return I18n::translate($singular, $plural, null, 6, $count); } } /** @@ -679,9 +672,9 @@ if (!function_exists('file_put_contents')) { } if ($return === false) { - echo I18n::translate($singular, $plural, $domain, LC_MESSAGES, $count); + echo I18n::translate($singular, $plural, $domain, 6, $count); } else { - return I18n::translate($singular, $plural, $domain, LC_MESSAGES, $count); + return I18n::translate($singular, $plural, $domain, 6, $count); } } /** diff --git a/cake/libs/i18n.php b/cake/libs/i18n.php index d987842b0..6e21ca5c9 100644 --- a/cake/libs/i18n.php +++ b/cake/libs/i18n.php @@ -123,7 +123,7 @@ class I18n extends Object { * @return string translated strings. * @access public */ - function translate($singular, $plural = null, $domain = null, $category = LC_MESSAGES, $count = null) { + function translate($singular, $plural = null, $domain = null, $category = 6, $count = null) { $_this =& I18n::getInstance(); if (strpos($singular, "\r\n") !== false) { diff --git a/cake/tests/cases/basics.test.php b/cake/tests/cases/basics.test.php index 5fb05837b..0f81ab27f 100644 --- a/cake/tests/cases/basics.test.php +++ b/cake/tests/cases/basics.test.php @@ -388,16 +388,16 @@ class BasicsTest extends CakeTestCase { function test__c() { Configure::write('Config.language', 'rule_1_po'); - $result = __c('Plural Rule 1', LC_MESSAGES, true); + $result = __c('Plural Rule 1', 6, true); $expected = 'Plural Rule 1 (translated)'; $this->assertEqual($result, $expected); - $result = __c('Plural Rule 1 (from core)', LC_MESSAGES, true); + $result = __c('Plural Rule 1 (from core)', 6, true); $expected = 'Plural Rule 1 (from core translated)'; $this->assertEqual($result, $expected); ob_start(); - __c('Plural Rule 1 (from core)', LC_MESSAGES); + __c('Plural Rule 1 (from core)', 6); $result = ob_get_clean(); $expected = 'Plural Rule 1 (from core translated)'; $this->assertEqual($result, $expected); @@ -411,24 +411,24 @@ class BasicsTest extends CakeTestCase { function test__dc() { Configure::write('Config.language', 'rule_1_po'); - $result = __dc('default', 'Plural Rule 1', LC_MESSAGES, true); + $result = __dc('default', 'Plural Rule 1', 6, true); $expected = 'Plural Rule 1 (translated)'; $this->assertEqual($result, $expected); - $result = __dc('default', 'Plural Rule 1 (from core)', LC_MESSAGES, true); + $result = __dc('default', 'Plural Rule 1 (from core)', 6, true); $expected = 'Plural Rule 1 (from core translated)'; $this->assertEqual($result, $expected); - $result = __dc('core', 'Plural Rule 1', LC_MESSAGES, true); + $result = __dc('core', 'Plural Rule 1', 6, true); $expected = 'Plural Rule 1'; $this->assertEqual($result, $expected); - $result = __dc('core', 'Plural Rule 1 (from core)', LC_MESSAGES, true); + $result = __dc('core', 'Plural Rule 1 (from core)', 6, true); $expected = 'Plural Rule 1 (from core translated)'; $this->assertEqual($result, $expected); ob_start(); - __dc('default', 'Plural Rule 1 (from core)', LC_MESSAGES); + __dc('default', 'Plural Rule 1 (from core)', 6); $result = ob_get_clean(); $expected = 'Plural Rule 1 (from core translated)'; $this->assertEqual($result, $expected); @@ -442,20 +442,20 @@ class BasicsTest extends CakeTestCase { function test__dcn() { Configure::write('Config.language', 'rule_1_po'); - $result = __dcn('default', '%d = 1', '%d = 0 or > 1', 0, LC_MESSAGES, true); + $result = __dcn('default', '%d = 1', '%d = 0 or > 1', 0, 6, true); $expected = '%d = 0 or > 1 (translated)'; $this->assertEqual($result, $expected); - $result = __dcn('default', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 1, LC_MESSAGES, true); + $result = __dcn('default', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 1, 6, true); $expected = '%d = 1 (from core translated)'; $this->assertEqual($result, $expected); - $result = __dcn('core', '%d = 1', '%d = 0 or > 1', 0, LC_MESSAGES, true); + $result = __dcn('core', '%d = 1', '%d = 0 or > 1', 0, 6, true); $expected = '%d = 0 or > 1'; $this->assertEqual($result, $expected); ob_start(); - __dcn('default', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 1, LC_MESSAGES); + __dcn('default', '%d = 1 (from core)', '%d = 0 or > 1 (from core)', 1, 6); $result = ob_get_clean(); $expected = '%d = 1 (from core translated)'; $this->assertEqual($result, $expected); From 9918583e7e0205b4527565333419f92e24d06d07 Mon Sep 17 00:00:00 2001 From: DarkAngelBGE Date: Mon, 6 Jul 2009 22:38:37 +0000 Subject: [PATCH 37/95] Adding testcases to disprove #6111 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8224 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/tests/cases/libs/model/behavior.test.php | 104 +++++++++++++++++- 1 file changed, 103 insertions(+), 1 deletion(-) diff --git a/cake/tests/cases/libs/model/behavior.test.php b/cake/tests/cases/libs/model/behavior.test.php index 9b3760259..3485b850f 100644 --- a/cake/tests/cases/libs/model/behavior.test.php +++ b/cake/tests/cases/libs/model/behavior.test.php @@ -337,6 +337,58 @@ class Test2Behavior extends TestBehavior{ */ class Test3Behavior extends TestBehavior{ } +/** + * Test4Behavior class + * + * @package cake + * @subpackage cake.tests.cases.libs.model + */ +class Test4Behavior extends ModelBehavior{ + function setup(&$model, $config = null) { + $model->bindModel( + array('hasMany' => array('Comment')) + ); + } +} +/** + * Test5Behavior class + * + * @package cake + * @subpackage cake.tests.cases.libs.model + */ +class Test5Behavior extends ModelBehavior{ + function setup(&$model, $config = null) { + $model->bindModel( + array('belongsTo' => array('User')) + ); + } +} +/** + * Test6Behavior class + * + * @package cake + * @subpackage cake.tests.cases.libs.model + */ +class Test6Behavior extends ModelBehavior{ + function setup(&$model, $config = null) { + $model->bindModel( + array('hasAndBelongsToMany' => array('Tag')) + ); + } +} +/** + * Test7Behavior class + * + * @package cake + * @subpackage cake.tests.cases.libs.model + */ +class Test7Behavior extends ModelBehavior{ + function setup(&$model, $config = null) { + $model->bindModel( + array('hasOne' => array('Attachment')) + ); + } +} /** * BehaviorTest class * @@ -350,7 +402,10 @@ class BehaviorTest extends CakeTestCase { * @var array * @access public */ - var $fixtures = array('core.apple', 'core.sample'); + var $fixtures = array( + 'core.apple', 'core.sample', 'core.article', 'core.user', 'core.comment', + 'core.attachment', 'core.tag', 'core.articles_tag' + ); /** * tearDown method * @@ -948,6 +1003,53 @@ class BehaviorTest extends CakeTestCase { $expected = array('TestBehavior', 'Test2Behavior'); $this->assertIdentical($Apple->beforeTestResult, $expected); } +/** + * undocumented function + * + * @return void + * @access public + */ + function testBindModelCallsInBehaviors() { + $this->loadFixtures('Article', 'Comment'); + + // hasMany + $Article = new Article(); + $Article->unbindModel(array('hasMany' => array('Comment'))); + $result = $Article->find('first'); + $this->assertFalse(array_key_exists('Comment', $result)); + + $Article->Behaviors->attach('Test4'); + $result = $Article->find('first'); + $this->assertTrue(array_key_exists('Comment', $result)); + + // belongsTo + $Article->unbindModel(array('belongsTo' => array('User'))); + $result = $Article->find('first'); + $this->assertFalse(array_key_exists('User', $result)); + + $Article->Behaviors->attach('Test5'); + $result = $Article->find('first'); + $this->assertTrue(array_key_exists('User', $result)); + + // hasAndBelongsToMany + $Article->unbindModel(array('hasAndBelongsToMany' => array('Tag'))); + $result = $Article->find('first'); + $this->assertFalse(array_key_exists('Tag', $result)); + + $Article->Behaviors->attach('Test6'); + $result = $Article->find('first'); + $this->assertTrue(array_key_exists('Comment', $result)); + + // hasOne + $Comment = new Comment(); + $Comment->unbindModel(array('hasOne' => array('Attachment'))); + $result = $Comment->find('first'); + $this->assertFalse(array_key_exists('Attachment', $result)); + + $Comment->Behaviors->attach('Test7'); + $result = $Comment->find('first'); + $this->assertTrue(array_key_exists('Attachment', $result)); + } /** * Test attach and detaching * From fb6b16c467cb4715aa2d9fce2f7b48ef8c4b0e5a Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 8 Jul 2009 03:25:30 +0000 Subject: [PATCH 38/95] Fixing empty time value handling in Model::deconstruct(). Both null and 00:00:00 are valid values now. Test cases added and refactored. Fixes #6488, #6018, Refs #5659 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8225 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/model.php | 46 +++++-- cake/tests/cases/libs/model/model.test.php | 141 +++++++++++++-------- 2 files changed, 123 insertions(+), 64 deletions(-) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index fbf2e360b..cf50f8f6c 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -827,8 +827,11 @@ class Model extends Overloadable { $type = $this->getColumnType($field); if (in_array($type, array('datetime', 'timestamp', 'date', 'time'))) { - $useNewDate = (isset($data['year']) || isset($data['month']) || isset($data['day']) || isset($data['hour']) || isset($data['minute'])); + $useNewDate = (isset($data['year']) || isset($data['month']) || + isset($data['day']) || isset($data['hour']) || isset($data['minute'])); + $dateFields = array('Y' => 'year', 'm' => 'month', 'd' => 'day', 'H' => 'hour', 'i' => 'min', 's' => 'sec'); + $timeFields = array('H' => 'hour', 'i' => 'min', 's' => 'sec'); $db =& ConnectionManager::getDataSource($this->useDbConfig); $format = $db->columns[$type]['format']; @@ -840,27 +843,42 @@ class Model extends Overloadable { if (isset($data['hour']) && isset($data['meridian']) && $data['hour'] == 12 && 'am' == $data['meridian']) { $data['hour'] = '00'; } - - foreach ($dateFields as $key => $val) { - if (in_array($val, array('hour', 'min', 'sec'))) { - if (!isset($data[$val]) || $data[$val] === '0' || empty($data[$val])) { + if ($type == 'time') { + foreach ($timeFields as $key => $val) { + if (!isset($data[$val]) || $data[$val] === '0' || $data[$val] === '00') { $data[$val] = '00'; + } elseif ($data[$val] === '') { + $data[$val] = ''; } else { $data[$val] = sprintf('%02d', $data[$val]); } + if (!empty($data[$val])) { + $date[$key] = $data[$val]; + } else { + return null; + } } - if (in_array($type, array('datetime', 'timestamp', 'date')) && !isset($data[$val]) || isset($data[$val]) && (empty($data[$val]) || $data[$val][0] === '-')) { - return null; - } elseif (isset($data[$val]) && !empty($data[$val])) { - $date[$key] = $data[$val]; + } + + if ($type == 'datetime' || $type == 'timestamp' || $type == 'date') { + foreach ($dateFields as $key => $val) { + if ($val == 'hour' || $val == 'min' || $val == 'sec') { + if (!isset($data[$val]) || $data[$val] === '0' || $data[$val] === '00') { + $data[$val] = '00'; + } else { + $data[$val] = sprintf('%02d', $data[$val]); + } + } + if (!isset($data[$val]) || isset($data[$val]) && (empty($data[$val]) || $data[$val][0] === '-')) { + return null; + } + if (isset($data[$val]) && !empty($data[$val])) { + $date[$key] = $data[$val]; + } } } $date = str_replace(array_keys($date), array_values($date), $format); - if ($type == 'time' && $date == '00:00:00') { - return null; - } - - if ($useNewDate && (!empty($date))) { + if ($useNewDate && !empty($date)) { return $date; } } diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 4594d397a..cceabb035 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -26,6 +26,9 @@ */ App::import('Core', array('AppModel', 'Model')); require_once dirname(__FILE__) . DS . 'models.php'; + +SimpleTest::ignore('BaseModelTest'); + /** * ModelBaseTest * @@ -603,12 +606,97 @@ class ModelTest extends BaseModelTest { $this->assertEqual($Post->getColumnTypes(), array_combine($columns, $types)); } /** - * testDeconstructFields method + * test deconstruct() with time fields. + * + * @return void + **/ + function testDeconstructFieldsTime() { + $this->loadFixtures('Apple'); + $TestModel =& new Apple(); + + $data = array(); + $data['Apple']['mytime']['hour'] = ''; + $data['Apple']['mytime']['min'] = ''; + $data['Apple']['mytime']['sec'] = ''; + + $TestModel->data = null; + $TestModel->set($data); + $expected = array('Apple'=> array('mytime'=> '')); + $this->assertEqual($TestModel->data, $expected); + + $data = array(); + $data['Apple']['mytime']['hour'] = ''; + $data['Apple']['mytime']['min'] = ''; + $data['Apple']['mytime']['meridan'] = ''; + + $TestModel->data = null; + $TestModel->set($data); + $expected = array('Apple'=> array('mytime'=> '')); + $this->assertEqual($TestModel->data, $expected, 'Empty values are not returning properly. %s'); + + $data = array(); + $data['Apple']['mytime']['hour'] = '12'; + $data['Apple']['mytime']['min'] = '0'; + $data['Apple']['mytime']['meridian'] = 'am'; + + $TestModel->data = null; + $TestModel->set($data); + $expected = array('Apple'=> array('mytime'=> '00:00:00')); + $this->assertEqual($TestModel->data, $expected, 'Midnight is not returning proper values. %s'); + + $data = array(); + $data['Apple']['mytime']['hour'] = '00'; + $data['Apple']['mytime']['min'] = '00'; + + $TestModel->data = null; + $TestModel->set($data); + $expected = array('Apple'=> array('mytime'=> '00:00:00')); + $this->assertEqual($TestModel->data, $expected, 'Midnight is not returning proper values. %s'); + + $data = array(); + $data['Apple']['mytime']['hour'] = '03'; + $data['Apple']['mytime']['min'] = '04'; + $data['Apple']['mytime']['sec'] = '04'; + + $TestModel->data = null; + $TestModel->set($data); + $expected = array('Apple'=> array('mytime'=> '03:04:04')); + $this->assertEqual($TestModel->data, $expected); + + $data = array(); + $data['Apple']['mytime']['hour'] = '3'; + $data['Apple']['mytime']['min'] = '4'; + $data['Apple']['mytime']['sec'] = '4'; + + $TestModel->data = null; + $TestModel->set($data); + $expected = array('Apple' => array('mytime'=> '03:04:04')); + $this->assertEqual($TestModel->data, $expected); + + $data = array(); + $data['Apple']['mytime']['hour'] = '03'; + $data['Apple']['mytime']['min'] = '4'; + $data['Apple']['mytime']['sec'] = '4'; + + $TestModel->data = null; + $TestModel->set($data); + $expected = array('Apple'=> array('mytime'=> '03:04:04')); + $this->assertEqual($TestModel->data, $expected); + + $db = ConnectionManager::getDataSource('test_suite'); + $data = array(); + $data['Apple']['mytime'] = $db->expression('NOW()'); + $TestModel->data = null; + $TestModel->set($data); + $this->assertEqual($TestModel->data, $data); + } +/** + * testDeconstructFields with datetime, timestamp, and date fields * * @access public * @return void */ - function testDeconstructFields() { + function testDeconstructFieldsDateTime() { $this->loadFixtures('Apple'); $TestModel =& new Apple(); @@ -635,17 +723,6 @@ class ModelTest extends BaseModelTest { $expected = array('Apple'=> array('date'=> '')); $this->assertEqual($TestModel->data, $expected); - $data = array(); - $data['Apple']['mytime']['hour'] = ''; - $data['Apple']['mytime']['min'] = ''; - $data['Apple']['mytime']['sec'] = ''; - - $TestModel->data = null; - $TestModel->set($data); - $expected = array('Apple'=> array('mytime'=> '')); - $this->assertEqual($TestModel->data, $expected); - - //test other data variations $data = array(); $data['Apple']['created']['year'] = '2007'; $data['Apple']['created']['month'] = '08'; @@ -781,49 +858,13 @@ class ModelTest extends BaseModelTest { $TestModel->set($data); $expected = array('Apple'=> array('date'=> '2006-12-25')); $this->assertEqual($TestModel->data, $expected); - - $data = array(); - $data['Apple']['mytime']['hour'] = '03'; - $data['Apple']['mytime']['min'] = '04'; - $data['Apple']['mytime']['sec'] = '04'; - - $TestModel->data = null; - $TestModel->set($data); - $expected = array('Apple'=> array('mytime'=> '03:04:04')); - $this->assertEqual($TestModel->data, $expected); - - $data = array(); - $data['Apple']['mytime']['hour'] = '3'; - $data['Apple']['mytime']['min'] = '4'; - $data['Apple']['mytime']['sec'] = '4'; - - $TestModel->data = null; - $TestModel->set($data); - $expected = array('Apple' => array('mytime'=> '03:04:04')); - $this->assertEqual($TestModel->data, $expected); - - $data = array(); - $data['Apple']['mytime']['hour'] = '03'; - $data['Apple']['mytime']['min'] = '4'; - $data['Apple']['mytime']['sec'] = '4'; - - $TestModel->data = null; - $TestModel->set($data); - $expected = array('Apple'=> array('mytime'=> '03:04:04')); - $this->assertEqual($TestModel->data, $expected); - + $db = ConnectionManager::getDataSource('test_suite'); $data = array(); $data['Apple']['modified'] = $db->expression('NOW()'); $TestModel->data = null; $TestModel->set($data); $this->assertEqual($TestModel->data, $data); - - $data = array(); - $data['Apple']['mytime'] = $db->expression('NOW()'); - $TestModel->data = null; - $TestModel->set($data); - $this->assertEqual($TestModel->data, $data); } /** * testTablePrefixSwitching method From 4f44a154701f0014a91d4825177877c9b2f9138b Mon Sep 17 00:00:00 2001 From: jperras Date: Fri, 10 Jul 2009 00:07:51 +0000 Subject: [PATCH 39/95] EmailComponent::reset now empties out attachments array. Fixes #6498. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8226 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/controller/components/email.php | 1 + cake/tests/cases/libs/controller/components/email.test.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php index 30daf1669..6868c21cd 100644 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -346,6 +346,7 @@ class EmailComponent extends Object{ $this->subject = null; $this->additionalParams = null; $this->smtpError = null; + $this->attachments = array(); $this->__header = array(); $this->__boundary = null; $this->__message = array(); diff --git a/cake/tests/cases/libs/controller/components/email.test.php b/cake/tests/cases/libs/controller/components/email.test.php index 318ce6b5f..f8090cf5f 100644 --- a/cake/tests/cases/libs/controller/components/email.test.php +++ b/cake/tests/cases/libs/controller/components/email.test.php @@ -574,6 +574,7 @@ TEXTBLOC; $this->Controller->EmailTest->additionalParams = 'X-additional-header'; $this->Controller->EmailTest->delivery = 'smtp'; $this->Controller->EmailTest->smtpOptions['host'] = 'blah'; + $this->Controller->EmailTest->attachments = array('attachment1', 'attachment2'); $this->assertFalse($this->Controller->EmailTest->send('Should not work')); @@ -592,6 +593,7 @@ TEXTBLOC; $this->assertNull($this->Controller->EmailTest->getBoundary()); $this->assertIdentical($this->Controller->EmailTest->getMessage(), array()); $this->assertNull($this->Controller->EmailTest->smtpError); + $this->assertIdentical($this->Controller->EmailTest->attachments, array()); } /** * osFix method From 11c664177f3d57137398afa85de0a73fe12eea1c Mon Sep 17 00:00:00 2001 From: DarkAngelBGE Date: Sat, 11 Jul 2009 15:36:45 +0000 Subject: [PATCH 40/95] git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8227 3807eeeb-6ff5-0310-8944-8be069107fe0 --- .../cases/libs/view/helpers/text.test.php | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/cake/tests/cases/libs/view/helpers/text.test.php b/cake/tests/cases/libs/view/helpers/text.test.php index 3360b8639..88a26a61b 100644 --- a/cake/tests/cases/libs/view/helpers/text.test.php +++ b/cake/tests/cases/libs/view/helpers/text.test.php @@ -140,10 +140,20 @@ class TextHelperTest extends CakeTestCase { $text1 = '

strongbow isn’t real cider

'; $text2 = '

strongbow isn’t real cider

'; $text3 = 'What a strong mouse!'; + $text4 = 'What a strong mouse: What a strong mouse!'; + + $expected = '

strongbow isn’t real cider

'; + $this->assertEqual($this->Text->highlight($text1, 'strong', '\1', true), $expected); + + $expected = '

strongbow isn’t real cider

'; + $this->assertEqual($this->Text->highlight($text2, 'strong', '\1', true), $expected); - $this->assertEqual($this->Text->highlight($text1, 'strong', '\1', true), '

strongbow isn’t real cider

'); - $this->assertEqual($this->Text->highlight($text2, 'strong', '\1', true), '

strongbow isn’t real cider

'); $this->assertEqual($this->Text->highlight($text3, 'strong', '\1', true), $text3); + + $this->assertEqual($this->Text->highlight($text3, array('strong', 'what'), '\1', true), $text3); + + $expected = 'What a strong mouse: What a strong mouse!'; + $this->assertEqual($this->Text->highlight($text4, array('strong', 'what'), '\1', true), $expected); } /** * testStripLinks method @@ -277,22 +287,32 @@ class TextHelperTest extends CakeTestCase { $expected = '...with test text...'; $result = $this->Text->excerpt($text, 'test', 9, '...'); $this->assertEqual($expected, $result); - + $expected = 'This is a...'; $result = $this->Text->excerpt($text, 'not_found', 9, '...'); $this->assertEqual($expected, $result); - + $expected = 'This is a phras...'; $result = $this->Text->excerpt($text, null, 9, '...'); $this->assertEqual($expected, $result); - + $expected = $text; $result = $this->Text->excerpt($text, null, 200, '...'); $this->assertEqual($expected, $result); - + $expected = '...phrase...'; $result = $this->Text->excerpt($text, 'phrase', 2, '...'); $this->assertEqual($expected, $result); + + $phrase = 'This is a phrase with test'; + $expected = $text; + $result = $this->Text->excerpt($text, $phrase, strlen($phrase) + 3, '...'); + $this->assertEqual($expected, $result); + + $phrase = 'This is a phrase with text'; + $expected = $text; + $result = $this->Text->excerpt($text, $phrase, 10, '...'); + $this->assertEqual($expected, $result); } /** * testExcerptCaseInsensitivity method From 44fa8d5fd0eb9868d788179eeb95659470961238 Mon Sep 17 00:00:00 2001 From: DarkAngelBGE Date: Sat, 11 Jul 2009 16:45:29 +0000 Subject: [PATCH 41/95] Getting the time helper code coverage up to 99% git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8228 3807eeeb-6ff5-0310-8944-8be069107fe0 --- .../tests/cases/libs/view/helpers/time.test.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cake/tests/cases/libs/view/helpers/time.test.php b/cake/tests/cases/libs/view/helpers/time.test.php index 1a92336c8..94da2a997 100644 --- a/cake/tests/cases/libs/view/helpers/time.test.php +++ b/cake/tests/cases/libs/view/helpers/time.test.php @@ -276,6 +276,23 @@ class TimeHelperTest extends CakeTestCase { $fourHours = $this->Time->timeAgoInWords(strtotime('-5 days, -2 hours'), array('userOffset' => -4)); $result = $this->Time->timeAgoInWords(strtotime('-5 days, -2 hours'), array('userOffset' => 4)); $this->assertEqual($fourHours, $result); + + $result = $this->Time->timeAgoInWords(strtotime('-2 hours')); + $expected = '2 hours ago'; + $this->assertEqual($expected, $result); + + $result = $this->Time->timeAgoInWords(strtotime('-12 minutes')); + $expected = '12 minutes ago'; + $this->assertEqual($expected, $result); + + $result = $this->Time->timeAgoInWords(strtotime('-12 seconds')); + $expected = '12 seconds ago'; + $this->assertEqual($expected, $result); + + $time = strtotime('-3 years -12 months'); + $result = $this->Time->timeAgoInWords($time); + $expected = 'on ' . date('j/n/y', $time); + $this->assertEqual($expected, $result); } /** * testRelative method From f712d84d33fd6914e12ddf19daeffb19fbc65108 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 14 Jul 2009 02:30:51 +0000 Subject: [PATCH 42/95] Applying patch from 'slywalker'. Updating datetime generation in baked files. Fixed #6505 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8229 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/console/libs/schema.php | 2 +- cake/console/libs/tasks/controller.php | 2 +- cake/console/libs/tasks/model.php | 4 ++-- cake/console/libs/tasks/test.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cake/console/libs/schema.php b/cake/console/libs/schema.php index 799bb0083..698164d05 100644 --- a/cake/console/libs/schema.php +++ b/cake/console/libs/schema.php @@ -199,7 +199,7 @@ class SchemaShell extends Shell { } } $db =& ConnectionManager::getDataSource($this->Schema->connection); - $contents = "#". $Schema->name ." sql generated on: " . date('Y-m-d H:m:s') . " : ". time()."\n\n"; + $contents = "#". $Schema->name ." sql generated on: " . date('Y-m-d H:i:s') . " : ". time()."\n\n"; $contents .= $db->dropSchema($Schema) . "\n\n". $db->createSchema($Schema); if ($write) { if (strpos($write, '.sql') === false) { diff --git a/cake/console/libs/tasks/controller.php b/cake/console/libs/tasks/controller.php index b4a98756d..bb7928db2 100644 --- a/cake/console/libs/tasks/controller.php +++ b/cake/console/libs/tasks/controller.php @@ -484,7 +484,7 @@ class ControllerTask extends Shell { $this->out("\nBaking unit test for $className..."); $header = '$Id'; - $content = ""; + $content = ""; return $this->createFile($path . $filename, $content); } /** diff --git a/cake/console/libs/tasks/model.php b/cake/console/libs/tasks/model.php index 464d5bae5..fc03da64b 100644 --- a/cake/console/libs/tasks/model.php +++ b/cake/console/libs/tasks/model.php @@ -733,7 +733,7 @@ class ModelTask extends Shell { $this->out("\nBaking unit test for $className..."); $header = '$Id'; - $content = ""; + $content = ""; return $this->createFile($path . $filename, $content); } return false; @@ -927,7 +927,7 @@ class ModelTask extends Shell { } $filename = Inflector::underscore($model).'_fixture.php'; $header = '$Id'; - $content = ""; + $content = ""; $this->out("\nBaking test fixture for $model..."); if ($this->createFile($path . $filename, $content)) { return str_replace("\t\t", "\t\t\t", $records); diff --git a/cake/console/libs/tasks/test.php b/cake/console/libs/tasks/test.php index 45b853448..f959d21da 100644 --- a/cake/console/libs/tasks/test.php +++ b/cake/console/libs/tasks/test.php @@ -181,7 +181,7 @@ class TestTask extends Shell { } $header = '$Id'; - $content = ""; + $content = ""; return $this->createFile($this->filePath . Inflector::underscore($name) . '.test.php', $content); } /** From 02ed77ab202b2f71a3f19395c034d4287fff25a4 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 14 Jul 2009 03:52:06 +0000 Subject: [PATCH 43/95] Adding tests for calling RequestHandlerComponent::renderAs() twice. Fixing issue where viewPath was not updated. Fixes #6466 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8230 3807eeeb-6ff5-0310-8944-8be069107fe0 --- .../controller/components/request_handler.php | 2 +- .../components/request_handler.test.php | 55 ++++++++++++++----- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/cake/libs/controller/components/request_handler.php b/cake/libs/controller/components/request_handler.php index 8887ff443..efca6b2c5 100644 --- a/cake/libs/controller/components/request_handler.php +++ b/cake/libs/controller/components/request_handler.php @@ -585,7 +585,7 @@ class RequestHandlerComponent extends Object { if (empty($this->__renderType)) { $controller->viewPath .= '/' . $type; } else { - $remove = preg_replace("/(?:\/{$type})$/", '/' . $type, $controller->viewPath); + $remove = preg_replace("/(?:\/{$this->__renderType})$/", '/' . $type, $controller->viewPath); $controller->viewPath = $remove; } $this->__renderType = $type; diff --git a/cake/tests/cases/libs/controller/components/request_handler.test.php b/cake/tests/cases/libs/controller/components/request_handler.test.php index 0af25da9c..f0e638d4d 100644 --- a/cake/tests/cases/libs/controller/components/request_handler.test.php +++ b/cake/tests/cases/libs/controller/components/request_handler.test.php @@ -35,6 +35,13 @@ Mock::generatePartial('RequestHandlerComponent', 'NoStopRequestHandler', array(' * @subpackage cake.tests.cases.libs.controller.components */ class RequestHandlerTestController extends Controller { +/** + * name property + * + * @var string + * @access public + **/ + var $name = 'RequestHandlerTest'; /** * uses property * @@ -124,21 +131,32 @@ class RequestHandlerComponentTest extends CakeTestCase { */ var $RequestHandler; /** - * setUp method + * startTest method * * @access public * @return void */ - function setUp() { + function startTest() { $this->_init(); } /** - * tearDown method + * init method + * + * @access protected + * @return void + */ + function _init() { + $this->Controller = new RequestHandlerTestController(array('components' => array('RequestHandler'))); + $this->Controller->constructClasses(); + $this->RequestHandler =& $this->Controller->RequestHandler; + } +/** + * endTest method * * @access public * @return void */ - function tearDown() { + function endTest() { unset($this->RequestHandler); unset($this->Controller); if (!headers_sent()) { @@ -241,6 +259,24 @@ class RequestHandlerComponentTest extends CakeTestCase { $this->RequestHandler->renderAs($this->Controller, 'xml'); $this->assertTrue(in_array('Xml', $this->Controller->helpers)); } +/** + * test that calling renderAs() more than once continues to work. + * + * @link #6466 + * @return void + **/ + function testRenderAsCalledTwice() { + $this->RequestHandler->renderAs($this->Controller, 'xml'); + $this->assertEqual($this->Controller->viewPath, 'request_handler_test/xml'); + $this->assertEqual($this->Controller->layoutPath, 'xml'); + + $this->assertTrue(in_array('Xml', $this->Controller->helpers)); + + $this->RequestHandler->renderAs($this->Controller, 'js'); + $this->assertEqual($this->Controller->viewPath, 'request_handler_test/js'); + $this->assertEqual($this->Controller->layoutPath, 'js'); + $this->assertTrue(in_array('Js', $this->Controller->helpers)); + } /** * testRequestClientTypes method * @@ -502,16 +538,5 @@ class RequestHandlerComponentTest extends CakeTestCase { Configure::write('viewPaths', $_paths); unset($_SERVER['HTTP_X_REQUESTED_WITH']); } -/** - * init method - * - * @access protected - * @return void - */ - function _init() { - $this->Controller = new RequestHandlerTestController(array('components' => array('RequestHandler'))); - $this->Controller->constructClasses(); - $this->RequestHandler =& $this->Controller->RequestHandler; - } } ?> \ No newline at end of file From baea31912299be11ea4fa76f62c2473103babf31 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 14 Jul 2009 17:11:46 +0000 Subject: [PATCH 44/95] Applying patch from 'Dremora' fixes JavascriptHelper::codeBlock() and blockEnd() bugs where content vanished due to incorrectly structured buffers. Minor behavior change in that codeBlock(null) no longer returns an opening script tag. The entire script tag is returned when blockEnd() is called. Test cases updated and refactored. Fixes #6504 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8231 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/helpers/javascript.php | 75 ++--- .../libs/view/helpers/javascript.test.php | 285 ++++++++++++------ 2 files changed, 217 insertions(+), 143 deletions(-) diff --git a/cake/libs/view/helpers/javascript.php b/cake/libs/view/helpers/javascript.php index bd1a804f0..7f4145d7c 100644 --- a/cake/libs/view/helpers/javascript.php +++ b/cake/libs/view/helpers/javascript.php @@ -60,10 +60,10 @@ class JavascriptHelper extends AppHelper { * @access public */ var $tags = array( - 'javascriptblock' => '', 'javascriptstart' => '', - 'javascriptend' => '' + 'javascriptend' => '', + 'javascriptblock' => '', + 'javascriptlink' => '' ); /** * Holds options passed to codeBlock(), saved for when block is dumped to output @@ -173,42 +173,28 @@ class JavascriptHelper extends AppHelper { $options = array(); } $defaultOptions = array('allowCache' => true, 'safe' => true, 'inline' => true); - $options = array_merge($defaultOptions, compact('safe'), $options); + $options = array_merge($defaultOptions, $options); - if ($this->_cacheEvents && $this->_cacheAll && $options['allowCache'] && $script !== null) { + if (empty($script)) { + $this->__scriptBuffer = @ob_get_contents(); + $this->_blockOptions = $options; + $this->inBlock = true; + @ob_end_clean(); + ob_start(); + return null; + } + if ($this->_cacheEvents && $this->_cacheAll && $options['allowCache']) { $this->_cachedEvents[] = $script; + return null; + } + if ($options['safe'] || $this->safe) { + $script = "\n" . '//' . "\n"; + } + if ($options['inline']) { + return sprintf($this->tags['javascriptblock'], $script); } else { - $block = ($script !== null); - $safe = ($options['safe'] || $this->safe); - if ($safe && !($this->_cacheAll && $options['allowCache'])) { - $script = "\n" . '//' . "\n"; - } - } - - if ($script === null) { - $this->__scriptBuffer = @ob_get_contents(); - $this->_blockOptions = $options; - $this->inBlock = true; - @ob_end_clean(); - ob_start(); - return null; - } else if (!$block) { - $this->_blockOptions = $options; - } - - if ($options['inline']) { - if ($block) { - return sprintf($this->tags['javascriptblock'], $script); - } else { - $safe = ($safe ? "\n" . '//tags['javascriptstart'] . $safe; - } - } elseif ($block) { - $view =& ClassRegistry::getObject('view'); - $view->addScript(sprintf($this->tags['javascriptblock'], $script)); - } + $view =& ClassRegistry::getObject('view'); + $view->addScript(sprintf($this->tags['javascriptblock'], $script)); } } /** @@ -217,26 +203,23 @@ class JavascriptHelper extends AppHelper { * @return mixed */ function blockEnd() { + if (!isset($this->inBlock) || !$this->inBlock) { + return; + } $script = @ob_get_contents(); @ob_end_clean(); ob_start(); echo $this->__scriptBuffer; $this->__scriptBuffer = null; $options = $this->_blockOptions; - $safe = ((isset($options['safe']) && $options['safe']) || $this->safe); $this->_blockOptions = array(); $this->inBlock = false; - - if (isset($options['inline']) && !$options['inline']) { - $view =& ClassRegistry::getObject('view'); - $view->addScript(sprintf($this->tags['javascriptblock'], $script)); - } - - if (!empty($script) && $this->_cacheAll && $options['allowCache']) { - $this->_cachedEvents[] = $script; + + if (empty($script)) { return null; } - return ife($safe, "\n" . '//]]>' . "\n", '').$this->tags['javascriptend']; + + return $this->codeBlock($script, $options); } /** * Returns a JavaScript include tag (SCRIPT element). If the filename is prefixed with "/", diff --git a/cake/tests/cases/libs/view/helpers/javascript.test.php b/cake/tests/cases/libs/view/helpers/javascript.test.php index 124f8a092..7ebad00eb 100644 --- a/cake/tests/cases/libs/view/helpers/javascript.test.php +++ b/cake/tests/cases/libs/view/helpers/javascript.test.php @@ -95,13 +95,25 @@ class TestJavascriptObject { * @since CakePHP Test Suite v 1.0.0.0 */ class JavascriptTest extends CakeTestCase { +/** + * Regexp for CDATA start block + * + * @var string + */ + var $cDataStart = 'preg:/^\/\/[\s\r\n]*/'; /** * setUp method * * @access public * @return void */ - function setUp() { + function startTest() { $this->Javascript =& new JavascriptHelper(); $this->Javascript->Html =& new HtmlHelper(); $this->Javascript->Form =& new FormHelper(); @@ -114,7 +126,7 @@ class JavascriptTest extends CakeTestCase { * @access public * @return void */ - function tearDown() { + function endTest() { unset($this->Javascript->Html); unset($this->Javascript->Form); unset($this->Javascript); @@ -356,11 +368,14 @@ class JavascriptTest extends CakeTestCase { $object = array('title' => 'New thing', 'indexes' => array(5, 6, 7, 8)); $result = $this->Javascript->object($object, array('block' => true)); - $expected = '{"title":"New thing","indexes":[5,6,7,8]}'; - $this->assertPattern('/^]+>\s*' . str_replace('/', '\\/', preg_quote('//')) . '\s*<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript">.+<\/script>$/s', $result); - $this->assertPattern('/^]+type="text\/javascript"[^<>]*>/', $result); - $this->assertNoPattern('/^]*>/', $result); + $expected = array( + 'script' => array('type' => 'text/javascript'), + $this->cDataStart, + '{"title":"New thing","indexes":[5,6,7,8]}', + $this->cDataEnd, + '/script' + ); + $this->assertTags($result, $expected); $object = array('title' => 'New thing', 'indexes' => array(5, 6, 7, 8), 'object' => array('inner' => array('value' => 1))); $result = $this->Javascript->object($object); @@ -402,7 +417,6 @@ class JavascriptTest extends CakeTestCase { $this->Javascript->useNative = $oldNative; } - /** * testScriptBlock method * @@ -410,68 +424,101 @@ class JavascriptTest extends CakeTestCase { * @return void */ function testScriptBlock() { - ob_flush(); + $result = $this->Javascript->codeBlock('something'); + $expected = array( + 'script' => array('type' => 'text/javascript'), + $this->cDataStart, + 'something', + $this->cDataEnd, + '/script' + ); + $this->assertTags($result, $expected); + $result = $this->Javascript->codeBlock('something', array('allowCache' => true, 'safe' => false)); - $this->assertPattern('/^]+>something<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript">something<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript"[^<>]*>/', $result); - $this->assertNoPattern('/^]*>/', $result); + $expected = array( + 'script' => array('type' => 'text/javascript'), + 'something', + '/script' + ); + $this->assertTags($result, $expected); $result = $this->Javascript->codeBlock('something', array('allowCache' => false, 'safe' => false)); - $this->assertPattern('/^]+>something<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript">something<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript"[^<>]*>/', $result); - $this->assertNoPattern('/^]*>/', $result); + $expected = array( + 'script' => array('type' => 'text/javascript'), + 'something', + '/script' + ); + $this->assertTags($result, $expected); $result = $this->Javascript->codeBlock('something', true); - $this->assertPattern('/^]+>\s*' . str_replace('/', '\\/', preg_quote('//')) . '\s*<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript">\s*' . str_replace('/', '\\/', preg_quote('//')) . '\s*<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript"[^<>]*>/', $result); - $this->assertNoPattern('/^]*>/', $result); + $expected = array( + 'script' => array('type' => 'text/javascript'), + $this->cDataStart, + 'something', + $this->cDataEnd, + '/script' + ); + $this->assertTags($result, $expected); $result = $this->Javascript->codeBlock('something', false); - $this->assertPattern('/^]+>\s*' . str_replace('/', '\\/', preg_quote('//')) . '\s*<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript">\s*' . str_replace('/', '\\/', preg_quote('//')) . '\s*<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript"[^<>]*>/', $result); - $this->assertNoPattern('/^]*>/', $result); + $expected = array( + 'script' => array('type' => 'text/javascript'), + $this->cDataStart, + 'something', + $this->cDataEnd, + '/script' + ); + $this->assertTags($result, $expected); $result = $this->Javascript->codeBlock('something', array('safe' => false)); - $this->assertPattern('/^]+>something<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript">something<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript"[^<>]*>/', $result); - $this->assertNoPattern('/^]*>/', $result); - - $result = $this->Javascript->blockEnd(); - $this->assertPattern('/^<\/script>$/', $result); + $expected = array( + 'script' => array('type' => 'text/javascript'), + 'something', + '/script' + ); + $this->assertTags($result, $expected); $result = $this->Javascript->codeBlock('something', array('safe' => true)); - $this->assertPattern('/^]+>\s*' . str_replace('/', '\\/', preg_quote('//')) . '\s*<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript">\s*' . str_replace('/', '\\/', preg_quote('//')) . '\s*<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript"[^<>]*>/', $result); - $this->assertNoPattern('/^]*>/', $result); + $expected = array( + 'script' => array('type' => 'text/javascript'), + $this->cDataStart, + 'something', + $this->cDataEnd, + '/script' + ); + $this->assertTags($result, $expected); $result = $this->Javascript->codeBlock(null, array('safe' => true, 'allowCache' => false)); - $this->assertPattern('/^]+>\s*' . str_replace('/', '\\/', preg_quote('//assertNoPattern('/^]*>/', $result); + $this->assertNull($result); + echo 'this is some javascript'; $result = $this->Javascript->blockEnd(); - $this->assertPattern('/^\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result); - - $result = $this->Javascript->codeBlock('something'); - $this->assertPattern('/^]+>\s*' . str_replace('/', '\\/', preg_quote('//')) . '\s*<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript">.+<\/script>$/s', $result); - $this->assertPattern('/^]+type="text\/javascript"[^<>]*>/', $result); - $this->assertNoPattern('/^]*>/', $result); + $expected = array( + 'script' => array('type' => 'text/javascript'), + $this->cDataStart, + 'this is some javascript', + $this->cDataEnd, + '/script' + ); + $this->assertTags($result, $expected); $result = $this->Javascript->codeBlock(); - $this->assertPattern('/^]+>\s*' . str_replace('/', '\\/', preg_quote('//assertNoPattern('/^]*>/', $result); - + $this->assertNull($result); + echo "alert('hey');"; $result = $this->Javascript->blockEnd(); - $this->assertPattern('/^\s*' . str_replace('/', '\\/', preg_quote('//]]>')) . '\s*<\/script>$/', $result); + + $expected = array( + 'script' => array('type' => 'text/javascript'), + $this->cDataStart, + "alert('hey');", + $this->cDataEnd, + '/script' + ); + $this->assertTags($result, $expected); $this->Javascript->cacheEvents(false, true); $this->assertFalse($this->Javascript->inBlock); + $result = $this->Javascript->codeBlock(); $this->assertIdentical($result, null); $this->assertTrue($this->Javascript->inBlock); @@ -491,11 +538,16 @@ class JavascriptTest extends CakeTestCase { * @return void */ function testOutOfLineScriptWriting() { - echo $this->Javascript->codeBlock('$(document).ready(function() { /* ... */ });', array('inline' => false)); + echo $this->Javascript->codeBlock('$(document).ready(function() { });', array('inline' => false)); $this->Javascript->codeBlock(null, array('inline' => false)); - echo '$(function(){ /* ... */ });'; + echo '$(function(){ });'; $this->Javascript->blockEnd(); + $script = $this->View->scripts(); + + $this->assertEqual(count($script), 2); + $this->assertPattern('/' . preg_quote('$(document).ready(function() { });', '/') . '/', $script[0]); + $this->assertPattern('/' . preg_quote('$(function(){ });', '/') . '/', $script[1]); } /** * testEvent method @@ -505,52 +557,78 @@ class JavascriptTest extends CakeTestCase { */ function testEvent() { $result = $this->Javascript->event('myId', 'click', 'something();'); - $this->assertPattern('/^]+>\s*' . str_replace('/', '\\/', preg_quote('//')) . '\s*<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript">.+' . str_replace('/', '\\/', preg_quote('Event.observe($(\'myId\'), \'click\', function(event) { something(); }, false);')) . '.+<\/script>$/s', $result); - $this->assertPattern('/^]+type="text\/javascript"[^<>]*>/', $result); - $this->assertNoPattern('/^]*>/', $result); + $expected = array( + 'script' => array('type' => 'text/javascript'), + $this->cDataStart, + "Event.observe($('myId'), 'click', function(event) { something(); }, false);", + $this->cDataEnd, + '/script' + ); + $this->assertTags($result, $expected); $result = $this->Javascript->event('myId', 'click', 'something();', array('safe' => false)); - $this->assertPattern('/^]+>[^<>]+<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript">' . str_replace('/', '\\/', preg_quote('Event.observe($(\'myId\'), \'click\', function(event) { something(); }, false);')) . '<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript"[^<>]*>/', $result); - $this->assertNoPattern('/^]*>/', $result); + $expected = array( + 'script' => array('type' => 'text/javascript'), + "Event.observe($('myId'), 'click', function(event) { something(); }, false);", + '/script' + ); + $this->assertTags($result, $expected); $result = $this->Javascript->event('myId', 'click'); - $this->assertPattern('/^]+>\s*' . str_replace('/', '\\/', preg_quote('//')) . '\s*<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript">.+' . str_replace('/', '\\/', preg_quote('Event.observe($(\'myId\'), \'click\', function(event) { }, false);')) . '.+<\/script>$/s', $result); - $this->assertPattern('/^]+type="text\/javascript"[^<>]*>/', $result); - $this->assertNoPattern('/^]*>/', $result); + $expected = array( + 'script' => array('type' => 'text/javascript'), + $this->cDataStart, + "Event.observe($('myId'), 'click', function(event) { }, false);", + $this->cDataEnd, + '/script' + ); + $this->assertTags($result, $expected); $result = $this->Javascript->event('myId', 'click', 'something();', false); - $this->assertPattern('/^]+>\s*' . str_replace('/', '\\/', preg_quote('//')) . '\s*<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript">.+' . str_replace('/', '\\/', preg_quote('Event.observe($(\'myId\'), \'click\', function(event) { something(); }, false);')) . '.+<\/script>$/s', $result); - $this->assertPattern('/^]+type="text\/javascript"[^<>]*>/', $result); - $this->assertNoPattern('/^]*>/', $result); + $expected = array( + 'script' => array('type' => 'text/javascript'), + $this->cDataStart, + "Event.observe($('myId'), 'click', function(event) { something(); }, false);", + $this->cDataEnd, + '/script' + ); + $this->assertTags($result, $expected); $result = $this->Javascript->event('myId', 'click', 'something();', array('useCapture' => true)); - $this->assertPattern('/^]+>\s*' . str_replace('/', '\\/', preg_quote('//')) . '\s*<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript">.+' . str_replace('/', '\\/', preg_quote('Event.observe($(\'myId\'), \'click\', function(event) { something(); }, true);')) . '.+<\/script>$/s', $result); - $this->assertPattern('/^]+type="text\/javascript"[^<>]*>/', $result); - $this->assertNoPattern('/^]*>/', $result); + $expected = array( + 'script' => array('type' => 'text/javascript'), + $this->cDataStart, + "Event.observe($('myId'), 'click', function(event) { something(); }, true);", + $this->cDataEnd, + '/script' + ); + $this->assertTags($result, $expected); $result = $this->Javascript->event('document', 'load'); - $this->assertPattern('/^]+>\s*' . str_replace('/', '\\/', preg_quote('//')) . '\s*<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript">.+' . str_replace('/', '\\/', preg_quote('Event.observe(document, \'load\', function(event) { }, false);')) . '.+<\/script>$/s', $result); - $this->assertPattern('/^]+type="text\/javascript"[^<>]*>/', $result); - $this->assertNoPattern('/^]*>/', $result); + $expected = array( + 'script' => array('type' => 'text/javascript'), + $this->cDataStart, + "Event.observe(document, 'load', function(event) { }, false);", + $this->cDataEnd, + '/script' + ); + $this->assertTags($result, $expected); $result = $this->Javascript->event('$(\'myId\')', 'click', 'something();', array('safe' => false)); - $this->assertPattern('/^]+>[^<>]+<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript">' . str_replace('/', '\\/', preg_quote('Event.observe($(\'myId\'), \'click\', function(event) { something(); }, false);')) . '<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript"[^<>]*>/', $result); - $this->assertNoPattern('/^]*>/', $result); + $expected = array( + 'script' => array('type' => 'text/javascript'), + "Event.observe($('myId'), 'click', function(event) { something(); }, false);", + '/script' + ); + $this->assertTags($result, $expected); $result = $this->Javascript->event('\'document\'', 'load', 'something();', array('safe' => false)); - $this->assertPattern('/^]+>[^<>]+<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript">' . str_replace('/', '\\/', preg_quote('Event.observe(\'document\', \'load\', function(event) { something(); }, false);')) . '<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript"[^<>]*>/', $result); - $this->assertNoPattern('/^]*>/', $result); + $expected = array( + 'script' => array('type' => 'text/javascript'), + "Event.observe('document', 'load', function(event) { something(); }, false);", + '/script' + ); + $this->assertTags($result, $expected); $this->Javascript->cacheEvents(); $result = $this->Javascript->event('myId', 'click', 'something();'); @@ -577,10 +655,14 @@ class JavascriptTest extends CakeTestCase { $this->assertNull($result); $result = $this->Javascript->writeEvents(); - $this->assertPattern('/^]+>\s*' . str_replace('/', '\\/', preg_quote('//')) . '\s*<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript">.+' . str_replace('/', '\\/', preg_quote('Event.observe($(\'myId\'), \'click\', function(event) { something(); }, false);')) . '.+<\/script>$/s', $result); - $this->assertPattern('/^]+type="text\/javascript"[^<>]*>/', $result); - $this->assertNoPattern('/^]*>/', $result); + $expected = array( + 'script' => array('type' => 'text/javascript'), + $this->cDataStart, + "Event.observe($('myId'), 'click', function(event) { something(); }, false);", + $this->cDataEnd, + '/script' + ); + $this->assertTags($result, $expected); $result = $this->Javascript->getCache(); $this->assertTrue(empty($result)); @@ -595,10 +677,15 @@ class JavascriptTest extends CakeTestCase { $this->assertNull($result); $this->assertEqual(count($resultScripts), 1); $result = current($resultScripts); - $this->assertPattern('/^]+>\s*' . str_replace('/', '\\/', preg_quote('//')) . '\s*<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript">.+' . str_replace('/', '\\/', preg_quote('Event.observe($(\'myId\'), \'click\', function(event) { something(); }, false);')) . '.+<\/script>$/s', $result); - $this->assertPattern('/^]+type="text\/javascript"[^<>]*>/', $result); - $this->assertNoPattern('/^]*>/', $result); + + $expected = array( + 'script' => array('type' => 'text/javascript'), + $this->cDataStart, + "Event.observe($('myId'), 'click', function(event) { something(); }, false);", + $this->cDataEnd, + '/script' + ); + $this->assertTags($result, $expected); $result = $this->Javascript->getCache(); $this->assertTrue(empty($result)); @@ -698,7 +785,7 @@ class JavascriptTest extends CakeTestCase { $data['mystring'] = "a \"double-quoted\" string"; $this->assertEqual(json_encode($data), $this->Javascript->object($data)); - + $data['mystring'] = 'a \\"double-quoted\\" string'; $this->assertEqual(json_encode($data), $this->Javascript->object($data)); } @@ -739,11 +826,15 @@ class JavascriptTest extends CakeTestCase { ob_start(); $this->Javascript->afterRender(); $result = ob_get_clean(); - - $this->assertPattern('/^]+>\s*' . str_replace('/', '\\/', preg_quote('//')) . '\s*<\/script>$/', $result); - $this->assertPattern('/^]+type="text\/javascript">.+' . str_replace('/', '\\/', preg_quote('Event.observe($(\'myId\'), \'click\', function(event) { something(); }, false);')) . '.+<\/script>$/s', $result); - $this->assertPattern('/^]+type="text\/javascript"[^<>]*>/', $result); - $this->assertNoPattern('/^]*>/', $result); + + $expected = array( + 'script' => array('type' => 'text/javascript'), + $this->cDataStart, + "Event.observe($('myId'), 'click', function(event) { something(); }, false);", + $this->cDataEnd, + '/script' + ); + $this->assertTags($result, $expected); $result = $this->Javascript->getCache(); $this->assertTrue(empty($result)); From 3b872a218ed89c0e2c7291ff6bc1d253f2b7d987 Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Wed, 15 Jul 2009 19:15:14 +0000 Subject: [PATCH 45/95] Removing supressing errors from HttpSocket, using condition instead. Fixes #6483. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8232 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/http_socket.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cake/libs/http_socket.php b/cake/libs/http_socket.php index 25105fd55..79a96cd32 100644 --- a/cake/libs/http_socket.php +++ b/cake/libs/http_socket.php @@ -220,7 +220,10 @@ class HttpSocket extends CakeSocket { $this->request['header']['Content-Length'] = strlen($this->request['body']); } - $connectionType = @$this->request['header']['Connection']; + $connectionType = null; + if (isset($this->request['header']['Connection'])) { + $connectionType = $this->request['header']['Connection']; + } $this->request['header'] = $this->buildHeader($this->request['header']).$cookies; if (empty($this->request['line'])) { @@ -395,7 +398,11 @@ class HttpSocket extends CakeSocket { } $response['header'] = $this->parseHeader($response['raw']['header']); - $decoded = $this->decodeBody($response['raw']['body'], @$response['header']['Transfer-Encoding']); + $transferEncoding = null; + if (isset($response['header']['Transfer-Encoding'])) { + $transferEncoding = $response['header']['Transfer-Encoding']; + } + $decoded = $this->decodeBody($response['raw']['body'], $transferEncoding); $response['body'] = $decoded['body']; if (!empty($decoded['header'])) { From 7fd6cc52c25d4f73fc74af011d190cadff077e2f Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Wed, 15 Jul 2009 19:17:41 +0000 Subject: [PATCH 46/95] Fixing issue with timeout when reading socket. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8233 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/socket.php | 14 ++++++++++++-- cake/tests/cases/libs/socket.test.php | 12 ++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/cake/libs/socket.php b/cake/libs/socket.php index fb50940d0..c5c945aa0 100644 --- a/cake/libs/socket.php +++ b/cake/libs/socket.php @@ -120,7 +120,11 @@ class CakeSocket extends Object { $this->setLastError($errStr, $errNum); } - return $this->connected = is_resource($this->connection); + $this->connected = is_resource($this->connection); + if ($this->connected) { + stream_set_timeout($this->connection, $this->config['timeout']); + } + return $this->connected; } /** @@ -218,7 +222,13 @@ class CakeSocket extends Object { } if (!feof($this->connection)) { - return fread($this->connection, $length); + $buffer = fread($this->connection, $length); + $info = stream_get_meta_data($this->connection); + if ($info['timed_out']) { + $this->setLastError(E_WARNING, __('Connection timed out', true)); + return false; + } + return $buffer; } else { return false; } diff --git a/cake/tests/cases/libs/socket.test.php b/cake/tests/cases/libs/socket.test.php index 31ce57873..931f2b531 100644 --- a/cake/tests/cases/libs/socket.test.php +++ b/cake/tests/cases/libs/socket.test.php @@ -144,6 +144,18 @@ class SocketTest extends CakeTestCase { $this->Socket = new CakeSocket(array('timeout' => 5)); $this->Socket->connect(); $this->assertEqual($this->Socket->read(26), null); + + $config = array('host' => 'www.cakephp.org', 'timeout' => 1); + $this->Socket = new CakeSocket($config); + $this->assertTrue($this->Socket->connect()); + $this->assertFalse($this->Socket->read(1024 * 1024)); + $this->assertEqual($this->Socket->lastError(), '2: ' . __('Connection timed out', true)); + + $config = array('host' => 'www.cakephp.org', 'timeout' => 30); + $this->Socket = new CakeSocket($config); + $this->assertTrue($this->Socket->connect()); + $this->assertEqual($this->Socket->read(26), null); + $this->assertEqual($this->Socket->lastError(), null); } /** * testLastError method From 76d5855d720c9fe65d4d3ec02dc176d405d91aed Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 17 Jul 2009 19:46:33 +0000 Subject: [PATCH 47/95] Applying patch from 'Phally' Fixes multiple issues in PaginatorHelper related to first and last option in numbers(). Fixes #6516 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8234 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/helpers/paginator.php | 34 +++++++---- .../libs/view/helpers/paginator.test.php | 60 +++++++++++++++++++ 2 files changed, 81 insertions(+), 13 deletions(-) diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php index 8dd83a144..21925dcee 100644 --- a/cake/libs/view/helpers/paginator.php +++ b/cake/libs/view/helpers/paginator.php @@ -449,9 +449,9 @@ class PaginatorHelper extends AppHelper { function numbers($options = array()) { if ($options === true) { $options = array( - 'before' => ' | ', 'after' => ' | ', - 'first' => 'first', 'last' => 'last', - ); + 'before' => ' | ', 'after' => ' | ', + 'first' => 'first', 'last' => 'last', + ); } $options = array_merge( @@ -490,11 +490,15 @@ class PaginatorHelper extends AppHelper { $end = $params['page'] + ($modulus - $params['page']) + 1; } - if ($first && $start > (int)$first) { - if ($start == $first + 1) { - $out .= $this->first($first, array('tag' => $tag, 'after' => $separator)); - } else { - $out .= $this->first($first, array('tag' => $tag)); + if ($first) { + if ($start > (int)$first) { + if ($start == $first + 1) { + $out .= $this->first($first, array('tag' => $tag, 'after' => $separator, 'separator' => $separator)); + } else { + $out .= $this->first($first, array('tag' => $tag, 'separator' => $separator)); + } + } elseif ($start == 2) { + $out .= $this->Html->tag($tag, $this->link(1, array('page' => 1), $options)) . $separator; } } @@ -520,11 +524,15 @@ class PaginatorHelper extends AppHelper { $out .= $after; - if ($last && $end <= $params['pageCount'] - (int)$last) { - if ($end + 1 == $params['pageCount']) { - $out .= $this->last($last, array('tag' => $tag, 'before' => $separator)); - } else { - $out .= $this->last($last, array('tag' => $tag)); + if ($last) { + if ($end <= $params['pageCount'] - (int)$last) { + if ($end + 1 == $params['pageCount']) { + $out .= $this->last($last, array('tag' => $tag, 'before' => $separator, 'separator' => $separator)); + } else { + $out .= $this->last($last, array('tag' => $tag, 'separator' => $separator)); + } + } elseif ($end == $params['pageCount'] - 1) { + $out .= $separator . $this->Html->tag($tag, $this->link($params['pageCount'], array('page' => $params['pageCount']), $options)); } } diff --git a/cake/tests/cases/libs/view/helpers/paginator.test.php b/cake/tests/cases/libs/view/helpers/paginator.test.php index 69095f1d8..30a8eeff5 100644 --- a/cake/tests/cases/libs/view/helpers/paginator.test.php +++ b/cake/tests/cases/libs/view/helpers/paginator.test.php @@ -725,6 +725,66 @@ class PaginatorHelperTest extends CakeTestCase { $result = $this->Paginator->numbers(); $expected = '1 | 2 | 3 | 4'; $this->assertEqual($result, $expected); + + $this->Paginator->params['paging'] = array('Client' => array( + 'page' => 4895, 'current' => 10, 'count' => 48962, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 4897, + 'defaults' => array('limit' => 10), + 'options' => array('page' => 4894, 'limit' => 10, 'order' => 'Client.name DESC', 'conditions' => array())) + ); + + $result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2)); + $expected = array( + array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', + '...', + array('span' => array()), array('a' => array('href' => '/index/page:4894')), '4894', '/a', '/span', + ' | ', + array('span' => array('class' => 'current')), '4895', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span', + ); + $this->assertTags($result, $expected); + + $this->Paginator->params['paging'] = array('Client' => array( + 'page' => 3, 'current' => 10, 'count' => 48962, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 4897, + 'defaults' => array('limit' => 10), + 'options' => array('page' => 4894, 'limit' => 10, 'order' => 'Client.name DESC', 'conditions' => array())) + ); + + $result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2)); + $expected = array( + array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', + ' | ', + array('span' => array('class' => 'current')), '3', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', + '...', + array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span', + ); + $this->assertTags($result, $expected); + + $result = $this->Paginator->numbers(array('first' => 2, 'modulus' => 2, 'last' => 2, 'separator' => ' - ')); + $expected = array( + array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:2')), '2', '/a', '/span', + ' - ', + array('span' => array('class' => 'current')), '3', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span', + '...', + array('span' => array()), array('a' => array('href' => '/index/page:4896')), '4896', '/a', '/span', + ' - ', + array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span', + ); + $this->assertTags($result, $expected); } /** * testFirstAndLast method From 74fd4849ba8e37ed7974a02bf7b9b40761ea7531 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 17 Jul 2009 21:35:23 +0000 Subject: [PATCH 48/95] Fixing issue in Router where generating plugin shortcut controller routes with admin prefixes left a :controller param behind. Fixes #6252 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8235 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/router.php | 2 +- cake/tests/cases/libs/router.test.php | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cake/libs/router.php b/cake/libs/router.php index 4071c6f12..84a24abf5 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -1082,7 +1082,7 @@ class Router extends Object { if (isset($params[$key])) { $string = $params[$key]; unset($params[$key]); - } else { + } elseif (strpos($out, $key) != strlen($out) - strlen($key)) { $key = $key . '/'; } $out = str_replace(':' . $key, $string, $out); diff --git a/cake/tests/cases/libs/router.test.php b/cake/tests/cases/libs/router.test.php index f57c91d9c..da062342b 100644 --- a/cake/tests/cases/libs/router.test.php +++ b/cake/tests/cases/libs/router.test.php @@ -1036,6 +1036,28 @@ class RouterTest extends CakeTestCase { $result = Router::url(array('controller' => 'posts', 'action' => 'index', '0', '?' => 'var=test&var2=test2')); $expected = '/beheer/posts/index/0?var=test&var2=test2'; $this->assertEqual($result, $expected); + + Configure::write('Routing.admin', 'admin'); + $paths = Configure::read('pluginPaths'); + Configure::write('pluginPaths', array( + TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS + )); + Configure::write('__objects.plugin', array('test_plugin')); + + Router::reload(); + Router::setRequestInfo(array( + array('admin' => true, 'controller' => 'controller', 'action' => 'action', + 'form' => array(), 'url' => array(), 'plugin' => null), + array('base' => '/', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(), + 'argSeparator' => ':', 'namedArgs' => array()) + )); + Router::parse('/'); + + $result = Router::url(array('plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'index')); + $expected = '/admin/test_plugin'; + $this->assertEqual($result, $expected); + + Configure::write('pluginPaths', $paths); } /** * testExtensionParsingSetting method From d2245fd514aa5f465f16ff7b6a9ee7568f21e2c1 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 20 Jul 2009 13:18:38 +0000 Subject: [PATCH 49/95] Fixing Router::normalize() so that a url containing the base param more than once, which is passed into normalize() multiple times does not get url segments removed. Fixes #6338 and #5978 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8236 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/router.php | 2 +- cake/tests/cases/libs/router.test.php | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/cake/libs/router.php b/cake/libs/router.php index 84a24abf5..3707a56d7 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -1200,7 +1200,7 @@ class Router extends Object { $paths = Router::getPaths(); if (!empty($paths['base']) && stristr($url, $paths['base'])) { - $url = preg_replace('/' . preg_quote($paths['base'], '/') . '/', '', $url, 1); + $url = preg_replace('/^' . preg_quote($paths['base'], '/') . '/', '', $url, 1); } $url = '/' . $url; diff --git a/cake/tests/cases/libs/router.test.php b/cake/tests/cases/libs/router.test.php index da062342b..08739db83 100644 --- a/cake/tests/cases/libs/router.test.php +++ b/cake/tests/cases/libs/router.test.php @@ -299,7 +299,7 @@ class RouterTest extends CakeTestCase { $result = Router::normalize('/recipe/recipes/add'); $this->assertEqual($result, '/recipe/recipes/add'); - Router::setRequestInfo(array(array(), array('base' => 'us'))); + Router::setRequestInfo(array(array(), array('base' => '/us'))); $result = Router::normalize('/us/users/logout/'); $this->assertEqual($result, '/users/logout'); @@ -309,6 +309,22 @@ class RouterTest extends CakeTestCase { $result = Router::normalize('/cake_12/users/logout/'); $this->assertEqual($result, '/users/logout'); + Router::reload(); + $_back = Configure::read('App.baseUrl'); + Configure::write('App.baseUrl', '/'); + + Router::setRequestInfo(array(array(), array('base' => '/'))); + $result = Router::normalize('users/login'); + $this->assertEqual($result, '/users/login'); + Configure::write('App.baseUrl', $_back); + + Router::reload(); + Router::setRequestInfo(array(array(), array('base' => 'beer'))); + $result = Router::normalize('beer/admin/beers_tags/add'); + $this->assertEqual($result, '/admin/beers_tags/add'); + + $result = Router::normalize('/admin/beers_tags/add'); + $this->assertEqual($result, '/admin/beers_tags/add'); } /** * testUrlGeneration method From c1bb9700f94307f7ec0af610dbaa53db7516fbf8 Mon Sep 17 00:00:00 2001 From: gwoo Date: Tue, 21 Jul 2009 01:31:50 +0000 Subject: [PATCH 50/95] fixes #6509, dispatcher uri error on IIS git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8237 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/dispatcher.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cake/dispatcher.php b/cake/dispatcher.php index 9756c841a..36a139eaf 100644 --- a/cake/dispatcher.php +++ b/cake/dispatcher.php @@ -515,10 +515,10 @@ class Dispatcher extends Object { parse_str($uri[1], $_GET); } $uri = $uri[0]; - } elseif (empty($uri) && is_string(env('QUERY_STRING'))) { + } else { $uri = env('QUERY_STRING'); } - if (strpos($uri, 'index.php') !== false) { + if (is_string($uri) && strpos($uri, 'index.php') !== false) { list(, $uri) = explode('index.php', $uri, 2); } if (empty($uri) || $uri == '/' || $uri == '//') { From 4cfdd311a90a8749ba4d45c43dc19d89355cedd5 Mon Sep 17 00:00:00 2001 From: gwoo Date: Tue, 21 Jul 2009 01:33:12 +0000 Subject: [PATCH 51/95] fixes #6476, crash on missing layout in session flash git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8238 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/helpers/session.php | 8 +-- cake/libs/view/view.php | 6 ++- .../cases/libs/view/helpers/session.test.php | 52 +++++++++++++++++++ 3 files changed, 61 insertions(+), 5 deletions(-) diff --git a/cake/libs/view/helpers/session.php b/cake/libs/view/helpers/session.php index adc0813dd..d78170ab1 100644 --- a/cake/libs/view/helpers/session.php +++ b/cake/libs/view/helpers/session.php @@ -142,10 +142,10 @@ class SessionHelper extends CakeSession { $out = $flash['message']; } else { $view =& ClassRegistry::getObject('view'); - list($tmpLayout, $tmpVars, $tmpTitle) = array($view->layout, $view->viewVars, $view->pageTitle); - list($view->layout, $view->viewVars, $view->pageTitle) = array($flash['layout'], $flash['params'], ''); - $out = $view->renderLayout($flash['message']); - list($view->layout, $view->viewVars, $view->pageTitle) = array($tmpLayout, $tmpVars, $tmpTitle); + list($tmpVars, $tmpTitle) = array($view->viewVars, $view->pageTitle); + list($view->viewVars, $view->pageTitle) = array($flash['params'], ''); + $out = $view->renderLayout($flash['message'], $flash['layout']); + list($view->viewVars, $view->pageTitle) = array($tmpVars, $tmpTitle); } echo($out); parent::del('Message.' . $key); diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index 80b29d21c..1604debfb 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -417,6 +417,10 @@ class View extends Object { */ function renderLayout($content_for_layout, $layout = null) { $layoutFileName = $this->_getLayoutFileName($layout); + if (empty($layoutFileName)) { + return $this->output; + } + $debug = ''; if (isset($this->viewVars['cakeDebug']) && Configure::read() > 2) { @@ -892,7 +896,7 @@ class View extends Object { $paths = array(); $viewPaths = Configure::read('viewPaths'); - if ($plugin !== null) { + if (!empty($plugin)) { $count = count($viewPaths); for ($i = 0; $i < $count; $i++) { $paths[] = $viewPaths[$i] . 'plugins' . DS . $plugin . DS; diff --git a/cake/tests/cases/libs/view/helpers/session.test.php b/cake/tests/cases/libs/view/helpers/session.test.php index 270194bd3..06947b2b6 100644 --- a/cake/tests/cases/libs/view/helpers/session.test.php +++ b/cake/tests/cases/libs/view/helpers/session.test.php @@ -27,6 +27,26 @@ if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) { define('CAKEPHP_UNIT_TEST_EXECUTION', 1); } +if (!class_exists('AppError')) { +App::import('Error'); + /** + * AppController class + * + * @package cake + * @subpackage cake.tests.cases.libs + */ + class AppError extends ErrorHandler { + /** + * _stop method + * + * @access public + * @return void + */ + function _stop() { + return; + } + } +} App::import('Core', array('Helper', 'AppHelper', 'Controller', 'View')); App::import('Helper', array('Session')); /** @@ -143,7 +163,9 @@ class SessionHelperTest extends CakeTestCase { $result = ob_get_clean(); $this->assertEqual($result, $expected); + $_viewPaths = Configure::read('viewPaths'); Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)); + $controller = new Controller(); $this->Session->view = new View($controller); @@ -165,6 +187,36 @@ class SessionHelperTest extends CakeTestCase { $expected = 'Bare message'; $this->assertEqual($result, $expected); $this->assertFalse($this->Session->check('Message.bare')); + + Configure::write('viewPaths', $_viewPaths); + } +/** + * testFlash method + * + * @access public + * @return void + */ + function testFlashMissingLayout() { + $_SESSION = array( + 'Message' => array( + 'notification' => array( + 'layout' => 'does_not_exist', + 'params' => array('title' => 'Notice!', 'name' => 'Alert!'), + 'message' => 'This is a test of the emergency broadcasting system', + ) + ) + ); + + $controller = new Controller(); + $this->Session->view = new View($controller); + + ob_start(); + $this->Session->flash('notification'); + $result = ob_get_contents(); + ob_clean(); + + $this->assertPattern("/Missing Layout/", $result); + $this->assertPattern("/layouts\/does_not_exist.ctp/", $result); } /** * testID method From 56bee6e1fc511f813c181082ffb38018db180906 Mon Sep 17 00:00:00 2001 From: gwoo Date: Tue, 21 Jul 2009 01:53:14 +0000 Subject: [PATCH 52/95] fixes #6507 paginator sort directions git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8239 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/helpers/paginator.php | 3 ++- cake/tests/cases/libs/view/helpers/paginator.test.php | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php index 21925dcee..4cb57c406 100644 --- a/cake/libs/view/helpers/paginator.php +++ b/cake/libs/view/helpers/paginator.php @@ -226,11 +226,12 @@ class PaginatorHelper extends AppHelper { } $dir = 'asc'; $sortKey = $this->sortKey($options['model']); - $isSorted = ($sortKey === $key); + $isSorted = ($sortKey === $key || $sortKey === $this->defaultModel() . '.' . $key); if ($isSorted && $this->sortDir($options['model']) === 'asc') { $dir = 'desc'; } + if (is_array($title) && array_key_exists($dir, $title)) { $title = $title[$dir]; } diff --git a/cake/tests/cases/libs/view/helpers/paginator.test.php b/cake/tests/cases/libs/view/helpers/paginator.test.php index 30a8eeff5..bbd81b53a 100644 --- a/cake/tests/cases/libs/view/helpers/paginator.test.php +++ b/cake/tests/cases/libs/view/helpers/paginator.test.php @@ -153,6 +153,17 @@ class PaginatorHelperTest extends CakeTestCase { $this->Paginator->params['paging']['Article']['options']['sort'] = 'title'; $result = $this->Paginator->sort(array('asc' => 'ascending', 'desc' => 'descending'), 'title'); $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc">descending<\/a>$/', $result); + + $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'desc'); + $this->Paginator->params['paging']['Article']['options']['sort'] = null; + $result = $this->Paginator->sort('title'); + $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc">Title<\/a>$/', $result); + + + $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc'); + $this->Paginator->params['paging']['Article']['options']['sort'] = null; + $result = $this->Paginator->sort('title'); + $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc">Title<\/a>$/', $result); } /** * testSortLinksUsingDotNotation method From f9ff43b35267c34b28b84469594c54595c6278c0 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 21 Jul 2009 02:59:30 +0000 Subject: [PATCH 53/95] Refactoring paginator.test.php to use assertTags() where it makes sense. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8240 3807eeeb-6ff5-0310-8944-8be069107fe0 --- .../libs/view/helpers/paginator.test.php | 468 +++++++++++++----- 1 file changed, 341 insertions(+), 127 deletions(-) diff --git a/cake/tests/cases/libs/view/helpers/paginator.test.php b/cake/tests/cases/libs/view/helpers/paginator.test.php index bbd81b53a..83a798420 100644 --- a/cake/tests/cases/libs/view/helpers/paginator.test.php +++ b/cake/tests/cases/libs/view/helpers/paginator.test.php @@ -116,9 +116,11 @@ class PaginatorHelperTest extends CakeTestCase { $this->assertEqual($result, $expected); $this->Paginator->params['paging']['Article']['prevPage'] = false; - $result = $this->Paginator->prev('prev', array('update'=> 'theList', 'indicator'=> 'loading', 'url'=> array('controller' => 'posts')), null, array('class' => 'disabled', 'tag' => 'span')); - $expected = 'prev'; - $this->assertEqual($result, $expected); + $result = $this->Paginator->prev('prev', array('update' => 'theList', 'indicator' => 'loading', 'url' => array('controller' => 'posts')), null, array('class' => 'disabled', 'tag' => 'span')); + $expected = array( + 'span' => array('class' => 'disabled'), 'prev', '/span' + ); + $this->assertTags($result, $expected); } /** * testSortLinks method @@ -135,31 +137,56 @@ class PaginatorHelperTest extends CakeTestCase { )); $this->Paginator->options(array('url' => array('param'))); $result = $this->Paginator->sort('title'); - $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:asc">Title<\/a>$/', $result); + $expected = array( + 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:title/direction:asc'), + 'Title', + '/a' + ); + $this->assertTags($result, $expected); $result = $this->Paginator->sort('date'); - $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:date\/direction:desc">Date<\/a>$/', $result); + $expected = array( + 'a' => array('href' => '/officespace/accounts/index/param/page:1/sort:date/direction:desc'), + 'Date', + '/a' + ); + $this->assertTags($result, $expected); $result = $this->Paginator->numbers(array('modulus'=> '2', 'url'=> array('controller'=>'projects', 'action'=>'sort'),'update'=>'list')); $this->assertPattern('/\/projects\/sort\/page:2/', $result); $this->assertPattern('/