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:
mark_story 2011-04-25 21:04:50 -04:00
parent 170ba71850
commit b31f25fb8b
2 changed files with 41 additions and 1 deletions

View file

@ -184,7 +184,7 @@ class ExceptionRenderer {
$this->controller->set($error->getAttributes()); $this->controller->set($error->getAttributes());
$this->_outputMessage($this->template); $this->_outputMessage($this->template);
} catch (Exception $e) { } catch (Exception $e) {
$this->_outputMessage('error500'); $this->_outputMessageSafe('error500');
} }
} }
@ -235,4 +235,16 @@ class ExceptionRenderer {
$this->controller->afterFilter(); $this->controller->afterFilter();
$this->controller->response->send(); $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();
}
} }

View file

@ -609,4 +609,32 @@ class ExceptionRendererTest extends CakeTestCase {
$this->assertPattern($pattern, $result); $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);
}
} }