BUGFIX Fixed empty ErrorPage types in output by setting status code in init() instead of index() and checking for "index" action - introduced in r75096 (see #3960)

BUGIFX Changed ErrorPage->publish() to doPublish->doPublish() - the publication of static HTML into the /assets directory was lagging one version behind the actual published content
BUGFIX Fixed wrong parameter in ErrorPage::get_static_filepath()

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@75915 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-05-04 02:20:57 +00:00
parent e78d6022fe
commit 681380424a
3 changed files with 44 additions and 22 deletions

View File

@ -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()));
@ -126,11 +126,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);
}
/**
@ -174,7 +169,7 @@ class ErrorPage extends Page {
/**
* @return string
*/
static function get_static_filepath($path) {
static function get_static_filepath() {
return self::$static_filepath;
}
}
@ -184,8 +179,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);
}
}
}

View File

@ -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"');

View File

@ -2,4 +2,5 @@ ErrorPage:
404:
Title: Page Not Found
URLSegment: page-not-found
Content: My error page body
ErrorCode: 404