public function testFileLinkRewritingOnVirtualPages()
 {
     // Publish the source page
     $page = $this->objFromFixture('Page', 'page1');
     $this->assertTrue($page->doPublish());
     // Create a virtual page from it, and publish that
     $svp = new VirtualPage();
     $svp->CopyContentFromID = $page->ID;
     $svp->write();
     $svp->doPublish();
     // Rename the file
     $file = $this->objFromFixture('Image', 'file1');
     $file->Name = 'renamed-test-file.jpg';
     $file->write();
     // Verify that the draft and publish virtual pages both have the corrected link
     $this->assertContains('<img src="/assets/FileLinkTrackingTest/55b443b601/renamed-test-file.jpg"', DB::prepared_query("SELECT \"Content\" FROM \"SiteTree\" WHERE \"ID\" = ?", array($svp->ID))->value());
     $this->assertContains('<img src="/assets/FileLinkTrackingTest/55b443b601/renamed-test-file.jpg"', DB::prepared_query("SELECT \"Content\" FROM \"SiteTree_Live\" WHERE \"ID\" = ?", array($svp->ID))->value());
 }
 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 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'));
 }
 function testEmbargoExpiryWithVirtualPages()
 {
     $custompublisher = $this->objFromFixture('Member', 'custompublisher');
     $custompublisher->login();
     $sourcePage = new Page();
     $sourcePage->Content = '<p>Pre-embargo</p>';
     $sourcePage->write();
     $sourcePage->doPublish();
     $sourcePage->Content = '<p>Post-embargo</p>';
     $sourcePage->write();
     $request = $sourcePage->openOrNewWorkflowRequest('WorkflowPublicationRequest');
     $sourcePage->setEmbargo('01/06/2050', '3:00pm');
     $sourcePage->write();
     $request->approve('all good');
     $virtualPage = new VirtualPage();
     $virtualPage->CopyContentFromID = $sourcePage->ID;
     $virtualPage->write();
     $virtualPage->doPublish();
     $liveVirtualPage = Versioned::get_one_by_stage('VirtualPage', 'Live', '"SiteTree"."ID" = ' . $virtualPage->ID);
     $this->assertEquals($liveVirtualPage->Content, '<p>Pre-embargo</p>');
 }