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 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. * @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) { function doPublish() {
$oldStage = Versioned::current_stage(); parent::doPublish();
// Run the page // Run the page
$response = Director::test(Director::makeRelative($this->Link())); $response = Director::test(Director::makeRelative($this->Link()));
@ -126,11 +126,6 @@ class ErrorPage extends Page {
FormResponse::respond(); FormResponse::respond();
return; 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 * @return string
*/ */
static function get_static_filepath($path) { static function get_static_filepath() {
return self::$static_filepath; return self::$static_filepath;
} }
} }
@ -184,9 +179,15 @@ class ErrorPage extends Page {
* @package cms * @package cms
*/ */
class ErrorPage_Controller extends Page_Controller { class ErrorPage_Controller extends Page_Controller {
public function index() { function init() {
parent::init();
$action = $this->request->param('Action');
if(!$action || $action == 'index') {
Director::set_status_code($this->failover->ErrorCode ? $this->failover->ErrorCode : 404); Director::set_status_code($this->failover->ErrorCode ? $this->failover->ErrorCode : 404);
} }
}
} }

View File

@ -7,20 +7,40 @@ class ErrorPageTest extends FunctionalTest {
static $fixture_file = 'sapphire/tests/ErrorPageTest.yml'; 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() { function test404ErrorPage() {
$page = $this->objFromFixture('ErrorPage', '404'); $page = $this->objFromFixture('ErrorPage', '404');
// ensure that the errorpage exists as a physical file
$page->publish('Stage', 'Live');
$response = $this->get($page->URLSegment); $response = $this->get('nonexistent-page');
/* A standard error is shown */ /* We have body text from the error page */
$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($page->URLSegment);
/* There is body text from the error page */
$this->assertNotNull($response->getBody(), '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" */ /* Status code of the HTTPResponse for error page is "404" */

View File

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