mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
No more skipped tests for ErrorHandler.
Removing missing_model as it was never called.
This commit is contained in:
parent
7fb62e9b7e
commit
99cde14432
3 changed files with 68 additions and 131 deletions
|
@ -139,11 +139,15 @@ class ErrorHandler {
|
|||
* @param array $params Parameters for controller
|
||||
*/
|
||||
public function error404($error) {
|
||||
$message = $error->getMessage();
|
||||
if (Configure::read('debug') == 0) {
|
||||
$message = __('Not Found');
|
||||
}
|
||||
$url = Router::normalize($this->controller->request->here);
|
||||
$this->controller->response->statusCode(404);
|
||||
$this->controller->set(array(
|
||||
'code' => 404,
|
||||
'name' => $error->getMessage(),
|
||||
'name' => $message,
|
||||
'url' => h($url),
|
||||
));
|
||||
$this->_outputMessage('error404');
|
||||
|
@ -155,18 +159,11 @@ class ErrorHandler {
|
|||
* @param array $params Parameters for controller
|
||||
*/
|
||||
public function error500($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
|
||||
if (!isset($url)) {
|
||||
$url = $this->controller->request->here;
|
||||
}
|
||||
$url = Router::normalize($url);
|
||||
$this->controller->header("HTTP/1.0 500 Internal Server Error");
|
||||
$url = Router::normalize($this->controller->request->here);
|
||||
$this->controller->response->statusCode(500);
|
||||
$this->controller->set(array(
|
||||
'code' => '500',
|
||||
'name' => __('An Internal Error Has Occurred'),
|
||||
'message' => h($url),
|
||||
'base' => $this->controller->request->base
|
||||
));
|
||||
$this->_outputMessage('error500');
|
||||
}
|
||||
|
@ -175,14 +172,11 @@ class ErrorHandler {
|
|||
*
|
||||
* @param array $params Parameters for controller
|
||||
*/
|
||||
public function missingController($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
|
||||
$controllerName = str_replace('Controller', '', $className);
|
||||
public function missingController($error) {
|
||||
$controllerName = str_replace('Controller', '', $error->getMessage());
|
||||
$this->controller->set(array(
|
||||
'controller' => $className,
|
||||
'controllerName' => $controllerName,
|
||||
'title' => __('Missing Controller')
|
||||
'controller' => $error->getMessage(),
|
||||
'controllerName' => $controllerName
|
||||
));
|
||||
$this->_outputMessage('missingController');
|
||||
}
|
||||
|
@ -371,21 +365,6 @@ class ErrorHandler {
|
|||
$this->_outputMessage('missingComponentClass');
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Missing Model class web page.
|
||||
*
|
||||
* @param unknown_type $params Parameters for controller
|
||||
*/
|
||||
public function missingModel($params) {
|
||||
extract($params, EXTR_OVERWRITE);
|
||||
|
||||
$this->controller->set(array(
|
||||
'model' => $className,
|
||||
'title' => __('Missing Model')
|
||||
));
|
||||
$this->_outputMessage('missingModel');
|
||||
}
|
||||
|
||||
/**
|
||||
* Output message
|
||||
*
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<h2><?php echo __('Missing Model'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php echo __('Error'); ?>: </strong>
|
||||
<?php printf(__('<em>%s</em> could not be found.'), $model); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php echo __('Error'); ?>: </strong>
|
||||
<?php printf(__('Create the class %s in file: %s'), '<em>' . $model . '</em>', APP_DIR . DS . 'models' . DS . Inflector::underscore($model) . '.php'); ?>
|
||||
</p>
|
||||
<pre>
|
||||
<?php
|
||||
class <?php echo $model;?> extends AppModel {
|
||||
|
||||
public $name = '<?php echo $model;?>';
|
||||
|
||||
}
|
||||
?>
|
||||
</pre>
|
||||
<p class="notice">
|
||||
<strong><?php echo __('Notice'); ?>: </strong>
|
||||
<?php printf(__('If you want to customize this error message, create %s'), APP_DIR . DS . 'views' . DS . 'errors' . DS . 'missing_model.ctp'); ?>
|
||||
</p>
|
|
@ -188,25 +188,13 @@ class MyCustomErrorHandler extends ErrorHandler {
|
|||
echo 'widget thing is missing';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TestErrorHandler class
|
||||
* Exception class for testing app error handlers and custom errors.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs
|
||||
* @package cake.test.cases.libs
|
||||
*/
|
||||
class TestErrorHandler extends ErrorHandler {
|
||||
class MissingWidgetThingException extends Error404Exception { }
|
||||
|
||||
/**
|
||||
* stop method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function _stop() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ErrorHandlerTest class
|
||||
|
@ -257,34 +245,60 @@ class ErrorHandlerTest extends CakeTestCase {
|
|||
|
||||
/**
|
||||
* test that methods declared in an ErrorHandler subclass are not converted
|
||||
* into error404 when debug == 0
|
||||
* into error404 when debug > 0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testSubclassMethodsNotBeingConvertedToError() {
|
||||
$this->markTestIncomplete('Not implemented now');
|
||||
$back = Configure::read('debug');
|
||||
Configure::write('debug', 2);
|
||||
|
||||
$exception = new MissingWidgetThingException('Widget not found');
|
||||
$ErrorHandler = new MyCustomErrorHandler($exception);
|
||||
|
||||
ob_start();
|
||||
$ErrorHandler = new MyCustomErrorHandler('missingWidgetThing', array('message' => 'doh!'));
|
||||
$ErrorHandler->render();
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEqual($result, 'widget thing is missing');
|
||||
}
|
||||
|
||||
/**
|
||||
* test that subclass methods are not converted when debug = 0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testSubclassMethodsNotBeingConvertedDebug0() {
|
||||
Configure::write('debug', 0);
|
||||
ob_start();
|
||||
$ErrorHandler = new MyCustomErrorHandler('missingWidgetThing', array('message' => 'doh!'));
|
||||
$result = ob_get_clean();
|
||||
$this->assertEqual($result, 'widget thing is missing', 'Method declared in subclass converted to error404. %s');
|
||||
$exception = new MissingWidgetThingException('Widget not found');
|
||||
$ErrorHandler = new MyCustomErrorHandler($exception);
|
||||
|
||||
$this->assertEqual('missingWidgetThing', $ErrorHandler->method);
|
||||
|
||||
Configure::write('debug', 0);
|
||||
ob_start();
|
||||
$ErrorHandler = new MyCustomErrorHandler('missingController', array(
|
||||
'className' => 'Missing', 'message' => 'Page not found'
|
||||
));
|
||||
$ErrorHandler->render();
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEqual($result, 'widget thing is missing', 'Method declared in subclass converted to error404');
|
||||
}
|
||||
|
||||
/**
|
||||
* test that ErrorHandler subclasses properly convert framework errors.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testSubclassConvertingFrameworkErrors() {
|
||||
Configure::write('debug', 0);
|
||||
|
||||
$exception = new MissingControllerException('PostsController');
|
||||
$ErrorHandler = new MyCustomErrorHandler($exception);
|
||||
|
||||
$this->assertEqual('error404', $ErrorHandler->method);
|
||||
|
||||
ob_start();
|
||||
$ErrorHandler->render();
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertPattern('/Not Found/', $result, 'Method declared in error handler not converted to error404. %s');
|
||||
|
||||
Configure::write('debug', $back);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -349,6 +363,8 @@ class ErrorHandlerTest extends CakeTestCase {
|
|||
|
||||
$exception = new Error404Exception('Custom message');
|
||||
$ErrorHandler = new ErrorHandler($exception);
|
||||
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode'));
|
||||
$ErrorHandler->controller->response->expects($this->once())->method('statusCode')->with(404);
|
||||
|
||||
ob_start();
|
||||
$ErrorHandler->render();
|
||||
|
@ -388,21 +404,16 @@ class ErrorHandlerTest extends CakeTestCase {
|
|||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testError500() {
|
||||
$this->markTestIncomplete('Not implemented now');
|
||||
ob_start();
|
||||
$ErrorHandler = new ErrorHandler('error500', array(
|
||||
'message' => 'An Internal Error Has Occurred'
|
||||
));
|
||||
$result = ob_get_clean();
|
||||
$this->assertPattern('/<h2>An Internal Error Has Occurred<\/h2>/', $result);
|
||||
function testError500Message() {
|
||||
$exception = new Error500Exception('An Internal Error Has Occurred');
|
||||
$ErrorHandler = new ErrorHandler($exception);
|
||||
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode'));
|
||||
$ErrorHandler->controller->response->expects($this->once())->method('statusCode')->with(500);
|
||||
|
||||
ob_start();
|
||||
$ErrorHandler = new ErrorHandler('error500', array(
|
||||
'message' => 'An Internal Error Has Occurred',
|
||||
'code' => '500'
|
||||
));
|
||||
$ErrorHandler->render();
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertPattern('/<h2>An Internal Error Has Occurred<\/h2>/', $result);
|
||||
}
|
||||
|
||||
|
@ -413,12 +424,15 @@ class ErrorHandlerTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testMissingController() {
|
||||
$this->markTestIncomplete('Not implemented now');
|
||||
$this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController');
|
||||
|
||||
$exception = new MissingControllerException('PostsController');
|
||||
$ErrorHandler = new ErrorHandler($exception);
|
||||
|
||||
ob_start();
|
||||
$ErrorHandler = new ErrorHandler('missingController', array('className' => 'PostsController'));
|
||||
$ErrorHandler->render();
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertPattern('/<h2>Missing Controller<\/h2>/', $result);
|
||||
$this->assertPattern('/<em>PostsController<\/em>/', $result);
|
||||
$this->assertPattern('/BlueberryComponent/', $result);
|
||||
|
@ -674,19 +688,4 @@ class ErrorHandlerTest extends CakeTestCase {
|
|||
$this->assertPattern('/(\/|\\\)sidebox.php/', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testMissingModel method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testMissingModel() {
|
||||
$this->markTestIncomplete('Not implemented now');
|
||||
ob_start();
|
||||
$ErrorHandler = new ErrorHandler('missingModel', array('className' => 'Article', 'file' => 'article.php'));
|
||||
$result = ob_get_clean();
|
||||
$this->assertPattern('/<h2>Missing Model<\/h2>/', $result);
|
||||
$this->assertPattern('/<em>Article<\/em> could not be found./', $result);
|
||||
$this->assertPattern('/(\/|\\\)article.php/', $result);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue