From 60b9cd80a02f7f17c55e33995b904ecc701d4872 Mon Sep 17 00:00:00 2001 From: Stefano Zoffoli Date: Tue, 13 Mar 2012 17:02:22 +0100 Subject: [PATCH 01/29] Prevent blackhole auth error where are present multi fields (part 2) --- lib/Cake/View/Helper/FormHelper.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 58e6493f3..16aaca259 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -604,12 +604,8 @@ class FormHelper extends AppHelper { } } - $last = end($field); - if (is_numeric($last) || empty($last)) { - array_pop($field); - } - $field = implode('.', $field); + $field = preg_replace('/(\.\d+)+$/', '', $field); if ($lock) { if (!in_array($field, $this->fields)) { From 1254a1068fd40cbc73b18232794e2c9e55bce7ea Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 14 Mar 2012 20:20:55 -0400 Subject: [PATCH 02/29] Fixing issues with unwanted querystring parameters. Because the request url was being appended as ?/$1 any nested named parameters would be added as additional GET params. This is yet another case where named parameters are fail. Modify the built-in htaccess rules to not use a GET parameter at all, and just read from REQUEST_URI. Fixes #2678 --- app/webroot/.htaccess | 2 +- lib/Cake/Console/Templates/skel/webroot/.htaccess | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/webroot/.htaccess b/app/webroot/.htaccess index f2646d170..48a63f014 100644 --- a/app/webroot/.htaccess +++ b/app/webroot/.htaccess @@ -2,5 +2,5 @@ RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f - RewriteRule ^(.*)$ index.php?/$1 [QSA,L] + RewriteRule ^(.*)$ index.php [QSA,L] diff --git a/lib/Cake/Console/Templates/skel/webroot/.htaccess b/lib/Cake/Console/Templates/skel/webroot/.htaccess index f2646d170..48a63f014 100644 --- a/lib/Cake/Console/Templates/skel/webroot/.htaccess +++ b/lib/Cake/Console/Templates/skel/webroot/.htaccess @@ -2,5 +2,5 @@ RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f - RewriteRule ^(.*)$ index.php?/$1 [QSA,L] + RewriteRule ^(.*)$ index.php [QSA,L] From 9f9c6fdd671be40b5c5da0d89b10d45eaebbc0b3 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Wed, 14 Mar 2012 01:12:35 +0100 Subject: [PATCH 03/29] ensure correct order in results as postgres does not always return in same order --- lib/Cake/Test/Case/Model/ModelWriteTest.php | 71 +++++++++++---------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index 9d9cf429d..5e896795d 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -2027,13 +2027,10 @@ class ModelWriteTest extends BaseModelTest { $articles = $Article->find('all', array( 'fields' => array('id','title'), - 'recursive' => -1 + 'recursive' => -1, + 'order' => array('Article.id' => 'ASC') )); - - $comments = $Comment->find('all', array( - 'fields' => array('id','article_id','user_id','comment','published'), 'recursive' => -1)); - - $this->assertEquals($articles, array( + $expected = array( array('Article' => array( 'id' => 1, 'title' => 'First Article' @@ -2045,9 +2042,15 @@ class ModelWriteTest extends BaseModelTest { array('Article' => array( 'id' => 3, 'title' => 'Third Article' - )))); + ))); + $this->assertEquals($expected, $articles); - $this->assertEquals($comments, array( + $comments = $Comment->find('all', array( + 'fields' => array('id','article_id','user_id','comment','published'), + 'recursive' => -1, + 'order' => array('Comment.id' => 'ASC') + )); + $expected = array( array('Comment' => array( 'id' => 1, 'article_id' => 1, @@ -2089,7 +2092,8 @@ class ModelWriteTest extends BaseModelTest { 'user_id' => 2, 'comment' => 'Second Comment for Second Article', 'published' => 'Y' - )))); + ))); + $this->assertEquals($expected, $comments); $data = array( 'Comment' => array( @@ -2102,24 +2106,18 @@ class ModelWriteTest extends BaseModelTest { 'id' => 2, 'title' => 'Second Article Modified' )); - $result = $Comment->create($data); - $this->assertFalse(empty($result)); + $result = $Comment->save(); $this->assertFalse(empty($result)); $articles = $Article->find('all', array( 'fields' => array('id','title'), - 'recursive' => -1 + 'recursive' => -1, + 'order' => array('Article.id' => 'ASC') )); - - $comments = $Comment->find('all', array( - 'fields' => array('id','article_id','user_id','comment','published'), - 'recursive' => -1 - )); - - $this->assertEquals($articles, array( + $expected = array( array('Article' => array( 'id' => 1, 'title' => 'First Article' @@ -2131,9 +2129,16 @@ class ModelWriteTest extends BaseModelTest { array('Article' => array( 'id' => 3, 'title' => 'Third Article' - )))); + ))); - $this->assertEquals($comments, array( + $this->assertEquals($expected, $articles); + + $comments = $Comment->find('all', array( + 'fields' => array('id','article_id','user_id','comment','published'), + 'recursive' => -1, + 'order' => array('Comment.id' => 'ASC') + )); + $expected = array( array('Comment' => array( 'id' => 1, 'article_id' => 1, @@ -2182,8 +2187,8 @@ class ModelWriteTest extends BaseModelTest { 'user_id' => 4, 'comment' => 'Brand New Comment', 'published' => 'N' - )))); - + ))); + $this->assertEquals($expected, $comments); } /** @@ -2197,7 +2202,7 @@ class ModelWriteTest extends BaseModelTest { $SecondaryArticle = new Article(); $result = $Article->field('title', array('id' => 1)); - $this->assertEquals($result, 'First Article'); + $this->assertEquals('First Article', $result); $data = array( 'Article' => array( @@ -2222,10 +2227,10 @@ class ModelWriteTest extends BaseModelTest { $articles = $Article->find('all', array( 'fields' => array('id','title'), - 'recursive' => -1 + 'recursive' => -1, + 'order' => array('Article.id' => 'ASC') )); - - $this->assertEquals($articles, array( + $expected = array( array('Article' => array( 'id' => 1, 'title' => 'First Article' @@ -2241,7 +2246,9 @@ class ModelWriteTest extends BaseModelTest { array('Article' => array( 'id' => 4, 'title' => 'Brand New Article' - )))); + ))); + + $this->assertEquals($expected, $articles); } /** @@ -2255,7 +2262,7 @@ class ModelWriteTest extends BaseModelTest { $Secondary = new PrimaryModel(); $result = $Primary->field('primary_name', array('id' => 1)); - $this->assertEquals($result, 'Primary Name Existing'); + $this->assertEquals('Primary Name Existing', $result); $data = array( 'PrimaryModel' => array( @@ -2270,16 +2277,16 @@ class ModelWriteTest extends BaseModelTest { $this->assertFalse(empty($result)); $result = $Primary->field('primary_name', array('id' => 1)); - $this->assertEquals($result, 'Primary Name Existing'); + $this->assertEquals('Primary Name Existing', $result); $result = $Primary->getInsertID(); $this->assertTrue(!empty($result)); $result = $Primary->field('primary_name', array('id' => $result)); - $this->assertEquals($result, 'Primary Name New'); + $this->assertEquals('Primary Name New', $result); $result = $Primary->find('count'); - $this->assertEquals($result, 2); + $this->assertEquals(2, $result); } /** From 3e0294a695a54b56aa65c96d77166d6ef1dfab0f Mon Sep 17 00:00:00 2001 From: Ceeram Date: Wed, 14 Mar 2012 15:01:19 +0100 Subject: [PATCH 04/29] Several fixes for testcases. - Ensure correct ordering of find results - avoid fatal error when testing email transport classes on 5.2 - add skips when running cross db join tests and multiple sqlite configs are defined --- .../Case/Model/ModelCrossSchemaHabtmTest.php | 3 +-- lib/Cake/Test/Case/Model/ModelDeleteTest.php | 15 ++++++++------ .../Test/Case/Model/ModelIntegrationTest.php | 3 ++- lib/Cake/Test/Case/Model/ModelWriteTest.php | 20 +++++++++++++------ .../Case/Network/Email/DebugTransportTest.php | 2 +- .../Case/Network/Email/SmtpTransportTest.php | 2 +- 6 files changed, 28 insertions(+), 17 deletions(-) diff --git a/lib/Cake/Test/Case/Model/ModelCrossSchemaHabtmTest.php b/lib/Cake/Test/Case/Model/ModelCrossSchemaHabtmTest.php index 42b71f562..ac0dc978c 100644 --- a/lib/Cake/Test/Case/Model/ModelCrossSchemaHabtmTest.php +++ b/lib/Cake/Test/Case/Model/ModelCrossSchemaHabtmTest.php @@ -63,6 +63,7 @@ class ModelCrossSchemaHabtmTest extends BaseModelTest { */ protected function _checkConfigs() { $config = ConnectionManager::enumConnectionObjects(); + $this->skipIf($this->db instanceof Sqlite, 'This test is not compatible with Sqlite.'); $this->skipIf( !isset($config['test']) || !isset($config['test2']), 'Primary and secondary test databases not configured, skipping cross-database join tests.' @@ -95,7 +96,6 @@ class ModelCrossSchemaHabtmTest extends BaseModelTest { */ public function testHabtmFind() { $this->loadFixtures('Player', 'Guild', 'GuildsPlayer'); - $Player = ClassRegistry::init('Player'); $players = $Player->find('all', array( @@ -130,7 +130,6 @@ class ModelCrossSchemaHabtmTest extends BaseModelTest { */ public function testHabtmSave() { $this->loadFixtures('Player', 'Guild', 'GuildsPlayer'); - $Player = ClassRegistry::init('Player'); $players = $Player->find('count'); $this->assertEquals(4, $players); diff --git a/lib/Cake/Test/Case/Model/ModelDeleteTest.php b/lib/Cake/Test/Case/Model/ModelDeleteTest.php index 942526ff9..e478035e4 100644 --- a/lib/Cake/Test/Case/Model/ModelDeleteTest.php +++ b/lib/Cake/Test/Case/Model/ModelDeleteTest.php @@ -316,7 +316,8 @@ class ModelDeleteTest extends BaseModelTest { $TestModel->recursive = -1; $result = $TestModel->find('all', array( - 'fields' => array('id', 'user_id', 'title', 'published') + 'fields' => array('id', 'user_id', 'title', 'published'), + 'order' => array('Article.id' => 'ASC') )); $expected = array( @@ -363,7 +364,8 @@ class ModelDeleteTest extends BaseModelTest { $TestModel->recursive = -1; $result = $TestModel->find('all', array( - 'fields' => array('id', 'user_id', 'title', 'published') + 'fields' => array('id', 'user_id', 'title', 'published'), + 'order' => array('Article.id' => 'ASC') )); $expected = array( array('Article' => array( @@ -398,7 +400,8 @@ class ModelDeleteTest extends BaseModelTest { $TestModel->recursive = -1; $result = $TestModel->find('all', array( - 'fields' => array('id', 'user_id', 'title', 'published') + 'fields' => array('id', 'user_id', 'title', 'published'), + 'order' => array('Article.id' => 'ASC') )); $expected = array( array('Article' => array( @@ -559,7 +562,7 @@ class ModelDeleteTest extends BaseModelTest { 'ArticlesTag', 'Comment', 'User', 'Attachment' ); $Bidding = new Bidding(); - $result = $Bidding->find('all'); + $result = $Bidding->find('all', array('order' => array('Bidding.id' => 'ASC'))); $expected = array( array( 'Bidding' => array('id' => 1, 'bid' => 'One', 'name' => 'Bid 1'), @@ -581,7 +584,7 @@ class ModelDeleteTest extends BaseModelTest { $this->assertEquals($expected, $result); $Bidding->delete(4, true); - $result = $Bidding->find('all'); + $result = $Bidding->find('all', array('order' => array('Bidding.id' => 'ASC'))); $expected = array( array( 'Bidding' => array('id' => 1, 'bid' => 'One', 'name' => 'Bid 1'), @@ -599,7 +602,7 @@ class ModelDeleteTest extends BaseModelTest { $this->assertEquals($expected, $result); $Bidding->delete(2, true); - $result = $Bidding->find('all'); + $result = $Bidding->find('all', array('order' => array('Bidding.id' => 'ASC'))); $expected = array( array( 'Bidding' => array('id' => 1, 'bid' => 'One', 'name' => 'Bid 1'), diff --git a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php index d209eb005..cbedee271 100644 --- a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php +++ b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php @@ -717,6 +717,7 @@ class ModelIntegrationTest extends BaseModelTest { */ public function testHABTMKeepExistingWithThreeDbs() { $config = ConnectionManager::enumConnectionObjects(); + $this->skipIf($this->db instanceof Sqlite, 'This test is not compatible with Sqlite.'); $this->skipIf( !isset($config['test']) || !isset($config['test2']) || !isset($config['test_database_three']), 'Primary, secondary, and tertiary test databases not configured, skipping test. To run this test define $test, $test2, and $test_database_three in your database configuration.' @@ -835,7 +836,7 @@ class ModelIntegrationTest extends BaseModelTest { array('hour' => '', 'min' => '', 'sec' => ''), '' ), - // set and empty merdian + // set and empty merdian array( array('hour' => '1', 'min' => '00', 'meridian' => ''), '' diff --git a/lib/Cake/Test/Case/Model/ModelWriteTest.php b/lib/Cake/Test/Case/Model/ModelWriteTest.php index 5e896795d..631342ee6 100644 --- a/lib/Cake/Test/Case/Model/ModelWriteTest.php +++ b/lib/Cake/Test/Case/Model/ModelWriteTest.php @@ -1006,7 +1006,10 @@ class ModelWriteTest extends BaseModelTest { $this->assertEquals($expected, $result); $TestModel->recursive = -1; - $result = $TestModel->find('all', array('fields' => array('id', 'title'))); + $result = $TestModel->find('all', array( + 'fields' => array('id', 'title'), + 'order' => array('Article.id' => 'ASC') + )); $expected = array( array('Article' => array('id' => 1, 'title' => 'First Article')), array('Article' => array('id' => 2, 'title' => 'Second Article')), @@ -3075,7 +3078,8 @@ class ModelWriteTest extends BaseModelTest { 'First new comment', 'Second new comment' ); - $this->assertEquals($expected, Set::extract($result['Comment'], '{n}.comment')); + $result = Set::extract(Set::sort($result['Comment'], '{n}.id', 'ASC'), '{n}.comment'); + $this->assertEquals($expected, $result); $result = $TestModel->Comment->User->field('id', array('user' => 'newuser', 'password' => 'newuserpass')); $this->assertEquals(5, $result); @@ -3097,7 +3101,8 @@ class ModelWriteTest extends BaseModelTest { 'Third new comment', 'Fourth new comment' ); - $this->assertEquals($expected, Set::extract($result['Comment'], '{n}.comment')); + $result = Set::extract(Set::sort($result['Comment'], '{n}.id', 'ASC'), '{n}.comment'); + $this->assertEquals($expected, $result); $result = $TestModel->Comment->Attachment->field('id', array('attachment' => 'deepsaved')); $this->assertEquals(2, $result); @@ -3848,7 +3853,8 @@ class ModelWriteTest extends BaseModelTest { 'First new comment', 'Second new comment' ); - $this->assertEquals(Set::extract($result['Comment'], '{n}.comment'), $expected); + $result = Set::extract(Set::sort($result['Comment'], '{n}.id', 'ASC'), '{n}.comment'); + $this->assertEquals($expected, $result); $result = $TestModel->saveAll( array( @@ -3871,7 +3877,8 @@ class ModelWriteTest extends BaseModelTest { 'Second new comment', 'Third new comment' ); - $this->assertEquals(Set::extract($result['Comment'], '{n}.comment'), $expected); + $result = Set::extract(Set::sort($result['Comment'], '{n}.id', 'ASC'), '{n}.comment'); + $this->assertEquals($expected, $result); $TestModel->beforeSaveReturn = false; $result = $TestModel->saveAll( @@ -3895,7 +3902,8 @@ class ModelWriteTest extends BaseModelTest { 'Second new comment', 'Third new comment' ); - $this->assertEquals(Set::extract($result['Comment'], '{n}.comment'), $expected); + $result = Set::extract(Set::sort($result['Comment'], '{n}.id', 'ASC'), '{n}.comment'); + $this->assertEquals($expected, $result); } /** diff --git a/lib/Cake/Test/Case/Network/Email/DebugTransportTest.php b/lib/Cake/Test/Case/Network/Email/DebugTransportTest.php index 9d170fdb4..72fe704c8 100644 --- a/lib/Cake/Test/Case/Network/Email/DebugTransportTest.php +++ b/lib/Cake/Test/Case/Network/Email/DebugTransportTest.php @@ -50,7 +50,7 @@ class DebugTransportTest extends CakeTestCase { $email->messageID('<4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>'); $email->subject('Testing Message'); $date = date(DATE_RFC2822); - $email->setHeaders(array('X-Mailer' => $email::EMAIL_CLIENT, 'Date' => $date)); + $email->setHeaders(array('X-Mailer' => DebugCakeEmail::EMAIL_CLIENT, 'Date' => $date)); $email->expects($this->any())->method('message')->will($this->returnValue(array('First Line', 'Second Line', ''))); $headers = "From: CakePHP Test \r\n"; diff --git a/lib/Cake/Test/Case/Network/Email/SmtpTransportTest.php b/lib/Cake/Test/Case/Network/Email/SmtpTransportTest.php index c6d58444b..6b1ecaadf 100644 --- a/lib/Cake/Test/Case/Network/Email/SmtpTransportTest.php +++ b/lib/Cake/Test/Case/Network/Email/SmtpTransportTest.php @@ -221,7 +221,7 @@ class SmtpTransportTest extends CakeTestCase { $email->messageID('<4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>'); $email->subject('Testing SMTP'); $date = date(DATE_RFC2822); - $email->setHeaders(array('X-Mailer' => $email::EMAIL_CLIENT, 'Date' => $date)); + $email->setHeaders(array('X-Mailer' => SmtpCakeEmail::EMAIL_CLIENT, 'Date' => $date)); $email->expects($this->any())->method('message')->will($this->returnValue(array('First Line', 'Second Line', ''))); $data = "From: CakePHP Test \r\n"; From f1931e43efa2221bc8f1d4a43f8c99aae67f7835 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 14 Mar 2012 20:56:59 -0400 Subject: [PATCH 05/29] Add class_exists() check for view class. Check that the view class hasn't already been mapped in the autoloader before mapping it. This allows developers to map view classes from plugins. Fixes #2684 --- lib/Cake/Controller/Component/RequestHandlerComponent.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Controller/Component/RequestHandlerComponent.php b/lib/Cake/Controller/Component/RequestHandlerComponent.php index 64d6e319b..b8831fe1d 100644 --- a/lib/Cake/Controller/Component/RequestHandlerComponent.php +++ b/lib/Cake/Controller/Component/RequestHandlerComponent.php @@ -581,9 +581,11 @@ class RequestHandlerComponent extends Component { $controller->ext = '.ctp'; $viewClass = Inflector::classify($type); - App::uses($viewClass . 'View', 'View'); - - if (class_exists($viewClass . 'View')) { + $viewName = $viewClass . 'View'; + if (!class_exists($viewName)) { + App::uses($viewName, 'View'); + } + if (class_exists($viewName)) { $controller->viewClass = $viewClass; } elseif (empty($this->_renderType)) { $controller->viewPath .= DS . $type; From fe3d354b618de4a6bacc5376cbe8d78328920482 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 14 Mar 2012 21:15:16 -0400 Subject: [PATCH 06/29] Define roles in pear package for files. Fixes a number of issues with the PEAR package where files would be installed in the incorrect directories as the role type was incorrect. Fixes #2680 --- build.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build.xml b/build.xml index 73e22f4c2..c65426438 100644 --- a/build.xml +++ b/build.xml @@ -137,11 +137,17 @@ script + php + php + php + php + php + php From cadfe155493a46136a9b768368a28f7512149787 Mon Sep 17 00:00:00 2001 From: Thomas Ploch Date: Thu, 15 Mar 2012 16:06:54 +0100 Subject: [PATCH 07/29] Fixed problems with custom Error handlers when inclusion of APP bootstrap is defered. --- lib/Cake/Core/Configure.php | 55 ++++++++++++++++++----- lib/Cake/Test/Case/Core/ConfigureTest.php | 43 +++++++++++++++++- 2 files changed, 86 insertions(+), 12 deletions(-) diff --git a/lib/Cake/Core/Configure.php b/lib/Cake/Core/Configure.php index 698050cee..d026eb761 100644 --- a/lib/Cake/Core/Configure.php +++ b/lib/Cake/Core/Configure.php @@ -75,20 +75,19 @@ class Configure { App::$bootstrapping = false; App::init(); App::build(); - $level = -1; - if (isset(self::$_values['Error']['level'])) { - error_reporting(self::$_values['Error']['level']); - $level = self::$_values['Error']['level']; - } - if (!empty(self::$_values['Error']['handler'])) { - set_error_handler(self::$_values['Error']['handler'], $level); - } - if (!empty(self::$_values['Exception']['handler'])) { - set_exception_handler(self::$_values['Exception']['handler']); - } + + $error = self::$_values['Error']; + $exception = self::$_values['Exception']; + self::setErrorHandlers(true); + if (!include APP . 'Config' . DS . 'bootstrap.php') { trigger_error(__d('cake_dev', "Can't find application bootstrap file. Please create %sbootstrap.php, and make sure it is readable by PHP.", APP . 'Config' . DS), E_USER_ERROR); } + + self::$_values['Error'] = $error; + self::$_values['Exception'] = $exception; + self::setErrorHandlers(); + unset($error, $exception); } } @@ -336,4 +335,38 @@ class Configure { return false; } +/** + * Sets the configure error and exception handlers. + * If reset is true, sets the cake default error and exception handlers + * + * @param boolean $reset True if the cake default error handlers should be set + * @return void + * @static + */ + public static function setErrorHandlers($reset = false) { + if (true === $reset) { + self::$_values['Exception'] = array( + 'handler' => 'ErrorHandler::handleException', + 'renderer' => 'ExceptionRenderer', + 'log' => true + ); + self::$_values['Error'] = array( + 'handler' => 'ErrorHandler::handleError', + 'level' => E_ALL & ~E_DEPRECATED, + 'trace' => true + ); + } + + $level = -1; + if (isset(self::$_values['Error']['level'])) { + error_reporting(self::$_values['Error']['level']); + $level = self::$_values['Error']['level']; + } + if (!empty(self::$_values['Error']['handler'])) { + set_error_handler(self::$_values['Error']['handler'], $level); + } + if (!empty(self::$_values['Exception']['handler'])) { + set_exception_handler(self::$_values['Exception']['handler']); + } + } } diff --git a/lib/Cake/Test/Case/Core/ConfigureTest.php b/lib/Cake/Test/Case/Core/ConfigureTest.php index d9e26664e..05b4f308a 100644 --- a/lib/Cake/Test/Case/Core/ConfigureTest.php +++ b/lib/Cake/Test/Case/Core/ConfigureTest.php @@ -353,5 +353,46 @@ class ConfigureTest extends CakeTestCase { $reader = new StdClass(); Configure::config('test', $reader); } -} +/** + * Tests that resetting the ErrorHandlers works as expected + * + * @return void + */ + public function testSetErrorHandlers() { + $error = array( + 'handler' => 'ErrorHandler::handleError', + 'level' => -2000, + 'trace' => false + ); + $exception = array( + 'handler' => 'ErrorHandler::handleException', + 'renderer' => 'MyExceptionRenderer', + 'log' => false + ); + + Configure::write('Error', $error); + Configure::setErrorHandlers(true); + + $expected = array( + 'handler' => 'ErrorHandler::handleError', + 'level' => E_ALL & ~E_DEPRECATED, + 'trace' => true + ); + $this->assertEqual(Configure::read('Error'), $expected); + + $expected = array( + 'handler' => 'ErrorHandler::handleException', + 'renderer' => 'ExceptionRenderer', + 'log' => true + ); + $this->assertEqual(Configure::read('Exception'), $expected); + + Configure::write('Error', $error); + Configure::write('Exception', $exception); + Configure::setErrorHandlers(); + $this->assertEqual(Configure::read('Error'), $error); + $this->assertEqual(Configure::read('Exception'), $exception); + } + +} From 5713cd3269fb4cbc0cd86f21d0b03418a3015916 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 15 Mar 2012 20:20:39 -0400 Subject: [PATCH 08/29] Fix the way bash is invoked. Using /usr/bin/env is more portable to various *nix flavours. Fixes #2688 --- app/Console/cake | 2 +- lib/Cake/Console/Templates/skel/Console/cake | 4 ++-- lib/Cake/Console/cake | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Console/cake b/app/Console/cake index 22331e20a..447743d0b 100755 --- a/app/Console/cake +++ b/app/Console/cake @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash ################################################################################ # # Bake is a shell script for running CakePHP bake script diff --git a/lib/Cake/Console/Templates/skel/Console/cake b/lib/Cake/Console/Templates/skel/Console/cake index d2ef17ce2..447743d0b 100644 --- a/lib/Cake/Console/Templates/skel/Console/cake +++ b/lib/Cake/Console/Templates/skel/Console/cake @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash ################################################################################ # # Bake is a shell script for running CakePHP bake script @@ -30,4 +30,4 @@ APP=`pwd` exec php -q "$LIB"cake.php -working "$APP" "$@" -exit; \ No newline at end of file +exit; diff --git a/lib/Cake/Console/cake b/lib/Cake/Console/cake index 753668468..424866966 100755 --- a/lib/Cake/Console/cake +++ b/lib/Cake/Console/cake @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash ################################################################################ # # Bake is a shell script for running CakePHP bake script From 6a55749e278f23c289033bf5c0051c3bf5acf5c2 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 15 Mar 2012 21:45:48 -0400 Subject: [PATCH 09/29] Fix reading multiple keys in a single request. Fixes #2676 --- .../Controller/Component/CookieComponent.php | 53 +++++++++++-------- .../Component/CookieComponentTest.php | 21 +++++++- 2 files changed, 50 insertions(+), 24 deletions(-) diff --git a/lib/Cake/Controller/Component/CookieComponent.php b/lib/Cake/Controller/Component/CookieComponent.php index a950e2337..31d2778f6 100644 --- a/lib/Cake/Controller/Component/CookieComponent.php +++ b/lib/Cake/Controller/Component/CookieComponent.php @@ -190,8 +190,9 @@ class CookieComponent extends Component { public function startup(Controller $controller) { $this->_expire($this->time); + $this->_values[$this->name] = array(); if (isset($_COOKIE[$this->name])) { - $this->_values = $this->_decrypt($_COOKIE[$this->name]); + $this->_values[$this->name] = $this->_decrypt($_COOKIE[$this->name]); } } @@ -215,6 +216,10 @@ class CookieComponent extends Component { * @link http://book.cakephp.org/2.0/en/core-libraries/components/cookie.html#CookieComponent::write */ public function write($key, $value = null, $encrypt = true, $expires = null) { + if (empty($this->_values[$this->name])) { + $this->read(); + } + if (is_null($encrypt)) { $encrypt = true; } @@ -227,14 +232,14 @@ class CookieComponent extends Component { foreach ($key as $name => $value) { if (strpos($name, '.') === false) { - $this->_values[$name] = $value; + $this->_values[$this->name][$name] = $value; $this->_write("[$name]", $value); } else { $names = explode('.', $name, 2); - if (!isset($this->_values[$names[0]])) { - $this->_values[$names[0]] = array(); + if (!isset($this->_values[$this->name][$names[0]])) { + $this->_values[$this->name][$names[0]] = array(); } - $this->_values[$names[0]] = Set::insert($this->_values[$names[0]], $names[1], $value); + $this->_values[$this->name][$names[0]] = Set::insert($this->_values[$this->name][$names[0]], $names[1], $value); $this->_write('[' . implode('][', $names) . ']', $value); } } @@ -252,26 +257,28 @@ class CookieComponent extends Component { * @link http://book.cakephp.org/2.0/en/core-libraries/components/cookie.html#CookieComponent::read */ public function read($key = null) { - if (empty($this->_values) && isset($_COOKIE[$this->name])) { - $this->_values = $this->_decrypt($_COOKIE[$this->name]); + if (empty($this->_values[$this->name]) && isset($_COOKIE[$this->name])) { + $this->_values[$this->name] = $this->_decrypt($_COOKIE[$this->name]); + } + if (empty($this->_values[$this->name])) { + $this->_values[$this->name] = array(); } - if (is_null($key)) { - return $this->_values; + return $this->_values[$this->name]; } if (strpos($key, '.') !== false) { $names = explode('.', $key, 2); $key = $names[0]; } - if (!isset($this->_values[$key])) { + if (!isset($this->_values[$this->name][$key])) { return null; } if (!empty($names[1])) { - return Set::extract($this->_values[$key], $names[1]); + return Set::extract($this->_values[$this->name][$key], $names[1]); } - return $this->_values[$key]; + return $this->_values[$this->name][$key]; } /** @@ -288,22 +295,22 @@ class CookieComponent extends Component { * @link http://book.cakephp.org/2.0/en/core-libraries/components/cookie.html#CookieComponent::delete */ public function delete($key) { - if (empty($this->_values)) { + if (empty($this->_values[$this->name])) { $this->read(); } if (strpos($key, '.') === false) { - if (isset($this->_values[$key]) && is_array($this->_values[$key])) { - foreach ($this->_values[$key] as $idx => $val) { + if (isset($this->_values[$this->name][$key]) && is_array($this->_values[$this->name][$key])) { + foreach ($this->_values[$this->name][$key] as $idx => $val) { $this->_delete("[$key][$idx]"); } } $this->_delete("[$key]"); - unset($this->_values[$key]); + unset($this->_values[$this->name][$key]); return; } $names = explode('.', $key, 2); - if (isset($this->_values[$names[0]])) { - $this->_values[$names[0]] = Set::remove($this->_values[$names[0]], $names[1]); + if (isset($this->_values[$this->name][$names[0]])) { + $this->_values[$this->name][$names[0]] = Set::remove($this->_values[$this->name][$names[0]], $names[1]); } $this->_delete('[' . implode('][', $names) . ']'); } @@ -319,17 +326,17 @@ class CookieComponent extends Component { */ public function destroy() { if (isset($_COOKIE[$this->name])) { - $this->_values = $this->_decrypt($_COOKIE[$this->name]); + $this->_values[$this->name] = $this->_decrypt($_COOKIE[$this->name]); } - foreach ($this->_values as $name => $value) { + foreach ($this->_values[$this->name] as $name => $value) { if (is_array($value)) { foreach ($value as $key => $val) { - unset($this->_values[$name][$key]); + unset($this->_values[$this->name][$name][$key]); $this->_delete("[$name][$key]"); } } - unset($this->_values[$name]); + unset($this->_values[$this->name][$name]); $this->_delete("[$name]"); } } @@ -503,5 +510,5 @@ class CookieComponent extends Component { } return $array; } - } + diff --git a/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php b/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php index e45a84562..eafe154d1 100644 --- a/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php @@ -160,7 +160,6 @@ class CookieComponentTest extends CakeTestCase { */ public function testReadPlainCookieData() { $this->_setCookieData(); - $data = $this->Cookie->read('Plain_array'); $expected = array('name' => 'CakePHP', 'version' => '1.2.0.x', 'tag' => 'CakePHP Rocks!'); $this->assertEquals($data, $expected); @@ -170,6 +169,26 @@ class CookieComponentTest extends CakeTestCase { $this->assertEquals($data, $expected); } +/** + * test read() after switching the cookie name. + * + * @return void + */ + public function testReadWithNameSwitch() { + $_COOKIE = array( + 'CakeTestCookie' => array( + 'key' => 'value' + ), + 'OtherTestCookie' => array( + 'key' => 'other value' + ) + ); + $this->assertEquals('value', $this->Cookie->read('key')); + + $this->Cookie->name = 'OtherTestCookie'; + $this->assertEquals('other value', $this->Cookie->read('key')); + } + /** * test a simple write() * From f5804cb4caca2dc3f98e42fa64c4de35055bc17d Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 15 Mar 2012 22:50:05 -0400 Subject: [PATCH 10/29] Fix most coding standards in Test/Case/View --- .../Test/Case/View/Helper/CacheHelperTest.php | 5 +- .../Test/Case/View/Helper/FormHelperTest.php | 31 +++--- .../Test/Case/View/Helper/HtmlHelperTest.php | 98 +++++++++---------- .../View/Helper/JqueryEngineHelperTest.php | 1 + .../Test/Case/View/Helper/JsHelperTest.php | 52 +++++++--- .../View/Helper/MootoolsEngineHelperTest.php | 1 + .../Case/View/Helper/NumberHelperTest.php | 1 - .../Case/View/Helper/PaginatorHelperTest.php | 9 +- .../View/Helper/PrototypeEngineHelperTest.php | 1 + .../Test/Case/View/Helper/RssHelperTest.php | 2 +- .../Case/View/Helper/SessionHelperTest.php | 6 +- .../Test/Case/View/HelperCollectionTest.php | 1 + lib/Cake/Test/Case/View/HelperTest.php | 24 +++-- lib/Cake/Test/Case/View/JsonViewTest.php | 2 +- lib/Cake/Test/Case/View/MediaViewTest.php | 16 +-- lib/Cake/Test/Case/View/ScaffoldViewTest.php | 19 ++-- lib/Cake/Test/Case/View/ThemeViewTest.php | 15 +-- lib/Cake/Test/Case/View/ViewTest.php | 89 +++++------------ lib/Cake/Test/Case/View/XmlViewTest.php | 2 +- 19 files changed, 184 insertions(+), 191 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/CacheHelperTest.php b/lib/Cake/Test/Case/View/Helper/CacheHelperTest.php index 5f77829c4..768d7a5f5 100644 --- a/lib/Cake/Test/Case/View/Helper/CacheHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/CacheHelperTest.php @@ -49,6 +49,7 @@ class CacheTestController extends Controller { $this->set('batman', 'bruce wayne'); $this->set('spiderman', 'peter parker'); } + } /** @@ -84,7 +85,7 @@ class CacheHelperTest extends CakeTestCase { Configure::write('Cache.check', true); Configure::write('Cache.disable', false); App::build(array( - 'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS) + 'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS) ), App::RESET); } @@ -380,7 +381,6 @@ class CacheHelperTest extends CakeTestCase { $this->assertTrue(file_exists($filename)); @unlink($filename); - $this->Controller->cache_parsing(); $this->Controller->cacheAction = array( 'cache_parsing' => 21600 @@ -398,7 +398,6 @@ class CacheHelperTest extends CakeTestCase { $this->assertTrue(file_exists($filename)); @unlink($filename); - $this->Controller->cache_parsing(); $this->Controller->request->addParams(array( 'controller' => 'cache_test', diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 5f2255172..271c69d53 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -182,6 +182,7 @@ class ContactTagsContact extends CakeTestModel { public function setSchema($schema) { $this->_schema = $schema; } + } /** @@ -217,6 +218,7 @@ class ContactNonStandardPk extends Contact { unset($this->_schema['id']); return $this->_schema; } + } /** @@ -369,6 +371,7 @@ class OpenidUrl extends CakeTestModel { $this->invalidate('openid_not_registered'); return true; } + } /** @@ -432,6 +435,7 @@ class ValidateUser extends CakeTestModel { $this->invalidate('email'); return false; } + } /** @@ -505,6 +509,7 @@ class ValidateProfile extends CakeTestModel { $this->invalidate('city'); return false; } + } /** @@ -568,6 +573,7 @@ class ValidateItem extends CakeTestModel { $this->invalidate('description'); return false; } + } /** @@ -675,8 +681,6 @@ class FormHelperTest extends CakeTestCase { Configure::write('Security.salt', $this->oldSalt); } - - /** * testFormCreateWithSecurity method * @@ -975,7 +979,6 @@ class FormHelperTest extends CakeTestCase { $this->assertEquals(array('Address.button'), $result); } - /** * Test that submit inputs created with foo[bar] name attributes are unlocked correctly. * @@ -1469,7 +1472,7 @@ class FormHelperTest extends CakeTestCase { */ public function testTagIsInvalid() { $Contact = ClassRegistry::getObject('Contact'); - $Contact->validationErrors[0]['email'] = array('Please provide an email'); + $Contact->validationErrors[0]['email'] = array('Please provide an email'); $this->Form->setEntity('Contact.0.email'); $result = $this->Form->tagIsInvalid(); @@ -1496,7 +1499,7 @@ class FormHelperTest extends CakeTestCase { */ public function testPasswordValidation() { $Contact = ClassRegistry::getObject('Contact'); - $Contact->validationErrors['password'] = array('Please provide a password'); + $Contact->validationErrors['password'] = array('Please provide a password'); $result = $this->Form->input('Contact.password'); $expected = array( @@ -2389,7 +2392,6 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); $this->Form->request->data = array('Model' => array('user_id' => 'value')); @@ -5271,7 +5273,6 @@ class FormHelperTest extends CakeTestCase { $this->assertContains('label for="ModelDateYear"', $result); } - /** * testMonth method * @@ -5613,7 +5614,7 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->hour('Model.field', true, array('value' => 'now')); $thisHour = date('H'); $optValue = date('G'); - $this->assertRegExp('/