From 99cde14432c730ef63a90ccffc5958f709c2fd11 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 29 Aug 2010 13:49:10 -0400 Subject: [PATCH] No more skipped tests for ErrorHandler. Removing missing_model as it was never called. --- cake/libs/error_handler.php | 43 ++----- cake/libs/view/errors/missing_model.ctp | 41 ------- cake/tests/cases/libs/error_handler.test.php | 115 +++++++++---------- 3 files changed, 68 insertions(+), 131 deletions(-) delete mode 100644 cake/libs/view/errors/missing_model.ctp diff --git a/cake/libs/error_handler.php b/cake/libs/error_handler.php index fa772e7e4..1d0502ee1 100644 --- a/cake/libs/error_handler.php +++ b/cake/libs/error_handler.php @@ -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 * diff --git a/cake/libs/view/errors/missing_model.ctp b/cake/libs/view/errors/missing_model.ctp deleted file mode 100644 index c3d7baa63..000000000 --- a/cake/libs/view/errors/missing_model.ctp +++ /dev/null @@ -1,41 +0,0 @@ - -

-

- : - %s could not be found.'), $model); ?> -

-

- : - ' . $model . '', APP_DIR . DS . 'models' . DS . Inflector::underscore($model) . '.php'); ?> -

-
-<?php
-class  extends AppModel {
-
-	public $name = '';
-
-}
-?>
-
-

- : - -

\ No newline at end of file diff --git a/cake/tests/cases/libs/error_handler.test.php b/cake/tests/cases/libs/error_handler.test.php index e8681eb66..e7ebf9af1 100644 --- a/cake/tests/cases/libs/error_handler.test.php +++ b/cake/tests/cases/libs/error_handler.test.php @@ -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('/

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('/

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('/

Missing Controller<\/h2>/', $result); $this->assertPattern('/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('/

Missing Model<\/h2>/', $result); - $this->assertPattern('/Article<\/em> could not be found./', $result); - $this->assertPattern('/(\/|\\\)article.php/', $result); - } }