Skip to content

Commit

Permalink
MINOR Merged from trunk
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@75916 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information
chillu authored and Sam Minnee committed Feb 2, 2011
1 parent 6095849 commit 897d4f1
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 25 deletions.
9 changes: 7 additions & 2 deletions core/control/ModelAsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,13 @@ protected function findOldPage($urlSegment) {
}

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

Expand Down
21 changes: 11 additions & 10 deletions core/model/ErrorPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ function getCMSFields() {
* @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()));
Expand Down Expand Up @@ -125,11 +125,6 @@ function publish($fromStage, $toStage, $createNewVersion = false) {
FormResponse::respond();
return;
}

// Restore the version we're currently connected to.
Versioned::reading_stage($oldStage);

return $this->extension_instances['Versioned']->publish($fromStage, $toStage, $createNewVersion);
}

/**
Expand Down Expand Up @@ -173,7 +168,7 @@ static function set_static_filepath($path) {
/**
* @return string
*/
static function get_static_filepath($path) {
static function get_static_filepath() {
return self::$static_filepath;
}
}
Expand All @@ -183,8 +178,14 @@ static function get_static_filepath($path) {
* @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);
}

}
}

Expand Down
2 changes: 1 addition & 1 deletion dev/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ static function friendlyError($statusCode = 500, $friendlyErrorMessage = null, $
} 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();
Expand Down
44 changes: 32 additions & 12 deletions tests/ErrorPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"');
Expand Down
1 change: 1 addition & 0 deletions tests/ErrorPageTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ ErrorPage:
404:
Title: Page Not Found
URLSegment: page-not-found
Content: My error page body
ErrorCode: 404

0 comments on commit 897d4f1

Please sign in to comment.