wiki.techinc.nl/tests/phpunit/maintenance/ExpireTemporaryAccountsTest.php
Dreamy Jazz 6535ad0590 Partly test expireTemporaryAccounts.php
Why:
* The expireTemporaryAccounts.php script is not tested, and testing
  some of the script (all except that which actually expires a
  temporary account) can improve test coverage for maintenance
  scripts in core

What:
* Create ExpireTemporaryAccountsTest which tests what the script
  does cases where no temporary accounts are actually expired.

Bug: T371167
Change-Id: I82f3b418edb08f45fc04393996c792df145db45d
2024-08-08 13:31:31 +00:00

40 lines
1.3 KiB
PHP

<?php
namespace MediaWiki\Tests\Maintenance;
use ExpireTemporaryAccounts;
use MediaWiki\Auth\AuthManager;
use MediaWiki\Tests\User\TempUser\TempUserTestTrait;
/**
* @covers \ExpireTemporaryAccounts
* @group Database
* @author Dreamy Jazz
*/
class ExpireTemporaryAccountsTest extends MaintenanceBaseTestCase {
use TempUserTestTrait;
protected function getMaintenanceClass() {
return ExpireTemporaryAccounts::class;
}
public function testExecuteWhenTemporaryAccountsNotKnown() {
$this->disableAutoCreateTempUser();
$this->expectOutputRegex( '/Temporary accounts are disabled/' );
$this->maintenance->execute();
}
public function testExecuteWhenTemporaryAccountsNeverExpire() {
$this->enableAutoCreateTempUser( [ 'expireAfterDays' => null, 'notifyBeforeExpirationDays' => null ] );
$this->expectOutputRegex( '/Temporary account expiry is not enabled/' );
$this->maintenance->execute();
}
public function testExecuteWithNoExistingTemporaryAccounts() {
// Create a no-op mock AuthManager, as no accounts should be expired by the script.
$this->setService( 'AuthManager', $this->createNoOpMock( AuthManager::class ) );
$this->enableAutoCreateTempUser();
$this->expectOutputRegex( '/Revoked access for 0 temporary users/' );
$this->maintenance->execute();
}
}