From b4c210f2112c0e05a23e85572a6d6a0b014d5803 Mon Sep 17 00:00:00 2001 From: Garion Herman Date: Thu, 4 Feb 2021 09:45:39 +1300 Subject: [PATCH] FIX Exclude links attached to archived Pages from report (#72) --- src/Reports/BrokenExternalLinksReport.php | 3 ++- tests/ExternalLinksTest.php | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Reports/BrokenExternalLinksReport.php b/src/Reports/BrokenExternalLinksReport.php index 540c4fa..bb94d8a 100644 --- a/src/Reports/BrokenExternalLinksReport.php +++ b/src/Reports/BrokenExternalLinksReport.php @@ -71,7 +71,8 @@ class BrokenExternalLinksReport extends Report { $track = BrokenExternalPageTrackStatus::get_latest(); if ($track) { - return $track->BrokenLinks(); + // Filter items that are attached to archived Pages + return $track->BrokenLinks()->exclude('Track.Page.ID', null); } return ArrayList::create(); } diff --git a/tests/ExternalLinksTest.php b/tests/ExternalLinksTest.php index 4806774..b9014fd 100644 --- a/tests/ExternalLinksTest.php +++ b/tests/ExternalLinksTest.php @@ -107,4 +107,22 @@ class ExternalLinksTest extends SapphireTest 'BrokenExternalLinksReport is in reports list' ); } + + public function testArchivedPagesAreHiddenFromReport() + { + // Run link checker + $task = CheckExternalLinksTask::create(); + $task->setSilent(true); // Be quiet during the test! + $task->runLinksCheck(); + + // Ensure report lists all broken links + $this->assertEquals(4, BrokenExternalLinksReport::create()->sourceRecords()->count()); + + // Archive a page + $page = $this->objFromFixture(ExternalLinksTestPage::class, 'page1'); + $page->doArchive(); + + // Ensure report does not list the link associated with an archived page + $this->assertEquals(3, BrokenExternalLinksReport::create()->sourceRecords()->count()); + } }