diff --git a/code/admin/SubsiteAdmin.php b/code/admin/SubsiteAdmin.php index e921031f..f89064fb 100644 --- a/code/admin/SubsiteAdmin.php +++ b/code/admin/SubsiteAdmin.php @@ -2,12 +2,10 @@ namespace SilverStripe\Subsites\Admin; - use SilverStripe\Admin\ModelAdmin; use SilverStripe\Subsites\Forms\GridFieldSubsiteDetailForm; use SilverStripe\Subsites\Model\Subsite; - /** * Admin interface to manage and create {@link Subsite} instances. * diff --git a/code/controller/SubsiteXHRController.php b/code/controller/SubsiteXHRController.php index 22934440..579f9f3f 100644 --- a/code/controller/SubsiteXHRController.php +++ b/code/controller/SubsiteXHRController.php @@ -2,12 +2,10 @@ namespace SilverStripe\Subsites\Controller; - use SilverStripe\Admin\LeftAndMain; use SilverStripe\Security\Permission; use SilverStripe\Subsites\Model\Subsite; - /** * Section-agnostic PJAX controller. */ @@ -69,5 +67,4 @@ public function SubsiteList() { return $this->renderWith('Includes/SubsiteList'); } - } diff --git a/code/extensions/ControllerSubsites.php b/code/extensions/ControllerSubsites.php index f8d40782..e131e821 100644 --- a/code/extensions/ControllerSubsites.php +++ b/code/extensions/ControllerSubsites.php @@ -5,6 +5,7 @@ use SilverStripe\Core\Extension; use SilverStripe\Subsites\Model\Subsite; use SilverStripe\View\SSViewer; + /** * @package subsites */ diff --git a/code/extensions/FileSubsites.php b/code/extensions/FileSubsites.php index 6092565d..7f736906 100644 --- a/code/extensions/FileSubsites.php +++ b/code/extensions/FileSubsites.php @@ -67,8 +67,10 @@ public function updateCMSFields(FieldList $fields) $fields->push(new LiteralField( 'Message', '
' )); } diff --git a/code/extensions/GroupSubsites.php b/code/extensions/GroupSubsites.php index 3d3a4eed..d74a18d8 100644 --- a/code/extensions/GroupSubsites.php +++ b/code/extensions/GroupSubsites.php @@ -88,7 +88,8 @@ public function updateCMSFields(FieldList $fields) // Interface is different if you have the rights to modify subsite group values on // all subsites if (isset($subsiteMap[0])) { - $fields->addFieldToTab('Root.Subsites', new OptionsetField('AccessAllSubsites', + $fields->addFieldToTab('Root.Subsites', new OptionsetField( + 'AccessAllSubsites', _t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'), [ 1 => _t('GroupSubsites.ACCESSALL', 'All subsites'), @@ -97,18 +98,24 @@ public function updateCMSFields(FieldList $fields) )); unset($subsiteMap[0]); - $fields->addFieldToTab('Root.Subsites', new CheckboxSetField('Subsites', '', - $subsiteMap)); - + $fields->addFieldToTab('Root.Subsites', new CheckboxSetField( + 'Subsites', + '', + $subsiteMap + )); } else { if (sizeof($subsiteMap) <= 1) { - $fields->addFieldToTab('Root.Subsites', new ReadonlyField('SubsitesHuman', + $fields->addFieldToTab('Root.Subsites', new ReadonlyField( + 'SubsitesHuman', _t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'), - reset($subsiteMap))); + reset($subsiteMap) + )); } else { - $fields->addFieldToTab('Root.Subsites', new CheckboxSetField('Subsites', + $fields->addFieldToTab('Root.Subsites', new CheckboxSetField( + 'Subsites', _t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'), - $subsiteMap)); + $subsiteMap + )); } } } @@ -147,7 +154,6 @@ public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) // If you're querying by ID, ignore the sub-site - this is a bit ugly... if (!$query->filtersOnID()) { - /*if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID; else */ @@ -156,9 +162,13 @@ public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) // Don't filter by Group_Subsites if we've already done that $hasGroupSubsites = false; foreach ($query->getFrom() as $item) { - if ((is_array($item) && strpos($item['table'], - 'Group_Subsites') !== false) || (!is_array($item) && strpos($item, - 'Group_Subsites') !== false) + if ((is_array($item) && strpos( + $item['table'], + 'Group_Subsites' + ) !== false) || (!is_array($item) && strpos( + $item, + 'Group_Subsites' + ) !== false) ) { $hasGroupSubsites = true; break; @@ -220,8 +230,10 @@ public function providePermissions() 'SECURITY_SUBSITE_GROUP' => [ 'name' => _t('GroupSubsites.MANAGE_SUBSITES', 'Manage subsites for groups'), 'category' => _t('Permissions.PERMISSIONS_CATEGORY', 'Roles and access permissions'), - 'help' => _t('GroupSubsites.MANAGE_SUBSITES_HELP', - 'Ability to limit the permissions for a group to one or more subsites.'), + 'help' => _t( + 'GroupSubsites.MANAGE_SUBSITES_HELP', + 'Ability to limit the permissions for a group to one or more subsites.' + ), 'sort' => 200 ] ]; diff --git a/code/extensions/LeftAndMainSubsites.php b/code/extensions/LeftAndMainSubsites.php index 34b10fda..748290a0 100644 --- a/code/extensions/LeftAndMainSubsites.php +++ b/code/extensions/LeftAndMainSubsites.php @@ -340,15 +340,17 @@ public function augmentNewSiteTreeItem(&$item) public function onAfterSave($record) { if ($record->hasMethod('NormalRelated') && ($record->NormalRelated() || $record->ReverseRelated())) { - $this->owner->response->addHeader('X-Status', - rawurlencode(_t('LeftAndMainSubsites.Saved', 'Saved, please update related pages.'))); + $this->owner->response->addHeader( + 'X-Status', + rawurlencode(_t('LeftAndMainSubsites.Saved', 'Saved, please update related pages.')) + ); } } - /** - * @param array $data - * @param Form $form - */ + /** + * @param array $data + * @param Form $form + */ public function copytosubsite($data, $form) { $page = DataObject::get_by_id('SiteTree', $data['ID']); diff --git a/code/extensions/SiteTreeSubsites.php b/code/extensions/SiteTreeSubsites.php index 40040a80..7631007f 100644 --- a/code/extensions/SiteTreeSubsites.php +++ b/code/extensions/SiteTreeSubsites.php @@ -108,13 +108,18 @@ public function updateCMSFields(FieldList $fields) if ($isDefaultSubsite && $subsitesMap) { $fields->addFieldToTab( 'Root.Main', - ToggleCompositeField::create('SubsiteOperations', + ToggleCompositeField::create( + 'SubsiteOperations', _t('SiteTreeSubsites.SubsiteOperations', 'Subsite Operations'), [ - new DropdownField('CopyToSubsiteID', _t('SiteTreeSubsites.CopyToSubsite', - 'Copy page to subsite'), $subsitesMap), - new CheckboxField('CopyToSubsiteWithChildren', - _t('SiteTreeSubsites.CopyToSubsiteWithChildren', 'Include children pages?')), + new DropdownField('CopyToSubsiteID', _t( + 'SiteTreeSubsites.CopyToSubsite', + 'Copy page to subsite' + ), $subsitesMap), + new CheckboxField( + 'CopyToSubsiteWithChildren', + _t('SiteTreeSubsites.CopyToSubsiteWithChildren', 'Include children pages?') + ), $copyAction = new FormAction( 'copytosubsite', _t('SiteTreeSubsites.CopyAction', 'Copy') @@ -393,9 +398,11 @@ public function augmentSyncLinkTracking() $origDisableSubsiteFilter = Subsite::$disable_subsite_filter; Subsite::disable_subsite_filter(true); - $candidatePage = DataObject::get_one(SiteTree::class, + $candidatePage = DataObject::get_one( + SiteTree::class, "\"URLSegment\" = '" . Convert::raw2sql(urldecode($rest)) . "' AND \"SubsiteID\" = " . $subsiteID, - false); + false + ); Subsite::disable_subsite_filter($origDisableSubsiteFilter); if ($candidatePage) { diff --git a/code/extensions/SubsiteMenuExtension.php b/code/extensions/SubsiteMenuExtension.php index a3ee1935..422df274 100644 --- a/code/extensions/SubsiteMenuExtension.php +++ b/code/extensions/SubsiteMenuExtension.php @@ -2,10 +2,8 @@ namespace SilverStripe\Subsites\Extensions; - use SilverStripe\Core\Extension; - /* * Simple extension to show admins in the menu of subsites. * If an admin area should be available to a subsite, you can attach diff --git a/code/forms/GridFieldSubsiteDetailForm_ItemRequest.php b/code/forms/GridFieldSubsiteDetailForm_ItemRequest.php index b42d55ce..c93a8866 100644 --- a/code/forms/GridFieldSubsiteDetailForm_ItemRequest.php +++ b/code/forms/GridFieldSubsiteDetailForm_ItemRequest.php @@ -36,8 +36,11 @@ public function ItemEditForm() $templateArray = $templates->map('ID', 'Title'); } - $templateDropdown = new DropdownField('TemplateID', _t('Subsite.COPYSTRUCTURE', 'Copy structure from:'), - $templateArray); + $templateDropdown = new DropdownField( + 'TemplateID', + _t('Subsite.COPYSTRUCTURE', 'Copy structure from:'), + $templateArray + ); $templateDropdown->setEmptyString('(' . _t('Subsite.NOTEMPLATE', 'No template') . ')'); $form->Fields()->addFieldToTab('Root.Configuration', $templateDropdown); } @@ -57,5 +60,4 @@ public function doSave($data, $form) return parent::doSave($data, $form); } - } diff --git a/code/forms/SubsitesTreeDropdownField.php b/code/forms/SubsitesTreeDropdownField.php index aa717152..287acb1c 100644 --- a/code/forms/SubsitesTreeDropdownField.php +++ b/code/forms/SubsitesTreeDropdownField.php @@ -2,14 +2,12 @@ namespace SilverStripe\Subsites\Forms; - use SilverStripe\Control\Controller; use SilverStripe\Control\HTTPRequest; use SilverStripe\Control\Session; use SilverStripe\Forms\TreeDropdownField; use SilverStripe\View\Requirements; - /** * Wraps around a TreedropdownField to add ability for temporary * switching of subsite sessions. diff --git a/code/forms/WildcardDomainField.php b/code/forms/WildcardDomainField.php index 4b1f09c8..6575a44a 100644 --- a/code/forms/WildcardDomainField.php +++ b/code/forms/WildcardDomainField.php @@ -2,6 +2,7 @@ namespace SilverStripe\Subsites\Forms; use SilverStripe\Forms\TextField; + /** * A text field that accepts only valid domain names, but allows the wildcard (*) character */ diff --git a/code/model/Subsite.php b/code/model/Subsite.php index 76bcc74c..e22233f0 100644 --- a/code/model/Subsite.php +++ b/code/model/Subsite.php @@ -35,7 +35,6 @@ use SilverStripe\Versioned\Versioned; use UnexpectedValueException; - /** * A dynamically created subsite. SiteTree objects can now belong to a subsite. * You can simulate subsite access without setting up virtual hosts by appending ?SubsiteID=' . _t('Subsite.DOMAINSAVEFIRST', - 'You can only add domains after saving for the first time') . '
' + '' . _t( + 'Subsite.DOMAINSAVEFIRST', + 'You can only add domains after saving for the first time' + ) . '
' ); } @@ -674,13 +689,13 @@ public function getCMSFields() asort($pageTypeMap); $fields = new FieldList( - $subsiteTabs = new TabSet('Root', + $subsiteTabs = new TabSet( + 'Root', new Tab( 'Configuration', _t('Subsite.TabTitleConfig', 'Configuration'), HeaderField::create('ConfigForSubsiteHeaderField', 'Subsite Configuration'), TextField::create('Title', $this->fieldLabel('Title'), $this->Title), - HeaderField::create( 'DomainsForSubsiteHeaderField', _t('Subsite.DomainsHeadline', 'Domains for this subsite') @@ -690,7 +705,6 @@ public function getCMSFields() // new TextField('RedirectURL', 'Redirect to URL', $this->RedirectURL), CheckboxField::create('DefaultSite', $this->fieldLabel('DefaultSite'), $this->DefaultSite), CheckboxField::create('IsPublic', $this->fieldLabel('IsPublic'), $this->IsPublic), - LiteralField::create( 'PageTypeBlacklistToggle', sprintf( @@ -712,9 +726,12 @@ public function getCMSFields() // If there are any themes available, add the dropdown $themes = $this->allowedThemes(); if (!empty($themes)) { - $fields->addFieldToTab('Root.Configuration', + $fields->addFieldToTab( + 'Root.Configuration', DropdownField::create('Theme', $this->fieldLabel('Theme'), $this->allowedThemes(), $this->Theme) - ->setEmptyString(_t('Subsite.ThemeFieldEmptyString', '-')), 'PageTypeBlacklistToggle'); + ->setEmptyString(_t('Subsite.ThemeFieldEmptyString', '-')), + 'PageTypeBlacklistToggle' + ); } $subsiteTabs->addExtraClass('subsite-model'); diff --git a/code/model/SubsiteDomain.php b/code/model/SubsiteDomain.php index bc7ccb3a..1a239049 100644 --- a/code/model/SubsiteDomain.php +++ b/code/model/SubsiteDomain.php @@ -10,7 +10,6 @@ use SilverStripe\ORM\DataObject; use SilverStripe\Subsites\Forms\WildcardDomainField; - /** * @property string $Domain domain name of this subsite. Can include wildcards. Do not include the URL scheme here * @property string $Protocol Required protocol (http or https) if only one is supported. 'automatic' implies diff --git a/code/pages/SubsitesVirtualPage.php b/code/pages/SubsitesVirtualPage.php index 023dfb93..e2a68ae1 100644 --- a/code/pages/SubsitesVirtualPage.php +++ b/code/pages/SubsitesVirtualPage.php @@ -2,7 +2,6 @@ namespace SilverStripe\Subsites\Pages; - use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\VirtualPage; use SilverStripe\Control\Controller; diff --git a/code/reports/SubsiteReportWrapper.php b/code/reports/SubsiteReportWrapper.php index 57f6695f..783b6fe6 100644 --- a/code/reports/SubsiteReportWrapper.php +++ b/code/reports/SubsiteReportWrapper.php @@ -2,13 +2,11 @@ namespace SilverStripe\Subsites\Reports; - use SilverStripe\Forms\FieldList; use SilverStripe\Forms\TreeMultiselectField; use SilverStripe\Reports\ReportWrapper; use SilverStripe\Subsites\Model\Subsite; - /** * Creates a subsite-aware version of another report. * Pass another report (or its classname) into the constructor. @@ -84,5 +82,4 @@ public function afterQuery() // Manually manage the subsite filtering Subsite::$force_subsite = null; } - } diff --git a/code/tasks/SubsiteCopyPagesTask.php b/code/tasks/SubsiteCopyPagesTask.php index cd6cc14a..f6ab4327 100644 --- a/code/tasks/SubsiteCopyPagesTask.php +++ b/code/tasks/SubsiteCopyPagesTask.php @@ -2,7 +2,6 @@ namespace SilverStripe\Subsites\Tasks; - use InvalidArgumentException; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Dev\BuildTask; @@ -11,7 +10,6 @@ use SilverStripe\Subsites\Pages\SubsitesVirtualPage; use SilverStripe\Versioned\Versioned; - /** * Handy alternative to copying pages when creating a subsite through the UI. * diff --git a/tests/SubsiteXHRControllerTest.php b/tests/SubsiteXHRControllerTest.php deleted file mode 100644 index f4cb3615..00000000 --- a/tests/SubsiteXHRControllerTest.php +++ /dev/null @@ -1,40 +0,0 @@ -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); - } -} diff --git a/tests/WildcardDomainFieldTest.php b/tests/WildcardDomainFieldTest.php deleted file mode 100644 index a096b8a4..00000000 --- a/tests/WildcardDomainFieldTest.php +++ /dev/null @@ -1,74 +0,0 @@ -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('*') - ); - } - -} diff --git a/tests/php/LeftAndMainSubsitesTest.php b/tests/php/LeftAndMainSubsitesTest.php index 7a9ca379..85565e98 100644 --- a/tests/php/LeftAndMainSubsitesTest.php +++ b/tests/php/LeftAndMainSubsitesTest.php @@ -76,10 +76,12 @@ public function testAccessChecksDontChangeCurrentSubsite() $left = new LeftAndMain(); $this->assertTrue($left->canView(), "Admin user can view subsites LeftAndMain with id = '$id'"); - $this->assertEquals($id, Subsite::currentSubsiteID(), - 'The current subsite has not been changed in the process of checking permissions for admin user.'); + $this->assertEquals( + $id, + Subsite::currentSubsiteID(), + 'The current subsite has not been changed in the process of checking permissions for admin user.' + ); } - } public function testShouldChangeSubsite() diff --git a/tests/php/SiteTreeSubsitesTest.php b/tests/php/SiteTreeSubsitesTest.php index ba97e8d9..c6155a8b 100644 --- a/tests/php/SiteTreeSubsitesTest.php +++ b/tests/php/SiteTreeSubsitesTest.php @@ -18,22 +18,24 @@ use SilverStripe\Subsites\Extensions\SiteTreeSubsites; use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Pages\SubsitesVirtualPage; +use SilverStripe\Subsites\Tests\SiteTreeSubsitesTest\TestClassA; +use SilverStripe\Subsites\Tests\SiteTreeSubsitesTest\TestClassB; +use SilverStripe\Subsites\Tests\SiteTreeSubsitesTest\TestErrorPage; use SilverStripe\Versioned\Versioned; use SilverStripe\View\SSViewer; class SiteTreeSubsitesTest extends BaseSubsiteTest { + protected static $fixture_file = 'subsites/tests/php/SubsiteTest.yml'; - public static $fixture_file = 'subsites/tests/php/SubsiteTest.yml'; - - protected $extraDataObjects = [ - 'SiteTreeSubsitesTest_ClassA', - 'SiteTreeSubsitesTest_ClassB', - 'SiteTreeSubsitesTest_ErrorPage' + protected static $extra_dataobjects = [ + TestClassA::class, + TestClassB::class, + TestErrorPage::class ]; - protected $illegalExtensions = [ - SiteTree::class => ['Translatable'] + protected static $illegal_extensions = [ + SiteTree::class => ['Translatable'] // @todo implement Translatable namespace ]; public function testPagesInDifferentSubsitesCanShareURLSegment() @@ -51,7 +53,9 @@ public function testPagesInDifferentSubsitesCanShareURLSegment() $pageMainOther->write(); $pageMainOther->copyVersionToStage('Stage', 'Live'); - $this->assertNotEquals($pageMain->URLSegment, $pageMainOther->URLSegment, + $this->assertNotEquals( + $pageMain->URLSegment, + $pageMainOther->URLSegment, 'Pages in same subsite cant share the same URL' ); @@ -62,7 +66,9 @@ public function testPagesInDifferentSubsitesCanShareURLSegment() $pageSubsite1->write(); $pageSubsite1->copyVersionToStage('Stage', 'Live'); - $this->assertEquals($pageMain->URLSegment, $pageSubsite1->URLSegment, + $this->assertEquals( + $pageMain->URLSegment, + $pageSubsite1->URLSegment, 'Pages in different subsites can share the same URL' ); } @@ -171,31 +177,37 @@ public function testPageTypesBlacklistInClassDropdown() $s2 = $this->objFromFixture(Subsite::class, 'domaintest2'); $page = singleton(SiteTree::class); - $s1->PageTypeBlacklist = implode(',', [SiteTreeSubsitesTest_ClassA::class, ErrorPage::class]); + $s1->PageTypeBlacklist = implode(',', [TestClassA::class, ErrorPage::class]); $s1->write(); Subsite::changeSubsite($s1); $settingsFields = $page->getSettingsFields()->dataFieldByName('ClassName')->getSource(); - $this->assertArrayNotHasKey(ErrorPage::class, + $this->assertArrayNotHasKey( + ErrorPage::class, $settingsFields ); - $this->assertArrayNotHasKey(SiteTreeSubsitesTest_ClassA::class, + $this->assertArrayNotHasKey( + TestClassA::class, $settingsFields ); - $this->assertArrayHasKey(SiteTreeSubsitesTest_ClassB::class, + $this->assertArrayHasKey( + TestClassB::class, $settingsFields ); Subsite::changeSubsite($s2); $settingsFields = $page->getSettingsFields()->dataFieldByName('ClassName')->getSource(); - $this->assertArrayHasKey(ErrorPage::class, + $this->assertArrayHasKey( + ErrorPage::class, $settingsFields ); - $this->assertArrayHasKey(SiteTreeSubsitesTest_ClassA::class, + $this->assertArrayHasKey( + TestClassA::class, $settingsFields ); - $this->assertArrayHasKey(SiteTreeSubsitesTest_ClassB::class, + $this->assertArrayHasKey( + TestClassB::class, $settingsFields ); } @@ -238,22 +250,22 @@ 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(',', [TestClassA::class, ErrorPage::class]); $s1->write(); Subsite::changeSubsite($s1); $hints = Convert::json2array($cmsmain->SiteTreeHints()); $classes = $hints['Root']['disallowedChildren']; static::assertContains(ErrorPage::class, $classes); - static::assertContains(SiteTreeSubsitesTest_ClassA::class, $classes); - static::assertNotContains(SiteTreeSubsitesTest_ClassB::class, $classes); + static::assertContains(TestClassA::class, $classes); + static::assertNotContains(TestClassB::class, $classes); Subsite::changeSubsite($s2); $hints = Convert::json2array($cmsmain->SiteTreeHints()); $classes = $hints['Root']['disallowedChildren']; static::assertNotContains(ErrorPage::class, $classes); - static::assertNotContains(SiteTreeSubsitesTest_ClassA::class, $classes); - static::assertNotContains(SiteTreeSubsitesTest_ClassB::class, $classes); + static::assertNotContains(TestClassA::class, $classes); + static::assertNotContains(TestClassB::class, $classes); } /** @@ -280,8 +292,11 @@ public function testValidateURLSegment() $subsite1Home->write(); $this->assertEquals('home', $subsite1Home->URLSegment); $subsite1Home->doPublish(); - $subsite1HomeLive = Versioned::get_one_by_stage('Page', 'Live', - sprintf('"SiteTree"."ID" = \'%d\'', $subsite1Home->ID)); + $subsite1HomeLive = Versioned::get_one_by_stage( + 'Page', + 'Live', + sprintf('"SiteTree"."ID" = \'%d\'', $subsite1Home->ID) + ); $this->assertEquals('home', $subsite1HomeLive->URLSegment); // Creating a new page in a subsite doesn't conflict with urls in other subsites @@ -294,8 +309,11 @@ public function testValidateURLSegment() $subsite1NewPage->write(); $this->assertEquals('important-page', $subsite1NewPage->URLSegment); $subsite1NewPage->doPublish(); - $subsite1NewPageLive = Versioned::get_one_by_stage('Page', 'Live', - sprintf('"SiteTree"."ID" = \'%d\'', $subsite1NewPage->ID)); + $subsite1NewPageLive = Versioned::get_one_by_stage( + 'Page', + 'Live', + sprintf('"SiteTree"."ID" = \'%d\'', $subsite1NewPage->ID) + ); $this->assertEquals('important-page', $subsite1NewPageLive->URLSegment); // Creating a new page in a subsite DOES conflict with urls in the same subsite @@ -306,8 +324,11 @@ public function testValidateURLSegment() $subsite1NewPage2->write(); $this->assertEquals('important-page-2', $subsite1NewPage2->URLSegment); $subsite1NewPage2->doPublish(); - $subsite1NewPage2Live = Versioned::get_one_by_stage('Page', 'Live', - sprintf('"SiteTree"."ID" = \'%d\'', $subsite1NewPage2->ID)); + $subsite1NewPage2Live = Versioned::get_one_by_stage( + 'Page', + 'Live', + sprintf('"SiteTree"."ID" = \'%d\'', $subsite1NewPage2->ID) + ); $this->assertEquals('important-page-2', $subsite1NewPage2Live->URLSegment); // Original page is left un-modified @@ -326,8 +347,11 @@ public function testCopySubsiteWithChildren() $moved = $page->duplicateToSubsite($newSubsite->ID, true); $this->assertEquals($moved->SubsiteID, $newSubsite->ID, 'Ensure returned records are on new subsite'); - $this->assertEquals($moved->AllChildren()->count(), $page->AllChildren()->count(), - 'All pages are copied across'); + $this->assertEquals( + $moved->AllChildren()->count(), + $page->AllChildren()->count(), + 'All pages are copied across' + ); } public function testCopySubsiteWithoutChildren() @@ -353,39 +377,21 @@ public function testIfSubsiteThemeIsSetToThemeList() $controller = ModelAsController::controller_for($subsitePage); SiteTree::singleton()->extend('contentcontrollerInit', $controller); - $this->assertEquals(SSViewer::get_themes(), $defaultThemes, - 'Themes should not be modified when Subsite has no theme defined'); + $this->assertEquals( + SSViewer::get_themes(), + $defaultThemes, + 'Themes should not be modified when Subsite has no theme defined' + ); $pageWithTheme = $this->objFromFixture(Page::class, 'subsite1_home'); Subsite::changeSubsite($pageWithTheme->SubsiteID); $controller = ModelAsController::controller_for($pageWithTheme); SiteTree::singleton()->extend('contentcontrollerInit', $controller); $subsiteTheme = $pageWithTheme->Subsite()->Theme; - $this->assertEquals(SSViewer::get_themes(), array_merge([$subsiteTheme], $defaultThemes), - 'Themes should be modified when Subsite has theme defined'); - - } -} - - -class SiteTreeSubsitesTest_ClassA extends SiteTree implements TestOnly -{ -} - -class SiteTreeSubsitesTest_ClassB extends SiteTree implements TestOnly -{ -} - -class SiteTreeSubsitesTest_ErrorPage extends ErrorPage implements TestOnly -{ - /** - * Helper method to call protected members - * - * @param int $statusCode - * @return string - */ - public static function get_error_filename_spy($statusCode) - { - return self::get_error_filename($statusCode); + $this->assertEquals( + SSViewer::get_themes(), + array_merge([$subsiteTheme], $defaultThemes), + 'Themes should be modified when Subsite has theme defined' + ); } } diff --git a/tests/php/SiteTreeSubsitesTest/TestClassA.php b/tests/php/SiteTreeSubsitesTest/TestClassA.php new file mode 100644 index 00000000..e333fec6 --- /dev/null +++ b/tests/php/SiteTreeSubsitesTest/TestClassA.php @@ -0,0 +1,10 @@ +assertRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), 'Admin is disallowed'); $response = $this->getAndFollowAll('SubsiteXHRController'); - $this->assertRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), - 'SubsiteXHRController is disallowed'); + $this->assertRegExp( + '#^Security/login.*#', + $this->mainSession->lastUrl(), + 'SubsiteXHRController is disallowed' + ); } /** @@ -68,8 +71,11 @@ public function testAdminCanAccessAllSubsites() $this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section'); $response = $this->getAndFollowAll(SubsiteXHRController::class); - $this->assertNotRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), - 'SubsiteXHRController is reachable'); + $this->assertNotRegExp( + '#^Security/login.*#', + $this->mainSession->lastUrl(), + 'SubsiteXHRController is reachable' + ); } public function testAdminIsRedirectedToObjectsSubsite() @@ -85,20 +91,29 @@ public function testAdminIsRedirectedToObjectsSubsite() Config::modify()->set(CMSPageEditController::class, 'treats_subsite_0_as_global', false); Subsite::changeSubsite(0); $this->getAndFollowAll("admin/pages/edit/show/$subsite1Home->ID"); - $this->assertEquals(Subsite::currentSubsiteID(), $subsite1Home->SubsiteID, - 'Loading an object switches the subsite'); + $this->assertEquals( + Subsite::currentSubsiteID(), + $subsite1Home->SubsiteID, + 'Loading an object switches the subsite' + ); $this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section'); Config::modify()->set(CMSPageEditController::class, 'treats_subsite_0_as_global', true); Subsite::changeSubsite(0); $this->getAndFollowAll("admin/pages/edit/show/$subsite1Home->ID"); - $this->assertEquals(Subsite::currentSubsiteID(), $subsite1Home->SubsiteID, - 'Loading a non-main-site object still switches the subsite if configured with treats_subsite_0_as_global'); + $this->assertEquals( + Subsite::currentSubsiteID(), + $subsite1Home->SubsiteID, + 'Loading a non-main-site object still switches the subsite if configured with treats_subsite_0_as_global' + ); $this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section'); $this->getAndFollowAll("admin/pages/edit/show/$mainSubsitePage->ID"); - $this->assertNotEquals(Subsite::currentSubsiteID(), $mainSubsitePage->SubsiteID, - 'Loading a main-site object does not change the subsite if configured with treats_subsite_0_as_global'); + $this->assertNotEquals( + Subsite::currentSubsiteID(), + $mainSubsitePage->SubsiteID, + 'Loading a main-site object does not change the subsite if configured with treats_subsite_0_as_global' + ); $this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section'); Config::unnest(); @@ -123,8 +138,11 @@ public function testEditorCanAccessAllSubsites() $this->assertRegExp('#^admin/pages.*#', $this->mainSession->lastUrl(), 'Lands on the correct section'); $response = $this->getAndFollowAll('SubsiteXHRController'); - $this->assertNotRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), - 'SubsiteXHRController is reachable'); + $this->assertNotRegExp( + '#^Security/login.*#', + $this->mainSession->lastUrl(), + 'SubsiteXHRController is reachable' + ); } /** @@ -145,8 +163,11 @@ public function testSubsiteAdmin() // Check forbidden section in allowed subsite. $this->getAndFollowAll("admin/assets/?SubsiteID={$subsite1->ID}"); $this->assertEquals(Subsite::currentSubsiteID(), $subsite1->ID, 'Is redirected within subsite.'); - $this->assertNotRegExp('#^admin/assets/.*#', $this->mainSession->lastUrl(), - 'Is redirected away from forbidden section'); + $this->assertNotRegExp( + '#^admin/assets/.*#', + $this->mainSession->lastUrl(), + 'Is redirected away from forbidden section' + ); // Check forbidden site, on a section that's allowed on another subsite $this->getAndFollowAll('admin/pages/?SubsiteID=0'); @@ -159,7 +180,10 @@ public function testSubsiteAdmin() // Check the standalone XHR controller. $response = $this->getAndFollowAll(SubsiteXHRController::class); - $this->assertNotRegExp('#^Security/login.*#', $this->mainSession->lastUrl(), - 'SubsiteXHRController is reachable'); + $this->assertNotRegExp( + '#^Security/login.*#', + $this->mainSession->lastUrl(), + 'SubsiteXHRController is reachable' + ); } } diff --git a/tests/php/SubsiteAdminTest.php b/tests/php/SubsiteAdminTest.php index 54e6f0cd..2b33db07 100644 --- a/tests/php/SubsiteAdminTest.php +++ b/tests/php/SubsiteAdminTest.php @@ -31,11 +31,15 @@ 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", + $response2 = Director::test( + "admin/subsites/SilverStripe-Subsites-Model-Subsite/EditForm/field/SilverStripe-Subsites-Model-Subsite/item/$subsite1ID/edit", null, - $this->adminLoggedInSession()); - $this->assertTrue(strpos($response2->getBody(), 'id="Form_ItemEditForm_ID"') !== false, - 'Testing Form_ItemEditForm_ID exists'); + $this->adminLoggedInSession() + ); + $this->assertTrue( + strpos($response2->getBody(), 'id="Form_ItemEditForm_ID"') !== false, + 'Testing Form_ItemEditForm_ID exists' + ); $this->assertTrue(strpos($response2->getBody(), ' exists'); } @@ -56,12 +60,15 @@ public function testMainsiteAdminCanAccessAllSubsites() $this->assertArrayHasKey(0, $ids, 'Main site accessible'); $this->assertArrayHasKey($this->idFromFixture(Subsite::class, 'main'), $ids, 'Site with no groups inaccesible'); - $this->assertArrayHasKey($this->idFromFixture(Subsite::class, 'subsite1'), $ids, - 'Subsite1 Template inaccessible'); - $this->assertArrayHasKey($this->idFromFixture(Subsite::class, 'subsite2'), $ids, - 'Subsite2 Template inaccessible'); + $this->assertArrayHasKey( + $this->idFromFixture(Subsite::class, 'subsite1'), + $ids, + 'Subsite1 Template inaccessible' + ); + $this->assertArrayHasKey( + $this->idFromFixture(Subsite::class, 'subsite2'), + $ids, + 'Subsite2 Template inaccessible' + ); } - - } - diff --git a/tests/php/SubsiteFunctionalTest.php b/tests/php/SubsiteFunctionalTest.php index 4989283e..4b8322b4 100644 --- a/tests/php/SubsiteFunctionalTest.php +++ b/tests/php/SubsiteFunctionalTest.php @@ -2,7 +2,6 @@ namespace subsites\tests\php; - use Page; use SilverStripe\Dev\FunctionalTest; use SilverStripe\Subsites\Model\Subsite; @@ -24,15 +23,20 @@ public function testIfSubsiteThemeIsSetToThemeList() $subsitePage = $this->objFromFixture(Page::class, 'contact'); $this->get($subsitePage->AbsoluteLink()); $this->assertEquals($subsitePage->SubsiteID, Subsite::currentSubsiteID(), 'Subsite should be changed'); - $this->assertEquals(SSViewer::get_themes(), $defaultThemes, - 'Themes should not be modified when Subsite has no theme defined'); + $this->assertEquals( + SSViewer::get_themes(), + $defaultThemes, + 'Themes should not be modified when Subsite has no theme defined' + ); $pageWithTheme = $this->objFromFixture(Page::class, 'subsite1_contactus'); $this->get($pageWithTheme->AbsoluteLink()); $subsiteTheme = $pageWithTheme->Subsite()->Theme; $this->assertEquals($pageWithTheme->SubsiteID, Subsite::currentSubsiteID(), 'Subsite should be changed'); - $this->assertEquals(SSViewer::get_themes(), array_merge([$subsiteTheme], $defaultThemes), - 'Themes should be modified when Subsite has theme defined'); - + $this->assertEquals( + SSViewer::get_themes(), + array_merge([$subsiteTheme], $defaultThemes), + 'Themes should be modified when Subsite has theme defined' + ); } } diff --git a/tests/php/SubsiteTest.php b/tests/php/SubsiteTest.php index 73f3eb18..695ecf9e 100644 --- a/tests/php/SubsiteTest.php +++ b/tests/php/SubsiteTest.php @@ -82,7 +82,9 @@ public function testSubsiteCreation() $siteHome = DataObject::get_one('Page', "\"URLSegment\" = 'home'"); $this->assertNotEquals($siteHome, false, 'Home Page for subsite not found'); - $this->assertEquals($subsite->ID, $siteHome->SubsiteID, + $this->assertEquals( + $subsite->ID, + $siteHome->SubsiteID, 'createInstance() copies existing pages retaining the same URLSegment' ); @@ -262,23 +264,33 @@ protected function createSubsiteWithDomains($domains) */ public function testDefaultDomain() { - $this->assertEquals('one.example.org', - $this->objFromFixture(Subsite::class, 'domaintest1')->domain()); + $this->assertEquals( + 'one.example.org', + $this->objFromFixture(Subsite::class, 'domaintest1')->domain() + ); - $this->assertEquals('two.mysite.com', - $this->objFromFixture(Subsite::class, 'domaintest2')->domain()); + $this->assertEquals( + 'two.mysite.com', + $this->objFromFixture(Subsite::class, 'domaintest2')->domain() + ); $_SERVER['HTTP_HOST'] = 'www.example.org'; - $this->assertEquals('three.example.org', - $this->objFromFixture(Subsite::class, 'domaintest3')->domain()); + $this->assertEquals( + 'three.example.org', + $this->objFromFixture(Subsite::class, 'domaintest3')->domain() + ); $_SERVER['HTTP_HOST'] = 'mysite.example.org'; - $this->assertEquals('three.mysite.example.org', - $this->objFromFixture(Subsite::class, 'domaintest3')->domain()); + $this->assertEquals( + 'three.mysite.example.org', + $this->objFromFixture(Subsite::class, 'domaintest3')->domain() + ); $this->assertEquals($_SERVER['HTTP_HOST'], singleton(Subsite::class)->PrimaryDomain); - $this->assertEquals('http://' . $_SERVER['HTTP_HOST'] . Director::baseURL(), - singleton(Subsite::class)->absoluteBaseURL()); + $this->assertEquals( + 'http://' . $_SERVER['HTTP_HOST'] . Director::baseURL(), + singleton(Subsite::class)->absoluteBaseURL() + ); } /** @@ -358,14 +370,22 @@ public function testAllAccessibleSites() */ public function testAccessibleSites() { - $member1Sites = Subsite::accessible_sites('CMS_ACCESS_CMSMain', false, null, - $this->objFromFixture(Member::class, 'subsite1member')); + $member1Sites = Subsite::accessible_sites( + 'CMS_ACCESS_CMSMain', + false, + null, + $this->objFromFixture(Member::class, 'subsite1member') + ); $member1SiteTitles = $member1Sites->column('Title'); sort($member1SiteTitles); $this->assertEquals('Subsite1 Template', $member1SiteTitles[0], 'Member can get to a subsite via a group'); - $adminSites = Subsite::accessible_sites('CMS_ACCESS_CMSMain', false, null, - $this->objFromFixture(Member::class, 'admin')); + $adminSites = Subsite::accessible_sites( + 'CMS_ACCESS_CMSMain', + false, + null, + $this->objFromFixture(Member::class, 'admin') + ); $adminSiteTitles = $adminSites->column('Title'); sort($adminSiteTitles); $this->assertEquals([ @@ -380,7 +400,9 @@ public function testAccessibleSites() ], array_values($adminSiteTitles)); $member2Sites = Subsite::accessible_sites( - 'CMS_ACCESS_CMSMain', false, null, + 'CMS_ACCESS_CMSMain', + false, + null, $this->objFromFixture(Member::class, 'subsite1member2') ); $member2SiteTitles = $member2Sites->column('Title'); diff --git a/tests/php/SubsitesVirtualPageTest.php b/tests/php/SubsitesVirtualPageTest.php index 8d5c53e7..94f1058c 100644 --- a/tests/php/SubsitesVirtualPageTest.php +++ b/tests/php/SubsitesVirtualPageTest.php @@ -97,10 +97,14 @@ public function testFileLinkRewritingOnVirtualPages() $file->write(); // Verify that the draft and publish virtual pages both have the corrected link - static::assertContains('ID")->value()); - static::assertContains('ID")->value()); + static::assertContains( + 'ID")->value() + ); + static::assertContains( + 'ID")->value() + ); } public function testSubsiteVirtualPagesArentInappropriatelyPublished() diff --git a/tests/php/WildcardDomainFieldTest.php b/tests/php/WildcardDomainFieldTest.php index 9fcbd75f..20a7fb62 100644 --- a/tests/php/WildcardDomainFieldTest.php +++ b/tests/php/WildcardDomainFieldTest.php @@ -83,5 +83,4 @@ public function validWildcards() ['*'] ]; } - }