From a5b33ab91660e88f23d4a43f60e917bc53d8e000 Mon Sep 17 00:00:00 2001 From: Nathan Date: Thu, 20 Oct 2016 15:35:09 +1100 Subject: [PATCH] Correcting an issue where page controller methods would end up with the error page response code, causing them to not work. This code only looks to be causing issues from what I can see. An example is an autocomplete that is populated using a method on page controller. The moment you end up on a 404 error page, the autocomplete will attempt to populate and end up with a 404 response. --- code/model/ErrorPage.php | 17 ----------------- tests/model/ErrorPageTest.php | 18 ++++++++++++------ 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/code/model/ErrorPage.php b/code/model/ErrorPage.php index 4307b78d..1e6ec59b 100644 --- a/code/model/ErrorPage.php +++ b/code/model/ErrorPage.php @@ -323,22 +323,5 @@ class ErrorPage extends Page { * @package cms */ class ErrorPage_Controller extends Page_Controller { - - /** - * Overload the provided {@link Controller::handleRequest()} to append the - * correct status code post request since otherwise permission related error - * pages such as 401 and 403 pages won't be rendered due to - * {@link SS_HTTPResponse::isFinished() ignoring the response body. - * - * @param SS_HTTPRequest $request - * @param DataModel $model - * @return SS_HTTPResponse - */ - public function handleRequest(SS_HTTPRequest $request, DataModel $model = NULL) { - $body = parent::handleRequest($request, $model); - $this->getResponse()->setStatusCode($this->ErrorCode); - - return $this->getResponse(); - } } diff --git a/tests/model/ErrorPageTest.php b/tests/model/ErrorPageTest.php index c2adc7ca..5d4b5f95 100644 --- a/tests/model/ErrorPageTest.php +++ b/tests/model/ErrorPageTest.php @@ -64,13 +64,19 @@ class ErrorPageTest extends FunctionalTest { public function testBehaviourOf403() { $page = $this->objFromFixture('ErrorPage', '403'); $page->publish('Stage', 'Live'); - - $response = $this->get($page->RelativeLink()); - - $this->assertEquals($response->getStatusCode(), '403'); - $this->assertNotNull($response->getBody(), 'We have body text from the error page'); + + try { + $controller = singleton('ContentController'); + $controller->httpError(403); + $this->fail('Expected exception to be thrown'); + } + catch(SS_HTTPResponse_Exception $e) { + $response = $e->getResponse(); + $this->assertEquals($response->getStatusCode(), '403'); + $this->assertNotNull($response->getBody(), 'We have body text from the error page'); + } } - + public function testSecurityError() { // Generate 404 page $page = $this->objFromFixture('ErrorPage', '404');