Skip to content

Commit

Permalink
Adjusting fix to be less likely to introduce regressions
Browse files Browse the repository at this point in the history
  • Loading branch information
snake14 committed Oct 17, 2024
1 parent 7474f4f commit 863e84f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
5 changes: 2 additions & 3 deletions core/Archive/ArchiveInvalidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
23 changes: 12 additions & 11 deletions tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', []],
];
}

Expand Down

0 comments on commit 863e84f

Please sign in to comment.