3 use MediaWiki\MainConfigNames
;
4 use MediaWiki\Tests\Maintenance\MaintenanceBaseTestCase
;
5 use Wikimedia\Timestamp\ConvertibleTimestamp
;
8 * @covers \PurgeExpiredWatchlistItems
12 class PurgeExpiredWatchlistItemsTest
extends MaintenanceBaseTestCase
{
13 public function getMaintenanceClass() {
14 return PurgeExpiredWatchlistItems
::class;
17 public function testExecuteWhenWatchlistExpiryDisabled() {
18 $this->overrideConfigValue( MainConfigNames
::WatchlistExpiry
, false );
19 $this->maintenance
->execute();
20 $this->expectOutputRegex( '/Watchlist expiry is not enabled.*/' );
23 public function testExecuteWhenNoItemsInWatchedItemStore() {
24 $this->overrideConfigValue( MainConfigNames
::WatchlistExpiry
, true );
25 $this->maintenance
->execute();
26 $this->expectOutputRegex( '/0 expired watchlist entries found.*/' );
29 /** @dataProvider provideExecuteWhenItemsExpired */
30 public function testExecuteWhenItemsExpired( $batchSize, $expiredWatchlistCount, $nonExpiredWatchlistCount ) {
31 $this->overrideConfigValue( MainConfigNames
::WatchlistExpiry
, true );
32 $testPage = $this->getExistingTestPage();
33 $watchedItemStore = $this->getServiceContainer()->getWatchedItemStore();
34 // Add some items that will be expired once we run the maintenance script.
35 ConvertibleTimestamp
::setFakeTime( '20230405060708' );
36 for ( $i = 0; $i < $expiredWatchlistCount; $i++
) {
37 $watchedItemStore->addWatch( $this->getMutableTestUser()->getUserIdentity(), $testPage, '1 month' );
39 // Add some items that will not be expired.
40 for ( $i = 0; $i < $nonExpiredWatchlistCount; $i++
) {
41 $watchedItemStore->addWatch( $this->getMutableTestUser()->getUserIdentity(), $testPage, '1 year' );
43 // Set the fake time to 2 months in advance of the previous take time
44 ConvertibleTimestamp
::setFakeTime( '20230605060708' );
45 // Run the maintenance script
46 $this->maintenance
->setOption( 'batch-size', $batchSize );
47 $this->maintenance
->execute();
48 $this->expectOutputRegex(
49 "/$expiredWatchlistCount expired watchlist entries found.\nAll expired entries purged.\n/"
52 $nonExpiredWatchlistCount,
53 $watchedItemStore->countWatchers( $testPage ),
54 'The number of watched items after the maintenance script was not as expected.'
58 public static function provideExecuteWhenItemsExpired() {
60 'All items expired' => [ 3, 7, 0 ],
61 'Some items expired' => [ 2, 3, 3 ],