public function testUnpublishingSourcePageOfAVirtualPageAlsoUnpublishesVirtualPage() { // Create page and virutal page $p = new Page(); $p->Title = "source"; $p->write(); $this->assertTrue($p->doPublish()); $vp = new VirtualPage(); $vp->CopyContentFromID = $p->ID; $vp->write(); $this->assertTrue($vp->doPublish()); // All is fine, the virtual page doesn't have a broken link $this->assertFalse($vp->HasBrokenLink); // Unpublish the source page, confirm that the virtual page has also been unpublished $p->doUnpublish(); // The draft VP still has the CopyContentFromID link $vp->flushCache(); $vp = DataObject::get_by_id('SiteTree', $vp->ID); $this->assertEquals($p->ID, $vp->CopyContentFromID); $vpLive = Versioned::get_one_by_stage('SiteTree', 'Live', '"SiteTree"."ID" = ' . $vp->ID); $this->assertNull($vpLive); // Delete from draft, confirm that the virtual page has a broken link on the draft site $p->delete(); $vp->flushCache(); $vp = DataObject::get_by_id('SiteTree', $vp->ID); $this->assertEquals(1, $vp->HasBrokenLink); }
function testTranslationGroupNotRemovedWhenSiteTreeUnpublished() { $enPage = new Page(); $enPage->Locale = 'en_US'; $enPage->write(); $enPage->publish('Stage', 'Live'); $enTranslationGroup = $enPage->getTranslationGroup(); $frPage = $enPage->createTranslation('fr_FR'); $frPage->write(); $frPage->publish('Stage', 'Live'); $frTranslationGroup = $frPage->getTranslationGroup(); $enPage->doUnpublish(); $this->assertEquals($enPage->getTranslationGroup(), $enTranslationGroup); $frPage->doUnpublish(); $this->assertEquals($frPage->getTranslationGroup(), $frTranslationGroup); }
public function testRestoreFixesBrokenLinks() { // Create page and virtual page $p = new Page(); $p->Title = "source"; $p->write(); $pageID = $p->ID; $this->assertTrue($p->doPublish()); // Content links are one kind of link to pages $p2 = new Page(); $p2->Title = "regular link"; $p2->Content = "<a href=\"[sitetree_link,id={$p->ID}]\">test</a>"; $p2->write(); $this->assertTrue($p2->doPublish()); // Virtual pages are another $vp = new VirtualPage(); $vp->CopyContentFromID = $p->ID; $vp->write(); // Redirector links are a third $rp = new RedirectorPage(); $rp->Title = "redirector"; $rp->LinkType = 'Internal'; $rp->LinkToID = $p->ID; $rp->write(); $this->assertTrue($rp->doPublish()); // Confirm that there are no broken links to begin with $this->assertFalse($p2->HasBrokenLink); $this->assertFalse($vp->HasBrokenLink); $this->assertFalse($rp->HasBrokenLink); // Unpublish the source page, confirm that the page 2 and RP has a broken link on published $p->doUnpublish(); $p2Live = Versioned::get_one_by_stage('SiteTree', 'Live', '"SiteTree"."ID" = ' . $p2->ID); $rpLive = Versioned::get_one_by_stage('SiteTree', 'Live', '"SiteTree"."ID" = ' . $rp->ID); $this->assertEquals(1, $p2Live->HasBrokenLink); $this->assertEquals(1, $rpLive->HasBrokenLink); // Delete the source page, confirm that the VP, RP and page 2 have broken links on draft $p->delete(); $vp->flushCache(); $vp = DataObject::get_by_id('SiteTree', $vp->ID); $p2->flushCache(); $p2 = DataObject::get_by_id('SiteTree', $p2->ID); $rp->flushCache(); $rp = DataObject::get_by_id('SiteTree', $rp->ID); $this->assertEquals(1, $p2->HasBrokenLink); $this->assertEquals(1, $vp->HasBrokenLink); $this->assertEquals(1, $rp->HasBrokenLink); // Restore the page to stage, confirm that this fixes the links $p = Versioned::get_latest_version('SiteTree', $pageID); $p->doRestoreToStage(); $p2->flushCache(); $p2 = DataObject::get_by_id('SiteTree', $p2->ID); $vp->flushCache(); $vp = DataObject::get_by_id('SiteTree', $vp->ID); $rp->flushCache(); $rp = DataObject::get_by_id('SiteTree', $rp->ID); $this->assertFalse((bool) $p2->HasBrokenLink); $this->assertFalse((bool) $vp->HasBrokenLink); $this->assertFalse((bool) $rp->HasBrokenLink); // Publish and confirm that the p2 and RP broken links are fixed on published $this->assertTrue($p->doPublish()); $p2Live = Versioned::get_one_by_stage('SiteTree', 'Live', '"SiteTree"."ID" = ' . $p2->ID); $rpLive = Versioned::get_one_by_stage('SiteTree', 'Live', '"SiteTree"."ID" = ' . $rp->ID); $this->assertFalse((bool) $p2Live->HasBrokenLink); $this->assertFalse((bool) $rpLive->HasBrokenLink); }
/** * When un-publishing the page it has to remove all the fields from the * live database table. * * @return void */ public function doUnpublish() { if ($this->Fields()) { foreach ($this->Fields() as $field) { $field->doDeleteFromStage('Live'); } } parent::doUnpublish(); }