diff --git a/core/Archive/ArchiveInvalidator.php b/core/Archive/ArchiveInvalidator.php index 8b17756a85a..2cec27df2aa 100644 --- a/core/Archive/ArchiveInvalidator.php +++ b/core/Archive/ArchiveInvalidator.php @@ -654,9 +654,8 @@ public function removeInvalidationsFromDistributedList($idSites, $pluginName = n $list = new ReArchiveList(); $entries = $list->getAll(); - // Make sure that idSites is an array or all before using it - $idSites = empty($idSites) || 'all' === $idSites - ? 'all' : (is_array($idSites) ? $idSites : [$idSites]); + // Make sure that if idSites is an int it is wrapped with an array + $idSites = (empty($idSites) || !is_numeric($idSites)) ? $idSites : [$idSites]; if ($idSites === 'all') { $idSites = $this->getAllSitesId(); diff --git a/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php b/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php index 60bf893328c..a1040a66218 100644 --- a/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php +++ b/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php @@ -360,34 +360,35 @@ public function testRemoveInvalidationsFromDistributedListRemovesEntriesFromList } /** - * @dataProvider getRemoveInvalidationsFromDistributedListRemovesAllSiteEntriesTestData + * @dataProvider getRemoveInvalidationsFromDistributedListDifferentIdSiteValues * @param $idSites * @return void */ - public function testRemoveInvalidationsFromDistributedListRemovesAllSiteEntries($idSites) + public function testRemoveInvalidationsFromDistributedListDifferentIdSiteValues($idSites, $expectedArray) { $this->invalidator->scheduleReArchiving([1, 2, 3], 'ExamplePlugin'); $this->invalidator->scheduleReArchiving([1, 4, 5], 'ExamplePlugin'); $this->invalidator->scheduleReArchiving('all', 'ExamplePlugin'); + if (empty($idSites)) { + $this->expectException(\TypeError::class); + } $this->invalidator->removeInvalidationsFromDistributedList($idSites, 'ExamplePlugin'); $list = new ReArchiveList(); $items = $list->getAll(); - $expected = []; - - $this->assertEquals($expected, $items); + $this->assertEquals($expectedArray, $items); } - public function getRemoveInvalidationsFromDistributedListRemovesAllSiteEntriesTestData(): array + public function getRemoveInvalidationsFromDistributedListDifferentIdSiteValues(): array { return [ - [null], - [0], - ['0'], - [false], - ['all'], + [null, [1, 2, 3, 4, 5]], + [0, [1, 2, 3, 4, 5]], + ['0', [1, 2, 3, 4, 5]], + [false, [1, 2, 3, 4, 5]], + ['all', []], ]; }