2010-03-01 03:56:19 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class SubsitesVirtualPageTest extends SapphireTest {
|
2010-03-01 22:38:59 +01:00
|
|
|
static $fixture_file = array(
|
|
|
|
'subsites/tests/SubsiteTest.yml',
|
|
|
|
'sapphire/tests/FileLinkTrackingTest.yml',
|
|
|
|
);
|
2010-03-01 03:56:19 +01:00
|
|
|
|
|
|
|
// Attempt to bring main:linky to subsite2:linky
|
|
|
|
function testVirtualPageFromAnotherSubsite() {
|
2010-03-01 03:58:13 +01:00
|
|
|
Subsite::$write_hostmap = false;
|
|
|
|
|
2010-03-01 03:56:19 +01:00
|
|
|
$subsite = $this->objFromFixture('Subsite_Template', 'subsite2');
|
|
|
|
|
|
|
|
Subsite::changeSubsite($subsite->ID);
|
|
|
|
Subsite::$disable_subsite_filter = false;
|
|
|
|
|
|
|
|
$linky = $this->objFromFixture('SiteTree', 'linky');
|
|
|
|
|
|
|
|
$svp = new SubsitesVirtualPage();
|
|
|
|
$svp->CopyContentFromID = $linky->ID;
|
|
|
|
$svp->SubsiteID = $subsite->ID;
|
|
|
|
$svp->URLSegment = 'linky';
|
|
|
|
|
|
|
|
$svp->write();
|
|
|
|
|
|
|
|
$this->assertEquals($svp->SubsiteID, $subsite->ID);
|
|
|
|
$this->assertEquals($svp->Title, $linky->Title);
|
|
|
|
}
|
2010-03-02 02:15:11 +01:00
|
|
|
|
2010-03-01 22:49:50 +01:00
|
|
|
/**
|
|
|
|
* Test custom metadata. Reloading Content should not
|
|
|
|
* obliterate our custom fields
|
|
|
|
*/
|
|
|
|
function testCustomMetadata() {
|
|
|
|
Subsite::$write_hostmap = false;
|
|
|
|
|
|
|
|
$subsite = $this->objFromFixture('Subsite_Template', 'main');
|
|
|
|
|
|
|
|
Subsite::changeSubsite($subsite->ID);
|
|
|
|
|
|
|
|
$orig = $this->objFromFixture('SiteTree', 'linky');
|
|
|
|
|
|
|
|
$svp = new SubsitesVirtualPage();
|
|
|
|
$svp->CopyContentFromID = $orig->ID;
|
|
|
|
$svp->SubsiteID = $subsite->ID;
|
|
|
|
$svp->URLSegment = 'linky-'.rand();
|
|
|
|
$svp->write();
|
|
|
|
|
|
|
|
$this->assertEquals($svp->MetaTitle, 'Linky');
|
|
|
|
|
|
|
|
$svp->CustomMetaTitle = 'SVPTitle';
|
|
|
|
$svp->write();
|
|
|
|
$this->assertEquals($svp->MetaTitle, 'SVPTitle');
|
|
|
|
|
|
|
|
$svp->copyFrom($svp->CopyContentFrom());
|
|
|
|
$svp->write();
|
|
|
|
|
|
|
|
$this->assertEquals($svp->MetaTitle, 'SVPTitle');
|
|
|
|
|
|
|
|
}
|
2010-03-01 23:27:46 +01:00
|
|
|
|
|
|
|
function testFileLinkRewritingOnVirtualPages() {
|
|
|
|
// File setup
|
2010-03-02 02:15:11 +01:00
|
|
|
$this->logInWithPermission('ADMIN');
|
2010-03-01 23:27:46 +01:00
|
|
|
touch(Director::baseFolder() . '/assets/testscript-test-file.pdf');
|
|
|
|
|
|
|
|
// Publish the source page
|
|
|
|
$page = $this->objFromFixture('Page', 'page1');
|
|
|
|
$this->assertTrue($page->doPublish());
|
|
|
|
|
2010-03-17 00:22:42 +01:00
|
|
|
// Create a virtual page from it, and publish that
|
2010-03-01 23:27:46 +01:00
|
|
|
$svp = new SubsitesVirtualPage();
|
|
|
|
$svp->CopyContentFromID = $page->ID;
|
|
|
|
$svp->write();
|
|
|
|
$svp->doPublish();
|
|
|
|
|
|
|
|
// Rename the file
|
|
|
|
$file = $this->objFromFixture('File', 'file1');
|
|
|
|
$file->Name = 'renamed-test-file.pdf';
|
|
|
|
|
|
|
|
// Verify that the draft and publish virtual pages both have the corrected link
|
2010-03-17 00:22:42 +01:00
|
|
|
$this->assertContains('<img src="assets/renamed-test-file.pdf"',
|
2010-03-01 23:27:46 +01:00
|
|
|
DB::query("SELECT \"Content\" FROM \"SiteTree\" WHERE \"ID\" = $svp->ID")->value());
|
2010-03-17 00:22:42 +01:00
|
|
|
$this->assertContains('<img src="assets/renamed-test-file.pdf"',
|
2010-03-01 23:27:46 +01:00
|
|
|
DB::query("SELECT \"Content\" FROM \"SiteTree_Live\" WHERE \"ID\" = $svp->ID")->value());
|
|
|
|
|
|
|
|
// File teardown
|
|
|
|
$testFiles = array(
|
|
|
|
'/assets/testscript-test-file.pdf',
|
|
|
|
'/assets/renamed-test-file.pdf',
|
|
|
|
);
|
|
|
|
foreach($testFiles as $file) {
|
|
|
|
if(file_exists(Director::baseFolder().$file)) unlink(Director::baseFolder().$file);
|
|
|
|
}
|
2010-03-01 23:32:24 +01:00
|
|
|
}
|
2010-03-01 23:27:46 +01:00
|
|
|
|
2010-03-01 23:32:24 +01:00
|
|
|
function testSubsiteVirtualPagesArentInappropriatelyPublished() {
|
|
|
|
// Fixture
|
|
|
|
$p = new Page();
|
|
|
|
$p->Content = "test content";
|
|
|
|
$p->write();
|
|
|
|
$vp = new SubsitesVirtualPage();
|
|
|
|
$vp->CopyContentFromID = $p->ID;
|
|
|
|
$vp->write();
|
|
|
|
|
|
|
|
// VP is oragne
|
|
|
|
$this->assertTrue($vp->IsAddedToStage);
|
|
|
|
|
|
|
|
// VP is still orange after we publish
|
|
|
|
$p->doPublish();
|
|
|
|
$this->fixVersionNumberCache($vp);
|
|
|
|
$this->assertTrue($vp->IsAddedToStage);
|
|
|
|
|
|
|
|
// A new VP created after P's initial construction
|
|
|
|
$vp2 = new SubsitesVirtualPage();
|
|
|
|
$vp2->CopyContentFromID = $p->ID;
|
|
|
|
$vp2->write();
|
|
|
|
$this->assertTrue($vp2->IsAddedToStage);
|
|
|
|
|
|
|
|
// Also remains orange after a republish
|
|
|
|
$p->Content = "new content";
|
|
|
|
$p->write();
|
|
|
|
$p->doPublish();
|
|
|
|
$this->fixVersionNumberCache($vp2);
|
|
|
|
$this->assertTrue($vp2->IsAddedToStage);
|
|
|
|
|
|
|
|
// VP is now published
|
|
|
|
$vp->doPublish();
|
|
|
|
|
|
|
|
$this->fixVersionNumberCache($vp);
|
|
|
|
$this->assertTrue($vp->ExistsOnLive);
|
|
|
|
$this->assertFalse($vp->IsModifiedOnStage);
|
|
|
|
|
|
|
|
// P edited, VP and P both go green
|
|
|
|
$p->Content = "third content";
|
|
|
|
$p->write();
|
|
|
|
|
|
|
|
$this->fixVersionNumberCache($vp, $p);
|
|
|
|
$this->assertTrue($p->IsModifiedOnStage);
|
|
|
|
$this->assertTrue($vp->IsModifiedOnStage);
|
|
|
|
|
|
|
|
// Publish, VP goes black
|
|
|
|
$p->doPublish();
|
|
|
|
$this->fixVersionNumberCache($vp);
|
|
|
|
$this->assertTrue($vp->ExistsOnLive);
|
|
|
|
$this->assertFalse($vp->IsModifiedOnStage);
|
|
|
|
}
|
2010-03-01 23:32:42 +01:00
|
|
|
|
|
|
|
function testUnpublishingParentPageUnpublishesSubsiteVirtualPages() {
|
|
|
|
StaticPublisher::$disable_realtime = true;
|
|
|
|
|
|
|
|
// Go to main site, get parent page
|
|
|
|
$subsite = $this->objFromFixture('Subsite_Template', 'main');
|
|
|
|
Subsite::changeSubsite($subsite->ID);
|
|
|
|
$page = $this->objFromFixture('SiteTree', 'importantpage');
|
|
|
|
|
|
|
|
// Create two SVPs on other subsites
|
|
|
|
$subsite = $this->objFromFixture('Subsite_Template', 'subsite1');
|
|
|
|
Subsite::changeSubsite($subsite->ID);
|
|
|
|
$vp1 = new SubsitesVirtualPage();
|
|
|
|
$vp1->CopyContentFromID = $page->ID;
|
|
|
|
$vp1->write();
|
|
|
|
$vp1->doPublish();
|
|
|
|
|
|
|
|
$subsite = $this->objFromFixture('Subsite_Template', 'subsite2');
|
|
|
|
Subsite::changeSubsite($subsite->ID);
|
|
|
|
$vp2 = new SubsitesVirtualPage();
|
|
|
|
$vp2->CopyContentFromID = $page->ID;
|
|
|
|
$vp2->write();
|
|
|
|
$vp2->doPublish();
|
|
|
|
|
|
|
|
// Switch back to main site, unpublish source
|
|
|
|
$subsite = $this->objFromFixture('Subsite_Template', 'main');
|
|
|
|
Subsite::changeSubsite($subsite->ID);
|
|
|
|
$page = $this->objFromFixture('SiteTree', 'importantpage');
|
|
|
|
$page->doUnpublish();
|
|
|
|
|
2010-03-01 23:33:28 +01:00
|
|
|
Subsite::changeSubsite($vp1->SubsiteID);
|
|
|
|
$onLive = Versioned::get_one_by_stage('SubsitesVirtualPage', 'Live', "SiteTree_Live.ID = ".$vp1->ID);
|
|
|
|
$this->assertFalse($onLive, 'SVP has been removed from live');
|
2010-03-01 23:32:42 +01:00
|
|
|
|
|
|
|
$subsite = $this->objFromFixture('Subsite_Template', 'subsite2');
|
2010-03-01 23:33:28 +01:00
|
|
|
Subsite::changeSubsite($vp2->SubsiteID);
|
|
|
|
$onLive = Versioned::get_one_by_stage('SubsitesVirtualPage', 'Live', "SiteTree_Live.ID = ".$vp2->ID);
|
|
|
|
$this->assertFalse($onLive, 'SVP has been removed from live');
|
2010-03-01 23:32:42 +01:00
|
|
|
}
|
2010-03-01 23:32:24 +01:00
|
|
|
|
|
|
|
function fixVersionNumberCache($page) {
|
|
|
|
$pages = func_get_args();
|
|
|
|
foreach($pages as $p) {
|
|
|
|
Versioned::prepopulate_versionnumber_cache('SiteTree', 'Stage', array($p->ID));
|
|
|
|
Versioned::prepopulate_versionnumber_cache('SiteTree', 'Live', array($p->ID));
|
|
|
|
}
|
2010-03-01 23:27:46 +01:00
|
|
|
}
|
|
|
|
|
2010-03-01 03:56:19 +01:00
|
|
|
}
|