Updating ErrorHandler and CakeErrorController to use CakeRequest. Tests updated.

This commit is contained in:
mark_story 2010-05-29 00:21:02 -04:00
parent 3e3265aa7c
commit 7e6773c60c
2 changed files with 20 additions and 9 deletions

View file

@ -48,7 +48,7 @@ class CakeErrorController extends AppController {
function __construct() {
parent::__construct();
$this->_set(Router::getPaths());
$this->params = Router::getParams();
$this->request = $this->params = Router::getRequest();
$this->constructClasses();
$this->Component->initialize($this);
$this->_set(array('cacheAction' => false, 'viewPath' => 'errors'));
@ -87,9 +87,9 @@ class ErrorHandler extends Object {
if ($__previousError != array($method, $messages)) {
$__previousError = array($method, $messages);
$this->controller =& new CakeErrorController();
$this->controller = new CakeErrorController();
} else {
$this->controller =& new Controller();
$this->controller = new Controller();
$this->controller->viewPath = 'errors';
}
$options = array('escape' => false);
@ -158,7 +158,7 @@ class ErrorHandler extends Object {
'code' => '404',
'name' => __('Not Found'),
'message' => h($url),
'base' => $this->controller->base
'base' => $this->controller->request->base
));
$this->_outputMessage('error404');
}
@ -172,7 +172,7 @@ class ErrorHandler extends Object {
extract($params, EXTR_OVERWRITE);
if (!isset($url)) {
$url = $this->controller->here;
$url = $this->controller->request->here;
}
$url = Router::normalize($url);
$this->controller->header("HTTP/1.0 500 Internal Server Error");
@ -180,7 +180,7 @@ class ErrorHandler extends Object {
'code' => '500',
'name' => __('An Internal Error Has Occurred'),
'message' => h($url),
'base' => $this->controller->base
'base' => $this->controller->request->base
));
$this->_outputMessage('error500');
}

View file

@ -269,6 +269,17 @@ class ErrorHandlerTest extends CakeTestCase {
$this->skipIf(PHP_SAPI === 'cli', '%s Cannot be run from console');
}
/**
* setup create a request object to get out of router later.
*
* @return void
*/
function setUp() {
$request = new CakeRequest(null, false);
$request->base = '';
Router::setRequestInfo($request);
}
/**
* test that methods declared in an ErrorHandler subclass are not converted
* into error404 when debug == 0
@ -279,19 +290,19 @@ class ErrorHandlerTest extends CakeTestCase {
$back = Configure::read('debug');
Configure::write('debug', 2);
ob_start();
$ErrorHandler =& new MyCustomErrorHandler('missingWidgetThing', array('message' => 'doh!'));
$ErrorHandler = new MyCustomErrorHandler('missingWidgetThing', array('message' => 'doh!'));
$result = ob_get_clean();
$this->assertEqual($result, 'widget thing is missing');
Configure::write('debug', 0);
ob_start();
$ErrorHandler =& new MyCustomErrorHandler('missingWidgetThing', array('message' => 'doh!'));
$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');
Configure::write('debug', 0);
ob_start();
$ErrorHandler =& new MyCustomErrorHandler('missingController', array(
$ErrorHandler = new MyCustomErrorHandler('missingController', array(
'className' => 'Missing', 'message' => 'Page not found'
));
$result = ob_get_clean();