mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR Using BlankPage template in SecurityTest, BasicAuthTest to remove ContentController dependency
MINOR Checking for SiteTree class existence in Security, Translatable MINOR Checking for ContentController existence in FulltextSearchable MINOR Removed unnecessary ContentController tests from ObjectTest MINOR Replaced CMS specific examples in PermissionCheckboxSetFieldTest, DataObjectTest MINOR Changed SecurityTest to make assertions against Security/login rather than relying on redirection from admin/cms
This commit is contained in:
parent
7f06f97761
commit
dc36725869
@ -453,7 +453,7 @@ class Translatable extends DataObjectDecorator implements PermissionProvider {
|
||||
* @deprecated 2.4 Use Object::add_extension('SiteTree', 'Translatable')
|
||||
*/
|
||||
static function enable() {
|
||||
Object::add_extension('SiteTree', 'Translatable');
|
||||
if(class_exists('SiteTree')) Object::add_extension('SiteTree', 'Translatable');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -462,7 +462,7 @@ class Translatable extends DataObjectDecorator implements PermissionProvider {
|
||||
* @deprecated 2.4 Use Object::remove_extension('SiteTree', 'Translatable')
|
||||
*/
|
||||
static function disable() {
|
||||
Object::remove_extension('SiteTree', 'Translatable');
|
||||
if(class_exists('SiteTree')) Object::remove_extension('SiteTree', 'Translatable');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -472,7 +472,11 @@ class Translatable extends DataObjectDecorator implements PermissionProvider {
|
||||
* @return boolean True if enabled
|
||||
*/
|
||||
static function is_enabled() {
|
||||
if(class_exists('SiteTree')){
|
||||
return Object::has_extension('SiteTree', 'Translatable');
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -620,7 +624,7 @@ class Translatable extends DataObjectDecorator implements PermissionProvider {
|
||||
))->column();
|
||||
if(!$idsWithoutLocale) return;
|
||||
|
||||
if($this->owner->class == 'SiteTree') {
|
||||
if(class_exists('SiteTree') && $this->owner->class == 'SiteTree') {
|
||||
foreach(array('Stage', 'Live') as $stage) {
|
||||
foreach($idsWithoutLocale as $id) {
|
||||
$obj = Versioned::get_one_by_stage(
|
||||
@ -779,7 +783,7 @@ class Translatable extends DataObjectDecorator implements PermissionProvider {
|
||||
// Caution: This logic is very sensitve to infinite loops when translation status isn't determined properly
|
||||
// If a parent for the newly written translation was existing before this
|
||||
// onBeforeWrite() call, it will already have been linked correctly through createTranslation()
|
||||
if($this->owner->hasField('ParentID') && $this->owner instanceof SiteTree) {
|
||||
if(class_exists('SiteTree') && $this->owner->hasField('ParentID') && $this->owner instanceof SiteTree) {
|
||||
if(
|
||||
!$this->owner->ID
|
||||
&& $this->owner->ParentID
|
||||
@ -898,6 +902,7 @@ class Translatable extends DataObjectDecorator implements PermissionProvider {
|
||||
* seeing readonly fields as well.
|
||||
*/
|
||||
function updateCMSFields(FieldSet &$fields) {
|
||||
if(!class_exists('SiteTree')) return;
|
||||
// Don't apply these modifications for normal DataObjects - they rely on CMSMain logic
|
||||
if(!($this->owner instanceof SiteTree)) return;
|
||||
|
||||
@ -905,10 +910,12 @@ class Translatable extends DataObjectDecorator implements PermissionProvider {
|
||||
$fields->push(new HiddenField("Locale", "Locale", $this->owner->Locale) );
|
||||
|
||||
// Don't allow translation of virtual pages because of data inconsistencies (see #5000)
|
||||
if(class_exists('VirtualPage')){
|
||||
$excludedPageTypes = array('VirtualPage');
|
||||
foreach($excludedPageTypes as $excludedPageType) {
|
||||
if(is_a($this->owner, $excludedPageType)) return;
|
||||
}
|
||||
}
|
||||
|
||||
$excludeFields = array(
|
||||
'ViewerGroups',
|
||||
@ -1271,7 +1278,7 @@ class Translatable extends DataObjectDecorator implements PermissionProvider {
|
||||
}
|
||||
|
||||
function providePermissions() {
|
||||
if(!Object::has_extension('SiteTree', 'Translatable')) return false;
|
||||
if(!Object::has_extension('SiteTree', 'Translatable') || !class_exists('SiteTree')) return false;
|
||||
|
||||
$locales = self::get_allowed_locales();
|
||||
|
||||
@ -1324,23 +1331,6 @@ class Translatable extends DataObjectDecorator implements PermissionProvider {
|
||||
return $returnMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the RelativeLink value for a home page in another locale. This is found by searching for the default home
|
||||
* page in the default language, then returning the link to the translated version (if one exists).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_homepage_link_by_locale($locale) {
|
||||
$originalLocale = self::get_current_locale();
|
||||
|
||||
self::set_current_locale(self::default_locale());
|
||||
$original = SiteTree::get_by_link(RootURLController::get_default_homepage_link());
|
||||
self::set_current_locale($originalLocale);
|
||||
|
||||
if($original) {
|
||||
if($translation = $original->getTranslation($locale)) return trim($translation->RelativeLink(true), '/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 2.4 Use {@link Translatable::get_homepage_link_by_locale()}
|
||||
|
@ -335,12 +335,13 @@ class Debug {
|
||||
if(Director::is_ajax()) {
|
||||
echo $friendlyErrorMessage;
|
||||
} else {
|
||||
if(class_exists('ErrorPage')){
|
||||
$errorFilePath = ErrorPage::get_filepath_for_errorcode($statusCode, Translatable::get_current_locale());
|
||||
if(file_exists($errorFilePath)) {
|
||||
$content = file_get_contents(ASSETS_PATH . "/error-$statusCode.html");
|
||||
// $BaseURL is left dynamic in error-###.html, so that multi-domain sites don't get broken
|
||||
echo str_replace('$BaseURL', Director::absoluteBaseURL(), $content);
|
||||
|
||||
}
|
||||
} else {
|
||||
$renderer = new DebugView();
|
||||
$renderer->writeHeader();
|
||||
|
@ -52,9 +52,10 @@ class FulltextSearchable extends DataObjectDecorator {
|
||||
}
|
||||
}
|
||||
self::$searchable_classes = $searchableClasses;
|
||||
|
||||
if(class_exists("ContentController")){
|
||||
Object::add_extension("ContentController", "ContentControllerSearchExtension");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Array|String $searchFields Comma-separated list (or array) of database column names
|
||||
|
@ -417,7 +417,7 @@ class Security extends Controller {
|
||||
Session::clear('Security.Message');
|
||||
|
||||
// custom processing
|
||||
return $customisedController->renderWith(array('Security_login', 'Security', $this->stat('template_main'), 'ContentController'));
|
||||
return $customisedController->renderWith(array('Security_login', 'Security', $this->stat('template_main'), 'BlankPage'));
|
||||
}
|
||||
|
||||
function basicauthlogin() {
|
||||
@ -455,7 +455,7 @@ class Security extends Controller {
|
||||
));
|
||||
|
||||
//Controller::$currentController = $controller;
|
||||
return $customisedController->renderWith(array('Security_lostpassword', 'Security', $this->stat('template_main'), 'ContentController'));
|
||||
return $customisedController->renderWith(array('Security_lostpassword', 'Security', $this->stat('template_main'), 'BlankPage'));
|
||||
}
|
||||
|
||||
|
||||
@ -514,7 +514,7 @@ class Security extends Controller {
|
||||
));
|
||||
|
||||
//Controller::$currentController = $controller;
|
||||
return $customisedController->renderWith(array('Security_passwordsent', 'Security', $this->stat('template_main'), 'ContentController'));
|
||||
return $customisedController->renderWith(array('Security_passwordsent', 'Security', $this->stat('template_main'), 'BlankPage'));
|
||||
}
|
||||
|
||||
|
||||
@ -594,7 +594,7 @@ class Security extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
return $customisedController->renderWith(array('Security_changepassword', 'Security', $this->stat('template_main'), 'ContentController'));
|
||||
return $customisedController->renderWith(array('Security_changepassword', 'Security', $this->stat('template_main'), 'BlankPage'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
15
templates/BlankPage.ss
Normal file
15
templates/BlankPage.ss
Normal file
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
|
||||
<title>$Title</title>
|
||||
<% base_tag %>
|
||||
</head>
|
||||
<body class="$CSSClasses">
|
||||
$Content
|
||||
<div class="right">
|
||||
$Form
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -697,22 +697,20 @@ class DataObjectTest extends SapphireTest {
|
||||
}
|
||||
|
||||
function testNewClassInstance() {
|
||||
$page = $this->objFromFixture('Page', 'page1');
|
||||
$changedPage = $page->newClassInstance('RedirectorPage');
|
||||
$changedFields = $changedPage->getChangedFields();
|
||||
$dataObject = $this->objFromFixture('DataObjectTest_TeamComment', 'comment1');
|
||||
$changedDO = $dataObject->newClassInstance('File');
|
||||
$changedFields = $changedDO->getChangedFields();
|
||||
|
||||
// Don't write the record, it will reset changed fields
|
||||
$this->assertType('RedirectorPage', $changedPage);
|
||||
$this->assertEquals($changedPage->ClassName, 'RedirectorPage');
|
||||
$this->assertEquals($changedPage->RedirectionType, 'Internal');
|
||||
//$this->assertEquals($changedPage->RecordClassName, 'RedirectorPage');
|
||||
$this->assertType('File', $changedDO);
|
||||
$this->assertEquals($changedDO->ClassName, 'File');
|
||||
$this->assertContains('ClassName', array_keys($changedFields));
|
||||
$this->assertEquals($changedFields['ClassName']['before'], 'Page');
|
||||
$this->assertEquals($changedFields['ClassName']['after'], 'RedirectorPage');
|
||||
$this->assertEquals($changedFields['ClassName']['before'], 'DataObjectTest_TeamComment');
|
||||
$this->assertEquals($changedFields['ClassName']['after'], 'File');
|
||||
|
||||
$changedPage->write();
|
||||
$this->assertType('RedirectorPage', $changedPage);
|
||||
$this->assertEquals($changedPage->ClassName, 'RedirectorPage');
|
||||
$changedDO->write();
|
||||
$this->assertType('File', $changedDO);
|
||||
$this->assertEquals($changedDO->ClassName, 'File');
|
||||
}
|
||||
|
||||
function testManyManyExtraFields() {
|
||||
|
@ -15,7 +15,7 @@ DataObjectTest_Team:
|
||||
|
||||
DataObjectTest_Player:
|
||||
captain1:
|
||||
FirstName: Captain 1
|
||||
FirstName: Captain
|
||||
FavouriteTeam: =>DataObjectTest_Team.team1
|
||||
Teams: =>DataObjectTest_Team.team1
|
||||
captain2:
|
||||
|
@ -20,7 +20,6 @@ class ObjectTest extends SapphireTest {
|
||||
/* SiteTree should have all of the methods that Versioned has, because Versioned is listed in SiteTree's
|
||||
* extensions */
|
||||
$st = new SiteTree();
|
||||
$cc = new ContentController($st);
|
||||
|
||||
$this->assertTrue($st->hasMethod('publish'), "Test SiteTree has publish");
|
||||
$this->assertTrue($st->hasMethod('migrateVersion'), "Test SiteTree has migrateVersion");
|
||||
@ -29,14 +28,6 @@ class ObjectTest extends SapphireTest {
|
||||
$this->assertTrue($st->hasMethod('PuBliSh'), "Test SiteTree has PuBliSh");
|
||||
$this->assertTrue($st->hasMethod('MiGratEVersIOn'), "Test SiteTree has MiGratEVersIOn");
|
||||
|
||||
/* In a similar manner, all of SiteTree's methods should be available on ContentController, because $failover is set */
|
||||
$this->assertTrue($cc->hasMethod('canView'), "Test ContentController has canView");
|
||||
$this->assertTrue($cc->hasMethod('linkorcurrent'), "Test ContentController has linkorcurrent");
|
||||
|
||||
/* This 'method copying' is transitive, so all of Versioned's methods should be available on ContentControler.
|
||||
* Once again, this is case-insensitive */
|
||||
$this->assertTrue($cc->hasMethod('MiGratEVersIOn'), "Test ContentController has MiGratEVersIOn");
|
||||
|
||||
/* The above examples make use of SiteTree, Versioned and ContentController. Let's test defineMethods() more
|
||||
* directly, with some sample objects */
|
||||
$objs = array();
|
||||
|
@ -318,6 +318,9 @@ class RequestHandlingTest_Controller extends Controller implements TestOnly {
|
||||
$this->httpError(404, 'This page does not exist.');
|
||||
}
|
||||
|
||||
public function getViewer(){
|
||||
return new SSViewer('ContentController');
|
||||
}
|
||||
}
|
||||
|
||||
class RequestHandlingTest_FormActionController extends Controller {
|
||||
@ -369,6 +372,11 @@ class RequestHandlingTest_FormActionController extends Controller {
|
||||
function formactionInAllowedActions($data, $form = null) {
|
||||
return 'formactionInAllowedActions';
|
||||
}
|
||||
|
||||
public function getViewer(){
|
||||
return new SSViewer('ContentController');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -422,6 +422,11 @@ class FormTest_Controller extends Controller implements TestOnly {
|
||||
$form->sessionMessage('Test save was successful', 'good');
|
||||
return $this->redirectBack();
|
||||
}
|
||||
|
||||
function getViewer(){
|
||||
return new SSViewer('ContentController');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class FormTest_ControllerWithSecurityToken extends Controller implements TestOnly {
|
||||
@ -454,6 +459,10 @@ class FormTest_ControllerWithSecurityToken extends Controller implements TestOnl
|
||||
$form->sessionMessage('Test save was successful', 'good');
|
||||
return $this->redirectBack();
|
||||
}
|
||||
|
||||
function getViewer(){
|
||||
return new SSViewer('ContentController');
|
||||
}
|
||||
}
|
||||
|
||||
Director::addRules(50, array(
|
||||
|
@ -107,18 +107,19 @@ class BasicAuthTest extends FunctionalTest {
|
||||
|
||||
}
|
||||
|
||||
class BasicAuthTest_ControllerSecuredWithPermission extends ContentController implements TestOnly {
|
||||
class BasicAuthTest_ControllerSecuredWithPermission extends Controller implements TestOnly {
|
||||
|
||||
static $post_init_called = false;
|
||||
|
||||
static $index_called = false;
|
||||
|
||||
protected $template = '../sapphire/templates/BlankPage.ss';
|
||||
|
||||
function init() {
|
||||
self::$post_init_called = false;
|
||||
self::$index_called = false;
|
||||
|
||||
BasicAuth::protect_entire_site(true, 'MYCODE');
|
||||
|
||||
parent::init();
|
||||
|
||||
self::$post_init_called = true;
|
||||
@ -128,13 +129,16 @@ class BasicAuthTest_ControllerSecuredWithPermission extends ContentController im
|
||||
self::$index_called = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
class BasicAuthTest_ControllerSecuredWithoutPermission extends ContentController implements TestOnly {
|
||||
class BasicAuthTest_ControllerSecuredWithoutPermission extends Controller implements TestOnly {
|
||||
|
||||
protected $template = '../sapphire/templates/BlankPage.ss';
|
||||
|
||||
function init() {
|
||||
BasicAuth::protect_entire_site(true, null);
|
||||
|
||||
parent::init();
|
||||
}
|
||||
|
||||
|
@ -14,14 +14,14 @@ class PermissionCheckboxSetFieldTest extends SapphireTest {
|
||||
'GroupID'
|
||||
);
|
||||
$f->setHiddenPermissions(
|
||||
array('CMS_ACCESS_ReportAdmin')
|
||||
array('NON-ADMIN')
|
||||
);
|
||||
$this->assertEquals(
|
||||
$f->getHiddenPermissions(),
|
||||
array('CMS_ACCESS_ReportAdmin')
|
||||
array('NON-ADMIN')
|
||||
);
|
||||
$this->assertContains('CMS_ACCESS_CMSMain', $f->Field());
|
||||
$this->assertNotContains('CMS_ACCESS_ReportAdmin', $f->Field());
|
||||
$this->assertContains('ADMIN', $f->Field());
|
||||
$this->assertNotContains('NON-ADMIN', $f->Field());
|
||||
}
|
||||
|
||||
function testSaveInto() {
|
||||
@ -53,7 +53,7 @@ class PermissionCheckboxSetFieldTest extends SapphireTest {
|
||||
// add some permissions
|
||||
$field->setValue(array(
|
||||
'ADMIN'=>true,
|
||||
'CMS_ACCESS_AssetAdmin'=>true
|
||||
'NON-ADMIN'=>true
|
||||
));
|
||||
|
||||
$field->saveInto($group);
|
||||
@ -61,7 +61,7 @@ class PermissionCheckboxSetFieldTest extends SapphireTest {
|
||||
$untouchable->flushCache();
|
||||
$this->assertEquals($group->Permissions()->Count(), 2, 'The tested group has two permissions permission');
|
||||
$this->assertEquals($group->Permissions("\"Code\"='ADMIN'")->Count(), 1, 'The tested group has ADMIN permission');
|
||||
$this->assertEquals($group->Permissions("\"Code\"='CMS_ACCESS_AssetAdmin'")->Count(), 1, 'The tested group has CMS_ACCESS_AssetAdmin permission');
|
||||
$this->assertEquals($group->Permissions("\"Code\"='NON-ADMIN'")->Count(), 1, 'The tested group has CMS_ACCESS_AssetAdmin permission');
|
||||
|
||||
$this->assertEquals($untouchable->Permissions()->Count(), 1, 'The other group has one permission');
|
||||
$this->assertEquals($untouchable->Permissions("\"Code\"='ADMIN'")->Count(), 1, 'The other group has ADMIN permission');
|
||||
|
@ -3,8 +3,9 @@ Group:
|
||||
Code: group
|
||||
untouchable:
|
||||
Code: untouchable
|
||||
|
||||
Permission:
|
||||
perm1:
|
||||
Code: ADMIN
|
||||
Group: =>Group.untouchable
|
||||
perm2:
|
||||
Code: NON-ADMIN
|
@ -59,7 +59,7 @@ class SecurityTest extends FunctionalTest {
|
||||
$this->session()->inst_set('loggedInAs', $member->ID);
|
||||
|
||||
/* View the Security/login page */
|
||||
$this->get('Security/login');
|
||||
$response = $this->get('Security/login');
|
||||
|
||||
$items = $this->cssParser()->getBySelector('#MemberLoginForm_LoginForm input.action');
|
||||
|
||||
@ -93,7 +93,7 @@ class SecurityTest extends FunctionalTest {
|
||||
$this->autoFollowRedirection = true;
|
||||
|
||||
/* Attempt to get into the admin section */
|
||||
$response = $this->get('admin/cms/');
|
||||
$response = $this->get('Security/login/');
|
||||
|
||||
$items = $this->cssParser()->getBySelector('#MemberLoginForm_LoginForm input.text');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user