2021-09-18 09:09:39 +00:00
|
|
|
<?php
|
|
|
|
|
use MediaWiki\Tests\Maintenance\MaintenanceBaseTestCase;
|
|
|
|
|
|
|
|
|
|
/**
|
2024-02-16 18:04:47 +00:00
|
|
|
* @covers \DeleteUserEmail
|
2023-07-17 14:08:20 +00:00
|
|
|
* @group Database
|
2021-09-18 09:09:39 +00:00
|
|
|
*/
|
|
|
|
|
class DeleteUserEmailTest extends MaintenanceBaseTestCase {
|
|
|
|
|
public function getMaintenanceClass() {
|
|
|
|
|
return DeleteUserEmail::class;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-27 21:52:14 +00:00
|
|
|
private function commonTestEmailDeletion( $userArg, $userName, $oldEmail ) {
|
|
|
|
|
// Execute the maintenance script
|
|
|
|
|
$this->maintenance->loadWithArgv( [ $userArg ] );
|
2021-09-18 09:09:39 +00:00
|
|
|
$this->maintenance->execute();
|
|
|
|
|
|
|
|
|
|
// Check that the email address was changed and invalidated
|
2024-07-27 21:52:14 +00:00
|
|
|
$userFactory = $this->getServiceContainer()->getUserFactory();
|
2021-09-18 09:09:39 +00:00
|
|
|
$testUserAfterExecution = $userFactory->newFromName( $userName );
|
|
|
|
|
$this->assertNotEquals( $oldEmail, $testUserAfterExecution->getEmail() );
|
|
|
|
|
$this->assertSame( '', $testUserAfterExecution->getEmail() );
|
|
|
|
|
$this->assertNull( $testUserAfterExecution->getEmailAuthenticationTimestamp() );
|
|
|
|
|
|
|
|
|
|
// Check that the script returns the right output
|
|
|
|
|
$this->expectOutputRegex( '/Done!/' );
|
|
|
|
|
}
|
2024-07-27 21:52:14 +00:00
|
|
|
|
|
|
|
|
public function testEmailDeletionWhenProvidingName() {
|
|
|
|
|
// Target an existing user with an email attached
|
|
|
|
|
$testUserBeforeExecution = $this->getTestSysop()->getUser();
|
|
|
|
|
$oldEmail = $testUserBeforeExecution->getEmail();
|
|
|
|
|
$this->assertNotNull( $oldEmail );
|
|
|
|
|
// Test providing the maintenance script with a username.
|
|
|
|
|
$this->commonTestEmailDeletion(
|
|
|
|
|
$testUserBeforeExecution->getName(), $testUserBeforeExecution->getName(), $oldEmail
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testEmailDeletionWhenProvidingId() {
|
|
|
|
|
// Target an existing user with an email attached
|
|
|
|
|
$testUserBeforeExecution = $this->getTestSysop()->getUser();
|
|
|
|
|
$oldEmail = $testUserBeforeExecution->getEmail();
|
|
|
|
|
$this->assertNotNull( $oldEmail );
|
|
|
|
|
// Test providing the maintenance script with a user ID.
|
|
|
|
|
$this->commonTestEmailDeletion(
|
|
|
|
|
"#" . $testUserBeforeExecution->getId(), $testUserBeforeExecution->getName(), $oldEmail
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-08-04 13:50:53 +00:00
|
|
|
|
|
|
|
|
/** @dataProvider provideInvalidUsernameArgumentValues */
|
|
|
|
|
public function testEmailDeletionForInvalidUsername( $invalidUsernameArgument ) {
|
|
|
|
|
$this->expectCallToFatalError();
|
|
|
|
|
$this->expectOutputRegex( "/$invalidUsernameArgument.*could not be loaded/" );
|
|
|
|
|
// Execute the maintenance script
|
|
|
|
|
$this->maintenance->setArg( 'user', $invalidUsernameArgument );
|
|
|
|
|
$this->maintenance->execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideInvalidUsernameArgumentValues() {
|
|
|
|
|
return [
|
|
|
|
|
'Invalid username' => [ 'Template:test#test' ],
|
|
|
|
|
'Non-existent user' => [ 'Non-existent-test-user-1234' ],
|
|
|
|
|
];
|
|
|
|
|
}
|
2021-09-18 09:09:39 +00:00
|
|
|
}
|