From 0fb4d1d3d8f832f9d25c887dd394e1025a4db046 Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 4 Oct 2012 00:24:27 +0530 Subject: [PATCH 01/85] Removing unneeded App::uses() call --- lib/Cake/Error/ErrorHandler.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Cake/Error/ErrorHandler.php b/lib/Cake/Error/ErrorHandler.php index dcc0973c9..87a605835 100644 --- a/lib/Cake/Error/ErrorHandler.php +++ b/lib/Cake/Error/ErrorHandler.php @@ -22,7 +22,6 @@ App::uses('Debugger', 'Utility'); App::uses('CakeLog', 'Log'); App::uses('ExceptionRenderer', 'Error'); -App::uses('AppController', 'Controller'); /** * From 972d5752bfe3102a2b756b8d2425c83ba617410a Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 4 Oct 2012 20:41:02 -0400 Subject: [PATCH 02/85] Improve error message. Fixture datasources must begin with test so you don't accidentally use a real datasource. Fixes #3254 --- lib/Cake/TestSuite/Fixture/CakeTestFixture.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php index db16cfff6..82f2ba9e1 100644 --- a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php +++ b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php @@ -75,7 +75,13 @@ class CakeTestFixture { if (!empty($this->useDbConfig)) { $connection = $this->useDbConfig; if (strpos($connection, 'test') !== 0) { - throw new CakeException(__d('cake_dev', 'Invalid datasource %s for object %s', $connection, $this->name)); + $message = __d( + 'cake_dev', + 'Invalid datasource name "%s" for "%s" fixture. Fixture datasource names must begin with "test".', + $connection, + $this->name + ); + throw new CakeException($message); } } $this->Schema = new CakeSchema(array('name' => 'TestSuite', 'connection' => $connection)); From e85b2a072a07f5b5489ab59625f433e167095b24 Mon Sep 17 00:00:00 2001 From: euromark Date: Sun, 7 Oct 2012 14:17:31 +0200 Subject: [PATCH 03/85] fix validation error domain for notEmpty $this->_validationDomain for default notEmpty message notEmpty default error message --- lib/Cake/Model/Validator/CakeValidationSet.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Model/Validator/CakeValidationSet.php b/lib/Cake/Model/Validator/CakeValidationSet.php index 3451f8103..60d41c6fe 100644 --- a/lib/Cake/Model/Validator/CakeValidationSet.php +++ b/lib/Cake/Model/Validator/CakeValidationSet.php @@ -280,7 +280,7 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable { $message = __d($this->_validationDomain, $name); } } else { - $message = __d('cake_dev', 'This field cannot be left blank'); + $message = __d('cake', 'This field cannot be left blank'); } return $message; From 2232c7e15d34f9530bd33420b0c020e09cd8275b Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 8 Oct 2012 09:46:58 -0400 Subject: [PATCH 04/85] Update doc blocks to reflect reality. Closes #3263 --- lib/Cake/Utility/Set.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Utility/Set.php b/lib/Cake/Utility/Set.php index 3bfa00882..7ac63cfbe 100644 --- a/lib/Cake/Utility/Set.php +++ b/lib/Cake/Utility/Set.php @@ -533,7 +533,7 @@ class Set { * * @param array $data Array from where to extract * @param string|array $path As an array, or as a dot-separated string. - * @return array Extracted data + * @return array|null Extracted data or null when $data or $path are empty. * @link http://book.cakephp.org/2.0/en/core-utility-libraries/set.html#Set::classicExtract */ public static function classicExtract($data, $path = null) { From a59db11e4eaa02d8e9fdbdd9aa30dbce7297b397 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 8 Oct 2012 11:41:32 -0400 Subject: [PATCH 05/85] Update doc blocks for logging + scopes. --- lib/Cake/Log/CakeLog.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Log/CakeLog.php b/lib/Cake/Log/CakeLog.php index ad5a411c1..39c6b8b08 100644 --- a/lib/Cake/Log/CakeLog.php +++ b/lib/Cake/Log/CakeLog.php @@ -67,6 +67,7 @@ App::uses('LogEngineCollection', 'Log'); * application. By using scopes you can control logging for each part * of your application and still keep standard log levels. * + * * See CakeLog::config() and CakeLog::write() for more information * on scopes * @@ -173,7 +174,10 @@ class CakeLog { * * The above logger will only capture log entries made in the * `payment` and `order` scopes. All other scopes including the - * undefined scope will be ignored. + * undefined scope will be ignored. Its important to remember that + * when using scopes you must also define the `types` of log messages + * that a logger will handle. Failing to do so will result in the logger + * catching all log messages even if the scope is incorrect. * * @param string $key The keyname for this logger, used to remove the * logger later. From 72f4d4fac09645c99c8443ec995b67a11eb1eeea Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 8 Oct 2012 12:57:02 -0400 Subject: [PATCH 06/85] Fix issue with logging scopes Logging scopes should be exclusive and not allow messages matching on level alone to be logged. By using scopes + levels you opt-in to new behavior so grabbing all messages by level should not occur. Fixes #3264 --- lib/Cake/Log/CakeLog.php | 33 +++++++++------- lib/Cake/Test/Case/Log/CakeLogTest.php | 53 +++++++++++++++++--------- 2 files changed, 55 insertions(+), 31 deletions(-) diff --git a/lib/Cake/Log/CakeLog.php b/lib/Cake/Log/CakeLog.php index 39c6b8b08..776ea9e6f 100644 --- a/lib/Cake/Log/CakeLog.php +++ b/lib/Cake/Log/CakeLog.php @@ -426,24 +426,29 @@ class CakeLog { $logged = false; foreach (self::$_Collection->enabled() as $streamName) { $logger = self::$_Collection->{$streamName}; - $types = null; - $scopes = array(); + $types = $scopes = $config = array(); if ($logger instanceof BaseLog) { $config = $logger->config(); - if (isset($config['types'])) { - $types = $config['types']; - } - if (isset($config['scopes'])) { - $scopes = $config['scopes']; - } } - if (is_string($scope)) { - $inScope = in_array($scope, $scopes); - } else { - $intersect = array_intersect($scope, $scopes); - $inScope = !empty($intersect); + if (isset($config['types'])) { + $types = $config['types']; } - if (empty($types) || in_array($type, $types) || in_array($type, $scopes) && $inScope) { + if (isset($config['scopes'])) { + $scopes = $config['scopes']; + } + $inScope = (count(array_intersect((array)$scope, $scopes)) > 0); + $correctLevel = in_array($type, $types); + + if ( + // No config is a catch all (bc mode) + (empty($types) && empty($scopes)) || + // BC layer for mixing scope & level + (in_array($type, $scopes)) || + // no scopes, but has level + (empty($scopes) && $correctLevel) || + // exact scope + level + ($correctLevel && $inScope) + ) { $logger->write($type, $message); $logged = true; } diff --git a/lib/Cake/Test/Case/Log/CakeLogTest.php b/lib/Cake/Test/Case/Log/CakeLogTest.php index 39f715eba..e54f2c71a 100644 --- a/lib/Cake/Test/Case/Log/CakeLogTest.php +++ b/lib/Cake/Test/Case/Log/CakeLogTest.php @@ -331,21 +331,22 @@ class CakeLogTest extends CakeTestCase { /** * test backward compatible scoped logging + * + * @return void */ public function testScopedLoggingBC() { - $this->_deleteLogs(); - $this->_resetLogConfig(); + CakeLog::config('shops', array( 'engine' => 'FileLog', 'types' => array('info', 'notice', 'warning'), 'scopes' => array('transactions', 'orders'), 'file' => 'shops', - )); + )); + $this->_deleteLogs(); CakeLog::write('info', 'info message'); $this->assertFalse(file_exists(LOGS . 'error.log')); - $this->assertTrue(file_exists(LOGS . 'shops.log')); $this->assertTrue(file_exists(LOGS . 'debug.log')); $this->_deleteLogs(); @@ -375,7 +376,6 @@ class CakeLogTest extends CakeTestCase { CakeLog::write('warning', 'warning message'); $this->assertTrue(file_exists(LOGS . 'error.log')); - $this->assertTrue(file_exists(LOGS . 'shops.log')); $this->assertFalse(file_exists(LOGS . 'debug.log')); $this->_deleteLogs(); @@ -383,29 +383,48 @@ class CakeLogTest extends CakeTestCase { CakeLog::drop('shops'); } + + public function testScopedLoggingExclusive() { + $this->_deleteLogs(); + + CakeLog::config('shops', array( + 'engine' => 'FileLog', + 'types' => array('info', 'notice', 'warning'), + 'scopes' => array('transactions', 'orders'), + 'file' => 'shops.log', + )); + CakeLog::config('eggs', array( + 'engine' => 'FileLog', + 'types' => array('info', 'notice', 'warning'), + 'scopes' => array('eggs'), + 'file' => 'eggs.log', + )); + + CakeLog::write('info', 'transactions message', 'transactions'); + $this->assertFalse(file_exists(LOGS . 'eggs.log')); + $this->assertTrue(file_exists(LOGS . 'shops.log')); + + $this->_deleteLogs(); + + CakeLog::write('info', 'eggs message', 'eggs'); + $this->assertTrue(file_exists(LOGS . 'eggs.log')); + $this->assertFalse(file_exists(LOGS . 'shops.log')); + } + /** * test scoped logging * * @return void */ public function testScopedLogging() { - if (file_exists(LOGS . 'shops.log')) { - unlink(LOGS . 'shops.log'); - } - if (file_exists(LOGS . 'error.log')) { - unlink(LOGS . 'error.log'); - } - if (file_exists(LOGS . 'debug.log')) { - unlink(LOGS . 'debug.log'); - } - $this->_resetLogConfig(); + $this->_deleteLogs(); CakeLog::config('shops', array( 'engine' => 'FileLog', 'types' => array('info', 'notice', 'warning'), 'scopes' => array('transactions', 'orders'), - 'file' => 'shops', - )); + 'file' => 'shops.log', + )); CakeLog::write('info', 'info message', 'transactions'); $this->assertFalse(file_exists(LOGS . 'error.log')); From 1234f96a6cffbfe4d5e1804007e5650315582015 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 8 Oct 2012 20:15:03 -0400 Subject: [PATCH 07/85] Update version number to 2.2.3 --- lib/Cake/VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/VERSION.txt b/lib/Cake/VERSION.txt index ce21ea75c..702a3d46a 100644 --- a/lib/Cake/VERSION.txt +++ b/lib/Cake/VERSION.txt @@ -17,4 +17,4 @@ // @license MIT License (http://www.opensource.org/licenses/mit-license.php) // +--------------------------------------------------------------------------------------------+ // //////////////////////////////////////////////////////////////////////////////////////////////////// -2.2.2 +2.2.3 From 33a879ff411928429a5b0188a68eecd9632f87e3 Mon Sep 17 00:00:00 2001 From: ADmad Date: Tue, 9 Oct 2012 10:43:27 +0530 Subject: [PATCH 08/85] Fix find('count') with 'group' when result has only one group. Closes #1677 --- lib/Cake/Model/Model.php | 4 ++-- lib/Cake/Test/Case/Model/ModelReadTest.php | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index b597ae297..9dd82b6b5 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -2749,8 +2749,8 @@ class Model extends Object implements CakeEventListener { } elseif ($state === 'after') { foreach (array(0, $this->alias) as $key) { if (isset($results[0][$key]['count'])) { - if (($count = count($results)) > 1) { - return $count; + if ($query['group']) { + return count($results); } else { return intval($results[0][$key]['count']); } diff --git a/lib/Cake/Test/Case/Model/ModelReadTest.php b/lib/Cake/Test/Case/Model/ModelReadTest.php index 7209e0216..6f14e47a2 100644 --- a/lib/Cake/Test/Case/Model/ModelReadTest.php +++ b/lib/Cake/Test/Case/Model/ModelReadTest.php @@ -6860,6 +6860,17 @@ class ModelReadTest extends BaseModelTest { )); $result = $Article->find('count', array('group' => array('Article.user_id'))); $this->assertEquals($expected, $result); + + $expected = count($Article->find('all', array( + 'fields' => array('Article.user_id'), + 'conditions' => array('Article.user_id' => 1), + 'group' => 'Article.user_id') + )); + $result = $Article->find('count', array( + 'conditions' => array('Article.user_id' => 1), + 'group' => array('Article.user_id'), + )); + $this->assertEquals($expected, $result); } /** @@ -6886,7 +6897,7 @@ class ModelReadTest extends BaseModelTest { $this->skipIf($this->db instanceof Sqlite, 'SELECT COUNT(DISTINCT field) is not compatible with SQLite.'); $this->skipIf($this->db instanceof Sqlserver, 'This test is not compatible with SQL Server.'); - $this->loadFixtures('Project'); + $this->loadFixtures('Project', 'Thread'); $TestModel = new Project(); $TestModel->create(array('name' => 'project')) && $TestModel->save(); $TestModel->create(array('name' => 'project')) && $TestModel->save(); From 2cff67184fdc135045d294b1e8e8d50147674f9c Mon Sep 17 00:00:00 2001 From: euromark Date: Tue, 9 Oct 2012 11:49:44 +0200 Subject: [PATCH 09/85] avoid offset -1 error on tests etc --- lib/Cake/Routing/Router.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Routing/Router.php b/lib/Cake/Routing/Router.php index 2c56c5290..0d936f3d9 100644 --- a/lib/Cake/Routing/Router.php +++ b/lib/Cake/Routing/Router.php @@ -633,8 +633,8 @@ class Router { * @return array Parameter information */ public static function getParams($current = false) { - if ($current) { - return self::$_requests[count(self::$_requests) - 1]->params; + if ($current && ($count = count(self::$_requests)) > 0) { + return self::$_requests[$count - 1]->params; } if (isset(self::$_requests[0])) { return self::$_requests[0]->params; From 0197700e4fd054cdb8165a01d2b152af2f85c043 Mon Sep 17 00:00:00 2001 From: euromark Date: Tue, 9 Oct 2012 12:24:10 +0200 Subject: [PATCH 10/85] simplify check --- lib/Cake/Routing/Router.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Routing/Router.php b/lib/Cake/Routing/Router.php index 0d936f3d9..2a02570cd 100644 --- a/lib/Cake/Routing/Router.php +++ b/lib/Cake/Routing/Router.php @@ -633,8 +633,8 @@ class Router { * @return array Parameter information */ public static function getParams($current = false) { - if ($current && ($count = count(self::$_requests)) > 0) { - return self::$_requests[$count - 1]->params; + if ($current && self::$_requests) { + return self::$_requests[count(self::$_requests) - 1]->params; } if (isset(self::$_requests[0])) { return self::$_requests[0]->params; From 5de492fb25d441837bdc36f8596acd461faff82a Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 10 Oct 2012 17:21:16 +0530 Subject: [PATCH 11/85] Allow saving new records with pre specified primary key value with treebehavior. --- lib/Cake/Model/Behavior/TreeBehavior.php | 2 +- .../Model/Behavior/TreeBehaviorNumberTest.php | 30 +++++++++++++++++ .../Model/Behavior/TreeBehaviorUuidTest.php | 32 +++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Model/Behavior/TreeBehavior.php b/lib/Cake/Model/Behavior/TreeBehavior.php index eb316a4d7..6895fe9d0 100644 --- a/lib/Cake/Model/Behavior/TreeBehavior.php +++ b/lib/Cake/Model/Behavior/TreeBehavior.php @@ -178,7 +178,7 @@ class TreeBehavior extends ModelBehavior { extract($this->settings[$Model->alias]); $this->_addToWhitelist($Model, array($left, $right)); - if (!$Model->id) { + if (!$Model->id || !$Model->exists()) { if (array_key_exists($parent, $Model->data[$Model->alias]) && $Model->data[$Model->alias][$parent]) { $parentNode = $Model->find('first', array( 'conditions' => array($scope, $Model->escapeField() => $Model->data[$Model->alias][$parent]), diff --git a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php index d93c6334e..f234a8cce 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php @@ -369,6 +369,36 @@ class TreeBehaviorNumberTest extends CakeTestCase { $this->assertSame($validTree, true); } +/** + * testAddWithPreSpecifiedId method + * + * @return void + */ + public function testAddWithPreSpecifiedId() { + extract($this->settings); + $this->Tree = new $modelClass(); + $this->Tree->initialize(2, 2); + + $data = $this->Tree->find('first', array( + 'fields' => array('id'), + 'conditions' => array($modelClass . '.name' => '1.1') + )); + + $this->Tree->create(); + $result = $this->Tree->save(array($modelClass => array( + 'id' => 100, + 'name' => 'testAddMiddle', + $parentField => $data[$modelClass]['id']) + )); + $expected = array_merge( + array($modelClass => array('id' => 100, 'name' => 'testAddMiddle', $parentField => '2')), + $result + ); + $this->assertSame($expected, $result); + + $this->assertTrue($this->Tree->verify()); + } + /** * testAddInvalid method * diff --git a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorUuidTest.php b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorUuidTest.php index a69445ef9..bd3590b3c 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorUuidTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorUuidTest.php @@ -21,6 +21,7 @@ App::uses('Model', 'Model'); App::uses('AppModel', 'Model'); +App::uses('String', 'Utility'); require_once dirname(dirname(__FILE__)) . DS . 'models.php'; /** @@ -56,6 +57,37 @@ class TreeBehaviorUuidTest extends CakeTestCase { */ public $fixtures = array('core.uuid_tree'); +/** + * testAddWithPreSpecifiedId method + * + * @return void + */ + public function testAddWithPreSpecifiedId() { + extract($this->settings); + $this->Tree = new $modelClass(); + $this->Tree->initialize(2, 2); + + $data = $this->Tree->find('first', array( + 'fields' => array('id'), + 'conditions' => array($modelClass . '.name' => '1.1') + )); + + $id = String::uuid(); + $this->Tree->create(); + $result = $this->Tree->save(array($modelClass => array( + 'id' => $id, + 'name' => 'testAddMiddle', + $parentField => $data[$modelClass]['id']) + )); + $expected = array_merge( + array($modelClass => array('id' => $id, 'name' => 'testAddMiddle', $parentField => '2')), + $result + ); + $this->assertSame($expected, $result); + + $this->assertTrue($this->Tree->verify()); + } + /** * testMovePromote method * From f06bdde8c6c57869ec7de718b6ae5d0b6bcad674 Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 11 Oct 2012 12:33:46 +0530 Subject: [PATCH 12/85] Fix docblock --- lib/Cake/Model/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 9dd82b6b5..51c3ed494 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -1082,7 +1082,7 @@ class Model extends Object implements CakeEventListener { } /** - * Sets a custom table for your controller class. Used by your controller to select a database table. + * Sets a custom table for your model class. Used by your controller to select a database table. * * @param string $tableName Name of the custom table * @throws MissingTableException when database table $tableName is not found on data source From 1e2ac0b9c8f8b00e322242bb24dca9e546d59fba Mon Sep 17 00:00:00 2001 From: euromark Date: Thu, 11 Oct 2012 14:03:59 +0200 Subject: [PATCH 13/85] comp mod for saveAll() better approach test case to assert saveAll still behaves like previous versions --- lib/Cake/Model/Model.php | 2 +- lib/Cake/Test/Case/Model/ModelWriteTest.php | 28 ++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 9dd82b6b5..101fac91f 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -2017,7 +2017,7 @@ class Model extends Object implements CakeEventListener { * @link http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-saveassociated-array-data-null-array-options-array * @link http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-saveall-array-data-null-array-options-array */ - public function saveAll($data, $options = array()) { + public function saveAll($data = array(), $options = array()) { $options = array_merge(array('validate' => 'first'), $options); if (Hash::numeric(array_keys($data))) { if ($options['validate'] === 'only') { diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index 31327e7de..c7976412e 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -4725,6 +4725,32 @@ class ModelWriteTest extends BaseModelTest { $this->assertEquals($expected, $TestModel->Comment->validationErrors); } +/** + * test that saveAll still behaves like previous versions (does not necessarily need a first argument) + * + * @return void + */ + public function testSaveAllWithSet() { + $this->loadFixtures('Article', 'Tag', 'Comment', 'User', 'ArticlesTag'); + $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(); + $Article->set($data); + $result = $Article->saveAll(); + $this->assertFalse(empty($result)); + } + /** * test that saveAll behaves like plain save() when supplied empty data * @@ -4740,7 +4766,7 @@ class ModelWriteTest extends BaseModelTest { $this->assertFalse(empty($result)); $model = new ProductUpdateAll(); - $result = $model->saveAll(array()); + $result = $model->saveAll(); $this->assertFalse($result); } From b1dfab87e44f4248ea9263627456cab23eb63b5c Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 11 Oct 2012 08:16:51 -0400 Subject: [PATCH 14/85] Fix autoLinkUrls so it re-capture query strings. Fixes #3296 --- lib/Cake/Test/Case/View/Helper/TextHelperTest.php | 15 +++++++++++++++ lib/Cake/View/Helper/TextHelper.php | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php index 2c04eb154..fe7ac135d 100644 --- a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php @@ -181,6 +181,11 @@ class TextHelperTest extends CakeTestCase { $result = $this->Text->autoLinkUrls($text); $this->assertEquals($expected, $result); + $text = 'This is a test that includes www.cakephp.org:8080'; + $expected = 'This is a test that includes www.cakephp.org:8080'; + $result = $this->Text->autoLinkUrls($text); + $this->assertEquals($expected, $result); + $text = 'This is a test that includes http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment'; $expected = 'This is a test that includes http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment'; $result = $this->Text->autoLinkUrls($text); @@ -191,6 +196,16 @@ class TextHelperTest extends CakeTestCase { $result = $this->Text->autoLinkUrls($text); $this->assertEquals($expected, $result); + $text = 'This is a test that includes http://example.com/test.php?foo=bar text'; + $expected = 'This is a test that includes http://example.com/test.php?foo=bar text'; + $result = $this->Text->autoLinkUrls($text); + $this->assertEquals($expected, $result); + + $text = 'This is a test that includes www.example.com/test.php?foo=bar text'; + $expected = 'This is a test that includes www.example.com/test.php?foo=bar text'; + $result = $this->Text->autoLinkUrls($text); + $this->assertEquals($expected, $result); + $text = 'Text with a partial www.cakephp.org URL'; $expected = 'Text with a partial www.cakephp.org URL'; $result = $this->Text->autoLinkUrls($text); diff --git a/lib/Cake/View/Helper/TextHelper.php b/lib/Cake/View/Helper/TextHelper.php index c7523b425..1601a5464 100644 --- a/lib/Cake/View/Helper/TextHelper.php +++ b/lib/Cake/View/Helper/TextHelper.php @@ -101,7 +101,7 @@ class TextHelper extends AppHelper { $this->_placeholders = array(); $options += array('escape' => true); - $pattern = '#(?)((?:https?|ftp|nntp)://[^\s<>()]+\.[a-z]+(?:\/[^\s]+)?)#i'; + $pattern = '#(?)((?:https?|ftp|nntp)://[a-z0-9.\-:]+(?:/[^\s]*)?)#i'; $text = preg_replace_callback( $pattern, array(&$this, '_insertPlaceHolder'), From 8800d7bdec1a2a08999ca7932a3b830a0ec79c6d Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 11 Oct 2012 08:25:15 -0400 Subject: [PATCH 15/85] Reduce duplication in test case. --- .../Test/Case/View/Helper/TextHelperTest.php | 133 ++++++++++-------- 1 file changed, 72 insertions(+), 61 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php index fe7ac135d..eba3ba7ab 100644 --- a/lib/Cake/Test/Case/View/Helper/TextHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/TextHelperTest.php @@ -165,81 +165,92 @@ class TextHelperTest extends CakeTestCase { $this->assertEquals($expected, $result); } +/** + * Data provider for autoLinking + */ + public static function autoLinkProvider() { + return array( + array( + 'This is a test text', + 'This is a test text', + ), + array( + 'This is a test that includes (www.cakephp.org)', + 'This is a test that includes (www.cakephp.org)', + ), + array( + 'This is a test that includes www.cakephp.org:8080', + 'This is a test that includes www.cakephp.org:8080', + ), + array( + 'This is a test that includes http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment', + 'This is a test that includes http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment', + ), + array( + 'This is a test that includes www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment', + 'This is a test that includes www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment', + ), + array( + 'This is a test that includes http://example.com/test.php?foo=bar text', + 'This is a test that includes http://example.com/test.php?foo=bar text', + ), + array( + 'This is a test that includes www.example.com/test.php?foo=bar text', + 'This is a test that includes www.example.com/test.php?foo=bar text', + ), + array( + 'Text with a partial www.cakephp.org URL', + 'Text with a partial www.cakephp.org URL', + ), + array( + 'Text with a partial WWW.cakephp.org URL', + 'Text with a partial WWW.cakephp.org URL', + ), + array( + 'Text with a partial WWW.cakephp.org ©, URL', + 'Text with a partial WWW.cakephp.org &copy, URL', + ), + array( + 'Text with a url www.cot.ag/cuIb2Q and more', + 'Text with a url www.cot.ag/cuIb2Q and more', + ), + array( + 'Text with a url http://www.does--not--work.com and more', + 'Text with a url http://www.does--not--work.com and more', + ), + array( + 'Text with a url http://www.not--work.com and more', + 'Text with a url http://www.not--work.com and more', + ), + ); + } + /** * testAutoLinkUrls method * + * @dataProvider autoLinkProvider + * @return void + */ + public function testAutoLinkUrls($text, $expected) { + $result = $this->Text->autoLinkUrls($text); + $this->assertEquals($expected, $result); + } + +/** + * Test the options for autoLinkUrls + * * @return void */ - public function testAutoLinkUrls() { - $text = 'This is a test text'; - $expected = 'This is a test text'; - $result = $this->Text->autoLinkUrls($text); - $this->assertEquals($expected, $result); - - $text = 'This is a test that includes (www.cakephp.org)'; - $expected = 'This is a test that includes (www.cakephp.org)'; - $result = $this->Text->autoLinkUrls($text); - $this->assertEquals($expected, $result); - - $text = 'This is a test that includes www.cakephp.org:8080'; - $expected = 'This is a test that includes www.cakephp.org:8080'; - $result = $this->Text->autoLinkUrls($text); - $this->assertEquals($expected, $result); - - $text = 'This is a test that includes http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment'; - $expected = 'This is a test that includes http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment'; - $result = $this->Text->autoLinkUrls($text); - $this->assertEquals($expected, $result); - - $text = 'This is a test that includes www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment'; - $expected = 'This is a test that includes www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment'; - $result = $this->Text->autoLinkUrls($text); - $this->assertEquals($expected, $result); - - $text = 'This is a test that includes http://example.com/test.php?foo=bar text'; - $expected = 'This is a test that includes http://example.com/test.php?foo=bar text'; - $result = $this->Text->autoLinkUrls($text); - $this->assertEquals($expected, $result); - - $text = 'This is a test that includes www.example.com/test.php?foo=bar text'; - $expected = 'This is a test that includes www.example.com/test.php?foo=bar text'; - $result = $this->Text->autoLinkUrls($text); - $this->assertEquals($expected, $result); - - $text = 'Text with a partial www.cakephp.org URL'; - $expected = 'Text with a partial www.cakephp.org URL'; - $result = $this->Text->autoLinkUrls($text); - $this->assertRegExp('#^' . $expected . '$#', $result); - + public function testAutoLinkUrlsOptions() { $text = 'Text with a partial www.cakephp.org URL'; $expected = 'Text with a partial www.cakephp.org URL'; $result = $this->Text->autoLinkUrls($text, array('class' => 'link')); $this->assertRegExp('#^' . $expected . '$#', $result); - $text = 'Text with a partial WWW.cakephp.org URL'; - $expected = 'Text with a partial WWW.cakephp.org URL'; - $result = $this->Text->autoLinkUrls($text); - $this->assertRegExp('#^' . $expected . '$#', $result); - $text = 'Text with a partial WWW.cakephp.org © URL'; $expected = 'Text with a partial WWW.cakephp.org © URL'; $result = $this->Text->autoLinkUrls($text, array('escape' => false)); $this->assertRegExp('#^' . $expected . '$#', $result); - - $text = 'Text with a url www.cot.ag/cuIb2Q and more'; - $expected = 'Text with a url www.cot.ag/cuIb2Q and more'; - $result = $this->Text->autoLinkUrls($text); - $this->assertEquals($expected, $result); - - $text = 'Text with a url http://www.does--not--work.com and more'; - $expected = 'Text with a url http://www.does--not--work.com and more'; - $result = $this->Text->autoLinkUrls($text); - $this->assertEquals($expected, $result); - - $text = 'Text with a url http://www.not--work.com and more'; - $expected = 'Text with a url http://www.not--work.com and more'; - $result = $this->Text->autoLinkUrls($text); - $this->assertEquals($expected, $result); } /** From 1110e26483fd0c509b10b096d414ed82004965c0 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 11 Oct 2012 08:39:46 -0400 Subject: [PATCH 16/85] Fix 0'th index file not being copied to $_FILES. Fixes #3256 --- lib/Cake/Network/CakeRequest.php | 2 +- lib/Cake/Test/Case/Network/CakeRequestTest.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index 238793912..39834b2a2 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -319,7 +319,7 @@ class CakeRequest implements ArrayAccess { protected function _processFiles() { if (isset($_FILES) && is_array($_FILES)) { foreach ($_FILES as $name => $data) { - if ($name != 'data') { + if ($name !== 'data') { $this->params['form'][$name] = $data; } } diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index d4d4c9dda..564191c54 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -587,6 +587,24 @@ class CakeRequestTest extends CakeTestCase { $this->assertEquals($request->params['form'], $_FILES); } +/** + * Test that files in the 0th index work. + */ + public function testFilesZeroithIndex() { + $_FILES = array( + 0 => array( + 'name' => 'cake_sqlserver_patch.patch', + 'type' => 'text/plain', + 'tmp_name' => '/private/var/tmp/phpy05Ywj', + 'error' => 0, + 'size' => 6271, + ), + ); + + $request = new CakeRequest('some/path'); + $this->assertEquals($_FILES, $request->params['form']); + } + /** * test method overrides coming in from POST data. * From 2dfb40bac053041dcbe2b59e963f8064ce36df54 Mon Sep 17 00:00:00 2001 From: euromark Date: Thu, 11 Oct 2012 14:54:11 +0200 Subject: [PATCH 17/85] remove duplicate line --- lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php index f234a8cce..adcbf4c58 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php @@ -354,8 +354,6 @@ class TreeBehaviorNumberTest extends CakeTestCase { $expected = array_merge(array($modelClass => array('name' => 'testAddMiddle', $parentField => '2')), $result); $this->assertSame($expected, $result); - $laterCount = $this->Tree->find('count'); - $laterCount = $this->Tree->find('count'); $this->assertEquals($initialCount + 1, $laterCount); From 8bc17996dc22901b30a54a476c4b6bccfe72c705 Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 11 Oct 2012 20:00:30 +0530 Subject: [PATCH 18/85] Update docblock --- lib/Cake/View/Helper/FormHelper.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 9ffab2c1a..301acaaec 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -299,8 +299,9 @@ class FormHelper extends AppHelper { * can be overridden when calling input() * - `encoding` Set the accept-charset encoding for the form. Defaults to `Configure::read('App.encoding')` * - * @param string $model The model object which the form is being defined for. Should + * @param string|array $model The model object which the form is being defined for. Should * include the plugin name for plugin forms. e.g. `ContactManager.Contact`. + * If an array is passed and $options argument is empty, the array will be used as options. * @param array $options An array of html attributes and options. * @return string An formatted opening FORM tag. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-create From 513851d1c1d755a4e85039959adc2c7a77de9fdd Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 13 Oct 2012 02:29:25 -0400 Subject: [PATCH 19/85] Update skel directory logging configuration. --- lib/Cake/Console/Templates/skel/Config/bootstrap.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Console/Templates/skel/Config/bootstrap.php b/lib/Cake/Console/Templates/skel/Config/bootstrap.php index 786011ee5..580f351d0 100644 --- a/lib/Cake/Console/Templates/skel/Config/bootstrap.php +++ b/lib/Cake/Console/Templates/skel/Config/bootstrap.php @@ -98,11 +98,11 @@ Configure::write('Dispatcher.filters', array( App::uses('CakeLog', 'Log'); CakeLog::config('debug', array( 'engine' => 'FileLog', - 'scopes' => array('notice', 'info', 'debug'), + 'types' => array('notice', 'info', 'debug'), 'file' => 'debug', )); CakeLog::config('error', array( 'engine' => 'FileLog', - 'scopes' => array('warning', 'error', 'critical', 'alert', 'emergency'), + 'types' => array('warning', 'error', 'critical', 'alert', 'emergency'), 'file' => 'error', )); From 59f84024e558169b2a79b395779971fce7fa7055 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 14 Oct 2012 11:58:07 -0400 Subject: [PATCH 20/85] Handle REQUEST_URI with domain names properly. Don't depend on parse_url() as it fails with corrupted urls. Instead use FULL_BASE_URL to prepare an absolute path. Fixes #3270 --- lib/Cake/Network/CakeRequest.php | 4 +++- .../Test/Case/Network/CakeRequestTest.php | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index 39834b2a2..bee097565 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -229,8 +229,10 @@ class CakeRequest implements ArrayAccess { protected function _url() { if (!empty($_SERVER['PATH_INFO'])) { return $_SERVER['PATH_INFO']; - } elseif (isset($_SERVER['REQUEST_URI'])) { + } elseif (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '://') === false) { $uri = $_SERVER['REQUEST_URI']; + } elseif (isset($_SERVER['REQUEST_URI'])) { + $uri = substr($_SERVER['REQUEST_URI'], strlen(FULL_BASE_URL)); } elseif (isset($_SERVER['PHP_SELF']) && isset($_SERVER['SCRIPT_NAME'])) { $uri = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['PHP_SELF']); } elseif (isset($_SERVER['HTTP_X_REWRITE_URL'])) { diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index 564191c54..e5ba8f850 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -1646,6 +1646,30 @@ class CakeRequestTest extends CakeTestCase { 'webroot' => '/', ), ), + array( + 'Apache - w/rewrite, document root set above top level cake dir, request root, absolute REQUEST_URI', + array( + 'App' => array( + 'base' => false, + 'baseUrl' => false, + 'dir' => 'app', + 'webroot' => 'webroot' + ), + 'SERVER' => array( + 'SERVER_NAME' => 'localhost', + 'DOCUMENT_ROOT' => '/Library/WebServer/Documents', + 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/index.php', + 'REQUEST_URI' => FULL_BASE_URL . '/site/posts/index', + 'SCRIPT_NAME' => '/site/app/webroot/index.php', + 'PHP_SELF' => '/site/app/webroot/index.php', + ), + ), + array( + 'url' => 'posts/index', + 'base' => '/site', + 'webroot' => '/site/', + ), + ), array( 'Nginx - w/rewrite, document root set to webroot, request root, no PATH_INFO', array( From 3e0fa0009bf91651ddebe9f08265095f9cfb31b3 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 14 Oct 2012 21:30:28 -0400 Subject: [PATCH 21/85] Show the last 200 queries instead of the first 200. Fixes #3273 --- lib/Cake/Model/Datasource/DboSource.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index bae55cff9..ea1c7dbca 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -921,14 +921,14 @@ class DboSource extends DataSource { $this->_queriesCnt++; $this->_queriesTime += $this->took; $this->_queriesLog[] = array( - 'query' => $sql, - 'params' => $params, - 'affected' => $this->affected, - 'numRows' => $this->numRows, - 'took' => $this->took + 'query' => $sql, + 'params' => $params, + 'affected' => $this->affected, + 'numRows' => $this->numRows, + 'took' => $this->took ); if (count($this->_queriesLog) > $this->_queriesLogMax) { - array_pop($this->_queriesLog); + array_shift($this->_queriesLog); } } From 2a803ea412b36467eea68e8fe54cb7292aa48ee1 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 14 Oct 2012 22:22:46 -0400 Subject: [PATCH 22/85] Add missing import Refs GH-877 --- lib/Cake/TestSuite/CakeTestRunner.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Cake/TestSuite/CakeTestRunner.php b/lib/Cake/TestSuite/CakeTestRunner.php index e2f39cddd..ad96c9783 100644 --- a/lib/Cake/TestSuite/CakeTestRunner.php +++ b/lib/Cake/TestSuite/CakeTestRunner.php @@ -17,6 +17,8 @@ */ require_once 'PHPUnit/TextUI/TestRunner.php'; +App::uses('CakeFixtureManager', 'TestSuite/Fixture'); + /** * A custom test runner for Cake's use of PHPUnit. * From 4090c2e9323e5e3d2112ee7f2f831bd5e5d292a4 Mon Sep 17 00:00:00 2001 From: Adam Taylor Date: Mon, 15 Oct 2012 18:19:22 -0600 Subject: [PATCH 23/85] Remove trailing whitespace from comments See http://groups.google.com/d/topic/cakephp-core/fuHTYMKVJno/discussion --- app/Config/acl.php | 36 +++++++++---------- app/Config/bootstrap.php | 2 +- app/Config/core.php | 4 +-- app/Config/routes.php | 2 +- lib/Cake/Cache/CacheEngine.php | 2 +- lib/Cake/Cache/Engine/FileEngine.php | 2 +- .../Console/Command/Task/TemplateTask.php | 2 +- lib/Cake/Console/Command/TestShell.php | 4 +-- .../Console/Templates/skel/Config/core.php | 2 +- lib/Cake/Controller/Component.php | 2 +- lib/Cake/Controller/Component/Acl/IniAcl.php | 2 +- lib/Cake/Controller/Component/Acl/PhpAcl.php | 34 +++++++++--------- .../Component/Auth/DigestAuthenticate.php | 2 +- .../Controller/Component/CookieComponent.php | 2 +- .../Component/SecurityComponent.php | 2 +- .../Controller/Component/SessionComponent.php | 4 +-- lib/Cake/Core/CakePlugin.php | 2 +- lib/Cake/Event/CakeEvent.php | 2 +- lib/Cake/Event/CakeEventManager.php | 6 ++-- .../Model/Behavior/ContainableBehavior.php | 4 +-- lib/Cake/Model/ConnectionManager.php | 2 +- lib/Cake/Model/Datasource/DataSource.php | 2 +- .../Model/Datasource/Database/Sqlserver.php | 2 +- lib/Cake/Network/Email/CakeEmail.php | 6 ++-- .../Test/Case/Cache/Engine/FileEngineTest.php | 2 +- .../Case/Console/Command/TestShellTest.php | 16 ++++----- .../Test/Case/Event/CakeEventManagerTest.php | 2 +- .../Case/Model/Datasource/DataSourceTest.php | 2 +- .../Case/TestSuite/CakeTestFixtureTest.php | 2 +- .../Test/Case/TestSuite/CakeTestSuiteTest.php | 8 ++--- .../TestSuite/Fixture/CakeTestFixture.php | 2 +- lib/Cake/Utility/File.php | 2 +- lib/Cake/View/Helper/SessionHelper.php | 2 +- lib/Cake/View/JsonView.php | 12 +++---- lib/Cake/View/ViewBlock.php | 2 +- 35 files changed, 91 insertions(+), 91 deletions(-) diff --git a/app/Config/acl.php b/app/Config/acl.php index 21f8ddaa7..3df822ab4 100644 --- a/app/Config/acl.php +++ b/app/Config/acl.php @@ -22,18 +22,18 @@ /** * Example * ------- - * + * * Assumptions: * - * 1. In your application you created a User model with the following properties: + * 1. In your application you created a User model with the following properties: * username, group_id, password, email, firstname, lastname and so on. - * 2. You configured AuthComponent to authorize actions via - * $this->Auth->authorize = array('Actions' => array('actionPath' => 'controllers/'),...) - * + * 2. You configured AuthComponent to authorize actions via + * $this->Auth->authorize = array('Actions' => array('actionPath' => 'controllers/'),...) + * * Now, when a user (i.e. jeff) authenticates successfully and requests a controller action (i.e. /invoices/delete) - * that is not allowed by default (e.g. via $this->Auth->allow('edit') in the Invoices controller) then AuthComponent - * will ask the configured ACL interface if access is granted. Under the assumptions 1. and 2. this will be - * done via a call to Acl->check() with + * that is not allowed by default (e.g. via $this->Auth->allow('edit') in the Invoices controller) then AuthComponent + * will ask the configured ACL interface if access is granted. Under the assumptions 1. and 2. this will be + * done via a call to Acl->check() with * * array('User' => array('username' => 'jeff', 'group_id' => 4, ...)) * @@ -42,7 +42,7 @@ * '/controllers/invoices/delete' * * as ACO. - * + * * If the configured map looks like * * $config['map'] = array( @@ -50,17 +50,17 @@ * 'Role' => 'User/group_id', * ); * - * then PhpAcl will lookup if we defined a role like User/jeff. If that role is not found, PhpAcl will try to - * find a definition for Role/4. If the definition isn't found then a default role (Role/default) will be used to + * then PhpAcl will lookup if we defined a role like User/jeff. If that role is not found, PhpAcl will try to + * find a definition for Role/4. If the definition isn't found then a default role (Role/default) will be used to * check rules for the given ACO. The search can be expanded by defining aliases in the alias configuration. * E.g. if you want to use a more readable name than Role/4 in your definitions you can define an alias like * * $config['alias'] = array( * 'Role/4' => 'Role/editor', * ); - * + * * In the roles configuration you can define roles on the lhs and inherited roles on the rhs: - * + * * $config['roles'] = array( * 'Role/admin' => null, * 'Role/accountant' => null, @@ -68,7 +68,7 @@ * 'Role/manager' => 'Role/editor, Role/accountant', * 'User/jeff' => 'Role/manager', * ); - * + * * In this example manager inherits all rules from editor and accountant. Role/admin doesn't inherit from any role. * Lets define some rules: * @@ -87,10 +87,10 @@ * ), * ); * - * Ok, so as jeff inherits from Role/manager he's matched every rule that references User/jeff, Role/manager, - * Role/editor, Role/accountant and Role/default. However, for jeff, rules for User/jeff are more specific than + * Ok, so as jeff inherits from Role/manager he's matched every rule that references User/jeff, Role/manager, + * Role/editor, Role/accountant and Role/default. However, for jeff, rules for User/jeff are more specific than * rules for Role/manager, rules for Role/manager are more specific than rules for Role/editor and so on. - * This is important when allow and deny rules match for a role. E.g. Role/accountant is allowed + * This is important when allow and deny rules match for a role. E.g. Role/accountant is allowed * controllers/invoices/* but at the same time controllers/invoices/delete is denied. But there is a more * specific rule defined for Role/manager which is allowed controllers/invoices/delete. However, the most specific * rule denies access to the delete action explicitly for User/jeff, so he'll be denied access to the resource. @@ -101,7 +101,7 @@ /** * The role map defines how to resolve the user record from your application - * to the roles you defined in the roles configuration. + * to the roles you defined in the roles configuration. */ $config['map'] = array( 'User' => 'User/username', diff --git a/app/Config/bootstrap.php b/app/Config/bootstrap.php index bcc50f6c4..dd7a596da 100644 --- a/app/Config/bootstrap.php +++ b/app/Config/bootstrap.php @@ -2,7 +2,7 @@ /** * This file is loaded automatically by the app/webroot/index.php file after core.php * - * This file should load/create any application wide configuration settings, such as + * This file should load/create any application wide configuration settings, such as * Caching, Logging, loading additional configuration files. * * You should also use this file to include any files that provide global functions/constants diff --git a/app/Config/core.php b/app/Config/core.php index 4bbfabe6e..99198539f 100644 --- a/app/Config/core.php +++ b/app/Config/core.php @@ -226,7 +226,7 @@ Configure::write('Acl.database', 'default'); /** - * Uncomment this line and correct your server timezone to fix + * Uncomment this line and correct your server timezone to fix * any date & time related errors. */ //date_default_timezone_set('UTC'); @@ -236,7 +236,7 @@ * If running via cli - apc is disabled by default. ensure it's available and enabled in this case * * Note: 'default' and other application caches should be configured in app/Config/bootstrap.php. - * Please check the comments in boostrap.php for more info on the cache engines available + * Please check the comments in boostrap.php for more info on the cache engines available * and their setttings. */ $engine = 'File'; diff --git a/app/Config/routes.php b/app/Config/routes.php index 32151d27c..c68cc3e4a 100644 --- a/app/Config/routes.php +++ b/app/Config/routes.php @@ -32,7 +32,7 @@ Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); /** - * Load all plugin routes. See the CakePlugin documentation on + * Load all plugin routes. See the CakePlugin documentation on * how to customize the loading of plugin routes. */ CakePlugin::routes(); diff --git a/lib/Cake/Cache/CacheEngine.php b/lib/Cake/Cache/CacheEngine.php index 6994701f4..9daf4d7c0 100644 --- a/lib/Cake/Cache/CacheEngine.php +++ b/lib/Cake/Cache/CacheEngine.php @@ -65,7 +65,7 @@ abstract class CacheEngine { * Garbage collection * * Permanently remove all expired and deleted data - * + * * @param integer $expires [optional] An expires timestamp, invalidataing all data before. * @return void */ diff --git a/lib/Cake/Cache/Engine/FileEngine.php b/lib/Cake/Cache/Engine/FileEngine.php index 9388fafb9..da68c398c 100644 --- a/lib/Cake/Cache/Engine/FileEngine.php +++ b/lib/Cake/Cache/Engine/FileEngine.php @@ -93,7 +93,7 @@ class FileEngine extends CacheEngine { /** * Garbage collection. Permanently remove all expired and deleted data - * + * * @param integer $expires [optional] An expires timestamp, invalidataing all data before. * @return boolean True if garbage collection was successful, false on failure */ diff --git a/lib/Cake/Console/Command/Task/TemplateTask.php b/lib/Cake/Console/Command/Task/TemplateTask.php index ffe993ce0..69b4cdd39 100644 --- a/lib/Cake/Console/Command/Task/TemplateTask.php +++ b/lib/Cake/Console/Command/Task/TemplateTask.php @@ -56,7 +56,7 @@ class TemplateTask extends AppShell { * * Bake themes are directories not named `skel` inside a `Console/Templates` path. * They are listed in this order: app -> plugin -> default - * + * * @return array Array of bake themes that are installed. */ protected function _findThemes() { diff --git a/lib/Cake/Console/Command/TestShell.php b/lib/Cake/Console/Command/TestShell.php index f14c51874..2b9892fc0 100644 --- a/lib/Cake/Console/Command/TestShell.php +++ b/lib/Cake/Console/Command/TestShell.php @@ -335,8 +335,8 @@ class TestShell extends Shell { * Find the test case for the passed file. The file could itself be a test. * * @param string $file - * @param string $category - * @param boolean $throwOnMissingFile + * @param string $category + * @param boolean $throwOnMissingFile * @access protected * @return array(type, case) * @throws Exception diff --git a/lib/Cake/Console/Templates/skel/Config/core.php b/lib/Cake/Console/Templates/skel/Config/core.php index c53e2fd02..7720e9ed6 100644 --- a/lib/Cake/Console/Templates/skel/Config/core.php +++ b/lib/Cake/Console/Templates/skel/Config/core.php @@ -226,7 +226,7 @@ Configure::write('Acl.database', 'default'); /** - * Uncomment this line and correct your server timezone to fix + * Uncomment this line and correct your server timezone to fix * any date & time related errors. */ //date_default_timezone_set('UTC'); diff --git a/lib/Cake/Controller/Component.php b/lib/Cake/Controller/Component.php index 876174e8c..42815e534 100644 --- a/lib/Cake/Controller/Component.php +++ b/lib/Cake/Controller/Component.php @@ -120,7 +120,7 @@ class Component extends Object { } /** - * Called before the Controller::beforeRender(), and before + * Called before the Controller::beforeRender(), and before * the view class is loaded, and before Controller::render() * * @param Controller $controller Controller with components to beforeRender diff --git a/lib/Cake/Controller/Component/Acl/IniAcl.php b/lib/Cake/Controller/Component/Acl/IniAcl.php index 8810668cc..d915443fb 100644 --- a/lib/Cake/Controller/Component/Acl/IniAcl.php +++ b/lib/Cake/Controller/Component/Acl/IniAcl.php @@ -143,7 +143,7 @@ class IniAcl extends Object implements AclInterface { } /** - * Parses an INI file and returns an array that reflects the + * Parses an INI file and returns an array that reflects the * INI file's section structure. Double-quote friendly. * * @param string $filename File diff --git a/lib/Cake/Controller/Component/Acl/PhpAcl.php b/lib/Cake/Controller/Component/Acl/PhpAcl.php index d63217857..bd9c7302e 100644 --- a/lib/Cake/Controller/Component/Acl/PhpAcl.php +++ b/lib/Cake/Controller/Component/Acl/PhpAcl.php @@ -18,7 +18,7 @@ */ /** - * PhpAcl implements an access control system using a plain PHP configuration file. + * PhpAcl implements an access control system using a plain PHP configuration file. * An example file can be found in app/Config/acl.php * * @package Cake.Controller.Component.Acl @@ -46,7 +46,7 @@ class PhpAcl extends Object implements AclInterface { /** * Aco Object - * + * * @var PhpAco */ public $Aco = null; @@ -65,8 +65,8 @@ class PhpAcl extends Object implements AclInterface { /** * Initialize method - * - * @param AclComponent $Component Component instance + * + * @param AclComponent $Component Component instance * @return void */ public function initialize(Component $Component) { @@ -199,7 +199,7 @@ class PhpAco { /** * map modifiers for ACO paths to their respective PCRE pattern - * + * * @var array */ public static $modifiers = array( @@ -263,7 +263,7 @@ class PhpAco { /** * allow/deny ARO access to ARO * - * @return void + * @return void */ public function access($aro, $aco, $action, $type = 'deny') { $aco = $this->resolve($aco); @@ -315,7 +315,7 @@ class PhpAco { * * @param array $allow ACO allow rules * @param array $deny ACO deny rules - * @return void + * @return void */ public function build(array $allow, array $deny = array()) { $this->_tree = array(); @@ -347,7 +347,7 @@ class PhpAco { class PhpAro { /** - * role to resolve to when a provided ARO is not listed in + * role to resolve to when a provided ARO is not listed in * the internal tree * * @var string @@ -357,12 +357,12 @@ class PhpAro { /** * map external identifiers. E.g. if * - * array('User' => array('username' => 'jeff', 'role' => 'editor')) + * array('User' => array('username' => 'jeff', 'role' => 'editor')) * - * is passed as an ARO to one of the methods of AclComponent, PhpAcl + * is passed as an ARO to one of the methods of AclComponent, PhpAcl * will check if it can be resolved to an User or a Role defined in the - * configuration file. - * + * configuration file. + * * @var array * @see app/Config/acl.php */ @@ -373,7 +373,7 @@ class PhpAro { /** * aliases to map - * + * * @var array */ public $aliases = array(); @@ -398,9 +398,9 @@ class PhpAro { * From the perspective of the given ARO, walk down the tree and * collect all inherited AROs levelwise such that AROs from different * branches with equal distance to the requested ARO will be collected at the same - * index. The resulting array will contain a prioritized list of (list of) roles ordered from + * index. The resulting array will contain a prioritized list of (list of) roles ordered from * the most distant AROs to the requested one itself. - * + * * @param string|array $aro An ARO identifier * @return array prioritized AROs */ @@ -425,7 +425,7 @@ class PhpAro { /** * resolve an ARO identifier to an internal ARO string using - * the internal mapping information. + * the internal mapping information. * * @param string|array $aro ARO identifier (User.jeff, array('User' => ...), etc) * @return string internal aro string (e.g. User/jeff, Role/default) @@ -527,7 +527,7 @@ class PhpAro { * build an ARO tree structure for internal processing * * @param array $aros array of AROs as key and their inherited AROs as values - * @return void + * @return void */ public function build(array $aros) { $this->_tree = array(); diff --git a/lib/Cake/Controller/Component/Auth/DigestAuthenticate.php b/lib/Cake/Controller/Component/Auth/DigestAuthenticate.php index bdea7d8aa..5e0fb0ee5 100644 --- a/lib/Cake/Controller/Component/Auth/DigestAuthenticate.php +++ b/lib/Cake/Controller/Component/Auth/DigestAuthenticate.php @@ -68,7 +68,7 @@ class DigestAuthenticate extends BaseAuthenticate { * - `realm` The realm authentication is for, Defaults to the servername. * - `nonce` A nonce used for authentication. Defaults to `uniqid()`. * - `qop` Defaults to auth, no other values are supported at this time. - * - `opaque` A string that must be returned unchanged by clients. + * - `opaque` A string that must be returned unchanged by clients. * Defaults to `md5($settings['realm'])` * * @var array diff --git a/lib/Cake/Controller/Component/CookieComponent.php b/lib/Cake/Controller/Component/CookieComponent.php index f314c42fa..1d962bc28 100644 --- a/lib/Cake/Controller/Component/CookieComponent.php +++ b/lib/Cake/Controller/Component/CookieComponent.php @@ -155,7 +155,7 @@ class CookieComponent extends Component { /** * A reference to the Controller's CakeResponse object - * + * * @var CakeResponse */ protected $_response = null; diff --git a/lib/Cake/Controller/Component/SecurityComponent.php b/lib/Cake/Controller/Component/SecurityComponent.php index 3b5eb8669..907b43a8f 100644 --- a/lib/Cake/Controller/Component/SecurityComponent.php +++ b/lib/Cake/Controller/Component/SecurityComponent.php @@ -23,7 +23,7 @@ App::uses('Hash', 'Utility'); App::uses('Security', 'Utility'); /** - * The Security Component creates an easy way to integrate tighter security in + * The Security Component creates an easy way to integrate tighter security in * your application. It provides methods for various tasks like: * * - Restricting which HTTP methods your application accepts. diff --git a/lib/Cake/Controller/Component/SessionComponent.php b/lib/Cake/Controller/Component/SessionComponent.php index ed42bff24..0bcdb7fa6 100644 --- a/lib/Cake/Controller/Component/SessionComponent.php +++ b/lib/Cake/Controller/Component/SessionComponent.php @@ -21,8 +21,8 @@ App::uses('Component', 'Controller'); App::uses('CakeSession', 'Model/Datasource'); /** - * The CakePHP SessionComponent provides a way to persist client data between - * page requests. It acts as a wrapper for the `$_SESSION` as well as providing + * The CakePHP SessionComponent provides a way to persist client data between + * page requests. It acts as a wrapper for the `$_SESSION` as well as providing * convenience methods for several `$_SESSION` related functions. * * @package Cake.Controller.Component diff --git a/lib/Cake/Core/CakePlugin.php b/lib/Cake/Core/CakePlugin.php index 5242c9f98..814f36b32 100644 --- a/lib/Cake/Core/CakePlugin.php +++ b/lib/Cake/Core/CakePlugin.php @@ -18,7 +18,7 @@ */ /** - * CakePlugin is responsible for loading and unloading plugins. It also can + * CakePlugin is responsible for loading and unloading plugins. It also can * retrieve plugin paths and load their bootstrap and routes files. * * @package Cake.Core diff --git a/lib/Cake/Event/CakeEvent.php b/lib/Cake/Event/CakeEvent.php index 52de3cf23..c70d4f816 100644 --- a/lib/Cake/Event/CakeEvent.php +++ b/lib/Cake/Event/CakeEvent.php @@ -27,7 +27,7 @@ class CakeEvent { /** * Name of the event - * + * * @var string $name */ protected $_name = null; diff --git a/lib/Cake/Event/CakeEventManager.php b/lib/Cake/Event/CakeEventManager.php index 252364d4c..aacd537c9 100644 --- a/lib/Cake/Event/CakeEventManager.php +++ b/lib/Cake/Event/CakeEventManager.php @@ -50,7 +50,7 @@ class CakeEventManager { protected $_listeners = array(); /** - * Internal flag to distinguish a common manager from the sigleton + * Internal flag to distinguish a common manager from the sigleton * * @var boolean */ @@ -64,7 +64,7 @@ class CakeEventManager { * * If called with a first params, it will be set as the globally available instance * - * @param CakeEventManager $manager + * @param CakeEventManager $manager * @return CakeEventManager the global event manager */ public static function instance($manager = null) { @@ -80,7 +80,7 @@ class CakeEventManager { } /** - * Adds a new listener to an event. Listeners + * Adds a new listener to an event. Listeners * * @param callback|CakeEventListener $callable PHP valid callback type or instance of CakeEventListener to be called * when the event named with $eventKey is triggered. If a CakeEventListener instances is passed, then the `implementedEvents` diff --git a/lib/Cake/Model/Behavior/ContainableBehavior.php b/lib/Cake/Model/Behavior/ContainableBehavior.php index bb33eaf46..98c067468 100644 --- a/lib/Cake/Model/Behavior/ContainableBehavior.php +++ b/lib/Cake/Model/Behavior/ContainableBehavior.php @@ -20,8 +20,8 @@ */ /** - * Behavior to allow for dynamic and atomic manipulation of a Model's associations - * used for a find call. Most useful for limiting the amount of associations and + * Behavior to allow for dynamic and atomic manipulation of a Model's associations + * used for a find call. Most useful for limiting the amount of associations and * data returned. * * @package Cake.Model.Behavior diff --git a/lib/Cake/Model/ConnectionManager.php b/lib/Cake/Model/ConnectionManager.php index edbcfa5eb..4edd0ac77 100644 --- a/lib/Cake/Model/ConnectionManager.php +++ b/lib/Cake/Model/ConnectionManager.php @@ -24,7 +24,7 @@ App::uses('DataSource', 'Model/Datasource'); /** * Manages loaded instances of DataSource objects * - * Provides an interface for loading and enumerating connections defined in + * Provides an interface for loading and enumerating connections defined in * app/Config/database.php * * @package Cake.Model diff --git a/lib/Cake/Model/Datasource/DataSource.php b/lib/Cake/Model/Datasource/DataSource.php index 06f526403..af65276ce 100644 --- a/lib/Cake/Model/Datasource/DataSource.php +++ b/lib/Cake/Model/Datasource/DataSource.php @@ -420,7 +420,7 @@ class DataSource extends Object { /** * Closes a connection. Override in subclasses - * + * * @return boolean * @access public */ diff --git a/lib/Cake/Model/Datasource/Database/Sqlserver.php b/lib/Cake/Model/Datasource/Database/Sqlserver.php index 46d565400..035f120ea 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlserver.php +++ b/lib/Cake/Model/Datasource/Database/Sqlserver.php @@ -637,7 +637,7 @@ class Sqlserver extends DboSource { /** * Generate a database-native column schema string * - * @param array $column An array structured like the + * @param array $column An array structured like the * following: array('name'=>'value', 'type'=>'value'[, options]), * where options can be 'default', 'length', or 'key'. * @return string diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index b812dac97..9bf4d434e 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/lib/Cake/Network/Email/CakeEmail.php @@ -1035,7 +1035,7 @@ class CakeEmail { /** * Send an email using the specified content, template and layout - * + * * @param string|array $content String with message or array with messages * @return array * @throws SocketException @@ -1337,7 +1337,7 @@ class CakeEmail { /** * Attach non-embedded files by adding file contents inside boundaries. * - * @param string $boundary Boundary to use. If null, will default to $this->_boundary + * @param string $boundary Boundary to use. If null, will default to $this->_boundary * @return array An array of lines to add to the message */ protected function _attachFiles($boundary = null) { @@ -1380,7 +1380,7 @@ class CakeEmail { /** * Attach inline/embedded files to the message. * - * @param string $boundary Boundary to use. If null, will default to $this->_boundary + * @param string $boundary Boundary to use. If null, will default to $this->_boundary * @return array An array of lines to add to the message */ protected function _attachInlineFiles($boundary = null) { diff --git a/lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php b/lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php index a091fbd6e..6f506d845 100644 --- a/lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php +++ b/lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php @@ -102,7 +102,7 @@ class FileEngineTest extends CakeTestCase { /** * Test read/write on the same cache key. Ensures file handles are re-wound. - * + * * @return void */ public function testConsecutiveReadWrite() { diff --git a/lib/Cake/Test/Case/Console/Command/TestShellTest.php b/lib/Cake/Test/Case/Console/Command/TestShellTest.php index 5d08c584d..ddae489e2 100644 --- a/lib/Cake/Test/Case/Console/Command/TestShellTest.php +++ b/lib/Cake/Test/Case/Console/Command/TestShellTest.php @@ -64,7 +64,7 @@ class TestShellTest extends CakeTestCase { /** * testMapCoreFileToCategory - * + * * @return void */ public function testMapCoreFileToCategory() { @@ -84,7 +84,7 @@ class TestShellTest extends CakeTestCase { * testMapCoreFileToCase * * basics.php is a slightly special case - it's the only file in the core with a test that isn't Capitalized - * + * * @return void */ public function testMapCoreFileToCase() { @@ -102,7 +102,7 @@ class TestShellTest extends CakeTestCase { /** * testMapAppFileToCategory - * + * * @return void */ public function testMapAppFileToCategory() { @@ -132,7 +132,7 @@ class TestShellTest extends CakeTestCase { /** * testMapPluginFileToCategory - * + * * @return void */ public function testMapPluginFileToCategory() { @@ -162,7 +162,7 @@ class TestShellTest extends CakeTestCase { /** * testMapCoreTestToCategory - * + * * @return void */ public function testMapCoreTestToCategory() { @@ -182,7 +182,7 @@ class TestShellTest extends CakeTestCase { * testMapCoreTestToCase * * basics.php is a slightly special case - it's the only file in the core with a test that isn't Capitalized - * + * * @return void */ public function testMapCoreTestToCase() { @@ -200,7 +200,7 @@ class TestShellTest extends CakeTestCase { /** * testMapAppTestToCategory - * + * * @return void */ public function testMapAppTestToCategory() { @@ -230,7 +230,7 @@ class TestShellTest extends CakeTestCase { /** * testMapPluginTestToCategory - * + * * @return void */ public function testMapPluginTestToCategory() { diff --git a/lib/Cake/Test/Case/Event/CakeEventManagerTest.php b/lib/Cake/Test/Case/Event/CakeEventManagerTest.php index 04a358ab4..01f1ff7d4 100644 --- a/lib/Cake/Test/Case/Event/CakeEventManagerTest.php +++ b/lib/Cake/Test/Case/Event/CakeEventManagerTest.php @@ -53,7 +53,7 @@ class CakeEventTestListener { /** * Auxiliary function to help in stopPropagation testing * - * @param CakeEvent $event + * @param CakeEvent $event * @return void */ public function stopListener($event) { diff --git a/lib/Cake/Test/Case/Model/Datasource/DataSourceTest.php b/lib/Cake/Test/Case/Model/Datasource/DataSourceTest.php index 3bb9bd0d7..a0de0aba2 100644 --- a/lib/Cake/Test/Case/Model/Datasource/DataSourceTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/DataSourceTest.php @@ -29,7 +29,7 @@ class TestSource extends DataSource { /** * _schema - * @var type + * @var type */ protected $_schema = array( 'id' => array( diff --git a/lib/Cake/Test/Case/TestSuite/CakeTestFixtureTest.php b/lib/Cake/Test/Case/TestSuite/CakeTestFixtureTest.php index 556554872..6afdc0b35 100644 --- a/lib/Cake/Test/Case/TestSuite/CakeTestFixtureTest.php +++ b/lib/Cake/Test/Case/TestSuite/CakeTestFixtureTest.php @@ -227,7 +227,7 @@ class CakeTestFixtureTest extends CakeTestCase { } /** - * test that init() correctly sets the fixture table when the connection + * test that init() correctly sets the fixture table when the connection * or model have prefixes defined. * * @return void diff --git a/lib/Cake/Test/Case/TestSuite/CakeTestSuiteTest.php b/lib/Cake/Test/Case/TestSuite/CakeTestSuiteTest.php index a30fd5a86..9a25b4939 100644 --- a/lib/Cake/Test/Case/TestSuite/CakeTestSuiteTest.php +++ b/lib/Cake/Test/Case/TestSuite/CakeTestSuiteTest.php @@ -22,7 +22,7 @@ class CakeTestSuiteTest extends CakeTestCase { /** * testAddTestDirectory - * + * * @return void */ public function testAddTestDirectory() { @@ -39,7 +39,7 @@ class CakeTestSuiteTest extends CakeTestCase { /** * testAddTestDirectoryRecursive - * + * * @return void */ public function testAddTestDirectoryRecursive() { @@ -57,7 +57,7 @@ class CakeTestSuiteTest extends CakeTestCase { /** * testAddTestDirectoryRecursiveWithHidden - * + * * @return void */ public function testAddTestDirectoryRecursiveWithHidden() { @@ -81,7 +81,7 @@ class CakeTestSuiteTest extends CakeTestCase { /** * testAddTestDirectoryRecursiveWithNonPhp - * + * * @return void */ public function testAddTestDirectoryRecursiveWithNonPhp() { diff --git a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php index 82f2ba9e1..dbe3ef82c 100644 --- a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php +++ b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php @@ -16,7 +16,7 @@ App::uses('CakeSchema', 'Model'); /** - * CakeTestFixture is responsible for building and destroying tables to be used + * CakeTestFixture is responsible for building and destroying tables to be used * during testing. * * @package Cake.TestSuite.Fixture diff --git a/lib/Cake/Utility/File.php b/lib/Cake/Utility/File.php index 6fe93995a..edf2dfbf3 100644 --- a/lib/Cake/Utility/File.php +++ b/lib/Cake/Utility/File.php @@ -546,7 +546,7 @@ class File { } /** - * Get the mime type of the file. Uses the finfo extension if + * Get the mime type of the file. Uses the finfo extension if * its available, otherwise falls back to mime_content_type * * @return false|string The mimetype of the file, or false if reading fails. diff --git a/lib/Cake/View/Helper/SessionHelper.php b/lib/Cake/View/Helper/SessionHelper.php index 259c4df81..2bb983c47 100644 --- a/lib/Cake/View/Helper/SessionHelper.php +++ b/lib/Cake/View/Helper/SessionHelper.php @@ -100,7 +100,7 @@ class SessionHelper extends AppHelper { * echo $this->Session->flash('flash', array('element' => 'my_custom_element')); * }}} * - * If you want to use an element from a plugin for rendering your flash message you can do that using the + * If you want to use an element from a plugin for rendering your flash message you can do that using the * plugin param: * * {{{ diff --git a/lib/Cake/View/JsonView.php b/lib/Cake/View/JsonView.php index 3cf669c43..785f75437 100644 --- a/lib/Cake/View/JsonView.php +++ b/lib/Cake/View/JsonView.php @@ -25,7 +25,7 @@ App::uses('View', 'View'); * * `$this->set(array('posts' => $posts, '_serialize' => 'posts'));` * - * When the view is rendered, the `$posts` view variable will be serialized + * When the view is rendered, the `$posts` view variable will be serialized * into JSON. * * You can also define `'_serialize'` as an array. This will create a top level object containing @@ -35,7 +35,7 @@ App::uses('View', 'View'); * $this->set(compact('posts', 'users', 'stuff')); * $this->set('_serialize', array('posts', 'users')); * }}} - * + * * The above would generate a JSON object that looks like: * * `{"posts": [...], "users": [...]}` @@ -49,9 +49,9 @@ App::uses('View', 'View'); class JsonView extends View { /** - * JSON views are always located in the 'json' sub directory for a + * JSON views are always located in the 'json' sub directory for a * controllers views. - * + * * @var string */ public $subDir = 'json'; @@ -72,8 +72,8 @@ class JsonView extends View { * Render a JSON view. * * Uses the special '_serialize' parameter to convert a set of - * view variables into a JSON response. Makes generating simple - * JSON responses very easy. You can omit the '_serialize' parameter, + * view variables into a JSON response. Makes generating simple + * JSON responses very easy. You can omit the '_serialize' parameter, * and use a normal view + layout as well. * * @param string $view The view being rendered. diff --git a/lib/Cake/View/ViewBlock.php b/lib/Cake/View/ViewBlock.php index 5636d74d5..98b16d7fe 100644 --- a/lib/Cake/View/ViewBlock.php +++ b/lib/Cake/View/ViewBlock.php @@ -73,7 +73,7 @@ class ViewBlock { } /** - * Append to an existing or new block. Appending to a new + * Append to an existing or new block. Appending to a new * block will create the block. * * Calling append() without a value will create a new capturing From f89fe0e1efcd77877a3fab8f13e41a7e129639f9 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 15 Oct 2012 21:35:57 -0400 Subject: [PATCH 24/85] Fix tests that fail in PHPUnit 3.7 Add skips for PHPUnit 3.6. Mock object expects required clones in 3.6, but fail in 3.7 with clones. --- .../Test/Case/Event/CakeEventManagerTest.php | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/Cake/Test/Case/Event/CakeEventManagerTest.php b/lib/Cake/Test/Case/Event/CakeEventManagerTest.php index 01f1ff7d4..3d4cae1dc 100644 --- a/lib/Cake/Test/Case/Event/CakeEventManagerTest.php +++ b/lib/Cake/Test/Case/Event/CakeEventManagerTest.php @@ -234,6 +234,10 @@ class CakeEventManagerTest extends CakeTestCase { * @return void */ public function testDispatchReturnValue() { + $this->skipIf( + version_compare(PHPUnit_Runner_Version::VERSION, '3.7', '<'), + 'These tests fail in PHPUnit 3.6' + ); $manager = new CakeEventManager; $listener = $this->getMock('CakeEventTestListener'); $anotherListener = $this->getMock('CakeEventTestListener'); @@ -241,11 +245,12 @@ class CakeEventManagerTest extends CakeTestCase { $manager->attach(array($anotherListener, 'listenerFunction'), 'fake.event'); $event = new CakeEvent('fake.event'); - $firstStep = clone $event; $listener->expects($this->at(0))->method('listenerFunction') - ->with($firstStep) + ->with($event) ->will($this->returnValue('something special')); - $anotherListener->expects($this->at(0))->method('listenerFunction')->with($event); + $anotherListener->expects($this->at(0)) + ->method('listenerFunction') + ->with($event); $manager->dispatch($event); $this->assertEquals('something special', $event->result); } @@ -256,6 +261,11 @@ class CakeEventManagerTest extends CakeTestCase { * @return void */ public function testDispatchFalseStopsEvent() { + $this->skipIf( + version_compare(PHPUnit_Runner_Version::VERSION, '3.7', '<'), + 'These tests fail in PHPUnit 3.6' + ); + $manager = new CakeEventManager; $listener = $this->getMock('CakeEventTestListener'); $anotherListener = $this->getMock('CakeEventTestListener'); @@ -263,11 +273,11 @@ class CakeEventManagerTest extends CakeTestCase { $manager->attach(array($anotherListener, 'listenerFunction'), 'fake.event'); $event = new CakeEvent('fake.event'); - $originalEvent = clone $event; $listener->expects($this->at(0))->method('listenerFunction') - ->with($originalEvent) + ->with($event) ->will($this->returnValue(false)); - $anotherListener->expects($this->never())->method('listenerFunction'); + $anotherListener->expects($this->never()) + ->method('listenerFunction'); $manager->dispatch($event); $this->assertTrue($event->isStopped()); } From f6c5ceb77a2344d722da07a6edc200694df2009e Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 15 Oct 2012 21:38:10 -0400 Subject: [PATCH 25/85] Use id() as VERSION doesn't exist in phpunit 3.6 --- lib/Cake/Test/Case/Event/CakeEventManagerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Event/CakeEventManagerTest.php b/lib/Cake/Test/Case/Event/CakeEventManagerTest.php index 3d4cae1dc..f3929cc9d 100644 --- a/lib/Cake/Test/Case/Event/CakeEventManagerTest.php +++ b/lib/Cake/Test/Case/Event/CakeEventManagerTest.php @@ -262,7 +262,7 @@ class CakeEventManagerTest extends CakeTestCase { */ public function testDispatchFalseStopsEvent() { $this->skipIf( - version_compare(PHPUnit_Runner_Version::VERSION, '3.7', '<'), + version_compare(PHPUnit_Runner_Version::id(), '3.7', '<'), 'These tests fail in PHPUnit 3.6' ); From 6d3ae3b83cc0ad7f2551ad4d35819cb56129cb30 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 15 Oct 2012 21:48:36 -0400 Subject: [PATCH 26/85] Fix missed use of VERSION. --- lib/Cake/Test/Case/Event/CakeEventManagerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Event/CakeEventManagerTest.php b/lib/Cake/Test/Case/Event/CakeEventManagerTest.php index f3929cc9d..9689b4d6f 100644 --- a/lib/Cake/Test/Case/Event/CakeEventManagerTest.php +++ b/lib/Cake/Test/Case/Event/CakeEventManagerTest.php @@ -235,7 +235,7 @@ class CakeEventManagerTest extends CakeTestCase { */ public function testDispatchReturnValue() { $this->skipIf( - version_compare(PHPUnit_Runner_Version::VERSION, '3.7', '<'), + version_compare(PHPUnit_Runner_Version::id(), '3.7', '<'), 'These tests fail in PHPUnit 3.6' ); $manager = new CakeEventManager; From 307759516bd6a2651fa89cc4c163598d3b66c878 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 15 Oct 2012 22:51:41 -0400 Subject: [PATCH 27/85] Try to make tests less fragile. --- lib/Cake/Test/Case/Utility/CakeTimeTest.php | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/CakeTimeTest.php b/lib/Cake/Test/Case/Utility/CakeTimeTest.php index 04b1b3cde..7185ef00f 100644 --- a/lib/Cake/Test/Case/Utility/CakeTimeTest.php +++ b/lib/Cake/Test/Case/Utility/CakeTimeTest.php @@ -779,17 +779,17 @@ class CakeTimeTest extends CakeTestCase { $expected = time(); $result = $this->Time->fromString(time(), $yourTimezone); - $this->assertEquals($expected, $result); + $this->assertWithinMargin($expected, $result, 1); $result = $this->Time->fromString(time(), $timezoneServer->getName()); - $this->assertEquals($expected, $result); + $this->assertWithinMargin($expected, $result, 1); $result = $this->Time->fromString(time(), $timezoneServer); - $this->assertEquals($expected, $result); + $this->assertWithinMargin($expected, $result, 1); Configure::write('Config.timezone', $timezoneServer->getName()); $result = $this->Time->fromString(time()); - $this->assertEquals($expected, $result); + $this->assertWithinMargin($expected, $result, 1); Configure::delete('Config.timezone'); } @@ -807,17 +807,17 @@ class CakeTimeTest extends CakeTestCase { $result = $this->Time->fromString('+1 hour'); $expected = strtotime('+1 hour'); - $this->assertEquals($expected, $result); + $this->assertWithinMargin($expected, $result, 1); $timezone = date('Z', time()); $result = $this->Time->fromString('+1 hour', $timezone); $expected = $this->Time->convert(strtotime('+1 hour'), $timezone); - $this->assertEquals($expected, $result); + $this->assertWithinMargin($expected, $result, 1); $timezone = date_default_timezone_get(); $result = $this->Time->fromString('+1 hour', $timezone); $expected = $this->Time->convert(strtotime('+1 hour'), $timezone); - $this->assertEquals($expected, $result); + $this->assertWithinMargin($expected, $result, 1); date_default_timezone_set('UTC'); $date = new DateTime('now', new DateTimeZone('Europe/London')); @@ -840,7 +840,7 @@ class CakeTimeTest extends CakeTestCase { $date->setTimezone(new DateTimeZone('UTC')); $expected = $date->format('U') + $date->getOffset(); - $this->assertEquals($expected, $result); + $this->assertWithinMargin($expected, $result, 1); date_default_timezone_set('Australia/Melbourne'); @@ -848,7 +848,7 @@ class CakeTimeTest extends CakeTestCase { $result = $this->Time->fromString($date, 'Asia/Kuwait'); $date->setTimezone(new DateTimeZone('Asia/Kuwait')); $expected = $date->format('U') + $date->getOffset(); - $this->assertEquals($expected, $result); + $this->assertWithinMargin($expected, $result, 1); $this->_restoreSystemTimezone(); } @@ -1058,10 +1058,10 @@ class CakeTimeTest extends CakeTestCase { public function testCorrectTimezoneConversion() { date_default_timezone_set('UTC'); $date = '2012-01-01 10:00:00'; - $converted = CakeTime::format($date, '%Y-%m-%d %H:%M:%S', '', 'Europe/Copenhagen'); + $converted = CakeTime::format($date, '%Y-%m-%d %H:%M', '', 'Europe/Copenhagen'); $expected = new DateTime($date); $expected->setTimezone(new DateTimeZone('Europe/Copenhagen')); - $this->assertEquals($expected->format('Y-m-d H:i:s'), $converted); + $this->assertEquals($expected->format('Y-m-d H:i'), $converted); } } From ea467e72d72e9eb7cd140816ee8d7abd900b2629 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 17 Oct 2012 17:23:08 -0400 Subject: [PATCH 28/85] Swap isset() for array_key_exists() Fixes #3283 --- lib/Cake/Controller/Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index 978dade84..8b3098998 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -796,7 +796,7 @@ class Controller extends Object implements CakeEventListener { * @return array Array with keys url, status and exit */ protected function _parseBeforeRedirect($response, $url, $status, $exit) { - if (is_array($response) && isset($response[0])) { + if (is_array($response) && array_key_exists(0, $response)) { foreach ($response as $resp) { if (is_array($resp) && isset($resp['url'])) { extract($resp, EXTR_OVERWRITE); From 888b1f47959e386021d4afa4491cbef5dab41721 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 20 Oct 2012 14:51:52 -0400 Subject: [PATCH 29/85] Fix issue with using contain() and query[contain] When contain() and query['contain'] = array(...) were used together the query['contain'] values where not respected. Fixes #3287 --- .../Model/Behavior/ContainableBehavior.php | 18 +++++++++++------- .../Model/Behavior/ContainableBehaviorTest.php | 13 +++++++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/Cake/Model/Behavior/ContainableBehavior.php b/lib/Cake/Model/Behavior/ContainableBehavior.php index 98c067468..799f6e238 100644 --- a/lib/Cake/Model/Behavior/ContainableBehavior.php +++ b/lib/Cake/Model/Behavior/ContainableBehavior.php @@ -91,21 +91,25 @@ class ContainableBehavior extends ModelBehavior { */ public function beforeFind(Model $Model, $query) { $reset = (isset($query['reset']) ? $query['reset'] : true); - $noContain = ( - (isset($this->runtime[$Model->alias]['contain']) && empty($this->runtime[$Model->alias]['contain'])) || - (isset($query['contain']) && empty($query['contain'])) - ); + $noContain = false; $contain = array(); + if (isset($this->runtime[$Model->alias]['contain'])) { + $noContain = empty($this->runtime[$Model->alias]['contain']); $contain = $this->runtime[$Model->alias]['contain']; unset($this->runtime[$Model->alias]['contain']); } + if (isset($query['contain'])) { - $contain = array_merge($contain, (array)$query['contain']); + $noContain = $noContain || empty($query['contain']); + if ($query['contain'] !== false) { + $contain = array_merge($contain, (array)$query['contain']); + } } + $noContain = $noContain && empty($contain); + if ( - $noContain || !$contain || in_array($contain, array(null, false), true) || - (isset($contain[0]) && $contain[0] === null) + $noContain || empty($contain) || (isset($contain[0]) && $contain[0] === null) ) { if ($noContain) { $query['recursive'] = -1; diff --git a/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php b/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php index 8345c87d6..e43f49bfa 100644 --- a/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php @@ -261,6 +261,19 @@ class ContainableBehaviorTest extends CakeTestCase { $this->assertFalse(Set::matches('/Comment/User', $r)); } +/** + * Test that mixing contain() and the contain find option. + * + * @return void + */ + public function testContainAndContainOption() { + $this->Article->contain(); + $r = $this->Article->find('all', array( + 'contain' => array('Comment') + )); + $this->assertTrue(isset($r[0]['Comment']), 'No comment returned'); + } + /** * testFindEmbeddedNoBindings method * From 08556ab879769ba0184e4df89c1d4778eabcd97c Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 20 Oct 2012 15:12:05 -0400 Subject: [PATCH 30/85] Fix saveAssociated() with validate=first, atomic=false When using the above options & validation errors on the associated models, saving would not be aborted. Fixes #3285 --- lib/Cake/Model/Model.php | 2 +- lib/Cake/Test/Case/Model/ModelWriteTest.php | 45 +++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 51c3ed494..cc1d80385 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -2183,7 +2183,7 @@ class Model extends Object implements CakeEventListener { if ($options['validate'] === 'first') { $validates = $this->validateAssociated($data, $options); - if ((!$validates && $options['atomic']) || (!$options['atomic'] && in_array(false, $validates, true))) { + if ((!$validates && $options['atomic']) || (!$options['atomic'] && in_array(false, Hash::flatten($validates), true))) { return $validates; } $options['validate'] = false; diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index 31327e7de..d317f6ca9 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -4830,6 +4830,51 @@ class ModelWriteTest extends BaseModelTest { $this->assertEquals($expected, $result[6]['Attachment']); } +/** + * Test that validate = first, atomic = false works when associated records + * fail validation. + * + * @return void + */ + public function testSaveAssociatedAtomicFalseValidateFirstWithErrors() { + $this->loadFixtures('Comment', 'Article', 'User'); + $Article = ClassRegistry::init('Article'); + $Article->Comment->validator()->add('comment', array( + array('rule' => 'notEmpty') + )); + + $data = array( + 'Article' => array( + 'user_id' => 1, + 'title' => 'Foo', + 'body' => 'text', + 'published' => 'N' + ), + 'Comment' => array( + array( + 'user_id' => 1, + 'comment' => '', + 'published' => 'N', + ) + ), + ); + + $Article->saveAssociated( + $data, + array('validate' => 'first', 'atomic' => false) + ); + + $result = $Article->validationErrors; + $expected = array( + 'Comment' => array( + array( + 'comment' => array( 'This field cannot be left blank' ) + ) + ) + ); + $this->assertEquals($expected, $result); + } + /** * testSaveMany method * From 9dc3b243ac33b19131a6ac28afabd7e945f72cda Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Mon, 22 Oct 2012 23:07:42 +0200 Subject: [PATCH 31/85] Correct inflection rules for cookies, fixes fixes #3291 --- lib/Cake/Test/Case/Utility/InflectorTest.php | 2 ++ lib/Cake/Utility/Inflector.php | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Utility/InflectorTest.php b/lib/Cake/Test/Case/Utility/InflectorTest.php index cd1989248..acfd68cf8 100644 --- a/lib/Cake/Test/Case/Utility/InflectorTest.php +++ b/lib/Cake/Test/Case/Utility/InflectorTest.php @@ -109,6 +109,7 @@ class InflectorTest extends CakeTestCase { $this->assertEquals(Inflector::singularize('roofs'), 'roof'); $this->assertEquals(Inflector::singularize('foes'), 'foe'); $this->assertEquals(Inflector::singularize('databases'), 'database'); + $this->assertEquals(Inflector::singularize('cookies'), 'cookie'); $this->assertEquals(Inflector::singularize(''), ''); } @@ -160,6 +161,7 @@ class InflectorTest extends CakeTestCase { $this->assertEquals(Inflector::pluralize('cafe'), 'cafes'); $this->assertEquals(Inflector::pluralize('roof'), 'roofs'); $this->assertEquals(Inflector::pluralize('foe'), 'foes'); + $this->assertEquals(Inflector::pluralize('cookie'), 'cookie'); $this->assertEquals(Inflector::pluralize(''), ''); } diff --git a/lib/Cake/Utility/Inflector.php b/lib/Cake/Utility/Inflector.php index 31829d621..47c591482 100644 --- a/lib/Cake/Utility/Inflector.php +++ b/lib/Cake/Utility/Inflector.php @@ -55,7 +55,7 @@ class Inflector { '/$/' => 's', ), 'uninflected' => array( - '.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', 'people' + '.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', 'people', 'cookie' ), 'irregular' => array( 'atlas' => 'atlases', @@ -63,6 +63,7 @@ class Inflector { 'brother' => 'brothers', 'cafe' => 'cafes', 'child' => 'children', + 'cookie' => 'cookies', 'corpus' => 'corpuses', 'cow' => 'cows', 'ganglion' => 'ganglions', From 1c0c8604c8ef45565a41170dd1f1dda181d7c1c2 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Mon, 22 Oct 2012 23:09:31 +0200 Subject: [PATCH 32/85] Pushed before fxing error in test case, I suck. Refs #3291 --- lib/Cake/Test/Case/Utility/InflectorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Utility/InflectorTest.php b/lib/Cake/Test/Case/Utility/InflectorTest.php index acfd68cf8..9e7d43add 100644 --- a/lib/Cake/Test/Case/Utility/InflectorTest.php +++ b/lib/Cake/Test/Case/Utility/InflectorTest.php @@ -161,7 +161,7 @@ class InflectorTest extends CakeTestCase { $this->assertEquals(Inflector::pluralize('cafe'), 'cafes'); $this->assertEquals(Inflector::pluralize('roof'), 'roofs'); $this->assertEquals(Inflector::pluralize('foe'), 'foes'); - $this->assertEquals(Inflector::pluralize('cookie'), 'cookie'); + $this->assertEquals(Inflector::pluralize('cookie'), 'cookies'); $this->assertEquals(Inflector::pluralize(''), ''); } From a0a61b5980272ec98dba0f02c9896d23a30d51fc Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 22 Oct 2012 20:33:43 -0400 Subject: [PATCH 33/85] Fix issue where createSchema() would omit primary keys sometimes. Fix missing primary key SQL when using the primary flag + other indexes. Fixes #3292 --- lib/Cake/Model/Datasource/DboSource.php | 2 +- .../Model/Datasource/Database/MysqlTest.php | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index ea1c7dbca..ef4bab7e7 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -2984,7 +2984,7 @@ class DboSource extends DataSource { $tableParameters = array_merge($tableParameters, $this->buildTableParameters($col, $table)); } } - if (empty($indexes) && !empty($primary)) { + if (!isset($columns['indexes']['PRIMARY']) && !empty($primary)) { $col = array('PRIMARY' => array('column' => $primary, 'unique' => 1)); $indexes = array_merge($indexes, $this->buildIndex($col, $table)); } diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php index f14bf6116..4f3baa0bd 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php @@ -877,6 +877,52 @@ class MysqlTest extends CakeTestCase { $this->assertContains('`user_id` int(11) NOT NULL,', $result); } +/** + * Test that the primary flag is handled correctly. + * + * @return void + */ + public function testCreateSchemaAutoPrimaryKey() { + $schema = new CakeSchema(); + $schema->tables = array( + 'no_indexes' => array( + 'id' => array('type' => 'integer', 'null' => false, 'key' => 'primary'), + 'data' => array('type' => 'integer', 'null' => false), + 'indexes' => array(), + ) + ); + $result = $this->Dbo->createSchema($schema, 'no_indexes'); + $this->assertContains('PRIMARY KEY (`id`)', $result); + $this->assertNotContains('UNIQUE KEY', $result); + + $schema->tables = array( + 'primary_index' => array( + 'id' => array('type' => 'integer', 'null' => false), + 'data' => array('type' => 'integer', 'null' => false), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + 'some_index' => array('column' => 'data', 'unique' => 1) + ), + ) + ); + $result = $this->Dbo->createSchema($schema, 'primary_index'); + $this->assertContains('PRIMARY KEY (`id`)', $result); + $this->assertContains('UNIQUE KEY `some_index` (`data`)', $result); + + $schema->tables = array( + 'primary_flag_has_index' => array( + 'id' => array('type' => 'integer', 'null' => false, 'key' => 'primary'), + 'data' => array('type' => 'integer', 'null' => false), + 'indexes' => array ( + 'some_index' => array('column' => 'data', 'unique' => 1) + ), + ) + ); + $result = $this->Dbo->createSchema($schema, 'primary_flag_has_index'); + $this->assertContains('PRIMARY KEY (`id`)', $result); + $this->assertContains('UNIQUE KEY `some_index` (`data`)', $result); + } + /** * Tests that listSources method sends the correct query and parses the result accordingly * @return void From ed6ff92296107121d8fa50fb6ae75cd6ca61ca5e Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 20 Oct 2012 21:03:38 -0400 Subject: [PATCH 34/85] Remove bad test. --- lib/Cake/Test/Case/Cache/Engine/MemcacheEngineTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Cake/Test/Case/Cache/Engine/MemcacheEngineTest.php b/lib/Cake/Test/Case/Cache/Engine/MemcacheEngineTest.php index a1c2abd5b..88a7b6143 100644 --- a/lib/Cake/Test/Case/Cache/Engine/MemcacheEngineTest.php +++ b/lib/Cake/Test/Case/Cache/Engine/MemcacheEngineTest.php @@ -121,7 +121,6 @@ class MemcacheEngineTest extends CakeTestCase { $Memcache = new MemcacheEngine(); $Memcache->init(array('engine' => 'Memcache', 'servers' => $servers)); - $servers = array_keys($Memcache->__Memcache->getExtendedStats()); $settings = $Memcache->settings(); $this->assertEquals($settings['servers'], $servers); Cache::drop('dual_server'); From 922d9865fa22685b3f1ffada0158cf1446b5a761 Mon Sep 17 00:00:00 2001 From: ADmad Date: Tue, 23 Oct 2012 13:15:08 +0530 Subject: [PATCH 35/85] Moving multibyte encoding setting to bootstrap.php. Closes #3290 --- lib/Cake/I18n/I18n.php | 7 ------- lib/Cake/bootstrap.php | 6 ++++++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/Cake/I18n/I18n.php b/lib/Cake/I18n/I18n.php index 7678ba6ae..862414b7c 100644 --- a/lib/Cake/I18n/I18n.php +++ b/lib/Cake/I18n/I18n.php @@ -24,13 +24,6 @@ App::uses('CakePlugin', 'Core'); App::uses('L10n', 'I18n'); App::uses('Multibyte', 'I18n'); -if (function_exists('mb_internal_encoding')) { - $encoding = Configure::read('App.encoding'); - if (!empty($encoding)) { - mb_internal_encoding($encoding); - } -} - /** * I18n handles translation of Text and time format strings. * diff --git a/lib/Cake/bootstrap.php b/lib/Cake/bootstrap.php index 2c013b2d5..cd537cb5c 100644 --- a/lib/Cake/bootstrap.php +++ b/lib/Cake/bootstrap.php @@ -145,6 +145,12 @@ App::$bootstrapping = true; Configure::bootstrap(isset($boot) ? $boot : true); +if (function_exists('mb_internal_encoding')) { + $encoding = Configure::read('App.encoding'); + if (!empty($encoding)) { + mb_internal_encoding($encoding); + } +} /** * Full url prefix From 9a9ac6f3a7fd112e4d685f3cf507d528ed9cf102 Mon Sep 17 00:00:00 2001 From: euromark Date: Tue, 23 Oct 2012 13:43:48 +0200 Subject: [PATCH 36/85] allow input type=number to also be magic --- lib/Cake/View/Helper/FormHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 301acaaec..1fb8d7a81 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -994,7 +994,7 @@ class FormHelper extends AppHelper { if ( (!isset($options['options']) && in_array($options['type'], $types)) || - (isset($magicType) && $options['type'] == 'text') + (isset($magicType) && in_array($options['type'], array('text', 'number'))) ) { $varName = Inflector::variable( Inflector::pluralize(preg_replace('/_id$/', '', $fieldKey)) From 5064601c6f3b02c4a30c2e989f3fd67d8962f0bf Mon Sep 17 00:00:00 2001 From: euromark Date: Tue, 23 Oct 2012 14:44:09 +0200 Subject: [PATCH 37/85] adding test case --- .../Test/Case/View/Helper/FormHelperTest.php | 23 +++++++++++++++++++ lib/Cake/View/Helper/FormHelper.php | 7 +++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 9da345458..340247be0 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -2650,6 +2650,29 @@ class FormHelperTest extends CakeTestCase { '/div' ); $this->assertTags($result, $expected); + + $this->View->viewVars['balances'] = array(0 => 'nothing', 1 => 'some', 100 => 'a lot'); + $this->Form->request->data = array('ValidateUser' => array('balance' => 1)); + $result = $this->Form->input('ValidateUser.balance'); + $expected = array( + 'div' => array('class' => 'input select'), + 'label' => array('for' => 'ValidateUserBalance'), + 'Balance', + '/label', + 'select' => array('name' => 'data[ValidateUser][balance]', 'id' => 'ValidateUserBalance'), + array('option' => array('value' => '0')), + 'nothing', + '/option', + array('option' => array('value' => '1', 'selected' => 'selected')), + 'some', + '/option', + array('option' => array('value' => '100')), + 'a lot', + '/option', + '/select', + '/div' + ); + $this->assertTags($result, $expected); } /** diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 1fb8d7a81..6d82b2865 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -1006,12 +1006,17 @@ class FormHelper extends AppHelper { } $options['options'] = $varOptions; } + + if ($options['type'] === 'select' && array_key_exists('step', $options)) { + unset($options['step']); + } } $autoLength = ( !array_key_exists('maxlength', $options) && isset($fieldDef['length']) && - is_scalar($fieldDef['length']) + is_scalar($fieldDef['length']) && + $options['type'] !== 'select' ); if ($autoLength && $options['type'] == 'text') { $options['maxlength'] = $fieldDef['length']; From 044cf60b69563ce60e73c60cac7f1361a5b346e4 Mon Sep 17 00:00:00 2001 From: euromark Date: Tue, 23 Oct 2012 16:07:43 +0200 Subject: [PATCH 38/85] move the test case to its own method --- .../Test/Case/View/Helper/FormHelperTest.php | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 340247be0..60dfdde24 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -2614,6 +2614,36 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); } +/** + * Test that magic input() selects are created for type=number + * + * @return void + */ + public function testInputMagicSelectForTypeNumber() { + $this->View->viewVars['balances'] = array(0 => 'nothing', 1 => 'some', 100 => 'a lot'); + $this->Form->request->data = array('ValidateUser' => array('balance' => 1)); + $result = $this->Form->input('ValidateUser.balance'); + $expected = array( + 'div' => array('class' => 'input select'), + 'label' => array('for' => 'ValidateUserBalance'), + 'Balance', + '/label', + 'select' => array('name' => 'data[ValidateUser][balance]', 'id' => 'ValidateUserBalance'), + array('option' => array('value' => '0')), + 'nothing', + '/option', + array('option' => array('value' => '1', 'selected' => 'selected')), + 'some', + '/option', + array('option' => array('value' => '100')), + 'a lot', + '/option', + '/select', + '/div' + ); + $this->assertTags($result, $expected); + } + /** * Test that magic input() selects can easily be converted into radio types without error. * @@ -2650,29 +2680,6 @@ class FormHelperTest extends CakeTestCase { '/div' ); $this->assertTags($result, $expected); - - $this->View->viewVars['balances'] = array(0 => 'nothing', 1 => 'some', 100 => 'a lot'); - $this->Form->request->data = array('ValidateUser' => array('balance' => 1)); - $result = $this->Form->input('ValidateUser.balance'); - $expected = array( - 'div' => array('class' => 'input select'), - 'label' => array('for' => 'ValidateUserBalance'), - 'Balance', - '/label', - 'select' => array('name' => 'data[ValidateUser][balance]', 'id' => 'ValidateUserBalance'), - array('option' => array('value' => '0')), - 'nothing', - '/option', - array('option' => array('value' => '1', 'selected' => 'selected')), - 'some', - '/option', - array('option' => array('value' => '100')), - 'a lot', - '/option', - '/select', - '/div' - ); - $this->assertTags($result, $expected); } /** From 3729ac1f2f83f9c47de3cf08661891add0f0dbac Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 23 Oct 2012 12:47:12 -0400 Subject: [PATCH 39/85] Fix issue where the incorrect meridian would be selected. When combining 12 hour format, interval and afternoon times, the incorrect meridian would be selected. Moving the hour math into FormHelper::hour() makes that method generally more correct and lenient on its input. Fixes #3299 --- .../Test/Case/View/Helper/FormHelperTest.php | 40 ++++++++----------- lib/Cake/View/Helper/FormHelper.php | 10 +++-- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 9da345458..d4ce34deb 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -2224,9 +2224,9 @@ class FormHelperTest extends CakeTestCase { 'type' => 'time', 'selected' => '18:15' )); - $this->assertRegExp('##', $result); - $this->assertRegExp('##', $result); - $this->assertRegExp('##', $result); + $this->assertContains('', $result); + $this->assertContains('', $result); + $this->assertContains('', $result); } /** @@ -2235,6 +2235,15 @@ class FormHelperTest extends CakeTestCase { * @return void */ public function testTimeSelectedWithInterval() { + $result = $this->Form->input('Model.start_time', array( + 'type' => 'time', + 'interval' => 15, + 'selected' => '2012-10-23 15:57:00' + )); + $this->assertContains('', $result); + $this->assertContains('', $result); + $this->assertContains('', $result); + $result = $this->Form->input('Model.start_time', array( 'timeFormat' => 24, 'type' => 'time', @@ -5621,26 +5630,11 @@ class FormHelperTest extends CakeTestCase { $this->Form->request->data['Model']['field'] = ''; $result = $this->Form->hour('Model.field', true, array('value' => '23')); - $expected = array( - array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')), - array('option' => array('value' => '')), - '/option', - array('option' => array('value' => '00')), - '0', - '/option', - array('option' => array('value' => '01')), - '1', - '/option', - array('option' => array('value' => '02')), - '2', - '/option', - $hoursRegex, - array('option' => array('value' => '23', 'selected' => 'selected')), - '23', - '/option', - '/select', - ); - $this->assertTags($result, $expected); + $this->assertContains('', $result); + + $result = $this->Form->hour('Model.field', false, array('value' => '23')); + $this->assertContains('', $result); + $this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32'; $result = $this->Form->hour('Model.field', true); diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 301acaaec..ea843e4ae 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -2042,6 +2042,11 @@ class FormHelper extends AppHelper { } elseif ($attributes['value'] === false) { $attributes['value'] = null; } + + if ($attributes['value'] > 12 && !$format24Hours) { + $attributes['value'] -= 12; + } + return $this->select( $fieldName . ".hour", $this->_generateOptions($format24Hours ? 'hour24' : 'hour'), @@ -2206,10 +2211,7 @@ class FormHelper extends AppHelper { if (!empty($timeFormat)) { $time = explode(':', $days[1]); - if (($time[0] > 12) && $timeFormat == '12') { - $time[0] = $time[0] - 12; - $meridian = 'pm'; - } elseif ($time[0] == '12' && $timeFormat == '12') { + if ($time[0] >= '12' && $timeFormat == '12') { $meridian = 'pm'; } elseif ($time[0] == '00' && $timeFormat == '12') { $time[0] = 12; From 2ac08bf024055dcf0a87ab81c5aee09080e52bf8 Mon Sep 17 00:00:00 2001 From: euromark Date: Tue, 23 Oct 2012 19:04:52 +0200 Subject: [PATCH 40/85] fix whitespace --- lib/Cake/View/Helper/FormHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 6d82b2865..4faff6a92 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -1016,7 +1016,7 @@ class FormHelper extends AppHelper { !array_key_exists('maxlength', $options) && isset($fieldDef['length']) && is_scalar($fieldDef['length']) && - $options['type'] !== 'select' + $options['type'] !== 'select' ); if ($autoLength && $options['type'] == 'text') { $options['maxlength'] = $fieldDef['length']; From 528671f468c9d5d74c11f04fe02b54201ddab156 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 25 Oct 2012 10:07:39 -0400 Subject: [PATCH 41/85] Replace Set with Hash. --- lib/Cake/Network/CakeRequest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index bee097565..081558597 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -15,8 +15,7 @@ * @since CakePHP(tm) v 2.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ - -App::uses('Set', 'Utility'); +App::uses('Hash', 'Utility'); /** * A class that helps wrap Request information and particulars about a single request. @@ -353,7 +352,7 @@ class CakeRequest implements ArrayAccess { $this->_processFileData($newPath, $fields, $field); } else { $newPath .= '.' . $field; - $this->data = Set::insert($this->data, $newPath, $fields); + $this->data = Hash::insert($this->data, $newPath, $fields); } } } From d269588e78ce0b20e986136a598e548bdfabe3aa Mon Sep 17 00:00:00 2001 From: Ber Clausen Date: Thu, 25 Oct 2012 12:19:53 -0300 Subject: [PATCH 42/85] Avoid duplicating RequestHandler component. --- lib/Cake/Controller/CakeErrorController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Controller/CakeErrorController.php b/lib/Cake/Controller/CakeErrorController.php index 577864881..3bcbd72ce 100644 --- a/lib/Cake/Controller/CakeErrorController.php +++ b/lib/Cake/Controller/CakeErrorController.php @@ -50,7 +50,11 @@ class CakeErrorController extends AppController { */ public function __construct($request = null, $response = null) { parent::__construct($request, $response); - if (count(Router::extensions())) { + if ( + count(Router::extensions()) && + !array_key_exists('RequestHandler', $this->components) && + !in_array('RequestHandler', $this->components, true) + ) { $this->components[] = 'RequestHandler'; } $this->constructClasses(); From c741f60367be5bba21fb96f65ac220106148ceaa Mon Sep 17 00:00:00 2001 From: Ber Clausen Date: Thu, 25 Oct 2012 17:32:32 -0300 Subject: [PATCH 43/85] Make Model::find('first') always return an array. --- lib/Cake/Model/Model.php | 15 +++++++++------ .../Case/Model/Behavior/TranslateBehaviorTest.php | 2 +- lib/Cake/Test/Case/Model/ModelDeleteTest.php | 14 +++++++------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index a66574b91..9e7cec275 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -2613,9 +2613,12 @@ class Model extends Object implements CakeEventListener { * * Note: find(list) + database views have issues with MySQL 5.0. Try upgrading to MySQL 5.1 if you * have issues with database views. + * + * Note: find(count) has its own return values. + * * @param string $type Type of find operation (all / first / count / neighbors / list / threaded) * @param array $query Option fields (conditions / fields / joins / limit / offset / order / page / group / callbacks) - * @return array Array of records + * @return array Array of records, or Null on failure. * @link http://book.cakephp.org/2.0/en/models/deleting-data.html#deleteall */ public function find($type = 'first', $query = array()) { @@ -2638,10 +2641,10 @@ class Model extends Object implements CakeEventListener { if ($type === 'all') { return $results; - } else { - if ($this->findMethods[$type] === true) { - return $this->{'_find' . ucfirst($type)}('after', $query, $results); - } + } + + if ($this->findMethods[$type] === true) { + return $this->{'_find' . ucfirst($type)}('after', $query, $results); } } @@ -2707,7 +2710,7 @@ class Model extends Object implements CakeEventListener { return $query; } elseif ($state === 'after') { if (empty($results[0])) { - return false; + return array(); } return $results[0]; } diff --git a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php index 9a7ab4342..73d460b92 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php @@ -422,7 +422,7 @@ class TranslateBehaviorTest extends CakeTestCase { $TestModel = new TranslatedItem(); $TestModel->locale = 'rus'; $result = $TestModel->read(null, 1); - $this->assertFalse($result); + $this->assertEquals(array(), $result); $TestModel->locale = array('rus'); $result = $TestModel->read(null, 1); diff --git a/lib/Cake/Test/Case/Model/ModelDeleteTest.php b/lib/Cake/Test/Case/Model/ModelDeleteTest.php index 329eef387..80eef2210 100644 --- a/lib/Cake/Test/Case/Model/ModelDeleteTest.php +++ b/lib/Cake/Test/Case/Model/ModelDeleteTest.php @@ -107,7 +107,7 @@ class ModelDeleteTest extends BaseModelTest { $result = $Portfolio->find('first', array( 'conditions' => array('Portfolio.id' => 1) )); - $this->assertFalse($result); + $this->assertEquals(array(), $result); $result = $Portfolio->ItemsPortfolio->find('all', array( 'conditions' => array('ItemsPortfolio.portfolio_id' => 1) @@ -195,7 +195,7 @@ class ModelDeleteTest extends BaseModelTest { $this->assertTrue($result); $result = $TestModel->read(null, 2); - $this->assertFalse($result); + $this->assertEquals(array(), $result); $TestModel->recursive = -1; $result = $TestModel->find('all', array( @@ -216,7 +216,7 @@ class ModelDeleteTest extends BaseModelTest { $this->assertTrue($result); $result = $TestModel->read(null, 3); - $this->assertFalse($result); + $this->assertEquals(array(), $result); $TestModel->recursive = -1; $result = $TestModel->find('all', array( @@ -448,16 +448,16 @@ class ModelDeleteTest extends BaseModelTest { $TestModel->recursive = 2; $result = $TestModel->read(null, 2); - $this->assertFalse($result); + $this->assertEquals(array(), $result); $result = $TestModel->Comment->read(null, 5); - $this->assertFalse($result); + $this->assertEquals(array(), $result); $result = $TestModel->Comment->read(null, 6); - $this->assertFalse($result); + $this->assertEquals(array(), $result); $result = $TestModel->Comment->Attachment->read(null, 1); - $this->assertFalse($result); + $this->assertEquals(array(), $result); $result = $TestModel->find('count'); $this->assertEquals(2, $result); From c359e4b6890a3cfa979b413f4e1b63c80ccd96cc Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 25 Oct 2012 20:46:54 -0400 Subject: [PATCH 44/85] Fix issue with array based values and interval. Fixes #3299 --- lib/Cake/Test/Case/View/Helper/FormHelperTest.php | 9 +++++++++ lib/Cake/View/Helper/FormHelper.php | 3 +++ 2 files changed, 12 insertions(+) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 59d5e8c46..855c97c60 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -2235,6 +2235,15 @@ class FormHelperTest extends CakeTestCase { * @return void */ public function testTimeSelectedWithInterval() { + $result = $this->Form->input('Model.start_time', array( + 'type' => 'time', + 'interval' => 15, + 'selected' => array('hour' => '3', 'min' => '57', 'meridian' => 'pm') + )); + $this->assertContains('', $result); + $this->assertContains('', $result); + $this->assertContains('', $result); + $result = $this->Form->input('Model.start_time', array( 'type' => 'time', 'interval' => 15, diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 4cf59532d..b5ce4c367 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -2197,6 +2197,9 @@ class FormHelper extends AppHelper { if (!empty($attributes['value'])) { if (is_array($attributes['value'])) { extract($attributes['value']); + if ($meridian === 'pm') { + $hour += 12; + } } else { if (is_numeric($attributes['value'])) { $attributes['value'] = strftime('%Y-%m-%d %H:%M:%S', $attributes['value']); From 50a4b792be7622abc2dfb57d5938925f19ec6e9e Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 25 Oct 2012 21:28:01 -0400 Subject: [PATCH 45/85] Clean up code in FormHelper::dateTime() Remove $$ variables and split a huge method into smaller pieces. --- lib/Cake/View/Helper/FormHelper.php | 197 +++++++++++++++------------- 1 file changed, 105 insertions(+), 92 deletions(-) diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index b5ce4c367..6926991b3 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -2195,50 +2195,12 @@ class FormHelper extends AppHelper { } if (!empty($attributes['value'])) { - if (is_array($attributes['value'])) { - extract($attributes['value']); - if ($meridian === 'pm') { - $hour += 12; - } - } else { - if (is_numeric($attributes['value'])) { - $attributes['value'] = strftime('%Y-%m-%d %H:%M:%S', $attributes['value']); - } - $meridian = 'am'; - $pos = strpos($attributes['value'], '-'); - if ($pos !== false) { - $date = explode('-', $attributes['value']); - $days = explode(' ', $date[2]); - $day = $days[0]; - $month = $date[1]; - $year = $date[0]; - } else { - $days[1] = $attributes['value']; - } - - if (!empty($timeFormat)) { - $time = explode(':', $days[1]); - - if ($time[0] >= '12' && $timeFormat == '12') { - $meridian = 'pm'; - } elseif ($time[0] == '00' && $timeFormat == '12') { - $time[0] = 12; - } elseif ($time[0] >= 12) { - $meridian = 'pm'; - } - if ($time[0] == 0 && $timeFormat == '12') { - $time[0] = 12; - } - $hour = $min = null; - if (isset($time[1])) { - $hour = $time[0]; - $min = $time[1]; - } - } - } + list($year, $month, $day, $hour, $min, $meridian) = $this->_getDateTimeValue( + $attributes['value'], + $timeFormat + ); } - $elements = array('Day', 'Month', 'Year', 'Hour', 'Minute', 'Meridian'); $defaults = array( 'minYear' => null, 'maxYear' => null, 'separator' => '-', 'interval' => 1, 'monthNames' => true @@ -2269,42 +2231,42 @@ class FormHelper extends AppHelper { list($year, $month, $day, $hour, $min, $meridian) = $newTime; } - if (isset($attributes['id'])) { - if (is_string($attributes['id'])) { - // build out an array version - foreach ($elements as $element) { - $selectAttrName = 'select' . $element . 'Attr'; - ${$selectAttrName} = $attributes; - ${$selectAttrName}['id'] = $attributes['id'] . $element; - } - } elseif (is_array($attributes['id'])) { - // check for missing ones and build selectAttr for each element - $attributes['id'] += array( - 'month' => '', 'year' => '', 'day' => '', - 'hour' => '', 'minute' => '', 'meridian' => '' - ); - foreach ($elements as $element) { - $selectAttrName = 'select' . $element . 'Attr'; - ${$selectAttrName} = $attributes; - ${$selectAttrName}['id'] = $attributes['id'][strtolower($element)]; - } + $keys = array('Day', 'Month', 'Year', 'Hour', 'Minute', 'Meridian'); + $attrs = array_fill_keys($keys, $attributes); + + $hasId = isset($attributes['id']); + if ($hasId && is_array($attributes['id'])) { + // check for missing ones and build selectAttr for each element + $attributes['id'] += array( + 'month' => '', + 'year' => '', + 'day' => '', + 'hour' => '', + 'minute' => '', + 'meridian' => '' + ); + foreach ($keys as $key) { + $attrs[$key]['id'] = $attributes['id'][strtolower($key)]; } - } else { - // build the selectAttrName with empty id's to pass - foreach ($elements as $element) { - $selectAttrName = 'select' . $element . 'Attr'; - ${$selectAttrName} = $attributes; + } + if ($hasId && is_string($attributes['id'])) { + // build out an array version + foreach ($keys as $key) { + $attrs[$key]['id'] = $attributes['id'] . $key; } } if (is_array($attributes['empty'])) { $attributes['empty'] += array( - 'month' => true, 'year' => true, 'day' => true, - 'hour' => true, 'minute' => true, 'meridian' => true + 'month' => true, + 'year' => true, + 'day' => true, + 'hour' => true, + 'minute' => true, + 'meridian' => true ); - foreach ($elements as $element) { - $selectAttrName = 'select' . $element . 'Attr'; - ${$selectAttrName}['empty'] = $attributes['empty'][strtolower($element)]; + foreach ($keys as $key) { + $attrs[$key]['empty'] = $attributes['empty'][strtolower($key)]; } } @@ -2312,47 +2274,98 @@ class FormHelper extends AppHelper { foreach (preg_split('//', $dateFormat, -1, PREG_SPLIT_NO_EMPTY) as $char) { switch ($char) { case 'Y': - $selectYearAttr['value'] = $year; + $attrs['Year']['value'] = $year; $selects[] = $this->year( - $fieldName, $minYear, $maxYear, $selectYearAttr + $fieldName, $minYear, $maxYear, $attrs['Year'] ); break; case 'M': - $selectMonthAttr['value'] = $month; - $selectMonthAttr['monthNames'] = $monthNames; - $selects[] = $this->month($fieldName, $selectMonthAttr); + $attrs['Month']['value'] = $month; + $attrs['Month']['monthNames'] = $monthNames; + $selects[] = $this->month($fieldName, $attrs['Month']); break; case 'D': - $selectDayAttr['value'] = $day; - $selects[] = $this->day($fieldName, $selectDayAttr); + $attrs['Day']['value'] = $day; + $selects[] = $this->day($fieldName, $attrs['Day']); break; } } $opt = implode($separator, $selects); - $selectMinuteAttr['interval'] = $interval; + $attrs['Minute']['interval'] = $interval; switch ($timeFormat) { case '24': - $selectHourAttr['value'] = $hour; - $selectMinuteAttr['value'] = $min; - $opt .= $this->hour($fieldName, true, $selectHourAttr) . ':' . - $this->minute($fieldName, $selectMinuteAttr); + $attrs['Hour']['value'] = $hour; + $attrs['Minute']['value'] = $min; + $opt .= $this->hour($fieldName, true, $attrs['Hour']) . ':' . + $this->minute($fieldName, $attrs['Minute']); break; case '12': - $selectHourAttr['value'] = $hour; - $selectMinuteAttr['value'] = $min; - $selectMeridianAttr['value'] = $meridian; - $opt .= $this->hour($fieldName, false, $selectHourAttr) . ':' . - $this->minute($fieldName, $selectMinuteAttr) . ' ' . - $this->meridian($fieldName, $selectMeridianAttr); - break; - default: - $opt .= ''; + $attrs['Hour']['value'] = $hour; + $attrs['Minute']['value'] = $min; + $attrs['Meridian']['value'] = $meridian; + $opt .= $this->hour($fieldName, false, $attrs['Hour']) . ':' . + $this->minute($fieldName, $attrs['Minute']) . ' ' . + $this->meridian($fieldName, $attrs['Meridian']); break; } return $opt; } +/** + * Parse the value for a datetime selected value + * + * @param string|array $value The selected value. + * @param integer $timeFormat The time format + * @return array Array of selected value. + */ + protected function _getDateTimeValue($value, $timeFormat) { + $year = $month = $day = $hour = $min = $meridian = null; + if (is_array($value)) { + extract($value); + if ($meridian === 'pm') { + $hour += 12; + } + return array($year, $month, $day, $hour, $min, $meridian); + } + + if (is_numeric($value)) { + $value = strftime('%Y-%m-%d %H:%M:%S', $value); + } + $meridian = 'am'; + $pos = strpos($value, '-'); + if ($pos !== false) { + $date = explode('-', $value); + $days = explode(' ', $date[2]); + $day = $days[0]; + $month = $date[1]; + $year = $date[0]; + } else { + $days[1] = $value; + } + + if (!empty($timeFormat)) { + $time = explode(':', $days[1]); + + if ($time[0] >= '12' && $timeFormat == '12') { + $meridian = 'pm'; + } elseif ($time[0] == '00' && $timeFormat == '12') { + $time[0] = 12; + } elseif ($time[0] >= 12) { + $meridian = 'pm'; + } + if ($time[0] == 0 && $timeFormat == '12') { + $time[0] = 12; + } + $hour = $min = null; + if (isset($time[1])) { + $hour = $time[0]; + $min = $time[1]; + } + } + return array($year, $month, $day, $hour, $min, $meridian); + } + /** * Gets the input field name for the current tag * From 559130b87b508ef3575492c4b4168a4669f80d7e Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 25 Oct 2012 21:56:00 -0400 Subject: [PATCH 46/85] Try and make test less likely to fail. --- lib/Cake/Test/Case/Cache/Engine/MemcacheEngineTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Cake/Test/Case/Cache/Engine/MemcacheEngineTest.php b/lib/Cake/Test/Case/Cache/Engine/MemcacheEngineTest.php index 88a7b6143..54c225c72 100644 --- a/lib/Cake/Test/Case/Cache/Engine/MemcacheEngineTest.php +++ b/lib/Cake/Test/Case/Cache/Engine/MemcacheEngineTest.php @@ -229,12 +229,11 @@ class MemcacheEngineTest extends CakeTestCase { $result = Cache::write('other_test', $data, 'memcache'); $this->assertTrue($result); - sleep(2); + sleep(3); $result = Cache::read('other_test', 'memcache'); $this->assertFalse($result); Cache::config('memcache', array('duration' => '+1 second')); - sleep(2); $result = Cache::read('other_test', 'memcache'); $this->assertFalse($result); From 0ddd130833f0b95a979234eea32bd4a711ac44d3 Mon Sep 17 00:00:00 2001 From: ADmad Date: Fri, 26 Oct 2012 12:58:24 +0530 Subject: [PATCH 47/85] Improved "required" field detection. Closes #3305. --- .../Test/Case/View/Helper/FormHelperTest.php | 19 +++++++++++++++++++ lib/Cake/View/Helper/FormHelper.php | 6 +++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 855c97c60..89b37c724 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -119,6 +119,11 @@ class Contact extends CakeTestModel { 'between' => array('rule' => array('between', 5, 30), 'allowEmpty' => true), ), 'imnotrequiredeither' => array('required' => true, 'rule' => array('between', 5, 30), 'allowEmpty' => true), + 'iamrequiredalways' => array( + 'email' => array('rule' => 'email'), + 'rule_on_create' => array('rule' => array('maxLength', 50), 'on' => 'create'), + 'rule_on_update' => array('rule' => array('between', 1, 50), 'on' => 'update'), + ), ); /** @@ -7068,6 +7073,20 @@ class FormHelperTest extends CakeTestCase { '/div' ); $this->assertTags($result, $expected); + + $result = $this->Form->input('Contact.iamrequiredalways'); + $expected = array( + 'div' => array('class' => 'input text required'), + 'label' => array('for' => 'ContactIamrequiredalways'), + 'Iamrequiredalways', + '/label', + 'input' => array( + 'type' => 'text', 'name' => 'data[Contact][iamrequiredalways]', + 'id' => 'ContactIamrequiredalways' + ), + '/div' + ); + $this->assertTags($result, $expected); } /** diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 6926991b3..24f586801 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -249,11 +249,11 @@ class FormHelper extends AppHelper { } foreach ($validationRules as $rule) { $rule->isUpdate($this->requestType === 'put'); - if ($rule->isEmptyAllowed()) { - return false; + if (!$rule->isEmptyAllowed()) { + return true; } } - return true; + return false; } /** From 39dcb80b451dec37e44750482a0d207109dcac11 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Fri, 26 Oct 2012 16:32:15 +0200 Subject: [PATCH 48/85] Fix failing test, find('first') now returns empty array when no record was found --- lib/Cake/Test/Case/Console/Command/AclShellTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Console/Command/AclShellTest.php b/lib/Cake/Test/Case/Console/Command/AclShellTest.php index 7dfbbc061..eaafdcf10 100644 --- a/lib/Cake/Test/Case/Console/Command/AclShellTest.php +++ b/lib/Cake/Test/Case/Console/Command/AclShellTest.php @@ -177,7 +177,7 @@ class AclShellTest extends CakeTestCase { $Aro = ClassRegistry::init('Aro'); $result = $Aro->findById(3); - $this->assertFalse($result); + $this->assertEmpty($result); } /** From 870d77c89e3462ac01d765b73b62bc8c52830646 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Fri, 26 Oct 2012 20:49:04 +0200 Subject: [PATCH 49/85] Make the test more accurate on type of result --- lib/Cake/Test/Case/Console/Command/AclShellTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Console/Command/AclShellTest.php b/lib/Cake/Test/Case/Console/Command/AclShellTest.php index eaafdcf10..cf98cabf5 100644 --- a/lib/Cake/Test/Case/Console/Command/AclShellTest.php +++ b/lib/Cake/Test/Case/Console/Command/AclShellTest.php @@ -177,7 +177,7 @@ class AclShellTest extends CakeTestCase { $Aro = ClassRegistry::init('Aro'); $result = $Aro->findById(3); - $this->assertEmpty($result); + $this->assertSame(array(), $result); } /** From a7d9422c099694031503c2772c5e2cf3c4d39385 Mon Sep 17 00:00:00 2001 From: Ber Clausen Date: Fri, 26 Oct 2012 19:18:05 -0300 Subject: [PATCH 50/85] Test all empty array with assertSame() because assertEquals() does not check the type. --- lib/Cake/Test/Case/BasicsTest.php | 2 +- .../Console/Command/Task/ControllerTaskTest.php | 4 ++-- lib/Cake/Test/Case/Core/AppTest.php | 6 +++--- lib/Cake/Test/Case/Log/CakeLogTest.php | 2 +- .../Model/Behavior/TranslateBehaviorTest.php | 6 +++--- .../Model/Datasource/Database/SqlserverTest.php | 2 +- lib/Cake/Test/Case/Model/ModelDeleteTest.php | 16 ++++++++-------- lib/Cake/Test/Case/Model/ModelReadTest.php | 2 +- lib/Cake/Test/Case/Model/ModelWriteTest.php | 4 ++-- lib/Cake/Test/Case/Routing/RouterTest.php | 6 +++--- lib/Cake/Test/Case/Utility/SetTest.php | 2 +- lib/Cake/Test/Case/View/Helper/JsHelperTest.php | 2 +- 12 files changed, 27 insertions(+), 27 deletions(-) diff --git a/lib/Cake/Test/Case/BasicsTest.php b/lib/Cake/Test/Case/BasicsTest.php index 0c12fed6f..0998dfa77 100644 --- a/lib/Cake/Test/Case/BasicsTest.php +++ b/lib/Cake/Test/Case/BasicsTest.php @@ -67,7 +67,7 @@ class BasicsTest extends CakeTestCase { $one = array('minYear' => null, 'maxYear' => null, 'separator' => '-', 'interval' => 1, 'monthNames' => true); $two = array('minYear' => null, 'maxYear' => null, 'separator' => '-', 'interval' => 1, 'monthNames' => true); $result = array_diff_key($one, $two); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); } /** diff --git a/lib/Cake/Test/Case/Console/Command/Task/ControllerTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/ControllerTaskTest.php index a17d2bb9d..4d11cbe60 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/ControllerTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/ControllerTaskTest.php @@ -181,7 +181,7 @@ class ControllerTaskTest extends CakeTestCase { public function testDoHelpersNo() { $this->Task->expects($this->any())->method('in')->will($this->returnValue('n')); $result = $this->Task->doHelpers(); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); } /** @@ -218,7 +218,7 @@ class ControllerTaskTest extends CakeTestCase { public function testDoComponentsNo() { $this->Task->expects($this->any())->method('in')->will($this->returnValue('n')); $result = $this->Task->doComponents(); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); } /** diff --git a/lib/Cake/Test/Case/Core/AppTest.php b/lib/Cake/Test/Case/Core/AppTest.php index 3b6cef55e..0c66766cd 100644 --- a/lib/Cake/Test/Case/Core/AppTest.php +++ b/lib/Cake/Test/Case/Core/AppTest.php @@ -347,7 +347,7 @@ class AppTest extends CakeTestCase { $this->assertEquals($expected, $result); $result = App::objects('NonExistingType'); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); App::build(array( 'plugins' => array( @@ -414,9 +414,9 @@ class AppTest extends CakeTestCase { $this->assertTrue(in_array('OtherComponent', $result)); $result = App::objects('TestPluginTwo.behavior'); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); $result = App::objects('TestPluginTwo.Model/Behavior'); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); $result = App::objects('model', null, false); $this->assertTrue(in_array('Comment', $result)); diff --git a/lib/Cake/Test/Case/Log/CakeLogTest.php b/lib/Cake/Test/Case/Log/CakeLogTest.php index e54f2c71a..2caaac0c6 100644 --- a/lib/Cake/Test/Case/Log/CakeLogTest.php +++ b/lib/Cake/Test/Case/Log/CakeLogTest.php @@ -175,7 +175,7 @@ class CakeLogTest extends CakeTestCase { CakeLog::drop('file'); $result = CakeLog::configured(); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); } /** diff --git a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php index 73d460b92..a73ccd17c 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php @@ -422,7 +422,7 @@ class TranslateBehaviorTest extends CakeTestCase { $TestModel = new TranslatedItem(); $TestModel->locale = 'rus'; $result = $TestModel->read(null, 1); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); $TestModel->locale = array('rus'); $result = $TestModel->read(null, 1); @@ -460,10 +460,10 @@ class TranslateBehaviorTest extends CakeTestCase { Configure::write('debug', 0); $result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => false)); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); $result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => 'after')); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); Configure::write('debug', $debug); } diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php index e31595bf3..ee7695a5f 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php @@ -574,7 +574,7 @@ class SqlserverTest extends CakeTestCase { $indexes = array('client_id' => array('column' => 'client_id')); $result = $this->db->buildIndex($indexes, 'items'); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); $indexes = array('client_id' => array('column' => array('client_id', 'period_id'), 'unique' => 1)); $result = $this->db->buildIndex($indexes, 'items'); diff --git a/lib/Cake/Test/Case/Model/ModelDeleteTest.php b/lib/Cake/Test/Case/Model/ModelDeleteTest.php index 80eef2210..7a69585c6 100644 --- a/lib/Cake/Test/Case/Model/ModelDeleteTest.php +++ b/lib/Cake/Test/Case/Model/ModelDeleteTest.php @@ -107,12 +107,12 @@ class ModelDeleteTest extends BaseModelTest { $result = $Portfolio->find('first', array( 'conditions' => array('Portfolio.id' => 1) )); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); $result = $Portfolio->ItemsPortfolio->find('all', array( 'conditions' => array('ItemsPortfolio.portfolio_id' => 1) )); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); } /** @@ -195,7 +195,7 @@ class ModelDeleteTest extends BaseModelTest { $this->assertTrue($result); $result = $TestModel->read(null, 2); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); $TestModel->recursive = -1; $result = $TestModel->find('all', array( @@ -216,7 +216,7 @@ class ModelDeleteTest extends BaseModelTest { $this->assertTrue($result); $result = $TestModel->read(null, 3); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); $TestModel->recursive = -1; $result = $TestModel->find('all', array( @@ -448,16 +448,16 @@ class ModelDeleteTest extends BaseModelTest { $TestModel->recursive = 2; $result = $TestModel->read(null, 2); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); $result = $TestModel->Comment->read(null, 5); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); $result = $TestModel->Comment->read(null, 6); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); $result = $TestModel->Comment->Attachment->read(null, 1); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); $result = $TestModel->find('count'); $this->assertEquals(2, $result); diff --git a/lib/Cake/Test/Case/Model/ModelReadTest.php b/lib/Cake/Test/Case/Model/ModelReadTest.php index 6f14e47a2..c416bba3f 100644 --- a/lib/Cake/Test/Case/Model/ModelReadTest.php +++ b/lib/Cake/Test/Case/Model/ModelReadTest.php @@ -4290,7 +4290,7 @@ class ModelReadTest extends BaseModelTest { $TestModel->resetAssociations(); $result = $TestModel->hasMany; - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); $result = $TestModel->bindModel(array('hasMany' => array('Comment')), false); $this->assertTrue($result); diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index 7b4e5a07c..1a015ef42 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -4536,7 +4536,7 @@ class ModelWriteTest extends BaseModelTest { $this->assertFalse($result); $result = $model->find('all'); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); $expected = array('Comment' => array( 1 => array('comment' => array('This field cannot be left blank')) )); @@ -5940,7 +5940,7 @@ class ModelWriteTest extends BaseModelTest { $this->assertFalse($result); $result = $model->find('all'); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); $expected = array('Comment' => array( 1 => array('comment' => array('This field cannot be left blank')) )); diff --git a/lib/Cake/Test/Case/Routing/RouterTest.php b/lib/Cake/Test/Case/Routing/RouterTest.php index b4c956de0..65e1ed7a9 100644 --- a/lib/Cake/Test/Case/Routing/RouterTest.php +++ b/lib/Cake/Test/Case/Routing/RouterTest.php @@ -111,7 +111,7 @@ class RouterTest extends CakeTestCase { $_SERVER['REQUEST_METHOD'] = 'GET'; $result = Router::parse('/posts/add'); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); Router::reload(); $resources = Router::mapResources('Posts', array('id' => '[a-z0-9_]+')); @@ -1907,7 +1907,7 @@ class RouterTest extends CakeTestCase { $this->assertEquals($expected, $result); $result = Router::parse('/blog/foobar'); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); $result = Router::url(array('controller' => 'blog_posts', 'action' => 'foo')); $this->assertEquals('/blog_posts/foo', $result); @@ -2117,7 +2117,7 @@ class RouterTest extends CakeTestCase { $this->assertEquals($expected, $result); $result = Router::parse('/badness/test/test_action'); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); Router::reload(); Router::connect('/:locale/:controller/:action/*', array(), array('locale' => 'dan|eng')); diff --git a/lib/Cake/Test/Case/Utility/SetTest.php b/lib/Cake/Test/Case/Utility/SetTest.php index e1c18a8a5..00d363dba 100644 --- a/lib/Cake/Test/Case/Utility/SetTest.php +++ b/lib/Cake/Test/Case/Utility/SetTest.php @@ -1967,7 +1967,7 @@ class SetTest extends CakeTestCase { $this->assertEquals($expected, $result); $result = Set::combine($a, 'fail', 'fail'); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); } /** diff --git a/lib/Cake/Test/Case/View/Helper/JsHelperTest.php b/lib/Cake/Test/Case/View/Helper/JsHelperTest.php index 950e5c221..47833e085 100644 --- a/lib/Cake/Test/Case/View/Helper/JsHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/JsHelperTest.php @@ -904,7 +904,7 @@ class JsBaseEngineTest extends CakeTestCase { public function testOptionMapping() { $JsEngine = new OptionEngineHelper($this->View); $result = $JsEngine->testMap(); - $this->assertEquals(array(), $result); + $this->assertSame(array(), $result); $result = $JsEngine->testMap(array('foo' => 'bar', 'baz' => 'sho')); $this->assertEquals(array('foo' => 'bar', 'baz' => 'sho'), $result); From e8f727fe688855369101a4d5fffcdd7458e0473a Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 27 Oct 2012 21:12:34 -0400 Subject: [PATCH 51/85] Using fixed points in time. This avoids lulz when the United Kingdom changes change to/from DST at a different time than your local timezone. --- lib/Cake/Test/Case/Utility/CakeTimeTest.php | 23 +++++++++++---------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/CakeTimeTest.php b/lib/Cake/Test/Case/Utility/CakeTimeTest.php index 7185ef00f..629446414 100644 --- a/lib/Cake/Test/Case/Utility/CakeTimeTest.php +++ b/lib/Cake/Test/Case/Utility/CakeTimeTest.php @@ -474,7 +474,7 @@ class CakeTimeTest extends CakeTestCase { date_default_timezone_set('UTC'); - $serverTime = new DateTime('now'); + $serverTime = new DateTime('2012-12-11 14:15:20'); $timezones = array('Europe/London', 'Europe/Brussels', 'UTC', 'America/Denver', 'America/Caracas', 'Asia/Kathmandu'); foreach ($timezones as $timezone) { @@ -509,17 +509,18 @@ class CakeTimeTest extends CakeTestCase { * @return void */ public function testToRss() { - $this->assertEquals(date('r'), $this->Time->toRss(time())); + $date = '2012-08-12 12:12:45'; + $time = strtotime($date); + $this->assertEquals(date('r', $time), $this->Time->toRss($time)); - if (!$this->skipIf(!class_exists('DateTimeZone'), '%s DateTimeZone class not available.')) { - $timezones = array('Europe/London', 'Europe/Brussels', 'UTC', 'America/Denver', 'America/Caracas', 'Asia/Kathmandu'); - foreach ($timezones as $timezone) { - $yourTimezone = new DateTimeZone($timezone); - $yourTime = new DateTime('now', $yourTimezone); - $userOffset = $yourTimezone->getOffset($yourTime) / HOUR; - $this->assertEquals($yourTime->format('r'), $this->Time->toRss(time(), $userOffset)); - $this->assertEquals($yourTime->format('r'), $this->Time->toRss(time(), $timezone)); - } + $timezones = array('Europe/London', 'Europe/Brussels', 'UTC', 'America/Denver', 'America/Caracas', 'Asia/Kathmandu'); + foreach ($timezones as $timezone) { + $yourTimezone = new DateTimeZone($timezone); + $yourTime = new DateTime($date, $yourTimezone); + $userOffset = $yourTimezone->getOffset($yourTime) / HOUR; + $time = $yourTime->getTimestamp(); + $this->assertEquals($yourTime->format('r'), $this->Time->toRss($time, $userOffset), "Failed on $timezone"); + $this->assertEquals($yourTime->format('r'), $this->Time->toRss($time, $timezone), "Failed on $timezone"); } } From 667dfd308f25db57e8ee4a3e3877dbff0844035b Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 27 Oct 2012 22:49:43 -0400 Subject: [PATCH 52/85] DateTime::getTimestamp() only exists in PHP > 5.3.0 --- lib/Cake/Test/Case/Utility/CakeTimeTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Utility/CakeTimeTest.php b/lib/Cake/Test/Case/Utility/CakeTimeTest.php index 629446414..eadb1cde0 100644 --- a/lib/Cake/Test/Case/Utility/CakeTimeTest.php +++ b/lib/Cake/Test/Case/Utility/CakeTimeTest.php @@ -518,7 +518,7 @@ class CakeTimeTest extends CakeTestCase { $yourTimezone = new DateTimeZone($timezone); $yourTime = new DateTime($date, $yourTimezone); $userOffset = $yourTimezone->getOffset($yourTime) / HOUR; - $time = $yourTime->getTimestamp(); + $time = $yourTime->format('U'); $this->assertEquals($yourTime->format('r'), $this->Time->toRss($time, $userOffset), "Failed on $timezone"); $this->assertEquals($yourTime->format('r'), $this->Time->toRss($time, $timezone), "Failed on $timezone"); } From ab2ce29bd690a6111354edbbe8ac88d34c254986 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 28 Oct 2012 16:11:07 -0400 Subject: [PATCH 53/85] Fix a few more tests that sometimes fail on postgres. --- lib/Cake/Test/Case/Model/ModelReadTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Model/ModelReadTest.php b/lib/Cake/Test/Case/Model/ModelReadTest.php index c416bba3f..cdd32951d 100644 --- a/lib/Cake/Test/Case/Model/ModelReadTest.php +++ b/lib/Cake/Test/Case/Model/ModelReadTest.php @@ -4959,7 +4959,9 @@ class ModelReadTest extends BaseModelTest { public function testAssociationAfterFind() { $this->loadFixtures('Post', 'Author', 'Comment'); $TestModel = new Post(); - $result = $TestModel->find('all'); + $result = $TestModel->find('all', array( + 'order' => array('Post.id' => 'ASC') + )); $expected = array( array( 'Post' => array( @@ -5028,6 +5030,7 @@ class ModelReadTest extends BaseModelTest { ))); $result = $Author->find('all', array( 'conditions' => array('Author.id' => 1), + 'order' => array('Author.id' => 'ASC'), 'recursive' => 2 )); $expected = array( From 94bd2cedcf139eba5718016231d15e2d7fffe079 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 28 Oct 2012 16:15:20 -0400 Subject: [PATCH 54/85] Fix more off by a second errors --- lib/Cake/Test/Case/Utility/CakeTimeTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/CakeTimeTest.php b/lib/Cake/Test/Case/Utility/CakeTimeTest.php index eadb1cde0..f21d066c8 100644 --- a/lib/Cake/Test/Case/Utility/CakeTimeTest.php +++ b/lib/Cake/Test/Case/Utility/CakeTimeTest.php @@ -340,14 +340,14 @@ class CakeTimeTest extends CakeTestCase { $this->assertEquals(date('Y-d-m', $time), $this->Time->nice($time)); $this->assertEquals('%Y-%d-%m', $this->Time->niceFormat); - CakeTime::$niceFormat = '%Y-%d-%m %H:%M:%S'; - $this->assertEquals(date('Y-d-m H:i:s', $time), $this->Time->nice($time)); - $this->assertEquals('%Y-%d-%m %H:%M:%S', $this->Time->niceFormat); + CakeTime::$niceFormat = '%Y-%d-%m %H:%M'; + $this->assertEquals(date('Y-d-m H:i', $time), $this->Time->nice($time)); + $this->assertEquals('%Y-%d-%m %H:%M', $this->Time->niceFormat); date_default_timezone_set('UTC'); $result = $this->Time->nice(null, 'America/New_York'); $expected = $this->Time->nice(time(), 'America/New_York'); - $this->assertEquals($expected, $result); + $this->assertEquals(substr($expected, 0, -1), substr($result, 0, -1)); $this->_restoreSystemTimezone(); } From d9a3ab844f3c563bde72fd28fb990a220b67f3e6 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 28 Oct 2012 21:16:50 -0400 Subject: [PATCH 55/85] Fix another test that fails on postgres sometimes. --- lib/Cake/Test/Case/Model/ModelReadTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Model/ModelReadTest.php b/lib/Cake/Test/Case/Model/ModelReadTest.php index cdd32951d..e0afbd1b4 100644 --- a/lib/Cake/Test/Case/Model/ModelReadTest.php +++ b/lib/Cake/Test/Case/Model/ModelReadTest.php @@ -7759,7 +7759,9 @@ class ModelReadTest extends BaseModelTest { $this->assertEquals($expected, $result); $Post->Author->virtualFields = array('joined' => 'Post.id * Author.id'); - $result = $Post->find('all'); + $result = $Post->find('all', array( + 'order' => array('Post.id' => 'ASC') + )); $result = Hash::extract($result, '{n}.Author.joined'); $expected = array(1, 6, 3); $this->assertEquals($expected, $result); From b9ee4fc9f1abd1639bc20a5536f87ad7a5318dea Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 29 Oct 2012 22:28:12 -0400 Subject: [PATCH 56/85] URL decode redirect urls. Some servers send url encoded Location headers. Decode location headers before processing a redirect. Fixes #3310 --- lib/Cake/Network/Http/HttpSocket.php | 2 +- .../Test/Case/Network/Http/HttpSocketTest.php | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Network/Http/HttpSocket.php b/lib/Cake/Network/Http/HttpSocket.php index 502505676..bda8ec4c7 100644 --- a/lib/Cake/Network/Http/HttpSocket.php +++ b/lib/Cake/Network/Http/HttpSocket.php @@ -403,7 +403,7 @@ class HttpSocket extends CakeSocket { } if ($this->request['redirect'] && $this->response->isRedirect()) { - $request['uri'] = $this->response->getHeader('Location'); + $request['uri'] = trim(urldecode($this->response->getHeader('Location')), '='); $request['redirect'] = is_int($this->request['redirect']) ? $this->request['redirect'] - 1 : $this->request['redirect']; $this->response = $this->request($request); } diff --git a/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php b/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php index dfd7db98b..3fc70d742 100644 --- a/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php +++ b/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php @@ -762,6 +762,38 @@ class HttpSocketTest extends CakeTestCase { $this->assertEquals('HTTP/1.x 2', $response->first10); } +/** + * Test that redirect urls are urldecoded + * + * @return void + */ + public function testRequestWithRedirectUrlEncoded() { + $request = array( + 'uri' => 'http://localhost/oneuri', + 'redirect' => 1 + ); + $serverResponse1 = "HTTP/1.x 302 Found\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\nLocation: http://i.cmpnet.com%2Ftechonline%2Fpdf%2Fa.pdf=\r\n\r\n"; + $serverResponse2 = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n

You have been redirected

"; + + $this->Socket->expects($this->at(1)) + ->method('read') + ->will($this->returnValue($serverResponse1)); + + $this->Socket->expects($this->at(3)) + ->method('write') + ->with($this->logicalAnd( + $this->stringContains('Host: i.cmpnet.com'), + $this->stringContains('GET /techonline/pdf/a.pdf') + )); + + $this->Socket->expects($this->at(4)) + ->method('read') + ->will($this->returnValue($serverResponse2)); + + $response = $this->Socket->request($request); + $this->assertEquals('

You have been redirected

', $response->body()); + } + /** * testRequestWithRedirect method * @@ -781,6 +813,11 @@ class HttpSocketTest extends CakeTestCase { $this->assertEquals('

You have been redirected

', $response->body()); } +/** + * Test that redirects with a count limit are decremented. + * + * @return void + */ public function testRequestWithRedirectAsInt() { $request = array( 'uri' => 'http://localhost/oneuri', @@ -795,6 +832,11 @@ class HttpSocketTest extends CakeTestCase { $this->assertEquals(1, $this->Socket->request['redirect']); } +/** + * Test that redirects after the redirect count reaches 9 are not followed. + * + * @return void + */ public function testRequestWithRedirectAsIntReachingZero() { $request = array( 'uri' => 'http://localhost/oneuri', From 26d8351af4e2ad0096287313beec8cf96ee79829 Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 1 Nov 2012 05:04:37 +0530 Subject: [PATCH 57/85] Fixing "required" field detection again. Closes #3305 --- .../Test/Case/View/Helper/FormHelperTest.php | 18 ++++++++++++++++++ lib/Cake/View/Helper/FormHelper.php | 10 +++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 89b37c724..fd97171e0 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -115,6 +115,10 @@ class Contact extends CakeTestModel { 'required_one' => array('required' => array('rule' => array('notEmpty'))), 'imnotrequired' => array('required' => false, 'rule' => 'alphaNumeric', 'allowEmpty' => true), 'imalsonotrequired' => array( + 'alpha' => array('rule' => 'alphaNumeric', 'allowEmpty' => true), + 'between' => array('rule' => array('between', 5, 30)), + ), + 'imalsonotrequired2' => array( 'alpha' => array('rule' => 'alphaNumeric', 'allowEmpty' => true), 'between' => array('rule' => array('between', 5, 30), 'allowEmpty' => true), ), @@ -7060,6 +7064,20 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); + $result = $this->Form->input('Contact.imalsonotrequired2'); + $expected = array( + 'div' => array('class' => 'input text'), + 'label' => array('for' => 'ContactImalsonotrequired2'), + 'Imalsonotrequired2', + '/label', + 'input' => array( + 'type' => 'text', 'name' => 'data[Contact][imalsonotrequired2]', + 'id' => 'ContactImalsonotrequired2' + ), + '/div' + ); + $this->assertTags($result, $expected); + $result = $this->Form->input('Contact.imnotrequiredeither'); $expected = array( 'div' => array('class' => 'input text'), diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 24f586801..34c344c3d 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -247,11 +247,15 @@ class FormHelper extends AppHelper { if (empty($validationRules) || count($validationRules) === 0) { return false; } + + $isUpdate = $this->requestType === 'put'; foreach ($validationRules as $rule) { - $rule->isUpdate($this->requestType === 'put'); - if (!$rule->isEmptyAllowed()) { - return true; + $rule->isUpdate($isUpdate); + if ($rule->skip()) { + continue; } + + return !$rule->allowEmpty; } return false; } From 8035b37df2c18771e2e14fd6fdf847becc8f9297 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 31 Oct 2012 21:02:47 -0400 Subject: [PATCH 58/85] Only set $request->data with PUT/DELETE when it can be decoded. Setting $request->data to the raw put data isn't overly useful unless it can be decoded. Generally $request->data is expected to be an array, when its a string things can go funny. Fixes #3320 --- lib/Cake/Network/CakeRequest.php | 11 ++++++----- lib/Cake/Test/Case/Network/CakeRequestTest.php | 5 +++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index 081558597..903fa72ca 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -162,11 +162,12 @@ class CakeRequest implements ArrayAccess { protected function _processPost() { if ($_POST) { $this->data = $_POST; - } elseif ($this->is('put') || $this->is('delete')) { - $this->data = $this->_readInput(); - if (strpos(env('CONTENT_TYPE'), 'application/x-www-form-urlencoded') === 0) { - parse_str($this->data, $this->data); - } + } elseif ( + ($this->is('put') || $this->is('delete')) && + strpos(env('CONTENT_TYPE'), 'application/x-www-form-urlencoded') === 0 + ) { + $data = $this->_readInput(); + parse_str($data, $this->data); } if (ini_get('magic_quotes_gpc') === '1') { $this->data = stripslashes_deep($this->data); diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index e5ba8f850..d9ae235d4 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -311,9 +311,10 @@ class CakeRequestTest extends CakeTestCase { $request = $this->getMock('TestCakeRequest', array('_readInput')); $request->expects($this->at(0))->method('_readInput') - ->will($this->returnValue('{Article":["title"]}')); + ->will($this->returnValue('{"Article":["title"]}')); $request->reConstruct(); - $this->assertEquals('{Article":["title"]}', $request->data); + $result = $request->input('json_decode', true); + $this->assertEquals(array('title'), $result['Article']); } /** From 414e0a34848b2f9d90f7135dfc63ca2b6050e316 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 31 Oct 2012 22:51:37 -0400 Subject: [PATCH 59/85] Fix totally incorrect test. TranslateBehavior should never be overlapped with real fields. It should only be used to add fields that don't exist on the parent table. --- .../Model/Behavior/TreeBehaviorScopedTest.php | 64 ++++++++++++------- lib/Cake/Test/Fixture/FlagTreeFixture.php | 10 +-- 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php index b9e829758..9f5056387 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php @@ -169,12 +169,12 @@ class TreeBehaviorScopedTest extends CakeTestCase { public function testTranslatingTree() { $this->Tree = new FlagTree(); $this->Tree->cacheQueries = false; - $this->Tree->Behaviors->attach('Translate', array('name')); + $this->Tree->Behaviors->attach('Translate', array('title')); //Save $this->Tree->locale = 'eng'; $data = array('FlagTree' => array( - 'name' => 'name #1', + 'title' => 'name #1', 'locale' => 'eng', 'parent_id' => null, )); @@ -182,7 +182,8 @@ class TreeBehaviorScopedTest extends CakeTestCase { $result = $this->Tree->find('all'); $expected = array(array('FlagTree' => array( 'id' => 1, - 'name' => 'name #1', + 'title' => 'name #1', + 'name' => '', 'parent_id' => null, 'lft' => 1, 'rght' => 2, @@ -191,15 +192,16 @@ class TreeBehaviorScopedTest extends CakeTestCase { ))); $this->assertEquals($expected, $result); - //update existing record, same locale + // update existing record, same locale $this->Tree->create(); - $data['FlagTree']['name'] = 'Named 2'; + $data['FlagTree']['title'] = 'Named 2'; $this->Tree->id = 1; $this->Tree->save($data); $result = $this->Tree->find('all'); $expected = array(array('FlagTree' => array( 'id' => 1, - 'name' => 'Named 2', + 'title' => 'Named 2', + 'name' => '', 'parent_id' => null, 'lft' => 1, 'rght' => 2, @@ -208,51 +210,65 @@ class TreeBehaviorScopedTest extends CakeTestCase { ))); $this->assertEquals($expected, $result); - //update different locale, same record + // update different locale, same record $this->Tree->create(); $this->Tree->locale = 'deu'; $this->Tree->id = 1; $data = array('FlagTree' => array( 'id' => 1, 'parent_id' => null, - 'name' => 'namen #1', + 'title' => 'namen #1', 'locale' => 'deu', )); $this->Tree->save($data); $this->Tree->locale = 'deu'; $result = $this->Tree->find('all'); - $expected = array(array('FlagTree' => array( - 'id' => 1, - 'name' => 'namen #1', - 'parent_id' => null, - 'lft' => 1, - 'rght' => 2, - 'flag' => 0, - 'locale' => 'deu', - ))); + $expected = array( + array( + 'FlagTree' => array( + 'id' => 1, + 'title' => 'namen #1', + 'name' => '', + 'parent_id' => null, + 'lft' => 1, + 'rght' => 2, + 'flag' => 0, + 'locale' => 'deu', + ) + ) + ); $this->assertEquals($expected, $result); - //Save with bindTranslation + // Save with bindTranslation $this->Tree->locale = 'eng'; $data = array( - 'name' => array('eng' => 'New title', 'spa' => 'Nuevo leyenda'), + 'title' => array('eng' => 'New title', 'spa' => 'Nuevo leyenda'), 'parent_id' => null ); $this->Tree->create($data); $this->Tree->save(); $this->Tree->unbindTranslation(); - $translations = array('name' => 'Name'); + $translations = array('title' => 'Title'); $this->Tree->bindTranslation($translations, false); $this->Tree->locale = array('eng', 'spa'); $result = $this->Tree->read(); $expected = array( - 'FlagTree' => array('id' => 2, 'parent_id' => null, 'locale' => 'eng', 'name' => 'New title', 'flag' => 0, 'lft' => 3, 'rght' => 4), - 'Name' => array( - array('id' => 21, 'locale' => 'eng', 'model' => 'FlagTree', 'foreign_key' => 2, 'field' => 'name', 'content' => 'New title'), - array('id' => 22, 'locale' => 'spa', 'model' => 'FlagTree', 'foreign_key' => 2, 'field' => 'name', 'content' => 'Nuevo leyenda') + 'FlagTree' => array( + 'id' => 2, + 'parent_id' => null, + 'locale' => 'eng', + 'name' => '', + 'title' => 'New title', + 'flag' => 0, + 'lft' => 3, + 'rght' => 4 + ), + 'Title' => array( + array('id' => 21, 'locale' => 'eng', 'model' => 'FlagTree', 'foreign_key' => 2, 'field' => 'title', 'content' => 'New title'), + array('id' => 22, 'locale' => 'spa', 'model' => 'FlagTree', 'foreign_key' => 2, 'field' => 'title', 'content' => 'Nuevo leyenda') ), ); $this->assertEquals($expected, $result); diff --git a/lib/Cake/Test/Fixture/FlagTreeFixture.php b/lib/Cake/Test/Fixture/FlagTreeFixture.php index e775e8fa7..99937e399 100644 --- a/lib/Cake/Test/Fixture/FlagTreeFixture.php +++ b/lib/Cake/Test/Fixture/FlagTreeFixture.php @@ -41,11 +41,11 @@ class FlagTreeFixture extends CakeTestFixture { * @var array */ public $fields = array( - 'id' => array('type' => 'integer','key' => 'primary'), - 'name' => array('type' => 'string','null' => false), + 'id' => array('type' => 'integer','key' => 'primary'), + 'name' => array('type' => 'string','null' => false), 'parent_id' => 'integer', - 'lft' => array('type' => 'integer','null' => false), - 'rght' => array('type' => 'integer','null' => false), - 'flag' => array('type' => 'integer','null' => false, 'length' => 1, 'default' => 0) + 'lft' => array('type' => 'integer','null' => false), + 'rght' => array('type' => 'integer','null' => false), + 'flag' => array('type' => 'integer','null' => false, 'length' => 1, 'default' => 0) ); } From 1f31340a2a3f200a7bd8a9329ab22c38a7005397 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 31 Oct 2012 23:13:56 -0400 Subject: [PATCH 60/85] Fix issue with Model::saveAssociated() and TranslateBehavior When combining saveAssociated() with validate=first and TranslateBehavior. Saving data for multiple locales was not done correctly. Fixes #3272 --- lib/Cake/Model/Behavior/TranslateBehavior.php | 15 +++++++++ .../Model/Behavior/TranslateBehaviorTest.php | 32 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/lib/Cake/Model/Behavior/TranslateBehavior.php b/lib/Cake/Model/Behavior/TranslateBehavior.php index dd1243b91..01a2c0d53 100644 --- a/lib/Cake/Model/Behavior/TranslateBehavior.php +++ b/lib/Cake/Model/Behavior/TranslateBehavior.php @@ -383,6 +383,21 @@ class TranslateBehavior extends ModelBehavior { $this->runtime[$Model->alias]['beforeSave'] = $tempData; } +/** + * Restores model data to the original data. + * This solves issues with saveAssociated and validate = first. + * + * @param Model $model + * @return void + */ + public function afterValidate(Model $Model) { + $Model->data[$Model->alias] = array_merge( + $Model->data[$Model->alias], + $this->runtime[$Model->alias]['beforeSave'] + ); + return true; + } + /** * afterSave Callback * diff --git a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php index a73ccd17c..50d897d60 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php @@ -530,6 +530,38 @@ class TranslateBehaviorTest extends CakeTestCase { $this->assertEquals($expected, $result); } +/** + * testSaveAssociatedCreate method + * + * @return void + */ + public function testSaveAssociatedMultipleLocale() { + $this->loadFixtures('Translate', 'TranslatedItem'); + + $TestModel = new TranslatedItem(); + $data = array( + 'slug' => 'fourth_translated', + 'title' => array( + 'eng' => 'Title #4', + 'spa' => 'Leyenda #4', + ), + 'content' => array( + 'eng' => 'Content #4', + 'spa' => 'Contenido #4', + ), + 'translated_article_id' => 1, + ); + $TestModel->create(); + $TestModel->saveAssociated($data); + + $translations = array('title' => 'Title', 'content' => 'Content'); + $TestModel->bindTranslation($translations, false); + $TestModel->locale = array('eng', 'spa'); + $result = $TestModel->read(); + $this->assertCount(2, $result['Title']); + $this->assertCount(2, $result['Content']); + } + /** * Test that saving only some of the translated fields allows the record to be found again. * From dfe54e90d6b77f56a9b98a59817f5c70e02f9d40 Mon Sep 17 00:00:00 2001 From: Schlaefer Date: Thu, 1 Nov 2012 15:47:50 +0100 Subject: [PATCH 61/85] =?UTF-8?q?removed=20Inflictor::slug()replacement=20?= =?UTF-8?q?from=20=C3=84=20to=20A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The slug replacement for Ä -> A is not necessary, because the better replacement Ä -> Ae is already defined and also covered by the test case. --- lib/Cake/Utility/Inflector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Utility/Inflector.php b/lib/Cake/Utility/Inflector.php index 47c591482..b724d4218 100644 --- a/lib/Cake/Utility/Inflector.php +++ b/lib/Cake/Utility/Inflector.php @@ -177,7 +177,7 @@ class Inflector { '/Ä/' => 'Ae', '/Ü/' => 'Ue', '/Ö/' => 'Oe', - '/À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ/' => 'A', + '/À|Á|Â|Ã|Å|Ǻ|Ā|Ă|Ą|Ǎ/' => 'A', '/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª/' => 'a', '/Ç|Ć|Ĉ|Ċ|Č/' => 'C', '/ç|ć|ĉ|ċ|č/' => 'c', From cc6b699db4fe729542ae06447b9c2f8d9a738e98 Mon Sep 17 00:00:00 2001 From: ADmad Date: Fri, 2 Nov 2012 01:55:37 +0530 Subject: [PATCH 62/85] Added missing App::uses() statement. Closes #3331 --- lib/Cake/Controller/CakeErrorController.php | 2 ++ lib/Cake/Error/ExceptionRenderer.php | 5 ++--- lib/Cake/Test/Case/Error/ExceptionRendererTest.php | 1 - 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Controller/CakeErrorController.php b/lib/Cake/Controller/CakeErrorController.php index 3bcbd72ce..c1835fd6e 100644 --- a/lib/Cake/Controller/CakeErrorController.php +++ b/lib/Cake/Controller/CakeErrorController.php @@ -19,6 +19,8 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +App::uses('AppController', 'Controller'); + /** * Error Handling Controller * diff --git a/lib/Cake/Error/ExceptionRenderer.php b/lib/Cake/Error/ExceptionRenderer.php index a404d3be8..3be08d26c 100644 --- a/lib/Cake/Error/ExceptionRenderer.php +++ b/lib/Cake/Error/ExceptionRenderer.php @@ -142,15 +142,14 @@ class ExceptionRenderer { * @return Controller */ protected function _getController($exception) { + App::uses('AppController', 'Controller'); App::uses('CakeErrorController', 'Controller'); if (!$request = Router::getRequest(true)) { $request = new CakeRequest(); } $response = new CakeResponse(array('charset' => Configure::read('App.encoding'))); try { - if (class_exists('AppController')) { - $controller = new CakeErrorController($request, $response); - } + $controller = new CakeErrorController($request, $response); } catch (Exception $e) { } if (empty($controller)) { diff --git a/lib/Cake/Test/Case/Error/ExceptionRendererTest.php b/lib/Cake/Test/Case/Error/ExceptionRendererTest.php index a5704433b..d11c66413 100644 --- a/lib/Cake/Test/Case/Error/ExceptionRendererTest.php +++ b/lib/Cake/Test/Case/Error/ExceptionRendererTest.php @@ -19,7 +19,6 @@ App::uses('ExceptionRenderer', 'Error'); App::uses('Controller', 'Controller'); -App::uses('AppController', 'Controller'); App::uses('Component', 'Controller'); App::uses('Router', 'Routing'); From ddd3baf7038e146cc1008481cce07545d3c5d529 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 1 Nov 2012 21:07:29 -0400 Subject: [PATCH 63/85] Fix null column errors in SQLite and Postgres. --- .../Case/Model/Behavior/TreeBehaviorScopedTest.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php index 9f5056387..66adac3e5 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php @@ -175,6 +175,7 @@ class TreeBehaviorScopedTest extends CakeTestCase { $this->Tree->locale = 'eng'; $data = array('FlagTree' => array( 'title' => 'name #1', + 'name' => 'test', 'locale' => 'eng', 'parent_id' => null, )); @@ -183,7 +184,7 @@ class TreeBehaviorScopedTest extends CakeTestCase { $expected = array(array('FlagTree' => array( 'id' => 1, 'title' => 'name #1', - 'name' => '', + 'name' => 'test', 'parent_id' => null, 'lft' => 1, 'rght' => 2, @@ -201,7 +202,7 @@ class TreeBehaviorScopedTest extends CakeTestCase { $expected = array(array('FlagTree' => array( 'id' => 1, 'title' => 'Named 2', - 'name' => '', + 'name' => 'test', 'parent_id' => null, 'lft' => 1, 'rght' => 2, @@ -218,6 +219,7 @@ class TreeBehaviorScopedTest extends CakeTestCase { 'id' => 1, 'parent_id' => null, 'title' => 'namen #1', + 'name' => 'test', 'locale' => 'deu', )); $this->Tree->save($data); @@ -229,7 +231,7 @@ class TreeBehaviorScopedTest extends CakeTestCase { 'FlagTree' => array( 'id' => 1, 'title' => 'namen #1', - 'name' => '', + 'name' => 'test', 'parent_id' => null, 'lft' => 1, 'rght' => 2, @@ -244,6 +246,7 @@ class TreeBehaviorScopedTest extends CakeTestCase { $this->Tree->locale = 'eng'; $data = array( 'title' => array('eng' => 'New title', 'spa' => 'Nuevo leyenda'), + 'name' => 'test', 'parent_id' => null ); $this->Tree->create($data); @@ -260,7 +263,7 @@ class TreeBehaviorScopedTest extends CakeTestCase { 'id' => 2, 'parent_id' => null, 'locale' => 'eng', - 'name' => '', + 'name' => 'test', 'title' => 'New title', 'flag' => 0, 'lft' => 3, From 118dd8c534b6d8be0f45352577f6967ca63a8249 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 1 Nov 2012 21:36:14 -0400 Subject: [PATCH 64/85] Make fragile test less fragile. --- lib/Cake/Test/Case/View/MediaViewTest.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Test/Case/View/MediaViewTest.php b/lib/Cake/Test/Case/View/MediaViewTest.php index 3b723c0bf..8660a119b 100644 --- a/lib/Cake/Test/Case/View/MediaViewTest.php +++ b/lib/Cake/Test/Case/View/MediaViewTest.php @@ -132,11 +132,14 @@ class MediaViewTest extends CakeTestCase { $this->MediaView->response->expects($this->at(1)) ->method('header') - ->with(array( - 'Date' => gmdate('D, d M Y H:i:s', time()) . ' GMT', - 'Expires' => '0', - 'Cache-Control' => 'private, must-revalidate, post-check=0, pre-check=0', - 'Pragma' => 'no-cache' + ->with($this->logicalAnd( + $this->arrayHasKey('Date'), + $this->arrayHasKey('Expires'), + $this->arrayHasKey('Cache-Control'), + $this->arrayHasKey('Pragma'), + $this->contains('0'), + $this->contains('private, must-revalidate, post-check=0, pre-check=0'), + $this->contains('no-cache') )); $this->MediaView->response->expects($this->once()) From 093275aef6ec79db2e6135925a37bd37b8eec4a3 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Fri, 2 Nov 2012 14:29:38 +0100 Subject: [PATCH 65/85] Use correct value when using virtualFields in conditions and IN (), refs PR#897 Squashed commit of the following: commit 6a986953e16601fb34a132df24ae16f882f218cf Merge: babd714 118dd8c Author: Ceeram Date: Fri Nov 2 13:02:15 2012 +0100 Merge branch 'master' into virtualcondition commit babd714d80178c68b0e3fbcc21fc53b846484fd8 Author: Ceeram Date: Fri Nov 2 00:22:43 2012 +0100 fix incorrect tests commit 9a46c13e1aa13905b8e5474947933676e03009ce Author: Ceeram Date: Thu Nov 1 11:44:19 2012 +0100 add test for regular fields and conditionKeysToString with IN commit 3aa62e5cb93aa0c7bbb47e874fc1446873dd0d27 Merge: a8f0c3d 1f31340 Author: Ceeram Date: Thu Nov 1 11:37:01 2012 +0100 Merge branch 'master' into virtualcondition commit a8f0c3d918761ff2c456cc3a53f1e3ee5b1c6173 Author: Ceeram Date: Thu Oct 11 16:46:10 2012 +0200 use correct value when using virtualFields in conditions and IN () --- lib/Cake/Model/Datasource/DboSource.php | 16 ++--- .../Model/Datasource/Database/MysqlTest.php | 8 +-- .../Case/Model/Datasource/DboSourceTest.php | 69 +++++++++++++++++++ 3 files changed, 81 insertions(+), 12 deletions(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index ef4bab7e7..5670adab9 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -2490,16 +2490,16 @@ class DboSource extends DataSource { $count = count($value); if ($count === 1 && !preg_match("/\s+NOT$/", $key)) { $data = $this->_quoteFields($key) . ' = ('; - } else { - $data = $this->_quoteFields($key) . ' IN ('; - } - if ($quoteValues) { - if (is_object($model)) { - $columnType = $model->getColumnType($key); + if ($quoteValues) { + if (is_object($model)) { + $columnType = $model->getColumnType($key); + } + $data .= implode(', ', $this->value($value, $columnType)); } - $data .= implode(', ', $this->value($value, $columnType)); + $data .= ')'; + } else { + $data = $this->_parseKey($model, $key, $value); } - $data .= ')'; } else { $ret = $this->conditionKeysToString($value, $quoteValues, $model); if (count($ret) > 1) { diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php index 4f3baa0bd..7ae749268 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php @@ -1960,7 +1960,7 @@ class MysqlTest extends CakeTestCase { $this->assertEquals($expected, $result); $result = $this->Dbo->conditions(array('score' => array(2 => 1, 2, 10))); - $expected = " WHERE score IN (1, 2, 10)"; + $expected = " WHERE `score` IN (1, 2, 10)"; $this->assertEquals($expected, $result); $result = $this->Dbo->conditions("Aro.rght = Aro.lft + 1.1"); @@ -2240,7 +2240,7 @@ class MysqlTest extends CakeTestCase { $this->assertEquals($expected, $result); $result = $this->Dbo->conditions(array('score' => array(1, 2, 10))); - $expected = " WHERE score IN (1, 2, 10)"; + $expected = " WHERE `score` IN (1, 2, 10)"; $this->assertEquals($expected, $result); $result = $this->Dbo->conditions(array('score' => array())); @@ -2331,7 +2331,7 @@ class MysqlTest extends CakeTestCase { 'NOT' => array('Course.id' => null, 'Course.vet' => 'N', 'level_of_education_id' => array(912,999)), 'Enrollment.yearcompleted >' => '0') ); - $this->assertRegExp('/^\s*WHERE\s+\(NOT\s+\(`Course`\.`id` IS NULL\)\s+AND NOT\s+\(`Course`\.`vet`\s+=\s+\'N\'\)\s+AND NOT\s+\(level_of_education_id IN \(912, 999\)\)\)\s+AND\s+`Enrollment`\.`yearcompleted`\s+>\s+\'0\'\s*$/', $result); + $this->assertRegExp('/^\s*WHERE\s+\(NOT\s+\(`Course`\.`id` IS NULL\)\s+AND NOT\s+\(`Course`\.`vet`\s+=\s+\'N\'\)\s+AND NOT\s+\(`level_of_education_id` IN \(912, 999\)\)\)\s+AND\s+`Enrollment`\.`yearcompleted`\s+>\s+\'0\'\s*$/', $result); $result = $this->Dbo->conditions(array('id <>' => '8')); $this->assertRegExp('/^\s*WHERE\s+`id`\s+<>\s+\'8\'\s*$/', $result); @@ -2367,7 +2367,7 @@ class MysqlTest extends CakeTestCase { $conditions = array('id' => array(2, 5, 6, 9, 12, 45, 78, 43, 76)); $result = $this->Dbo->conditions($conditions); - $expected = " WHERE id IN (2, 5, 6, 9, 12, 45, 78, 43, 76)"; + $expected = " WHERE `id` IN (2, 5, 6, 9, 12, 45, 78, 43, 76)"; $this->assertEquals($expected, $result); $conditions = array('title' => 'user(s)'); diff --git a/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php b/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php index de8cc903f..c38e1d085 100644 --- a/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php @@ -1103,4 +1103,73 @@ class DboSourceTest extends CakeTestCase { $this->assertEquals($expected, $result); } +/** + * Test conditionKeysToString() + * + * @return void + */ + public function testConditionKeysToString() { + $Article = ClassRegistry::init('Article'); + $conn = $this->getMock('MockPDO', array('quote')); + $db = new DboTestSource; + $db->setConnection($conn); + + $conn->expects($this->at(0)) + ->method('quote') + ->will($this->returnValue('just text')); + + $conditions = array('Article.name' => 'just text'); + $result = $db->conditionKeysToString($conditions, true, $Article); + $expected = "Article.name = just text"; + $this->assertEquals($expected, $result[0]); + + $conn->expects($this->at(0)) + ->method('quote') + ->will($this->returnValue('just text')); + $conn->expects($this->at(1)) + ->method('quote') + ->will($this->returnValue('other text')); + + $conditions = array('Article.name' => array('just text', 'other text')); + $result = $db->conditionKeysToString($conditions, true, $Article); + $expected = "Article.name IN (just text, other text)"; + $this->assertEquals($expected, $result[0]); + } + +/** + * Test conditionKeysToString() with virtual field + * + * @return void + */ + public function testConditionKeysToStringVirtualField() { + $Article = ClassRegistry::init('Article'); + $Article->virtualFields = array( + 'extra' => 'something virtual' + ); + $conn = $this->getMock('MockPDO', array('quote')); + $db = new DboTestSource; + $db->setConnection($conn); + + $conn->expects($this->at(0)) + ->method('quote') + ->will($this->returnValue('just text')); + + $conditions = array('Article.extra' => 'just text'); + $result = $db->conditionKeysToString($conditions, true, $Article); + $expected = "(" . $Article->virtualFields['extra'] . ") = just text"; + $this->assertEquals($expected, $result[0]); + + $conn->expects($this->at(0)) + ->method('quote') + ->will($this->returnValue('just text')); + $conn->expects($this->at(1)) + ->method('quote') + ->will($this->returnValue('other text')); + + $conditions = array('Article.extra' => array('just text', 'other text')); + $result = $db->conditionKeysToString($conditions, true, $Article); + $expected = "(" . $Article->virtualFields['extra'] . ") IN (just text, other text)"; + $this->assertEquals($expected, $result[0]); + } + } From 9ce70044b0d73e1a9fe52c28b8df454f0d3bebe7 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 2 Nov 2012 16:46:36 -0400 Subject: [PATCH 66/85] Fix missing query arguments in array urls. Adding documented features that previously wasn't implemented. Fixes #3328 --- lib/Cake/Core/Object.php | 9 +++++++-- lib/Cake/Test/Case/Core/ObjectTest.php | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Core/Object.php b/lib/Cake/Core/Object.php index d95855788..15a58309d 100644 --- a/lib/Cake/Core/Object.php +++ b/lib/Cake/Core/Object.php @@ -73,9 +73,13 @@ class Object { $extra['autoRender'] = 1; unset($extra[$index]); } - if (is_array($url) && !isset($extra['url'])) { + $arrayUrl = is_array($url); + if ($arrayUrl && !isset($extra['url'])) { $extra['url'] = array(); } + if ($arrayUrl && !isset($extra['data'])) { + $extra['data'] = array(); + } $extra = array_merge(array('autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1), $extra); $data = isset($extra['data']) ? $extra['data'] : null; unset($extra['data']); @@ -88,11 +92,12 @@ class Object { } elseif (is_array($url)) { $params = $url + array('pass' => array(), 'named' => array(), 'base' => false); $params = array_merge($params, $extra); - $request = new CakeRequest(Router::reverse($params), false); + $request = new CakeRequest(Router::reverse($params)); } if (isset($data)) { $request->data = $data; } + $dispatcher = new Dispatcher(); $result = $dispatcher->dispatch($request, new CakeResponse(), $extra); Router::popRequest(); diff --git a/lib/Cake/Test/Case/Core/ObjectTest.php b/lib/Cake/Test/Case/Core/ObjectTest.php index 222a231a7..5738e201c 100644 --- a/lib/Cake/Test/Case/Core/ObjectTest.php +++ b/lib/Cake/Test/Case/Core/ObjectTest.php @@ -619,6 +619,24 @@ class ObjectTest extends CakeTestCase { $this->assertEquals($expected, $result['named']); } +/** + * Test that requestAction handles get parameters correctly. + * + * @return void + */ + public function testRequestActionGetParameters() { + $result = $this->object->requestAction( + '/request_action/params_pass?get=value&limit=5' + ); + $this->assertEquals('value', $result->query['get']); + + $result = $this->object->requestAction( + array('controller' => 'request_action', 'action' => 'params_pass'), + array('url' => array('get' => 'value', 'limit' => 5)) + ); + $this->assertEquals('value', $result->query['get']); + } + /** * test that requestAction does not fish data out of the POST * superglobal. @@ -632,7 +650,6 @@ class ObjectTest extends CakeTestCase { 'item' => 'value' )); $result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'post_pass')); - $expected = null; $this->assertEmpty($result); $result = $this->object->requestAction( From ce3aa692b50b4239e32a58a250d4a7c8f0afca21 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 2 Nov 2012 18:06:59 -0400 Subject: [PATCH 67/85] Use set order for test that failed on travis. --- lib/Cake/Test/Case/Model/ModelReadTest.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/Cake/Test/Case/Model/ModelReadTest.php b/lib/Cake/Test/Case/Model/ModelReadTest.php index e0afbd1b4..8780d7b80 100644 --- a/lib/Cake/Test/Case/Model/ModelReadTest.php +++ b/lib/Cake/Test/Case/Model/ModelReadTest.php @@ -4203,7 +4203,8 @@ class ModelReadTest extends BaseModelTest { $this->assertTrue($result); $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user' + 'fields' => 'User.id, User.user', + 'order' => array('User.id' => 'ASC'), )); $expected = array( array( @@ -4296,7 +4297,8 @@ class ModelReadTest extends BaseModelTest { $this->assertTrue($result); $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user' + 'fields' => 'User.id, User.user', + 'order' => array('User.id' => 'ASC'), )); $expected = array( @@ -4407,7 +4409,8 @@ class ModelReadTest extends BaseModelTest { $this->assertEquals($expected, $result); $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user' + 'fields' => 'User.id, User.user', + 'order' => array('User.id' => 'ASC'), )); $expected = array( array('User' => array('id' => '1', 'user' => 'mariano')), @@ -4417,7 +4420,8 @@ class ModelReadTest extends BaseModelTest { $this->assertEquals($expected, $result); $result = $TestModel->find('all', array( - 'fields' => 'User.id, User.user' + 'fields' => 'User.id, User.user', + 'order' => array('User.id' => 'ASC'), )); $expected = array( array( @@ -4505,7 +4509,10 @@ class ModelReadTest extends BaseModelTest { $result = $TestModel->unbindModel(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', + 'order' => array('User.id' => 'ASC'), + )); $expected = array( array('User' => array('id' => '1', 'user' => 'mariano')), array('User' => array('id' => '2', 'user' => 'nate')), @@ -4522,7 +4529,10 @@ class ModelReadTest extends BaseModelTest { ))); $this->assertTrue($result); - $result = $TestModel->find('all', array('fields' => 'User.id, User.user')); + $result = $TestModel->find('all', array( + 'fields' => 'User.id, User.user', + 'order' => array('User.id' => 'ASC'), + )); $expected = array( array( 'User' => array( From 8b2b0771192390bd35dc327a03a50a7802a08124 Mon Sep 17 00:00:00 2001 From: Ber Clausen Date: Fri, 2 Nov 2012 19:23:39 -0300 Subject: [PATCH 68/85] Set::flatten() fails to generate keys when 'tip' value is an empty array. --- lib/Cake/Test/Case/Utility/HashTest.php | 16 +++++++++++++++- lib/Cake/Test/Case/Utility/SetTest.php | 16 ++++++++++++++++ lib/Cake/Utility/Hash.php | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/HashTest.php b/lib/Cake/Test/Case/Utility/HashTest.php index 40fcd7b54..3b398d0d5 100644 --- a/lib/Cake/Test/Case/Utility/HashTest.php +++ b/lib/Cake/Test/Case/Utility/HashTest.php @@ -298,7 +298,6 @@ class HashTest extends CakeTestCase { 'Author' => array('id' => '3', 'user' => 'larry', 'password' => null), ) ); - $result = Hash::flatten($data); $expected = array( '0.Post.id' => '1', @@ -317,6 +316,21 @@ class HashTest extends CakeTestCase { ); $this->assertEquals($expected, $result); + $data = array( + array( + 'Post' => array('id' => '1', 'author_id' => null, 'title' => 'First Post'), + 'Author' => array(), + ) + ); + $result = Hash::flatten($data); + $expected = array( + '0.Post.id' => '1', + '0.Post.author_id' => null, + '0.Post.title' => 'First Post', + '0.Author' => array() + ); + $this->assertEquals($expected, $result); + $data = array( array('Post' => array('id' => 1)), array('Post' => array('id' => 2)), diff --git a/lib/Cake/Test/Case/Utility/SetTest.php b/lib/Cake/Test/Case/Utility/SetTest.php index 00d363dba..c49ec3278 100644 --- a/lib/Cake/Test/Case/Utility/SetTest.php +++ b/lib/Cake/Test/Case/Utility/SetTest.php @@ -3054,6 +3054,7 @@ class SetTest extends CakeTestCase { /** * Tests Set::flatten * + * @see Hash test cases, as Set::flatten() is just a proxy. * @return void */ public function testFlatten() { @@ -3064,6 +3065,21 @@ class SetTest extends CakeTestCase { $data[9] = 'Shemp'; $result = Set::flatten($data); $this->assertEquals($data, $result); + + $data = array( + array( + 'Post' => array('id' => '1', 'author_id' => null, 'title' => 'First Post'), + 'Author' => array(), + ) + ); + $result = Set::flatten($data); + $expected = array( + '0.Post.id' => '1', + '0.Post.author_id' => null, + '0.Post.title' => 'First Post', + '0.Author' => array() + ); + $this->assertEquals($expected, $result); } /** diff --git a/lib/Cake/Utility/Hash.php b/lib/Cake/Utility/Hash.php index fc133ff5f..8f01beb5d 100644 --- a/lib/Cake/Utility/Hash.php +++ b/lib/Cake/Utility/Hash.php @@ -527,7 +527,7 @@ class Hash { $element = $data[$key]; unset($data[$key]); - if (is_array($element)) { + if (is_array($element) && !empty($element)) { if (!empty($data)) { $stack[] = array($data, $path); } From 0dfe373f92358a1249ef6226246002552225d629 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Fri, 2 Nov 2012 15:51:35 +0100 Subject: [PATCH 69/85] add phpcs to travis --- .travis.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5af60d8d8..689921dc8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,16 @@ env: - DB=pgsql - DB=sqlite +matrix: + allow_failures: + - php: 5.4 + env: + - PHPCS=1 + include: + - php: 5.4 + env: + - PHPCS=1 + before_script: - sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi" - sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE DATABASE cakephp_test2;'; fi" @@ -23,6 +33,9 @@ before_script: server.listen(80, 'localhost'); console.log('TCP server listening on port 80 at localhost.');" > app/tmp/socket.js - sudo node ./app/tmp/socket.js & + - pear channel-discover pear.cakephp.org + - pear install --alldeps cakephp/CakePHP_CodeSniffer + - phpenv rehash - set +H - echo " app/Config/database.php script: - - ./lib/Cake/Console/cake test core AllTests --stderr + - sh -c "if [ '$PHPCS' != '1' ]; then ./lib/Cake/Console/cake test core AllTests --stderr; else phpcs --standard=CakePHP ./lib/Cake; fi" notifications: email: false \ No newline at end of file From 670bf3c47c29c45a1a72e9ff400386117bce24f4 Mon Sep 17 00:00:00 2001 From: Ber Clausen Date: Fri, 2 Nov 2012 21:01:48 -0300 Subject: [PATCH 70/85] Revert "Removing unneeded App::uses() call" as it causes ControllerTest to fail. This reverts commit 0fb4d1d3d8f832f9d25c887dd394e1025a4db046. --- lib/Cake/Error/ErrorHandler.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Cake/Error/ErrorHandler.php b/lib/Cake/Error/ErrorHandler.php index 87a605835..dcc0973c9 100644 --- a/lib/Cake/Error/ErrorHandler.php +++ b/lib/Cake/Error/ErrorHandler.php @@ -22,6 +22,7 @@ App::uses('Debugger', 'Utility'); App::uses('CakeLog', 'Log'); App::uses('ExceptionRenderer', 'Error'); +App::uses('AppController', 'Controller'); /** * From 9007406b9d9fc035fb52cdf5da20911ab09759b2 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 2 Nov 2012 20:46:05 -0400 Subject: [PATCH 71/85] Fix another test that sometimes fails on travis. --- lib/Cake/Test/Case/Model/ModelReadTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Model/ModelReadTest.php b/lib/Cake/Test/Case/Model/ModelReadTest.php index 8780d7b80..2593ea931 100644 --- a/lib/Cake/Test/Case/Model/ModelReadTest.php +++ b/lib/Cake/Test/Case/Model/ModelReadTest.php @@ -5123,7 +5123,10 @@ class ModelReadTest extends BaseModelTest { public function testAssociationAfterFindCalbacksDisabled() { $this->loadFixtures('Post', 'Author', 'Comment'); $TestModel = new Post(); - $result = $TestModel->find('all', array('callbacks' => false)); + $result = $TestModel->find('all', array( + 'callbacks' => false, + 'order' => array('Post.id' => 'ASC'), + )); $expected = array( array( 'Post' => array( @@ -5190,6 +5193,7 @@ class ModelReadTest extends BaseModelTest { $result = $Author->find('all', array( 'conditions' => array('Author.id' => 1), 'recursive' => 2, + 'order' => array('Post.id' => 'ASC'), 'callbacks' => false )); $expected = array( From fa759231da1d7d9f1d3c9c246a4c6bbaeadd9b50 Mon Sep 17 00:00:00 2001 From: Ryan Morris Date: Fri, 2 Nov 2012 09:35:02 -0400 Subject: [PATCH 72/85] Update checkRequired to simply check if an array key is present rather than isset (which fails if the value is null) --- .../Model/Validator/CakeValidationRule.php | 4 +-- .../Validator/CakeValidationRuleTest.php | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Model/Validator/CakeValidationRule.php b/lib/Cake/Model/Validator/CakeValidationRule.php index 6380376bf..3ce7c2fcd 100644 --- a/lib/Cake/Model/Validator/CakeValidationRule.php +++ b/lib/Cake/Model/Validator/CakeValidationRule.php @@ -163,9 +163,9 @@ class CakeValidationRule { */ public function checkRequired($field, &$data) { return ( - (!isset($data[$field]) && $this->isRequired() === true) || + (!array_key_exists($field, $data) && $this->isRequired() === true) || ( - isset($data[$field]) && (empty($data[$field]) && + array_key_exists($field, $data) && (empty($data[$field]) && !is_numeric($data[$field])) && $this->allowEmpty === false ) ); diff --git a/lib/Cake/Test/Case/Model/Validator/CakeValidationRuleTest.php b/lib/Cake/Test/Case/Model/Validator/CakeValidationRuleTest.php index e0d9c8b35..7a43f32f5 100644 --- a/lib/Cake/Test/Case/Model/Validator/CakeValidationRuleTest.php +++ b/lib/Cake/Test/Case/Model/Validator/CakeValidationRuleTest.php @@ -171,4 +171,30 @@ class CakeValidationRuleTest extends CakeTestCase { $Rule->isUpdate(true); $this->assertTrue($Rule->isEmptyAllowed()); } + +/** + * Test checkRequired method + * + * @return void + */ + public function testCheckRequiredWhenRequiredAndAllowEmpty() { + + $Rule = $this->getMock('CakeValidationRule', array('isRequired')); + $Rule->expects($this->any()) + ->method('isRequired') + ->will($this->returnValue(true)); + $Rule->allowEmpty = true; + + $fieldname = 'field'; + $data = array( + $fieldname => null + ); + + $this->assertFalse($Rule->checkRequired($fieldname, $data), "A null but present field should not fail requirement check if allowEmpty is true"); + + $Rule->allowEmpty = false; + + $this->assertTrue($Rule->checkRequired($fieldname, $data), "A null but present field should fail requirement check if allowEmpty is false"); + + } } From f04259d1959d31beece3dd6ed616b81da3b18ba7 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Sat, 3 Nov 2012 14:51:39 +0900 Subject: [PATCH 73/85] Fixing broken test --- lib/Cake/Test/Case/Model/ModelReadTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Model/ModelReadTest.php b/lib/Cake/Test/Case/Model/ModelReadTest.php index 2593ea931..fe3780345 100644 --- a/lib/Cake/Test/Case/Model/ModelReadTest.php +++ b/lib/Cake/Test/Case/Model/ModelReadTest.php @@ -5193,7 +5193,7 @@ class ModelReadTest extends BaseModelTest { $result = $Author->find('all', array( 'conditions' => array('Author.id' => 1), 'recursive' => 2, - 'order' => array('Post.id' => 'ASC'), + 'order' => array('Author.id' => 'ASC'), 'callbacks' => false )); $expected = array( From 1476ccbe7e9729aea97c609f33f49911f59cc029 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sat, 3 Nov 2012 21:54:00 +0530 Subject: [PATCH 74/85] Revert "Merge pull request #937 from bar/master-controlelr-test" This reverts commit ba8f2780757719ae0badc68c56b866ce14117728, reversing changes made to 4c6c3b05542bef349470bf87423674d8657a9f52. --- lib/Cake/Error/ErrorHandler.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Cake/Error/ErrorHandler.php b/lib/Cake/Error/ErrorHandler.php index dcc0973c9..87a605835 100644 --- a/lib/Cake/Error/ErrorHandler.php +++ b/lib/Cake/Error/ErrorHandler.php @@ -22,7 +22,6 @@ App::uses('Debugger', 'Utility'); App::uses('CakeLog', 'Log'); App::uses('ExceptionRenderer', 'Error'); -App::uses('AppController', 'Controller'); /** * From 084636bf9db7458945e5f321094286018f60bdb2 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sat, 3 Nov 2012 21:55:46 +0530 Subject: [PATCH 75/85] Add App::uses() --- .../Plugin/TestPlugin/Controller/TestPluginAppController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Cake/Test/test_app/Plugin/TestPlugin/Controller/TestPluginAppController.php b/lib/Cake/Test/test_app/Plugin/TestPlugin/Controller/TestPluginAppController.php index 93a498147..23ab63b3a 100644 --- a/lib/Cake/Test/test_app/Plugin/TestPlugin/Controller/TestPluginAppController.php +++ b/lib/Cake/Test/test_app/Plugin/TestPlugin/Controller/TestPluginAppController.php @@ -16,5 +16,8 @@ * @since CakePHP(tm) v 1.2.0.5432 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ + +App::uses('AppController', 'Controller'); + class TestPluginAppController extends AppController { } From fa5ccf46d0f3041444e0baea12060927a2bd0db7 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 4 Nov 2012 02:52:00 +0530 Subject: [PATCH 76/85] Fix coding standard errors --- lib/Cake/Console/ShellDispatcher.php | 2 +- lib/Cake/Test/Case/Log/CakeLogTest.php | 1 - lib/Cake/Test/Case/Model/Validator/CakeValidationRuleTest.php | 3 +-- lib/Cake/Test/Case/View/Helper/FormHelperTest.php | 1 - 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Console/ShellDispatcher.php b/lib/Cake/Console/ShellDispatcher.php index 162e8f508..426e73485 100644 --- a/lib/Cake/Console/ShellDispatcher.php +++ b/lib/Cake/Console/ShellDispatcher.php @@ -215,7 +215,7 @@ class ShellDispatcher { return $Shell->main(); } } - + throw new MissingShellMethodException(array('shell' => $shell, 'method' => $command)); } diff --git a/lib/Cake/Test/Case/Log/CakeLogTest.php b/lib/Cake/Test/Case/Log/CakeLogTest.php index 2caaac0c6..1226dde7e 100644 --- a/lib/Cake/Test/Case/Log/CakeLogTest.php +++ b/lib/Cake/Test/Case/Log/CakeLogTest.php @@ -383,7 +383,6 @@ class CakeLogTest extends CakeTestCase { CakeLog::drop('shops'); } - public function testScopedLoggingExclusive() { $this->_deleteLogs(); diff --git a/lib/Cake/Test/Case/Model/Validator/CakeValidationRuleTest.php b/lib/Cake/Test/Case/Model/Validator/CakeValidationRuleTest.php index 7a43f32f5..f4510b9af 100644 --- a/lib/Cake/Test/Case/Model/Validator/CakeValidationRuleTest.php +++ b/lib/Cake/Test/Case/Model/Validator/CakeValidationRuleTest.php @@ -178,7 +178,6 @@ class CakeValidationRuleTest extends CakeTestCase { * @return void */ public function testCheckRequiredWhenRequiredAndAllowEmpty() { - $Rule = $this->getMock('CakeValidationRule', array('isRequired')); $Rule->expects($this->any()) ->method('isRequired') @@ -195,6 +194,6 @@ class CakeValidationRuleTest extends CakeTestCase { $Rule->allowEmpty = false; $this->assertTrue($Rule->checkRequired($fieldname, $data), "A null but present field should fail requirement check if allowEmpty is false"); - } + } diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index fd97171e0..4549e48a0 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -5683,7 +5683,6 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->hour('Model.field', false, array('value' => '23')); $this->assertContains('', $result); - $this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32'; $result = $this->Form->hour('Model.field', true); $expected = array( From 138098f327770c1b11a5be2c2dc6c1a726fb8bf6 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Sun, 4 Nov 2012 13:25:50 +0100 Subject: [PATCH 77/85] only run codesniff on php files --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 689921dc8..f7705b817 100644 --- a/.travis.yml +++ b/.travis.yml @@ -118,7 +118,7 @@ before_script: }" > app/Config/database.php script: - - sh -c "if [ '$PHPCS' != '1' ]; then ./lib/Cake/Console/cake test core AllTests --stderr; else phpcs --standard=CakePHP ./lib/Cake; fi" + - sh -c "if [ '$PHPCS' != '1' ]; then ./lib/Cake/Console/cake test core AllTests --stderr; else phpcs --extensions=php --standard=CakePHP ./lib/Cake; fi" notifications: email: false \ No newline at end of file From aaf2d2ef71886a95cc5d31f74e09ca0f767b9857 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Sun, 4 Nov 2012 12:23:36 +0100 Subject: [PATCH 78/85] fix remaining cs errors --- app/Config/Schema/i18n.php | 5 +- .../Templates/skel/Config/Schema/i18n.php | 5 +- lib/Cake/I18n/Multibyte.php | 4 +- lib/Cake/Model/Model.php | 4 ++ .../Controller/Component/Acl/DbAclTest.php | 10 +-- .../Component/CookieComponentTest.php | 18 ++--- .../Test/Case/Network/CakeRequestTest.php | 4 +- lib/Cake/Test/Case/Routing/DispatcherTest.php | 70 +------------------ lib/Cake/TestSuite/templates/menu.php | 3 +- 9 files changed, 35 insertions(+), 88 deletions(-) diff --git a/app/Config/Schema/i18n.php b/app/Config/Schema/i18n.php index 8de0052dd..08aab843b 100644 --- a/app/Config/Schema/i18n.php +++ b/app/Config/Schema/i18n.php @@ -19,14 +19,17 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +// @codingStandardsIgnoreStart + /* * * Using the Schema command line utility * cake schema run create i18n - * */ class i18nSchema extends CakeSchema { +// @codingStandardsIgnoreEnd + public $name = 'i18n'; public function before($event = array()) { diff --git a/lib/Cake/Console/Templates/skel/Config/Schema/i18n.php b/lib/Cake/Console/Templates/skel/Config/Schema/i18n.php index 1a29ffd98..1b8b08735 100644 --- a/lib/Cake/Console/Templates/skel/Config/Schema/i18n.php +++ b/lib/Cake/Console/Templates/skel/Config/Schema/i18n.php @@ -21,14 +21,17 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +// @codingStandardsIgnoreStart + /* * * Using the Schema command line utility * cake schema run create i18n - * */ class i18nSchema extends CakeSchema { +// @codingStandardsIgnoreEnd + public $name = 'i18n'; public function before($event = array()) { diff --git a/lib/Cake/I18n/Multibyte.php b/lib/Cake/I18n/Multibyte.php index b741ef4d6..eb4847aa4 100644 --- a/lib/Cake/I18n/Multibyte.php +++ b/lib/Cake/I18n/Multibyte.php @@ -1008,7 +1008,8 @@ class Multibyte { if ($charset == 'UTF-8') { $parts = array(); $maxchars = floor(($length * 3) / 4); - while (strlen($string) > $maxchars) { + $stringLength = strlen($string); + while ($stringLength > $maxchars) { $i = (int)$maxchars; $test = ord($string[$i]); while ($test >= 128 && $test <= 191) { @@ -1017,6 +1018,7 @@ class Multibyte { } $parts[] = base64_encode(substr($string, 0, $i)); $string = substr($string, $i); + $stringLength = strlen($string); } $parts[] = base64_encode($string); $string = implode($spacer, $parts); diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 9e7cec275..2104739ac 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -558,6 +558,8 @@ class Model extends Object implements CakeEventListener { */ protected $_associations = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'); +// @codingStandardsIgnoreStart + /** * Holds model associations temporarily to allow for dynamic (un)binding. * @@ -586,6 +588,8 @@ class Model extends Object implements CakeEventListener { */ public $__backContainableAssociation = array(); +// @codingStandardsIgnoreEnd + /** * The ID of the model record that was last inserted. * diff --git a/lib/Cake/Test/Case/Controller/Component/Acl/DbAclTest.php b/lib/Cake/Test/Case/Controller/Component/Acl/DbAclTest.php index bfc33f68a..c0964ccb0 100644 --- a/lib/Cake/Test/Case/Controller/Component/Acl/DbAclTest.php +++ b/lib/Cake/Test/Case/Controller/Component/Acl/DbAclTest.php @@ -483,14 +483,14 @@ class DbAclTest extends CakeTestCase { /** * debug function - to help editing/creating test cases for the ACL component * - * To check the overall ACL status at any time call $this->__debug(); + * To check the overall ACL status at any time call $this->_debug(); * Generates a list of the current aro and aco structures and a grid dump of the permissions that are defined * Only designed to work with the db based ACL * * @param bool $treesToo * @return void */ - protected function __debug($printTreesToo = false) { + protected function _debug($printTreesToo = false) { $this->Acl->Aro->displayField = 'alias'; $this->Acl->Aco->displayField = 'alias'; $aros = $this->Acl->Aro->find('list', array('order' => 'lft')); @@ -518,10 +518,10 @@ class DbAclTest extends CakeTestCase { } foreach ($permissions as $key => $values) { array_unshift($values, $key); - $values = array_map(array(&$this, '__pad'), $values); + $values = array_map(array(&$this, '_pad'), $values); $permissions[$key] = implode (' ', $values); } - $permisssions = array_map(array(&$this, '__pad'), $permissions); + $permisssions = array_map(array(&$this, '_pad'), $permissions); array_unshift($permissions, 'Current Permissions :'); if ($printTreesToo) { debug(array('aros' => $this->Acl->Aro->generateTreeList(), 'acos' => $this->Acl->Aco->generateTreeList())); @@ -537,7 +537,7 @@ class DbAclTest extends CakeTestCase { * @param integer $len * @return void */ - protected function __pad($string = '', $len = 14) { + protected function _pad($string = '', $len = 14) { return str_pad($string, $len); } } diff --git a/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php b/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php index 380c29099..7c4be8972 100644 --- a/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php @@ -412,11 +412,11 @@ class CookieComponentTest extends CakeTestCase { $this->assertNull($data); $_COOKIE['CakeTestCookie'] = array( - 'Encrytped_array' => $this->__encrypt(array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' => 'CakePHP Rocks!')), + 'Encrytped_array' => $this->_encrypt(array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' => 'CakePHP Rocks!')), 'Encrytped_multi_cookies' => array( - 'name' => $this->__encrypt('CakePHP'), - 'version' => $this->__encrypt('1.2.0.x'), - 'tag' => $this->__encrypt('CakePHP Rocks!')), + 'name' => $this->_encrypt('CakePHP'), + 'version' => $this->_encrypt('1.2.0.x'), + 'tag' => $this->_encrypt('CakePHP Rocks!')), 'Plain_array' => '{"name":"CakePHP","version":"1.2.0.x","tag":"CakePHP Rocks!"}', 'Plain_multi_cookies' => array( 'name' => 'CakePHP', @@ -467,11 +467,11 @@ class CookieComponentTest extends CakeTestCase { $this->assertEquals($expected, $data); $_COOKIE['CakeTestCookie'] = array( - 'Encrytped_array' => $this->__encrypt(array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' => 'CakePHP Rocks!')), + 'Encrytped_array' => $this->_encrypt(array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' => 'CakePHP Rocks!')), 'Encrytped_multi_cookies' => array( - 'name' => $this->__encrypt('CakePHP'), - 'version' => $this->__encrypt('1.2.0.x'), - 'tag' => $this->__encrypt('CakePHP Rocks!')), + 'name' => $this->_encrypt('CakePHP'), + 'version' => $this->_encrypt('1.2.0.x'), + 'tag' => $this->_encrypt('CakePHP Rocks!')), 'Plain_array' => '{"name":"CakePHP","version":"1.2.0.x","tag":"CakePHP Rocks!"}', 'Plain_multi_cookies' => array( 'name' => 'CakePHP', @@ -594,7 +594,7 @@ class CookieComponentTest extends CakeTestCase { * @param array|string $value * @return string */ - protected function __encrypt($value) { + protected function _encrypt($value) { if (is_array($value)) { $value = $this->_implode($value); } diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index d9ae235d4..487f60e80 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -1710,7 +1710,7 @@ class CakeRequestTest extends CakeTestCase { */ public function testEnvironmentDetection($name, $env, $expected) { $_GET = array(); - $this->__loadEnvironment($env); + $this->_loadEnvironment($env); $request = new CakeRequest(); $this->assertEquals($expected['url'], $request->url, "url error"); @@ -1913,7 +1913,7 @@ XML; * @param array $env * @return void */ - protected function __loadEnvironment($env) { + protected function _loadEnvironment($env) { if (isset($env['App'])) { Configure::write('App', $env['App']); } diff --git a/lib/Cake/Test/Case/Routing/DispatcherTest.php b/lib/Cake/Test/Case/Routing/DispatcherTest.php index a0e3df7ba..cf0ce8752 100644 --- a/lib/Cake/Test/Case/Routing/DispatcherTest.php +++ b/lib/Cake/Test/Case/Routing/DispatcherTest.php @@ -1574,7 +1574,7 @@ class DispatcherTest extends CakeTestCase { $this->assertTextEquals($out, $cached); - $filename = $this->__cachePath($request->here()); + $filename = $this->_cachePath($request->here()); unlink($filename); } @@ -1657,79 +1657,13 @@ class DispatcherTest extends CakeTestCase { unset($_POST['_method']); } -/** - * backupEnvironment method - * - * @return void - */ - protected function __backupEnvironment() { - return array( - 'App' => Configure::read('App'), - 'GET' => $_GET, - 'POST' => $_POST, - 'SERVER' => $_SERVER - ); - } - -/** - * reloadEnvironment method - * - * @return void - */ - protected function __reloadEnvironment() { - foreach ($_GET as $key => $val) { - unset($_GET[$key]); - } - foreach ($_POST as $key => $val) { - unset($_POST[$key]); - } - foreach ($_SERVER as $key => $val) { - unset($_SERVER[$key]); - } - Configure::write('App', array()); - } - -/** - * loadEnvironment method - * - * @param array $env - * @return void - */ - protected function __loadEnvironment($env) { - if ($env['reload']) { - $this->__reloadEnvironment(); - } - - if (isset($env['App'])) { - Configure::write('App', $env['App']); - } - - if (isset($env['GET'])) { - foreach ($env['GET'] as $key => $val) { - $_GET[$key] = $val; - } - } - - if (isset($env['POST'])) { - foreach ($env['POST'] as $key => $val) { - $_POST[$key] = $val; - } - } - - if (isset($env['SERVER'])) { - foreach ($env['SERVER'] as $key => $val) { - $_SERVER[$key] = $val; - } - } - } - /** * cachePath method * * @param string $here * @return string */ - protected function __cachePath($here) { + protected function _cachePath($here) { $path = $here; if ($here == '/') { $path = 'home'; diff --git a/lib/Cake/TestSuite/templates/menu.php b/lib/Cake/TestSuite/templates/menu.php index df6ec413f..f41cfa69d 100644 --- a/lib/Cake/TestSuite/templates/menu.php +++ b/lib/Cake/TestSuite/templates/menu.php @@ -1,4 +1,5 @@
  • Plugins - +
    • From 929ed57844fda3797d2b4e218e1aaba30f6c1de1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renan=20Gonc=CC=A7alves?= Date: Tue, 6 Nov 2012 01:44:51 +0100 Subject: [PATCH 79/85] Fixed TestShell options, removed space which caused the option to not be recognized. --- lib/Cake/Console/Command/TestShell.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Console/Command/TestShell.php b/lib/Cake/Console/Command/TestShell.php index 2b9892fc0..c96279305 100644 --- a/lib/Cake/Console/Command/TestShell.php +++ b/lib/Cake/Console/Command/TestShell.php @@ -114,7 +114,7 @@ class TestShell extends Shell { ))->addOption('stop-on-failure', array( 'help' => __d('cake_console', 'Stop execution upon first failure.'), 'boolean' => true - ))->addOption('stop-on-skipped ', array( + ))->addOption('stop-on-skipped', array( 'help' => __d('cake_console', 'Stop execution upon first skipped test.'), 'boolean' => true ))->addOption('stop-on-incomplete', array( @@ -132,7 +132,7 @@ class TestShell extends Shell { ))->addOption('no-globals-backup', array( 'help' => __d('cake_console', 'Do not backup and restore $GLOBALS for each test.'), 'boolean' => true - ))->addOption('static-backup ', array( + ))->addOption('static-backup', array( 'help' => __d('cake_console', 'Backup and restore static attributes for each test.'), 'boolean' => true ))->addOption('syntax-check', array( From 3de72baeb1d911aecbea51006f815742696b3c9f Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 6 Nov 2012 20:27:28 -0500 Subject: [PATCH 80/85] Remove int cast from authentication adapters. Forcing an int cast makes using the contain option difficult as you are also required to manually set the recursive option. Omitting the cast allows recursive to be set to null. Fixes #3347 --- lib/Cake/Controller/Component/Auth/BaseAuthenticate.php | 2 +- lib/Cake/Controller/Component/Auth/DigestAuthenticate.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Controller/Component/Auth/BaseAuthenticate.php b/lib/Cake/Controller/Component/Auth/BaseAuthenticate.php index d9dc7248f..e5bd08cfe 100644 --- a/lib/Cake/Controller/Component/Auth/BaseAuthenticate.php +++ b/lib/Cake/Controller/Component/Auth/BaseAuthenticate.php @@ -84,7 +84,7 @@ abstract class BaseAuthenticate { } $result = ClassRegistry::init($userModel)->find('first', array( 'conditions' => $conditions, - 'recursive' => (int)$this->settings['recursive'], + 'recursive' => $this->settings['recursive'], 'contain' => $this->settings['contain'], )); if (empty($result) || empty($result[$model])) { diff --git a/lib/Cake/Controller/Component/Auth/DigestAuthenticate.php b/lib/Cake/Controller/Component/Auth/DigestAuthenticate.php index 5e0fb0ee5..21c353339 100644 --- a/lib/Cake/Controller/Component/Auth/DigestAuthenticate.php +++ b/lib/Cake/Controller/Component/Auth/DigestAuthenticate.php @@ -170,7 +170,7 @@ class DigestAuthenticate extends BaseAuthenticate { } $result = ClassRegistry::init($userModel)->find('first', array( 'conditions' => $conditions, - 'recursive' => (int)$this->settings['recursive'] + 'recursive' => $this->settings['recursive'] )); if (empty($result) || empty($result[$model])) { return false; From ec3e85e31d08f206009315d7ca55412442f726fc Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 8 Nov 2012 22:19:51 -0500 Subject: [PATCH 81/85] Update docs for the escape option in CakeNumber::currency() Unfortunately, using actual bytes creates a host of problems for sites not using UTF-8. Update the documentation to reflect reality, as changing reality could cause more problems than it solves. Closes #3351 --- lib/Cake/Utility/CakeNumber.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Utility/CakeNumber.php b/lib/Cake/Utility/CakeNumber.php index 3b21cbc36..7f61ec077 100644 --- a/lib/Cake/Utility/CakeNumber.php +++ b/lib/Cake/Utility/CakeNumber.php @@ -211,7 +211,10 @@ class CakeNumber { * - `decimals` - Decimal separator symbol ie. '.' * - `negative` - Symbol for negative numbers. If equal to '()', * the number will be wrapped with ( and ) - * - `escape` - Should the output be htmlentity escaped? Defaults to true + * - `escape` - Should the output be escaped for html special characters. + * The default value for this option is controlled by the currency settings. + * By default the EUR, and GBP contain HTML encoded symbols. If you require non HTML + * encoded symbols you will need to update the settings with the correct bytes. * * @param float $number * @param string $currency Shortcut to default options. Valid values are From 7360abb0fe7c2194817572766028bfa812f8b810 Mon Sep 17 00:00:00 2001 From: ADmad Date: Fri, 9 Nov 2012 16:51:51 +0530 Subject: [PATCH 82/85] Added query logging to DboSource::insertMulti(). Closes #3354 --- lib/Cake/Model/Datasource/DboSource.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 5670adab9..623b7a01f 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -2917,6 +2917,10 @@ class DboSource extends DataSource { } $statement->execute(); $statement->closeCursor(); + + if ($this->fullDebug) { + $this->logQuery($sql, $value); + } } return $this->commit(); } From 644d47c843d45d5fb3b1874c226aeae2ee0c9bd8 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 10 Nov 2012 14:24:30 -0500 Subject: [PATCH 83/85] Fix ordering on another query that was failing on travis-ci. --- .../Test/Case/Model/Behavior/ContainableBehaviorTest.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php b/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php index e43f49bfa..d84f07e67 100644 --- a/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php @@ -2993,7 +2993,8 @@ class ContainableBehaviorTest extends CakeTestCase { 'User' => array( 'fields' => array('user') ) - ) + ), + 'order' => 'Article.id ASC', )); $this->assertTrue(isset($result[0]['Article']['title']), 'title missing %s'); $this->assertTrue(isset($result[0]['Article']['body']), 'body missing %s'); @@ -3016,7 +3017,10 @@ class ContainableBehaviorTest extends CakeTestCase { 'conditions' => array('created >=' => '2007-03-18 12:24') ) )); - $result = $this->Article->find('all', array('fields' => array('title'), 'order' => array('Article.id' => 'ASC'))); + $result = $this->Article->find('all', array( + 'fields' => array('title'), + 'order' => array('Article.id' => 'ASC') + )); $expected = array( array( 'Article' => array('id' => 1, 'title' => 'First Article'), From e0586da808431811dc2d0f0738032b7a5838f8c0 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 11 Nov 2012 22:14:59 -0500 Subject: [PATCH 84/85] Fix tests that occasionally fail on postgres. --- .../Case/Model/BehaviorCollectionTest.php | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php b/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php index 19497f7a6..21104eda5 100644 --- a/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php +++ b/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php @@ -786,21 +786,22 @@ class BehaviorCollectionTest extends CakeTestCase { public function testBehaviorBelongsToFindCallbacks() { $this->skipIf($this->db instanceof Sqlserver, 'This test is not compatible with SQL Server.'); + $conditions = array('order' => 'Apple.id ASC'); $Apple = new Apple(); $Apple->unbindModel(array('hasMany' => array('Child'), 'hasOne' => array('Sample')), false); - $expected = $Apple->find('all'); + $expected = $Apple->find('all', $conditions); $Apple->unbindModel(array('belongsTo' => array('Parent'))); - $wellBehaved = $Apple->find('all'); + $wellBehaved = $Apple->find('all', $conditions); $Apple->Parent->Behaviors->attach('Test'); $Apple->unbindModel(array('belongsTo' => array('Parent'))); - $this->assertSame($Apple->find('all'), $wellBehaved); + $this->assertSame($Apple->find('all', $conditions), $wellBehaved); $Apple->Parent->Behaviors->attach('Test', array('before' => 'off')); - $this->assertSame($expected, $Apple->find('all')); + $this->assertSame($expected, $Apple->find('all', $conditions)); $Apple->Parent->Behaviors->attach('Test', array('before' => 'test')); - $this->assertSame($expected, $Apple->find('all')); + $this->assertSame($expected, $Apple->find('all', $conditions)); $Apple->Parent->Behaviors->attach('Test', array('before' => 'modify')); $expected2 = array( @@ -816,22 +817,23 @@ class BehaviorCollectionTest extends CakeTestCase { ); $result2 = $Apple->find('all', array( 'fields' => array('Apple.id', 'Parent.id', 'Parent.name', 'Parent.mytime'), - 'conditions' => array('Apple.id <' => '4') + 'conditions' => array('Apple.id <' => '4'), + 'order' => 'Apple.id ASC', )); $this->assertEquals($expected2, $result2); $Apple->Parent->Behaviors->disable('Test'); - $result = $Apple->find('all'); + $result = $Apple->find('all', $conditions); $this->assertEquals($expected, $result); $Apple->Parent->Behaviors->attach('Test', array('after' => 'off')); - $this->assertEquals($expected, $Apple->find('all')); + $this->assertEquals($expected, $Apple->find('all', $conditions)); $Apple->Parent->Behaviors->attach('Test', array('after' => 'test')); - $this->assertEquals($expected, $Apple->find('all')); + $this->assertEquals($expected, $Apple->find('all', $conditions)); $Apple->Parent->Behaviors->attach('Test', array('after' => 'test2')); - $this->assertEquals($expected, $Apple->find('all')); + $this->assertEquals($expected, $Apple->find('all', $conditions)); } /** From ac087ec9385899447d5bb0773d37601f0984b24b Mon Sep 17 00:00:00 2001 From: ADmad Date: Tue, 13 Nov 2012 22:13:15 +0530 Subject: [PATCH 85/85] Fix rules set being updated with array instead of CakeValidationRule objects. Closes #3367 --- lib/Cake/Model/Validator/CakeValidationSet.php | 9 +++++---- .../Case/Model/Validator/CakeValidationSetTest.php | 12 ++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Model/Validator/CakeValidationSet.php b/lib/Cake/Model/Validator/CakeValidationSet.php index 60d41c6fe..4ada8bd27 100644 --- a/lib/Cake/Model/Validator/CakeValidationSet.php +++ b/lib/Cake/Model/Validator/CakeValidationSet.php @@ -192,7 +192,7 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable { * @return CakeValidationSet this instance */ public function setRule($name, $rule) { - if (!$rule instanceof CakeValidationRule) { + if (!($rule instanceof CakeValidationRule)) { $rule = new CakeValidationRule($rule); } $this->_rules[$name] = $rule; @@ -236,9 +236,10 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable { */ public function setRules($rules = array(), $mergeVars = true) { if ($mergeVars === false) { - $this->_rules = $rules; - } else { - $this->_rules = array_merge($this->_rules, $rules); + $this->_rules = array(); + } + foreach ($rules as $name => $rule) { + $this->setRule($name, $rule); } return $this; } diff --git a/lib/Cake/Test/Case/Model/Validator/CakeValidationSetTest.php b/lib/Cake/Test/Case/Model/Validator/CakeValidationSetTest.php index 10fa6fdf6..aa604fac9 100644 --- a/lib/Cake/Test/Case/Model/Validator/CakeValidationSetTest.php +++ b/lib/Cake/Test/Case/Model/Validator/CakeValidationSetTest.php @@ -156,10 +156,22 @@ class CakeValidationSetTest extends CakeTestCase { $result = $Field->getRules(); $this->assertEquals(array('validEmail'), array_keys($result)); + $Field->setRules(array('validEmail' => $rule), false); + $result = $Field->getRules(); + $this->assertEquals(array('validEmail'), array_keys($result)); + $this->assertTrue(array_pop($result) instanceof CakeValidationRule); + $rules = array('notEmpty' => $RuleEmpty); $Field->setRules($rules, true); $result = $Field->getRules(); $this->assertEquals(array('validEmail', 'notEmpty'), array_keys($result)); + + $rules = array('notEmpty' => array('rule' => 'notEmpty')); + $Field->setRules($rules, true); + $result = $Field->getRules(); + $this->assertEquals(array('validEmail', 'notEmpty'), array_keys($result)); + $this->assertTrue(array_pop($result) instanceof CakeValidationRule); + $this->assertTrue(array_pop($result) instanceof CakeValidationRule); } /**