wiki.techinc.nl/tests/phpunit/maintenance/DeleteUserEmailTest.php
Dreamy Jazz db702d19d5 Expand DeleteUserEmailTest
Why:
* The maintenance scripts in core are mostly untested and testing
  the less complex scripts will improve the test coverage in core.

What:
* Expand the integration tests in ResetUserEmailTest to cover the
  case where a user ID is provided instead of a username in the
  script arguments.

Bug: T371167
Change-Id: I6887db8035210dc3a68d23c3aaa2bc0494f8b056
2024-07-27 21:54:50 +00:00

50 lines
1.8 KiB
PHP

<?php
use MediaWiki\Tests\Maintenance\MaintenanceBaseTestCase;
/**
* @covers \DeleteUserEmail
* @group Database
*/
class DeleteUserEmailTest extends MaintenanceBaseTestCase {
public function getMaintenanceClass() {
return DeleteUserEmail::class;
}
private function commonTestEmailDeletion( $userArg, $userName, $oldEmail ) {
// Execute the maintenance script
$this->maintenance->loadWithArgv( [ $userArg ] );
$this->maintenance->execute();
// Check that the email address was changed and invalidated
$userFactory = $this->getServiceContainer()->getUserFactory();
$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!/' );
}
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
);
}
}