Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -2,24 +2,41 @@
/**
* ErrorHandlerTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.Error
* @since CakePHP(tm) v 1.2.0.5432
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('ErrorHandler', 'Error');
App::uses('Controller', 'Controller');
App::uses('Router', 'Routing');
App::uses('Debugger', 'Utility');
/**
* A faulty ExceptionRenderer to test nesting.
*/
class FaultyExceptionRenderer extends ExceptionRenderer {
/**
* Dummy rendering implementation.
*
* @return void
* @throws Exception
*/
public function render() {
throw new Exception('Error from renderer.');
}
}
/**
* ErrorHandlerTest class
@ -76,6 +93,8 @@ class ErrorHandlerTest extends CakeTestCase {
set_error_handler('ErrorHandler::handleError');
$this->_restoreError = true;
Debugger::getInstance()->output('html');
ob_start();
$wrong .= '';
$result = ob_get_clean();
@ -107,6 +126,8 @@ class ErrorHandlerTest extends CakeTestCase {
set_error_handler('ErrorHandler::handleError');
$this->_restoreError = true;
Debugger::getInstance()->output('html');
ob_start();
trigger_error('Test error', $error);
@ -182,7 +203,7 @@ class ErrorHandlerTest extends CakeTestCase {
$result[0]
);
$this->assertRegExp('/^Trace:/', $result[1]);
$this->assertRegExp('/^ErrorHandlerTest\:\:testHandleErrorLoggingTrace\(\)/', $result[2]);
$this->assertRegExp('/^ErrorHandlerTest\:\:testHandleErrorLoggingTrace\(\)/', $result[3]);
if (file_exists(LOGS . 'debug.log')) {
unlink(LOGS . 'debug.log');
}
@ -194,8 +215,6 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
public function testHandleException() {
$this->skipIf(file_exists(APP . 'app_error.php'), 'App error exists cannot run.');
$error = new NotFoundException('Kaboom!');
ob_start();
ErrorHandler::handleException($error);
@ -209,8 +228,6 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
public function testHandleExceptionLog() {
$this->skipIf(file_exists(APP . 'app_error.php'), 'App error exists cannot run.');
if (file_exists(LOGS . 'error.log')) {
unlink(LOGS . 'error.log');
}
@ -223,8 +240,37 @@ class ErrorHandlerTest extends CakeTestCase {
$this->assertRegExp('/Kaboom!/', $result, 'message missing.');
$log = file(LOGS . 'error.log');
$this->assertRegExp('/\[NotFoundException\] Kaboom!/', $log[0], 'message missing.');
$this->assertRegExp('/\#0.*ErrorHandlerTest->testHandleExceptionLog/', $log[1], 'Stack trace missing.');
$this->assertContains('[NotFoundException] Kaboom!', $log[0], 'message missing.');
$this->assertContains('ErrorHandlerTest->testHandleExceptionLog', $log[2], 'Stack trace missing.');
}
/**
* test handleException generating log.
*
* @return void
*/
public function testHandleExceptionLogSkipping() {
if (file_exists(LOGS . 'error.log')) {
unlink(LOGS . 'error.log');
}
Configure::write('Exception.log', true);
Configure::write('Exception.skipLog', array('NotFoundException'));
$notFound = new NotFoundException('Kaboom!');
$forbidden = new ForbiddenException('Fooled you!');
ob_start();
ErrorHandler::handleException($notFound);
$result = ob_get_clean();
$this->assertRegExp('/Kaboom!/', $result, 'message missing.');
ob_start();
ErrorHandler::handleException($forbidden);
$result = ob_get_clean();
$this->assertRegExp('/Fooled you!/', $result, 'message missing.');
$log = file(LOGS . 'error.log');
$this->assertNotContains('[NotFoundException] Kaboom!', $log[0], 'message should not be logged.');
$this->assertContains('[ForbiddenException] Fooled you!', $log[0], 'message missing.');
}
/**
@ -251,14 +297,14 @@ class ErrorHandlerTest extends CakeTestCase {
/**
* test handleFatalError generating a page.
*
* These tests start two buffers as handleFatalError blows the outer one up.
*
* @return void
*/
public function testHandleFatalErrorPage() {
$this->skipIf(file_exists(APP . 'app_error.php'), 'App error exists cannot run.');
$originalDebugLevel = Configure::read('debug');
$line = __LINE__;
ob_start();
ob_start();
Configure::write('debug', 1);
ErrorHandler::handleFatalError(E_ERROR, 'Something wrong', __FILE__, $line);
@ -267,6 +313,7 @@ class ErrorHandlerTest extends CakeTestCase {
$this->assertContains(__FILE__, $result, 'filename missing.');
$this->assertContains((string)$line, $result, 'line missing.');
ob_start();
ob_start();
Configure::write('debug', 0);
ErrorHandler::handleFatalError(E_ERROR, 'Something wrong', __FILE__, $line);
@ -274,8 +321,6 @@ class ErrorHandlerTest extends CakeTestCase {
$this->assertNotContains('Something wrong', $result, 'message must not appear.');
$this->assertNotContains(__FILE__, $result, 'filename must not appear.');
$this->assertContains('An Internal Error Has Occurred', $result);
Configure::write('debug', $originalDebugLevel);
}
/**
@ -284,8 +329,6 @@ class ErrorHandlerTest extends CakeTestCase {
* @return void
*/
public function testHandleFatalErrorLog() {
$this->skipIf(file_exists(APP . 'app_error.php'), 'App error exists cannot run.');
if (file_exists(LOGS . 'error.log')) {
unlink(LOGS . 'error.log');
}
@ -299,4 +342,48 @@ class ErrorHandlerTest extends CakeTestCase {
$this->assertContains('[FatalErrorException] Something wrong', $log[1], 'message missing.');
}
/**
* testExceptionRendererNestingDebug method
*
* @return void
*/
public function testExceptionRendererNestingDebug() {
Configure::write('debug', 2);
Configure::write('Exception.renderer', 'FaultyExceptionRenderer');
$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
*
* @return void
*/
public function testExceptionRendererNestingProduction() {
Configure::write('debug', 0);
Configure::write('Exception.renderer', 'FaultyExceptionRenderer');
$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);
}
}

View file

@ -2,25 +2,25 @@
/**
* ExceptionRendererTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.Error
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('ExceptionRenderer', 'Error');
App::uses('Controller', 'Controller');
App::uses('Component', 'Controller');
App::uses('Router', 'Routing');
App::uses('CakeEventManager', 'Event');
/**
* Short description for class.
@ -29,13 +29,6 @@ App::uses('Router', 'Routing');
*/
class AuthBlueberryUser extends CakeTestModel {
/**
* name property
*
* @var string 'AuthBlueberryUser'
*/
public $name = 'AuthBlueberryUser';
/**
* useTable property
*
@ -137,7 +130,6 @@ class MyCustomExceptionRenderer extends ExceptionRenderer {
class MissingWidgetThingException extends NotFoundException {
}
/**
* ExceptionRendererTest class
*
@ -154,6 +146,7 @@ class ExceptionRendererTest extends CakeTestCase {
*/
public function setUp() {
parent::setUp();
Configure::write('Config.language', 'eng');
App::build(array(
'View' => array(
CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS
@ -278,6 +271,8 @@ class ExceptionRendererTest extends CakeTestCase {
/**
* test that helpers in custom CakeErrorController are not lost
*
* @return void
*/
public function testCakeErrorHelpersNotLost() {
$testApp = CAKE . 'Test' . DS . 'test_app' . DS;
@ -479,6 +474,27 @@ class ExceptionRendererTest extends CakeTestCase {
$this->assertRegExp('/<h2>An Internal Error Has Occurred<\/h2>/', $result);
}
/**
* testExceptionResponseHeader method
*
* @return void
*/
public function testExceptionResponseHeader() {
$exception = new MethodNotAllowedException('Only allowing POST and DELETE');
$exception->responseHeader(array('Allow: POST, DELETE'));
$ExceptionRenderer = new ExceptionRenderer($exception);
//Replace response object with mocked object add back the original headers which had been set in ExceptionRenderer constructor
$headers = $ExceptionRenderer->controller->response->header();
$ExceptionRenderer->controller->response = $this->getMock('CakeResponse', array('_sendHeader'));
$ExceptionRenderer->controller->response->header($headers);
$ExceptionRenderer->controller->response->expects($this->at(1))->method('_sendHeader')->with('Allow', 'POST, DELETE');
ob_start();
$ExceptionRenderer->render();
ob_get_clean();
}
/**
* testMissingController method
*
@ -512,7 +528,7 @@ class ExceptionRendererTest extends CakeTestCase {
404
),
array(
new PrivateActionException(array('controller' => 'PostsController' , 'action' => '_secretSauce')),
new PrivateActionException(array('controller' => 'PostsController', 'action' => '_secretSauce')),
array(
'/<h2>Private Method in PostsController<\/h2>/',
'/<em>PostsController::<\/em><em>_secretSauce\(\)<\/em>/'
@ -746,7 +762,74 @@ class ExceptionRendererTest extends CakeTestCase {
$ExceptionRenderer->render();
$this->assertEquals('', $ExceptionRenderer->controller->layoutPath);
$this->assertEquals('', $ExceptionRenderer->controller->subDir);
$this->assertEquals('Errors/', $ExceptionRenderer->controller->viewPath);
$this->assertEquals('Errors', $ExceptionRenderer->controller->viewPath);
}
/**
* Test that missing plugin disables Controller::$plugin if the two are the same plugin.
*
* @return void
*/
public function testMissingPluginRenderSafe() {
$exception = new NotFoundException();
$ExceptionRenderer = new ExceptionRenderer($exception);
$ExceptionRenderer->controller = $this->getMock('Controller', array('render'));
$ExceptionRenderer->controller->plugin = 'TestPlugin';
$ExceptionRenderer->controller->request = $this->getMock('CakeRequest');
$exception = new MissingPluginException(array('plugin' => 'TestPlugin'));
$ExceptionRenderer->controller->expects($this->once())
->method('render')
->with('error400')
->will($this->throwException($exception));
$response = $this->getMock('CakeResponse');
$response->expects($this->once())
->method('body')
->with($this->logicalAnd(
$this->logicalNot($this->stringContains('test plugin error500')),
$this->stringContains('Not Found')
));
$ExceptionRenderer->controller->response = $response;
$ExceptionRenderer->render();
}
/**
* Test that missing plugin doesn't disable Controller::$plugin if the two aren't the same plugin.
*
* @return void
*/
public function testMissingPluginRenderSafeWithPlugin() {
App::build(array(
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
), App::RESET);
CakePlugin::load('TestPlugin');
$exception = new NotFoundException();
$ExceptionRenderer = new ExceptionRenderer($exception);
$ExceptionRenderer->controller = $this->getMock('Controller', array('render'));
$ExceptionRenderer->controller->plugin = 'TestPlugin';
$ExceptionRenderer->controller->request = $this->getMock('CakeRequest');
$exception = new MissingPluginException(array('plugin' => 'TestPluginTwo'));
$ExceptionRenderer->controller->expects($this->once())
->method('render')
->with('error400')
->will($this->throwException($exception));
$response = $this->getMock('CakeResponse');
$response->expects($this->once())
->method('body')
->with($this->logicalAnd(
$this->stringContains('test plugin error500'),
$this->stringContains('Not Found')
));
$ExceptionRenderer->controller->response = $response;
$ExceptionRenderer->render();
CakePlugin::unload();
}
/**
@ -792,7 +875,33 @@ class ExceptionRendererTest extends CakeTestCase {
$this->assertContains('<h2>Database Error</h2>', $result);
$this->assertContains('There was an error in the SQL query', $result);
$this->assertContains('SELECT * from poo_query < 5 and :seven', $result);
$this->assertContains(h('SELECT * from poo_query < 5 and :seven'), $result);
$this->assertContains("'seven' => (int) 7", $result);
}
/**
* Test that rendering exceptions triggers shutdown events.
*
* @return void
*/
public function testRenderShutdownEvents() {
$fired = array();
$listener = function ($event) use (&$fired) {
$fired[] = $event->name();
};
$EventManager = CakeEventManager::instance();
$EventManager->attach($listener, 'Controller.shutdown');
$EventManager->attach($listener, 'Dispatcher.afterDispatch');
$exception = new Exception('Terrible');
$ExceptionRenderer = new ExceptionRenderer($exception);
ob_start();
$ExceptionRenderer->render();
ob_get_clean();
$expected = array('Controller.shutdown', 'Dispatcher.afterDispatch');
$this->assertEquals($expected, $fired);
}
}