mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
formatting code
This commit is contained in:
parent
55c7240425
commit
a4a1ab6a78
@ -37,11 +37,11 @@ class SubsiteXHRController extends LeftAndMain
|
||||
*/
|
||||
public function canAccess()
|
||||
{
|
||||
// Allow if any cms access is available
|
||||
return Permission::check(array(
|
||||
'CMS_ACCESS', // Supported by 3.1.14 and up
|
||||
'CMS_ACCESS_LeftAndMain'
|
||||
));
|
||||
// Allow if any cms access is available
|
||||
return Permission::check([
|
||||
'CMS_ACCESS', // Supported by 3.1.14 and up
|
||||
'CMS_ACCESS_LeftAndMain'
|
||||
]);
|
||||
}
|
||||
|
||||
public function getResponseNegotiator()
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Subsites\Extensions;
|
||||
|
||||
use SilverStripe\Core\Extension;
|
||||
use SilverStripe\Forms\HiddenField;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Subsites\Extensions;
|
||||
|
||||
use SilverStripe\Core\Extension;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
use SilverStripe\View\SSViewer;
|
||||
@ -13,18 +14,18 @@ class ControllerSubsites extends Extension
|
||||
|
||||
public function controllerAugmentInit()
|
||||
{
|
||||
if ($subsite = Subsite::currentSubsite()) {
|
||||
if ($theme = $subsite->Theme) {
|
||||
SSViewer::set_themes([$theme, SSViewer::DEFAULT_THEME]);
|
||||
}
|
||||
$subsite = $this->CurrentSubsite();
|
||||
if ($subsite && $theme = $subsite->Theme) {
|
||||
SSViewer::set_themes([$theme, SSViewer::DEFAULT_THEME]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Subsite
|
||||
*/
|
||||
public function CurrentSubsite()
|
||||
{
|
||||
if ($subsite = Subsite::currentSubsite()) {
|
||||
return $subsite;
|
||||
}
|
||||
return Subsite::currentSubsite();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
namespace SilverStripe\Subsites\Extensions;
|
||||
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\ORM\DataExtension;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
|
||||
class ErrorPageSubsite extends DataExtension
|
||||
|
@ -25,17 +25,17 @@ use SilverStripe\Subsites\Model\Subsite;
|
||||
*/
|
||||
class GroupSubsites extends DataExtension implements PermissionProvider
|
||||
{
|
||||
private static $db = [
|
||||
'AccessAllSubsites' => 'Boolean'
|
||||
];
|
||||
private static $db = [
|
||||
'AccessAllSubsites' => 'Boolean'
|
||||
];
|
||||
|
||||
private static $many_many = [
|
||||
'Subsites' => Subsite::class
|
||||
];
|
||||
private static $many_many = [
|
||||
'Subsites' => Subsite::class
|
||||
];
|
||||
|
||||
private static $defaults = [
|
||||
'AccessAllSubsites' => true
|
||||
];
|
||||
private static $defaults = [
|
||||
'AccessAllSubsites' => true
|
||||
];
|
||||
|
||||
/**
|
||||
* Migrations for GroupSubsites data.
|
||||
@ -68,7 +68,8 @@ class GroupSubsites extends DataExtension implements PermissionProvider
|
||||
if (!DB::query('SELECT "Group"."ID" FROM "Group"
|
||||
LEFT JOIN "Group_Subsites" ON "Group_Subsites"."GroupID" = "Group"."ID" AND "Group_Subsites"."SubsiteID" > 0
|
||||
WHERE "AccessAllSubsites" = 1
|
||||
OR "Group_Subsites"."GroupID" IS NOT NULL ')->value()) {
|
||||
OR "Group_Subsites"."GroupID" IS NOT NULL ')->value()
|
||||
) {
|
||||
DB::query('UPDATE "Group" SET "AccessAllSubsites" = 1');
|
||||
}
|
||||
}
|
||||
@ -83,37 +84,37 @@ class GroupSubsites extends DataExtension implements PermissionProvider
|
||||
$subsites = Subsite::accessible_sites(['ADMIN', 'SECURITY_SUBSITE_GROUP'], true);
|
||||
$subsiteMap = $subsites->map();
|
||||
|
||||
// Prevent XSS injection
|
||||
$subsiteMap = Convert::raw2xml($subsiteMap->toArray());
|
||||
// Prevent XSS injection
|
||||
$subsiteMap = Convert::raw2xml($subsiteMap->toArray());
|
||||
|
||||
// Interface is different if you have the rights to modify subsite group values on
|
||||
// all subsites
|
||||
if(isset($subsiteMap[0])) {
|
||||
$fields->addFieldToTab('Root.Subsites', new OptionsetField('AccessAllSubsites',
|
||||
_t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'),
|
||||
[
|
||||
1 => _t('GroupSubsites.ACCESSALL', 'All subsites'),
|
||||
0 => _t('GroupSubsites.ACCESSONLY', 'Only these subsites'),
|
||||
]
|
||||
));
|
||||
// Interface is different if you have the rights to modify subsite group values on
|
||||
// all subsites
|
||||
if (isset($subsiteMap[0])) {
|
||||
$fields->addFieldToTab('Root.Subsites', new OptionsetField('AccessAllSubsites',
|
||||
_t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'),
|
||||
[
|
||||
1 => _t('GroupSubsites.ACCESSALL', 'All subsites'),
|
||||
0 => _t('GroupSubsites.ACCESSONLY', 'Only these subsites'),
|
||||
]
|
||||
));
|
||||
|
||||
unset($subsiteMap[0]);
|
||||
$fields->addFieldToTab('Root.Subsites', new CheckboxSetField('Subsites', '',
|
||||
$subsiteMap));
|
||||
unset($subsiteMap[0]);
|
||||
$fields->addFieldToTab('Root.Subsites', new CheckboxSetField('Subsites', '',
|
||||
$subsiteMap));
|
||||
|
||||
} else {
|
||||
if (sizeof($subsiteMap) <= 1) {
|
||||
$fields->addFieldToTab('Root.Subsites', new ReadonlyField('SubsitesHuman',
|
||||
_t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'),
|
||||
reset($subsiteMap)));
|
||||
} else {
|
||||
$fields->addFieldToTab('Root.Subsites', new CheckboxSetField('Subsites',
|
||||
_t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'),
|
||||
$subsiteMap));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (sizeof($subsiteMap) <= 1) {
|
||||
$fields->addFieldToTab('Root.Subsites', new ReadonlyField('SubsitesHuman',
|
||||
_t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'),
|
||||
reset($subsiteMap)));
|
||||
} else {
|
||||
$fields->addFieldToTab('Root.Subsites', new CheckboxSetField('Subsites',
|
||||
_t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'),
|
||||
$subsiteMap));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If this group belongs to a subsite,
|
||||
|
@ -3,13 +3,12 @@
|
||||
namespace SilverStripe\Subsites\Extensions;
|
||||
|
||||
|
||||
use Page;
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Control\HTTP;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Forms\CheckboxField;
|
||||
use SilverStripe\Forms\DropdownField;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
@ -35,13 +34,13 @@ class SiteTreeSubsites extends DataExtension
|
||||
'Subsite' => Subsite::class, // The subsite that this page belongs to
|
||||
];
|
||||
|
||||
private static $many_many = array(
|
||||
private static $many_many = [
|
||||
'CrossSubsiteLinkTracking' => SiteTree::class // Stored separately, as the logic for URL rewriting is different
|
||||
);
|
||||
];
|
||||
|
||||
private static $many_many_extraFields = array(
|
||||
'CrossSubsiteLinkTracking' => array('FieldName' => 'Varchar')
|
||||
);
|
||||
private static $many_many_extraFields = [
|
||||
'CrossSubsiteLinkTracking' => ['FieldName' => 'Varchar']
|
||||
];
|
||||
|
||||
public function isMainSite()
|
||||
{
|
||||
@ -72,7 +71,8 @@ class SiteTreeSubsites extends DataExtension
|
||||
$subsiteID = Subsite::$force_subsite;
|
||||
} else {
|
||||
/*if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID;
|
||||
else */$subsiteID = (int)Subsite::currentSubsiteID();
|
||||
else */
|
||||
$subsiteID = (int)Subsite::currentSubsiteID();
|
||||
}
|
||||
|
||||
// The foreach is an ugly way of getting the first key :-)
|
||||
@ -99,7 +99,7 @@ class SiteTreeSubsites extends DataExtension
|
||||
public function updateCMSFields(FieldList $fields)
|
||||
{
|
||||
$subsites = Subsite::accessible_sites('CMS_ACCESS_CMSMain');
|
||||
$subsitesMap = array();
|
||||
$subsitesMap = [];
|
||||
if ($subsites && $subsites->count()) {
|
||||
$subsitesToMap = $subsites->exclude('ID', $this->owner->SubsiteID);
|
||||
$subsitesMap = $subsitesToMap->map('ID', 'Title');
|
||||
@ -113,15 +113,16 @@ class SiteTreeSubsites extends DataExtension
|
||||
'Root.Main',
|
||||
ToggleCompositeField::create('SubsiteOperations',
|
||||
_t('SiteTreeSubsites.SubsiteOperations', 'Subsite Operations'),
|
||||
array(
|
||||
[
|
||||
new DropdownField('CopyToSubsiteID', _t('SiteTreeSubsites.CopyToSubsite',
|
||||
'Copy page to subsite'), $subsitesMap),
|
||||
new CheckboxField('CopyToSubsiteWithChildren', _t('SiteTreeSubsites.CopyToSubsiteWithChildren', 'Include children pages?')),
|
||||
new CheckboxField('CopyToSubsiteWithChildren',
|
||||
_t('SiteTreeSubsites.CopyToSubsiteWithChildren', 'Include children pages?')),
|
||||
$copyAction = new InlineFormAction(
|
||||
'copytosubsite',
|
||||
_t('SiteTreeSubsites.CopyAction', 'Copy')
|
||||
)
|
||||
)
|
||||
]
|
||||
)->setHeadingLevel(4)
|
||||
);
|
||||
|
||||
@ -137,7 +138,7 @@ class SiteTreeSubsites extends DataExtension
|
||||
$baseLink = $subsite->absoluteBaseURL();
|
||||
|
||||
// Add parent page if enabled
|
||||
if($nested_urls_enabled && $this->owner->ParentID) {
|
||||
if ($nested_urls_enabled && $this->owner->ParentID) {
|
||||
$baseLink = Controller::join_links(
|
||||
$baseLink,
|
||||
$this->owner->Parent()->RelativeLink(true)
|
||||
@ -278,8 +279,8 @@ class SiteTreeSubsites extends DataExtension
|
||||
|
||||
Subsite::changeSubsite($oldSubsite);
|
||||
|
||||
if($includeChildren) {
|
||||
foreach($this->owner->AllChildren() as $child) {
|
||||
if ($includeChildren) {
|
||||
foreach ($this->owner->AllChildren() as $child) {
|
||||
$child->duplicateToSubsite($subsiteID, $includeChildren, $page->ID);
|
||||
}
|
||||
}
|
||||
@ -306,7 +307,7 @@ class SiteTreeSubsites extends DataExtension
|
||||
// This helps deal with Link() returning an absolute URL.
|
||||
$url = Director::absoluteURL($this->owner->Link());
|
||||
if ($this->owner->SubsiteID) {
|
||||
$url = preg_replace('/\/\/[^\/]+\//', '//' . $this->owner->Subsite()->domain() . '/', $url);
|
||||
$url = preg_replace('/\/\/[^\/]+\//', '//' . $this->owner->Subsite()->domain() . '/', $url);
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
@ -344,7 +345,7 @@ class SiteTreeSubsites extends DataExtension
|
||||
{
|
||||
// Set LinkTracking appropriately
|
||||
$links = HTTP::getLinksIn($this->owner->Content);
|
||||
$linkedPages = array();
|
||||
$linkedPages = [];
|
||||
|
||||
if ($links) {
|
||||
foreach ($links as $link) {
|
||||
@ -359,9 +360,11 @@ class SiteTreeSubsites extends DataExtension
|
||||
continue;
|
||||
} // We have no idea what the domain for the main site is, so cant track links to it
|
||||
|
||||
$origDisableSubsiteFilter = Subsite::$disable_subsite_filter;
|
||||
$origDisableSubsiteFilter = Subsite::$disable_subsite_filter;
|
||||
Subsite::disable_subsite_filter(true);
|
||||
$candidatePage = DataObject::get_one(SiteTree::class, "\"URLSegment\" = '" . Convert::raw2sql(urldecode($rest)) . "' AND \"SubsiteID\" = " . $subsiteID, false);
|
||||
$candidatePage = DataObject::get_one(SiteTree::class,
|
||||
"\"URLSegment\" = '" . Convert::raw2sql(urldecode($rest)) . "' AND \"SubsiteID\" = " . $subsiteID,
|
||||
false);
|
||||
Subsite::disable_subsite_filter($origDisableSubsiteFilter);
|
||||
|
||||
if ($candidatePage) {
|
||||
@ -409,7 +412,7 @@ class SiteTreeSubsites extends DataExtension
|
||||
*/
|
||||
public function cacheKeyComponent()
|
||||
{
|
||||
return 'subsite-'.Subsite::currentSubsiteID();
|
||||
return 'subsite-' . Subsite::currentSubsiteID();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -9,9 +9,9 @@ use SilverStripe\Subsites\Model\Subsite;
|
||||
class GridFieldSubsiteDetailForm_ItemRequest extends GridFieldDetailForm_ItemRequest
|
||||
{
|
||||
|
||||
private static $allowed_actions = array(
|
||||
private static $allowed_actions = [
|
||||
'ItemEditForm',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Builds an item edit form. The arguments to getCMSFields() are the popupController and
|
||||
@ -26,16 +26,17 @@ class GridFieldSubsiteDetailForm_ItemRequest extends GridFieldDetailForm_ItemReq
|
||||
*/
|
||||
public function ItemEditForm()
|
||||
{
|
||||
$form=parent::ItemEditForm();
|
||||
$form = parent::ItemEditForm();
|
||||
|
||||
if ($this->record->ID == 0) {
|
||||
$templates = Subsite::get()->sort('Title');
|
||||
$templateArray = array();
|
||||
$templateArray = [];
|
||||
if ($templates) {
|
||||
$templateArray = $templates->map('ID', 'Title');
|
||||
}
|
||||
|
||||
$templateDropdown = new DropdownField('TemplateID', _t('Subsite.COPYSTRUCTURE', 'Copy structure from:'), $templateArray);
|
||||
$templateDropdown = new DropdownField('TemplateID', _t('Subsite.COPYSTRUCTURE', 'Copy structure from:'),
|
||||
$templateArray);
|
||||
$templateDropdown->setEmptyString('(' . _t('Subsite.NOTEMPLATE', 'No template') . ')');
|
||||
$form->Fields()->addFieldToTab('Root.Configuration', $templateDropdown);
|
||||
}
|
||||
|
@ -17,15 +17,15 @@ use SilverStripe\View\Requirements;
|
||||
*/
|
||||
class SubsitesTreeDropdownField extends TreeDropdownField
|
||||
{
|
||||
private static $allowed_actions = array(
|
||||
private static $allowed_actions = [
|
||||
'tree'
|
||||
);
|
||||
];
|
||||
|
||||
protected $subsiteID = 0;
|
||||
|
||||
protected $extraClasses = array('SubsitesTreeDropdownField');
|
||||
protected $extraClasses = ['SubsitesTreeDropdownField'];
|
||||
|
||||
public function Field($properties = array())
|
||||
public function Field($properties = [])
|
||||
{
|
||||
$html = parent::Field($properties);
|
||||
|
||||
|
@ -55,7 +55,7 @@ class SubsiteCopyPagesTask extends BuildTask
|
||||
// This will make sure that the new parents on the new subsite are correct, and there are no funny
|
||||
// issues with having to check whether or not the new parents have been added to the site tree
|
||||
// when a page, etc, is duplicated
|
||||
$stack = array(array(0,0));
|
||||
$stack = [[0, 0]];
|
||||
while (count($stack) > 0) {
|
||||
list($sourceParentID, $destParentID) = array_pop($stack);
|
||||
|
||||
@ -75,7 +75,7 @@ class SubsiteCopyPagesTask extends BuildTask
|
||||
$childClone->ParentID = $destParentID;
|
||||
$childClone->writeToStage('Stage');
|
||||
$childClone->copyVersionToStage('Stage', 'Live');
|
||||
array_push($stack, array($child->ID, $childClone->ID));
|
||||
array_push($stack, [$child->ID, $childClone->ID]);
|
||||
|
||||
$this->log(sprintf('Copied "%s" (#%d, %s)', $child->Title, $child->ID, $child->Link()));
|
||||
}
|
||||
|
@ -6,19 +6,18 @@ if (!class_exists('SilverStripe\BehatExtension\Context\SilverStripeContext')) {
|
||||
return;
|
||||
}
|
||||
|
||||
use SilverStripe\BehatExtension\Context\SilverStripeContext;
|
||||
use SilverStripe\BehatExtension\Context\BasicContext;
|
||||
use SilverStripe\BehatExtension\Context\LoginContext;
|
||||
use SilverStripe\BehatExtension\Context\FixtureContext;
|
||||
use SilverStripe\Framework\Test\Behaviour\CmsFormsContext;
|
||||
use SilverStripe\Framework\Test\Behaviour\CmsUiContext;
|
||||
use SilverStripe\Cms\Test\Behaviour;
|
||||
use SilverStripe\BehatExtension\Context\LoginContext;
|
||||
use SilverStripe\BehatExtension\Context\SilverStripeContext;
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Core\ClassInfo;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Dev\BehatFixtureFactory;
|
||||
use SilverStripe\Dev\FixtureBlueprint;
|
||||
use SilverStripe\Dev\FixtureFactory;
|
||||
use SilverStripe\Framework\Test\Behaviour\CmsFormsContext;
|
||||
use SilverStripe\Framework\Test\Behaviour\CmsUiContext;
|
||||
use SilverStripe\Security\Member;
|
||||
|
||||
// PHPUnit
|
||||
@ -32,7 +31,7 @@ require_once 'PHPUnit/Framework/Assert/Functions.php';
|
||||
* Uses subcontexts to extend functionality.
|
||||
*/
|
||||
class FeatureContext extends SilverStripeContext
|
||||
{
|
||||
{
|
||||
/**
|
||||
* @var FixtureFactory
|
||||
*/
|
||||
|
@ -13,7 +13,7 @@ class BaseSubsiteTest extends SapphireTest
|
||||
parent::setUp();
|
||||
|
||||
Subsite::$use_session_subsiteid = true;
|
||||
Subsite::$force_subsite = null;
|
||||
Subsite::$force_subsite = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -22,18 +22,20 @@ class BaseSubsiteTest extends SapphireTest
|
||||
* @param string $id
|
||||
* @return \SilverStripe\ORM\DataObject
|
||||
*/
|
||||
public function objFromFixture($class, $id)
|
||||
{Subsite::disable_subsite_filter(true);
|
||||
$obj = parent::objFromFixture($class, $id);
|
||||
Subsite::disable_subsite_filter(false);
|
||||
public function objFromFixture($class, $id)
|
||||
{
|
||||
Subsite::disable_subsite_filter(true);
|
||||
$obj = parent::objFromFixture($class, $id);
|
||||
Subsite::disable_subsite_filter(false);
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the initial state of disable_subsite_filter
|
||||
*/
|
||||
public function testDisableSubsiteFilter()
|
||||
{$this->assertFalse(Subsite::$disable_subsite_filter);
|
||||
}
|
||||
/**
|
||||
* Tests the initial state of disable_subsite_filter
|
||||
*/
|
||||
public function testDisableSubsiteFilter()
|
||||
{
|
||||
$this->assertFalse(Subsite::$disable_subsite_filter);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ use SilverStripe\Assets\Folder;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Security\Member;
|
||||
use SilverStripe\Subsites\Extensions\FileSubsites;
|
||||
use SilverStripe\Subsites\Tests\BaseSubsiteTest;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
|
||||
class FileSubsitesTest extends BaseSubsiteTest
|
||||
@ -20,15 +19,15 @@ class FileSubsitesTest extends BaseSubsiteTest
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $illegalExtensions = array(
|
||||
'File' => array(
|
||||
protected $illegalExtensions = [
|
||||
'File' => [
|
||||
'SecureFileExtension',
|
||||
'VersionedFileExtension'
|
||||
),
|
||||
'SiteTree' => array(
|
||||
],
|
||||
'SiteTree' => [
|
||||
'Translatable',
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
|
||||
public function testTrivialFeatures()
|
||||
{
|
||||
@ -92,7 +91,7 @@ class FileSubsitesTest extends BaseSubsiteTest
|
||||
$source = array_values($file->getCMSFields()->dataFieldByName('SubsiteID')->getSource());
|
||||
asort($source);
|
||||
|
||||
$this->assertEquals(array(
|
||||
$this->assertEquals([
|
||||
'Main site',
|
||||
'Subsite1 Template',
|
||||
'Subsite2 Template',
|
||||
@ -102,6 +101,6 @@ class FileSubsitesTest extends BaseSubsiteTest
|
||||
'Test 3',
|
||||
'Test Non-SSL',
|
||||
'Test SSL',
|
||||
), array_values($source));
|
||||
], array_values($source));
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
namespace SilverStripe\Subsites\Tests;
|
||||
|
||||
use SilverStripe\Security\Group;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Security\Group;
|
||||
use SilverStripe\Subsites\Extensions\GroupSubsites;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
|
||||
@ -12,6 +12,7 @@ class GroupSubsitesTest extends BaseSubsiteTest
|
||||
public static $fixture_file = 'subsites/tests/php/SubsiteTest.yml';
|
||||
|
||||
protected $requireDefaultRecordsFrom = [GroupSubsites::class];
|
||||
|
||||
public function testTrivialFeatures()
|
||||
{
|
||||
$this->assertTrue(is_array(singleton(GroupSubsites::class)->extraStatics()));
|
||||
|
@ -2,13 +2,13 @@
|
||||
|
||||
namespace SilverStripe\Subsites\Tests;
|
||||
|
||||
use SilverStripe\AssetAdmin\Controller\AssetAdmin;
|
||||
use SilverStripe\Security\Member;
|
||||
use SilverStripe\CMS\Controllers\CMSMain;
|
||||
use SilverStripe\Admin\LeftAndMain;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\AssetAdmin\Controller\AssetAdmin;
|
||||
use SilverStripe\CMS\Controllers\CMSMain;
|
||||
use SilverStripe\CMS\Controllers\CMSPageEditController;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
use SilverStripe\Security\Member;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
|
||||
class LeftAndMainSubsitesTest extends FunctionalTest
|
||||
@ -36,9 +36,9 @@ class LeftAndMainSubsitesTest extends FunctionalTest
|
||||
|
||||
$cmsmain = singleton(CMSMain::class);
|
||||
$subsites = $cmsmain->sectionSites(true, 'Main site', $member);
|
||||
$this->assertDOSEquals(array(
|
||||
array('Title' =>'Subsite1 Template')
|
||||
), $subsites, 'Lists member-accessible sites for the accessible controller.');
|
||||
$this->assertDOSEquals([
|
||||
['Title' => 'Subsite1 Template']
|
||||
], $subsites, 'Lists member-accessible sites for the accessible controller.');
|
||||
|
||||
$assetadmin = singleton(AssetAdmin::class);
|
||||
$subsites = $assetadmin->sectionSites(true, 'Main site', $member);
|
||||
@ -48,16 +48,16 @@ class LeftAndMainSubsitesTest extends FunctionalTest
|
||||
|
||||
$cmsmain = singleton(CMSMain::class);
|
||||
$subsites = $cmsmain->sectionSites(true, 'Main site', $member);
|
||||
$this->assertDOSContains(array(
|
||||
array('Title' =>'Main site')
|
||||
), $subsites, 'Includes the main site for members who can access all sites.');
|
||||
$this->assertDOSContains([
|
||||
['Title' => 'Main site']
|
||||
], $subsites, 'Includes the main site for members who can access all sites.');
|
||||
}
|
||||
|
||||
public function testAccessChecksDontChangeCurrentSubsite()
|
||||
{
|
||||
$admin = $this->objFromFixture(Member::class, 'admin');
|
||||
$this->logInAs($admin);
|
||||
$ids = array();
|
||||
$ids = [];
|
||||
|
||||
$subsite1 = $this->objFromFixture(Subsite::class, 'domaintest1');
|
||||
$subsite2 = $this->objFromFixture(Subsite::class, 'domaintest2');
|
||||
@ -74,13 +74,13 @@ class LeftAndMainSubsitesTest extends FunctionalTest
|
||||
Subsite::changeSubsite($id);
|
||||
$this->assertEquals($id, Subsite::currentSubsiteID());
|
||||
|
||||
$left = new LeftAndMain();
|
||||
$this->assertTrue($left->canView(), "Admin user can view subsites LeftAndMain with id = '$id'");
|
||||
$this->assertEquals($id, Subsite::currentSubsiteID(),
|
||||
$left = new LeftAndMain();
|
||||
$this->assertTrue($left->canView(), "Admin user can view subsites LeftAndMain with id = '$id'");
|
||||
$this->assertEquals($id, Subsite::currentSubsiteID(),
|
||||
'The current subsite has not been changed in the process of checking permissions for admin user.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function testShouldChangeSubsite()
|
||||
{
|
||||
|
@ -15,29 +15,29 @@ class SiteConfigSubsitesTest extends BaseSubsiteTest
|
||||
$subsite1 = $this->objFromFixture(Subsite::class, 'domaintest1');
|
||||
$subsite2 = $this->objFromFixture(Subsite::class, 'domaintest2');
|
||||
|
||||
$this->assertTrue(is_array(singleton(SiteConfigSubsites::class)->extraStatics()));
|
||||
$this->assertTrue(is_array(singleton(SiteConfigSubsites::class)->extraStatics()));
|
||||
|
||||
Subsite::changeSubsite(0);
|
||||
$sc = SiteConfig::current_site_config();
|
||||
$sc->Title = 'RootSite';
|
||||
$sc->write();
|
||||
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($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($subsite2->ID);
|
||||
$sc = SiteConfig::current_site_config();
|
||||
$sc->Title = 'Subsite2';
|
||||
$sc->write();
|
||||
|
||||
Subsite::changeSubsite(0);
|
||||
$this->assertEquals('RootSite', SiteConfig::current_site_config()->Title);
|
||||
Subsite::changeSubsite($subsite1->ID);
|
||||
$this->assertEquals('Subsite1', SiteConfig::current_site_config()->Title);
|
||||
Subsite::changeSubsite($subsite2->ID);
|
||||
$this->assertEquals('Subsite2', SiteConfig::current_site_config()->Title);
|
||||
Subsite::changeSubsite(0);
|
||||
$this->assertEquals('RootSite', SiteConfig::current_site_config()->Title);
|
||||
Subsite::changeSubsite($subsite1->ID);
|
||||
$this->assertEquals('Subsite1', SiteConfig::current_site_config()->Title);
|
||||
Subsite::changeSubsite($subsite2->ID);
|
||||
$this->assertEquals('Subsite2', SiteConfig::current_site_config()->Title);
|
||||
|
||||
$keys = SiteConfig::current_site_config()->extend('cacheKeyComponent');
|
||||
static::assertContains('subsite-' . $subsite2->ID, $keys);
|
||||
|
@ -169,7 +169,7 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
||||
$s2 = $this->objFromFixture(Subsite::class, 'domaintest2');
|
||||
$page = singleton(SiteTree::class);
|
||||
|
||||
$s1->PageTypeBlacklist = implode(',', [SiteTreeSubsitesTest_ClassA::class , ErrorPage::class]);
|
||||
$s1->PageTypeBlacklist = implode(',', [SiteTreeSubsitesTest_ClassA::class, ErrorPage::class]);
|
||||
$s1->write();
|
||||
|
||||
Subsite::changeSubsite($s1);
|
||||
@ -236,7 +236,7 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
||||
$s1 = $this->objFromFixture(Subsite::class, 'domaintest1');
|
||||
$s2 = $this->objFromFixture(Subsite::class, 'domaintest2');
|
||||
|
||||
$s1->PageTypeBlacklist = implode(',', [SiteTreeSubsitesTest_ClassA::class , ErrorPage::class]);
|
||||
$s1->PageTypeBlacklist = implode(',', [SiteTreeSubsitesTest_ClassA::class, ErrorPage::class]);
|
||||
$s1->write();
|
||||
|
||||
Subsite::changeSubsite($s1);
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
namespace SilverStripe\Subsites\Tests;
|
||||
|
||||
use SilverStripe\Security\Member;
|
||||
use SilverStripe\CMS\Controllers\CMSPageEditController;
|
||||
use SilverStripe\Control\Session;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\CMS\Controllers\CMSPageEditController;
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
use SilverStripe\Security\Member;
|
||||
use SilverStripe\Subsites\Controller\SubsiteXHRController;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
|
||||
@ -15,7 +15,7 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
|
||||
public static $fixture_file = 'subsites/tests/php/SubsiteTest.yml';
|
||||
public static $use_draft_site = true;
|
||||
|
||||
protected $autoFollowRedirection = false;
|
||||
protected $autoFollowRedirection = false;
|
||||
|
||||
/**
|
||||
* Helper: FunctionalTest is only able to follow redirection once, we want to go all the way.
|
||||
@ -30,8 +30,8 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
|
||||
}
|
||||
echo $response->getHeader('Location');
|
||||
|
||||
return $response;
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Anonymous user cannot access anything.
|
||||
@ -80,26 +80,29 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
|
||||
$mainSubsitePage = $this->objFromFixture('Page', 'mainSubsitePage');
|
||||
$subsite1Home = $this->objFromFixture('Page', 'subsite1_home');
|
||||
|
||||
Config::nest();
|
||||
Config::nest();
|
||||
|
||||
Config::modify()->set(CMSPageEditController::class, 'treats_subsite_0_as_global', false);
|
||||
Subsite::changeSubsite(0);
|
||||
$this->getAndFollowAll("admin/pages/edit/show/$subsite1Home->ID");
|
||||
$this->assertEquals(Subsite::currentSubsiteID(), $subsite1Home->SubsiteID, 'Loading an object switches the subsite');
|
||||
$this->assertEquals(Subsite::currentSubsiteID(), $subsite1Home->SubsiteID,
|
||||
'Loading an object switches the subsite');
|
||||
$this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section');
|
||||
|
||||
Config::modify()->set(CMSPageEditController::class, 'treats_subsite_0_as_global', true);
|
||||
Subsite::changeSubsite(0);
|
||||
$this->getAndFollowAll("admin/pages/edit/show/$subsite1Home->ID");
|
||||
$this->assertEquals(Subsite::currentSubsiteID(), $subsite1Home->SubsiteID, 'Loading a non-main-site object still switches the subsite if configured with treats_subsite_0_as_global');
|
||||
$this->assertEquals(Subsite::currentSubsiteID(), $subsite1Home->SubsiteID,
|
||||
'Loading a non-main-site object still switches the subsite if configured with treats_subsite_0_as_global');
|
||||
$this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section');
|
||||
|
||||
$this->getAndFollowAll("admin/pages/edit/show/$mainSubsitePage->ID");
|
||||
$this->assertNotEquals(Subsite::currentSubsiteID(), $mainSubsitePage->SubsiteID, 'Loading a main-site object does not change the subsite if configured with treats_subsite_0_as_global');
|
||||
$this->assertNotEquals(Subsite::currentSubsiteID(), $mainSubsitePage->SubsiteID,
|
||||
'Loading a main-site object does not change the subsite if configured with treats_subsite_0_as_global');
|
||||
$this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section');
|
||||
|
||||
Config::unnest();
|
||||
}
|
||||
Config::unnest();
|
||||
}
|
||||
|
||||
/**
|
||||
* User which has AccessAllSubsites set to 1 should be able to access all subsites and main site,
|
||||
@ -110,9 +113,9 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
|
||||
$member = $this->objFromFixture(Member::class, 'editor');
|
||||
Session::set('loggedInAs', $member->ID);
|
||||
|
||||
$this->getAndFollowAll('admin/pages/?SubsiteID=0');
|
||||
$this->assertEquals(Subsite::currentSubsiteID(), '0', 'Can access main site.');
|
||||
$this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section');
|
||||
$this->getAndFollowAll('admin/pages/?SubsiteID=0');
|
||||
$this->assertEquals(Subsite::currentSubsiteID(), '0', 'Can access main site.');
|
||||
$this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section');
|
||||
|
||||
$subsite1 = $this->objFromFixture(Subsite::class, 'subsite1');
|
||||
$this->getAndFollowAll("admin/pages/?SubsiteID={$subsite1->ID}");
|
||||
@ -134,25 +137,25 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
|
||||
|
||||
$subsite1 = $this->objFromFixture(Subsite::class, 'subsite1');
|
||||
|
||||
// Check allowed URL.
|
||||
$this->getAndFollowAll("admin/pages/?SubsiteID={$subsite1->ID}");
|
||||
$this->assertEquals(Subsite::currentSubsiteID(), $subsite1->ID, 'Can access own subsite.');
|
||||
$this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Can access permitted section.');
|
||||
// Check allowed URL.
|
||||
$this->getAndFollowAll("admin/pages/?SubsiteID={$subsite1->ID}");
|
||||
$this->assertEquals(Subsite::currentSubsiteID(), $subsite1->ID, 'Can access own subsite.');
|
||||
$this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Can access permitted section.');
|
||||
|
||||
// Check forbidden section in allowed subsite.
|
||||
$this->getAndFollowAll("admin/assets/?SubsiteID={$subsite1->ID}");
|
||||
$this->assertEquals(Subsite::currentSubsiteID(), $subsite1->ID, 'Is redirected within subsite.');
|
||||
$this->assertNotRegExp('#^admin/assets/.*#', $this->mainSession->lastUrl(),
|
||||
'Is redirected away from forbidden section');
|
||||
// Check forbidden section in allowed subsite.
|
||||
$this->getAndFollowAll("admin/assets/?SubsiteID={$subsite1->ID}");
|
||||
$this->assertEquals(Subsite::currentSubsiteID(), $subsite1->ID, 'Is redirected within subsite.');
|
||||
$this->assertNotRegExp('#^admin/assets/.*#', $this->mainSession->lastUrl(),
|
||||
'Is redirected away from forbidden section');
|
||||
|
||||
// Check forbidden site, on a section that's allowed on another subsite
|
||||
$this->getAndFollowAll('admin/pages/?SubsiteID=0');
|
||||
$this->assertEquals(Subsite::currentSubsiteID(), $subsite1->ID, 'Is redirected to permitted subsite.');
|
||||
// Check forbidden site, on a section that's allowed on another subsite
|
||||
$this->getAndFollowAll('admin/pages/?SubsiteID=0');
|
||||
$this->assertEquals(Subsite::currentSubsiteID(), $subsite1->ID, 'Is redirected to permitted subsite.');
|
||||
|
||||
// Check forbidden site, on a section that's not allowed on any other subsite
|
||||
$this->getAndFollowAll('admin/assets/?SubsiteID=0');
|
||||
$this->assertEquals(Subsite::currentSubsiteID(), $subsite1->ID, 'Is redirected to first permitted subsite.');
|
||||
$this->assertNotRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), 'Is not denied access');
|
||||
// Check forbidden site, on a section that's not allowed on any other subsite
|
||||
$this->getAndFollowAll('admin/assets/?SubsiteID=0');
|
||||
$this->assertEquals(Subsite::currentSubsiteID(), $subsite1->ID, 'Is redirected to first permitted subsite.');
|
||||
$this->assertNotRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), 'Is not denied access');
|
||||
|
||||
// Check the standalone XHR controller.
|
||||
$response = $this->getAndFollowAll(SubsiteXHRController::class);
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
namespace SilverStripe\Subsites\Tests;
|
||||
|
||||
use SilverStripe\Security\Member;
|
||||
use SilverStripe\Control\Session;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\CMS\Controllers\CMSMain;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Control\Session;
|
||||
use SilverStripe\Security\Member;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
|
||||
class SubsiteAdminTest extends BaseSubsiteTest
|
||||
@ -14,9 +14,9 @@ class SubsiteAdminTest extends BaseSubsiteTest
|
||||
|
||||
public function adminLoggedInSession()
|
||||
{
|
||||
return new Session(array(
|
||||
return new Session([
|
||||
'loggedInAs' => $this->idFromFixture(Member::class, 'admin')
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -31,7 +31,8 @@ class SubsiteAdminTest extends BaseSubsiteTest
|
||||
$response1 = Director::test('admin/subsites/', null, $this->adminLoggedInSession());
|
||||
|
||||
// Confirm that this URL gets you the entire page, with the edit form loaded
|
||||
$response2 = Director::test("admin/subsites/SilverStripe-Subsites-Model-Subsite/EditForm/field/SilverStripe-Subsites-Model-Subsite/item/$subsite1ID/edit", null,
|
||||
$response2 = Director::test("admin/subsites/SilverStripe-Subsites-Model-Subsite/EditForm/field/SilverStripe-Subsites-Model-Subsite/item/$subsite1ID/edit",
|
||||
null,
|
||||
$this->adminLoggedInSession());
|
||||
$this->assertTrue(strpos($response2->getBody(), 'id="Form_ItemEditForm_ID"') !== false,
|
||||
'Testing Form_ItemEditForm_ID exists');
|
||||
@ -53,13 +54,13 @@ class SubsiteAdminTest extends BaseSubsiteTest
|
||||
$ids[$subsite->ID] = true;
|
||||
}
|
||||
|
||||
$this->assertArrayHasKey(0, $ids, 'Main site accessible');
|
||||
$this->assertArrayHasKey($this->idFromFixture(Subsite::class,'main'), $ids, 'Site with no groups inaccesible');
|
||||
$this->assertArrayHasKey($this->idFromFixture(Subsite::class,'subsite1'), $ids,
|
||||
$this->assertArrayHasKey(0, $ids, 'Main site accessible');
|
||||
$this->assertArrayHasKey($this->idFromFixture(Subsite::class, 'main'), $ids, 'Site with no groups inaccesible');
|
||||
$this->assertArrayHasKey($this->idFromFixture(Subsite::class, 'subsite1'), $ids,
|
||||
'Subsite1 Template inaccessible');
|
||||
$this->assertArrayHasKey($this->idFromFixture(Subsite::class,'subsite2'), $ids,
|
||||
$this->assertArrayHasKey($this->idFromFixture(Subsite::class, 'subsite2'), $ids,
|
||||
'Subsite2 Template inaccessible');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ class SubsiteTest extends BaseSubsiteTest
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $origServer = array();
|
||||
protected $origServer = [];
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
@ -59,7 +59,7 @@ class SubsiteTest extends BaseSubsiteTest
|
||||
|
||||
// Test that changeSubsite is working
|
||||
Subsite::changeSubsite($template->ID);
|
||||
$this->assertEquals($template->ID, Subsite::currentSubsiteID());
|
||||
$this->assertEquals($template->ID, Subsite::currentSubsiteID());
|
||||
$tmplStaff = $this->objFromFixture('Page', 'staff');
|
||||
$tmplHome = DataObject::get_one('Page', "\"URLSegment\" = 'home'");
|
||||
|
||||
@ -103,20 +103,20 @@ class SubsiteTest extends BaseSubsiteTest
|
||||
}
|
||||
|
||||
// Much more expressive than YML in this case
|
||||
$subsite1 = $this->createSubsiteWithDomains(array(
|
||||
$subsite1 = $this->createSubsiteWithDomains([
|
||||
'one.example.org' => true,
|
||||
'one.*' => false,
|
||||
));
|
||||
$subsite2 = $this->createSubsiteWithDomains(array(
|
||||
]);
|
||||
$subsite2 = $this->createSubsiteWithDomains([
|
||||
'two.mysite.com' => true,
|
||||
'*.mysite.com' => false,
|
||||
'subdomain.onmultiplesubsites.com' => false,
|
||||
));
|
||||
$subsite3 = $this->createSubsiteWithDomains(array(
|
||||
]);
|
||||
$subsite3 = $this->createSubsiteWithDomains([
|
||||
'three.*' => true, // wildcards in primary domain are not recommended
|
||||
'subdomain.unique.com' => false,
|
||||
'*.onmultiplesubsites.com' => false,
|
||||
));
|
||||
]);
|
||||
|
||||
$this->assertEquals(
|
||||
$subsite3->ID,
|
||||
@ -177,15 +177,15 @@ class SubsiteTest extends BaseSubsiteTest
|
||||
}
|
||||
|
||||
// Much more expressive than YML in this case
|
||||
$subsite1 = $this->createSubsiteWithDomains(array(
|
||||
$subsite1 = $this->createSubsiteWithDomains([
|
||||
'example.org' => true,
|
||||
'example.com' => false,
|
||||
'*.wildcard.com' => false,
|
||||
));
|
||||
$subsite2 = $this->createSubsiteWithDomains(array(
|
||||
]);
|
||||
$subsite2 = $this->createSubsiteWithDomains([
|
||||
'www.example.org' => true,
|
||||
'www.wildcard.com' => false,
|
||||
));
|
||||
]);
|
||||
|
||||
Subsite::$strict_subdomain_matching = false;
|
||||
|
||||
@ -241,16 +241,16 @@ class SubsiteTest extends BaseSubsiteTest
|
||||
|
||||
protected function createSubsiteWithDomains($domains)
|
||||
{
|
||||
$subsite = new Subsite(array(
|
||||
$subsite = new Subsite([
|
||||
'Title' => 'My Subsite'
|
||||
));
|
||||
]);
|
||||
$subsite->write();
|
||||
foreach ($domains as $domainStr => $isPrimary) {
|
||||
$domain = new SubsiteDomain(array(
|
||||
$domain = new SubsiteDomain([
|
||||
'Domain' => $domainStr,
|
||||
'IsPrimary' => $isPrimary,
|
||||
'SubsiteID' => $subsite->ID
|
||||
));
|
||||
]);
|
||||
$domain->write();
|
||||
}
|
||||
|
||||
@ -277,13 +277,15 @@ class SubsiteTest extends BaseSubsiteTest
|
||||
$this->objFromFixture(Subsite::class, 'domaintest3')->domain());
|
||||
|
||||
$this->assertEquals($_SERVER['HTTP_HOST'], singleton(Subsite::class)->PrimaryDomain);
|
||||
$this->assertEquals('http://'.$_SERVER['HTTP_HOST'].Director::baseURL(), singleton(Subsite::class)->absoluteBaseURL());
|
||||
$this->assertEquals('http://' . $_SERVER['HTTP_HOST'] . Director::baseURL(),
|
||||
singleton(Subsite::class)->absoluteBaseURL());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that Subsite and SubsiteDomain both respect http protocol correctly
|
||||
*/
|
||||
public function testDomainProtocol() {
|
||||
public function testDomainProtocol()
|
||||
{
|
||||
// domaintest2 has 'protocol'
|
||||
$subsite2 = $this->objFromFixture(Subsite::class, 'domaintest2');
|
||||
$domain2a = $this->objFromFixture(SubsiteDomain::class, 'dt2a');
|
||||
@ -328,17 +330,17 @@ class SubsiteTest extends BaseSubsiteTest
|
||||
public function testAllSites()
|
||||
{
|
||||
$subsites = Subsite::all_sites();
|
||||
$this->assertDOSEquals(array(
|
||||
array('Title' =>'Main site'),
|
||||
array('Title' =>'Template'),
|
||||
array('Title' =>'Subsite1 Template'),
|
||||
array('Title' =>'Subsite2 Template'),
|
||||
array('Title' =>'Test 1'),
|
||||
array('Title' =>'Test 2'),
|
||||
array('Title' =>'Test 3'),
|
||||
array('Title' => 'Test Non-SSL'),
|
||||
array('Title' => 'Test SSL')
|
||||
), $subsites, 'Lists all subsites');
|
||||
$this->assertDOSEquals([
|
||||
['Title' => 'Main site'],
|
||||
['Title' => 'Template'],
|
||||
['Title' => 'Subsite1 Template'],
|
||||
['Title' => 'Subsite2 Template'],
|
||||
['Title' => 'Test 1'],
|
||||
['Title' => 'Test 2'],
|
||||
['Title' => 'Test 3'],
|
||||
['Title' => 'Test Non-SSL'],
|
||||
['Title' => 'Test SSL']
|
||||
], $subsites, 'Lists all subsites');
|
||||
}
|
||||
|
||||
public function testAllAccessibleSites()
|
||||
@ -346,9 +348,9 @@ class SubsiteTest extends BaseSubsiteTest
|
||||
$member = $this->objFromFixture(Member::class, 'subsite1member');
|
||||
|
||||
$subsites = Subsite::all_accessible_sites(true, 'Main site', $member);
|
||||
$this->assertDOSEquals(array(
|
||||
array('Title' =>'Subsite1 Template')
|
||||
), $subsites, 'Lists member-accessible sites.');
|
||||
$this->assertDOSEquals([
|
||||
['Title' => 'Subsite1 Template']
|
||||
], $subsites, 'Lists member-accessible sites.');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -366,7 +368,7 @@ class SubsiteTest extends BaseSubsiteTest
|
||||
$this->objFromFixture(Member::class, 'admin'));
|
||||
$adminSiteTitles = $adminSites->column('Title');
|
||||
sort($adminSiteTitles);
|
||||
$this->assertEquals(array(
|
||||
$this->assertEquals([
|
||||
'Subsite1 Template',
|
||||
'Subsite2 Template',
|
||||
'Template',
|
||||
@ -375,7 +377,7 @@ class SubsiteTest extends BaseSubsiteTest
|
||||
'Test 3',
|
||||
'Test Non-SSL',
|
||||
'Test SSL'
|
||||
), array_values($adminSiteTitles));
|
||||
], array_values($adminSiteTitles));
|
||||
|
||||
$member2Sites = Subsite::accessible_sites(
|
||||
'CMS_ACCESS_CMSMain', false, null,
|
||||
@ -398,31 +400,31 @@ class SubsiteTest extends BaseSubsiteTest
|
||||
'Default permissions granted for super-admin'
|
||||
);
|
||||
$this->assertTrue(
|
||||
Subsite::hasMainSitePermission($admin, array('ADMIN')),
|
||||
Subsite::hasMainSitePermission($admin, ['ADMIN']),
|
||||
'ADMIN permissions granted for super-admin'
|
||||
);
|
||||
$this->assertFalse(
|
||||
Subsite::hasMainSitePermission($subsite1admin, array('ADMIN')),
|
||||
Subsite::hasMainSitePermission($subsite1admin, ['ADMIN']),
|
||||
'ADMIN permissions (on main site) denied for subsite1 admin'
|
||||
);
|
||||
$this->assertFalse(
|
||||
Subsite::hasMainSitePermission($subsite1admin, array('CMS_ACCESS_CMSMain')),
|
||||
Subsite::hasMainSitePermission($subsite1admin, ['CMS_ACCESS_CMSMain']),
|
||||
'CMS_ACCESS_CMSMain (on main site) denied for subsite1 admin'
|
||||
);
|
||||
$this->assertFalse(
|
||||
Subsite::hasMainSitePermission($allsubsitesauthor, array('ADMIN')),
|
||||
Subsite::hasMainSitePermission($allsubsitesauthor, ['ADMIN']),
|
||||
'ADMIN permissions (on main site) denied for CMS author with edit rights on all subsites'
|
||||
);
|
||||
$this->assertTrue(
|
||||
Subsite::hasMainSitePermission($allsubsitesauthor, array('CMS_ACCESS_CMSMain')),
|
||||
Subsite::hasMainSitePermission($allsubsitesauthor, ['CMS_ACCESS_CMSMain']),
|
||||
'CMS_ACCESS_CMSMain (on main site) granted for CMS author with edit rights on all subsites'
|
||||
);
|
||||
$this->assertFalse(
|
||||
Subsite::hasMainSitePermission($subsite1member, array('ADMIN')),
|
||||
Subsite::hasMainSitePermission($subsite1member, ['ADMIN']),
|
||||
'ADMIN (on main site) denied for subsite1 subsite1 cms author'
|
||||
);
|
||||
$this->assertFalse(
|
||||
Subsite::hasMainSitePermission($subsite1member, array('CMS_ACCESS_CMSMain')),
|
||||
Subsite::hasMainSitePermission($subsite1member, ['CMS_ACCESS_CMSMain']),
|
||||
'CMS_ACCESS_CMSMain (on main site) denied for subsite1 cms author'
|
||||
);
|
||||
}
|
||||
|
@ -13,37 +13,38 @@ use SilverStripe\Dev\FunctionalTest;
|
||||
*/
|
||||
class SubsiteXHRControllerTest extends FunctionalTest
|
||||
{
|
||||
protected static $fixture_file = 'SubsiteTest.yml';
|
||||
protected static $fixture_file = 'SubsiteTest.yml';
|
||||
|
||||
public function testCanView() {
|
||||
// Test unauthenticated access
|
||||
Session::clear('MemberID');
|
||||
$result = $this->get('SubsiteXHRController', null, array(
|
||||
'X-Pjax' => 'SubsiteList',
|
||||
'X-Requested-With' => 'XMLHttpRequest'
|
||||
));
|
||||
$this->assertEquals(403, $result->getStatusCode());
|
||||
public function testCanView()
|
||||
{
|
||||
// Test unauthenticated access
|
||||
Session::clear('MemberID');
|
||||
$result = $this->get('SubsiteXHRController', null, [
|
||||
'X-Pjax' => 'SubsiteList',
|
||||
'X-Requested-With' => 'XMLHttpRequest'
|
||||
]);
|
||||
$this->assertEquals(403, $result->getStatusCode());
|
||||
|
||||
// Login with NO permissions
|
||||
$this->logInWithPermission('NOT_CMS_PERMISSION');
|
||||
$result = $this->get('SubsiteXHRController', null, array(
|
||||
'X-Pjax' => 'SubsiteList',
|
||||
'X-Requested-With' => 'XMLHttpRequest'
|
||||
));
|
||||
$this->assertEquals(403, $result->getStatusCode());
|
||||
// Login with NO permissions
|
||||
$this->logInWithPermission('NOT_CMS_PERMISSION');
|
||||
$result = $this->get('SubsiteXHRController', null, [
|
||||
'X-Pjax' => 'SubsiteList',
|
||||
'X-Requested-With' => 'XMLHttpRequest'
|
||||
]);
|
||||
$this->assertEquals(403, $result->getStatusCode());
|
||||
|
||||
// Test cms user
|
||||
$this->logInWithPermission('CMS_ACCESS_CMSMain');
|
||||
$result = $this->get('SubsiteXHRController', null, array(
|
||||
'X-Pjax' => 'SubsiteList',
|
||||
'X-Requested-With' => 'XMLHttpRequest'
|
||||
));
|
||||
$this->assertEquals(200, $result->getStatusCode());
|
||||
$this->assertEquals('text/json', $result->getHeader('Content-Type'));
|
||||
$body = $result->getBody();
|
||||
static::assertContains('Main site', $body);
|
||||
static::assertContains('Test 1', $body);
|
||||
static::assertContains('Test 2', $body);
|
||||
static::assertContains('Test 3', $body);
|
||||
}
|
||||
// Test cms user
|
||||
$this->logInWithPermission('CMS_ACCESS_CMSMain');
|
||||
$result = $this->get('SubsiteXHRController', null, [
|
||||
'X-Pjax' => 'SubsiteList',
|
||||
'X-Requested-With' => 'XMLHttpRequest'
|
||||
]);
|
||||
$this->assertEquals(200, $result->getStatusCode());
|
||||
$this->assertEquals('text/json', $result->getHeader('Content-Type'));
|
||||
$body = $result->getBody();
|
||||
static::assertContains('Main site', $body);
|
||||
static::assertContains('Test 1', $body);
|
||||
static::assertContains('Test 2', $body);
|
||||
static::assertContains('Test 3', $body);
|
||||
}
|
||||
}
|
||||
|
@ -3,27 +3,27 @@
|
||||
namespace SilverStripe\Subsites\Tests;
|
||||
|
||||
use Page;
|
||||
use SilverStripe\Assets\File;
|
||||
use SilverStripe\Assets\Filesystem;
|
||||
use SilverStripe\Assets\Tests\Storage\AssetStoreTest\TestAssetStore;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Assets\File;
|
||||
use SilverStripe\ORM\DB;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use SilverStripe\ORM\DB;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
use SilverStripe\Subsites\Pages\SubsitesVirtualPage;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
|
||||
class SubsitesVirtualPageTest extends BaseSubsiteTest
|
||||
{
|
||||
public static $fixture_file = array(
|
||||
public static $fixture_file = [
|
||||
'subsites/tests/php/SubsiteTest.yml',
|
||||
'subsites/tests/php/SubsitesVirtualPageTest.yml',
|
||||
);
|
||||
];
|
||||
|
||||
protected $illegalExtensions = array(
|
||||
'SiteTree' => array('Translatable')
|
||||
);
|
||||
protected $illegalExtensions = [
|
||||
'SiteTree' => ['Translatable']
|
||||
];
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
@ -238,12 +238,12 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest
|
||||
$page->doUnpublish();
|
||||
|
||||
Subsite::changeSubsite($vp1->SubsiteID);
|
||||
$onLive = Versioned::get_one_by_stage(SubsitesVirtualPage::class, 'Live', '"SiteTree_Live"."ID" = ' .$vp1->ID);
|
||||
$onLive = Versioned::get_one_by_stage(SubsitesVirtualPage::class, 'Live', '"SiteTree_Live"."ID" = ' . $vp1->ID);
|
||||
$this->assertNull($onLive, 'SVP has been removed from live');
|
||||
|
||||
$subsite = $this->objFromFixture(Subsite::class, 'subsite2');
|
||||
Subsite::changeSubsite($vp2->SubsiteID);
|
||||
$onLive = Versioned::get_one_by_stage(SubsitesVirtualPage::class, 'Live', '"SiteTree_Live"."ID" = ' .$vp2->ID);
|
||||
$onLive = Versioned::get_one_by_stage(SubsitesVirtualPage::class, 'Live', '"SiteTree_Live"."ID" = ' . $vp2->ID);
|
||||
$this->assertNull($onLive, 'SVP has been removed from live');
|
||||
}
|
||||
|
||||
@ -288,10 +288,10 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest
|
||||
'Does allow explicit URLSegment overrides when only existing in a different subsite'
|
||||
);
|
||||
|
||||
// When changing subsites and re-saving this page, it doesn't trigger a change
|
||||
Subsite::changeSubsite($subsite1->ID);
|
||||
$subsite1Page->write();
|
||||
$subsite2Vp->write();
|
||||
// When changing subsites and re-saving this page, it doesn't trigger a change
|
||||
Subsite::changeSubsite($subsite1->ID);
|
||||
$subsite1Page->write();
|
||||
$subsite2Vp->write();
|
||||
$this->assertEquals(
|
||||
$subsite2Vp->URLSegment,
|
||||
$subsite1Page->URLSegment,
|
||||
@ -303,8 +303,8 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest
|
||||
{
|
||||
$pages = func_get_args();
|
||||
foreach ($pages as $p) {
|
||||
Versioned::prepopulate_versionnumber_cache(SiteTree::class, 'Stage', array($p->ID));
|
||||
Versioned::prepopulate_versionnumber_cache(SiteTree::class, 'Live', array($p->ID));
|
||||
Versioned::prepopulate_versionnumber_cache(SiteTree::class, 'Stage', [$p->ID]);
|
||||
Versioned::prepopulate_versionnumber_cache(SiteTree::class, 'Live', [$p->ID]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,8 @@ use SilverStripe\Subsites\Forms\WildcardDomainField;
|
||||
/**
|
||||
* Tests {@see WildcardDomainField}
|
||||
*/
|
||||
class WildcardDomainFieldTest extends SapphireTest {
|
||||
class WildcardDomainFieldTest extends SapphireTest
|
||||
{
|
||||
|
||||
/**
|
||||
* Check that valid domains are accepted
|
||||
@ -16,7 +17,8 @@ class WildcardDomainFieldTest extends SapphireTest {
|
||||
* @dataProvider validDomains
|
||||
* @param $domain
|
||||
*/
|
||||
public function testValidDomains($domain) {
|
||||
public function testValidDomains($domain)
|
||||
{
|
||||
$field = new WildcardDomainField('DomainField');
|
||||
$this->assertTrue($field->checkHostname($domain), "Validate that {$domain} is a valid domain name");
|
||||
}
|
||||
@ -27,7 +29,8 @@ class WildcardDomainFieldTest extends SapphireTest {
|
||||
* @dataProvider invalidDomains
|
||||
* @param $domain
|
||||
*/
|
||||
public function testInvalidDomains($domain) {
|
||||
public function testInvalidDomains($domain)
|
||||
{
|
||||
$field = new WildcardDomainField('DomainField');
|
||||
$this->assertFalse($field->checkHostname($domain), "Validate that {$domain} is an invalid domain name");
|
||||
}
|
||||
@ -38,43 +41,47 @@ class WildcardDomainFieldTest extends SapphireTest {
|
||||
* @dataProvider validWildcards
|
||||
* @param $domain
|
||||
*/
|
||||
public function testValidWildcards($domain) {
|
||||
public function testValidWildcards($domain)
|
||||
{
|
||||
$field = new WildcardDomainField('DomainField');
|
||||
$this->assertTrue($field->checkHostname($domain), "Validate that {$domain} is a valid domain wildcard");
|
||||
}
|
||||
|
||||
public function validDomains() {
|
||||
return array(
|
||||
array('www.mysite.com'),
|
||||
array('domain7'),
|
||||
array('mysite.co.n-z'),
|
||||
array('subdomain.my-site.com'),
|
||||
array('subdomain.mysite')
|
||||
);
|
||||
public function validDomains()
|
||||
{
|
||||
return [
|
||||
['www.mysite.com'],
|
||||
['domain7'],
|
||||
['mysite.co.n-z'],
|
||||
['subdomain.my-site.com'],
|
||||
['subdomain.mysite']
|
||||
];
|
||||
}
|
||||
|
||||
public function invalidDomains() {
|
||||
return array(
|
||||
array('-mysite'),
|
||||
array('.mysite'),
|
||||
array('mys..ite'),
|
||||
array('mysite-'),
|
||||
array('mysite.'),
|
||||
array('-mysite.*'),
|
||||
array('.mysite.*'),
|
||||
array('mys..ite.*'),
|
||||
array('*.mysite-'),
|
||||
array('*.mysite.')
|
||||
);
|
||||
public function invalidDomains()
|
||||
{
|
||||
return [
|
||||
['-mysite'],
|
||||
['.mysite'],
|
||||
['mys..ite'],
|
||||
['mysite-'],
|
||||
['mysite.'],
|
||||
['-mysite.*'],
|
||||
['.mysite.*'],
|
||||
['mys..ite.*'],
|
||||
['*.mysite-'],
|
||||
['*.mysite.']
|
||||
];
|
||||
}
|
||||
|
||||
public function validWildcards() {
|
||||
return array(
|
||||
array('*.mysite.com'),
|
||||
array('mys*ite.com'),
|
||||
array('*.my-site.*'),
|
||||
array('*')
|
||||
);
|
||||
public function validWildcards()
|
||||
{
|
||||
return [
|
||||
['*.mysite.com'],
|
||||
['mys*ite.com'],
|
||||
['*.my-site.*'],
|
||||
['*']
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user