2010-03-21 23:32:22 +01:00
|
|
|
<?php
|
|
|
|
|
2016-09-22 16:38:29 +02:00
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
|
|
|
use SilverStripe\SiteConfig\SiteConfig;
|
|
|
|
use SilverStripe\Forms\FieldList;
|
|
|
|
use SilverStripe\Control\Session;
|
|
|
|
use SilverStripe\CMS\Controllers\CMSMain;
|
|
|
|
use SilverStripe\Core\Convert;
|
|
|
|
use SilverStripe\Dev\TestOnly;
|
|
|
|
use SilverStripe\CMS\Model\ErrorPage;
|
|
|
|
|
2013-01-03 14:46:56 +01:00
|
|
|
class SiteTreeSubsitesTest extends BaseSubsiteTest {
|
2011-08-30 18:58:36 +02:00
|
|
|
|
2010-03-21 23:32:22 +01:00
|
|
|
static $fixture_file = 'subsites/tests/SubsiteTest.yml';
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2011-08-30 18:58:36 +02:00
|
|
|
protected $extraDataObjects = array(
|
|
|
|
'SiteTreeSubsitesTest_ClassA',
|
2015-11-20 03:32:52 +01:00
|
|
|
'SiteTreeSubsitesTest_ClassB',
|
|
|
|
'SiteTreeSubsitesTest_ErrorPage'
|
2011-08-30 18:58:36 +02:00
|
|
|
);
|
2015-03-23 02:35:52 +01:00
|
|
|
|
|
|
|
protected $illegalExtensions = array(
|
2016-09-22 16:38:29 +02:00
|
|
|
'SilverStripe\CMS\Model\SiteTree' => array('Translatable')
|
2015-03-23 02:35:52 +01:00
|
|
|
);
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2010-03-21 23:32:22 +01:00
|
|
|
function testPagesInDifferentSubsitesCanShareURLSegment() {
|
2012-08-07 17:37:44 +02:00
|
|
|
$subsiteMain = $this->objFromFixture('Subsite', 'main');
|
|
|
|
$subsite1 = $this->objFromFixture('Subsite', 'subsite1');
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2010-03-21 23:32:22 +01:00
|
|
|
$pageMain = new SiteTree();
|
|
|
|
$pageMain->URLSegment = 'testpage';
|
|
|
|
$pageMain->write();
|
|
|
|
$pageMain->publish('Stage', 'Live');
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2010-03-21 23:32:22 +01:00
|
|
|
$pageMainOther = new SiteTree();
|
|
|
|
$pageMainOther->URLSegment = 'testpage';
|
|
|
|
$pageMainOther->write();
|
|
|
|
$pageMainOther->publish('Stage', 'Live');
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2010-03-21 23:32:22 +01:00
|
|
|
$this->assertNotEquals($pageMain->URLSegment, $pageMainOther->URLSegment,
|
|
|
|
'Pages in same subsite cant share the same URL'
|
|
|
|
);
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2010-03-21 23:32:22 +01:00
|
|
|
Subsite::changeSubsite($subsite1->ID);
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2010-03-21 23:32:22 +01:00
|
|
|
$pageSubsite1 = new SiteTree();
|
|
|
|
$pageSubsite1->URLSegment = 'testpage';
|
|
|
|
$pageSubsite1->write();
|
|
|
|
$pageSubsite1->publish('Stage', 'Live');
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2010-03-21 23:32:22 +01:00
|
|
|
$this->assertEquals($pageMain->URLSegment, $pageSubsite1->URLSegment,
|
|
|
|
'Pages in different subsites can share the same URL'
|
|
|
|
);
|
|
|
|
}
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2010-03-21 23:32:22 +01:00
|
|
|
function testBasicSanity() {
|
2016-09-22 16:38:29 +02:00
|
|
|
$this->assertTrue(singleton('SilverStripe\\CMS\\Model\\SiteTree')->getSiteConfig() instanceof SiteConfig);
|
2013-10-16 05:24:01 +02:00
|
|
|
// The following assert is breaking in Translatable.
|
2016-09-22 16:38:29 +02:00
|
|
|
$this->assertTrue(singleton('SilverStripe\\CMS\\Model\\SiteTree')->getCMSFields() instanceof FieldList);
|
2012-03-25 18:35:01 +02:00
|
|
|
$this->assertTrue(singleton('SubsitesVirtualPage')->getCMSFields() instanceof FieldList);
|
2010-03-21 23:32:22 +01:00
|
|
|
$this->assertTrue(is_array(singleton('SiteTreeSubsites')->extraStatics()));
|
|
|
|
}
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2010-03-21 23:32:22 +01:00
|
|
|
function testErrorPageLocations() {
|
|
|
|
$subsite1 = $this->objFromFixture('Subsite', 'domaintest1');
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2010-03-21 23:32:22 +01:00
|
|
|
Subsite::changeSubsite($subsite1->ID);
|
2015-11-20 03:32:52 +01:00
|
|
|
$path = SiteTreeSubsitesTest_ErrorPage::get_error_filename_spy(500);
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2015-11-20 03:32:52 +01:00
|
|
|
$expected_path = 'error-500-'.$subsite1->domain().'.html';
|
2010-03-21 23:32:22 +01:00
|
|
|
$this->assertEquals($expected_path, $path);
|
|
|
|
}
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2010-03-21 23:32:22 +01:00
|
|
|
function testCanEditSiteTree() {
|
2016-09-22 16:38:29 +02:00
|
|
|
$admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'admin');
|
|
|
|
$subsite1member = $this->objFromFixture('SilverStripe\\Security\\Member', 'subsite1member');
|
|
|
|
$subsite2member = $this->objFromFixture('SilverStripe\\Security\\Member', 'subsite2member');
|
2013-01-03 14:15:41 +01:00
|
|
|
$mainpage = $this->objFromFixture('Page', 'home');
|
|
|
|
$subsite1page = $this->objFromFixture('Page', 'subsite1_home');
|
|
|
|
$subsite2page = $this->objFromFixture('Page', 'subsite2_home');
|
2012-08-07 17:37:44 +02:00
|
|
|
$subsite1 = $this->objFromFixture('Subsite', 'subsite1');
|
|
|
|
$subsite2 = $this->objFromFixture('Subsite', 'subsite2');
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2010-03-21 23:32:22 +01:00
|
|
|
// Cant pass member as arguments to canEdit() because of GroupSubsites
|
|
|
|
Session::set("loggedInAs", $admin->ID);
|
|
|
|
$this->assertTrue(
|
|
|
|
(bool)$subsite1page->canEdit(),
|
|
|
|
'Administrators can edit all subsites'
|
|
|
|
);
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2010-03-21 23:32:22 +01:00
|
|
|
// @todo: Workaround because GroupSubsites->augmentSQL() is relying on session state
|
|
|
|
Subsite::changeSubsite($subsite1);
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2010-03-21 23:32:22 +01:00
|
|
|
Session::set("loggedInAs", $subsite1member->ID);
|
|
|
|
$this->assertTrue(
|
|
|
|
(bool)$subsite1page->canEdit(),
|
|
|
|
'Members can edit pages on a subsite if they are in a group belonging to this subsite'
|
|
|
|
);
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2010-03-21 23:32:22 +01:00
|
|
|
Session::set("loggedInAs", $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'
|
|
|
|
);
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2010-03-21 23:32:22 +01:00
|
|
|
// @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'
|
|
|
|
);
|
|
|
|
}
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2011-08-22 17:52:21 +02:00
|
|
|
/**
|
|
|
|
* Similar to {@link SubsitesVirtualPageTest->testSubsiteVirtualPageCanHaveSameUrlsegmentAsOtherSubsite()}.
|
|
|
|
*/
|
2010-03-21 23:32:22 +01:00
|
|
|
function testTwoPagesWithSameURLOnDifferentSubsites() {
|
|
|
|
// Set up a couple of pages with the same URL on different subsites
|
|
|
|
$s1 = $this->objFromFixture('Subsite','domaintest1');
|
|
|
|
$s2 = $this->objFromFixture('Subsite','domaintest2');
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2010-03-21 23:32:22 +01:00
|
|
|
$p1 = new SiteTree();
|
|
|
|
$p1->Title = $p1->URLSegment = "test-page";
|
|
|
|
$p1->SubsiteID = $s1->ID;
|
|
|
|
$p1->write();
|
|
|
|
|
|
|
|
$p2 = new SiteTree();
|
|
|
|
$p2->Title = $p1->URLSegment = "test-page";
|
|
|
|
$p2->SubsiteID = $s2->ID;
|
|
|
|
$p2->write();
|
|
|
|
|
|
|
|
// Check that the URLs weren't modified in our set-up
|
|
|
|
$this->assertEquals($p1->URLSegment, 'test-page');
|
|
|
|
$this->assertEquals($p2->URLSegment, 'test-page');
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2010-03-21 23:32:22 +01: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);
|
|
|
|
|
|
|
|
Subsite::changeSubsite($s2);
|
|
|
|
$this->assertEquals($p2->ID, SiteTree::get_by_link('test-page')->ID);
|
|
|
|
}
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2011-08-30 18:58:36 +02:00
|
|
|
function testPageTypesBlacklistInClassDropdown() {
|
2016-09-22 16:38:29 +02:00
|
|
|
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'editor');
|
2015-04-30 11:45:22 +02:00
|
|
|
Session::set("loggedInAs", $editor->ID);
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2011-08-30 18:58:36 +02:00
|
|
|
$s1 = $this->objFromFixture('Subsite','domaintest1');
|
|
|
|
$s2 = $this->objFromFixture('Subsite','domaintest2');
|
2016-09-22 16:38:29 +02:00
|
|
|
$page = singleton('SilverStripe\\CMS\\Model\\SiteTree');
|
|
|
|
|
2011-08-30 18:58:36 +02:00
|
|
|
$s1->PageTypeBlacklist = 'SiteTreeSubsitesTest_ClassA,ErrorPage';
|
|
|
|
$s1->write();
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2011-08-30 18:58:36 +02:00
|
|
|
Subsite::changeSubsite($s1);
|
2012-07-11 15:32:10 +02:00
|
|
|
$settingsFields = $page->getSettingsFields()->dataFieldByName('ClassName')->getSource();
|
2016-09-22 16:38:29 +02:00
|
|
|
|
|
|
|
$this->assertArrayNotHasKey('SilverStripe\\CMS\\Model\\ErrorPage',
|
2012-07-11 15:32:10 +02:00
|
|
|
$settingsFields
|
2011-11-15 14:15:28 +01:00
|
|
|
);
|
2016-09-22 16:38:29 +02:00
|
|
|
$this->assertArrayNotHasKey('SiteTreeSubsitesTest_ClassA',
|
2012-07-11 15:32:10 +02:00
|
|
|
$settingsFields
|
2011-11-15 14:15:28 +01:00
|
|
|
);
|
2016-09-22 16:38:29 +02:00
|
|
|
$this->assertArrayHasKey('SiteTreeSubsitesTest_ClassB',
|
2012-07-11 15:32:10 +02:00
|
|
|
$settingsFields
|
2011-11-15 14:15:28 +01:00
|
|
|
);
|
2011-08-30 18:58:36 +02:00
|
|
|
|
|
|
|
Subsite::changeSubsite($s2);
|
2012-07-11 15:32:10 +02:00
|
|
|
$settingsFields = $page->getSettingsFields()->dataFieldByName('ClassName')->getSource();
|
2016-09-22 16:38:29 +02:00
|
|
|
$this->assertArrayHasKey('SilverStripe\\CMS\\Model\\ErrorPage',
|
2012-07-11 15:32:10 +02:00
|
|
|
$settingsFields
|
2011-11-15 14:15:28 +01:00
|
|
|
);
|
2016-09-22 16:38:29 +02:00
|
|
|
$this->assertArrayHasKey('SiteTreeSubsitesTest_ClassA',
|
2012-07-11 15:32:10 +02:00
|
|
|
$settingsFields
|
2011-11-15 14:15:28 +01:00
|
|
|
);
|
2016-09-22 16:38:29 +02:00
|
|
|
$this->assertArrayHasKey('SiteTreeSubsitesTest_ClassB',
|
2012-07-11 15:32:10 +02:00
|
|
|
$settingsFields
|
2011-11-15 14:15:28 +01:00
|
|
|
);
|
2011-08-30 18:58:36 +02:00
|
|
|
}
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2011-08-30 18:58:36 +02:00
|
|
|
function testPageTypesBlacklistInCMSMain() {
|
2016-09-22 16:38:29 +02:00
|
|
|
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'editor');
|
2015-04-30 11:45:22 +02:00
|
|
|
Session::set("loggedInAs", $editor->ID);
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2011-08-30 18:58:36 +02:00
|
|
|
$cmsmain = new CMSMain();
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2011-08-30 18:58:36 +02:00
|
|
|
$s1 = $this->objFromFixture('Subsite','domaintest1');
|
|
|
|
$s2 = $this->objFromFixture('Subsite','domaintest2');
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2011-08-30 18:58:36 +02:00
|
|
|
$s1->PageTypeBlacklist = 'SiteTreeSubsitesTest_ClassA,ErrorPage';
|
|
|
|
$s1->write();
|
|
|
|
|
|
|
|
Subsite::changeSubsite($s1);
|
2015-03-23 02:35:52 +01:00
|
|
|
$hints = Convert::json2array($cmsmain->SiteTreeHints());
|
|
|
|
$classes = $hints['Root']['disallowedChildren'];
|
2016-09-22 16:38:29 +02:00
|
|
|
$this->assertContains('SilverStripe\\CMS\\Model\\ErrorPage', $classes);
|
2011-08-30 18:58:36 +02:00
|
|
|
$this->assertContains('SiteTreeSubsitesTest_ClassA', $classes);
|
2015-03-23 02:35:52 +01:00
|
|
|
$this->assertNotContains('SiteTreeSubsitesTest_ClassB', $classes);
|
|
|
|
|
|
|
|
Subsite::changeSubsite($s2);
|
|
|
|
$hints = Convert::json2array($cmsmain->SiteTreeHints());
|
|
|
|
$classes = $hints['Root']['disallowedChildren'];
|
2016-09-22 16:38:29 +02:00
|
|
|
$this->assertNotContains('SilverStripe\\CMS\\Model\\ErrorPage', $classes);
|
2015-03-23 02:35:52 +01:00
|
|
|
$this->assertNotContains('SiteTreeSubsitesTest_ClassA', $classes);
|
|
|
|
$this->assertNotContains('SiteTreeSubsitesTest_ClassB', $classes);
|
2011-08-30 18:58:36 +02:00
|
|
|
}
|
2016-09-22 16:38:29 +02:00
|
|
|
|
2010-03-21 23:32:22 +01:00
|
|
|
}
|
2011-08-30 18:58:36 +02:00
|
|
|
|
|
|
|
class SiteTreeSubsitesTest_ClassA extends SiteTree implements TestOnly {}
|
|
|
|
|
2012-10-10 02:49:08 +02:00
|
|
|
class SiteTreeSubsitesTest_ClassB extends SiteTree implements TestOnly {}
|
2015-11-20 03:32:52 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2016-09-22 16:38:29 +02:00
|
|
|
}
|