From f621bb7fe5c6e648630ac615b4e90a08d290708f Mon Sep 17 00:00:00 2001 From: David Steinsland Date: Thu, 15 Jan 2015 19:20:28 +0100 Subject: [PATCH 01/15] Fixed nesting when ExceptionRenderer throws exception --- lib/Cake/Error/ErrorHandler.php | 13 +++++-- lib/Cake/Test/Case/Error/ErrorHandlerTest.php | 34 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Error/ErrorHandler.php b/lib/Cake/Error/ErrorHandler.php index e87c636d1..18efed6ce 100644 --- a/lib/Cake/Error/ErrorHandler.php +++ b/lib/Cake/Error/ErrorHandler.php @@ -125,6 +125,8 @@ class ErrorHandler { $e->getMessage(), $e->getTraceAsString() ); + + Configure::write('Exception.bail', true); trigger_error($message, E_USER_ERROR); } } @@ -249,10 +251,17 @@ class ErrorHandler { } if (Configure::read('debug')) { - call_user_func($exceptionHandler, new FatalErrorException($description, 500, $file, $line)); + $exception = new FatalErrorException($description, 500, $file, $line); } else { - call_user_func($exceptionHandler, new InternalErrorException()); + $exception = new InternalErrorException(); } + + if (Configure::read('Exception.bail')) { + throw $exception; + } + + call_user_func($exceptionHandler, $exception); + return false; } diff --git a/lib/Cake/Test/Case/Error/ErrorHandlerTest.php b/lib/Cake/Test/Case/Error/ErrorHandlerTest.php index 6ec656036..b2f87882d 100644 --- a/lib/Cake/Test/Case/Error/ErrorHandlerTest.php +++ b/lib/Cake/Test/Case/Error/ErrorHandlerTest.php @@ -20,6 +20,16 @@ App::uses('ErrorHandler', 'Error'); App::uses('Controller', 'Controller'); App::uses('Router', 'Routing'); +/** + * A faulty ExceptionRenderer to test nesting. + */ +class FaultyExceptionRenderer extends ExceptionRenderer { + + public function render() { + throw new Exception('Error from renderer.'); + } +} + /** * ErrorHandlerTest class * @@ -320,4 +330,28 @@ class ErrorHandlerTest extends CakeTestCase { $this->assertContains('[FatalErrorException] Something wrong', $log[1], 'message missing.'); } +/** + * testExceptionRendererNestingDebug method + * + * @expectedException FatalErrorException + * @return void + */ + public function testExceptionRendererNestingDebug() { + Configure::write('debug', 2); + Configure::write('Exception.renderer', 'FaultyExceptionRenderer'); + ErrorHandler::handleFatalError(E_USER_ERROR, 'Initial error', __FILE__ ,__LINE__); + } + +/** + * testExceptionRendererNestingProduction method + * + * @expectedException InternalErrorException + * @return void + */ + public function testExceptionRendererNestingProduction() { + Configure::write('debug', 0); + Configure::write('Exception.renderer', 'FaultyExceptionRenderer'); + ErrorHandler::handleFatalError(E_USER_ERROR, 'Initial error', __FILE__ ,__LINE__); + } + } From ed3b15f13b4b7e70c3d49d3aa05ce9a68a2ede4a Mon Sep 17 00:00:00 2001 From: David Steinsland Date: Thu, 15 Jan 2015 20:04:06 +0100 Subject: [PATCH 02/15] Fixed phpcs --- lib/Cake/Error/ErrorHandler.php | 2 ++ lib/Cake/Test/Case/Error/ErrorHandlerTest.php | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Error/ErrorHandler.php b/lib/Cake/Error/ErrorHandler.php index 18efed6ce..e7fe53da5 100644 --- a/lib/Cake/Error/ErrorHandler.php +++ b/lib/Cake/Error/ErrorHandler.php @@ -236,6 +236,8 @@ class ErrorHandler { * @param string $file File on which error occurred * @param int $line Line that triggered the error * @return bool + * @throws FatalErrorException If the Exception renderer threw an exception during rendering, and debug > 0. + * @throws InternalErrorException If the Exception renderer threw an exception during rendering, and debug is 0. */ public static function handleFatalError($code, $description, $file, $line) { $logMessage = 'Fatal Error (' . $code . '): ' . $description . ' in [' . $file . ', line ' . $line . ']'; diff --git a/lib/Cake/Test/Case/Error/ErrorHandlerTest.php b/lib/Cake/Test/Case/Error/ErrorHandlerTest.php index b2f87882d..2db99959f 100644 --- a/lib/Cake/Test/Case/Error/ErrorHandlerTest.php +++ b/lib/Cake/Test/Case/Error/ErrorHandlerTest.php @@ -25,9 +25,16 @@ App::uses('Router', 'Routing'); */ class FaultyExceptionRenderer extends ExceptionRenderer { +/** + * Dummy rendering implementation. + * + * @return void + * @throws Exception + */ public function render() { throw new Exception('Error from renderer.'); } + } /** @@ -339,7 +346,7 @@ class ErrorHandlerTest extends CakeTestCase { public function testExceptionRendererNestingDebug() { Configure::write('debug', 2); Configure::write('Exception.renderer', 'FaultyExceptionRenderer'); - ErrorHandler::handleFatalError(E_USER_ERROR, 'Initial error', __FILE__ ,__LINE__); + ErrorHandler::handleFatalError(E_USER_ERROR, 'Initial error', __FILE__, __LINE__); } /** @@ -351,7 +358,7 @@ class ErrorHandlerTest extends CakeTestCase { public function testExceptionRendererNestingProduction() { Configure::write('debug', 0); Configure::write('Exception.renderer', 'FaultyExceptionRenderer'); - ErrorHandler::handleFatalError(E_USER_ERROR, 'Initial error', __FILE__ ,__LINE__); + ErrorHandler::handleFatalError(E_USER_ERROR, 'Initial error', __FILE__, __LINE__); } } From e5134986e616a3bc137b97ba0b0424cbcd48c3ec Mon Sep 17 00:00:00 2001 From: David Steinsland Date: Thu, 15 Jan 2015 20:10:48 +0100 Subject: [PATCH 03/15] Reset Exception.bail just in case --- 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 e7fe53da5..33a7e764e 100644 --- a/lib/Cake/Error/ErrorHandler.php +++ b/lib/Cake/Error/ErrorHandler.php @@ -259,6 +259,7 @@ class ErrorHandler { } if (Configure::read('Exception.bail')) { + Configure::write('Exception.bail', false); throw $exception; } From a5e1be7abfb3b45d3b588e99105c782ccd17a259 Mon Sep 17 00:00:00 2001 From: David Steinsland Date: Thu, 15 Jan 2015 23:11:36 +0100 Subject: [PATCH 04/15] Fixed tests --- lib/Cake/Test/Case/Error/ErrorHandlerTest.php | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Test/Case/Error/ErrorHandlerTest.php b/lib/Cake/Test/Case/Error/ErrorHandlerTest.php index 2db99959f..aa7448d64 100644 --- a/lib/Cake/Test/Case/Error/ErrorHandlerTest.php +++ b/lib/Cake/Test/Case/Error/ErrorHandlerTest.php @@ -340,25 +340,45 @@ class ErrorHandlerTest extends CakeTestCase { /** * testExceptionRendererNestingDebug method * - * @expectedException FatalErrorException * @return void */ public function testExceptionRendererNestingDebug() { Configure::write('debug', 2); Configure::write('Exception.renderer', 'FaultyExceptionRenderer'); - ErrorHandler::handleFatalError(E_USER_ERROR, 'Initial error', __FILE__, __LINE__); + + $result = false; + try { + ob_start(); + ob_start(); + ErrorHandler::handleFatalError(E_USER_ERROR, 'Initial error', __FILE__, __LINE__); + } catch (Exception $e) { + $result = $e instanceof FatalErrorException; + } + + restore_error_handler(); + $this->assertTrue($result); } /** * testExceptionRendererNestingProduction method * - * @expectedException InternalErrorException * @return void */ public function testExceptionRendererNestingProduction() { Configure::write('debug', 0); Configure::write('Exception.renderer', 'FaultyExceptionRenderer'); - ErrorHandler::handleFatalError(E_USER_ERROR, 'Initial error', __FILE__, __LINE__); + + $result = false; + try { + ob_start(); + ob_start(); + ErrorHandler::handleFatalError(E_USER_ERROR, 'Initial error', __FILE__, __LINE__); + } catch (Exception $e) { + $result = $e instanceof InternalErrorException; + } + + restore_error_handler(); + $this->assertTrue($result); } } From e37db25ce0ece51a63a76a26ef08ad6781ca88dc Mon Sep 17 00:00:00 2001 From: David Steinsland Date: Fri, 16 Jan 2015 14:47:44 +0100 Subject: [PATCH 05/15] Change configuration property to static class property --- lib/Cake/Error/ErrorHandler.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Error/ErrorHandler.php b/lib/Cake/Error/ErrorHandler.php index 33a7e764e..e89574a85 100644 --- a/lib/Cake/Error/ErrorHandler.php +++ b/lib/Cake/Error/ErrorHandler.php @@ -95,6 +95,14 @@ App::uses('Router', 'Routing'); */ class ErrorHandler { +/** + * Whether to give up rendering an exception, if the renderer itself is + * throwing exceptions. + * + * @var bool + */ + protected static $_bailExceptionRendering = false; + /** * Set as the default exception handler by the CakePHP bootstrap process. * @@ -126,7 +134,7 @@ class ErrorHandler { $e->getTraceAsString() ); - Configure::write('Exception.bail', true); + static::$_bailExceptionRendering = true; trigger_error($message, E_USER_ERROR); } } @@ -258,8 +266,8 @@ class ErrorHandler { $exception = new InternalErrorException(); } - if (Configure::read('Exception.bail')) { - Configure::write('Exception.bail', false); + if (static::$_bailExceptionRendering) { + static::$_bailExceptionRendering = false; throw $exception; } From e5d1846d4b59e1ebd960ddeca600d17b6cb091d0 Mon Sep 17 00:00:00 2001 From: David Steinsland Date: Fri, 16 Jan 2015 16:02:44 +0100 Subject: [PATCH 06/15] Fixed PHP 5.2 compatibility --- lib/Cake/Error/ErrorHandler.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Error/ErrorHandler.php b/lib/Cake/Error/ErrorHandler.php index e89574a85..5ecba0960 100644 --- a/lib/Cake/Error/ErrorHandler.php +++ b/lib/Cake/Error/ErrorHandler.php @@ -134,7 +134,7 @@ class ErrorHandler { $e->getTraceAsString() ); - static::$_bailExceptionRendering = true; + self::$_bailExceptionRendering = true; trigger_error($message, E_USER_ERROR); } } @@ -266,8 +266,8 @@ class ErrorHandler { $exception = new InternalErrorException(); } - if (static::$_bailExceptionRendering) { - static::$_bailExceptionRendering = false; + if (self::$_bailExceptionRendering) { + self::$_bailExceptionRendering = false; throw $exception; } From 8a600e357b0009d571d174eb19b486679d445bc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Barta?= Date: Thu, 29 Jan 2015 16:38:01 +0100 Subject: [PATCH 07/15] Adding webfont formats as binary in .gitattributes With the current state, our Linux workstations with default configs convert fonts' line endings, and that screws them up. These lines fix this. --- .gitattributes | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitattributes b/.gitattributes index cc576ac79..3c21bde61 100644 --- a/.gitattributes +++ b/.gitattributes @@ -33,3 +33,6 @@ *.ico binary *.mo binary *.pdf binary +*.woff binary +*.ttf binary +*.eot binary From 970cb81d03dc8f3db9efe7b9271f4b4e089dd3ae Mon Sep 17 00:00:00 2001 From: James Watts Date: Mon, 2 Feb 2015 02:07:13 +0100 Subject: [PATCH 08/15] Typo typo --- lib/Cake/Network/CakeResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index 9902fe632..b2890b7f1 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/lib/Cake/Network/CakeResponse.php @@ -1138,7 +1138,7 @@ class CakeResponse { /** * Checks whether a response has not been modified according to the 'If-None-Match' * (Etags) and 'If-Modified-Since' (last modification date) request - * headers headers. If the response is detected to be not modified, it + * headers. If the response is detected to be not modified, it * is marked as so accordingly so the client can be informed of that. * * In order to mark a response as not modified, you need to set at least From acd32b71fe5e9e229d50d051bf208556d0835684 Mon Sep 17 00:00:00 2001 From: Rachman Chavik Date: Wed, 4 Feb 2015 15:47:01 +0700 Subject: [PATCH 09/15] Fix: "bake plugin" generates incorrect directory for View/Layouts --- lib/Cake/Console/Command/Task/PluginTask.php | 2 +- lib/Cake/Test/Case/Console/Command/Task/PluginTaskTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Console/Command/Task/PluginTask.php b/lib/Cake/Console/Command/Task/PluginTask.php index 8105cc8d0..95c3b3039 100644 --- a/lib/Cake/Console/Command/Task/PluginTask.php +++ b/lib/Cake/Console/Command/Task/PluginTask.php @@ -123,7 +123,7 @@ class PluginTask extends AppShell { 'Test' . DS . 'Fixture', 'View' . DS . 'Elements', 'View' . DS . 'Helper', - 'View' . DS . 'Layout', + 'View' . DS . 'Layouts', 'webroot' . DS . 'css', 'webroot' . DS . 'js', 'webroot' . DS . 'img', diff --git a/lib/Cake/Test/Case/Console/Command/Task/PluginTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/PluginTaskTest.php index 38c243d21..82500e3aa 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/PluginTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/PluginTaskTest.php @@ -115,7 +115,7 @@ class PluginTaskTest extends CakeTestCase { 'Test' . DS . 'Fixture', 'View' . DS . 'Elements', 'View' . DS . 'Helper', - 'View' . DS . 'Layout', + 'View' . DS . 'Layouts', 'webroot' . DS . 'css', 'webroot' . DS . 'js', 'webroot' . DS . 'img', From 3f715c4262aa5f141c941a90b9015a2e50713ae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20M=C3=B8ller?= Date: Wed, 4 Feb 2015 21:29:16 +0100 Subject: [PATCH 10/15] Load ClassRegistry Once --- lib/Cake/Console/Shell.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Cake/Console/Shell.php b/lib/Cake/Console/Shell.php index 67e3c2eab..71ca72352 100644 --- a/lib/Cake/Console/Shell.php +++ b/lib/Cake/Console/Shell.php @@ -22,7 +22,6 @@ App::uses('ConsoleInputSubcommand', 'Console'); App::uses('ConsoleOptionParser', 'Console'); App::uses('ClassRegistry', 'Utility'); App::uses('File', 'Utility'); -App::uses('ClassRegistry', 'Utility'); /** * Base class for command-line utilities for automating programmer chores. From 703be31c83709d3008615257f5fb0bff744d2eb8 Mon Sep 17 00:00:00 2001 From: David Yell Date: Thu, 5 Feb 2015 12:02:18 +0000 Subject: [PATCH 11/15] Update phpunit.php PHPUnit can no longer be installed using pear --- lib/Cake/TestSuite/templates/phpunit.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/Cake/TestSuite/templates/phpunit.php b/lib/Cake/TestSuite/templates/phpunit.php index f25d8d971..3f39a59d9 100644 --- a/lib/Cake/TestSuite/templates/phpunit.php +++ b/lib/Cake/TestSuite/templates/phpunit.php @@ -20,12 +20,7 @@

PHPUnit is not installed!

You must install PHPUnit to use the CakePHP(tm) Test Suite.

-

PHPUnit can be installed with pear, using the pear installer.

-

To install with the PEAR installer run the following commands:

-
    -
  • pear config-set auto_discover 1
  • -
  • pear install pear.phpunit.de/PHPUnit
  • -
+

PHPUnit can be installed with Composer, or downloaded as a phar archive.

Once PHPUnit is installed make sure its located on PHP's include_path by checking your php.ini

For full instructions on how to install PHPUnit, see the PHPUnit installation guide.

Download PHPUnit

From ae8653a06622ed2a3886c1cb5f5753510156dbcc Mon Sep 17 00:00:00 2001 From: Michael Dabydeen Date: Thu, 5 Feb 2015 13:26:03 -0500 Subject: [PATCH 12/15] Contributing: Fixed a broken link. Link to markdown files should end in .md not .mdown. --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 85f793b6b..5bb121179 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -60,7 +60,7 @@ To run the sniffs for CakePHP coding standards: phpcs -p --extensions=php --standard=CakePHP ./lib/Cake Check the [cakephp-codesniffer](https://github.com/cakephp/cakephp-codesniffer) -repository to setup the CakePHP standard. The [README](https://github.com/cakephp/cakephp-codesniffer/blob/master/README.mdown) contains installation info +repository to setup the CakePHP standard. The [README](https://github.com/cakephp/cakephp-codesniffer/blob/master/README.md) contains installation info for the sniff and phpcs. # Additional Resources From b974daac7bf66602f2d38c45782900033dc4e291 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 5 Feb 2015 22:28:02 -0500 Subject: [PATCH 13/15] Don't create invalid maxlength attributes for decimal columns. Converting the maxlength to an int avoids any commas from decimal columns. Refs #5832 --- .../Test/Case/View/Helper/FormHelperTest.php | 26 +++++++++++++++++++ lib/Cake/View/Helper/FormHelper.php | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 3f9a765cb..0a4e8f004 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -763,6 +763,32 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); } +/** + * Tests correct generation of decimal fields as text inputs + * + * @return void + */ + public function testTextFieldGenerationForDecimalAsText() { + $this->Form->create('ValidateUser'); + $result = $this->Form->input('cost_decimal', array( + 'type' => 'text' + )); + $expected = array( + 'div' => array('class' => 'input text'), + 'label' => array('for' => 'ValidateUserCostDecimal'), + 'Cost Decimal', + '/label', + array('input' => array( + 'type' => 'text', + 'name' => 'data[ValidateUser][cost_decimal]', + 'id' => 'ValidateUserCostDecimal', + 'maxlength' => 6, + )), + '/div' + ); + $this->assertTags($result, $expected); + } + /** * Tests correct generation of number fields for integer fields * diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index ed614e830..21e86e93d 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -1292,7 +1292,7 @@ class FormHelper extends AppHelper { if ($autoLength && in_array($options['type'], array('text', 'textarea', 'email', 'tel', 'url', 'search')) ) { - $options['maxlength'] = $fieldDef['length']; + $options['maxlength'] = (int)$fieldDef['length']; } return $options; } From ff39d93299793cd6f1528a7a98db640010846d08 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sat, 7 Feb 2015 15:52:34 -0500 Subject: [PATCH 14/15] Remove PHP5.2 from the build matrix. Travis-ci no longer supports PHP5.2. Attempting to run tests on it causes our builds to fail out. I think this also begs a broader discussion around supported versions in the future. I'm not personally comfortable saying we support PHP 5.2 when we don't run tests against it anymore. --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index c62fd7bde..82761958e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 5.2 - 5.3 - 5.4 - 5.5 @@ -27,8 +26,8 @@ matrix: before_script: - - sh -c "if [ '$TRAVIS_PHP_VERSION' != '5.2' ]; then composer global require 'phpunit/phpunit=3.7.33'; fi" - - sh -c "if [ '$TRAVIS_PHP_VERSION' != '5.2' ]; then ln -s ~/.composer/vendor/phpunit/phpunit/PHPUnit ./vendors/PHPUnit; fi" + - sh -c "composer global require 'phpunit/phpunit=3.7.33'" + - sh -c "ln -s ~/.composer/vendor/phpunit/phpunit/PHPUnit ./vendors/PHPUnit" - sudo locale-gen de_DE - 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" From 3dfa22b02117d09070c8eee2ec1c79faf6368533 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 10 Feb 2015 22:46:53 -0500 Subject: [PATCH 15/15] Fix order of hasOne assocation. This should fix non-deterministic failures. --- .../Controller/Component/Auth/BasicAuthenticateTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Controller/Component/Auth/BasicAuthenticateTest.php b/lib/Cake/Test/Case/Controller/Component/Auth/BasicAuthenticateTest.php index c4402a7f7..df18703c4 100644 --- a/lib/Cake/Test/Case/Controller/Component/Auth/BasicAuthenticateTest.php +++ b/lib/Cake/Test/Case/Controller/Component/Auth/BasicAuthenticateTest.php @@ -254,7 +254,11 @@ class BasicAuthenticateTest extends CakeTestCase { */ public function testAuthenticateUserFieldsRelatedModelsSuccess() { $User = ClassRegistry::init('User'); - $User->bindModel(array('hasOne' => array('Article'))); + $User->bindModel(array('hasOne' => array( + 'Article' => array( + 'order' => 'Article.id ASC' + ) + ))); $this->auth->settings['recursive'] = 0; $this->auth->settings['userFields'] = array('Article.id', 'Article.title'); $request = new CakeRequest('posts/index', false);