mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
Get some more tests working
Updating config and i18n calls
This commit is contained in:
parent
492f437589
commit
997459caf3
@ -36,10 +36,6 @@ SilverStripe\SiteConfig\SiteConfig:
|
|||||||
extensions:
|
extensions:
|
||||||
- SilverStripe\Subsites\Extensions\SiteConfigSubsites
|
- SilverStripe\Subsites\Extensions\SiteConfigSubsites
|
||||||
|
|
||||||
SilverStripe\Reports\Report:
|
|
||||||
extensions:
|
|
||||||
- SilverStripe\Subsites\SubsiteReportWrapper
|
|
||||||
|
|
||||||
SilverStripe\AssetAdmin\Controller\AssetAdmin:
|
SilverStripe\AssetAdmin\Controller\AssetAdmin:
|
||||||
extensions:
|
extensions:
|
||||||
- SilverStripe\Subsites\Extensions\SubsiteMenuExtension
|
- SilverStripe\Subsites\Extensions\SubsiteMenuExtension
|
||||||
|
@ -42,8 +42,11 @@ class GroupSubsites extends DataExtension implements PermissionProvider
|
|||||||
*/
|
*/
|
||||||
public function requireDefaultRecords()
|
public function requireDefaultRecords()
|
||||||
{
|
{
|
||||||
|
if (!$this->owner) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Migration for Group.SubsiteID data from when Groups only had a single subsite
|
// Migration for Group.SubsiteID data from when Groups only had a single subsite
|
||||||
$schema = $this->owner->getSchema();
|
$schema = $this->owner::getSchema();
|
||||||
$groupFields = DB::field_list($schema->tableName(Group::class));
|
$groupFields = DB::field_list($schema->tableName(Group::class));
|
||||||
|
|
||||||
// Detection of SubsiteID field is the trigger for old-style-subsiteID migration
|
// Detection of SubsiteID field is the trigger for old-style-subsiteID migration
|
||||||
|
@ -186,8 +186,8 @@ class Subsite extends DataObject
|
|||||||
Session::set('SubsiteID', (int)$subsiteID);
|
Session::set('SubsiteID', (int)$subsiteID);
|
||||||
|
|
||||||
// Set locale
|
// Set locale
|
||||||
if (is_object($subsite) && $subsite->Language != '') {
|
if (is_object($subsite) && $subsite->Language !== '') {
|
||||||
$locale = i18n::get_locale_from_lang($subsite->Language);
|
$locale = (new IntlLocales())->localeFromLang($subsite->Language);
|
||||||
if ($locale) {
|
if ($locale) {
|
||||||
i18n::set_locale($locale);
|
i18n::set_locale($locale);
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ class SubsitesVirtualPage extends VirtualPage
|
|||||||
TextareaField::create(
|
TextareaField::create(
|
||||||
'CustomMetaKeywords',
|
'CustomMetaKeywords',
|
||||||
$this->fieldLabel('CustomMetaTitle')
|
$this->fieldLabel('CustomMetaTitle')
|
||||||
)->setDescription(_t('SubsitesVirtualPage.OverrideNote')),
|
)->setDescription(_t('SubsitesVirtualPage.OverrideNote', 'Overrides inherited value from the source')),
|
||||||
'MetaKeywords'
|
'MetaKeywords'
|
||||||
);
|
);
|
||||||
$fields->addFieldToTab(
|
$fields->addFieldToTab(
|
||||||
@ -108,7 +108,7 @@ class SubsitesVirtualPage extends VirtualPage
|
|||||||
TextareaField::create(
|
TextareaField::create(
|
||||||
'CustomMetaDescription',
|
'CustomMetaDescription',
|
||||||
$this->fieldLabel('CustomMetaTitle')
|
$this->fieldLabel('CustomMetaTitle')
|
||||||
)->setDescription(_t('SubsitesVirtualPage.OverrideNote')),
|
)->setDescription(_t('SubsitesVirtualPage.OverrideNote', 'Overrides inherited value from the source')),
|
||||||
'MetaDescription'
|
'MetaDescription'
|
||||||
);
|
);
|
||||||
$fields->addFieldToTab(
|
$fields->addFieldToTab(
|
||||||
@ -116,7 +116,7 @@ class SubsitesVirtualPage extends VirtualPage
|
|||||||
TextField::create(
|
TextField::create(
|
||||||
'CustomExtraMeta',
|
'CustomExtraMeta',
|
||||||
$this->fieldLabel('CustomMetaTitle')
|
$this->fieldLabel('CustomMetaTitle')
|
||||||
)->setDescription(_t('SubsitesVirtualPage.OverrideNote')),
|
)->setDescription(_t('SubsitesVirtualPage.OverrideNote', 'Overrides inherited value from the source')),
|
||||||
'ExtraMeta'
|
'ExtraMeta'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@ class GroupSubsitesTest extends BaseSubsiteTest
|
|||||||
protected $requireDefaultRecordsFrom = [GroupSubsites::class];
|
protected $requireDefaultRecordsFrom = [GroupSubsites::class];
|
||||||
public function testTrivialFeatures()
|
public function testTrivialFeatures()
|
||||||
{
|
{
|
||||||
$this->assertTrue(is_array(singleton('GroupSubsites')->extraStatics()));
|
$this->assertTrue(is_array(singleton(GroupSubsites::class)->extraStatics()));
|
||||||
$this->assertTrue(is_array(singleton('GroupSubsites')->providePermissions()));
|
$this->assertTrue(is_array(singleton(GroupSubsites::class)->providePermissions()));
|
||||||
$this->assertTrue(singleton(Group::class)->getCMSFields() instanceof FieldList);
|
$this->assertTrue(singleton(Group::class)->getCMSFields() instanceof FieldList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ class LeftAndMainSubsitesTest extends FunctionalTest
|
|||||||
public function testShouldChangeSubsite()
|
public function testShouldChangeSubsite()
|
||||||
{
|
{
|
||||||
$l = new LeftAndMain();
|
$l = new LeftAndMain();
|
||||||
Config::inst()->nest();
|
Config::nest();
|
||||||
|
|
||||||
Config::modify()->set(CMSPageEditController::class, 'treats_subsite_0_as_global', false);
|
Config::modify()->set(CMSPageEditController::class, 'treats_subsite_0_as_global', false);
|
||||||
$this->assertTrue($l->shouldChangeSubsite(CMSPageEditController::class, 0, 5));
|
$this->assertTrue($l->shouldChangeSubsite(CMSPageEditController::class, 0, 5));
|
||||||
@ -96,6 +96,6 @@ class LeftAndMainSubsitesTest extends FunctionalTest
|
|||||||
$this->assertTrue($l->shouldChangeSubsite(CMSPageEditController::class, 1, 5));
|
$this->assertTrue($l->shouldChangeSubsite(CMSPageEditController::class, 1, 5));
|
||||||
$this->assertFalse($l->shouldChangeSubsite(CMSPageEditController::class, 1, 1));
|
$this->assertFalse($l->shouldChangeSubsite(CMSPageEditController::class, 1, 1));
|
||||||
|
|
||||||
Config::inst()->unnest();
|
Config::unnest();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ use SilverStripe\SiteConfig\SiteConfig;
|
|||||||
use SilverStripe\Subsites\Extensions\SiteConfigSubsites;
|
use SilverStripe\Subsites\Extensions\SiteConfigSubsites;
|
||||||
use SilverStripe\Subsites\Model\Subsite;
|
use SilverStripe\Subsites\Model\Subsite;
|
||||||
|
|
||||||
|
|
||||||
class SiteConfigSubsitesTest extends BaseSubsiteTest
|
class SiteConfigSubsitesTest extends BaseSubsiteTest
|
||||||
{
|
{
|
||||||
public static $fixture_file = 'subsites/tests/php/SubsiteTest.yml';
|
public static $fixture_file = 'subsites/tests/php/SubsiteTest.yml';
|
||||||
|
@ -2,22 +2,22 @@
|
|||||||
|
|
||||||
namespace SilverStripe\Subsites\Tests;
|
namespace SilverStripe\Subsites\Tests;
|
||||||
|
|
||||||
use SilverStripe\CMS\Model\SiteTree;
|
use Page;
|
||||||
use SilverStripe\SiteConfig\SiteConfig;
|
|
||||||
use SilverStripe\Forms\FieldList;
|
|
||||||
use SilverStripe\CMS\Model\ErrorPage;
|
|
||||||
use SilverStripe\Core\Config\Config;
|
|
||||||
use SilverStripe\Security\Member;
|
|
||||||
use SilverStripe\Control\Session;
|
|
||||||
use SilverStripe\Control\Director;
|
|
||||||
use SilverStripe\CMS\Controllers\CMSMain;
|
use SilverStripe\CMS\Controllers\CMSMain;
|
||||||
|
use SilverStripe\CMS\Model\ErrorPage;
|
||||||
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
|
use SilverStripe\Control\Director;
|
||||||
|
use SilverStripe\Control\Session;
|
||||||
|
use SilverStripe\Core\Config\Config;
|
||||||
use SilverStripe\Core\Convert;
|
use SilverStripe\Core\Convert;
|
||||||
use SilverStripe\Versioned\Versioned;
|
|
||||||
use SilverStripe\Dev\TestOnly;
|
use SilverStripe\Dev\TestOnly;
|
||||||
|
use SilverStripe\Forms\FieldList;
|
||||||
|
use SilverStripe\Security\Member;
|
||||||
|
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\Versioned\Versioned;
|
||||||
|
|
||||||
class SiteTreeSubsitesTest extends BaseSubsiteTest
|
class SiteTreeSubsitesTest extends BaseSubsiteTest
|
||||||
{
|
{
|
||||||
@ -34,7 +34,8 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
|||||||
SiteTree::class => ['Translatable']
|
SiteTree::class => ['Translatable']
|
||||||
];
|
];
|
||||||
|
|
||||||
public function testPagesInDifferentSubsitesCanShareURLSegment() {
|
public function testPagesInDifferentSubsitesCanShareURLSegment()
|
||||||
|
{
|
||||||
$subsiteMain = $this->objFromFixture(Subsite::class, 'main');
|
$subsiteMain = $this->objFromFixture(Subsite::class, 'main');
|
||||||
$subsite1 = $this->objFromFixture(Subsite::class, 'subsite1');
|
$subsite1 = $this->objFromFixture(Subsite::class, 'subsite1');
|
||||||
|
|
||||||
@ -62,9 +63,10 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
|||||||
$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'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testBasicSanity() {
|
public function testBasicSanity()
|
||||||
|
{
|
||||||
$this->assertTrue(singleton(SiteTree::class)->getSiteConfig() instanceof SiteConfig);
|
$this->assertTrue(singleton(SiteTree::class)->getSiteConfig() instanceof SiteConfig);
|
||||||
// The following assert is breaking in Translatable.
|
// The following assert is breaking in Translatable.
|
||||||
$this->assertTrue(singleton(SiteTree::class)->getCMSFields() instanceof FieldList);
|
$this->assertTrue(singleton(SiteTree::class)->getCMSFields() instanceof FieldList);
|
||||||
@ -72,16 +74,17 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
|||||||
$this->assertTrue(is_array(singleton(SiteTreeSubsites::class)->extraStatics()));
|
$this->assertTrue(is_array(singleton(SiteTreeSubsites::class)->extraStatics()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testErrorPageLocations() {
|
public function testErrorPageLocations()
|
||||||
$subsite1 = $this->objFromFixture(Subsite::class, 'domaintest1');
|
{
|
||||||
|
$subsite1 = $this->objFromFixture(Subsite::class, 'domaintest1');
|
||||||
|
|
||||||
Subsite::changeSubsite($subsite1->ID);
|
Subsite::changeSubsite($subsite1->ID);
|
||||||
$path = ErrorPage::get_filepath_for_errorcode(500);
|
$path = ErrorPage::get_filepath_for_errorcode(500);
|
||||||
|
|
||||||
$static_path = Config::inst()->get(ErrorPage::class, 'static_filepath');
|
$static_path = Config::inst()->get(ErrorPage::class, 'static_filepath');
|
||||||
$expected_path = $static_path . '/error-500-'.$subsite1->domain().'.html';
|
$expected_path = $static_path . '/error-500-' . $subsite1->domain() . '.html';
|
||||||
$this->assertEquals($expected_path, $path);
|
$this->assertEquals($expected_path, $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanEditSiteTree()
|
public function testCanEditSiteTree()
|
||||||
{
|
{
|
||||||
@ -94,48 +97,49 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
|||||||
$subsite1 = $this->objFromFixture(Subsite::class, 'subsite1');
|
$subsite1 = $this->objFromFixture(Subsite::class, 'subsite1');
|
||||||
$subsite2 = $this->objFromFixture(Subsite::class, 'subsite2');
|
$subsite2 = $this->objFromFixture(Subsite::class, 'subsite2');
|
||||||
|
|
||||||
// Cant pass member as arguments to canEdit() because of GroupSubsites
|
// Cant pass member as arguments to canEdit() because of GroupSubsites
|
||||||
Session::set("loggedInAs", $admin->ID);
|
Session::set("loggedInAs", $admin->ID);
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
(bool)$subsite1page->canEdit(),
|
(bool)$subsite1page->canEdit(),
|
||||||
'Administrators can edit all subsites'
|
'Administrators can edit all subsites'
|
||||||
);
|
);
|
||||||
|
|
||||||
// @todo: Workaround because GroupSubsites->augmentSQL() is relying on session state
|
// @todo: Workaround because GroupSubsites->augmentSQL() is relying on session state
|
||||||
Subsite::changeSubsite($subsite1);
|
Subsite::changeSubsite($subsite1);
|
||||||
|
|
||||||
Session::set("loggedInAs", $subsite1member->ID);
|
Session::set("loggedInAs", $subsite1member->ID);
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
(bool)$subsite1page->canEdit(),
|
(bool)$subsite1page->canEdit(),
|
||||||
'Members can edit pages on a subsite if they are in a group belonging to this subsite'
|
'Members can edit pages on a subsite if they are in a group belonging to this subsite'
|
||||||
);
|
);
|
||||||
|
|
||||||
Session::set("loggedInAs", $subsite2member->ID);
|
Session::set("loggedInAs", $subsite2member->ID);
|
||||||
$this->assertFalse(
|
$this->assertFalse(
|
||||||
(bool)$subsite1page->canEdit(),
|
(bool)$subsite1page->canEdit(),
|
||||||
'Members cant edit pages on a subsite if they are not in a group belonging to this subsite'
|
'Members cant edit pages on a subsite if they are not in a group belonging to this subsite'
|
||||||
);
|
);
|
||||||
|
|
||||||
// @todo: Workaround because GroupSubsites->augmentSQL() is relying on session state
|
// @todo: Workaround because GroupSubsites->augmentSQL() is relying on session state
|
||||||
Subsite::changeSubsite(0);
|
Subsite::changeSubsite(0);
|
||||||
$this->assertFalse(
|
$this->assertFalse(
|
||||||
$mainpage->canEdit(),
|
$mainpage->canEdit(),
|
||||||
'Members cant edit pages on the main site if they are not in a group allowing this'
|
'Members cant edit pages on the main site if they are not in a group allowing this'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Similar to {@link SubsitesVirtualPageTest->testSubsiteVirtualPageCanHaveSameUrlsegmentAsOtherSubsite()}.
|
* Similar to {@link SubsitesVirtualPageTest->testSubsiteVirtualPageCanHaveSameUrlsegmentAsOtherSubsite()}.
|
||||||
*/
|
*/
|
||||||
public function testTwoPagesWithSameURLOnDifferentSubsites() {
|
public function testTwoPagesWithSameURLOnDifferentSubsites()
|
||||||
// Set up a couple of pages with the same URL on different subsites
|
{
|
||||||
|
// Set up a couple of pages with the same URL on different subsites
|
||||||
$s1 = $this->objFromFixture(Subsite::class, 'domaintest1');
|
$s1 = $this->objFromFixture(Subsite::class, 'domaintest1');
|
||||||
$s2 = $this->objFromFixture(Subsite::class, 'domaintest2');
|
$s2 = $this->objFromFixture(Subsite::class, 'domaintest2');
|
||||||
|
|
||||||
$p1 = new SiteTree();
|
$p1 = new SiteTree();
|
||||||
$p1->Title = $p1->URLSegment = "test-page";
|
$p1->Title = $p1->URLSegment = "test-page";
|
||||||
$p1->SubsiteID = $s1->ID;
|
$p1->SubsiteID = $s1->ID;
|
||||||
$p1->write();
|
$p1->write();
|
||||||
|
|
||||||
$p2 = new SiteTree();
|
$p2 = new SiteTree();
|
||||||
$p2->Title = $p1->URLSegment = "test-page";
|
$p2->Title = $p1->URLSegment = "test-page";
|
||||||
@ -150,48 +154,50 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
|||||||
Subsite::changeSubsite($s1);
|
Subsite::changeSubsite($s1);
|
||||||
$this->assertEquals($p1->ID, SiteTree::get_by_link('test-page')->ID);
|
$this->assertEquals($p1->ID, SiteTree::get_by_link('test-page')->ID);
|
||||||
|
|
||||||
Subsite::changeSubsite($s2);
|
Subsite::changeSubsite($s2);
|
||||||
$this->assertEquals($p2->ID, SiteTree::get_by_link('test-page')->ID);
|
$this->assertEquals($p2->ID, SiteTree::get_by_link('test-page')->ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPageTypesBlacklistInClassDropdown() {
|
public function testPageTypesBlacklistInClassDropdown()
|
||||||
$editor = $this->objFromFixture(Member::class, 'editor');
|
{
|
||||||
Session::set("loggedInAs", $editor->ID);
|
$editor = $this->objFromFixture(Member::class, 'editor');
|
||||||
|
Session::set("loggedInAs", $editor->ID);
|
||||||
|
|
||||||
$s1 = $this->objFromFixture(Subsite::class, 'domaintest1');
|
$s1 = $this->objFromFixture(Subsite::class, 'domaintest1');
|
||||||
$s2 = $this->objFromFixture(Subsite::class, 'domaintest2');
|
$s2 = $this->objFromFixture(Subsite::class, 'domaintest2');
|
||||||
$page = singleton('SiteTree');
|
$page = singleton(SiteTree::class);
|
||||||
|
|
||||||
$s1->PageTypeBlacklist = 'SiteTreeSubsitesTest_ClassA,ErrorPage';
|
$s1->PageTypeBlacklist = 'SiteTreeSubsitesTest_ClassA,ErrorPage';
|
||||||
$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',
|
$this->assertArrayNotHasKey('SiteTreeSubsitesTest_ClassA',
|
||||||
$settingsFields
|
$settingsFields
|
||||||
);
|
);
|
||||||
$this->assertArrayHasKey('SiteTreeSubsitesTest_ClassB',
|
$this->assertArrayHasKey('SiteTreeSubsitesTest_ClassB',
|
||||||
$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',
|
$this->assertArrayHasKey('SiteTreeSubsitesTest_ClassA',
|
||||||
$settingsFields
|
$settingsFields
|
||||||
);
|
);
|
||||||
$this->assertArrayHasKey('SiteTreeSubsitesTest_ClassB',
|
$this->assertArrayHasKey('SiteTreeSubsitesTest_ClassB',
|
||||||
$settingsFields
|
$settingsFields
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCopyToSubsite() {
|
public function testCopyToSubsite()
|
||||||
|
{
|
||||||
// Remove baseurl if testing in subdir
|
// Remove baseurl if testing in subdir
|
||||||
Config::modify()->set(Director::class, 'alternate_base_url', '/');
|
Config::modify()->set(Director::class, 'alternate_base_url', '/');
|
||||||
|
|
||||||
@ -214,40 +220,43 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
|||||||
|
|
||||||
// Staff is shifted to top level and given a unique url segment
|
// Staff is shifted to top level and given a unique url segment
|
||||||
$domain = $otherSubsite->domain();
|
$domain = $otherSubsite->domain();
|
||||||
$this->assertEquals('http://'.$domain.'/staff-2/', $staffPage2->AbsoluteLink());
|
$this->assertEquals('http://' . $domain . '/staff-2/', $staffPage2->AbsoluteLink());
|
||||||
$this->assertEquals('http://'.$domain.'/contact-us-2/', $contactPage2->AbsoluteLink());
|
$this->assertEquals('http://' . $domain . '/contact-us-2/', $contactPage2->AbsoluteLink());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPageTypesBlacklistInCMSMain() {
|
public function testPageTypesBlacklistInCMSMain()
|
||||||
$editor = $this->objFromFixture(Member::class, 'editor');
|
{
|
||||||
Session::set("loggedInAs", $editor->ID);
|
$editor = $this->objFromFixture(Member::class, 'editor');
|
||||||
|
Session::set("loggedInAs", $editor->ID);
|
||||||
|
|
||||||
$cmsmain = new CMSMain();
|
$cmsmain = new CMSMain();
|
||||||
|
|
||||||
$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 = 'SiteTreeSubsitesTest_ClassA,ErrorPage';
|
$s1->PageTypeBlacklist = 'SiteTreeSubsitesTest_ClassA,ErrorPage';
|
||||||
$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'];
|
||||||
$this->assertContains(ErrorPage::class, $classes);
|
$this->assertContains(ErrorPage::class, $classes);
|
||||||
$this->assertContains('SiteTreeSubsitesTest_ClassA', $classes);
|
$this->assertContains('SiteTreeSubsitesTest_ClassA', $classes);
|
||||||
$this->assertNotContains('SiteTreeSubsitesTest_ClassB', $classes);
|
$this->assertNotContains('SiteTreeSubsitesTest_ClassB', $classes);
|
||||||
|
|
||||||
|
Subsite::changeSubsite($s2);
|
||||||
|
$hints = Convert::json2array($cmsmain->SiteTreeHints());
|
||||||
|
$classes = $hints['Root']['disallowedChildren'];
|
||||||
|
$this->assertNotContains(ErrorPage::class, $classes);
|
||||||
|
$this->assertNotContains('SiteTreeSubsitesTest_ClassA', $classes);
|
||||||
|
$this->assertNotContains('SiteTreeSubsitesTest_ClassB', $classes);
|
||||||
|
}
|
||||||
|
|
||||||
Subsite::changeSubsite($s2);
|
|
||||||
$hints = Convert::json2array($cmsmain->SiteTreeHints());
|
|
||||||
$classes = $hints['Root']['disallowedChildren'];
|
|
||||||
$this->assertNotContains(ErrorPage::class, $classes);
|
|
||||||
$this->assertNotContains('SiteTreeSubsitesTest_ClassA', $classes);
|
|
||||||
$this->assertNotContains('SiteTreeSubsitesTest_ClassB', $classes);
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Tests that url segments between subsites don't conflict, but do conflict within them
|
* Tests that url segments between subsites don't conflict, but do conflict within them
|
||||||
*/
|
*/
|
||||||
public function testValidateURLSegment() {
|
public function testValidateURLSegment()
|
||||||
|
{
|
||||||
$this->logInWithPermission('ADMIN');
|
$this->logInWithPermission('ADMIN');
|
||||||
// Saving existing page in the same subsite doesn't change urls
|
// Saving existing page in the same subsite doesn't change urls
|
||||||
$mainHome = $this->objFromFixture('Page', 'home');
|
$mainHome = $this->objFromFixture('Page', 'home');
|
||||||
@ -267,7 +276,8 @@ 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', 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);
|
$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
|
||||||
@ -280,7 +290,8 @@ 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', 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);
|
$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
|
||||||
@ -291,7 +302,8 @@ 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', 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);
|
$this->assertEquals('important-page-2', $subsite1NewPage2Live->URLSegment);
|
||||||
|
|
||||||
// Original page is left un-modified
|
// Original page is left un-modified
|
||||||
@ -303,16 +315,19 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
|||||||
$this->assertEquals('important-page', $mainSubsiteImportantPage->URLSegment);
|
$this->assertEquals('important-page', $mainSubsiteImportantPage->URLSegment);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCopySubsiteWithChildren() {
|
public function testCopySubsiteWithChildren()
|
||||||
|
{
|
||||||
$page = $this->objFromFixture('Page', 'about');
|
$page = $this->objFromFixture('Page', 'about');
|
||||||
$newSubsite = $this->objFromFixture(Subsite::class, 'subsite1');
|
$newSubsite = $this->objFromFixture(Subsite::class, 'subsite1');
|
||||||
|
|
||||||
$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(), 'All pages are copied across');
|
$this->assertEquals($moved->AllChildren()->count(), $page->AllChildren()->count(),
|
||||||
|
'All pages are copied across');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCopySubsiteWithoutChildren() {
|
public function testCopySubsiteWithoutChildren()
|
||||||
|
{
|
||||||
$page = $this->objFromFixture('Page', 'about');
|
$page = $this->objFromFixture('Page', 'about');
|
||||||
$newSubsite = $this->objFromFixture(Subsite::class, 'subsite2');
|
$newSubsite = $this->objFromFixture(Subsite::class, 'subsite2');
|
||||||
|
|
||||||
@ -326,6 +341,7 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
|||||||
class SiteTreeSubsitesTest_ClassA extends SiteTree implements TestOnly
|
class SiteTreeSubsitesTest_ClassA extends SiteTree implements TestOnly
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
class SiteTreeSubsitesTest_ClassB extends SiteTree implements TestOnly
|
class SiteTreeSubsitesTest_ClassB extends SiteTree implements TestOnly
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
|
|||||||
$mainSubsitePage = $this->objFromFixture('Page', 'mainSubsitePage');
|
$mainSubsitePage = $this->objFromFixture('Page', 'mainSubsitePage');
|
||||||
$subsite1Home = $this->objFromFixture('Page', 'subsite1_home');
|
$subsite1Home = $this->objFromFixture('Page', 'subsite1_home');
|
||||||
|
|
||||||
Config::inst()->nest();
|
Config::nest();
|
||||||
|
|
||||||
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);
|
||||||
@ -96,7 +96,7 @@ class SubsiteAdminFunctionalTest extends FunctionalTest
|
|||||||
$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');
|
$this->assertRegExp("#^admin/pages.*#", $this->mainSession->lastUrl(), 'Lands on the correct section');
|
||||||
|
|
||||||
Config::inst()->unnest();
|
Config::unnest();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace SilverStripe\Subsites\Tests;
|
namespace SilverStripe\Subsites\Tests;
|
||||||
|
|
||||||
|
use Page;
|
||||||
use SilverStripe\CMS\Model\SiteTree;
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
use SilverStripe\Control\Director;
|
use SilverStripe\Control\Director;
|
||||||
use SilverStripe\Core\Config\Config;
|
use SilverStripe\Core\Config\Config;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace SilverStripe\Subsites\Tests;
|
namespace SilverStripe\Subsites\Tests;
|
||||||
|
|
||||||
|
use Page;
|
||||||
use SilverStripe\Assets\Filesystem;
|
use SilverStripe\Assets\Filesystem;
|
||||||
use SilverStripe\Assets\Tests\Storage\AssetStoreTest\TestAssetStore;
|
use SilverStripe\Assets\Tests\Storage\AssetStoreTest\TestAssetStore;
|
||||||
use SilverStripe\Control\Director;
|
use SilverStripe\Control\Director;
|
||||||
@ -17,7 +18,7 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest
|
|||||||
{
|
{
|
||||||
public static $fixture_file = array(
|
public static $fixture_file = array(
|
||||||
'subsites/tests/php/SubsiteTest.yml',
|
'subsites/tests/php/SubsiteTest.yml',
|
||||||
'subsites/tests/SubsitesVirtualPageTest.yml',
|
'subsites/tests/php/SubsitesVirtualPageTest.yml',
|
||||||
);
|
);
|
||||||
|
|
||||||
protected $illegalExtensions = array(
|
protected $illegalExtensions = array(
|
||||||
|
Loading…
Reference in New Issue
Block a user