Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MINOR Using BlankPage template in SecurityTest, BasicAuthTest to remo…

…ve 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
  • Loading branch information...
commit dc36725869dc7e261ff0bb7181e17ca7d96138d8 1 parent 7f06f97
Paul Meyrick authored chillu committed
View
44 core/model/Translatable.php
@@ -453,7 +453,7 @@ static function get_langs_by_id($class, $id) {
* @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 @@ static function enable() {
* @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 @@ static function disable() {
* @return boolean True if enabled
*/
static function is_enabled() {
- return Object::has_extension('SiteTree', 'Translatable');
+ if(class_exists('SiteTree')){
+ return Object::has_extension('SiteTree', 'Translatable');
+ }else{
+ return false;
+ }
}
@@ -620,7 +624,7 @@ function requireDefaultRecords() {
))->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 @@ function onBeforeWrite() {
// 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,16 +902,19 @@ public function alternateGetByLink($URLSegment, $parentID) {
* 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;
// used in CMSMain->init() to set language state when reading/writing record
$fields->push(new HiddenField("Locale", "Locale", $this->owner->Locale) );
- // Don't allow translation of virtual pages because of data inconsistencies (see #5000)
- $excludedPageTypes = array('VirtualPage');
- foreach($excludedPageTypes as $excludedPageType) {
- if(is_a($this->owner, $excludedPageType)) return;
+ // 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(
@@ -1271,7 +1278,7 @@ function MetaTags(&$tags) {
}
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 @@ static function get_existing_content_languages($className = 'SiteTree', $where =
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()}
View
13 dev/Debug.php
@@ -335,12 +335,13 @@ static function friendlyError($statusCode = 500, $friendlyErrorMessage = null, $
if(Director::is_ajax()) {
echo $friendlyErrorMessage;
} else {
- $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);
-
+ 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();
View
5 search/FulltextSearchable.php
@@ -52,8 +52,9 @@ static function enable($searchableClasses = array('SiteTree', 'File')) {
}
}
self::$searchable_classes = $searchableClasses;
-
- Object::add_extension("ContentController", "ContentControllerSearchExtension");
+ if(class_exists("ContentController")){
+ Object::add_extension("ContentController", "ContentControllerSearchExtension");
+ }
}
/**
View
8 security/Security.php
@@ -417,7 +417,7 @@ public function login() {
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 @@ public function lostpassword() {
));
//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 @@ public function passwordsent($request) {
));
//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 @@ public function changepassword() {
}
}
- return $customisedController->renderWith(array('Security_changepassword', 'Security', $this->stat('template_main'), 'ContentController'));
+ return $customisedController->renderWith(array('Security_changepassword', 'Security', $this->stat('template_main'), 'BlankPage'));
}
/**
View
15 templates/BlankPage.ss
@@ -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>
View
22 tests/DataObjectTest.php
@@ -697,22 +697,20 @@ function testPopulateDefaults() {
}
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() {
View
90 tests/DataObjectTest.yml
@@ -1,54 +1,54 @@
Page:
- home:
- Title: Home
- page1:
- Title: First Page
- Content: <p>Some test content</p>
- page2:
- Title: Second Page
+ home:
+ Title: Home
+ page1:
+ Title: First Page
+ Content: <p>Some test content</p>
+ page2:
+ Title: Second Page
DataObjectTest_Team:
- team1:
- Title: Team 1
- team2:
- Title: Team 2
+ team1:
+ Title: Team 1
+ team2:
+ Title: Team 2
DataObjectTest_Player:
- captain1:
- FirstName: Captain 1
- FavouriteTeam: =>DataObjectTest_Team.team1
- Teams: =>DataObjectTest_Team.team1
- captain2:
- FirstName: Captain 2
- Teams: =>DataObjectTest_Team.team2
- player1:
- FirstName: Player 1
- player2:
- FirstName: Player 2
- Teams: =>DataObjectTest_Team.team1,=>DataObjectTest_Team.team2
+ captain1:
+ FirstName: Captain
+ FavouriteTeam: =>DataObjectTest_Team.team1
+ Teams: =>DataObjectTest_Team.team1
+ captain2:
+ FirstName: Captain 2
+ Teams: =>DataObjectTest_Team.team2
+ player1:
+ FirstName: Player 1
+ player2:
+ FirstName: Player 2
+ Teams: =>DataObjectTest_Team.team1,=>DataObjectTest_Team.team2
DataObjectTest_SubTeam:
- subteam1:
- Title: Subteam 1
- SubclassDatabaseField: Subclassed 1
- DecoratedDatabaseField: Decorated 1
- subteam2_with_player_relation:
- Title: Subteam 2
- SubclassDatabaseField: Subclassed 2
- DecoratedHasOneRelationship: =>DataObjectTest_Player.player1
- subteam3_with_empty_fields:
- Title: Subteam 3
+ subteam1:
+ Title: Subteam 1
+ SubclassDatabaseField: Subclassed 1
+ DecoratedDatabaseField: Decorated 1
+ subteam2_with_player_relation:
+ Title: Subteam 2
+ SubclassDatabaseField: Subclassed 2
+ DecoratedHasOneRelationship: =>DataObjectTest_Player.player1
+ subteam3_with_empty_fields:
+ Title: Subteam 3
DataObjectTest_TeamComment:
- comment1:
- Name: Joe
- Comment: This is a team comment by Joe
- Team: =>DataObjectTest_Team.team1
- comment2:
- Name: Bob
- Comment: This is a team comment by Bob
- Team: =>DataObjectTest_Team.team1
- comment3:
- Name: Phil
- Comment: Phil is a unique guy, and comments on team2
- Team: =>DataObjectTest_Team.team2
+ comment1:
+ Name: Joe
+ Comment: This is a team comment by Joe
+ Team: =>DataObjectTest_Team.team1
+ comment2:
+ Name: Bob
+ Comment: This is a team comment by Bob
+ Team: =>DataObjectTest_Team.team1
+ comment3:
+ Name: Phil
+ Comment: Phil is a unique guy, and comments on team2
+ Team: =>DataObjectTest_Team.team2
View
9 tests/ObjectTest.php
@@ -20,7 +20,6 @@ function testHasmethodBehaviour() {
/* 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 @@ function testHasmethodBehaviour() {
$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();
View
10 tests/RequestHandlingTest.php
@@ -317,7 +317,10 @@ public function throwresponseexception() {
public function throwhttperror() {
$this->httpError(404, 'This page does not exist.');
}
-
+
+ public function getViewer(){
+ return new SSViewer('ContentController');
+ }
}
class RequestHandlingTest_FormActionController extends Controller {
@@ -369,6 +372,11 @@ function formaction($data, $form = null) {
function formactionInAllowedActions($data, $form = null) {
return 'formactionInAllowedActions';
}
+
+ public function getViewer(){
+ return new SSViewer('ContentController');
+ }
+
}
/**
View
9 tests/forms/FormTest.php
@@ -422,6 +422,11 @@ function doSubmit($data, $form, $request) {
$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 @@ function doSubmit($data, $form, $request) {
$form->sessionMessage('Test save was successful', 'good');
return $this->redirectBack();
}
+
+ function getViewer(){
+ return new SSViewer('ContentController');
+ }
}
Director::addRules(50, array(
View
18 tests/security/BasicAuthTest.php
@@ -107,34 +107,38 @@ function testBasicAuthEnabledWithoutPermission() {
}
-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;
}
function index() {
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();
}
View
12 tests/security/PermissionCheckboxSetFieldTest.php
@@ -14,14 +14,14 @@ function testHiddenPermissions() {
'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 @@ function testSaveInto() {
// add some permissions
$field->setValue(array(
'ADMIN'=>true,
- 'CMS_ACCESS_AssetAdmin'=>true
+ 'NON-ADMIN'=>true
));
$field->saveInto($group);
@@ -61,7 +61,7 @@ function testSaveInto() {
$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');
View
17 tests/security/PermissionCheckboxSetFieldTest.yml
@@ -1,10 +1,11 @@
Group:
- group:
- Code: group
- untouchable:
- Code: untouchable
-
+ group:
+ Code: group
+ untouchable:
+ Code: untouchable
Permission:
- perm1:
- Code: ADMIN
- Group: =>Group.untouchable
+ perm1:
+ Code: ADMIN
+ Group: =>Group.untouchable
+ perm2:
+ Code: NON-ADMIN
View
4 tests/security/SecurityTest.php
@@ -59,7 +59,7 @@ function testLogInAsSomeoneElse() {
$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 @@ function testMemberIDInSessionDoesntExistInDatabaseHasToLogin() {
$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');
Please sign in to comment.
Something went wrong with that request. Please try again.