Skip to content
Permalink
Browse files

Updating ErrorHandler and CakeErrorController to use CakeRequest. Tes…

…ts updated.
  • Loading branch information...
markstory committed May 29, 2010
1 parent 3e3265a commit 7e6773c60cee0b50b506b7c87ba2214d7ef63c3f
Showing with 20 additions and 9 deletions.
  1. +6 −6 cake/libs/error.php
  2. +14 −3 cake/tests/cases/libs/error.test.php
@@ -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 @@ function __construct($method, $messages) {
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 @@ public function error404($params) {
'code' => '404',
'name' => __('Not Found'),
'message' => h($url),
'base' => $this->controller->base
'base' => $this->controller->request->base
));
$this->_outputMessage('error404');
}
@@ -172,15 +172,15 @@ public function error500($params) {
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");
$this->controller->set(array(
'code' => '500',
'name' => __('An Internal Error Has Occurred'),
'message' => h($url),
'base' => $this->controller->base
'base' => $this->controller->request->base
));
$this->_outputMessage('error500');
}
@@ -269,6 +269,17 @@ function skip() {
$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 @@ function testSubclassMethodsNotBeingConvertedToError() {
$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();

0 comments on commit 7e6773c

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