mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR Merged from trunk
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@75916 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
60958496fc
commit
897d4f193a
@ -123,8 +123,13 @@ class ModelAsController extends Controller implements NestedController {
|
||||
}
|
||||
|
||||
protected function get404Page() {
|
||||
if($page = DataObject::get_one("ErrorPage", "ErrorCode = '404'")) return $page;
|
||||
else return DataObject::get_one("SiteTree", "URLSegment = '404'");
|
||||
$page = DataObject::get_one("ErrorPage", "\"ErrorCode\" = '404'");
|
||||
if($page) {
|
||||
return $page;
|
||||
} else {
|
||||
// @deprecated 2.5 Use ErrorPage class
|
||||
return DataObject::get_one("SiteTree", "\"URLSegment\" = '404'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,8 +95,8 @@ class ErrorPage extends Page {
|
||||
* @param string $toStage Place to copy to. Must be a stage name.
|
||||
* @param boolean $createNewVersion Set this to true to create a new version number. By default, the existing version number will be copied over.
|
||||
*/
|
||||
function publish($fromStage, $toStage, $createNewVersion = false) {
|
||||
$oldStage = Versioned::current_stage();
|
||||
function doPublish() {
|
||||
parent::doPublish();
|
||||
|
||||
// Run the page
|
||||
$response = Director::test(Director::makeRelative($this->Link()));
|
||||
@ -125,11 +125,6 @@ class ErrorPage extends Page {
|
||||
FormResponse::respond();
|
||||
return;
|
||||
}
|
||||
|
||||
// Restore the version we're currently connected to.
|
||||
Versioned::reading_stage($oldStage);
|
||||
|
||||
return $this->extension_instances['Versioned']->publish($fromStage, $toStage, $createNewVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -173,7 +168,7 @@ class ErrorPage extends Page {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
static function get_static_filepath($path) {
|
||||
static function get_static_filepath() {
|
||||
return self::$static_filepath;
|
||||
}
|
||||
}
|
||||
@ -183,8 +178,14 @@ class ErrorPage extends Page {
|
||||
* @package cms
|
||||
*/
|
||||
class ErrorPage_Controller extends Page_Controller {
|
||||
public function index() {
|
||||
Director::set_status_code($this->failover->ErrorCode ? $this->failover->ErrorCode : 404);
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
$action = $this->request->param('Action');
|
||||
if(!$action || $action == 'index') {
|
||||
Director::set_status_code($this->failover->ErrorCode ? $this->failover->ErrorCode : 404);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -257,7 +257,7 @@ class Debug {
|
||||
} else {
|
||||
$errorFilePath = ErrorPage::get_filepath_for_errorcode($statusCode, Translatable::current_lang());
|
||||
if(file_exists($errorFilePath)) {
|
||||
echo file_get_contents(ASSETS_PATH . "/error-$statusCode.html");
|
||||
echo file_get_contents($errorFilePath);
|
||||
} else {
|
||||
$renderer = new DebugView();
|
||||
$renderer->writeHeader();
|
||||
|
@ -7,24 +7,44 @@ class ErrorPageTest extends FunctionalTest {
|
||||
|
||||
static $fixture_file = 'sapphire/tests/ErrorPageTest.yml';
|
||||
|
||||
protected $orig = array();
|
||||
|
||||
protected $tmpAssetsPath = '';
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->orig['ErrorPage_staticfilepath'] = ErrorPage::get_static_filepath();
|
||||
$this->tmpAssetsPath = sprintf('%s/_tmp_assets_%s', TEMP_FOLDER, rand());
|
||||
Filesystem::makeFolder($this->tmpAssetsPath . '/ErrorPageTest');
|
||||
ErrorPage::set_static_filepath($this->tmpAssetsPath . '/ErrorPageTest');
|
||||
|
||||
$this->orig['Director_environmenttype'] = Director::get_environment_type();
|
||||
Director::set_environment_type('live');
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
parent::tearDown();
|
||||
|
||||
ErrorPage::set_static_filepath($this->orig['ErrorPage_staticfilepath']);
|
||||
Director::set_environment_type($this->orig['Director_environmenttype']);
|
||||
|
||||
Filesystem::removeFolder($this->tmpAssetsPath . '/ErrorPageTest');
|
||||
Filesystem::removeFolder($this->tmpAssetsPath);
|
||||
}
|
||||
|
||||
function test404ErrorPage() {
|
||||
$page = $this->objFromFixture('ErrorPage', '404');
|
||||
|
||||
$response = $this->get($page->URLSegment);
|
||||
// ensure that the errorpage exists as a physical file
|
||||
$page->publish('Stage', 'Live');
|
||||
|
||||
/* A standard error is shown */
|
||||
$this->assertEquals($response->getBody(), 'The requested page couldn\'t be found.', 'A standard error is shown');
|
||||
|
||||
/* When the page is published, an error page with the theme is shown instead */
|
||||
$page->publish('Stage', 'Live', false);
|
||||
$response = $this->get('nonexistent-page');
|
||||
|
||||
$response = $this->get($page->URLSegment);
|
||||
|
||||
/* There is body text from the error page */
|
||||
/* We have body text from the error page */
|
||||
$this->assertNotNull($response->getBody(), 'We have body text from the error page');
|
||||
|
||||
|
||||
/* Status code of the HTTPResponse for error page is "404" */
|
||||
$this->assertEquals($response->getStatusCode(), '404', 'Status cod eof the HTTPResponse for error page is "404"');
|
||||
$this->assertEquals($response->getStatusCode(), '404', 'Status code of the HTTPResponse for error page is "404"');
|
||||
|
||||
/* Status message of the HTTPResponse for error page is "Not Found" */
|
||||
$this->assertEquals($response->getStatusDescription(), 'Not Found', 'Status message of the HTTResponse for error page is "Not found"');
|
||||
|
@ -2,4 +2,5 @@ ErrorPage:
|
||||
404:
|
||||
Title: Page Not Found
|
||||
URLSegment: page-not-found
|
||||
Content: My error page body
|
||||
ErrorCode: 404
|
Loading…
x
Reference in New Issue
Block a user