2011-03-18 04:33:47 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @package cms
|
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class ErrorPageTest extends FunctionalTest {
|
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
protected static $fixture_file = 'ErrorPageTest.yml';
|
2011-03-18 04:33:47 +01:00
|
|
|
|
|
|
|
protected $orig = array();
|
|
|
|
|
|
|
|
protected $tmpAssetsPath = '';
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function setUp() {
|
2011-03-18 04:33:47 +01:00
|
|
|
parent::setUp();
|
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
$this->orig['ErrorPage_staticfilepath'] = ErrorPage::config()->static_filepath;
|
2011-03-18 04:33:47 +01:00
|
|
|
$this->tmpAssetsPath = sprintf('%s/_tmp_assets_%s', TEMP_FOLDER, rand());
|
|
|
|
Filesystem::makeFolder($this->tmpAssetsPath . '/ErrorPageTest');
|
2013-03-18 11:47:15 +01:00
|
|
|
ErrorPage::config()->static_filepath = $this->tmpAssetsPath . '/ErrorPageTest';
|
2013-06-19 13:17:22 +02:00
|
|
|
|
|
|
|
$this->origEnvType = Config::inst()->get('Director', 'environment_type');
|
2013-03-18 11:47:15 +01:00
|
|
|
Config::inst()->update('Director', 'environment_type', 'live');
|
2011-03-18 04:33:47 +01:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function tearDown() {
|
2011-03-18 04:33:47 +01:00
|
|
|
parent::tearDown();
|
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
ErrorPage::config()->static_filepath = $this->orig['ErrorPage_staticfilepath'];
|
2011-03-18 04:33:47 +01:00
|
|
|
|
|
|
|
Filesystem::removeFolder($this->tmpAssetsPath . '/ErrorPageTest');
|
|
|
|
Filesystem::removeFolder($this->tmpAssetsPath);
|
2013-06-19 13:17:22 +02:00
|
|
|
|
|
|
|
Config::inst()->update('Director', 'environment_type', $this->origEnvType);
|
2011-03-18 04:33:47 +01:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function test404ErrorPage() {
|
2011-03-18 04:33:47 +01:00
|
|
|
$page = $this->objFromFixture('ErrorPage', '404');
|
|
|
|
// ensure that the errorpage exists as a physical file
|
|
|
|
$page->publish('Stage', 'Live');
|
|
|
|
|
|
|
|
$response = $this->get('nonexistent-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 SS_HTTPResponse for error page is "404" */
|
|
|
|
$this->assertEquals($response->getStatusCode(), '404', 'Status code of the SS_HTTPResponse for error page is "404"');
|
|
|
|
|
|
|
|
/* Status message of the SS_HTTPResponse for error page is "Not Found" */
|
|
|
|
$this->assertEquals($response->getStatusDescription(), 'Not Found', 'Status message of the HTTResponse for error page is "Not found"');
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testBehaviourOfShowInMenuAndShowInSearchFlags() {
|
2011-03-18 04:33:47 +01:00
|
|
|
$page = $this->objFromFixture('ErrorPage', '404');
|
|
|
|
|
|
|
|
/* Don't show the error page in the menus */
|
|
|
|
$this->assertEquals($page->ShowInMenus, 0, 'Don\'t show the error page in the menus');
|
|
|
|
|
|
|
|
/* Don't show the error page in the search */
|
|
|
|
$this->assertEquals($page->ShowInSearch, 0, 'Don\'t show the error page in search');
|
|
|
|
}
|
2013-11-18 04:32:15 +01:00
|
|
|
|
|
|
|
public function testBehaviourOf403() {
|
|
|
|
$page = $this->objFromFixture('ErrorPage', '403');
|
|
|
|
$page->publish('Stage', 'Live');
|
|
|
|
|
|
|
|
$response = $this->get($page->Link());
|
|
|
|
|
|
|
|
$this->assertEquals($response->getStatusCode(), '403');
|
|
|
|
$this->assertNotNull($response->getBody(), 'We have body text from the error page');
|
|
|
|
}
|
|
|
|
}
|