Merge pull request #1007 from tractorcow/pulls/3.1-security-errorpage

API Error page support for Security controller errors
This commit is contained in:
Hamish Friedlander 2014-05-06 11:44:22 +12:00
commit 435a5ee843
3 changed files with 34 additions and 2 deletions

View File

@ -1,3 +1,6 @@
LeftAndMain: LeftAndMain:
extensions: extensions:
- LeftAndMainPageIconsExtension - LeftAndMainPageIconsExtension
Security:
extensions:
- ErrorPageControllerExtension

View File

@ -0,0 +1,17 @@
<?php
/**
* Enhances error handling for a controller with ErrorPage generated output
*
* @package cms
* @subpackage controller
*/
class ErrorPageControllerExtension extends Extension {
public function onBeforeHTTPError($statusCode, $request) {
$response = ErrorPage::response_for($statusCode);
if($response) {
throw new SS_HTTPResponse_Exception($response, $statusCode);
}
}
}

View File

@ -70,4 +70,16 @@ class ErrorPageTest extends FunctionalTest {
$this->assertEquals($response->getStatusCode(), '403'); $this->assertEquals($response->getStatusCode(), '403');
$this->assertNotNull($response->getBody(), 'We have body text from the error page'); $this->assertNotNull($response->getBody(), 'We have body text from the error page');
} }
public function testSecurityError() {
// Generate 404 page
$page = $this->objFromFixture('ErrorPage', '404');
$page->publish('Stage', 'Live');
// Test invalid action
$response = $this->get('Security/nosuchaction');
$this->assertEquals($response->getStatusCode(), '404');
$this->assertNotNull($response->getBody());
$this->assertContains('text/html', $response->getHeader('Content-Type'));
}
} }