/** * Test the broken links report. */ public function testBrokenLinksReport() { // --- // BROKEN LINKS // --- // Create a "draft" page with a broken link. $page = Page::create(); $page->Content = "<a href='[sitetree_link,id=987654321]'>This</a> is a broken link."; $page->writeToStage('Stage'); // Retrieve the broken links report. $reports = SS_Report::get_reports(); $brokenLinksReport = null; foreach ($reports as $report) { if ($report instanceof BrokenLinksReport) { $brokenLinksReport = $report; break; } } // Determine that the report exists, otherwise it has been excluded. if ($brokenLinksReport) { // ASSERT that the "draft" report has detected the page having a broken link. // ASSERT that the "published" report has NOT detected the page having a broken link, as the page has not been "published" yet. $this->isReportBroken($brokenLinksReport, true, false, 'BROKENLINK'); // Make sure the page is now "published". $page->writeToStage('Live'); // ASSERT that the "draft" report has detected the page having a broken link. // ASSERT that the "published" report has detected the page having a broken link. $this->isReportBroken($brokenLinksReport, true, true, 'BROKENLINK'); // Correct the "draft" broken link. $page->Content = str_replace('987654321', $page->ID, $page->Content); $page->writeToStage('Stage'); // ASSERT that the "draft" report has NOT detected the page having a broken link. // ASSERT that the "published" report has detected the page having a broken link, as the previous content remains "published". $this->isReportBroken($brokenLinksReport, false, true, 'BROKENLINK'); // Make sure the change has now been "published". $page->writeToStage('Live'); // ASSERT that the "draft" report has NOT detected the page having a broken link. // ASSERT that the "published" report has NOT detected the page having a broken link. $this->isReportBroken($brokenLinksReport, false, false, 'BROKENLINK'); $page->delete(); // --- // BROKEN FILES // --- // Create a "draft" page with a broken file. $page = Page::create(); $page->Content = "<a href='[file_link,id=987654321]'>This</a> is a broken file."; $page->writeToStage('Stage'); // ASSERT that the "draft" report has detected the page having a broken file. // ASSERT that the "published" report has NOT detected the page having a broken file, as the page has not been "published" yet. $this->isReportBroken($brokenLinksReport, true, false, 'BROKENFILE'); // Make sure the page is now "published". $page->writeToStage('Live'); // ASSERT that the "draft" report has detected the page having a broken file. // ASSERT that the "published" report has detected the page having a broken file. $this->isReportBroken($brokenLinksReport, true, true, 'BROKENFILE'); // Correct the "draft" broken file. $file = File::create(); $file->Filename = 'name.pdf'; $file->write(); $page->Content = str_replace('987654321', $file->ID, $page->Content); $page->writeToStage('Stage'); // ASSERT that the "draft" report has NOT detected the page having a broken file. // ASSERT that the "published" report has detected the page having a broken file, as the previous content remains "published". $this->isReportBroken($brokenLinksReport, false, true, 'BROKENFILE'); // Make sure the change has now been "published". $page->writeToStage('Live'); // ASSERT that the "draft" report has NOT detected the page having a broken file. // ASSERT that the "published" report has NOT detected the page having a broken file. $this->isReportBroken($brokenLinksReport, false, false, 'BROKENFILE'); $page->delete(); // --- // BROKEN VIRTUAL PAGES // --- // Create a "draft" virtual page with a broken link. $page = VirtualPage::create(); $page->CopyContentFromID = 987654321; $page->writeToStage('Stage'); // ASSERT that the "draft" report has detected the page having a broken link. // ASSERT that the "published" report has NOT detected the page having a broken link, as the page has not been "published" yet. $this->isReportBroken($brokenLinksReport, true, false, 'VPBROKENLINK'); // Make sure the page is now "published". $page->writeToStage('Live'); // ASSERT that the "draft" report has detected the page having a broken link. // ASSERT that the "published" report has detected the page having a broken link. $this->isReportBroken($brokenLinksReport, true, true, 'VPBROKENLINK'); // Correct the "draft" broken link. $contentPage = Page::create(); $contentPage->Content = 'This is some content.'; $contentPage->writeToStage('Stage'); $contentPage->writeToStage('Live'); $page->CopyContentFromID = $contentPage->ID; $page->writeToStage('Stage'); // ASSERT that the "draft" report has NOT detected the page having a broken link. // ASSERT that the "published" report has detected the page having a broken link, as the previous content remains "published". $this->isReportBroken($brokenLinksReport, false, true, 'VPBROKENLINK'); // Make sure the change has now been "published". $page->writeToStage('Live'); // ASSERT that the "draft" report has NOT detected the page having a broken link. // ASSERT that the "published" report has NOT detected the page having a broken link. $this->isReportBroken($brokenLinksReport, false, false, 'VPBROKENLINK'); $contentPage->delete(); $page->delete(); // --- // BROKEN REDIRECTOR PAGES // --- // Create a "draft" redirector page with a broken link. $page = RedirectorPage::create(); $page->RedirectionType = 'Internal'; $page->LinkToID = 987654321; $page->writeToStage('Stage'); // ASSERT that the "draft" report has detected the page having a broken link. // ASSERT that the "published" report has NOT detected the page having a broken link, as the page has not been "published" yet. $this->isReportBroken($brokenLinksReport, true, false, 'RPBROKENLINK'); // Make sure the page is now "published". $page->writeToStage('Live'); // ASSERT that the "draft" report has detected the page having a broken link. // ASSERT that the "published" report has detected the page having a broken link. $this->isReportBroken($brokenLinksReport, true, true, 'RPBROKENLINK'); // Correct the "draft" broken link. $contentPage = Page::create(); $contentPage->Content = 'This is some content.'; $contentPage->writeToStage('Stage'); $contentPage->writeToStage('Live'); $page->LinkToID = $contentPage->ID; $page->writeToStage('Stage'); // ASSERT that the "draft" report has NOT detected the page having a broken link. // ASSERT that the "published" report has detected the page having a broken link, as the previous content remains "published". $this->isReportBroken($brokenLinksReport, false, true, 'RPBROKENLINK'); // Make sure the change has now been "published". $page->writeToStage('Live'); // ASSERT that the "draft" report has NOT detected the page having a broken link. // ASSERT that the "published" report has NOT detected the page having a broken link. $this->isReportBroken($brokenLinksReport, false, false, 'RPBROKENLINK'); } }
/** * Test the broken virtual pages side report. */ public function testBrokenVirtualPages() { // Create a "draft" virtual page with a broken link. $page = VirtualPage::create(); $page->CopyContentFromID = 987654321; $page->writeToStage('Stage'); // Retrieve the broken virtual pages side report. $reports = SS_Report::get_reports(); $brokenVirtualPagesReport = null; foreach ($reports as $report) { if ($report instanceof SideReport_BrokenVirtualPages) { $brokenVirtualPagesReport = $report; break; } } // Determine that the report exists, otherwise it has been excluded. if ($brokenVirtualPagesReport) { // ASSERT that the "draft" report has detected the page having a broken link. // ASSERT that the "published" report has NOT detected the page having a broken link, as the page has not been "published" yet. $this->isReportBroken($brokenVirtualPagesReport, true, false); // Make sure the page is now "published". $page->writeToStage('Live'); // ASSERT that the "draft" report has detected the page having a broken link. // ASSERT that the "published" report has detected the page having a broken link. $this->isReportBroken($brokenVirtualPagesReport, true, true); // Correct the "draft" broken link. $contentPage = Page::create(); $contentPage->Content = 'This is some content.'; $contentPage->writeToStage('Stage'); $contentPage->writeToStage('Live'); $page->CopyContentFromID = $contentPage->ID; $page->writeToStage('Stage'); // ASSERT that the "draft" report has NOT detected the page having a broken link. // ASSERT that the "published" report has detected the page having a broken link, as the previous content remains "published". $this->isReportBroken($brokenVirtualPagesReport, false, true); // Make sure the change has now been "published". $page->writeToStage('Live'); // ASSERT that the "draft" report has NOT detected the page having a broken link. // ASSERT that the "published" report has NOT detected the page having a broken link. $this->isReportBroken($brokenVirtualPagesReport, false, false); } }