From 1e3865acc7a684be350b5ffcaca3aa7685a31ad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20B=C3=BCttner?= Date: Mon, 18 Nov 2013 11:56:00 +0100 Subject: [PATCH 01/11] formatting app::uses blocks (refs #2265) --- app/Controller/AppController.php | 1 + app/Controller/PagesController.php | 1 + app/View/Helper/AppHelper.php | 1 + lib/Cake/Controller/Component/Auth/BlowfishPasswordHasher.php | 1 + lib/Cake/Controller/Component/Auth/SimplePasswordHasher.php | 1 + lib/Cake/Test/Case/BasicsTest.php | 1 + lib/Cake/Test/Case/Console/TaskCollectionTest.php | 1 + lib/Cake/Test/Case/Log/Engine/SyslogLogTest.php | 1 + lib/Cake/Test/Case/Log/LogEngineCollectionTest.php | 1 + lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php | 1 + lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php | 1 + lib/Cake/Test/Case/Model/Behavior/TreeBehaviorAfterTest.php | 1 + lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php | 1 + lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php | 1 + lib/Cake/Test/Case/Model/Behavior/TreeBehaviorUuidTest.php | 1 + lib/Cake/Test/Case/Model/BehaviorCollectionTest.php | 1 + lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php | 1 + lib/Cake/Test/Case/Model/ModelIntegrationTest.php | 1 + lib/Cake/Test/Case/Model/ModelTestBase.php | 1 + lib/Cake/Test/bake_compare/Controller/NoActions.ctp | 2 ++ lib/Cake/Test/bake_compare/Controller/NoHelpersOrComponents.ctp | 2 ++ lib/Cake/Test/bake_compare/Controller/Scaffold.ctp | 2 ++ .../Test/test_app/Model/Datasource/Database/TestLocalDriver.php | 2 ++ .../Plugin/TestPlugin/Model/Datasource/Database/DboDummy.php | 1 + .../test_app/Plugin/TestPlugin/Model/Datasource/TestSource.php | 1 + 25 files changed, 29 insertions(+) diff --git a/app/Controller/AppController.php b/app/Controller/AppController.php index 55316850c..c1999b330 100644 --- a/app/Controller/AppController.php +++ b/app/Controller/AppController.php @@ -20,6 +20,7 @@ * @since CakePHP(tm) v 0.2.9 * @license http://www.opensource.org/licenses/mit-license.php MIT License */ + App::uses('Controller', 'Controller'); /** diff --git a/app/Controller/PagesController.php b/app/Controller/PagesController.php index 7c428d827..7dbe8c563 100644 --- a/app/Controller/PagesController.php +++ b/app/Controller/PagesController.php @@ -19,6 +19,7 @@ * @since CakePHP(tm) v 0.2.9 * @license http://www.opensource.org/licenses/mit-license.php MIT License */ + App::uses('AppController', 'Controller'); /** diff --git a/app/View/Helper/AppHelper.php b/app/View/Helper/AppHelper.php index 2e5229aba..43b9f560b 100644 --- a/app/View/Helper/AppHelper.php +++ b/app/View/Helper/AppHelper.php @@ -20,6 +20,7 @@ * @since CakePHP(tm) v 0.2.9 * @license http://www.opensource.org/licenses/mit-license.php MIT License */ + App::uses('Helper', 'View'); /** diff --git a/lib/Cake/Controller/Component/Auth/BlowfishPasswordHasher.php b/lib/Cake/Controller/Component/Auth/BlowfishPasswordHasher.php index e5c071088..4cea67db0 100644 --- a/lib/Cake/Controller/Component/Auth/BlowfishPasswordHasher.php +++ b/lib/Cake/Controller/Component/Auth/BlowfishPasswordHasher.php @@ -14,6 +14,7 @@ * @since CakePHP(tm) v 2.4.0 * @license http://www.opensource.org/licenses/mit-license.php MIT License */ + App::uses('AbstractPasswordHasher', 'Controller/Component/Auth'); App::uses('Security', 'Utility'); diff --git a/lib/Cake/Controller/Component/Auth/SimplePasswordHasher.php b/lib/Cake/Controller/Component/Auth/SimplePasswordHasher.php index 4877c0284..2a264684b 100644 --- a/lib/Cake/Controller/Component/Auth/SimplePasswordHasher.php +++ b/lib/Cake/Controller/Component/Auth/SimplePasswordHasher.php @@ -14,6 +14,7 @@ * @since CakePHP(tm) v 2.4.0 * @license http://www.opensource.org/licenses/mit-license.php MIT License */ + App::uses('AbstractPasswordHasher', 'Controller/Component/Auth'); App::uses('Security', 'Utility'); diff --git a/lib/Cake/Test/Case/BasicsTest.php b/lib/Cake/Test/Case/BasicsTest.php index 38f5fda6f..eff3e9b41 100644 --- a/lib/Cake/Test/Case/BasicsTest.php +++ b/lib/Cake/Test/Case/BasicsTest.php @@ -19,6 +19,7 @@ */ require_once CAKE . 'basics.php'; + App::uses('Folder', 'Utility'); App::uses('CakeResponse', 'Network'); diff --git a/lib/Cake/Test/Case/Console/TaskCollectionTest.php b/lib/Cake/Test/Case/Console/TaskCollectionTest.php index ba1553611..845ff3824 100644 --- a/lib/Cake/Test/Case/Console/TaskCollectionTest.php +++ b/lib/Cake/Test/Case/Console/TaskCollectionTest.php @@ -20,6 +20,7 @@ App::uses('TaskCollection', 'Console'); App::uses('Shell', 'Console'); + /** * Extended Task */ diff --git a/lib/Cake/Test/Case/Log/Engine/SyslogLogTest.php b/lib/Cake/Test/Case/Log/Engine/SyslogLogTest.php index ca6c0055e..5add025c9 100644 --- a/lib/Cake/Test/Case/Log/Engine/SyslogLogTest.php +++ b/lib/Cake/Test/Case/Log/Engine/SyslogLogTest.php @@ -16,6 +16,7 @@ * @since CakePHP(tm) v 2.4 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ + App::uses('SyslogLog', 'Log/Engine'); /** diff --git a/lib/Cake/Test/Case/Log/LogEngineCollectionTest.php b/lib/Cake/Test/Case/Log/LogEngineCollectionTest.php index 92133d10b..ad3e37be2 100644 --- a/lib/Cake/Test/Case/Log/LogEngineCollectionTest.php +++ b/lib/Cake/Test/Case/Log/LogEngineCollectionTest.php @@ -17,6 +17,7 @@ * @since CakePHP(tm) v 2.4 * @license http://www.opensource.org/licenses/mit-license.php MIT License */ + App::uses('LogEngineCollection', 'Log'); App::uses('FileLog', 'Log/Engine'); diff --git a/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php b/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php index f979870e6..1ede99272 100644 --- a/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php @@ -20,6 +20,7 @@ App::uses('Model', 'Model'); App::uses('AppModel', 'Model'); + require_once dirname(dirname(__FILE__)) . DS . 'models.php'; /** diff --git a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php index f90526ed7..fe18575b8 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php @@ -15,6 +15,7 @@ App::uses('Model', 'Model'); App::uses('AppModel', 'Model'); + require_once dirname(dirname(__FILE__)) . DS . 'models.php'; /** diff --git a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorAfterTest.php b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorAfterTest.php index c5252945b..d2352a8a6 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorAfterTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorAfterTest.php @@ -20,6 +20,7 @@ App::uses('Model', 'Model'); App::uses('AppModel', 'Model'); + require_once dirname(dirname(__FILE__)) . DS . 'models.php'; /** diff --git a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php index baf0d0388..986f65965 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php @@ -22,6 +22,7 @@ App::uses('Model', 'Model'); App::uses('AppModel', 'Model'); + require_once dirname(dirname(__FILE__)) . DS . 'models.php'; /** diff --git a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php index 92f93ab07..4c39fc6f9 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorScopedTest.php @@ -22,6 +22,7 @@ App::uses('Model', 'Model'); App::uses('AppModel', 'Model'); + require_once dirname(dirname(__FILE__)) . DS . 'models.php'; /** diff --git a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorUuidTest.php b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorUuidTest.php index 63d7f6875..ab10ad315 100644 --- a/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorUuidTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/TreeBehaviorUuidTest.php @@ -23,6 +23,7 @@ App::uses('Model', 'Model'); App::uses('AppModel', 'Model'); App::uses('String', 'Utility'); + require_once dirname(dirname(__FILE__)) . DS . 'models.php'; /** diff --git a/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php b/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php index 5bb173503..5081fe919 100644 --- a/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php +++ b/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php @@ -21,6 +21,7 @@ */ App::uses('AppModel', 'Model'); + require_once dirname(__FILE__) . DS . 'models.php'; /** diff --git a/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php b/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php index 944266af3..34ee2b010 100644 --- a/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php @@ -24,6 +24,7 @@ App::uses('DboSource', 'Model/Datasource'); App::uses('DboTestSource', 'Model/Datasource'); App::uses('DboSecondTestSource', 'Model/Datasource'); App::uses('MockDataSource', 'Model/Datasource'); + require_once dirname(dirname(__FILE__)) . DS . 'models.php'; /** diff --git a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php index cbe20026c..91740ec85 100644 --- a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php +++ b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php @@ -19,6 +19,7 @@ */ require_once dirname(__FILE__) . DS . 'ModelTestBase.php'; + App::uses('DboSource', 'Model/Datasource'); App::uses('DboMock', 'Model/Datasource'); diff --git a/lib/Cake/Test/Case/Model/ModelTestBase.php b/lib/Cake/Test/Case/Model/ModelTestBase.php index f68729158..df725fc4c 100644 --- a/lib/Cake/Test/Case/Model/ModelTestBase.php +++ b/lib/Cake/Test/Case/Model/ModelTestBase.php @@ -20,6 +20,7 @@ App::uses('Model', 'Model'); App::uses('AppModel', 'Model'); + require_once dirname(__FILE__) . DS . 'models.php'; /** diff --git a/lib/Cake/Test/bake_compare/Controller/NoActions.ctp b/lib/Cake/Test/bake_compare/Controller/NoActions.ctp index 54efe9f9f..2b9fb5f19 100644 --- a/lib/Cake/Test/bake_compare/Controller/NoActions.ctp +++ b/lib/Cake/Test/bake_compare/Controller/NoActions.ctp @@ -1,5 +1,7 @@ Date: Wed, 20 Nov 2013 12:26:03 +0100 Subject: [PATCH 02/11] fix the failing test case. --- lib/Cake/Test/bake_compare/Controller/NoActions.ctp | 2 -- lib/Cake/Test/bake_compare/Controller/NoHelpersOrComponents.ctp | 2 -- lib/Cake/Test/bake_compare/Controller/Scaffold.ctp | 2 -- 3 files changed, 6 deletions(-) diff --git a/lib/Cake/Test/bake_compare/Controller/NoActions.ctp b/lib/Cake/Test/bake_compare/Controller/NoActions.ctp index 2b9fb5f19..54efe9f9f 100644 --- a/lib/Cake/Test/bake_compare/Controller/NoActions.ctp +++ b/lib/Cake/Test/bake_compare/Controller/NoActions.ctp @@ -1,7 +1,5 @@ Date: Thu, 5 Dec 2013 12:03:07 +0200 Subject: [PATCH 03/11] Check if the item is an array. --- lib/Cake/Utility/Hash.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Utility/Hash.php b/lib/Cake/Utility/Hash.php index 697b3df98..630e82062 100644 --- a/lib/Cake/Utility/Hash.php +++ b/lib/Cake/Utility/Hash.php @@ -130,7 +130,7 @@ class Hash { if ($conditions) { $filter = array(); foreach ($next as $item) { - if (self::_matches($item, $conditions)) { + if (is_array($item) && self::_matches($item, $conditions)) { $filter[] = $item; } } From 848a0ce21725a8d5c9476e96343067e59f05e7cd Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Sat, 7 Dec 2013 22:25:33 +0100 Subject: [PATCH 04/11] Fiexed error in CakeSession that would call start() in an infinite loop when the session is marked as invalid --- lib/Cake/Model/Datasource/CakeSession.php | 41 ++++++++++++------- lib/Cake/Network/CakeResponse.php | 12 +++--- .../Case/Model/Datasource/CakeSessionTest.php | 38 ++++++++++++++++- 3 files changed, 68 insertions(+), 23 deletions(-) diff --git a/lib/Cake/Model/Datasource/CakeSession.php b/lib/Cake/Model/Datasource/CakeSession.php index 6ce55ff47..b7c829a22 100644 --- a/lib/Cake/Model/Datasource/CakeSession.php +++ b/lib/Cake/Model/Datasource/CakeSession.php @@ -194,6 +194,7 @@ class CakeSession { } self::$error = false; + self::$valid = true; return self::started(); } @@ -426,9 +427,14 @@ class CakeSession { * @return void */ public static function destroy() { - self::start(); + if (!self::started()) { + self::_startSession(); + } + session_destroy(); - self::clear(); + + $_SESSION = null; + self::$id = null; } /** @@ -439,7 +445,6 @@ class CakeSession { public static function clear() { $_SESSION = null; self::$id = null; - self::start(); self::renew(); } @@ -620,14 +625,11 @@ class CakeSession { * @return void */ protected static function _checkValid() { - if (!self::start()) { - self::$valid = false; - return false; - } - if ($config = self::read('Config')) { + $config = self::read('Config'); + if ($config) { $sessionConfig = Configure::read('Session'); - if (self::_validAgentAndTime()) { + if (self::valid()) { self::write('Config.time', self::$sessionTime); if (isset($sessionConfig['autoRegenerate']) && $sessionConfig['autoRegenerate'] === true) { $check = $config['countdown']; @@ -639,20 +641,29 @@ class CakeSession { self::write('Config.countdown', self::$requestCountdown); } } - self::$valid = true; } else { + $_SESSION = array(); self::destroy(); - self::$valid = false; self::_setError(1, 'Session Highjacking Attempted !!!'); + self::_startSession(); + self::_writeConfig(); } } else { - self::write('Config.userAgent', self::$_userAgent); - self::write('Config.time', self::$sessionTime); - self::write('Config.countdown', self::$requestCountdown); - self::$valid = true; + self::_writeConfig(); } } +/** + * Writes configuration variables to the session + * + * @return void + */ + protected static function _writeConfig() { + self::write('Config.userAgent', self::$_userAgent); + self::write('Config.time', self::$sessionTime); + self::write('Config.countdown', self::$requestCountdown); + } + /** * Restarts this session. * diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index f6a0ed2e5..c5ca77f29 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/lib/Cake/Network/CakeResponse.php @@ -629,12 +629,12 @@ class CakeResponse { /** * Queries & sets valid HTTP response codes & messages. * - * @param integer|array $code If $code is an integer, then the corresponding code/message is - * returned if it exists, null if it does not exist. If $code is an array, then the - * keys are used as codes and the values as messages to add to the default HTTP - * codes. The codes must be integers greater than 99 and less than 1000. Keep in - * mind that the HTTP specification outlines that status codes begin with a digit - * between 1 and 5, which defines the class of response the client is to expect. + * @param integer|array $code If $code is an integer, then the corresponding code/message is + * returned if it exists, null if it does not exist. If $code is an array, then the + * keys are used as codes and the values as messages to add to the default HTTP + * codes. The codes must be integers greater than 99 and less than 1000. Keep in + * mind that the HTTP specification outlines that status codes begin with a digit + * between 1 and 5, which defines the class of response the client is to expect. * Example: * * httpCodes(404); // returns array(404 => 'Not Found') diff --git a/lib/Cake/Test/Case/Model/Datasource/CakeSessionTest.php b/lib/Cake/Test/Case/Model/Datasource/CakeSessionTest.php index b034c2d54..81091c905 100644 --- a/lib/Cake/Test/Case/Model/Datasource/CakeSessionTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/CakeSessionTest.php @@ -548,9 +548,13 @@ class CakeSessionTest extends CakeTestCase { 'engine' => 'TestAppLibSession' ) )); - TestCakeSession::destroy(); + + TestCakeSession::start(); $this->assertTrue(TestCakeSession::started()); + TestCakeSession::destroy(); + $this->assertFalse(TestCakeSession::started()); + App::build(); } @@ -572,9 +576,12 @@ class CakeSessionTest extends CakeTestCase { ) )); - TestCakeSession::destroy(); + TestCakeSession::start(); $this->assertTrue(TestCakeSession::started()); + TestCakeSession::destroy(); + $this->assertFalse(TestCakeSession::started()); + App::build(); } @@ -752,4 +759,31 @@ class CakeSessionTest extends CakeTestCase { $this->assertEquals(400, Configure::read('Session.timeout')); } +/** + * Proves that invalid sessions will be destroyed and re-created + * if invalid + * + * @return void + */ + public function testInvalidSessionRenew() { + TestCakeSession::start(); + $this->assertNotEmpty($_SESSION['Config']); + $data = $_SESSION; + + session_write_close(); + $_SESSION = null; + + TestCakeSession::start(); + $this->assertEquals($data, $_SESSION); + TestCakeSession::write('Foo', 'Bar'); + + session_write_close(); + $_SESSION = null; + + TestCakeSession::userAgent('bogus!'); + TestCakeSession::start(); + $this->assertNotEquals($data, $_SESSION); + $this->assertEquals('bogus!', $_SESSION['Config']['userAgent']); + } + } From 70d5c37834420ccd6084eac9785b9df142f2c241 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Sun, 8 Dec 2013 13:44:16 +0100 Subject: [PATCH 05/11] Ensuring session is configured before trying to destory it --- lib/Cake/Model/Datasource/CakeSession.php | 24 ++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Model/Datasource/CakeSession.php b/lib/Cake/Model/Datasource/CakeSession.php index b7c829a22..01c79ed23 100644 --- a/lib/Cake/Model/Datasource/CakeSession.php +++ b/lib/Cake/Model/Datasource/CakeSession.php @@ -122,6 +122,13 @@ class CakeSession { */ public static $requestCountdown = 10; +/** + * Whether or not the init function in this class was already called + * + * @var boolean + */ + protected static $_initialized = false; + /** * Pseudo constructor. * @@ -130,15 +137,20 @@ class CakeSession { */ public static function init($base = null) { self::$time = time(); - $checkAgent = Configure::read('Session.checkAgent'); + if (env('HTTP_USER_AGENT')) { self::$_userAgent = md5(env('HTTP_USER_AGENT') . Configure::read('Security.salt')); } + self::_setPath($base); self::_setHost(env('HTTP_HOST')); - register_shutdown_function('session_write_close'); + if (!self::$_initialized) { + register_shutdown_function('session_write_close'); + } + + self::$_initialized = true; } /** @@ -183,10 +195,8 @@ class CakeSession { if (self::started()) { return true; } - self::init(); + $id = self::id(); - session_write_close(); - self::_configureSession(); self::_startSession(); if (!$id && self::started()) { @@ -607,6 +617,10 @@ class CakeSession { * @return boolean Success */ protected static function _startSession() { + self::init(); + session_write_close(); + self::_configureSession(); + if (headers_sent()) { if (empty($_SESSION)) { $_SESSION = array(); From 3a2c4972061c83d5070578a5cde8e56ad87f9d87 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Sun, 8 Dec 2013 14:08:57 +0100 Subject: [PATCH 06/11] Fixed failing test --- lib/Cake/Test/Case/Controller/Component/SessionComponentTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Cake/Test/Case/Controller/Component/SessionComponentTest.php b/lib/Cake/Test/Case/Controller/Component/SessionComponentTest.php index 5354b41e4..b62d14841 100644 --- a/lib/Cake/Test/Case/Controller/Component/SessionComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/SessionComponentTest.php @@ -177,6 +177,7 @@ class SessionComponentTest extends CakeTestCase { * @return void */ public function testSessionError() { + CakeSession::$lastError = null; $Session = new SessionComponent($this->ComponentCollection); $this->assertFalse($Session->error()); } From edcfe2d3a8905f5a2972a48a6d8427e85aab2632 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 9 Dec 2013 12:17:25 -0500 Subject: [PATCH 07/11] Add tests for #2433 --- lib/Cake/Test/Case/Utility/HashTest.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/Cake/Test/Case/Utility/HashTest.php b/lib/Cake/Test/Case/Utility/HashTest.php index ebfa9c520..b023847fd 100644 --- a/lib/Cake/Test/Case/Utility/HashTest.php +++ b/lib/Cake/Test/Case/Utility/HashTest.php @@ -828,6 +828,26 @@ class HashTest extends CakeTestCase { $this->assertEquals(5, $result[3]['id']); } +/** + * Test that attribute matchers don't cause errors on scalar data. + * + * @return void + */ + public function testExtractAttributeEqualityOnScalarValue() { + $data = array( + 'Entity' => array( + 'id' => 1 , + 'data1' => 'value', + ) + ); + $result = Hash::extract($data, 'Entity[id=1].data1'); + $this->assertEquals(array('value'), $result); + + $data = array('Entity' => false ); + $result = Hash::extract($data, 'Entity[id=1].data1'); + $this->assertEquals(array(), $result); + } + /** * Test comparison operators. * From 3b867a048ec8887da13365ed8d0c7882a42700fe Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 11 Dec 2013 12:43:18 -0500 Subject: [PATCH 08/11] Add test for saveMany + validate=false. Closes #2468 --- lib/Cake/Test/Case/Model/ModelWriteTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index 3ad70fd84..04244230d 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -5027,6 +5027,23 @@ class ModelWriteTest extends BaseModelTest { $this->assertEquals($expected, $result); } +/** + * Test SaveMany with validate=false. + * + * @return void + */ + public function testSaveManyValidateFalse() { + $this->loadFixtures('Post'); + $TestModel = new Post(); + $TestModel->deleteAll(true); + $data = array( + array('id' => 1, 'author_id' => 1, 'title' => 'hi'), + array('id' => 2, 'author_id' => 1, 'title' => 'bye') + ); + $result = $TestModel->saveAll($data, array('validate' => false)); + $this->assertTrue($result); + } + /** * Test SaveAssociated with Habtm relations * From 87440bba870b2432dd6d322cf9d39fe3293794eb Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 12 Dec 2013 11:00:29 +0530 Subject: [PATCH 09/11] Fixed docblock. Closes #2476 --- lib/Cake/Network/CakeResponse.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index c2a2b42fa..e8b14fb8a 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/lib/Cake/Network/CakeResponse.php @@ -429,9 +429,9 @@ class CakeResponse { } /** - * Sets the cookies that have been added via static method CakeResponse::addCookie() - * before any other output is sent to the client. - * Will set the cookies in the order they have been set. + * Sets the cookies that have been added via CakeResponse::cookie() before any + * other output is sent to the client. Will set the cookies in the order they + * have been set. * * @return void */ From fc6edf4d9c3d1e6ba68a295a557b1ca4fddcaf0a Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Thu, 12 Dec 2013 09:07:00 +0100 Subject: [PATCH 10/11] Fixed small coding standard error --- lib/Cake/Test/Case/Utility/HashTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Utility/HashTest.php b/lib/Cake/Test/Case/Utility/HashTest.php index b023847fd..5df02e3ca 100644 --- a/lib/Cake/Test/Case/Utility/HashTest.php +++ b/lib/Cake/Test/Case/Utility/HashTest.php @@ -836,7 +836,7 @@ class HashTest extends CakeTestCase { public function testExtractAttributeEqualityOnScalarValue() { $data = array( 'Entity' => array( - 'id' => 1 , + 'id' => 1, 'data1' => 'value', ) ); From 79701af5019f25af65a30f4a8b4bdd3022035566 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 12 Dec 2013 17:41:38 -0500 Subject: [PATCH 11/11] Make Hash::numeric() accept more numeric things. Negative numbers and other stringy forms of numbers should be accepted. The name Hash::numeric implies is_numeric which it now uses. Fixes #2478 --- lib/Cake/Test/Case/Utility/HashTest.php | 3 +++ lib/Cake/Utility/Hash.php | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/HashTest.php b/lib/Cake/Test/Case/Utility/HashTest.php index 5df02e3ca..26bde007c 100644 --- a/lib/Cake/Test/Case/Utility/HashTest.php +++ b/lib/Cake/Test/Case/Utility/HashTest.php @@ -665,6 +665,9 @@ class HashTest extends CakeTestCase { $data = array('one', 2 => 'two', 3 => 'three', 4 => 'four', 'a' => 'five'); $this->assertFalse(Hash::numeric(array_keys($data))); + + $data = array(2.4, 1, 0, -1, -2); + $this->assertTrue(Hash::numeric($data)); } /** diff --git a/lib/Cake/Utility/Hash.php b/lib/Cake/Utility/Hash.php index 630e82062..1cfe45d45 100644 --- a/lib/Cake/Utility/Hash.php +++ b/lib/Cake/Utility/Hash.php @@ -626,9 +626,7 @@ class Hash { if (empty($data)) { return false; } - $values = array_values($data); - $str = implode('', $values); - return (bool)ctype_digit($str); + return $data === array_filter($data, 'is_numeric'); } /**