3 namespace MediaWiki\Tests\Maintenance
;
5 use InvalidateBotPasswords
;
6 use MediaWiki\User\BotPasswordStore
;
9 * @covers \InvalidateBotPasswords
13 class InvalidateBotPasswordsTest
extends MaintenanceBaseTestCase
{
14 public function getMaintenanceClass() {
15 return InvalidateBotPasswords
::class;
18 /** @dataProvider provideExecuteForFatalError */
19 public function testExecuteForFatalError( $options, $expectedOutputRegex = null ) {
20 $this->expectCallToFatalError();
21 foreach ( $options as $name => $value ) {
22 $this->maintenance
->setOption( $name, $value );
24 $this->maintenance
->execute();
25 if ( $expectedOutputRegex ) {
26 $this->expectOutputRegex( $expectedOutputRegex );
30 public static function provideExecuteForFatalError() {
32 'No options provided' => [ [], '/A "user" or "userid" must be set/' ],
33 'User ID option for ID which does not exist' => [ [ 'userid' => 0 ] ],
34 'User option for user which does not exist' => [ [ 'user' => 'Non-existent-test-user' ] ],
38 /** @dataProvider provideExecute */
39 public function testExecute( $mockBotPasswordsWereInvalidated, $expectedOutputRegex ) {
40 $name = $this->getTestUser()->getUserIdentity()->getName();
41 // Mock the BotPasswordStore to expect a call to ::invalidateUserPasswords
42 // This is done to avoid indirectly testing the BotPasswordStore as that should
43 // be tested separately.
44 $this->setService( 'BotPasswordStore', function () use ( $name, $mockBotPasswordsWereInvalidated ) {
45 $mockBotPasswordStore = $this->createMock( BotPasswordStore
::class );
46 $mockBotPasswordStore->expects( $this->once() )
47 ->method( 'invalidateUserPasswords' )
49 ->willReturn( $mockBotPasswordsWereInvalidated );
50 return $mockBotPasswordStore;
52 // Run the maintenance script
53 $this->maintenance
->setOption( 'user', $name );
54 $this->maintenance
->execute();
55 $this->expectOutputRegex( $expectedOutputRegex );
58 public static function provideExecute() {
60 'No bot passwords were invalidated' => [ false, '/No bot passwords invalidated for/' ],
61 'Bot passwords were invalidated' => [ true, '/Bot passwords invalidated/' ],