Skip to content

Commit

Permalink
Updating ErrorHandler and CakeErrorController to use CakeRequest. Tes…
Browse files Browse the repository at this point in the history
…ts updated.
  • Loading branch information
markstory committed May 29, 2010
1 parent 3e3265a commit 7e6773c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
12 changes: 6 additions & 6 deletions cake/libs/error.php
Expand Up @@ -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'));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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');
}
Expand All @@ -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');
}
Expand Down
17 changes: 14 additions & 3 deletions cake/tests/cases/libs/error.test.php
Expand Up @@ -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
Expand All @@ -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();
Expand Down

0 comments on commit 7e6773c

Please sign in to comment.