diff --git a/code/reports/BrokenFilesReport.php b/code/reports/BrokenFilesReport.php index fe4e5235..13d34514 100644 --- a/code/reports/BrokenFilesReport.php +++ b/code/reports/BrokenFilesReport.php @@ -16,16 +16,18 @@ class BrokenFilesReport extends SS_Report { public function sourceRecords($params = null) { // Get class names for page types that are not virtual pages or redirector pages - $classes = array_diff(ClassInfo::subclassesFor('SiteTree'), ClassInfo::subclassesFor('VirtualPage'), ClassInfo::subclassesFor('RedirectorPage')); + $classes = array_diff( + ClassInfo::subclassesFor('SiteTree'), + ClassInfo::subclassesFor('VirtualPage'), + ClassInfo::subclassesFor('RedirectorPage') + ); + $classParams = DB::placeholders($classes); + $classFilter = array( + "\"ClassName\" IN ($classParams) AND \"HasBrokenFile\" = 1" => $classes + ); - $classNames = "'".join("','", $classes)."'"; - - if (isset($_REQUEST['OnLive'])) { - $ret = Versioned::get_by_stage('SiteTree', 'Live', "\"ClassName\" IN ($classNames) AND \"HasBrokenFile\" = 1"); - } else { - $ret = DataObject::get('SiteTree', "\"ClassName\" IN ($classNames) AND \"HasBrokenFile\" = 1"); - } - return $ret; + $stage = isset($params['OnLive']) ? 'Live' : 'Stage'; + return Versioned::get_by_stage('SiteTree', $stage, $classFilter); } public function columns() { @@ -42,4 +44,14 @@ class BrokenFilesReport extends SS_Report { new CheckboxField('OnLive', _t('SideReport.ParameterLiveCheckbox', 'Check live site')) ); } -} \ No newline at end of file +} + +/** + * @deprecated 3.2..4.0 + */ +class SideReport_BrokenFiles extends BrokenFilesReport { + public function __construct() { + Deprecation::notice('4.0', 'Use BrokenFilesReport instead'); + parent::__construct(); + } +} diff --git a/code/reports/BrokenLinksReport.php b/code/reports/BrokenLinksReport.php index 6dc1d2c0..4ef1511c 100644 --- a/code/reports/BrokenLinksReport.php +++ b/code/reports/BrokenLinksReport.php @@ -29,14 +29,14 @@ class BrokenLinksReport extends SS_Report { $sort = ''; } } - if (!isset($_REQUEST['CheckSite']) || $params['CheckSite'] == 'Published') { - $ret = Versioned::get_by_stage('SiteTree', 'Live', array( - '"SiteTree"."HasBrokenLink" = ? OR "SiteTree"."HasBrokenFile" = ?' => array(true, true) - ), $sort, $join, $limit); + $brokenFilter = array( + '"SiteTree"."HasBrokenLink" = ? OR "SiteTree"."HasBrokenFile" = ?' => array(true, true) + ); + $isLive = !isset($params['CheckSite']) || $params['CheckSite'] == 'Published'; + if ($isLive) { + $ret = Versioned::get_by_stage('SiteTree', 'Live', $brokenFilter, $sort, $join, $limit); } else { - $ret = DataObject::get('SiteTree', array( - '"SiteTree"."HasBrokenFile" = ? OR "SiteTree"."HasBrokenLink" = ?' => array(true, true) - ), $sort, $join, $limit); + $ret = DataObject::get('SiteTree', $brokenFilter, $sort, $join, $limit); } $returnSet = new ArrayList(); @@ -141,3 +141,14 @@ class BrokenLinksReport extends SS_Report { ); } } + + +/** + * @deprecated 3.2..4.0 + */ +class SideReport_BrokenLinks extends BrokenLinksReport { + public function __construct() { + Deprecation::notice('4.0', 'Use BrokenLinksReport instead'); + parent::__construct(); + } +} diff --git a/code/reports/BrokenRedirectorPagesReport.php b/code/reports/BrokenRedirectorPagesReport.php index 56c14425..5a69e619 100644 --- a/code/reports/BrokenRedirectorPagesReport.php +++ b/code/reports/BrokenRedirectorPagesReport.php @@ -15,11 +15,13 @@ class BrokenRedirectorPagesReport extends SS_Report { } public function sourceRecords($params = null) { - $classNames = "'".join("','", ClassInfo::subclassesFor('RedirectorPage'))."'"; - - if (isset($_REQUEST['OnLive'])) $ret = Versioned::get_by_stage('SiteTree', 'Live', "\"ClassName\" IN ($classNames) AND \"HasBrokenLink\" = 1"); - else $ret = DataObject::get('SiteTree', "\"ClassName\" IN ($classNames) AND \"HasBrokenLink\" = 1"); - return $ret; + $classes = ClassInfo::subclassesFor('RedirectorPage'); + $classParams = DB::placeholders($classes); + $classFilter = array( + "\"ClassName\" IN ($classParams) AND \"HasBrokenLink\" = 1" => $classes + ); + $stage = isset($params['OnLive']) ? 'Live' : 'Stage'; + return Versioned::get_by_stage('SiteTree', $stage, $classFilter); } public function columns() { @@ -37,3 +39,13 @@ class BrokenRedirectorPagesReport extends SS_Report { ); } } + +/** + * @deprecated 3.2..4.0 + */ +class SideReport_BrokenRedirectorPages extends BrokenRedirectorPagesReport { + public function __construct() { + Deprecation::notice('4.0', 'Use BrokenRedirectorPagesReport instead'); + parent::__construct(); + } +} diff --git a/code/reports/BrokenVirtualPagesReport.php b/code/reports/BrokenVirtualPagesReport.php index f187d90f..01eb430d 100644 --- a/code/reports/BrokenVirtualPagesReport.php +++ b/code/reports/BrokenVirtualPagesReport.php @@ -15,15 +15,13 @@ class BrokenVirtualPagesReport extends SS_Report { } public function sourceRecords($params = null) { - $classNames = "'".join("','", ClassInfo::subclassesFor('VirtualPage'))."'"; - - if (isset($_REQUEST['OnLive'])) { - $ret = Versioned::get_by_stage('SiteTree', 'Live', "\"ClassName\" IN ($classNames) AND \"HasBrokenLink\" = 1"); - } else { - $ret = DataObject::get('SiteTree', "\"ClassName\" IN ($classNames) AND \"HasBrokenLink\" = 1"); - } - - return $ret; + $classes = ClassInfo::subclassesFor('VirtualPage'); + $classParams = DB::placeholders($classes); + $classFilter = array( + "\"ClassName\" IN ($classParams) AND \"HasBrokenLink\" = 1" => $classes + ); + $stage = isset($params['OnLive']) ? 'Live' : 'Stage'; + return Versioned::get_by_stage('SiteTree', $stage, $classFilter); } public function columns() { @@ -40,4 +38,14 @@ class BrokenVirtualPagesReport extends SS_Report { new CheckboxField('OnLive', _t('SideReport.ParameterLiveCheckbox', 'Check live site')) ); } -} \ No newline at end of file +} + +/** + * @deprecated 3.2..4.0 + */ +class SideReport_BrokenVirtualPages extends BrokenVirtualPagesReport { + public function __construct() { + Deprecation::notice('4.0', 'Use BrokenVirtualPagesReport instead'); + parent::__construct(); + } +} diff --git a/code/reports/EmptyPagesReport.php b/code/reports/EmptyPagesReport.php index ed718660..4bbfc9fb 100644 --- a/code/reports/EmptyPagesReport.php +++ b/code/reports/EmptyPagesReport.php @@ -32,4 +32,14 @@ class EmptyPagesReport extends SS_Report { ), ); } -} \ No newline at end of file +} + +/** + * @deprecated 3.2..4.0 + */ +class SideReport_EmptyPages extends EmptyPagesReport { + public function __construct() { + Deprecation::notice('4.0', 'Use EmptyPagesReport instead'); + parent::__construct(); + } +} diff --git a/code/reports/RecentlyEditedReport.php b/code/reports/RecentlyEditedReport.php index 65d1664c..c1dca206 100644 --- a/code/reports/RecentlyEditedReport.php +++ b/code/reports/RecentlyEditedReport.php @@ -31,4 +31,14 @@ class RecentlyEditedReport extends SS_Report { ), ); } -} \ No newline at end of file +} + +/** + * @deprecated 3.2..4.0 + */ +class SideReport_RecentlyEdited extends RecentlyEditedReport { + public function __construct() { + Deprecation::notice('4.0', 'Use RecentlyEditedReport instead'); + parent::__construct(); + } +} diff --git a/tests/reports/CmsReportsTest.php b/tests/reports/CmsReportsTest.php index 25b14c83..3e8b713b 100644 --- a/tests/reports/CmsReportsTest.php +++ b/tests/reports/CmsReportsTest.php @@ -37,15 +37,13 @@ class CmsReportsTest extends SapphireTest { $class = get_class($report); // ASSERT that the "draft" report is returning the correct results. - - $results = count($report->sourceRecords(array())) > 0; + $parameters = array('CheckSite' => 'Draft'); + $results = count($report->sourceRecords($parameters, null, null)) > 0; $isDraftBroken ? $this->assertTrue($results, "{$class} has NOT returned the correct DRAFT results, as NO pages were found.") : $this->assertFalse($results, "{$class} has NOT returned the correct DRAFT results, as pages were found."); // ASSERT that the "published" report is returning the correct results. - - $results = count($report->sourceRecords(array( - 'OnLive' => 1 - ))) > 0; + $parameters = array('CheckSite' => 'Published', 'OnLive' => 1); + $results = count($report->sourceRecords($parameters, null, null)) > 0; $isPublishedBroken ? $this->assertTrue($results, "{$class} has NOT returned the correct PUBLISHED results, as NO pages were found.") : $this->assertFalse($results, "{$class} has NOT returned the correct PUBLISHED results, as pages were found."); } @@ -82,49 +80,50 @@ class CmsReportsTest extends SapphireTest { $reports = SS_Report::get_reports(); $brokenLinksReport = null; foreach($reports as $report) { - if($report instanceof SideReport_BrokenLinks) { + 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); - - // 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); - - // 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); - - // 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); + if(!$brokenLinksReport){ + $this->markTestSkipped('BrokenLinksReport is not an available report'); + return; } + + // 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); + + // 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); + + // 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); + + // 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); } /** @@ -144,52 +143,53 @@ class CmsReportsTest extends SapphireTest { $reports = SS_Report::get_reports(); $brokenFilesReport = null; foreach($reports as $report) { - if($report instanceof SideReport_BrokenFiles) { + if($report instanceof BrokenFilesReport) { $brokenFilesReport = $report; break; } } // Determine that the report exists, otherwise it has been excluded. - - if($brokenFilesReport) { - - // 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($brokenFilesReport, true, false); - - // 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($brokenFilesReport, true, true); - - // 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($brokenFilesReport, 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 file. - // ASSERT that the "published" report has NOT detected the page having a broken file. - - $this->isReportBroken($brokenFilesReport, false, false); + if(!$brokenFilesReport){ + $this->markTestSkipped('BrokenFilesReport is not an available report'); + return; } + + // 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($brokenFilesReport, true, false); + + // 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($brokenFilesReport, true, true); + + // 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($brokenFilesReport, 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 file. + // ASSERT that the "published" report has NOT detected the page having a broken file. + + $this->isReportBroken($brokenFilesReport, false, false); } /** @@ -209,53 +209,54 @@ class CmsReportsTest extends SapphireTest { $reports = SS_Report::get_reports(); $brokenVirtualPagesReport = null; foreach($reports as $report) { - if($report instanceof SideReport_BrokenVirtualPages) { + if($report instanceof BrokenVirtualPagesReport) { $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); + if(!$brokenVirtualPagesReport){ + $this->markTestSkipped('BrokenFilesReport is not an available report'); + return; } + + // 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); } /** @@ -276,53 +277,54 @@ class CmsReportsTest extends SapphireTest { $reports = SS_Report::get_reports(); $brokenRedirectorPagesReport = null; foreach($reports as $report) { - if($report instanceof SideReport_BrokenRedirectorPages) { + if($report instanceof BrokenRedirectorPagesReport) { $brokenRedirectorPagesReport = $report; break; } } // Determine that the report exists, otherwise it has been excluded. - - if($brokenRedirectorPagesReport) { - - // 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($brokenRedirectorPagesReport, 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($brokenRedirectorPagesReport, true, true); - - // 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($brokenRedirectorPagesReport, 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($brokenRedirectorPagesReport, false, false); + if(!$brokenRedirectorPagesReport){ + $this->markTestSkipped('BrokenRedirectorPagesReport is not an available report'); + return; } + + // 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($brokenRedirectorPagesReport, 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($brokenRedirectorPagesReport, true, true); + + // 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($brokenRedirectorPagesReport, 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($brokenRedirectorPagesReport, false, false); } }