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