wiki.techinc.nl/tests/phpunit/maintenance/DeleteUserEmailTest.php
Daimona Eaytoy 2a0de02aab phpunit: Avoid TestUser in non-database tests
TestUser creates the user and therefore needs the database. Avoid using
it in non-database tests.

Add ApiQueryBlockInfoTraitTest to the Database group because it needs
the database.

Add DeleteUserEmailTest to the Database group because since 3bedffa8
the default user is not created any more in non-database tests

Change-Id: Iff438964dde47a47a2fa4a314d55010bd8c7fee5
2023-07-29 14:26:50 +00:00

34 lines
1.2 KiB
PHP

<?php
use MediaWiki\Tests\Maintenance\MaintenanceBaseTestCase;
/**
* @covers DeleteUserEmail
* @group Database
*/
class DeleteUserEmailTest extends MaintenanceBaseTestCase {
public function getMaintenanceClass() {
return DeleteUserEmail::class;
}
public function testEmailDeletion() {
// Target an existing user with an email attached
$userName = $this->getTestSysop()->getUserIdentity()->getName();
$userFactory = $this->getServiceContainer()->getUserFactory();
$testUserBeforeExecution = $userFactory->newFromName( $userName );
$oldEmail = $testUserBeforeExecution->getEmail();
$this->assertNotNull( $oldEmail );
// Execute the maintance script
$this->maintenance->loadWithArgv( [ $userName ] );
$this->maintenance->execute();
// Check that the email address was changed and invalidated
$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!/' );
}
}