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); }
public function testVirtualPagePointingToRedirectorPage() { if (!class_exists('RedirectorPage')) { $this->markTestSkipped('RedirectorPage required'); } $rp = new RedirectorPage(array('ExternalURL' => 'http://google.com', 'RedirectionType' => 'External')); $rp->write(); $rp->doPublish(); $vp = new VirtualPage(array('URLSegment' => 'vptest', 'CopyContentFromID' => $rp->ID)); $vp->write(); $vp->doPublish(); $response = $this->get($vp->Link()); $this->assertEquals(301, $response->getStatusCode()); $this->assertEquals('http://google.com', $response->getHeader('Location')); }