2010-03-21 23:32:22 +01:00
|
|
|
<?php
|
|
|
|
|
2017-04-23 22:23:34 +02:00
|
|
|
namespace SilverStripe\Subsites\Tests;
|
|
|
|
|
2017-05-30 17:35:02 +02:00
|
|
|
use Page;
|
|
|
|
use SilverStripe\CMS\Controllers\CMSMain;
|
2017-06-07 11:57:32 +02:00
|
|
|
use SilverStripe\CMS\Controllers\ModelAsController;
|
2017-05-30 17:35:02 +02:00
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
2017-05-29 13:42:42 +02:00
|
|
|
use SilverStripe\Control\Director;
|
2017-05-30 17:35:02 +02:00
|
|
|
use SilverStripe\Core\Config\Config;
|
2016-09-22 16:38:29 +02:00
|
|
|
use SilverStripe\Core\Convert;
|
2017-09-06 15:56:15 +02:00
|
|
|
use SilverStripe\ErrorPage\ErrorPage;
|
2017-05-30 17:35:02 +02:00
|
|
|
use SilverStripe\Forms\FieldList;
|
|
|
|
use SilverStripe\Security\Member;
|
|
|
|
use SilverStripe\SiteConfig\SiteConfig;
|
2017-05-24 15:26:28 +02:00
|
|
|
use SilverStripe\Subsites\Extensions\SiteTreeSubsites;
|
2017-05-24 15:25:34 +02:00
|
|
|
use SilverStripe\Subsites\Model\Subsite;
|
|
|
|
use SilverStripe\Subsites\Pages\SubsitesVirtualPage;
|
2017-08-29 07:07:24 +02:00
|
|
|
use SilverStripe\Subsites\Tests\SiteTreeSubsitesTest\TestClassA;
|
|
|
|
use SilverStripe\Subsites\Tests\SiteTreeSubsitesTest\TestClassB;
|
|
|
|
use SilverStripe\Subsites\Tests\SiteTreeSubsitesTest\TestErrorPage;
|
2017-05-30 17:35:02 +02:00
|
|
|
use SilverStripe\Versioned\Versioned;
|
2017-06-07 11:57:32 +02:00
|
|
|
use SilverStripe\View\SSViewer;
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2017-05-24 15:26:28 +02:00
|
|
|
class SiteTreeSubsitesTest extends BaseSubsiteTest
|
|
|
|
{
|
2017-08-29 07:22:32 +02:00
|
|
|
protected static $fixture_file = 'SubsiteTest.yml';
|
2017-05-24 15:26:28 +02:00
|
|
|
|
2017-08-29 07:07:24 +02:00
|
|
|
protected static $extra_dataobjects = [
|
|
|
|
TestClassA::class,
|
|
|
|
TestClassB::class,
|
|
|
|
TestErrorPage::class
|
2017-05-24 15:26:28 +02:00
|
|
|
];
|
|
|
|
|
2017-08-29 07:07:24 +02:00
|
|
|
protected static $illegal_extensions = [
|
|
|
|
SiteTree::class => ['Translatable'] // @todo implement Translatable namespace
|
2017-05-24 15:26:28 +02:00
|
|
|
];
|
|
|
|
|
2018-05-04 03:56:26 +02:00
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
// We have our own home page fixtures, prevent the default one being created in this test suite.
|
|
|
|
Config::modify()->set(SiteTree::class, 'create_default_pages', false);
|
|
|
|
|
|
|
|
parent::setUp();
|
|
|
|
}
|
|
|
|
|
2017-05-30 17:35:02 +02:00
|
|
|
public function testPagesInDifferentSubsitesCanShareURLSegment()
|
|
|
|
{
|
2017-05-24 15:26:28 +02:00
|
|
|
$subsiteMain = $this->objFromFixture(Subsite::class, 'main');
|
|
|
|
$subsite1 = $this->objFromFixture(Subsite::class, 'subsite1');
|
|
|
|
|
|
|
|
$pageMain = new SiteTree();
|
|
|
|
$pageMain->URLSegment = 'testpage';
|
|
|
|
$pageMain->write();
|
2017-06-01 14:57:28 +02:00
|
|
|
$pageMain->copyVersionToStage('Stage', 'Live');
|
2017-05-24 15:26:28 +02:00
|
|
|
|
|
|
|
$pageMainOther = new SiteTree();
|
|
|
|
$pageMainOther->URLSegment = 'testpage';
|
|
|
|
$pageMainOther->write();
|
2017-06-01 14:57:28 +02:00
|
|
|
$pageMainOther->copyVersionToStage('Stage', 'Live');
|
2017-05-24 15:26:28 +02:00
|
|
|
|
2017-08-29 07:07:24 +02:00
|
|
|
$this->assertNotEquals(
|
|
|
|
$pageMain->URLSegment,
|
|
|
|
$pageMainOther->URLSegment,
|
2017-05-24 15:26:28 +02:00
|
|
|
'Pages in same subsite cant share the same URL'
|
|
|
|
);
|
|
|
|
|
|
|
|
Subsite::changeSubsite($subsite1->ID);
|
|
|
|
|
|
|
|
$pageSubsite1 = new SiteTree();
|
|
|
|
$pageSubsite1->URLSegment = 'testpage';
|
|
|
|
$pageSubsite1->write();
|
2017-06-01 14:57:28 +02:00
|
|
|
$pageSubsite1->copyVersionToStage('Stage', 'Live');
|
2017-05-24 15:26:28 +02:00
|
|
|
|
2017-08-29 07:07:24 +02:00
|
|
|
$this->assertEquals(
|
|
|
|
$pageMain->URLSegment,
|
|
|
|
$pageSubsite1->URLSegment,
|
2017-05-24 15:26:28 +02:00
|
|
|
'Pages in different subsites can share the same URL'
|
|
|
|
);
|
2017-05-30 17:35:02 +02:00
|
|
|
}
|
2017-05-24 15:26:28 +02:00
|
|
|
|
2017-05-30 17:35:02 +02:00
|
|
|
public function testBasicSanity()
|
|
|
|
{
|
2017-06-01 15:12:18 +02:00
|
|
|
$this->assertInstanceOf(SiteConfig::class, singleton(SiteTree::class)->getSiteConfig());
|
2017-05-24 15:26:28 +02:00
|
|
|
// The following assert is breaking in Translatable.
|
2017-06-01 15:12:18 +02:00
|
|
|
$this->assertInstanceOf(FieldList::class, singleton(SiteTree::class)->getCMSFields());
|
|
|
|
$this->assertInstanceOf(FieldList::class, singleton(SubsitesVirtualPage::class)->getCMSFields());
|
2017-05-24 15:26:28 +02:00
|
|
|
$this->assertTrue(is_array(singleton(SiteTreeSubsites::class)->extraStatics()));
|
|
|
|
}
|
|
|
|
|
2017-09-06 15:56:15 +02:00
|
|
|
public function errorPageLocationsProvider()
|
2017-05-30 17:35:02 +02:00
|
|
|
{
|
2017-09-06 15:56:15 +02:00
|
|
|
return [
|
|
|
|
['domaintest1', '/error-500-one.example.org.html'],
|
|
|
|
['domaintestVagrant', '/error-500-localhost8080.html']
|
|
|
|
];
|
|
|
|
}
|
2017-05-24 15:26:28 +02:00
|
|
|
|
2017-09-06 15:56:15 +02:00
|
|
|
/**
|
|
|
|
* @dataProvider errorPageLocationsProvider
|
|
|
|
*/
|
|
|
|
public function testErrorPageLocations($subsiteFixtureName, $expectedFilename)
|
|
|
|
{
|
|
|
|
$static_path = Config::inst()->get(ErrorPage::class, 'static_filepath');
|
|
|
|
|
|
|
|
$subsite = $this->objFromFixture(Subsite::class, $subsiteFixtureName);
|
|
|
|
$expected_path = $static_path . $expectedFilename;
|
|
|
|
|
|
|
|
Subsite::changeSubsite($subsite->ID);
|
2017-08-30 02:14:11 +02:00
|
|
|
$path = TestErrorPage::get_error_filename_spy(500);
|
2017-05-24 15:26:28 +02:00
|
|
|
|
2017-05-30 17:35:02 +02:00
|
|
|
$this->assertEquals($expected_path, $path);
|
|
|
|
}
|
2017-05-24 15:26:28 +02:00
|
|
|
|
2018-10-19 01:00:50 +02:00
|
|
|
public function testCanEditSiteTree()
|
2017-05-24 15:26:28 +02:00
|
|
|
{
|
2018-10-19 01:00:50 +02:00
|
|
|
$admin = $this->objFromFixture(Member::class, 'admin');
|
|
|
|
$subsite1member = $this->objFromFixture(Member::class, 'subsite1member');
|
|
|
|
$subsite2member = $this->objFromFixture(Member::class, 'subsite2member');
|
|
|
|
$mainpage = $this->objFromFixture('Page', 'home');
|
|
|
|
$subsite1page = $this->objFromFixture('Page', 'subsite1_home');
|
|
|
|
$subsite2page = $this->objFromFixture('Page', 'subsite2_home');
|
|
|
|
$subsite1 = $this->objFromFixture(Subsite::class, 'subsite1');
|
|
|
|
$subsite2 = $this->objFromFixture(Subsite::class, 'subsite2');
|
2017-08-30 01:06:07 +02:00
|
|
|
|
2018-10-19 01:00:50 +02:00
|
|
|
// Cant pass member as arguments to canEdit() because of GroupSubsites
|
|
|
|
$this->logInAs($admin);
|
2017-05-30 17:35:02 +02:00
|
|
|
|
2018-10-19 01:00:50 +02:00
|
|
|
$this->assertTrue(
|
|
|
|
(bool)$subsite1page->canEdit(),
|
|
|
|
'Administrators can edit all subsites'
|
|
|
|
);
|
2017-05-30 17:35:02 +02:00
|
|
|
|
2018-10-19 01:00:50 +02:00
|
|
|
// @todo: Workaround because GroupSubsites->augmentSQL() is relying on session state
|
|
|
|
Subsite::changeSubsite($subsite1);
|
2017-05-30 17:35:02 +02:00
|
|
|
|
2018-10-19 01:00:50 +02:00
|
|
|
$this->logInAs($subsite1member->ID);
|
|
|
|
$this->assertTrue(
|
|
|
|
(bool)$subsite1page->canEdit(),
|
|
|
|
'Members can edit pages on a subsite if they are in a group belonging to this subsite'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->logInAs($subsite2member->ID);
|
|
|
|
$this->assertFalse(
|
|
|
|
(bool)$subsite1page->canEdit(),
|
|
|
|
'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
|
|
|
|
Subsite::changeSubsite(0);
|
|
|
|
$this->assertFalse(
|
|
|
|
$mainpage->canEdit(),
|
|
|
|
'Members cant edit pages on the main site if they are not in a group allowing this'
|
|
|
|
);
|
2017-05-30 17:35:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Similar to {@link SubsitesVirtualPageTest->testSubsiteVirtualPageCanHaveSameUrlsegmentAsOtherSubsite()}.
|
|
|
|
*/
|
|
|
|
public function testTwoPagesWithSameURLOnDifferentSubsites()
|
|
|
|
{
|
|
|
|
// Set up a couple of pages with the same URL on different subsites
|
2017-05-24 15:26:28 +02:00
|
|
|
$s1 = $this->objFromFixture(Subsite::class, 'domaintest1');
|
|
|
|
$s2 = $this->objFromFixture(Subsite::class, 'domaintest2');
|
|
|
|
|
2017-05-30 17:35:02 +02:00
|
|
|
$p1 = new SiteTree();
|
2017-06-01 14:49:55 +02:00
|
|
|
$p1->Title = $p1->URLSegment = 'test-page';
|
2017-05-30 17:35:02 +02:00
|
|
|
$p1->SubsiteID = $s1->ID;
|
|
|
|
$p1->write();
|
2017-05-24 15:26:28 +02:00
|
|
|
|
|
|
|
$p2 = new SiteTree();
|
2017-06-01 14:49:55 +02:00
|
|
|
$p2->Title = $p1->URLSegment = 'test-page';
|
2017-05-24 15:26:28 +02:00
|
|
|
$p2->SubsiteID = $s2->ID;
|
|
|
|
$p2->write();
|
|
|
|
|
|
|
|
// Check that the URLs weren't modified in our set-up
|
2017-08-30 23:44:09 +02:00
|
|
|
$this->assertEquals('test-page', $p1->URLSegment);
|
|
|
|
$this->assertEquals('test-page', $p2->URLSegment);
|
2017-05-24 15:26:28 +02:00
|
|
|
|
|
|
|
// Check that if we switch between the different subsites, we receive the correct pages
|
|
|
|
Subsite::changeSubsite($s1);
|
|
|
|
$this->assertEquals($p1->ID, SiteTree::get_by_link('test-page')->ID);
|
|
|
|
|
2017-05-30 17:35:02 +02:00
|
|
|
Subsite::changeSubsite($s2);
|
|
|
|
$this->assertEquals($p2->ID, SiteTree::get_by_link('test-page')->ID);
|
|
|
|
}
|
2017-05-24 15:26:28 +02:00
|
|
|
|
2017-05-30 17:35:02 +02:00
|
|
|
public function testPageTypesBlacklistInClassDropdown()
|
|
|
|
{
|
2017-08-30 01:06:07 +02:00
|
|
|
$this->logInAs('editor');
|
2017-05-24 15:26:28 +02:00
|
|
|
|
|
|
|
$s1 = $this->objFromFixture(Subsite::class, 'domaintest1');
|
|
|
|
$s2 = $this->objFromFixture(Subsite::class, 'domaintest2');
|
2017-05-30 17:35:02 +02:00
|
|
|
$page = singleton(SiteTree::class);
|
|
|
|
|
2018-03-15 04:34:13 +01:00
|
|
|
$s1->PageTypeBlacklist = json_encode([TestClassA::class, ErrorPage::class]);
|
2017-05-30 17:35:02 +02:00
|
|
|
$s1->write();
|
|
|
|
|
|
|
|
Subsite::changeSubsite($s1);
|
|
|
|
$settingsFields = $page->getSettingsFields()->dataFieldByName('ClassName')->getSource();
|
|
|
|
|
2017-08-29 07:07:24 +02:00
|
|
|
$this->assertArrayNotHasKey(
|
|
|
|
ErrorPage::class,
|
2017-05-30 17:35:02 +02:00
|
|
|
$settingsFields
|
|
|
|
);
|
2017-08-29 07:07:24 +02:00
|
|
|
$this->assertArrayNotHasKey(
|
|
|
|
TestClassA::class,
|
2017-05-30 17:35:02 +02:00
|
|
|
$settingsFields
|
|
|
|
);
|
2017-08-29 07:07:24 +02:00
|
|
|
$this->assertArrayHasKey(
|
|
|
|
TestClassB::class,
|
2017-05-30 17:35:02 +02:00
|
|
|
$settingsFields
|
|
|
|
);
|
|
|
|
|
|
|
|
Subsite::changeSubsite($s2);
|
|
|
|
$settingsFields = $page->getSettingsFields()->dataFieldByName('ClassName')->getSource();
|
2017-08-29 07:07:24 +02:00
|
|
|
$this->assertArrayHasKey(
|
|
|
|
ErrorPage::class,
|
2017-05-30 17:35:02 +02:00
|
|
|
$settingsFields
|
|
|
|
);
|
2017-08-29 07:07:24 +02:00
|
|
|
$this->assertArrayHasKey(
|
|
|
|
TestClassA::class,
|
2017-05-30 17:35:02 +02:00
|
|
|
$settingsFields
|
|
|
|
);
|
2017-08-29 07:07:24 +02:00
|
|
|
$this->assertArrayHasKey(
|
|
|
|
TestClassB::class,
|
2017-05-30 17:35:02 +02:00
|
|
|
$settingsFields
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCopyToSubsite()
|
|
|
|
{
|
2017-05-29 13:42:42 +02:00
|
|
|
// Remove baseurl if testing in subdir
|
2017-05-30 15:14:28 +02:00
|
|
|
Config::modify()->set(Director::class, 'alternate_base_url', '/');
|
2017-05-29 13:42:42 +02:00
|
|
|
|
|
|
|
/** @var Subsite $otherSubsite */
|
|
|
|
$otherSubsite = $this->objFromFixture(Subsite::class, 'subsite1');
|
2017-08-30 23:44:09 +02:00
|
|
|
$staffPage = $this->objFromFixture(Page::class, 'staff'); // nested page
|
|
|
|
$contactPage = $this->objFromFixture(Page::class, 'contact'); // top level page
|
2017-05-29 13:42:42 +02:00
|
|
|
|
|
|
|
$staffPage2 = $staffPage->duplicateToSubsite($otherSubsite->ID);
|
|
|
|
$contactPage2 = $contactPage->duplicateToSubsite($otherSubsite->ID);
|
|
|
|
|
|
|
|
$this->assertNotEquals($staffPage->ID, $staffPage2->ID);
|
|
|
|
$this->assertNotEquals($staffPage->SubsiteID, $staffPage2->SubsiteID);
|
|
|
|
$this->assertNotEquals($contactPage->ID, $contactPage2->ID);
|
|
|
|
$this->assertNotEquals($contactPage->SubsiteID, $contactPage2->SubsiteID);
|
|
|
|
$this->assertEmpty($staffPage2->ParentID);
|
|
|
|
$this->assertEmpty($contactPage2->ParentID);
|
|
|
|
$this->assertNotEmpty($staffPage->ParentID);
|
|
|
|
$this->assertEmpty($contactPage->ParentID);
|
|
|
|
|
|
|
|
// Staff is shifted to top level and given a unique url segment
|
|
|
|
$domain = $otherSubsite->domain();
|
2017-05-30 17:35:02 +02:00
|
|
|
$this->assertEquals('http://' . $domain . '/staff-2/', $staffPage2->AbsoluteLink());
|
|
|
|
$this->assertEquals('http://' . $domain . '/contact-us-2/', $contactPage2->AbsoluteLink());
|
2017-05-29 13:42:42 +02:00
|
|
|
}
|
2017-05-24 15:26:28 +02:00
|
|
|
|
2017-05-30 17:35:02 +02:00
|
|
|
public function testPageTypesBlacklistInCMSMain()
|
|
|
|
{
|
2017-08-30 01:06:07 +02:00
|
|
|
$this->logInAs('editor');
|
2017-05-24 15:26:28 +02:00
|
|
|
|
2017-05-30 17:35:02 +02:00
|
|
|
$s1 = $this->objFromFixture(Subsite::class, 'domaintest1');
|
|
|
|
$s2 = $this->objFromFixture(Subsite::class, 'domaintest2');
|
2017-05-24 15:26:28 +02:00
|
|
|
|
2018-03-15 04:34:13 +01:00
|
|
|
$s1->PageTypeBlacklist = json_encode([TestClassA::class, ErrorPage::class]);
|
2017-05-30 17:35:02 +02:00
|
|
|
$s1->write();
|
2017-05-24 15:26:28 +02:00
|
|
|
|
2017-05-30 17:35:02 +02:00
|
|
|
Subsite::changeSubsite($s1);
|
2018-03-15 05:03:41 +01:00
|
|
|
$cmsmain = CMSMain::create();
|
2017-05-30 17:35:02 +02:00
|
|
|
$hints = Convert::json2array($cmsmain->SiteTreeHints());
|
|
|
|
$classes = $hints['Root']['disallowedChildren'];
|
2017-08-29 07:30:22 +02:00
|
|
|
$this->assertContains(ErrorPage::class, $classes);
|
|
|
|
$this->assertContains(TestClassA::class, $classes);
|
|
|
|
$this->assertNotContains(TestClassB::class, $classes);
|
2017-05-30 17:35:02 +02:00
|
|
|
|
|
|
|
Subsite::changeSubsite($s2);
|
2018-03-18 22:03:32 +01:00
|
|
|
// SS 4.1 and above
|
|
|
|
if ($cmsmain->hasMethod('getHintsCache')) {
|
|
|
|
$cmsmain->getHintsCache()->clear();
|
|
|
|
}
|
2017-05-30 17:35:02 +02:00
|
|
|
$hints = Convert::json2array($cmsmain->SiteTreeHints());
|
2018-03-18 22:03:32 +01:00
|
|
|
|
2017-05-30 17:35:02 +02:00
|
|
|
$classes = $hints['Root']['disallowedChildren'];
|
2017-08-29 07:30:22 +02:00
|
|
|
$this->assertNotContains(ErrorPage::class, $classes);
|
|
|
|
$this->assertNotContains(TestClassA::class, $classes);
|
|
|
|
$this->assertNotContains(TestClassB::class, $classes);
|
2017-05-30 17:35:02 +02:00
|
|
|
}
|
2017-05-24 15:26:28 +02:00
|
|
|
|
2017-05-29 13:42:42 +02:00
|
|
|
/**
|
|
|
|
* Tests that url segments between subsites don't conflict, but do conflict within them
|
|
|
|
*/
|
2017-05-30 17:35:02 +02:00
|
|
|
public function testValidateURLSegment()
|
|
|
|
{
|
2017-05-29 13:42:42 +02:00
|
|
|
$this->logInWithPermission('ADMIN');
|
|
|
|
// Saving existing page in the same subsite doesn't change urls
|
2017-08-30 23:44:09 +02:00
|
|
|
$mainHome = $this->objFromFixture(Page::class, 'home');
|
2017-05-29 13:42:42 +02:00
|
|
|
$mainSubsiteID = $this->idFromFixture(Subsite::class, 'main');
|
|
|
|
Subsite::changeSubsite($mainSubsiteID);
|
|
|
|
$mainHome->Content = '<p>Some new content</p>';
|
|
|
|
$mainHome->write();
|
|
|
|
$this->assertEquals('home', $mainHome->URLSegment);
|
2018-02-01 01:24:48 +01:00
|
|
|
$mainHome->publishRecursive();
|
2017-05-29 13:42:42 +02:00
|
|
|
$mainHomeLive = Versioned::get_one_by_stage('Page', 'Live', sprintf('"SiteTree"."ID" = \'%d\'', $mainHome->ID));
|
|
|
|
$this->assertEquals('home', $mainHomeLive->URLSegment);
|
|
|
|
|
|
|
|
// Saving existing page in another subsite doesn't change urls
|
|
|
|
Subsite::changeSubsite($mainSubsiteID);
|
|
|
|
$subsite1Home = $this->objFromFixture('Page', 'subsite1_home');
|
|
|
|
$subsite1Home->Content = '<p>In subsite 1</p>';
|
|
|
|
$subsite1Home->write();
|
|
|
|
$this->assertEquals('home', $subsite1Home->URLSegment);
|
2018-02-01 01:24:48 +01:00
|
|
|
$subsite1Home->publishRecursive();
|
2017-08-29 07:07:24 +02:00
|
|
|
$subsite1HomeLive = Versioned::get_one_by_stage(
|
|
|
|
'Page',
|
|
|
|
'Live',
|
|
|
|
sprintf('"SiteTree"."ID" = \'%d\'', $subsite1Home->ID)
|
|
|
|
);
|
2017-05-29 13:42:42 +02:00
|
|
|
$this->assertEquals('home', $subsite1HomeLive->URLSegment);
|
|
|
|
|
|
|
|
// Creating a new page in a subsite doesn't conflict with urls in other subsites
|
|
|
|
$subsite1ID = $this->idFromFixture(Subsite::class, 'subsite1');
|
|
|
|
Subsite::changeSubsite($subsite1ID);
|
|
|
|
$subsite1NewPage = new Page();
|
|
|
|
$subsite1NewPage->SubsiteID = $subsite1ID;
|
|
|
|
$subsite1NewPage->Title = 'Important Page (Subsite 1)';
|
|
|
|
$subsite1NewPage->URLSegment = 'important-page'; // Also exists in main subsite
|
|
|
|
$subsite1NewPage->write();
|
|
|
|
$this->assertEquals('important-page', $subsite1NewPage->URLSegment);
|
2018-01-30 22:10:09 +01:00
|
|
|
$subsite1NewPage->publishRecursive();
|
2017-08-29 07:07:24 +02:00
|
|
|
$subsite1NewPageLive = Versioned::get_one_by_stage(
|
|
|
|
'Page',
|
|
|
|
'Live',
|
|
|
|
sprintf('"SiteTree"."ID" = \'%d\'', $subsite1NewPage->ID)
|
|
|
|
);
|
2017-05-29 13:42:42 +02:00
|
|
|
$this->assertEquals('important-page', $subsite1NewPageLive->URLSegment);
|
|
|
|
|
|
|
|
// Creating a new page in a subsite DOES conflict with urls in the same subsite
|
|
|
|
$subsite1NewPage2 = new Page();
|
|
|
|
$subsite1NewPage2->SubsiteID = $subsite1ID;
|
|
|
|
$subsite1NewPage2->Title = 'Important Page (Subsite 1)';
|
|
|
|
$subsite1NewPage2->URLSegment = 'important-page'; // Also exists in main subsite
|
|
|
|
$subsite1NewPage2->write();
|
|
|
|
$this->assertEquals('important-page-2', $subsite1NewPage2->URLSegment);
|
2018-01-30 22:10:09 +01:00
|
|
|
$subsite1NewPage2->publishRecursive();
|
2017-08-29 07:07:24 +02:00
|
|
|
$subsite1NewPage2Live = Versioned::get_one_by_stage(
|
|
|
|
'Page',
|
|
|
|
'Live',
|
|
|
|
sprintf('"SiteTree"."ID" = \'%d\'', $subsite1NewPage2->ID)
|
|
|
|
);
|
2017-05-29 13:42:42 +02:00
|
|
|
$this->assertEquals('important-page-2', $subsite1NewPage2Live->URLSegment);
|
|
|
|
|
|
|
|
// Original page is left un-modified
|
|
|
|
$mainSubsiteImportantPageID = $this->idFromFixture('Page', 'importantpage');
|
|
|
|
$mainSubsiteImportantPage = Page::get()->byID($mainSubsiteImportantPageID);
|
|
|
|
$this->assertEquals('important-page', $mainSubsiteImportantPage->URLSegment);
|
|
|
|
$mainSubsiteImportantPage->Content = '<p>New Important Page Content</p>';
|
|
|
|
$mainSubsiteImportantPage->write();
|
|
|
|
$this->assertEquals('important-page', $mainSubsiteImportantPage->URLSegment);
|
|
|
|
}
|
2017-05-24 15:26:28 +02:00
|
|
|
|
2018-08-24 00:12:05 +02:00
|
|
|
/**
|
|
|
|
* @param bool $withChildren
|
|
|
|
* @param int $expectedChildren
|
|
|
|
* @dataProvider duplicateToSubsiteProvider
|
|
|
|
*/
|
|
|
|
public function testDuplicateToSubsite($withChildren, $expectedChildren)
|
2017-05-30 17:35:02 +02:00
|
|
|
{
|
2018-08-24 00:12:05 +02:00
|
|
|
/** @var SiteTree $page */
|
|
|
|
$page = $this->objFromFixture(Page::class, 'about');
|
|
|
|
/** @var Subsite $newSubsite */
|
2017-05-29 13:42:42 +02:00
|
|
|
$newSubsite = $this->objFromFixture(Subsite::class, 'subsite1');
|
2017-05-24 15:26:28 +02:00
|
|
|
|
2018-08-24 00:12:05 +02:00
|
|
|
/** @var SiteTree $duplicatedPage */
|
|
|
|
$duplicatedPage = $page->duplicateToSubsite($newSubsite->ID, $withChildren);
|
|
|
|
$this->assertInstanceOf(SiteTree::class, $duplicatedPage, 'A new page is returned');
|
|
|
|
|
|
|
|
$this->assertEquals($newSubsite->ID, $duplicatedPage->SubsiteID, 'Ensure returned records are on new subsite');
|
|
|
|
|
|
|
|
$this->assertCount(1, $page->AllChildren());
|
|
|
|
$this->assertCount(
|
|
|
|
$expectedChildren,
|
|
|
|
$duplicatedPage->AllChildren(),
|
|
|
|
'Duplicated page also duplicates children'
|
2017-08-29 07:07:24 +02:00
|
|
|
);
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2018-08-24 00:12:05 +02:00
|
|
|
/**
|
|
|
|
* @return array[]
|
|
|
|
*/
|
|
|
|
public function duplicateToSubsiteProvider()
|
2017-05-30 17:35:02 +02:00
|
|
|
{
|
2018-08-24 00:12:05 +02:00
|
|
|
return [
|
|
|
|
[true, 1],
|
|
|
|
[false, 0],
|
|
|
|
];
|
2017-05-29 13:42:42 +02:00
|
|
|
}
|
2017-06-07 11:57:32 +02:00
|
|
|
|
|
|
|
public function testIfSubsiteThemeIsSetToThemeList()
|
|
|
|
{
|
|
|
|
$defaultThemes = ['default'];
|
|
|
|
SSViewer::set_themes($defaultThemes);
|
|
|
|
|
|
|
|
$subsitePage = $this->objFromFixture(Page::class, 'home');
|
|
|
|
Subsite::changeSubsite($subsitePage->SubsiteID);
|
|
|
|
$controller = ModelAsController::controller_for($subsitePage);
|
|
|
|
SiteTree::singleton()->extend('contentcontrollerInit', $controller);
|
|
|
|
|
2017-08-29 07:07:24 +02:00
|
|
|
$this->assertEquals(
|
|
|
|
SSViewer::get_themes(),
|
|
|
|
$defaultThemes,
|
|
|
|
'Themes should not be modified when Subsite has no theme defined'
|
|
|
|
);
|
2017-06-07 11:57:32 +02:00
|
|
|
|
|
|
|
$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;
|
2017-09-13 06:13:55 +02:00
|
|
|
|
|
|
|
$allThemes = SSViewer::get_themes();
|
|
|
|
|
2017-09-04 01:45:21 +02:00
|
|
|
$this->assertContains(
|
|
|
|
$subsiteTheme,
|
2017-09-13 06:13:55 +02:00
|
|
|
$allThemes,
|
2017-08-29 07:07:24 +02:00
|
|
|
'Themes should be modified when Subsite has theme defined'
|
|
|
|
);
|
2017-09-13 06:13:55 +02:00
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
$subsiteTheme,
|
|
|
|
array_shift($allThemes),
|
|
|
|
'Subsite theme should be prepeded to theme list'
|
|
|
|
);
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
2017-09-07 15:56:42 +02:00
|
|
|
|
2017-09-13 01:51:32 +02:00
|
|
|
public function provideAlternateAbsoluteLink()
|
2017-09-07 15:56:42 +02:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
['home', null, 'http://localhost/'],
|
|
|
|
['home', 'myaction', 'http://localhost/home/myaction'],
|
|
|
|
['contact', null, 'http://localhost/contact-us/'],
|
|
|
|
['contact', 'myaction', 'http://localhost/contact-us/myaction'],
|
|
|
|
['subsite1_home', null, 'http://subsite1.localhost/'],
|
|
|
|
['subsite1_home', 'myaction', 'http://subsite1.localhost/home/myaction'],
|
|
|
|
['subsite1_contactus', null, 'http://subsite1.localhost/contact-us/'],
|
|
|
|
['subsite1_contactus', 'myaction', 'http://subsite1.localhost/contact-us/myaction']
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideAlternateAbsoluteLink
|
2017-09-13 01:51:32 +02:00
|
|
|
* @param name $pageFixtureName
|
|
|
|
* @param string|null $action
|
|
|
|
* @param string $expectedAbsoluteLink
|
2017-09-07 15:56:42 +02:00
|
|
|
*/
|
|
|
|
public function testAlternateAbsoluteLink($pageFixtureName, $action, $expectedAbsoluteLink)
|
|
|
|
{
|
2018-02-01 02:26:12 +01:00
|
|
|
// Setting a control value, in case base url is set for the installation under test
|
|
|
|
Config::modify()->set(Director::class, 'alternate_base_url', 'http://localhost/');
|
|
|
|
|
2017-09-07 15:56:42 +02:00
|
|
|
/** @var Page $page */
|
2017-09-13 01:51:32 +02:00
|
|
|
$page = $this->objFromFixture(Page::class, $pageFixtureName);
|
2017-09-07 15:56:42 +02:00
|
|
|
|
|
|
|
$result = $page->AbsoluteLink($action);
|
|
|
|
|
|
|
|
$this->assertEquals($expectedAbsoluteLink, $result);
|
|
|
|
}
|
2016-09-22 16:38:29 +02:00
|
|
|
}
|