diff --git a/libraries/cms/error/page.php b/libraries/cms/error/page.php index 4f1488786b4a2..5f46a07b7d7d8 100644 --- a/libraries/cms/error/page.php +++ b/libraries/cms/error/page.php @@ -35,11 +35,9 @@ public static function render(Exception $error) if (!$document) { // We're probably in an CLI environment - exit($error->getMessage()); + jexit($error->getMessage()); } - $config = JFactory::getConfig(); - // Get the current template from the application $template = $app->getTemplate(); @@ -52,26 +50,28 @@ public static function render(Exception $error) } $document->setTitle(JText::_('Error') . ': ' . $error->getCode()); + $data = $document->render( false, - array('template' => $template, - 'directory' => JPATH_THEMES, - 'debug' => $config->get('debug')) + array( + 'template' => $template, + 'directory' => JPATH_THEMES, + 'debug' => JDEBUG + ) ); - // Failsafe to get the error displayed. + // Do not allow cache + $app->allowCache(false); + + // If nothing was rendered, just use the message from the Exception if (empty($data)) { - exit($error->getMessage()); + $data = $error->getMessage(); } - else - { - // Do not allow cache - $app->allowCache(false); - $app->setBody($data); - echo $app->toString(); - } + $app->setBody($data); + + echo $app->toString(); } catch (Exception $e) { @@ -81,7 +81,7 @@ public static function render(Exception $error) header('HTTP/1.1 500 Internal Server Error'); } - exit('Error displaying the error page: ' . $e->getMessage() . ': ' . $error->getMessage()); + jexit('Error displaying the error page: ' . $e->getMessage() . ': ' . $error->getMessage()); } } } diff --git a/tests/unit/suites/libraries/cms/error/JErrorPageTest.php b/tests/unit/suites/libraries/cms/error/JErrorPageTest.php new file mode 100644 index 0000000000000..3edf72d9c6432 --- /dev/null +++ b/tests/unit/suites/libraries/cms/error/JErrorPageTest.php @@ -0,0 +1,55 @@ +saveFactoryState(); + + JFactory::$application = $this->getMockCmsApp(); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + $this->restoreFactoryState(); + + parent::tearDown(); + } + + /** + * @covers JErrorPage::render + */ + public function testEnsureTheErrorPageIsCorrectlyRendered() + { + // Create an Exception to inject into the method + $exception = new RuntimeException('Testing JErrorPage::render()', 500); + + // The render method echoes the output, so catch it in a buffer + ob_start(); + JErrorPage::render($exception); + $output = ob_get_clean(); + + // Validate the element was set correctly + $this->assertContains('<title>500 - Testing JErrorPage::render()', $output); + } +}