mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
FIX Run SS standard PHP linter, separate SiteTree test mock classes
This commit is contained in:
parent
9fdc1d6607
commit
8d8ee14cc2
@ -2,12 +2,10 @@
|
||||
|
||||
namespace SilverStripe\Subsites\Admin;
|
||||
|
||||
|
||||
use SilverStripe\Admin\ModelAdmin;
|
||||
use SilverStripe\Subsites\Forms\GridFieldSubsiteDetailForm;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
|
||||
|
||||
/**
|
||||
* Admin interface to manage and create {@link Subsite} instances.
|
||||
*
|
||||
|
@ -2,12 +2,10 @@
|
||||
|
||||
namespace SilverStripe\Subsites\Controller;
|
||||
|
||||
|
||||
use SilverStripe\Admin\LeftAndMain;
|
||||
use SilverStripe\Security\Permission;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
|
||||
|
||||
/**
|
||||
* Section-agnostic PJAX controller.
|
||||
*/
|
||||
@ -69,5 +67,4 @@ class SubsiteXHRController extends LeftAndMain
|
||||
{
|
||||
return $this->renderWith('Includes/SubsiteList');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ namespace SilverStripe\Subsites\Extensions;
|
||||
use SilverStripe\Core\Extension;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
use SilverStripe\View\SSViewer;
|
||||
|
||||
/**
|
||||
* @package subsites
|
||||
*/
|
||||
|
@ -67,8 +67,10 @@ class FileSubsites extends DataExtension
|
||||
$fields->push(new LiteralField(
|
||||
'Message',
|
||||
'<p class="message notice">' .
|
||||
_t('ASSETADMIN.SUBSITENOTICE',
|
||||
'Folders and files created in the main site are accessible by all subsites.')
|
||||
_t(
|
||||
'ASSETADMIN.SUBSITENOTICE',
|
||||
'Folders and files created in the main site are accessible by all subsites.'
|
||||
)
|
||||
. '</p>'
|
||||
));
|
||||
}
|
||||
|
@ -88,7 +88,8 @@ class GroupSubsites extends DataExtension implements PermissionProvider
|
||||
// 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',
|
||||
$fields->addFieldToTab('Root.Subsites', new OptionsetField(
|
||||
'AccessAllSubsites',
|
||||
_t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'),
|
||||
[
|
||||
1 => _t('GroupSubsites.ACCESSALL', 'All subsites'),
|
||||
@ -97,18 +98,24 @@ class GroupSubsites extends DataExtension implements PermissionProvider
|
||||
));
|
||||
|
||||
unset($subsiteMap[0]);
|
||||
$fields->addFieldToTab('Root.Subsites', new CheckboxSetField('Subsites', '',
|
||||
$subsiteMap));
|
||||
|
||||
$fields->addFieldToTab('Root.Subsites', new CheckboxSetField(
|
||||
'Subsites',
|
||||
'',
|
||||
$subsiteMap
|
||||
));
|
||||
} else {
|
||||
if (sizeof($subsiteMap) <= 1) {
|
||||
$fields->addFieldToTab('Root.Subsites', new ReadonlyField('SubsitesHuman',
|
||||
$fields->addFieldToTab('Root.Subsites', new ReadonlyField(
|
||||
'SubsitesHuman',
|
||||
_t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'),
|
||||
reset($subsiteMap)));
|
||||
reset($subsiteMap)
|
||||
));
|
||||
} else {
|
||||
$fields->addFieldToTab('Root.Subsites', new CheckboxSetField('Subsites',
|
||||
$fields->addFieldToTab('Root.Subsites', new CheckboxSetField(
|
||||
'Subsites',
|
||||
_t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'),
|
||||
$subsiteMap));
|
||||
$subsiteMap
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -147,7 +154,6 @@ class GroupSubsites extends DataExtension implements PermissionProvider
|
||||
|
||||
// If you're querying by ID, ignore the sub-site - this is a bit ugly...
|
||||
if (!$query->filtersOnID()) {
|
||||
|
||||
/*if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID;
|
||||
|
||||
else */
|
||||
@ -156,9 +162,13 @@ class GroupSubsites extends DataExtension implements PermissionProvider
|
||||
// Don't filter by Group_Subsites if we've already done that
|
||||
$hasGroupSubsites = false;
|
||||
foreach ($query->getFrom() as $item) {
|
||||
if ((is_array($item) && strpos($item['table'],
|
||||
'Group_Subsites') !== false) || (!is_array($item) && strpos($item,
|
||||
'Group_Subsites') !== false)
|
||||
if ((is_array($item) && strpos(
|
||||
$item['table'],
|
||||
'Group_Subsites'
|
||||
) !== false) || (!is_array($item) && strpos(
|
||||
$item,
|
||||
'Group_Subsites'
|
||||
) !== false)
|
||||
) {
|
||||
$hasGroupSubsites = true;
|
||||
break;
|
||||
@ -220,8 +230,10 @@ class GroupSubsites extends DataExtension implements PermissionProvider
|
||||
'SECURITY_SUBSITE_GROUP' => [
|
||||
'name' => _t('GroupSubsites.MANAGE_SUBSITES', 'Manage subsites for groups'),
|
||||
'category' => _t('Permissions.PERMISSIONS_CATEGORY', 'Roles and access permissions'),
|
||||
'help' => _t('GroupSubsites.MANAGE_SUBSITES_HELP',
|
||||
'Ability to limit the permissions for a group to one or more subsites.'),
|
||||
'help' => _t(
|
||||
'GroupSubsites.MANAGE_SUBSITES_HELP',
|
||||
'Ability to limit the permissions for a group to one or more subsites.'
|
||||
),
|
||||
'sort' => 200
|
||||
]
|
||||
];
|
||||
|
@ -340,15 +340,17 @@ class LeftAndMainSubsites extends Extension
|
||||
public function onAfterSave($record)
|
||||
{
|
||||
if ($record->hasMethod('NormalRelated') && ($record->NormalRelated() || $record->ReverseRelated())) {
|
||||
$this->owner->response->addHeader('X-Status',
|
||||
rawurlencode(_t('LeftAndMainSubsites.Saved', 'Saved, please update related pages.')));
|
||||
$this->owner->response->addHeader(
|
||||
'X-Status',
|
||||
rawurlencode(_t('LeftAndMainSubsites.Saved', 'Saved, please update related pages.'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param Form $form
|
||||
*/
|
||||
/**
|
||||
* @param array $data
|
||||
* @param Form $form
|
||||
*/
|
||||
public function copytosubsite($data, $form)
|
||||
{
|
||||
$page = DataObject::get_by_id('SiteTree', $data['ID']);
|
||||
|
@ -108,13 +108,18 @@ class SiteTreeSubsites extends DataExtension
|
||||
if ($isDefaultSubsite && $subsitesMap) {
|
||||
$fields->addFieldToTab(
|
||||
'Root.Main',
|
||||
ToggleCompositeField::create('SubsiteOperations',
|
||||
ToggleCompositeField::create(
|
||||
'SubsiteOperations',
|
||||
_t('SiteTreeSubsites.SubsiteOperations', 'Subsite Operations'),
|
||||
[
|
||||
new DropdownField('CopyToSubsiteID', _t('SiteTreeSubsites.CopyToSubsite',
|
||||
'Copy page to subsite'), $subsitesMap),
|
||||
new CheckboxField('CopyToSubsiteWithChildren',
|
||||
_t('SiteTreeSubsites.CopyToSubsiteWithChildren', 'Include children pages?')),
|
||||
new DropdownField('CopyToSubsiteID', _t(
|
||||
'SiteTreeSubsites.CopyToSubsite',
|
||||
'Copy page to subsite'
|
||||
), $subsitesMap),
|
||||
new CheckboxField(
|
||||
'CopyToSubsiteWithChildren',
|
||||
_t('SiteTreeSubsites.CopyToSubsiteWithChildren', 'Include children pages?')
|
||||
),
|
||||
$copyAction = new FormAction(
|
||||
'copytosubsite',
|
||||
_t('SiteTreeSubsites.CopyAction', 'Copy')
|
||||
@ -393,9 +398,11 @@ class SiteTreeSubsites extends DataExtension
|
||||
|
||||
$origDisableSubsiteFilter = Subsite::$disable_subsite_filter;
|
||||
Subsite::disable_subsite_filter(true);
|
||||
$candidatePage = DataObject::get_one(SiteTree::class,
|
||||
$candidatePage = DataObject::get_one(
|
||||
SiteTree::class,
|
||||
"\"URLSegment\" = '" . Convert::raw2sql(urldecode($rest)) . "' AND \"SubsiteID\" = " . $subsiteID,
|
||||
false);
|
||||
false
|
||||
);
|
||||
Subsite::disable_subsite_filter($origDisableSubsiteFilter);
|
||||
|
||||
if ($candidatePage) {
|
||||
|
@ -2,10 +2,8 @@
|
||||
|
||||
namespace SilverStripe\Subsites\Extensions;
|
||||
|
||||
|
||||
use SilverStripe\Core\Extension;
|
||||
|
||||
|
||||
/*
|
||||
* Simple extension to show admins in the menu of subsites.
|
||||
* If an admin area should be available to a subsite, you can attach
|
||||
|
@ -36,8 +36,11 @@ class GridFieldSubsiteDetailForm_ItemRequest extends GridFieldDetailForm_ItemReq
|
||||
$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);
|
||||
}
|
||||
@ -57,5 +60,4 @@ class GridFieldSubsiteDetailForm_ItemRequest extends GridFieldDetailForm_ItemReq
|
||||
|
||||
return parent::doSave($data, $form);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,14 +2,12 @@
|
||||
|
||||
namespace SilverStripe\Subsites\Forms;
|
||||
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\Session;
|
||||
use SilverStripe\Forms\TreeDropdownField;
|
||||
use SilverStripe\View\Requirements;
|
||||
|
||||
|
||||
/**
|
||||
* Wraps around a TreedropdownField to add ability for temporary
|
||||
* switching of subsite sessions.
|
||||
|
@ -2,6 +2,7 @@
|
||||
namespace SilverStripe\Subsites\Forms;
|
||||
|
||||
use SilverStripe\Forms\TextField;
|
||||
|
||||
/**
|
||||
* A text field that accepts only valid domain names, but allows the wildcard (*) character
|
||||
*/
|
||||
|
@ -35,7 +35,6 @@ use SilverStripe\Security\Permission;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use UnexpectedValueException;
|
||||
|
||||
|
||||
/**
|
||||
* A dynamically created subsite. SiteTree objects can now belong to a subsite.
|
||||
* You can simulate subsite access without setting up virtual hosts by appending ?SubsiteID=<ID> to the request.
|
||||
@ -231,8 +230,10 @@ class Subsite extends DataObject
|
||||
SubsiteDomain::class,
|
||||
"'$SQL_host' LIKE replace(\"SubsiteDomain\".\"Domain\",'*','%')",
|
||||
'"IsPrimary" DESC'
|
||||
)->innerJoin('Subsite',
|
||||
'"Subsite"."ID" = "SubsiteDomain"."SubsiteID" AND "Subsite"."IsPublic"=1');
|
||||
)->innerJoin(
|
||||
'Subsite',
|
||||
'"Subsite"."ID" = "SubsiteDomain"."SubsiteID" AND "Subsite"."IsPublic"=1'
|
||||
);
|
||||
}
|
||||
|
||||
if ($matchingDomains && $matchingDomains->count()) {
|
||||
@ -379,8 +380,8 @@ class Subsite extends DataObject
|
||||
$includeMainSite = true,
|
||||
$mainSiteTitle = 'Main site',
|
||||
$member = null
|
||||
)
|
||||
{
|
||||
) {
|
||||
|
||||
// Rationalise member arguments
|
||||
if (!$member) {
|
||||
$member = Member::currentUser();
|
||||
@ -408,12 +409,18 @@ class Subsite extends DataObject
|
||||
$subsites = DataList::create(Subsite::class)
|
||||
->where("\"Subsite\".\"Title\" != ''")
|
||||
->leftJoin('Group_Subsites', '"Group_Subsites"."SubsiteID" = "Subsite"."ID"')
|
||||
->innerJoin('Group',
|
||||
'"Group"."ID" = "Group_Subsites"."GroupID" OR "Group"."AccessAllSubsites" = 1')
|
||||
->innerJoin('Group_Members',
|
||||
"\"Group_Members\".\"GroupID\"=\"Group\".\"ID\" AND \"Group_Members\".\"MemberID\" = $member->ID")
|
||||
->innerJoin('Permission',
|
||||
"\"Group\".\"ID\"=\"Permission\".\"GroupID\" AND \"Permission\".\"Code\" IN ($SQL_codes, 'CMS_ACCESS_LeftAndMain', 'ADMIN')");
|
||||
->innerJoin(
|
||||
'Group',
|
||||
'"Group"."ID" = "Group_Subsites"."GroupID" OR "Group"."AccessAllSubsites" = 1'
|
||||
)
|
||||
->innerJoin(
|
||||
'Group_Members',
|
||||
"\"Group_Members\".\"GroupID\"=\"Group\".\"ID\" AND \"Group_Members\".\"MemberID\" = $member->ID"
|
||||
)
|
||||
->innerJoin(
|
||||
'Permission',
|
||||
"\"Group\".\"ID\"=\"Permission\".\"GroupID\" AND \"Permission\".\"Code\" IN ($SQL_codes, 'CMS_ACCESS_LeftAndMain', 'ADMIN')"
|
||||
);
|
||||
|
||||
if (!$subsites) {
|
||||
$subsites = new ArrayList();
|
||||
@ -423,14 +430,20 @@ class Subsite extends DataObject
|
||||
$rolesSubsites = DataList::create(Subsite::class)
|
||||
->where("\"Subsite\".\"Title\" != ''")
|
||||
->leftJoin('Group_Subsites', '"Group_Subsites"."SubsiteID" = "Subsite"."ID"')
|
||||
->innerJoin('Group',
|
||||
'"Group"."ID" = "Group_Subsites"."GroupID" OR "Group"."AccessAllSubsites" = 1')
|
||||
->innerJoin('Group_Members',
|
||||
"\"Group_Members\".\"GroupID\"=\"Group\".\"ID\" AND \"Group_Members\".\"MemberID\" = $member->ID")
|
||||
->innerJoin(
|
||||
'Group',
|
||||
'"Group"."ID" = "Group_Subsites"."GroupID" OR "Group"."AccessAllSubsites" = 1'
|
||||
)
|
||||
->innerJoin(
|
||||
'Group_Members',
|
||||
"\"Group_Members\".\"GroupID\"=\"Group\".\"ID\" AND \"Group_Members\".\"MemberID\" = $member->ID"
|
||||
)
|
||||
->innerJoin('Group_Roles', '"Group_Roles"."GroupID"="Group"."ID"')
|
||||
->innerJoin('PermissionRole', '"Group_Roles"."PermissionRoleID"="PermissionRole"."ID"')
|
||||
->innerJoin('PermissionRoleCode',
|
||||
"\"PermissionRole\".\"ID\"=\"PermissionRoleCode\".\"RoleID\" AND \"PermissionRoleCode\".\"Code\" IN ($SQL_codes, 'CMS_ACCESS_LeftAndMain', 'ADMIN')");
|
||||
->innerJoin(
|
||||
'PermissionRoleCode',
|
||||
"\"PermissionRole\".\"ID\"=\"PermissionRoleCode\".\"RoleID\" AND \"PermissionRoleCode\".\"Code\" IN ($SQL_codes, 'CMS_ACCESS_LeftAndMain', 'ADMIN')"
|
||||
);
|
||||
|
||||
if (!$subsites && $rolesSubsites) {
|
||||
return $rolesSubsites;
|
||||
@ -655,8 +668,10 @@ class Subsite extends DataObject
|
||||
} else {
|
||||
$domainTable = new LiteralField(
|
||||
'Domains',
|
||||
'<p>' . _t('Subsite.DOMAINSAVEFIRST',
|
||||
'You can only add domains after saving for the first time') . '</p>'
|
||||
'<p>' . _t(
|
||||
'Subsite.DOMAINSAVEFIRST',
|
||||
'You can only add domains after saving for the first time'
|
||||
) . '</p>'
|
||||
);
|
||||
}
|
||||
|
||||
@ -674,13 +689,13 @@ class Subsite extends DataObject
|
||||
asort($pageTypeMap);
|
||||
|
||||
$fields = new FieldList(
|
||||
$subsiteTabs = new TabSet('Root',
|
||||
$subsiteTabs = new TabSet(
|
||||
'Root',
|
||||
new Tab(
|
||||
'Configuration',
|
||||
_t('Subsite.TabTitleConfig', 'Configuration'),
|
||||
HeaderField::create('ConfigForSubsiteHeaderField', 'Subsite Configuration'),
|
||||
TextField::create('Title', $this->fieldLabel('Title'), $this->Title),
|
||||
|
||||
HeaderField::create(
|
||||
'DomainsForSubsiteHeaderField',
|
||||
_t('Subsite.DomainsHeadline', 'Domains for this subsite')
|
||||
@ -690,7 +705,6 @@ class Subsite extends DataObject
|
||||
// new TextField('RedirectURL', 'Redirect to URL', $this->RedirectURL),
|
||||
CheckboxField::create('DefaultSite', $this->fieldLabel('DefaultSite'), $this->DefaultSite),
|
||||
CheckboxField::create('IsPublic', $this->fieldLabel('IsPublic'), $this->IsPublic),
|
||||
|
||||
LiteralField::create(
|
||||
'PageTypeBlacklistToggle',
|
||||
sprintf(
|
||||
@ -712,9 +726,12 @@ class Subsite extends DataObject
|
||||
// If there are any themes available, add the dropdown
|
||||
$themes = $this->allowedThemes();
|
||||
if (!empty($themes)) {
|
||||
$fields->addFieldToTab('Root.Configuration',
|
||||
$fields->addFieldToTab(
|
||||
'Root.Configuration',
|
||||
DropdownField::create('Theme', $this->fieldLabel('Theme'), $this->allowedThemes(), $this->Theme)
|
||||
->setEmptyString(_t('Subsite.ThemeFieldEmptyString', '-')), 'PageTypeBlacklistToggle');
|
||||
->setEmptyString(_t('Subsite.ThemeFieldEmptyString', '-')),
|
||||
'PageTypeBlacklistToggle'
|
||||
);
|
||||
}
|
||||
|
||||
$subsiteTabs->addExtraClass('subsite-model');
|
||||
|
@ -10,7 +10,6 @@ use SilverStripe\Forms\OptionsetField;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\Subsites\Forms\WildcardDomainField;
|
||||
|
||||
|
||||
/**
|
||||
* @property string $Domain domain name of this subsite. Can include wildcards. Do not include the URL scheme here
|
||||
* @property string $Protocol Required protocol (http or https) if only one is supported. 'automatic' implies
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace SilverStripe\Subsites\Pages;
|
||||
|
||||
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\CMS\Model\VirtualPage;
|
||||
use SilverStripe\Control\Controller;
|
||||
|
@ -2,13 +2,11 @@
|
||||
|
||||
namespace SilverStripe\Subsites\Reports;
|
||||
|
||||
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\TreeMultiselectField;
|
||||
use SilverStripe\Reports\ReportWrapper;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a subsite-aware version of another report.
|
||||
* Pass another report (or its classname) into the constructor.
|
||||
@ -84,5 +82,4 @@ class SubsiteReportWrapper extends ReportWrapper
|
||||
// Manually manage the subsite filtering
|
||||
Subsite::$force_subsite = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace SilverStripe\Subsites\Tasks;
|
||||
|
||||
|
||||
use InvalidArgumentException;
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Dev\BuildTask;
|
||||
@ -11,7 +10,6 @@ use SilverStripe\Subsites\Model\Subsite;
|
||||
use SilverStripe\Subsites\Pages\SubsitesVirtualPage;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
|
||||
|
||||
/**
|
||||
* Handy alternative to copying pages when creating a subsite through the UI.
|
||||
*
|
||||
|
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
|
||||
class SubsiteXHRControllerTest extends FunctionalTest
|
||||
{
|
||||
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());
|
||||
|
||||
// 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());
|
||||
|
||||
// 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();
|
||||
$this->assertContains('Main site', $body);
|
||||
$this->assertContains('Test 1', $body);
|
||||
$this->assertContains('Test 2', $body);
|
||||
$this->assertContains('Test 3', $body);
|
||||
}
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
|
||||
/**
|
||||
* Tests {@see WildcardDomainField}
|
||||
*/
|
||||
class WildcardDomainFieldTest extends SapphireTest {
|
||||
|
||||
/**
|
||||
* Check that valid domains are accepted
|
||||
*
|
||||
* @dataProvider validDomains
|
||||
*/
|
||||
public function testValidDomains($domain) {
|
||||
$field = new WildcardDomainField('DomainField');
|
||||
$this->assertTrue($field->checkHostname($domain), "Validate that {$domain} is a valid domain name");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that valid domains are accepted
|
||||
*
|
||||
* @dataProvider invalidDomains
|
||||
*/
|
||||
public function testInvalidDomains($domain) {
|
||||
$field = new WildcardDomainField('DomainField');
|
||||
$this->assertFalse($field->checkHostname($domain), "Validate that {$domain} is an invalid domain name");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that valid domains are accepted
|
||||
*
|
||||
* @dataProvider validWildcards
|
||||
*/
|
||||
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 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 validWildcards() {
|
||||
return array(
|
||||
array('*.mysite.com'),
|
||||
array('mys*ite.com'),
|
||||
array('*.my-site.*'),
|
||||
array('*')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -76,10 +76,12 @@ class LeftAndMainSubsitesTest extends FunctionalTest
|
||||
|
||||
$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.');
|
||||
$this->assertEquals(
|
||||
$id,
|
||||
Subsite::currentSubsiteID(),
|
||||
'The current subsite has not been changed in the process of checking permissions for admin user.'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function testShouldChangeSubsite()
|
||||
|
@ -18,22 +18,24 @@ use SilverStripe\SiteConfig\SiteConfig;
|
||||
use SilverStripe\Subsites\Extensions\SiteTreeSubsites;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
use SilverStripe\Subsites\Pages\SubsitesVirtualPage;
|
||||
use SilverStripe\Subsites\Tests\SiteTreeSubsitesTest\TestClassA;
|
||||
use SilverStripe\Subsites\Tests\SiteTreeSubsitesTest\TestClassB;
|
||||
use SilverStripe\Subsites\Tests\SiteTreeSubsitesTest\TestErrorPage;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use SilverStripe\View\SSViewer;
|
||||
|
||||
class SiteTreeSubsitesTest extends BaseSubsiteTest
|
||||
{
|
||||
protected static $fixture_file = 'subsites/tests/php/SubsiteTest.yml';
|
||||
|
||||
public static $fixture_file = 'subsites/tests/php/SubsiteTest.yml';
|
||||
|
||||
protected $extraDataObjects = [
|
||||
'SiteTreeSubsitesTest_ClassA',
|
||||
'SiteTreeSubsitesTest_ClassB',
|
||||
'SiteTreeSubsitesTest_ErrorPage'
|
||||
protected static $extra_dataobjects = [
|
||||
TestClassA::class,
|
||||
TestClassB::class,
|
||||
TestErrorPage::class
|
||||
];
|
||||
|
||||
protected $illegalExtensions = [
|
||||
SiteTree::class => ['Translatable']
|
||||
protected static $illegal_extensions = [
|
||||
SiteTree::class => ['Translatable'] // @todo implement Translatable namespace
|
||||
];
|
||||
|
||||
public function testPagesInDifferentSubsitesCanShareURLSegment()
|
||||
@ -51,7 +53,9 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
||||
$pageMainOther->write();
|
||||
$pageMainOther->copyVersionToStage('Stage', 'Live');
|
||||
|
||||
$this->assertNotEquals($pageMain->URLSegment, $pageMainOther->URLSegment,
|
||||
$this->assertNotEquals(
|
||||
$pageMain->URLSegment,
|
||||
$pageMainOther->URLSegment,
|
||||
'Pages in same subsite cant share the same URL'
|
||||
);
|
||||
|
||||
@ -62,7 +66,9 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
||||
$pageSubsite1->write();
|
||||
$pageSubsite1->copyVersionToStage('Stage', 'Live');
|
||||
|
||||
$this->assertEquals($pageMain->URLSegment, $pageSubsite1->URLSegment,
|
||||
$this->assertEquals(
|
||||
$pageMain->URLSegment,
|
||||
$pageSubsite1->URLSegment,
|
||||
'Pages in different subsites can share the same URL'
|
||||
);
|
||||
}
|
||||
@ -171,31 +177,37 @@ 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(',', [TestClassA::class, ErrorPage::class]);
|
||||
$s1->write();
|
||||
|
||||
Subsite::changeSubsite($s1);
|
||||
$settingsFields = $page->getSettingsFields()->dataFieldByName('ClassName')->getSource();
|
||||
|
||||
$this->assertArrayNotHasKey(ErrorPage::class,
|
||||
$this->assertArrayNotHasKey(
|
||||
ErrorPage::class,
|
||||
$settingsFields
|
||||
);
|
||||
$this->assertArrayNotHasKey(SiteTreeSubsitesTest_ClassA::class,
|
||||
$this->assertArrayNotHasKey(
|
||||
TestClassA::class,
|
||||
$settingsFields
|
||||
);
|
||||
$this->assertArrayHasKey(SiteTreeSubsitesTest_ClassB::class,
|
||||
$this->assertArrayHasKey(
|
||||
TestClassB::class,
|
||||
$settingsFields
|
||||
);
|
||||
|
||||
Subsite::changeSubsite($s2);
|
||||
$settingsFields = $page->getSettingsFields()->dataFieldByName('ClassName')->getSource();
|
||||
$this->assertArrayHasKey(ErrorPage::class,
|
||||
$this->assertArrayHasKey(
|
||||
ErrorPage::class,
|
||||
$settingsFields
|
||||
);
|
||||
$this->assertArrayHasKey(SiteTreeSubsitesTest_ClassA::class,
|
||||
$this->assertArrayHasKey(
|
||||
TestClassA::class,
|
||||
$settingsFields
|
||||
);
|
||||
$this->assertArrayHasKey(SiteTreeSubsitesTest_ClassB::class,
|
||||
$this->assertArrayHasKey(
|
||||
TestClassB::class,
|
||||
$settingsFields
|
||||
);
|
||||
}
|
||||
@ -238,22 +250,22 @@ 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(',', [TestClassA::class, ErrorPage::class]);
|
||||
$s1->write();
|
||||
|
||||
Subsite::changeSubsite($s1);
|
||||
$hints = Convert::json2array($cmsmain->SiteTreeHints());
|
||||
$classes = $hints['Root']['disallowedChildren'];
|
||||
static::assertContains(ErrorPage::class, $classes);
|
||||
static::assertContains(SiteTreeSubsitesTest_ClassA::class, $classes);
|
||||
static::assertNotContains(SiteTreeSubsitesTest_ClassB::class, $classes);
|
||||
static::assertContains(TestClassA::class, $classes);
|
||||
static::assertNotContains(TestClassB::class, $classes);
|
||||
|
||||
Subsite::changeSubsite($s2);
|
||||
$hints = Convert::json2array($cmsmain->SiteTreeHints());
|
||||
$classes = $hints['Root']['disallowedChildren'];
|
||||
static::assertNotContains(ErrorPage::class, $classes);
|
||||
static::assertNotContains(SiteTreeSubsitesTest_ClassA::class, $classes);
|
||||
static::assertNotContains(SiteTreeSubsitesTest_ClassB::class, $classes);
|
||||
static::assertNotContains(TestClassA::class, $classes);
|
||||
static::assertNotContains(TestClassB::class, $classes);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -280,8 +292,11 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
||||
$subsite1Home->write();
|
||||
$this->assertEquals('home', $subsite1Home->URLSegment);
|
||||
$subsite1Home->doPublish();
|
||||
$subsite1HomeLive = Versioned::get_one_by_stage('Page', 'Live',
|
||||
sprintf('"SiteTree"."ID" = \'%d\'', $subsite1Home->ID));
|
||||
$subsite1HomeLive = Versioned::get_one_by_stage(
|
||||
'Page',
|
||||
'Live',
|
||||
sprintf('"SiteTree"."ID" = \'%d\'', $subsite1Home->ID)
|
||||
);
|
||||
$this->assertEquals('home', $subsite1HomeLive->URLSegment);
|
||||
|
||||
// Creating a new page in a subsite doesn't conflict with urls in other subsites
|
||||
@ -294,8 +309,11 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
||||
$subsite1NewPage->write();
|
||||
$this->assertEquals('important-page', $subsite1NewPage->URLSegment);
|
||||
$subsite1NewPage->doPublish();
|
||||
$subsite1NewPageLive = Versioned::get_one_by_stage('Page', 'Live',
|
||||
sprintf('"SiteTree"."ID" = \'%d\'', $subsite1NewPage->ID));
|
||||
$subsite1NewPageLive = Versioned::get_one_by_stage(
|
||||
'Page',
|
||||
'Live',
|
||||
sprintf('"SiteTree"."ID" = \'%d\'', $subsite1NewPage->ID)
|
||||
);
|
||||
$this->assertEquals('important-page', $subsite1NewPageLive->URLSegment);
|
||||
|
||||
// Creating a new page in a subsite DOES conflict with urls in the same subsite
|
||||
@ -306,8 +324,11 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
||||
$subsite1NewPage2->write();
|
||||
$this->assertEquals('important-page-2', $subsite1NewPage2->URLSegment);
|
||||
$subsite1NewPage2->doPublish();
|
||||
$subsite1NewPage2Live = Versioned::get_one_by_stage('Page', 'Live',
|
||||
sprintf('"SiteTree"."ID" = \'%d\'', $subsite1NewPage2->ID));
|
||||
$subsite1NewPage2Live = Versioned::get_one_by_stage(
|
||||
'Page',
|
||||
'Live',
|
||||
sprintf('"SiteTree"."ID" = \'%d\'', $subsite1NewPage2->ID)
|
||||
);
|
||||
$this->assertEquals('important-page-2', $subsite1NewPage2Live->URLSegment);
|
||||
|
||||
// Original page is left un-modified
|
||||
@ -326,8 +347,11 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
||||
|
||||
$moved = $page->duplicateToSubsite($newSubsite->ID, true);
|
||||
$this->assertEquals($moved->SubsiteID, $newSubsite->ID, 'Ensure returned records are on new subsite');
|
||||
$this->assertEquals($moved->AllChildren()->count(), $page->AllChildren()->count(),
|
||||
'All pages are copied across');
|
||||
$this->assertEquals(
|
||||
$moved->AllChildren()->count(),
|
||||
$page->AllChildren()->count(),
|
||||
'All pages are copied across'
|
||||
);
|
||||
}
|
||||
|
||||
public function testCopySubsiteWithoutChildren()
|
||||
@ -353,39 +377,21 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
||||
$controller = ModelAsController::controller_for($subsitePage);
|
||||
SiteTree::singleton()->extend('contentcontrollerInit', $controller);
|
||||
|
||||
$this->assertEquals(SSViewer::get_themes(), $defaultThemes,
|
||||
'Themes should not be modified when Subsite has no theme defined');
|
||||
$this->assertEquals(
|
||||
SSViewer::get_themes(),
|
||||
$defaultThemes,
|
||||
'Themes should not be modified when Subsite has no theme defined'
|
||||
);
|
||||
|
||||
$pageWithTheme = $this->objFromFixture(Page::class, 'subsite1_home');
|
||||
Subsite::changeSubsite($pageWithTheme->SubsiteID);
|
||||
$controller = ModelAsController::controller_for($pageWithTheme);
|
||||
SiteTree::singleton()->extend('contentcontrollerInit', $controller);
|
||||
$subsiteTheme = $pageWithTheme->Subsite()->Theme;
|
||||
$this->assertEquals(SSViewer::get_themes(), array_merge([$subsiteTheme], $defaultThemes),
|
||||
'Themes should be modified when Subsite has theme defined');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class SiteTreeSubsitesTest_ClassA extends SiteTree implements TestOnly
|
||||
{
|
||||
}
|
||||
|
||||
class SiteTreeSubsitesTest_ClassB extends SiteTree implements TestOnly
|
||||
{
|
||||
}
|
||||
|
||||
class SiteTreeSubsitesTest_ErrorPage extends ErrorPage implements TestOnly
|
||||
{
|
||||
/**
|
||||
* Helper method to call protected members
|
||||
*
|
||||
* @param int $statusCode
|
||||
* @return string
|
||||
*/
|
||||
public static function get_error_filename_spy($statusCode)
|
||||
{
|
||||
return self::get_error_filename($statusCode);
|
||||
$this->assertEquals(
|
||||
SSViewer::get_themes(),
|
||||
array_merge([$subsiteTheme], $defaultThemes),
|
||||
'Themes should be modified when Subsite has theme defined'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
10
tests/php/SiteTreeSubsitesTest/TestClassA.php
Normal file
10
tests/php/SiteTreeSubsitesTest/TestClassA.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Subsites\Tests\SiteTreeSubsitesTest;
|
||||
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
|
||||
class TestClassA extends SiteTree implements TestOnly
|
||||
{
|
||||
}
|
10
tests/php/SiteTreeSubsitesTest/TestClassB.php
Normal file
10
tests/php/SiteTreeSubsitesTest/TestClassB.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Subsites\Tests\SiteTreeSubsitesTest;
|
||||
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
|
||||
class TestClassB extends SiteTree implements TestOnly
|
||||
{
|
||||
}
|
20
tests/php/SiteTreeSubsitesTest/TestErrorPage.php
Normal file
20
tests/php/SiteTreeSubsitesTest/TestErrorPage.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Subsites\Tests\SiteTreeSubsitesTest;
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\ErrorPage\ErrorPage;
|
||||
|
||||
class TestErrorPage extends ErrorPage implements TestOnly
|
||||
{
|
||||
/**
|
||||
* Helper method to call protected members
|
||||
*
|
||||
* @param int $statusCode
|
||||
* @return string
|
||||
*/
|
||||
public static function get_error_filename_spy($statusCode)
|
||||
{
|
||||
return self::get_error_filename($statusCode);
|
||||
}
|
||||
}
|
@ -46,8 +46,11 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
|
||||
$this->assertRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), 'Admin is disallowed');
|
||||
|
||||
$response = $this->getAndFollowAll('SubsiteXHRController');
|
||||
$this->assertRegExp('#^Security/login.*#', $this->mainSession->lastUrl(),
|
||||
'SubsiteXHRController is disallowed');
|
||||
$this->assertRegExp(
|
||||
'#^Security/login.*#',
|
||||
$this->mainSession->lastUrl(),
|
||||
'SubsiteXHRController is disallowed'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,8 +71,11 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
|
||||
$this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section');
|
||||
|
||||
$response = $this->getAndFollowAll(SubsiteXHRController::class);
|
||||
$this->assertNotRegExp('#^Security/login.*#', $this->mainSession->lastUrl(),
|
||||
'SubsiteXHRController is reachable');
|
||||
$this->assertNotRegExp(
|
||||
'#^Security/login.*#',
|
||||
$this->mainSession->lastUrl(),
|
||||
'SubsiteXHRController is reachable'
|
||||
);
|
||||
}
|
||||
|
||||
public function testAdminIsRedirectedToObjectsSubsite()
|
||||
@ -85,20 +91,29 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
|
||||
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();
|
||||
@ -123,8 +138,11 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
|
||||
$this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section');
|
||||
|
||||
$response = $this->getAndFollowAll('SubsiteXHRController');
|
||||
$this->assertNotRegExp('#^Security/login.*#', $this->mainSession->lastUrl(),
|
||||
'SubsiteXHRController is reachable');
|
||||
$this->assertNotRegExp(
|
||||
'#^Security/login.*#',
|
||||
$this->mainSession->lastUrl(),
|
||||
'SubsiteXHRController is reachable'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -145,8 +163,11 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
|
||||
// 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');
|
||||
$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');
|
||||
@ -159,7 +180,10 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
|
||||
|
||||
// Check the standalone XHR controller.
|
||||
$response = $this->getAndFollowAll(SubsiteXHRController::class);
|
||||
$this->assertNotRegExp('#^Security/login.*#', $this->mainSession->lastUrl(),
|
||||
'SubsiteXHRController is reachable');
|
||||
$this->assertNotRegExp(
|
||||
'#^Security/login.*#',
|
||||
$this->mainSession->lastUrl(),
|
||||
'SubsiteXHRController is reachable'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -31,11 +31,15 @@ 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",
|
||||
$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');
|
||||
$this->adminLoggedInSession()
|
||||
);
|
||||
$this->assertTrue(
|
||||
strpos($response2->getBody(), 'id="Form_ItemEditForm_ID"') !== false,
|
||||
'Testing Form_ItemEditForm_ID exists'
|
||||
);
|
||||
$this->assertTrue(strpos($response2->getBody(), '<head') !== false, 'Testing <head> exists');
|
||||
}
|
||||
|
||||
@ -56,12 +60,15 @@ class SubsiteAdminTest extends BaseSubsiteTest
|
||||
|
||||
$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,
|
||||
'Subsite2 Template inaccessible');
|
||||
$this->assertArrayHasKey(
|
||||
$this->idFromFixture(Subsite::class, 'subsite1'),
|
||||
$ids,
|
||||
'Subsite1 Template inaccessible'
|
||||
);
|
||||
$this->assertArrayHasKey(
|
||||
$this->idFromFixture(Subsite::class, 'subsite2'),
|
||||
$ids,
|
||||
'Subsite2 Template inaccessible'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace subsites\tests\php;
|
||||
|
||||
|
||||
use Page;
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
@ -24,15 +23,20 @@ class SubsiteFunctionalTest extends FunctionalTest
|
||||
$subsitePage = $this->objFromFixture(Page::class, 'contact');
|
||||
$this->get($subsitePage->AbsoluteLink());
|
||||
$this->assertEquals($subsitePage->SubsiteID, Subsite::currentSubsiteID(), 'Subsite should be changed');
|
||||
$this->assertEquals(SSViewer::get_themes(), $defaultThemes,
|
||||
'Themes should not be modified when Subsite has no theme defined');
|
||||
$this->assertEquals(
|
||||
SSViewer::get_themes(),
|
||||
$defaultThemes,
|
||||
'Themes should not be modified when Subsite has no theme defined'
|
||||
);
|
||||
|
||||
$pageWithTheme = $this->objFromFixture(Page::class, 'subsite1_contactus');
|
||||
$this->get($pageWithTheme->AbsoluteLink());
|
||||
$subsiteTheme = $pageWithTheme->Subsite()->Theme;
|
||||
$this->assertEquals($pageWithTheme->SubsiteID, Subsite::currentSubsiteID(), 'Subsite should be changed');
|
||||
$this->assertEquals(SSViewer::get_themes(), array_merge([$subsiteTheme], $defaultThemes),
|
||||
'Themes should be modified when Subsite has theme defined');
|
||||
|
||||
$this->assertEquals(
|
||||
SSViewer::get_themes(),
|
||||
array_merge([$subsiteTheme], $defaultThemes),
|
||||
'Themes should be modified when Subsite has theme defined'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,9 @@ class SubsiteTest extends BaseSubsiteTest
|
||||
|
||||
$siteHome = DataObject::get_one('Page', "\"URLSegment\" = 'home'");
|
||||
$this->assertNotEquals($siteHome, false, 'Home Page for subsite not found');
|
||||
$this->assertEquals($subsite->ID, $siteHome->SubsiteID,
|
||||
$this->assertEquals(
|
||||
$subsite->ID,
|
||||
$siteHome->SubsiteID,
|
||||
'createInstance() copies existing pages retaining the same URLSegment'
|
||||
);
|
||||
|
||||
@ -262,23 +264,33 @@ class SubsiteTest extends BaseSubsiteTest
|
||||
*/
|
||||
public function testDefaultDomain()
|
||||
{
|
||||
$this->assertEquals('one.example.org',
|
||||
$this->objFromFixture(Subsite::class, 'domaintest1')->domain());
|
||||
$this->assertEquals(
|
||||
'one.example.org',
|
||||
$this->objFromFixture(Subsite::class, 'domaintest1')->domain()
|
||||
);
|
||||
|
||||
$this->assertEquals('two.mysite.com',
|
||||
$this->objFromFixture(Subsite::class, 'domaintest2')->domain());
|
||||
$this->assertEquals(
|
||||
'two.mysite.com',
|
||||
$this->objFromFixture(Subsite::class, 'domaintest2')->domain()
|
||||
);
|
||||
|
||||
$_SERVER['HTTP_HOST'] = 'www.example.org';
|
||||
$this->assertEquals('three.example.org',
|
||||
$this->objFromFixture(Subsite::class, 'domaintest3')->domain());
|
||||
$this->assertEquals(
|
||||
'three.example.org',
|
||||
$this->objFromFixture(Subsite::class, 'domaintest3')->domain()
|
||||
);
|
||||
|
||||
$_SERVER['HTTP_HOST'] = 'mysite.example.org';
|
||||
$this->assertEquals('three.mysite.example.org',
|
||||
$this->objFromFixture(Subsite::class, 'domaintest3')->domain());
|
||||
$this->assertEquals(
|
||||
'three.mysite.example.org',
|
||||
$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()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -358,14 +370,22 @@ class SubsiteTest extends BaseSubsiteTest
|
||||
*/
|
||||
public function testAccessibleSites()
|
||||
{
|
||||
$member1Sites = Subsite::accessible_sites('CMS_ACCESS_CMSMain', false, null,
|
||||
$this->objFromFixture(Member::class, 'subsite1member'));
|
||||
$member1Sites = Subsite::accessible_sites(
|
||||
'CMS_ACCESS_CMSMain',
|
||||
false,
|
||||
null,
|
||||
$this->objFromFixture(Member::class, 'subsite1member')
|
||||
);
|
||||
$member1SiteTitles = $member1Sites->column('Title');
|
||||
sort($member1SiteTitles);
|
||||
$this->assertEquals('Subsite1 Template', $member1SiteTitles[0], 'Member can get to a subsite via a group');
|
||||
|
||||
$adminSites = Subsite::accessible_sites('CMS_ACCESS_CMSMain', false, null,
|
||||
$this->objFromFixture(Member::class, 'admin'));
|
||||
$adminSites = Subsite::accessible_sites(
|
||||
'CMS_ACCESS_CMSMain',
|
||||
false,
|
||||
null,
|
||||
$this->objFromFixture(Member::class, 'admin')
|
||||
);
|
||||
$adminSiteTitles = $adminSites->column('Title');
|
||||
sort($adminSiteTitles);
|
||||
$this->assertEquals([
|
||||
@ -380,7 +400,9 @@ class SubsiteTest extends BaseSubsiteTest
|
||||
], array_values($adminSiteTitles));
|
||||
|
||||
$member2Sites = Subsite::accessible_sites(
|
||||
'CMS_ACCESS_CMSMain', false, null,
|
||||
'CMS_ACCESS_CMSMain',
|
||||
false,
|
||||
null,
|
||||
$this->objFromFixture(Member::class, 'subsite1member2')
|
||||
);
|
||||
$member2SiteTitles = $member2Sites->column('Title');
|
||||
|
@ -97,10 +97,14 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest
|
||||
$file->write();
|
||||
|
||||
// Verify that the draft and publish virtual pages both have the corrected link
|
||||
static::assertContains('<img src="/assets/SubsitesVirtualPageTest/464dedb70a/renamed-test-file.pdf"',
|
||||
DB::query("SELECT \"Content\" FROM \"SiteTree\" WHERE \"ID\" = $svp->ID")->value());
|
||||
static::assertContains('<img src="/assets/SubsitesVirtualPageTest/464dedb70a/renamed-test-file.pdf"',
|
||||
DB::query("SELECT \"Content\" FROM \"SiteTree_Live\" WHERE \"ID\" = $svp->ID")->value());
|
||||
static::assertContains(
|
||||
'<img src="/assets/SubsitesVirtualPageTest/464dedb70a/renamed-test-file.pdf"',
|
||||
DB::query("SELECT \"Content\" FROM \"SiteTree\" WHERE \"ID\" = $svp->ID")->value()
|
||||
);
|
||||
static::assertContains(
|
||||
'<img src="/assets/SubsitesVirtualPageTest/464dedb70a/renamed-test-file.pdf"',
|
||||
DB::query("SELECT \"Content\" FROM \"SiteTree_Live\" WHERE \"ID\" = $svp->ID")->value()
|
||||
);
|
||||
}
|
||||
|
||||
public function testSubsiteVirtualPagesArentInappropriatelyPublished()
|
||||
|
@ -83,5 +83,4 @@ class WildcardDomainFieldTest extends SapphireTest
|
||||
['*']
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user