Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / maintenance / DeleteUserEmailTest.php
blobffca7b096a627b8f5486f8c5a3d5e40a67b5a34c
1 <?php
2 use MediaWiki\Tests\Maintenance\MaintenanceBaseTestCase;
4 /**
5 * @covers \DeleteUserEmail
6 * @group Database
7 */
8 class DeleteUserEmailTest extends MaintenanceBaseTestCase {
9 public function getMaintenanceClass() {
10 return DeleteUserEmail::class;
13 private function commonTestEmailDeletion( $userArg, $userName, $oldEmail ) {
14 // Execute the maintenance script
15 $this->maintenance->loadWithArgv( [ $userArg ] );
16 $this->maintenance->execute();
18 // Check that the email address was changed and invalidated
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() );
25 // Check that the script returns the right output
26 $this->expectOutputRegex( '/Done!/' );
29 public function testEmailDeletionWhenProvidingName() {
30 // Target an existing user with an email attached
31 $testUserBeforeExecution = $this->getTestSysop()->getUser();
32 $oldEmail = $testUserBeforeExecution->getEmail();
33 $this->assertNotNull( $oldEmail );
34 // Test providing the maintenance script with a username.
35 $this->commonTestEmailDeletion(
36 $testUserBeforeExecution->getName(), $testUserBeforeExecution->getName(), $oldEmail
40 public function testEmailDeletionWhenProvidingId() {
41 // Target an existing user with an email attached
42 $testUserBeforeExecution = $this->getTestSysop()->getUser();
43 $oldEmail = $testUserBeforeExecution->getEmail();
44 $this->assertNotNull( $oldEmail );
45 // Test providing the maintenance script with a user ID.
46 $this->commonTestEmailDeletion(
47 "#" . $testUserBeforeExecution->getId(), $testUserBeforeExecution->getName(), $oldEmail
51 /** @dataProvider provideInvalidUsernameArgumentValues */
52 public function testEmailDeletionForInvalidUsername( $invalidUsernameArgument ) {
53 $this->expectCallToFatalError();
54 $this->expectOutputRegex( "/$invalidUsernameArgument.*could not be loaded/" );
55 // Execute the maintenance script
56 $this->maintenance->setArg( 'user', $invalidUsernameArgument );
57 $this->maintenance->execute();
60 public static function provideInvalidUsernameArgumentValues() {
61 return [
62 'Invalid username' => [ 'Template:test#test' ],
63 'Non-existent user' => [ 'Non-existent-test-user-1234' ],