Skip to content
Permalink
Browse files

No more skipped tests for ErrorHandler.

Removing missing_model as it was never called.
  • Loading branch information...
markstory committed Aug 29, 2010
1 parent 7fb62e9 commit 99cde14432c730ef63a90ccffc5958f709c2fd11
Showing with 65 additions and 128 deletions.
  1. +11 −32 cake/libs/error_handler.php
  2. +0 −41 cake/libs/view/errors/missing_model.ctp
  3. +54 −55 cake/tests/cases/libs/error_handler.test.php
@@ -139,11 +139,15 @@ public function error(Exception $error) {
* @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 @@ public function error404($error) {
* @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 @@ public function error500($params) {
*
* @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 @@ public function missingComponentClass($error) {
$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
*

This file was deleted.

Oops, something went wrong.
@@ -188,25 +188,13 @@ function missingWidgetThing() {
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 @@ function testHandleException() {
/**
* 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);
$exception = new MissingWidgetThingException('Widget not found');
$ErrorHandler = new MyCustomErrorHandler($exception);
$this->assertEqual('missingWidgetThing', $ErrorHandler->method);
ob_start();
$ErrorHandler = new MyCustomErrorHandler('missingWidgetThing', array('message' => 'doh!'));
$ErrorHandler->render();
$result = ob_get_clean();
$this->assertEqual($result, 'widget thing is missing', 'Method declared in subclass converted to error404. %s');
$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 = new MyCustomErrorHandler('missingController', array(
'className' => 'Missing', 'message' => 'Page not found'
));
$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);
$this->assertPattern('/Not Found/', $result, 'Method declared in error handler not converted to error404. %s');
}
/**
@@ -349,6 +363,8 @@ function testError404() {
$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 @@ function testError404NoInjection() {
* @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 @@ function testError500() {
* @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 @@ function testMissingComponentClass() {
$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);
}
}

0 comments on commit 99cde14

Please sign in to comment.
You can’t perform that action at this time.