mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing issues rendering repeat errors coming from the rendering of an error page (like a missing helper).
Test added. Fixes #1671
This commit is contained in:
parent
170ba71850
commit
b31f25fb8b
2 changed files with 41 additions and 1 deletions
|
@ -184,7 +184,7 @@ class ExceptionRenderer {
|
|||
$this->controller->set($error->getAttributes());
|
||||
$this->_outputMessage($this->template);
|
||||
} catch (Exception $e) {
|
||||
$this->_outputMessage('error500');
|
||||
$this->_outputMessageSafe('error500');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,4 +235,16 @@ class ExceptionRenderer {
|
|||
$this->controller->afterFilter();
|
||||
$this->controller->response->send();
|
||||
}
|
||||
|
||||
/**
|
||||
* A safer way to render error messages, replaces all helpers, with basics
|
||||
* and doesn't call component methods.
|
||||
*
|
||||
* @param string $template The template to render
|
||||
*/
|
||||
protected function _outputMessageSafe($template) {
|
||||
$this->controller->helpers = array('Form', 'Html', 'Session');
|
||||
$this->controller->render($template);
|
||||
$this->controller->response->send();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -609,4 +609,32 @@ class ExceptionRendererTest extends CakeTestCase {
|
|||
$this->assertPattern($pattern, $result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exceptions being raised when helpers are missing.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testMissingRenderSafe() {
|
||||
$exception = new MissingHelperFileException(array('class' => 'Fail'));
|
||||
$ExceptionRenderer = new ExceptionRenderer($exception);
|
||||
|
||||
$ExceptionRenderer->controller = $this->getMock('Controller');
|
||||
$ExceptionRenderer->controller->helpers = array('Fail', 'Boom');
|
||||
$ExceptionRenderer->controller->request = $this->getMock('CakeRequest');
|
||||
$ExceptionRenderer->controller->expects($this->at(2))
|
||||
->method('render')
|
||||
->with('missingHelperFile')
|
||||
->will($this->throwException($exception));
|
||||
|
||||
$ExceptionRenderer->controller->expects($this->at(3))
|
||||
->method('render')
|
||||
->with('error500')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$ExceptionRenderer->controller->response = $this->getMock('CakeResponse');
|
||||
$ExceptionRenderer->render();
|
||||
sort($ExceptionRenderer->controller->helpers);
|
||||
$this->assertEquals(array('Form', 'Html', 'Session'), $ExceptionRenderer->controller->helpers);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue