| 1 |
<?php |
| 2 |
use MediaWiki\Tests\Maintenance\MaintenanceBaseTestCase; |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
class DeleteUserEmailTest extends MaintenanceBaseTestCase { |
| 9 |
public function getMaintenanceClass() { |
| 10 |
return DeleteUserEmail::class; |
| 11 |
} |
| 12 |
|
| 13 |
private function commonTestEmailDeletion( $userArg, $userName, $oldEmail ) { |
| 14 |
|
| 15 |
$this->maintenance->loadWithArgv( [ $userArg ] ); |
| 16 |
$this->maintenance->execute(); |
| 17 |
|
| 18 |
|
| 19 |
$userFactory = $this->getServiceContainer()->getUserFactory(); |
| 20 |
$testUserAfterExecution = $userFactory->newFromName( $userName ); |
| 21 |
$this->assertNotEquals( $oldEmail, $testUserAfterExecution->getEmail() ); |
| 22 |
$this->assertSame( '', $testUserAfterExecution->getEmail() ); |
| 23 |
$this->assertNull( $testUserAfterExecution->getEmailAuthenticationTimestamp() ); |
| 24 |
|
| 25 |
|
| 26 |
$this->expectOutputRegex( '/Done!/' ); |
| 27 |
} |
| 28 |
|
| 29 |
public function testEmailDeletionWhenProvidingName() { |
| 30 |
|
| 31 |
$testUserBeforeExecution = $this->getTestSysop()->getUser(); |
| 32 |
$oldEmail = $testUserBeforeExecution->getEmail(); |
| 33 |
$this->assertNotNull( $oldEmail ); |
| 34 |
|
| 35 |
$this->commonTestEmailDeletion( |
| 36 |
$testUserBeforeExecution->getName(), $testUserBeforeExecution->getName(), $oldEmail |
| 37 |
); |
| 38 |
} |
| 39 |
|
| 40 |
public function testEmailDeletionWhenProvidingId() { |
| 41 |
|
| 42 |
$testUserBeforeExecution = $this->getTestSysop()->getUser(); |
| 43 |
$oldEmail = $testUserBeforeExecution->getEmail(); |
| 44 |
$this->assertNotNull( $oldEmail ); |
| 45 |
|
| 46 |
$this->commonTestEmailDeletion( |
| 47 |
"#" . $testUserBeforeExecution->getId(), $testUserBeforeExecution->getName(), $oldEmail |
| 48 |
); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
public function testEmailDeletionForInvalidUsername( $invalidUsernameArgument ) { |
| 53 |
$this->expectCallToFatalError(); |
| 54 |
$this->expectOutputRegex( "/$invalidUsernameArgument.*could not be loaded/" ); |
| 55 |
|
| 56 |
$this->maintenance->setArg( 'user', $invalidUsernameArgument ); |
| 57 |
$this->maintenance->execute(); |
| 58 |
} |
| 59 |
|
| 60 |
public static function provideInvalidUsernameArgumentValues() { |
| 61 |
return [ |
| 62 |
'Invalid username' => [ 'Template:test#test' ], |
| 63 |
'Non-existent user' => [ 'Non-existent-test-user-1234' ], |
| 64 |
]; |
| 65 |
} |
| 66 |
} |