public function testDeletingFromLiveSourcePageOfAVirtualPageAlsoUnpublishesVirtualPage()
 {
     // 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);
     // Delete the source page from draft, confirm that this creates a broken link
     $pID = $p->ID;
     $p->delete();
     $vp->flushCache();
     $vp = DataObject::get_by_id('SiteTree', $vp->ID);
     $this->assertEquals(1, $vp->HasBrokenLink);
     // Delete the source page form live, confirm that the virtual page has also been unpublished
     $pLive = Versioned::get_one_by_stage('SiteTree', 'Live', '"SiteTree"."ID" = ' . $pID);
     $this->assertTrue($pLive->doDeleteFromLive());
     $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
     $pLive->delete();
     $vp->flushCache();
     $vp = DataObject::get_by_id('SiteTree', $vp->ID);
     $this->assertEquals(1, $vp->HasBrokenLink);
 }
 public function testRevertToLiveFixesBrokenLinks()
 {
     // Create page and virutal 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);
     // Delete from draft and confirm that broken links are marked
     $pID = $p->ID;
     $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);
     // Call doRevertToLive and confirm that broken links are restored
     $pLive = Versioned::get_one_by_stage('SiteTree', 'Live', '"SiteTree"."ID" = ' . $pID);
     $pLive->doRevertToLive();
     $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);
 }