FIX Run SS standard PHP linter, separate SiteTree test mock classes

This commit is contained in:
Robbie Averill 2017-08-29 17:07:24 +12:00
parent 9fdc1d6607
commit 8d8ee14cc2
29 changed files with 323 additions and 301 deletions

View File

@ -2,12 +2,10 @@
namespace SilverStripe\Subsites\Admin; namespace SilverStripe\Subsites\Admin;
use SilverStripe\Admin\ModelAdmin; use SilverStripe\Admin\ModelAdmin;
use SilverStripe\Subsites\Forms\GridFieldSubsiteDetailForm; use SilverStripe\Subsites\Forms\GridFieldSubsiteDetailForm;
use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Model\Subsite;
/** /**
* Admin interface to manage and create {@link Subsite} instances. * Admin interface to manage and create {@link Subsite} instances.
* *

View File

@ -2,12 +2,10 @@
namespace SilverStripe\Subsites\Controller; namespace SilverStripe\Subsites\Controller;
use SilverStripe\Admin\LeftAndMain; use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Security\Permission; use SilverStripe\Security\Permission;
use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Model\Subsite;
/** /**
* Section-agnostic PJAX controller. * Section-agnostic PJAX controller.
*/ */
@ -69,5 +67,4 @@ class SubsiteXHRController extends LeftAndMain
{ {
return $this->renderWith('Includes/SubsiteList'); return $this->renderWith('Includes/SubsiteList');
} }
} }

View File

@ -5,6 +5,7 @@ namespace SilverStripe\Subsites\Extensions;
use SilverStripe\Core\Extension; use SilverStripe\Core\Extension;
use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\View\SSViewer; use SilverStripe\View\SSViewer;
/** /**
* @package subsites * @package subsites
*/ */

View File

@ -67,8 +67,10 @@ class FileSubsites extends DataExtension
$fields->push(new LiteralField( $fields->push(new LiteralField(
'Message', 'Message',
'<p class="message notice">' . '<p class="message notice">' .
_t('ASSETADMIN.SUBSITENOTICE', _t(
'Folders and files created in the main site are accessible by all subsites.') 'ASSETADMIN.SUBSITENOTICE',
'Folders and files created in the main site are accessible by all subsites.'
)
. '</p>' . '</p>'
)); ));
} }

View File

@ -88,7 +88,8 @@ class GroupSubsites extends DataExtension implements PermissionProvider
// Interface is different if you have the rights to modify subsite group values on // Interface is different if you have the rights to modify subsite group values on
// all subsites // all subsites
if (isset($subsiteMap[0])) { 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'), _t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'),
[ [
1 => _t('GroupSubsites.ACCESSALL', 'All subsites'), 1 => _t('GroupSubsites.ACCESSALL', 'All subsites'),
@ -97,18 +98,24 @@ class GroupSubsites extends DataExtension implements PermissionProvider
)); ));
unset($subsiteMap[0]); unset($subsiteMap[0]);
$fields->addFieldToTab('Root.Subsites', new CheckboxSetField('Subsites', '', $fields->addFieldToTab('Root.Subsites', new CheckboxSetField(
$subsiteMap)); 'Subsites',
'',
$subsiteMap
));
} else { } else {
if (sizeof($subsiteMap) <= 1) { 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'), _t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'),
reset($subsiteMap))); reset($subsiteMap)
));
} else { } else {
$fields->addFieldToTab('Root.Subsites', new CheckboxSetField('Subsites', $fields->addFieldToTab('Root.Subsites', new CheckboxSetField(
'Subsites',
_t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'), _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 you're querying by ID, ignore the sub-site - this is a bit ugly...
if (!$query->filtersOnID()) { if (!$query->filtersOnID()) {
/*if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID; /*if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID;
else */ else */
@ -156,9 +162,13 @@ class GroupSubsites extends DataExtension implements PermissionProvider
// Don't filter by Group_Subsites if we've already done that // Don't filter by Group_Subsites if we've already done that
$hasGroupSubsites = false; $hasGroupSubsites = false;
foreach ($query->getFrom() as $item) { foreach ($query->getFrom() as $item) {
if ((is_array($item) && strpos($item['table'], if ((is_array($item) && strpos(
'Group_Subsites') !== false) || (!is_array($item) && strpos($item, $item['table'],
'Group_Subsites') !== false) 'Group_Subsites'
) !== false) || (!is_array($item) && strpos(
$item,
'Group_Subsites'
) !== false)
) { ) {
$hasGroupSubsites = true; $hasGroupSubsites = true;
break; break;
@ -220,8 +230,10 @@ class GroupSubsites extends DataExtension implements PermissionProvider
'SECURITY_SUBSITE_GROUP' => [ 'SECURITY_SUBSITE_GROUP' => [
'name' => _t('GroupSubsites.MANAGE_SUBSITES', 'Manage subsites for groups'), 'name' => _t('GroupSubsites.MANAGE_SUBSITES', 'Manage subsites for groups'),
'category' => _t('Permissions.PERMISSIONS_CATEGORY', 'Roles and access permissions'), 'category' => _t('Permissions.PERMISSIONS_CATEGORY', 'Roles and access permissions'),
'help' => _t('GroupSubsites.MANAGE_SUBSITES_HELP', 'help' => _t(
'Ability to limit the permissions for a group to one or more subsites.'), 'GroupSubsites.MANAGE_SUBSITES_HELP',
'Ability to limit the permissions for a group to one or more subsites.'
),
'sort' => 200 'sort' => 200
] ]
]; ];

View File

@ -340,8 +340,10 @@ class LeftAndMainSubsites extends Extension
public function onAfterSave($record) public function onAfterSave($record)
{ {
if ($record->hasMethod('NormalRelated') && ($record->NormalRelated() || $record->ReverseRelated())) { if ($record->hasMethod('NormalRelated') && ($record->NormalRelated() || $record->ReverseRelated())) {
$this->owner->response->addHeader('X-Status', $this->owner->response->addHeader(
rawurlencode(_t('LeftAndMainSubsites.Saved', 'Saved, please update related pages.'))); 'X-Status',
rawurlencode(_t('LeftAndMainSubsites.Saved', 'Saved, please update related pages.'))
);
} }
} }

View File

@ -108,13 +108,18 @@ class SiteTreeSubsites extends DataExtension
if ($isDefaultSubsite && $subsitesMap) { if ($isDefaultSubsite && $subsitesMap) {
$fields->addFieldToTab( $fields->addFieldToTab(
'Root.Main', 'Root.Main',
ToggleCompositeField::create('SubsiteOperations', ToggleCompositeField::create(
'SubsiteOperations',
_t('SiteTreeSubsites.SubsiteOperations', 'Subsite Operations'), _t('SiteTreeSubsites.SubsiteOperations', 'Subsite Operations'),
[ [
new DropdownField('CopyToSubsiteID', _t('SiteTreeSubsites.CopyToSubsite', new DropdownField('CopyToSubsiteID', _t(
'Copy page to subsite'), $subsitesMap), 'SiteTreeSubsites.CopyToSubsite',
new CheckboxField('CopyToSubsiteWithChildren', 'Copy page to subsite'
_t('SiteTreeSubsites.CopyToSubsiteWithChildren', 'Include children pages?')), ), $subsitesMap),
new CheckboxField(
'CopyToSubsiteWithChildren',
_t('SiteTreeSubsites.CopyToSubsiteWithChildren', 'Include children pages?')
),
$copyAction = new FormAction( $copyAction = new FormAction(
'copytosubsite', 'copytosubsite',
_t('SiteTreeSubsites.CopyAction', 'Copy') _t('SiteTreeSubsites.CopyAction', 'Copy')
@ -393,9 +398,11 @@ class SiteTreeSubsites extends DataExtension
$origDisableSubsiteFilter = Subsite::$disable_subsite_filter; $origDisableSubsiteFilter = Subsite::$disable_subsite_filter;
Subsite::disable_subsite_filter(true); 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, "\"URLSegment\" = '" . Convert::raw2sql(urldecode($rest)) . "' AND \"SubsiteID\" = " . $subsiteID,
false); false
);
Subsite::disable_subsite_filter($origDisableSubsiteFilter); Subsite::disable_subsite_filter($origDisableSubsiteFilter);
if ($candidatePage) { if ($candidatePage) {

View File

@ -2,10 +2,8 @@
namespace SilverStripe\Subsites\Extensions; namespace SilverStripe\Subsites\Extensions;
use SilverStripe\Core\Extension; use SilverStripe\Core\Extension;
/* /*
* Simple extension to show admins in the menu of subsites. * Simple extension to show admins in the menu of subsites.
* If an admin area should be available to a subsite, you can attach * If an admin area should be available to a subsite, you can attach

View File

@ -36,8 +36,11 @@ class GridFieldSubsiteDetailForm_ItemRequest extends GridFieldDetailForm_ItemReq
$templateArray = $templates->map('ID', 'Title'); $templateArray = $templates->map('ID', 'Title');
} }
$templateDropdown = new DropdownField('TemplateID', _t('Subsite.COPYSTRUCTURE', 'Copy structure from:'), $templateDropdown = new DropdownField(
$templateArray); 'TemplateID',
_t('Subsite.COPYSTRUCTURE', 'Copy structure from:'),
$templateArray
);
$templateDropdown->setEmptyString('(' . _t('Subsite.NOTEMPLATE', 'No template') . ')'); $templateDropdown->setEmptyString('(' . _t('Subsite.NOTEMPLATE', 'No template') . ')');
$form->Fields()->addFieldToTab('Root.Configuration', $templateDropdown); $form->Fields()->addFieldToTab('Root.Configuration', $templateDropdown);
} }
@ -57,5 +60,4 @@ class GridFieldSubsiteDetailForm_ItemRequest extends GridFieldDetailForm_ItemReq
return parent::doSave($data, $form); return parent::doSave($data, $form);
} }
} }

View File

@ -2,14 +2,12 @@
namespace SilverStripe\Subsites\Forms; namespace SilverStripe\Subsites\Forms;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPRequest; use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\Session; use SilverStripe\Control\Session;
use SilverStripe\Forms\TreeDropdownField; use SilverStripe\Forms\TreeDropdownField;
use SilverStripe\View\Requirements; use SilverStripe\View\Requirements;
/** /**
* Wraps around a TreedropdownField to add ability for temporary * Wraps around a TreedropdownField to add ability for temporary
* switching of subsite sessions. * switching of subsite sessions.

View File

@ -2,6 +2,7 @@
namespace SilverStripe\Subsites\Forms; namespace SilverStripe\Subsites\Forms;
use SilverStripe\Forms\TextField; use SilverStripe\Forms\TextField;
/** /**
* A text field that accepts only valid domain names, but allows the wildcard (*) character * A text field that accepts only valid domain names, but allows the wildcard (*) character
*/ */

View File

@ -35,7 +35,6 @@ use SilverStripe\Security\Permission;
use SilverStripe\Versioned\Versioned; use SilverStripe\Versioned\Versioned;
use UnexpectedValueException; use UnexpectedValueException;
/** /**
* A dynamically created subsite. SiteTree objects can now belong to a subsite. * 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. * 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, SubsiteDomain::class,
"'$SQL_host' LIKE replace(\"SubsiteDomain\".\"Domain\",'*','%')", "'$SQL_host' LIKE replace(\"SubsiteDomain\".\"Domain\",'*','%')",
'"IsPrimary" DESC' '"IsPrimary" DESC'
)->innerJoin('Subsite', )->innerJoin(
'"Subsite"."ID" = "SubsiteDomain"."SubsiteID" AND "Subsite"."IsPublic"=1'); 'Subsite',
'"Subsite"."ID" = "SubsiteDomain"."SubsiteID" AND "Subsite"."IsPublic"=1'
);
} }
if ($matchingDomains && $matchingDomains->count()) { if ($matchingDomains && $matchingDomains->count()) {
@ -379,8 +380,8 @@ class Subsite extends DataObject
$includeMainSite = true, $includeMainSite = true,
$mainSiteTitle = 'Main site', $mainSiteTitle = 'Main site',
$member = null $member = null
) ) {
{
// Rationalise member arguments // Rationalise member arguments
if (!$member) { if (!$member) {
$member = Member::currentUser(); $member = Member::currentUser();
@ -408,12 +409,18 @@ class Subsite extends DataObject
$subsites = DataList::create(Subsite::class) $subsites = DataList::create(Subsite::class)
->where("\"Subsite\".\"Title\" != ''") ->where("\"Subsite\".\"Title\" != ''")
->leftJoin('Group_Subsites', '"Group_Subsites"."SubsiteID" = "Subsite"."ID"') ->leftJoin('Group_Subsites', '"Group_Subsites"."SubsiteID" = "Subsite"."ID"')
->innerJoin('Group', ->innerJoin(
'"Group"."ID" = "Group_Subsites"."GroupID" OR "Group"."AccessAllSubsites" = 1') 'Group',
->innerJoin('Group_Members', '"Group"."ID" = "Group_Subsites"."GroupID" OR "Group"."AccessAllSubsites" = 1'
"\"Group_Members\".\"GroupID\"=\"Group\".\"ID\" AND \"Group_Members\".\"MemberID\" = $member->ID") )
->innerJoin('Permission', ->innerJoin(
"\"Group\".\"ID\"=\"Permission\".\"GroupID\" AND \"Permission\".\"Code\" IN ($SQL_codes, 'CMS_ACCESS_LeftAndMain', 'ADMIN')"); '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) { if (!$subsites) {
$subsites = new ArrayList(); $subsites = new ArrayList();
@ -423,14 +430,20 @@ class Subsite extends DataObject
$rolesSubsites = DataList::create(Subsite::class) $rolesSubsites = DataList::create(Subsite::class)
->where("\"Subsite\".\"Title\" != ''") ->where("\"Subsite\".\"Title\" != ''")
->leftJoin('Group_Subsites', '"Group_Subsites"."SubsiteID" = "Subsite"."ID"') ->leftJoin('Group_Subsites', '"Group_Subsites"."SubsiteID" = "Subsite"."ID"')
->innerJoin('Group', ->innerJoin(
'"Group"."ID" = "Group_Subsites"."GroupID" OR "Group"."AccessAllSubsites" = 1') 'Group',
->innerJoin('Group_Members', '"Group"."ID" = "Group_Subsites"."GroupID" OR "Group"."AccessAllSubsites" = 1'
"\"Group_Members\".\"GroupID\"=\"Group\".\"ID\" AND \"Group_Members\".\"MemberID\" = $member->ID") )
->innerJoin(
'Group_Members',
"\"Group_Members\".\"GroupID\"=\"Group\".\"ID\" AND \"Group_Members\".\"MemberID\" = $member->ID"
)
->innerJoin('Group_Roles', '"Group_Roles"."GroupID"="Group"."ID"') ->innerJoin('Group_Roles', '"Group_Roles"."GroupID"="Group"."ID"')
->innerJoin('PermissionRole', '"Group_Roles"."PermissionRoleID"="PermissionRole"."ID"') ->innerJoin('PermissionRole', '"Group_Roles"."PermissionRoleID"="PermissionRole"."ID"')
->innerJoin('PermissionRoleCode', ->innerJoin(
"\"PermissionRole\".\"ID\"=\"PermissionRoleCode\".\"RoleID\" AND \"PermissionRoleCode\".\"Code\" IN ($SQL_codes, 'CMS_ACCESS_LeftAndMain', 'ADMIN')"); 'PermissionRoleCode',
"\"PermissionRole\".\"ID\"=\"PermissionRoleCode\".\"RoleID\" AND \"PermissionRoleCode\".\"Code\" IN ($SQL_codes, 'CMS_ACCESS_LeftAndMain', 'ADMIN')"
);
if (!$subsites && $rolesSubsites) { if (!$subsites && $rolesSubsites) {
return $rolesSubsites; return $rolesSubsites;
@ -655,8 +668,10 @@ class Subsite extends DataObject
} else { } else {
$domainTable = new LiteralField( $domainTable = new LiteralField(
'Domains', 'Domains',
'<p>' . _t('Subsite.DOMAINSAVEFIRST', '<p>' . _t(
'You can only add domains after saving for the first time') . '</p>' 'Subsite.DOMAINSAVEFIRST',
'You can only add domains after saving for the first time'
) . '</p>'
); );
} }
@ -674,13 +689,13 @@ class Subsite extends DataObject
asort($pageTypeMap); asort($pageTypeMap);
$fields = new FieldList( $fields = new FieldList(
$subsiteTabs = new TabSet('Root', $subsiteTabs = new TabSet(
'Root',
new Tab( new Tab(
'Configuration', 'Configuration',
_t('Subsite.TabTitleConfig', 'Configuration'), _t('Subsite.TabTitleConfig', 'Configuration'),
HeaderField::create('ConfigForSubsiteHeaderField', 'Subsite Configuration'), HeaderField::create('ConfigForSubsiteHeaderField', 'Subsite Configuration'),
TextField::create('Title', $this->fieldLabel('Title'), $this->Title), TextField::create('Title', $this->fieldLabel('Title'), $this->Title),
HeaderField::create( HeaderField::create(
'DomainsForSubsiteHeaderField', 'DomainsForSubsiteHeaderField',
_t('Subsite.DomainsHeadline', 'Domains for this subsite') _t('Subsite.DomainsHeadline', 'Domains for this subsite')
@ -690,7 +705,6 @@ class Subsite extends DataObject
// new TextField('RedirectURL', 'Redirect to URL', $this->RedirectURL), // new TextField('RedirectURL', 'Redirect to URL', $this->RedirectURL),
CheckboxField::create('DefaultSite', $this->fieldLabel('DefaultSite'), $this->DefaultSite), CheckboxField::create('DefaultSite', $this->fieldLabel('DefaultSite'), $this->DefaultSite),
CheckboxField::create('IsPublic', $this->fieldLabel('IsPublic'), $this->IsPublic), CheckboxField::create('IsPublic', $this->fieldLabel('IsPublic'), $this->IsPublic),
LiteralField::create( LiteralField::create(
'PageTypeBlacklistToggle', 'PageTypeBlacklistToggle',
sprintf( sprintf(
@ -712,9 +726,12 @@ class Subsite extends DataObject
// If there are any themes available, add the dropdown // If there are any themes available, add the dropdown
$themes = $this->allowedThemes(); $themes = $this->allowedThemes();
if (!empty($themes)) { if (!empty($themes)) {
$fields->addFieldToTab('Root.Configuration', $fields->addFieldToTab(
'Root.Configuration',
DropdownField::create('Theme', $this->fieldLabel('Theme'), $this->allowedThemes(), $this->Theme) DropdownField::create('Theme', $this->fieldLabel('Theme'), $this->allowedThemes(), $this->Theme)
->setEmptyString(_t('Subsite.ThemeFieldEmptyString', '-')), 'PageTypeBlacklistToggle'); ->setEmptyString(_t('Subsite.ThemeFieldEmptyString', '-')),
'PageTypeBlacklistToggle'
);
} }
$subsiteTabs->addExtraClass('subsite-model'); $subsiteTabs->addExtraClass('subsite-model');

View File

@ -10,7 +10,6 @@ use SilverStripe\Forms\OptionsetField;
use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObject;
use SilverStripe\Subsites\Forms\WildcardDomainField; 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 $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 * @property string $Protocol Required protocol (http or https) if only one is supported. 'automatic' implies

View File

@ -2,7 +2,6 @@
namespace SilverStripe\Subsites\Pages; namespace SilverStripe\Subsites\Pages;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\CMS\Model\VirtualPage; use SilverStripe\CMS\Model\VirtualPage;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;

View File

@ -2,13 +2,11 @@
namespace SilverStripe\Subsites\Reports; namespace SilverStripe\Subsites\Reports;
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TreeMultiselectField; use SilverStripe\Forms\TreeMultiselectField;
use SilverStripe\Reports\ReportWrapper; use SilverStripe\Reports\ReportWrapper;
use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Model\Subsite;
/** /**
* Creates a subsite-aware version of another report. * Creates a subsite-aware version of another report.
* Pass another report (or its classname) into the constructor. * Pass another report (or its classname) into the constructor.
@ -84,5 +82,4 @@ class SubsiteReportWrapper extends ReportWrapper
// Manually manage the subsite filtering // Manually manage the subsite filtering
Subsite::$force_subsite = null; Subsite::$force_subsite = null;
} }
} }

View File

@ -2,7 +2,6 @@
namespace SilverStripe\Subsites\Tasks; namespace SilverStripe\Subsites\Tasks;
use InvalidArgumentException; use InvalidArgumentException;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Dev\BuildTask; use SilverStripe\Dev\BuildTask;
@ -11,7 +10,6 @@ use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\Subsites\Pages\SubsitesVirtualPage; use SilverStripe\Subsites\Pages\SubsitesVirtualPage;
use SilverStripe\Versioned\Versioned; use SilverStripe\Versioned\Versioned;
/** /**
* Handy alternative to copying pages when creating a subsite through the UI. * Handy alternative to copying pages when creating a subsite through the UI.
* *

View File

@ -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);
}
}

View File

@ -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('*')
);
}
}

View File

@ -76,10 +76,12 @@ class LeftAndMainSubsitesTest extends FunctionalTest
$left = new LeftAndMain(); $left = new LeftAndMain();
$this->assertTrue($left->canView(), "Admin user can view subsites LeftAndMain with id = '$id'"); $this->assertTrue($left->canView(), "Admin user can view subsites LeftAndMain with id = '$id'");
$this->assertEquals($id, Subsite::currentSubsiteID(), $this->assertEquals(
'The current subsite has not been changed in the process of checking permissions for admin user.'); $id,
Subsite::currentSubsiteID(),
'The current subsite has not been changed in the process of checking permissions for admin user.'
);
} }
} }
public function testShouldChangeSubsite() public function testShouldChangeSubsite()

View File

@ -18,22 +18,24 @@ use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\Subsites\Extensions\SiteTreeSubsites; use SilverStripe\Subsites\Extensions\SiteTreeSubsites;
use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\Subsites\Pages\SubsitesVirtualPage; 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\Versioned\Versioned;
use SilverStripe\View\SSViewer; use SilverStripe\View\SSViewer;
class SiteTreeSubsitesTest extends BaseSubsiteTest class SiteTreeSubsitesTest extends BaseSubsiteTest
{ {
protected static $fixture_file = 'subsites/tests/php/SubsiteTest.yml';
public static $fixture_file = 'subsites/tests/php/SubsiteTest.yml'; protected static $extra_dataobjects = [
TestClassA::class,
protected $extraDataObjects = [ TestClassB::class,
'SiteTreeSubsitesTest_ClassA', TestErrorPage::class
'SiteTreeSubsitesTest_ClassB',
'SiteTreeSubsitesTest_ErrorPage'
]; ];
protected $illegalExtensions = [ protected static $illegal_extensions = [
SiteTree::class => ['Translatable'] SiteTree::class => ['Translatable'] // @todo implement Translatable namespace
]; ];
public function testPagesInDifferentSubsitesCanShareURLSegment() public function testPagesInDifferentSubsitesCanShareURLSegment()
@ -51,7 +53,9 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
$pageMainOther->write(); $pageMainOther->write();
$pageMainOther->copyVersionToStage('Stage', 'Live'); $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' 'Pages in same subsite cant share the same URL'
); );
@ -62,7 +66,9 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
$pageSubsite1->write(); $pageSubsite1->write();
$pageSubsite1->copyVersionToStage('Stage', 'Live'); $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' 'Pages in different subsites can share the same URL'
); );
} }
@ -171,31 +177,37 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
$s2 = $this->objFromFixture(Subsite::class, 'domaintest2'); $s2 = $this->objFromFixture(Subsite::class, 'domaintest2');
$page = singleton(SiteTree::class); $page = singleton(SiteTree::class);
$s1->PageTypeBlacklist = implode(',', [SiteTreeSubsitesTest_ClassA::class, ErrorPage::class]); $s1->PageTypeBlacklist = implode(',', [TestClassA::class, ErrorPage::class]);
$s1->write(); $s1->write();
Subsite::changeSubsite($s1); Subsite::changeSubsite($s1);
$settingsFields = $page->getSettingsFields()->dataFieldByName('ClassName')->getSource(); $settingsFields = $page->getSettingsFields()->dataFieldByName('ClassName')->getSource();
$this->assertArrayNotHasKey(ErrorPage::class, $this->assertArrayNotHasKey(
ErrorPage::class,
$settingsFields $settingsFields
); );
$this->assertArrayNotHasKey(SiteTreeSubsitesTest_ClassA::class, $this->assertArrayNotHasKey(
TestClassA::class,
$settingsFields $settingsFields
); );
$this->assertArrayHasKey(SiteTreeSubsitesTest_ClassB::class, $this->assertArrayHasKey(
TestClassB::class,
$settingsFields $settingsFields
); );
Subsite::changeSubsite($s2); Subsite::changeSubsite($s2);
$settingsFields = $page->getSettingsFields()->dataFieldByName('ClassName')->getSource(); $settingsFields = $page->getSettingsFields()->dataFieldByName('ClassName')->getSource();
$this->assertArrayHasKey(ErrorPage::class, $this->assertArrayHasKey(
ErrorPage::class,
$settingsFields $settingsFields
); );
$this->assertArrayHasKey(SiteTreeSubsitesTest_ClassA::class, $this->assertArrayHasKey(
TestClassA::class,
$settingsFields $settingsFields
); );
$this->assertArrayHasKey(SiteTreeSubsitesTest_ClassB::class, $this->assertArrayHasKey(
TestClassB::class,
$settingsFields $settingsFields
); );
} }
@ -238,22 +250,22 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
$s1 = $this->objFromFixture(Subsite::class, 'domaintest1'); $s1 = $this->objFromFixture(Subsite::class, 'domaintest1');
$s2 = $this->objFromFixture(Subsite::class, 'domaintest2'); $s2 = $this->objFromFixture(Subsite::class, 'domaintest2');
$s1->PageTypeBlacklist = implode(',', [SiteTreeSubsitesTest_ClassA::class, ErrorPage::class]); $s1->PageTypeBlacklist = implode(',', [TestClassA::class, ErrorPage::class]);
$s1->write(); $s1->write();
Subsite::changeSubsite($s1); Subsite::changeSubsite($s1);
$hints = Convert::json2array($cmsmain->SiteTreeHints()); $hints = Convert::json2array($cmsmain->SiteTreeHints());
$classes = $hints['Root']['disallowedChildren']; $classes = $hints['Root']['disallowedChildren'];
static::assertContains(ErrorPage::class, $classes); static::assertContains(ErrorPage::class, $classes);
static::assertContains(SiteTreeSubsitesTest_ClassA::class, $classes); static::assertContains(TestClassA::class, $classes);
static::assertNotContains(SiteTreeSubsitesTest_ClassB::class, $classes); static::assertNotContains(TestClassB::class, $classes);
Subsite::changeSubsite($s2); Subsite::changeSubsite($s2);
$hints = Convert::json2array($cmsmain->SiteTreeHints()); $hints = Convert::json2array($cmsmain->SiteTreeHints());
$classes = $hints['Root']['disallowedChildren']; $classes = $hints['Root']['disallowedChildren'];
static::assertNotContains(ErrorPage::class, $classes); static::assertNotContains(ErrorPage::class, $classes);
static::assertNotContains(SiteTreeSubsitesTest_ClassA::class, $classes); static::assertNotContains(TestClassA::class, $classes);
static::assertNotContains(SiteTreeSubsitesTest_ClassB::class, $classes); static::assertNotContains(TestClassB::class, $classes);
} }
/** /**
@ -280,8 +292,11 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
$subsite1Home->write(); $subsite1Home->write();
$this->assertEquals('home', $subsite1Home->URLSegment); $this->assertEquals('home', $subsite1Home->URLSegment);
$subsite1Home->doPublish(); $subsite1Home->doPublish();
$subsite1HomeLive = Versioned::get_one_by_stage('Page', 'Live', $subsite1HomeLive = Versioned::get_one_by_stage(
sprintf('"SiteTree"."ID" = \'%d\'', $subsite1Home->ID)); 'Page',
'Live',
sprintf('"SiteTree"."ID" = \'%d\'', $subsite1Home->ID)
);
$this->assertEquals('home', $subsite1HomeLive->URLSegment); $this->assertEquals('home', $subsite1HomeLive->URLSegment);
// Creating a new page in a subsite doesn't conflict with urls in other subsites // 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(); $subsite1NewPage->write();
$this->assertEquals('important-page', $subsite1NewPage->URLSegment); $this->assertEquals('important-page', $subsite1NewPage->URLSegment);
$subsite1NewPage->doPublish(); $subsite1NewPage->doPublish();
$subsite1NewPageLive = Versioned::get_one_by_stage('Page', 'Live', $subsite1NewPageLive = Versioned::get_one_by_stage(
sprintf('"SiteTree"."ID" = \'%d\'', $subsite1NewPage->ID)); 'Page',
'Live',
sprintf('"SiteTree"."ID" = \'%d\'', $subsite1NewPage->ID)
);
$this->assertEquals('important-page', $subsite1NewPageLive->URLSegment); $this->assertEquals('important-page', $subsite1NewPageLive->URLSegment);
// Creating a new page in a subsite DOES conflict with urls in the same subsite // 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(); $subsite1NewPage2->write();
$this->assertEquals('important-page-2', $subsite1NewPage2->URLSegment); $this->assertEquals('important-page-2', $subsite1NewPage2->URLSegment);
$subsite1NewPage2->doPublish(); $subsite1NewPage2->doPublish();
$subsite1NewPage2Live = Versioned::get_one_by_stage('Page', 'Live', $subsite1NewPage2Live = Versioned::get_one_by_stage(
sprintf('"SiteTree"."ID" = \'%d\'', $subsite1NewPage2->ID)); 'Page',
'Live',
sprintf('"SiteTree"."ID" = \'%d\'', $subsite1NewPage2->ID)
);
$this->assertEquals('important-page-2', $subsite1NewPage2Live->URLSegment); $this->assertEquals('important-page-2', $subsite1NewPage2Live->URLSegment);
// Original page is left un-modified // Original page is left un-modified
@ -326,8 +347,11 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
$moved = $page->duplicateToSubsite($newSubsite->ID, true); $moved = $page->duplicateToSubsite($newSubsite->ID, true);
$this->assertEquals($moved->SubsiteID, $newSubsite->ID, 'Ensure returned records are on new subsite'); $this->assertEquals($moved->SubsiteID, $newSubsite->ID, 'Ensure returned records are on new subsite');
$this->assertEquals($moved->AllChildren()->count(), $page->AllChildren()->count(), $this->assertEquals(
'All pages are copied across'); $moved->AllChildren()->count(),
$page->AllChildren()->count(),
'All pages are copied across'
);
} }
public function testCopySubsiteWithoutChildren() public function testCopySubsiteWithoutChildren()
@ -353,39 +377,21 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
$controller = ModelAsController::controller_for($subsitePage); $controller = ModelAsController::controller_for($subsitePage);
SiteTree::singleton()->extend('contentcontrollerInit', $controller); SiteTree::singleton()->extend('contentcontrollerInit', $controller);
$this->assertEquals(SSViewer::get_themes(), $defaultThemes, $this->assertEquals(
'Themes should not be modified when Subsite has no theme defined'); SSViewer::get_themes(),
$defaultThemes,
'Themes should not be modified when Subsite has no theme defined'
);
$pageWithTheme = $this->objFromFixture(Page::class, 'subsite1_home'); $pageWithTheme = $this->objFromFixture(Page::class, 'subsite1_home');
Subsite::changeSubsite($pageWithTheme->SubsiteID); Subsite::changeSubsite($pageWithTheme->SubsiteID);
$controller = ModelAsController::controller_for($pageWithTheme); $controller = ModelAsController::controller_for($pageWithTheme);
SiteTree::singleton()->extend('contentcontrollerInit', $controller); SiteTree::singleton()->extend('contentcontrollerInit', $controller);
$subsiteTheme = $pageWithTheme->Subsite()->Theme; $subsiteTheme = $pageWithTheme->Subsite()->Theme;
$this->assertEquals(SSViewer::get_themes(), array_merge([$subsiteTheme], $defaultThemes), $this->assertEquals(
'Themes should be modified when Subsite has theme defined'); 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);
} }
} }

View 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
{
}

View 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
{
}

View 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);
}
}

View File

@ -46,8 +46,11 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
$this->assertRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), 'Admin is disallowed'); $this->assertRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), 'Admin is disallowed');
$response = $this->getAndFollowAll('SubsiteXHRController'); $response = $this->getAndFollowAll('SubsiteXHRController');
$this->assertRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), $this->assertRegExp(
'SubsiteXHRController is disallowed'); '#^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'); $this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section');
$response = $this->getAndFollowAll(SubsiteXHRController::class); $response = $this->getAndFollowAll(SubsiteXHRController::class);
$this->assertNotRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), $this->assertNotRegExp(
'SubsiteXHRController is reachable'); '#^Security/login.*#',
$this->mainSession->lastUrl(),
'SubsiteXHRController is reachable'
);
} }
public function testAdminIsRedirectedToObjectsSubsite() public function testAdminIsRedirectedToObjectsSubsite()
@ -85,20 +91,29 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
Config::modify()->set(CMSPageEditController::class, 'treats_subsite_0_as_global', false); Config::modify()->set(CMSPageEditController::class, 'treats_subsite_0_as_global', false);
Subsite::changeSubsite(0); Subsite::changeSubsite(0);
$this->getAndFollowAll("admin/pages/edit/show/$subsite1Home->ID"); $this->getAndFollowAll("admin/pages/edit/show/$subsite1Home->ID");
$this->assertEquals(Subsite::currentSubsiteID(), $subsite1Home->SubsiteID, $this->assertEquals(
'Loading an object switches the subsite'); Subsite::currentSubsiteID(),
$subsite1Home->SubsiteID,
'Loading an object switches the subsite'
);
$this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section'); $this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section');
Config::modify()->set(CMSPageEditController::class, 'treats_subsite_0_as_global', true); Config::modify()->set(CMSPageEditController::class, 'treats_subsite_0_as_global', true);
Subsite::changeSubsite(0); Subsite::changeSubsite(0);
$this->getAndFollowAll("admin/pages/edit/show/$subsite1Home->ID"); $this->getAndFollowAll("admin/pages/edit/show/$subsite1Home->ID");
$this->assertEquals(Subsite::currentSubsiteID(), $subsite1Home->SubsiteID, $this->assertEquals(
'Loading a non-main-site object still switches the subsite if configured with treats_subsite_0_as_global'); 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->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section');
$this->getAndFollowAll("admin/pages/edit/show/$mainSubsitePage->ID"); $this->getAndFollowAll("admin/pages/edit/show/$mainSubsitePage->ID");
$this->assertNotEquals(Subsite::currentSubsiteID(), $mainSubsitePage->SubsiteID, $this->assertNotEquals(
'Loading a main-site object does not change the subsite if configured with treats_subsite_0_as_global'); 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'); $this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section');
Config::unnest(); Config::unnest();
@ -123,8 +138,11 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
$this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section'); $this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section');
$response = $this->getAndFollowAll('SubsiteXHRController'); $response = $this->getAndFollowAll('SubsiteXHRController');
$this->assertNotRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), $this->assertNotRegExp(
'SubsiteXHRController is reachable'); '#^Security/login.*#',
$this->mainSession->lastUrl(),
'SubsiteXHRController is reachable'
);
} }
/** /**
@ -145,8 +163,11 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
// Check forbidden section in allowed subsite. // Check forbidden section in allowed subsite.
$this->getAndFollowAll("admin/assets/?SubsiteID={$subsite1->ID}"); $this->getAndFollowAll("admin/assets/?SubsiteID={$subsite1->ID}");
$this->assertEquals(Subsite::currentSubsiteID(), $subsite1->ID, 'Is redirected within subsite.'); $this->assertEquals(Subsite::currentSubsiteID(), $subsite1->ID, 'Is redirected within subsite.');
$this->assertNotRegExp('#^admin/assets/.*#', $this->mainSession->lastUrl(), $this->assertNotRegExp(
'Is redirected away from forbidden section'); '#^admin/assets/.*#',
$this->mainSession->lastUrl(),
'Is redirected away from forbidden section'
);
// Check forbidden site, on a section that's allowed on another subsite // Check forbidden site, on a section that's allowed on another subsite
$this->getAndFollowAll('admin/pages/?SubsiteID=0'); $this->getAndFollowAll('admin/pages/?SubsiteID=0');
@ -159,7 +180,10 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
// Check the standalone XHR controller. // Check the standalone XHR controller.
$response = $this->getAndFollowAll(SubsiteXHRController::class); $response = $this->getAndFollowAll(SubsiteXHRController::class);
$this->assertNotRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), $this->assertNotRegExp(
'SubsiteXHRController is reachable'); '#^Security/login.*#',
$this->mainSession->lastUrl(),
'SubsiteXHRController is reachable'
);
} }
} }

View File

@ -31,11 +31,15 @@ class SubsiteAdminTest extends BaseSubsiteTest
$response1 = Director::test('admin/subsites/', null, $this->adminLoggedInSession()); $response1 = Director::test('admin/subsites/', null, $this->adminLoggedInSession());
// Confirm that this URL gets you the entire page, with the edit form loaded // 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, null,
$this->adminLoggedInSession()); $this->adminLoggedInSession()
$this->assertTrue(strpos($response2->getBody(), 'id="Form_ItemEditForm_ID"') !== false, );
'Testing Form_ItemEditForm_ID exists'); $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'); $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(0, $ids, 'Main site accessible');
$this->assertArrayHasKey($this->idFromFixture(Subsite::class, 'main'), $ids, 'Site with no groups inaccesible'); $this->assertArrayHasKey($this->idFromFixture(Subsite::class, 'main'), $ids, 'Site with no groups inaccesible');
$this->assertArrayHasKey($this->idFromFixture(Subsite::class, 'subsite1'), $ids, $this->assertArrayHasKey(
'Subsite1 Template inaccessible'); $this->idFromFixture(Subsite::class, 'subsite1'),
$this->assertArrayHasKey($this->idFromFixture(Subsite::class, 'subsite2'), $ids, $ids,
'Subsite2 Template inaccessible'); 'Subsite1 Template inaccessible'
);
$this->assertArrayHasKey(
$this->idFromFixture(Subsite::class, 'subsite2'),
$ids,
'Subsite2 Template inaccessible'
);
} }
} }

View File

@ -2,7 +2,6 @@
namespace subsites\tests\php; namespace subsites\tests\php;
use Page; use Page;
use SilverStripe\Dev\FunctionalTest; use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Model\Subsite;
@ -24,15 +23,20 @@ class SubsiteFunctionalTest extends FunctionalTest
$subsitePage = $this->objFromFixture(Page::class, 'contact'); $subsitePage = $this->objFromFixture(Page::class, 'contact');
$this->get($subsitePage->AbsoluteLink()); $this->get($subsitePage->AbsoluteLink());
$this->assertEquals($subsitePage->SubsiteID, Subsite::currentSubsiteID(), 'Subsite should be changed'); $this->assertEquals($subsitePage->SubsiteID, Subsite::currentSubsiteID(), 'Subsite should be changed');
$this->assertEquals(SSViewer::get_themes(), $defaultThemes, $this->assertEquals(
'Themes should not be modified when Subsite has no theme defined'); SSViewer::get_themes(),
$defaultThemes,
'Themes should not be modified when Subsite has no theme defined'
);
$pageWithTheme = $this->objFromFixture(Page::class, 'subsite1_contactus'); $pageWithTheme = $this->objFromFixture(Page::class, 'subsite1_contactus');
$this->get($pageWithTheme->AbsoluteLink()); $this->get($pageWithTheme->AbsoluteLink());
$subsiteTheme = $pageWithTheme->Subsite()->Theme; $subsiteTheme = $pageWithTheme->Subsite()->Theme;
$this->assertEquals($pageWithTheme->SubsiteID, Subsite::currentSubsiteID(), 'Subsite should be changed'); $this->assertEquals($pageWithTheme->SubsiteID, Subsite::currentSubsiteID(), 'Subsite should be changed');
$this->assertEquals(SSViewer::get_themes(), array_merge([$subsiteTheme], $defaultThemes), $this->assertEquals(
'Themes should be modified when Subsite has theme defined'); SSViewer::get_themes(),
array_merge([$subsiteTheme], $defaultThemes),
'Themes should be modified when Subsite has theme defined'
);
} }
} }

View File

@ -82,7 +82,9 @@ class SubsiteTest extends BaseSubsiteTest
$siteHome = DataObject::get_one('Page', "\"URLSegment\" = 'home'"); $siteHome = DataObject::get_one('Page', "\"URLSegment\" = 'home'");
$this->assertNotEquals($siteHome, false, 'Home Page for subsite not found'); $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' 'createInstance() copies existing pages retaining the same URLSegment'
); );
@ -262,23 +264,33 @@ class SubsiteTest extends BaseSubsiteTest
*/ */
public function testDefaultDomain() public function testDefaultDomain()
{ {
$this->assertEquals('one.example.org', $this->assertEquals(
$this->objFromFixture(Subsite::class, 'domaintest1')->domain()); 'one.example.org',
$this->objFromFixture(Subsite::class, 'domaintest1')->domain()
);
$this->assertEquals('two.mysite.com', $this->assertEquals(
$this->objFromFixture(Subsite::class, 'domaintest2')->domain()); 'two.mysite.com',
$this->objFromFixture(Subsite::class, 'domaintest2')->domain()
);
$_SERVER['HTTP_HOST'] = 'www.example.org'; $_SERVER['HTTP_HOST'] = 'www.example.org';
$this->assertEquals('three.example.org', $this->assertEquals(
$this->objFromFixture(Subsite::class, 'domaintest3')->domain()); 'three.example.org',
$this->objFromFixture(Subsite::class, 'domaintest3')->domain()
);
$_SERVER['HTTP_HOST'] = 'mysite.example.org'; $_SERVER['HTTP_HOST'] = 'mysite.example.org';
$this->assertEquals('three.mysite.example.org', $this->assertEquals(
$this->objFromFixture(Subsite::class, 'domaintest3')->domain()); 'three.mysite.example.org',
$this->objFromFixture(Subsite::class, 'domaintest3')->domain()
);
$this->assertEquals($_SERVER['HTTP_HOST'], singleton(Subsite::class)->PrimaryDomain); $this->assertEquals($_SERVER['HTTP_HOST'], singleton(Subsite::class)->PrimaryDomain);
$this->assertEquals('http://' . $_SERVER['HTTP_HOST'] . Director::baseURL(), $this->assertEquals(
singleton(Subsite::class)->absoluteBaseURL()); 'http://' . $_SERVER['HTTP_HOST'] . Director::baseURL(),
singleton(Subsite::class)->absoluteBaseURL()
);
} }
/** /**
@ -358,14 +370,22 @@ class SubsiteTest extends BaseSubsiteTest
*/ */
public function testAccessibleSites() public function testAccessibleSites()
{ {
$member1Sites = Subsite::accessible_sites('CMS_ACCESS_CMSMain', false, null, $member1Sites = Subsite::accessible_sites(
$this->objFromFixture(Member::class, 'subsite1member')); 'CMS_ACCESS_CMSMain',
false,
null,
$this->objFromFixture(Member::class, 'subsite1member')
);
$member1SiteTitles = $member1Sites->column('Title'); $member1SiteTitles = $member1Sites->column('Title');
sort($member1SiteTitles); sort($member1SiteTitles);
$this->assertEquals('Subsite1 Template', $member1SiteTitles[0], 'Member can get to a subsite via a group'); $this->assertEquals('Subsite1 Template', $member1SiteTitles[0], 'Member can get to a subsite via a group');
$adminSites = Subsite::accessible_sites('CMS_ACCESS_CMSMain', false, null, $adminSites = Subsite::accessible_sites(
$this->objFromFixture(Member::class, 'admin')); 'CMS_ACCESS_CMSMain',
false,
null,
$this->objFromFixture(Member::class, 'admin')
);
$adminSiteTitles = $adminSites->column('Title'); $adminSiteTitles = $adminSites->column('Title');
sort($adminSiteTitles); sort($adminSiteTitles);
$this->assertEquals([ $this->assertEquals([
@ -380,7 +400,9 @@ class SubsiteTest extends BaseSubsiteTest
], array_values($adminSiteTitles)); ], array_values($adminSiteTitles));
$member2Sites = Subsite::accessible_sites( $member2Sites = Subsite::accessible_sites(
'CMS_ACCESS_CMSMain', false, null, 'CMS_ACCESS_CMSMain',
false,
null,
$this->objFromFixture(Member::class, 'subsite1member2') $this->objFromFixture(Member::class, 'subsite1member2')
); );
$member2SiteTitles = $member2Sites->column('Title'); $member2SiteTitles = $member2Sites->column('Title');

View File

@ -97,10 +97,14 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest
$file->write(); $file->write();
// Verify that the draft and publish virtual pages both have the corrected link // Verify that the draft and publish virtual pages both have the corrected link
static::assertContains('<img src="/assets/SubsitesVirtualPageTest/464dedb70a/renamed-test-file.pdf"', static::assertContains(
DB::query("SELECT \"Content\" FROM \"SiteTree\" WHERE \"ID\" = $svp->ID")->value()); '<img src="/assets/SubsitesVirtualPageTest/464dedb70a/renamed-test-file.pdf"',
static::assertContains('<img src="/assets/SubsitesVirtualPageTest/464dedb70a/renamed-test-file.pdf"', DB::query("SELECT \"Content\" FROM \"SiteTree\" WHERE \"ID\" = $svp->ID")->value()
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_Live\" WHERE \"ID\" = $svp->ID")->value()
);
} }
public function testSubsiteVirtualPagesArentInappropriatelyPublished() public function testSubsiteVirtualPagesArentInappropriatelyPublished()

View File

@ -83,5 +83,4 @@ class WildcardDomainFieldTest extends SapphireTest
['*'] ['*']
]; ];
} }
} }