| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Maintenance; |
| 4 |
|
| 5 |
use InvalidateBotPasswords; |
| 6 |
use MediaWiki\User\BotPasswordStore; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class InvalidateBotPasswordsTest extends MaintenanceBaseTestCase { |
| 14 |
public function getMaintenanceClass() { |
| 15 |
return InvalidateBotPasswords::class; |
| 16 |
} |
| 17 |
|
| 18 |
|
| 19 |
public function testExecuteForFatalError( $options, $expectedOutputRegex = null ) { |
| 20 |
$this->expectCallToFatalError(); |
| 21 |
foreach ( $options as $name => $value ) { |
| 22 |
$this->maintenance->setOption( $name, $value ); |
| 23 |
} |
| 24 |
$this->maintenance->execute(); |
| 25 |
if ( $expectedOutputRegex ) { |
| 26 |
$this->expectOutputRegex( $expectedOutputRegex ); |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
public static function provideExecuteForFatalError() { |
| 31 |
return [ |
| 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' ] ], |
| 35 |
]; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
public function testExecute( $mockBotPasswordsWereInvalidated, $expectedOutputRegex ) { |
| 40 |
$name = $this->getTestUser()->getUserIdentity()->getName(); |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
$this->setService( 'BotPasswordStore', function () use ( $name, $mockBotPasswordsWereInvalidated ) { |
| 45 |
$mockBotPasswordStore = $this->createMock( BotPasswordStore::class ); |
| 46 |
$mockBotPasswordStore->expects( $this->once() ) |
| 47 |
->method( 'invalidateUserPasswords' ) |
| 48 |
->with( $name ) |
| 49 |
->willReturn( $mockBotPasswordsWereInvalidated ); |
| 50 |
return $mockBotPasswordStore; |
| 51 |
} ); |
| 52 |
|
| 53 |
$this->maintenance->setOption( 'user', $name ); |
| 54 |
$this->maintenance->execute(); |
| 55 |
$this->expectOutputRegex( $expectedOutputRegex ); |
| 56 |
} |
| 57 |
|
| 58 |
public static function provideExecute() { |
| 59 |
return [ |
| 60 |
'No bot passwords were invalidated' => [ false, '/No bot passwords invalidated for/' ], |
| 61 |
'Bot passwords were invalidated' => [ true, '/Bot passwords invalidated/' ], |
| 62 |
]; |
| 63 |
} |
| 64 |
} |