mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 09:05:55 +00:00
This commit is contained in:
parent
a9ce309881
commit
1b4c314304
@ -13,7 +13,6 @@ Object::add_extension('LeftAndMain', 'LeftAndMainSubsites');
|
||||
Object::add_extension('LeftAndMain', 'ControllerSubsites');
|
||||
|
||||
Object::add_extension('Group', 'GroupSubsites');
|
||||
Object::add_extension('Member', 'MemberSubsites');
|
||||
Object::add_extension('File', 'FileSubsites');
|
||||
Object::add_extension('ErrorPage', 'ErrorPageSubsite');
|
||||
if (class_exists('SiteConfig')) Object::add_extension('SiteConfig', 'SiteConfigSubsites');
|
||||
|
@ -14,9 +14,7 @@ class ErrorPageSubsite extends DataObjectDecorator {
|
||||
$subdomainPart = "";
|
||||
|
||||
// when there's a controller get it subsite from session
|
||||
if (Controller::curr()) {
|
||||
$subsite = Subsite::currentSubsite(false);
|
||||
}
|
||||
if (Controller::curr()) $subsite = Subsite::currentSubsite(false);
|
||||
// since this function is called from Page class before the controller is created, we have to get subsite from domain instead
|
||||
else {
|
||||
$subsiteID = Subsite::getSubsiteIDForDomain();
|
||||
|
@ -11,9 +11,7 @@ class FileSubsites extends DataObjectDecorator {
|
||||
static $default_root_folders_global = false;
|
||||
|
||||
function extraStatics() {
|
||||
if(!method_exists('DataObjectDecorator', 'load_extra_statics')) {
|
||||
if($this->owner->class != 'File') return null;
|
||||
}
|
||||
if(!method_exists('DataObjectDecorator', 'load_extra_statics') && $this->owner->class != 'File') return null;
|
||||
return array(
|
||||
'has_one' => array(
|
||||
'Subsite' => 'Subsite',
|
||||
|
@ -171,36 +171,6 @@ class GroupSubsites extends DataObjectDecorator implements PermissionProvider {
|
||||
return (bool)array_intersect($accessibleSites, $linkedSites);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a duplicate of this group and save it to another subsite.
|
||||
* The group and permissions will be duplicated, but not the members.
|
||||
* @param $subsiteID int|Subsite The Subsite to copy to, or its ID
|
||||
*/
|
||||
public function duplicateToSubsite($subsiteID = null) {
|
||||
if(is_object($subsiteID)) {
|
||||
$subsite = $subsiteID;
|
||||
$subsiteID = $subsite->ID;
|
||||
} else {
|
||||
$subsite = DataObject::get_by_id('Subsite', $subsiteID);
|
||||
}
|
||||
|
||||
$group = $this->owner->duplicate(false);
|
||||
|
||||
$group->write();
|
||||
|
||||
$subsite->Groups()->add($group->ID);
|
||||
|
||||
// Duplicate permissions
|
||||
$permissions = $this->owner->Permissions();
|
||||
foreach($permissions as $permission) {
|
||||
$newPerm = $permission->duplicate(false);
|
||||
$newPerm->GroupID = $group->ID;
|
||||
$newPerm->write();
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
|
||||
function providePermissions() {
|
||||
return array(
|
||||
'SECURITY_SUBSITE_GROUP' => array(
|
||||
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Extension for the Group object to add subsites support
|
||||
*
|
||||
* @package subsites
|
||||
*/
|
||||
class MemberSubsites extends DataObjectDecorator {
|
||||
|
||||
/* Only allow adding to groups we can edit */
|
||||
public function saveGroups( $groups ) {
|
||||
$groups = explode( ',', $groups ) ;
|
||||
$filtered = array() ;
|
||||
foreach( $groups as $groupID ) {
|
||||
$group = DataObject::get_by_id('Group', $groupID) ;
|
||||
if ( $group && $group->canEdit() ) $filtered[] = $groupID ;
|
||||
}
|
||||
$this->owner->Groups()->setByIDList( $filtered ) ;
|
||||
}
|
||||
|
||||
}
|
@ -64,10 +64,8 @@ class RelatedPageLink extends DataObject {
|
||||
}
|
||||
|
||||
function RelatedPageAdminLink($master = false) {
|
||||
$page = $master ? Dataobject::get_by_id("SiteTree", $this->MasterPageID)
|
||||
: Dataobject::get_by_id("SiteTree", $this->RelatedPageID);
|
||||
$otherPage = $master ? Dataobject::get_by_id("SiteTree", $this->RelatedPageID)
|
||||
: Dataobject::get_by_id("SiteTree", $this->MasterPageID);
|
||||
$page = $master ? Dataobject::get_by_id("SiteTree", $this->MasterPageID) : Dataobject::get_by_id("SiteTree", $this->RelatedPageID);
|
||||
$otherPage = $master ? Dataobject::get_by_id("SiteTree", $this->RelatedPageID) : Dataobject::get_by_id("SiteTree", $this->MasterPageID);
|
||||
if(!$page) return;
|
||||
|
||||
// Use cmsEditlink only when moving between different pages in the same subsite.
|
||||
@ -76,8 +74,7 @@ class RelatedPageLink extends DataObject {
|
||||
}
|
||||
|
||||
function AbsoluteLink($master = false) {
|
||||
$page = $master ? Dataobject::get_by_id("SiteTree", $this->MasterPageID)
|
||||
: Dataobject::get_by_id("SiteTree", $this->RelatedPageID);
|
||||
$page = $master ? Dataobject::get_by_id("SiteTree", $this->MasterPageID) : Dataobject::get_by_id("SiteTree", $this->RelatedPageID);
|
||||
if(!$page) return;
|
||||
|
||||
|
||||
|
@ -19,11 +19,7 @@ class SiteConfigSubsites extends DataObjectDecorator {
|
||||
if(Subsite::$disable_subsite_filter) return;
|
||||
|
||||
// If you're querying by ID, ignore the sub-site - this is a bit ugly...
|
||||
if (!$query->where || (
|
||||
!preg_match('/\.(\'|"|`|)ID(\'|"|`|)( ?)=/', $query->where[0]) &&
|
||||
!preg_match('/\.?(\'|"|`|)SubsiteID(\'|"|`|)( ?)=/', $query->where[0])
|
||||
)) {
|
||||
|
||||
if (!$query->where || (!preg_match('/\.(\'|"|`|)ID(\'|"|`|)( ?)=/', $query->where[0]) && !preg_match('/\.?(\'|"|`|)SubsiteID(\'|"|`|)( ?)=/', $query->where[0]))) {
|
||||
if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID;
|
||||
else $subsiteID = (int)Subsite::currentSubsiteID();
|
||||
|
||||
@ -33,10 +29,8 @@ class SiteConfigSubsites extends DataObjectDecorator {
|
||||
}
|
||||
}
|
||||
|
||||
function augmentBeforeWrite() {
|
||||
if((!is_numeric($this->owner->ID) || !$this->owner->ID) && !$this->owner->SubsiteID) {
|
||||
$this->owner->SubsiteID = Subsite::currentSubsiteID();
|
||||
}
|
||||
function onBeforeWrite() {
|
||||
if((!is_numeric($this->owner->ID) || !$this->owner->ID) && !$this->owner->SubsiteID) $this->owner->SubsiteID = Subsite::currentSubsiteID();
|
||||
}
|
||||
|
||||
/**
|
||||
|
57
tests/FileSubsitesTest.php
Normal file
57
tests/FileSubsitesTest.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
class FileSubsitesTest extends SapphireTest {
|
||||
static $fixture_file = 'subsites/tests/SubsiteTest.yml';
|
||||
|
||||
function testTrivialFeatures() {
|
||||
$this->assertTrue(is_array(singleton('FileSubsites')->extraStatics()));
|
||||
$file = new File();
|
||||
$file->Title = 'FileTitle';
|
||||
$this->assertEquals(' * FileTitle', $file->alternateTreeTitle());
|
||||
$file->SubsiteID = $this->objFromFixture('Subsite', 'domaintest1')->ID;
|
||||
$this->assertEquals('FileTitle', $file->TreeTitle());
|
||||
$this->assertTrue(singleton('Folder')->getCMSFields() instanceof FieldSet);
|
||||
Subsite::changeSubsite(1);
|
||||
$this->assertEquals($file->cacheKeyComponent(), 'subsite-1');
|
||||
}
|
||||
|
||||
function testWritingSubsiteID() {
|
||||
$this->objFromFixture('Member', 'admin')->logIn();
|
||||
|
||||
$subsite = $this->objFromFixture('Subsite', 'domaintest1');
|
||||
FileSubsites::$default_root_folders_global = true;
|
||||
|
||||
Subsite::changeSubsite(0);
|
||||
$file = new File();
|
||||
$file->write();
|
||||
$file->onAfterUpload();
|
||||
$this->assertEquals((int)$file->SubsiteID, 0);
|
||||
|
||||
Subsite::changeSubsite($subsite->ID);
|
||||
$this->assertTrue($file->canEdit());
|
||||
|
||||
$file = new File();
|
||||
$file->write();
|
||||
$this->assertEquals((int)$file->SubsiteID, 0);
|
||||
$this->assertTrue($file->canEdit());
|
||||
|
||||
FileSubsites::$default_root_folders_global = false;
|
||||
|
||||
Subsite::changeSubsite($subsite->ID);
|
||||
$file = new File();
|
||||
$file->write();
|
||||
$this->assertEquals($file->SubsiteID, $subsite->ID);
|
||||
|
||||
// Test inheriting from parent folder
|
||||
$folder = new Folder();
|
||||
$folder->write();
|
||||
$this->assertEquals($folder->SubsiteID, $subsite->ID);
|
||||
FileSubsites::$default_root_folders_global = true;
|
||||
$file = new File();
|
||||
$file->ParentID = $folder->ID;
|
||||
$file->onAfterUpload();
|
||||
$this->assertEquals($folder->SubsiteID, $file->SubsiteID);
|
||||
}
|
||||
|
||||
|
||||
}
|
25
tests/GroupSubsitesTest.php
Normal file
25
tests/GroupSubsitesTest.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
class GroupSubsitesTest extends SapphireTest {
|
||||
static $fixture_file = 'subsites/tests/SubsiteTest.yml';
|
||||
|
||||
protected $requireDefaultRecordsFrom = array('GroupSubsites');
|
||||
|
||||
function testTrivialFeatures() {
|
||||
$this->assertTrue(is_array(singleton('GroupSubsites')->extraStatics()));
|
||||
$this->assertTrue(is_array(singleton('GroupSubsites')->providePermissions()));
|
||||
$this->assertTrue(singleton('Group')->getCMSFields() instanceof FieldSet);
|
||||
}
|
||||
|
||||
function testAlternateTreeTitle() {
|
||||
$group = new Group();
|
||||
$group->Title = 'The A Team';
|
||||
$group->AccessAllSubsites = true;
|
||||
$this->assertEquals($group->TreeTitle(), 'The A Team <i>(global group)</i>');
|
||||
$group->AccessAllSubsites = false;
|
||||
$group->write();
|
||||
$group->Subsites()->add($this->objFromFixture('Subsite', 'domaintest1'));
|
||||
$group->Subsites()->add($this->objFromFixture('Subsite', 'domaintest2'));
|
||||
$this->assertEquals($group->TreeTitle(), 'The A Team <i>(Test 1, Test 2)</i>');
|
||||
}
|
||||
}
|
36
tests/SiteConfigSubsitesTest.php
Normal file
36
tests/SiteConfigSubsitesTest.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
class SiteConfigSubsitesTest extends SapphireTest {
|
||||
static $fixture_file = 'subsites/tests/SubsiteTest.yml';
|
||||
|
||||
function testEachSubsiteHasAUniqueSiteConfig() {
|
||||
$subsite1 = $this->objFromFixture('Subsite', 'domaintest1');
|
||||
$subsite2 = $this->objFromFixture('Subsite', 'domaintest2');
|
||||
|
||||
$this->assertTrue(is_array(singleton('SiteConfigSubsites')->extraStatics()));
|
||||
|
||||
Subsite::changeSubsite(0);
|
||||
$sc = SiteConfig::current_site_config();
|
||||
$sc->Title = 'RootSite';
|
||||
$sc->write();
|
||||
|
||||
Subsite::changeSubsite($subsite1->ID);
|
||||
$sc = SiteConfig::current_site_config();
|
||||
$sc->Title = 'Subsite1';
|
||||
$sc->write();
|
||||
|
||||
Subsite::changeSubsite($subsite2->ID);
|
||||
$sc = SiteConfig::current_site_config();
|
||||
$sc->Title = 'Subsite2';
|
||||
$sc->write();
|
||||
|
||||
Subsite::changeSubsite(0);
|
||||
$this->assertEquals(SiteConfig::current_site_config()->Title, 'RootSite');
|
||||
Subsite::changeSubsite($subsite1->ID);
|
||||
$this->assertEquals(SiteConfig::current_site_config()->Title, 'Subsite1');
|
||||
Subsite::changeSubsite($subsite2->ID);
|
||||
$this->assertEquals(SiteConfig::current_site_config()->Title, 'Subsite2');
|
||||
$this->assertEquals(SiteConfig::current_site_config()->cacheKeyComponent(), 'subsite-'.$subsite2->ID);
|
||||
}
|
||||
|
||||
}
|
155
tests/SiteTreeSubsitesTest.php
Normal file
155
tests/SiteTreeSubsitesTest.php
Normal file
@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
class SiteTreeSubsitesTest extends SapphireTest {
|
||||
static $fixture_file = 'subsites/tests/SubsiteTest.yml';
|
||||
|
||||
function testPagesInDifferentSubsitesCanShareURLSegment() {
|
||||
$subsiteMain = $this->objFromFixture('Subsite_Template', 'main');
|
||||
$subsite1 = $this->objFromFixture('Subsite_Template', 'subsite1');
|
||||
|
||||
$pageMain = new SiteTree();
|
||||
$pageMain->URLSegment = 'testpage';
|
||||
$pageMain->write();
|
||||
$pageMain->publish('Stage', 'Live');
|
||||
|
||||
$pageMainOther = new SiteTree();
|
||||
$pageMainOther->URLSegment = 'testpage';
|
||||
$pageMainOther->write();
|
||||
$pageMainOther->publish('Stage', 'Live');
|
||||
|
||||
$this->assertNotEquals($pageMain->URLSegment, $pageMainOther->URLSegment,
|
||||
'Pages in same subsite cant share the same URL'
|
||||
);
|
||||
|
||||
Subsite::changeSubsite($subsite1->ID);
|
||||
|
||||
$pageSubsite1 = new SiteTree();
|
||||
$pageSubsite1->URLSegment = 'testpage';
|
||||
$pageSubsite1->write();
|
||||
$pageSubsite1->publish('Stage', 'Live');
|
||||
|
||||
$this->assertEquals($pageMain->URLSegment, $pageSubsite1->URLSegment,
|
||||
'Pages in different subsites can share the same URL'
|
||||
);
|
||||
}
|
||||
|
||||
function testBasicSanity() {
|
||||
$this->assertTrue(singleton('SiteTree')->getCMSFields() instanceof FieldSet);
|
||||
$this->assertTrue(is_array(singleton('SiteTreeSubsites')->extraStatics()));
|
||||
|
||||
$mainpage = $this->objFromFixture('SiteTree', 'home');
|
||||
$this->objFromFixture('Member', 'admin')->logIn();
|
||||
$this->assertTrue($mainpage->canEdit());
|
||||
$this->assertTrue($mainpage->canDelete());
|
||||
$this->assertTrue($mainpage->canPublish());
|
||||
}
|
||||
|
||||
function testErrorPageLocations() {
|
||||
$subsite1 = $this->objFromFixture('Subsite', 'domaintest1');
|
||||
|
||||
Subsite::changeSubsite($subsite1->ID);
|
||||
$path = ErrorPage::get_filepath_for_errorcode(500);
|
||||
|
||||
$static_path = Object::get_static('ErrorPage', 'static_filepath');
|
||||
$expected_path = $static_path . '/error-500-'.$subsite1->Subdomain.'.html';
|
||||
$this->assertEquals($expected_path, $path);
|
||||
}
|
||||
|
||||
function testRelatedPages() {
|
||||
$this->assertTrue(singleton('RelatedPageLink')->getCMSFields() instanceof FieldSet);
|
||||
|
||||
$importantpage = $this->objFromFixture('SiteTree', 'importantpage');
|
||||
$contact = $this->objFromFixture('SiteTree', 'contact');
|
||||
|
||||
$link = new RelatedPageLink();
|
||||
$link->MasterPageID = $importantpage->ID;
|
||||
$link->RelatedPageID = $contact->ID;
|
||||
$link->write();
|
||||
$importantpage->RelatedPages()->add($link);
|
||||
$this->assertTrue(singleton('SiteTree')->getCMSFields() instanceof FieldSet);
|
||||
|
||||
$this->assertEquals($importantpage->NormalRelated()->Count(), 1);
|
||||
$this->assertEquals($contact->ReverseRelated()->Count(), 1);
|
||||
}
|
||||
|
||||
function testPageWithVirtualPagesGetsTable() {
|
||||
$importantpage = $this->objFromFixture('SiteTree', 'importantpage');
|
||||
|
||||
$link = new SubsitesVirtualPage();
|
||||
$link->CopyContentFromID = $importantpage->ID;
|
||||
$link->write();
|
||||
$link->doPublish();
|
||||
|
||||
$fields = $importantpage->getCMSFields();
|
||||
|
||||
$this->assertNotNull($fields->fieldByName('Root.VirtualPages'));
|
||||
}
|
||||
|
||||
function testCanEditSiteTree() {
|
||||
$admin = $this->objFromFixture('Member', 'admin');
|
||||
$subsite1member = $this->objFromFixture('Member', 'subsite1member');
|
||||
$subsite2member = $this->objFromFixture('Member', 'subsite2member');
|
||||
$mainpage = $this->objFromFixture('SiteTree', 'home');
|
||||
$subsite1page = $this->objFromFixture('SiteTree', 'subsite1_home');
|
||||
$subsite2page = $this->objFromFixture('SiteTree', 'subsite2_home');
|
||||
$subsite1 = $this->objFromFixture('Subsite_Template', 'subsite1');
|
||||
$subsite2 = $this->objFromFixture('Subsite_Template', 'subsite2');
|
||||
|
||||
// Cant pass member as arguments to canEdit() because of GroupSubsites
|
||||
Session::set("loggedInAs", $admin->ID);
|
||||
$this->assertTrue(
|
||||
(bool)$subsite1page->canEdit(),
|
||||
'Administrators can edit all subsites'
|
||||
);
|
||||
|
||||
// @todo: Workaround because GroupSubsites->augmentSQL() is relying on session state
|
||||
Subsite::changeSubsite($subsite1);
|
||||
|
||||
Session::set("loggedInAs", $subsite1member->ID);
|
||||
$this->assertTrue(
|
||||
(bool)$subsite1page->canEdit(),
|
||||
'Members can edit pages on a subsite if they are in a group belonging to this subsite'
|
||||
);
|
||||
|
||||
Session::set("loggedInAs", $subsite2member->ID);
|
||||
$this->assertFalse(
|
||||
(bool)$subsite1page->canEdit(),
|
||||
'Members cant edit pages on a subsite if they are not in a group belonging to this subsite'
|
||||
);
|
||||
|
||||
// @todo: Workaround because GroupSubsites->augmentSQL() is relying on session state
|
||||
Subsite::changeSubsite(0);
|
||||
$this->assertFalse(
|
||||
$mainpage->canEdit(),
|
||||
'Members cant edit pages on the main site if they are not in a group allowing this'
|
||||
);
|
||||
}
|
||||
|
||||
function testTwoPagesWithSameURLOnDifferentSubsites() {
|
||||
// Set up a couple of pages with the same URL on different subsites
|
||||
$s1 = $this->objFromFixture('Subsite','domaintest1');
|
||||
$s2 = $this->objFromFixture('Subsite','domaintest2');
|
||||
|
||||
$p1 = new SiteTree();
|
||||
$p1->Title = $p1->URLSegment = "test-page";
|
||||
$p1->SubsiteID = $s1->ID;
|
||||
$p1->write();
|
||||
|
||||
$p2 = new SiteTree();
|
||||
$p2->Title = $p1->URLSegment = "test-page";
|
||||
$p2->SubsiteID = $s2->ID;
|
||||
$p2->write();
|
||||
|
||||
// Check that the URLs weren't modified in our set-up
|
||||
$this->assertEquals($p1->URLSegment, 'test-page');
|
||||
$this->assertEquals($p2->URLSegment, 'test-page');
|
||||
|
||||
// Check that if we switch between the different subsites, we receive the correct pages
|
||||
Subsite::changeSubsite($s1);
|
||||
$this->assertEquals($p1->ID, SiteTree::get_by_link('test-page')->ID);
|
||||
|
||||
Subsite::changeSubsite($s2);
|
||||
$this->assertEquals($p2->ID, SiteTree::get_by_link('test-page')->ID);
|
||||
}
|
||||
|
||||
}
|
@ -3,36 +3,6 @@
|
||||
class SubsiteTest extends SapphireTest {
|
||||
static $fixture_file = 'subsites/tests/SubsiteTest.yml';
|
||||
|
||||
function testPagesInDifferentSubsitesCanShareURLSegment() {
|
||||
$subsiteMain = $this->objFromFixture('Subsite_Template', 'main');
|
||||
$subsite1 = $this->objFromFixture('Subsite_Template', 'subsite1');
|
||||
|
||||
$pageMain = new SiteTree();
|
||||
$pageMain->URLSegment = 'testpage';
|
||||
$pageMain->write();
|
||||
$pageMain->publish('Stage', 'Live');
|
||||
|
||||
$pageMainOther = new SiteTree();
|
||||
$pageMainOther->URLSegment = 'testpage';
|
||||
$pageMainOther->write();
|
||||
$pageMainOther->publish('Stage', 'Live');
|
||||
|
||||
$this->assertNotEquals($pageMain->URLSegment, $pageMainOther->URLSegment,
|
||||
'Pages in same subsite cant share the same URL'
|
||||
);
|
||||
|
||||
Subsite::changeSubsite($subsite1->ID);
|
||||
|
||||
$pageSubsite1 = new SiteTree();
|
||||
$pageSubsite1->URLSegment = 'testpage';
|
||||
$pageSubsite1->write();
|
||||
$pageSubsite1->publish('Stage', 'Live');
|
||||
|
||||
$this->assertEquals($pageMain->URLSegment, $pageSubsite1->URLSegment,
|
||||
'Pages in different subsites can share the same URL'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new subsite from the template and verify that all the template's pages are copied
|
||||
*/
|
||||
@ -126,14 +96,6 @@ class SubsiteTest extends SapphireTest {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Only the published content from the template should publish.
|
||||
*/
|
||||
function testUnpublishedPagesDontCopy() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Subsite::accessible_sites()
|
||||
*/
|
||||
@ -158,86 +120,4 @@ class SubsiteTest extends SapphireTest {
|
||||
), $adminSiteTitles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish a change on a master page of a newly created sub-site, and verify that the change has been propagated.
|
||||
* Verify that if CustomContent is set, then the changes aren't propagated.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Reorganise a couple of pages on the master site and verify that the changes are propagated, whether or not CustomContent
|
||||
* is set.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Edit a subsite's content and verify that CustomContent is set on the page.
|
||||
* Edit a page without actually making any changes and verify that CustomContent isn't set.
|
||||
*/
|
||||
|
||||
function testCanEditSiteTree() {
|
||||
$admin = $this->objFromFixture('Member', 'admin');
|
||||
$subsite1member = $this->objFromFixture('Member', 'subsite1member');
|
||||
$subsite2member = $this->objFromFixture('Member', 'subsite2member');
|
||||
$mainpage = $this->objFromFixture('SiteTree', 'home');
|
||||
$subsite1page = $this->objFromFixture('SiteTree', 'subsite1_home');
|
||||
$subsite2page = $this->objFromFixture('SiteTree', 'subsite2_home');
|
||||
$subsite1 = $this->objFromFixture('Subsite_Template', 'subsite1');
|
||||
$subsite2 = $this->objFromFixture('Subsite_Template', 'subsite2');
|
||||
|
||||
// Cant pass member as arguments to canEdit() because of GroupSubsites
|
||||
Session::set("loggedInAs", $admin->ID);
|
||||
$this->assertTrue(
|
||||
(bool)$subsite1page->canEdit(),
|
||||
'Administrators can edit all subsites'
|
||||
);
|
||||
|
||||
// @todo: Workaround because GroupSubsites->augmentSQL() is relying on session state
|
||||
Subsite::changeSubsite($subsite1);
|
||||
|
||||
Session::set("loggedInAs", $subsite1member->ID);
|
||||
$this->assertTrue(
|
||||
(bool)$subsite1page->canEdit(),
|
||||
'Members can edit pages on a subsite if they are in a group belonging to this subsite'
|
||||
);
|
||||
|
||||
Session::set("loggedInAs", $subsite2member->ID);
|
||||
$this->assertFalse(
|
||||
(bool)$subsite1page->canEdit(),
|
||||
'Members cant edit pages on a subsite if they are not in a group belonging to this subsite'
|
||||
);
|
||||
|
||||
// @todo: Workaround because GroupSubsites->augmentSQL() is relying on session state
|
||||
Subsite::changeSubsite(0);
|
||||
$this->assertFalse(
|
||||
$mainpage->canEdit(),
|
||||
'Members cant edit pages on the main site if they are not in a group allowing this'
|
||||
);
|
||||
}
|
||||
|
||||
function testTwoPagesWithSameURLOnDifferentSubsites() {
|
||||
// Set up a couple of pages with the same URL on different subsites
|
||||
$s1 = $this->objFromFixture('Subsite','domaintest1');
|
||||
$s2 = $this->objFromFixture('Subsite','domaintest2');
|
||||
|
||||
$p1 = new SiteTree();
|
||||
$p1->Title = $p1->URLSegment = "test-page";
|
||||
$p1->SubsiteID = $s1->ID;
|
||||
$p1->write();
|
||||
|
||||
$p2 = new SiteTree();
|
||||
$p2->Title = $p1->URLSegment = "test-page";
|
||||
$p2->SubsiteID = $s2->ID;
|
||||
$p2->write();
|
||||
|
||||
// Check that the URLs weren't modified in our set-up
|
||||
$this->assertEquals($p1->URLSegment, 'test-page');
|
||||
$this->assertEquals($p2->URLSegment, 'test-page');
|
||||
|
||||
// Check that if we switch between the different subsites, we receive the correct pages
|
||||
Subsite::changeSubsite($s1);
|
||||
$this->assertEquals($p1->ID, SiteTree::get_by_link('test-page')->ID);
|
||||
|
||||
Subsite::changeSubsite($s2);
|
||||
$this->assertEquals($p2->ID, SiteTree::get_by_link('test-page')->ID);
|
||||
}
|
||||
|
||||
}
|
@ -97,6 +97,13 @@ Permission:
|
||||
accesscmsmain2:
|
||||
Code: CMS_ACCESS_CMSMain
|
||||
GroupID: =>Group.subsite2_group
|
||||
securityaccess1:
|
||||
Code: CMS_ACCESS_SecurityAdmin
|
||||
GroupID: =>Group.subsite1_group
|
||||
securityaccess2:
|
||||
Code: CMS_ACCESS_SecurityAdmin
|
||||
GroupID: =>Group.subsite2_group
|
||||
|
||||
Member:
|
||||
admin:
|
||||
FirstName: Admin
|
||||
|
Loading…
x
Reference in New Issue
Block a user