2007-08-16 08:38:29 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class SubsiteTest extends SapphireTest {
|
|
|
|
static $fixture_file = 'subsites/tests/SubsiteTest.yml';
|
2007-08-21 00:37:43 +02:00
|
|
|
|
2009-10-16 03:15:54 +02:00
|
|
|
function testPagesInDifferentSubsitesCanShareURLSegment() {
|
|
|
|
$subsiteMain = $this->objFromFixture('Subsite_Template', 'main');
|
|
|
|
$subsite1 = $this->objFromFixture('Subsite_Template', 'subsite1');
|
|
|
|
|
|
|
|
$pageMain = new SiteTree();
|
|
|
|
$pageMain->URLSegment = 'testpage';
|
|
|
|
$pageMain->write();
|
|
|
|
$pageMain->publish('Stage', 'Live');
|
|
|
|
|
|
|
|
$pageMainOther = new SiteTree();
|
|
|
|
$pageMainOther->URLSegment = 'testpage';
|
|
|
|
$pageMainOther->write();
|
|
|
|
$pageMainOther->publish('Stage', 'Live');
|
|
|
|
|
|
|
|
$this->assertNotEquals($pageMain->URLSegment, $pageMainOther->URLSegment,
|
|
|
|
'Pages in same subsite cant share the same URL'
|
|
|
|
);
|
|
|
|
|
|
|
|
Subsite::changeSubsite($subsite1->ID);
|
|
|
|
|
|
|
|
$pageSubsite1 = new SiteTree();
|
|
|
|
$pageSubsite1->URLSegment = 'testpage';
|
|
|
|
$pageSubsite1->write();
|
|
|
|
$pageSubsite1->publish('Stage', 'Live');
|
|
|
|
|
|
|
|
$this->assertEquals($pageMain->URLSegment, $pageSubsite1->URLSegment,
|
|
|
|
'Pages in different subsites can share the same URL'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2007-08-16 08:38:29 +02:00
|
|
|
/**
|
|
|
|
* Create a new subsite from the template and verify that all the template's pages are copied
|
|
|
|
*/
|
|
|
|
function testSubsiteCreation() {
|
2010-03-01 03:58:13 +01:00
|
|
|
Subsite::$write_hostmap = false;
|
|
|
|
|
2007-08-16 08:38:29 +02:00
|
|
|
// Create the instance
|
|
|
|
$template = $this->objFromFixture('Subsite_Template', 'main');
|
2009-10-16 03:15:54 +02:00
|
|
|
|
2007-08-16 08:38:29 +02:00
|
|
|
// Test that changeSubsite is working
|
|
|
|
Subsite::changeSubsite($template->ID);
|
2009-10-16 03:15:54 +02:00
|
|
|
|
2009-11-02 02:59:15 +01:00
|
|
|
if(defined('DB::USE_ANSI_SQL'))
|
|
|
|
$q="\"";
|
|
|
|
else $q='`';
|
|
|
|
|
|
|
|
$tmplHome = DataObject::get_one('SiteTree', "{$q}URLSegment{$q} = 'home'");
|
2009-10-16 03:15:54 +02:00
|
|
|
|
2007-08-16 08:38:29 +02:00
|
|
|
// Publish all the pages in the template, testing that DataObject::get only returns pages from the chosen subsite
|
|
|
|
$pages = DataObject::get("SiteTree");
|
|
|
|
$totalPages = $pages->TotalItems();
|
|
|
|
foreach($pages as $page) {
|
|
|
|
$this->assertEquals($template->ID, $page->SubsiteID);
|
|
|
|
$page->publish('Stage', 'Live');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a new site
|
2010-03-01 03:48:45 +01:00
|
|
|
$subsite = $template->createInstance('My Site', 'something.test.com');
|
2009-10-16 03:15:54 +02:00
|
|
|
|
2007-08-16 08:38:29 +02:00
|
|
|
// Check title
|
|
|
|
$this->assertEquals($subsite->Title, 'My Site');
|
|
|
|
|
|
|
|
// Check that domain generation is working
|
2010-03-01 03:48:45 +01:00
|
|
|
$this->assertEquals('something.test.com', $subsite->domain());
|
2009-10-16 03:15:54 +02:00
|
|
|
|
2007-08-16 08:38:29 +02:00
|
|
|
// Another test that changeSubsite is working
|
|
|
|
Subsite::changeSubsite($subsite->ID);
|
2009-10-16 03:15:54 +02:00
|
|
|
|
2009-11-02 02:59:15 +01:00
|
|
|
$siteHome = DataObject::get_one('SiteTree', "{$q}URLSegment{$q} = 'home'");
|
2009-10-16 03:15:54 +02:00
|
|
|
$this->assertNotNull($siteHome);
|
|
|
|
$this->assertEquals($subsite->ID, $siteHome->SubsiteID,
|
|
|
|
'createInstance() copies existing pages retaining the same URLSegment'
|
|
|
|
);
|
|
|
|
$this->assertEquals($siteHome->MasterPageID, $tmplHome->ID, 'Check master page value');
|
2007-08-16 08:38:29 +02:00
|
|
|
|
|
|
|
// Check linking of child pages
|
2009-05-04 07:03:44 +02:00
|
|
|
$tmplStaff = $this->objFromFixture('SiteTree','staff');
|
2009-11-02 02:59:15 +01:00
|
|
|
$siteStaff = DataObject::get_one('SiteTree', "{$q}URLSegment{$q} = '" . Convert::raw2sql($tmplStaff->URLSegment) . "'");
|
2007-08-16 08:38:29 +02:00
|
|
|
$this->assertEquals($siteStaff->MasterPageID, $tmplStaff->ID);
|
|
|
|
|
2008-11-24 07:37:22 +01:00
|
|
|
Subsite::changeSubsite(0);
|
|
|
|
|
2007-08-16 08:38:29 +02:00
|
|
|
}
|
|
|
|
|
2010-03-01 03:48:45 +01:00
|
|
|
/**
|
|
|
|
* Confirm that domain lookup is working
|
|
|
|
*/
|
|
|
|
function testDomainLookup() {
|
|
|
|
$this->assertEquals($this->idFromFixture('Subsite','domaintest1'),
|
|
|
|
Subsite::getSubsiteIDForDomain('one.example.org'));
|
|
|
|
$this->assertEquals($this->idFromFixture('Subsite','domaintest1'),
|
|
|
|
Subsite::getSubsiteIDForDomain('one.localhost'));
|
|
|
|
|
|
|
|
$this->assertEquals($this->idFromFixture('Subsite','domaintest2'),
|
|
|
|
Subsite::getSubsiteIDForDomain('two.mysite.com'));
|
|
|
|
$this->assertEquals($this->idFromFixture('Subsite','domaintest2'),
|
|
|
|
Subsite::getSubsiteIDForDomain('other.mysite.com'));
|
|
|
|
|
2010-03-01 04:00:40 +01:00
|
|
|
$this->assertEquals(0, Subsite::getSubsiteIDForDomain('other.example.com'));
|
|
|
|
$this->assertEquals(0, Subsite::getSubsiteIDForDomain('two.example.com'));
|
2010-03-01 03:48:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the Subsite->domain() method
|
|
|
|
*/
|
|
|
|
function testDefaultDomain() {
|
|
|
|
$this->assertEquals('one.example.org',
|
|
|
|
$this->objFromFixture('Subsite','domaintest1')->domain());
|
|
|
|
|
|
|
|
$this->assertEquals('two.mysite.com',
|
|
|
|
$this->objFromFixture('Subsite','domaintest2')->domain());
|
|
|
|
|
|
|
|
$originalHTTPHost = $_SERVER['HTTP_HOST'];
|
|
|
|
|
|
|
|
$_SERVER['HTTP_HOST'] = "www.example.org";
|
|
|
|
$this->assertEquals('three.example.org',
|
|
|
|
$this->objFromFixture('Subsite','domaintest3')->domain());
|
|
|
|
|
|
|
|
$_SERVER['HTTP_HOST'] = "mysite.example.org";
|
|
|
|
$this->assertEquals('three.mysite.example.org',
|
|
|
|
$this->objFromFixture('Subsite','domaintest3')->domain());
|
|
|
|
|
|
|
|
|
|
|
|
$_SERVER['HTTP_HOST'] = $originalHTTPHost;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-16 08:38:29 +02:00
|
|
|
/**
|
|
|
|
* Only the published content from the template should publish.
|
|
|
|
*/
|
|
|
|
function testUnpublishedPagesDontCopy() {
|
|
|
|
|
|
|
|
}
|
2009-10-16 03:15:54 +02:00
|
|
|
|
2010-03-01 22:37:56 +01:00
|
|
|
/**
|
|
|
|
* Test Subsite::accessible_sites()
|
|
|
|
*/
|
|
|
|
function testAccessibleSites() {
|
|
|
|
$member1Sites = Subsite::accessible_sites("CMS_ACCESS_CMSMain", false, null,
|
|
|
|
$this->objFromFixture('Member', 'subsite1member'));
|
|
|
|
$member1SiteTitles = $member1Sites->column("Title");
|
|
|
|
sort($member1SiteTitles);
|
|
|
|
$this->assertEquals(array('Subsite1 Template'), $member1SiteTitles);
|
|
|
|
|
|
|
|
$adminSites = Subsite::accessible_sites("CMS_ACCESS_CMSMain", false, null,
|
|
|
|
$this->objFromFixture('Member', 'admin'));
|
|
|
|
$adminSiteTitles = $adminSites->column("Title");
|
|
|
|
sort($adminSiteTitles);
|
|
|
|
$this->assertEquals(array(
|
|
|
|
'Subsite1 Template',
|
|
|
|
'Subsite2 Template',
|
|
|
|
'Template',
|
|
|
|
'Test 1',
|
|
|
|
'Test 2',
|
|
|
|
'Test 3',
|
|
|
|
), $adminSiteTitles);
|
|
|
|
}
|
|
|
|
|
2007-08-16 08:38:29 +02:00
|
|
|
/**
|
|
|
|
* Publish a change on a master page of a newly created sub-site, and verify that the change has been propagated.
|
|
|
|
* Verify that if CustomContent is set, then the changes aren't propagated.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reorganise a couple of pages on the master site and verify that the changes are propagated, whether or not CustomContent
|
|
|
|
* is set.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit a subsite's content and verify that CustomContent is set on the page.
|
|
|
|
* Edit a page without actually making any changes and verify that CustomContent isn't set.
|
|
|
|
*/
|
|
|
|
|
2008-11-24 07:37:22 +01:00
|
|
|
function testCanEditSiteTree() {
|
|
|
|
$admin = $this->objFromFixture('Member', 'admin');
|
|
|
|
$subsite1member = $this->objFromFixture('Member', 'subsite1member');
|
|
|
|
$subsite2member = $this->objFromFixture('Member', 'subsite2member');
|
2009-05-04 07:03:44 +02:00
|
|
|
$mainpage = $this->objFromFixture('SiteTree', 'home');
|
|
|
|
$subsite1page = $this->objFromFixture('SiteTree', 'subsite1_home');
|
|
|
|
$subsite2page = $this->objFromFixture('SiteTree', 'subsite2_home');
|
2008-11-24 07:37:22 +01:00
|
|
|
$subsite1 = $this->objFromFixture('Subsite_Template', 'subsite1');
|
|
|
|
$subsite2 = $this->objFromFixture('Subsite_Template', 'subsite2');
|
2009-10-16 03:15:54 +02:00
|
|
|
|
|
|
|
// Cant pass member as arguments to canEdit() because of GroupSubsites
|
2009-05-04 07:03:44 +02:00
|
|
|
Session::set("loggedInAs", $admin->ID);
|
2008-11-24 07:37:22 +01:00
|
|
|
$this->assertTrue(
|
2009-05-04 07:03:44 +02:00
|
|
|
(bool)$subsite1page->canEdit(),
|
2008-11-24 07:37:22 +01:00
|
|
|
'Administrators can edit all subsites'
|
|
|
|
);
|
2009-10-16 03:15:54 +02:00
|
|
|
|
2008-11-24 07:37:22 +01:00
|
|
|
// @todo: Workaround because GroupSubsites->augmentSQL() is relying on session state
|
|
|
|
Subsite::changeSubsite($subsite1);
|
2009-05-04 07:03:44 +02:00
|
|
|
|
|
|
|
Session::set("loggedInAs", $subsite1member->ID);
|
2008-11-24 07:37:22 +01:00
|
|
|
$this->assertTrue(
|
2009-05-04 07:03:44 +02:00
|
|
|
(bool)$subsite1page->canEdit(),
|
2008-11-24 07:37:22 +01:00
|
|
|
'Members can edit pages on a subsite if they are in a group belonging to this subsite'
|
|
|
|
);
|
2009-10-16 03:15:54 +02:00
|
|
|
|
2009-05-04 07:03:44 +02:00
|
|
|
Session::set("loggedInAs", $subsite2member->ID);
|
2008-11-24 07:37:22 +01:00
|
|
|
$this->assertFalse(
|
2009-05-04 07:03:44 +02:00
|
|
|
(bool)$subsite1page->canEdit(),
|
2008-11-24 07:37:22 +01:00
|
|
|
'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
|
2009-05-14 00:44:55 +02:00
|
|
|
Subsite::changeSubsite(0);
|
2008-11-24 07:37:22 +01:00
|
|
|
$this->assertFalse(
|
2009-05-04 07:03:44 +02:00
|
|
|
$mainpage->canEdit(),
|
2008-11-24 07:37:22 +01:00
|
|
|
'Members cant edit pages on the main site if they are not in a group allowing this'
|
|
|
|
);
|
|
|
|
}
|
2007-08-16 08:38:29 +02:00
|
|
|
|
|
|
|
}
|