objFromFixture('Page', 'master'); $master->Title = "New title"; $master->MenuTitle = "New menutitle"; $master->Content = "
New content
"; $master->write(); $vp1 = $this->objFromFixture('VirtualPage', 'vp1'); $vp2 = $this->objFromFixture('VirtualPage', 'vp2'); $this->assertEquals("New title", $vp1->Title); $this->assertEquals("New title", $vp2->Title); $this->assertEquals("New menutitle", $vp1->MenuTitle); $this->assertEquals("New menutitle", $vp2->MenuTitle); $this->assertEquals("New content
", $vp1->Content); $this->assertEquals("New content
", $vp2->Content); } /** * Test that, after you publish the source page of a virtual page, all the virtual pages * are published */ function testPublishingSourcePagePublishesVirtualPages() { $this->logInWithPermssion('ADMIN'); $master = $this->objFromFixture('Page', 'master'); $master->Title = "New title"; $master->MenuTitle = "New menutitle"; $master->Content = "New content
"; $master->write(); $master->doPublish(); Versioned::reading_stage("Live"); $vp1 = DataObject::get_by_id("VirtualPage", $this->idFromFixture('VirtualPage', 'vp1')); $vp2 = DataObject::get_by_id("VirtualPage", $this->idFromFixture('VirtualPage', 'vp2')); $this->assertNotNull($vp1); $this->assertNotNull($vp2); $this->assertEquals("New title", $vp1->Title); $this->assertEquals("New title", $vp2->Title); $this->assertEquals("New menutitle", $vp1->MenuTitle); $this->assertEquals("New menutitle", $vp2->MenuTitle); $this->assertEquals("New content
", $vp1->Content); $this->assertEquals("New content
", $vp2->Content); Versioned::reading_stage("Stage"); } /** * Test that virtual pages get the content from the master page when they are created. */ function testNewVirtualPagesGrabTheContentFromTheirMaster() { $vp = new VirtualPage(); $vp->write(); $vp->CopyContentFromID = $this->idFromFixture('Page', 'master'); $vp->write(); $this->assertEquals("My Page", $vp->Title); $this->assertEquals("My Page Nav", $vp->MenuTitle); $vp->CopyContentFromID = $this->idFromFixture('Page', 'master2'); $vp->write(); $this->assertEquals("My Other Page", $vp->Title); $this->assertEquals("My Other Page Nav", $vp->MenuTitle); } /** * Virtual pages are always supposed to chose the same content as the published source page. * This means that when you publish them, they should show the published content of the source * page, not the draft content at the time when you clicked 'publish' in the CMS. */ function testPublishingAVirtualPageCopiedPublishedContentNotDraftContent() { $p = new Page(); $p->Content = "published content"; $p->write(); $p->doPublish(); // Don't publish this change - published page will still say 'published content' $p->Content = "draft content"; $p->write(); $vp = new VirtualPage(); $vp->CopyContentFromID = $p->ID; $vp->write(); $vp->doPublish(); // The draft content of the virtual page should say 'draft content' $this->assertEquals('draft content', DB::query('SELECT "Content" from "SiteTree" WHERE ID = ' . $vp->ID)->value()); // The published content of the virtual page should say 'published content' $this->assertEquals('published content', DB::query('SELECT "Content" from "SiteTree_Live" WHERE ID = ' . $vp->ID)->value()); } function testCantPublishVirtualPagesBeforeTheirSource() { // An unpublished source page $p = new Page(); $p->Content = "test content"; $p->write(); // With no source page, we can't publish $vp = new VirtualPage(); $vp->write(); $this->assertFalse($vp->canPublish()); // When the source page isn't published, we can't publish $vp->CopyContentFromID = $p->ID; $vp->write(); $this->assertFalse($vp->canPublish()); // Once the source page gets published, then we can publish $p->doPublish(); $this->assertTrue($vp->canPublish()); } function testCanDeleteOrphanedVirtualPagesFromLive() { // An unpublished source page $p = new Page(); $p->Content = "test content"; $p->write(); $p->doPublish(); // With no source page, we can't publish $vp = new VirtualPage(); $vp->CopyContentFromID = $p->ID; $vp->write(); // Delete the source page $this->assertTrue($vp->canPublish()); $this->assertTrue($p->doDeleteFromLive()); // Confirm that we can unpublish, but not publish $this->assertTrue($vp->canDeleteFromLive()); $this->assertFalse($vp->canPublish()); // Confirm that the action really works $this->assertTrue($vp->doDeleteFromLive()); $this->assertNull(DB::query("SELECT \"ID\" FROM \"SiteTree_Live\" WHERE \"ID\" = $vp->ID")->value()); } }