3 use MediaWiki\Tests\Maintenance\MaintenanceBaseTestCase
;
4 use MediaWiki\User\UserGroupManager
;
7 * @covers \PurgeExpiredUserrights
10 class PurgeExpiredUserrightsTest
extends MaintenanceBaseTestCase
{
11 public function getMaintenanceClass() {
12 return PurgeExpiredUserrights
::class;
15 /** @dataProvider provideExecute */
16 public function testExecute( $mockPurgeExpiredReturnValue, $expectedOutputRegex ) {
17 // Mock the UserGroupManager to expect that ::purgeExpired is called once
18 // and also then return a fake value.
19 $mockUserGroupManager = $this->createMock( UserGroupManager
::class );
20 $mockUserGroupManager->expects( $this->once() )
21 ->method( 'purgeExpired' )
22 ->willReturn( $mockPurgeExpiredReturnValue );
23 $this->setService( 'UserGroupManager', $mockUserGroupManager );
24 $this->maintenance
->execute();
25 $this->expectOutputRegex( $expectedOutputRegex );
28 public static function provideExecute() {
30 '::purgeExpired returns false' => [ false, '/Purging expired user rights[\s\S]*Purging failed/' ],
31 '::purgeExpired returns 0' => [ 0, '/Purging expired user rights[\s\S]*0 rows purged/' ],
32 '::purgeExpired returns 3' => [ 3, '/Purging expired user rights[\s\S]*3 rows purged/' ],