wiki.techinc.nl/tests/phpunit/maintenance/CheckUsernamesTest.php
Dreamy Jazz 55642b2ee8 Test checkUsernames.php
The checkUsernames.php script is completely untested. Adding tests
is useful to verify that the script works, especially that the
output remains consistent.

Bug: T371167
Change-Id: Ib1889908a69d1401463ae0ae93e7c9446903327b
2024-07-28 00:17:58 +01:00

32 lines
977 B
PHP

<?php
namespace MediaWiki\Tests\Maintenance;
use CheckUsernames;
use MediaWiki\MainConfigNames;
use TestUser;
/**
* @covers \CheckUsernames
* @group Database
*/
class CheckUsernamesTest extends MaintenanceBaseTestCase {
protected function getMaintenanceClass() {
return CheckUsernames::class;
}
public function testExecute() {
$testUser1 = ( new TestUser( "TestUser 1234" ) )->getUserIdentity();
$testUser2 = ( new TestUser( "TestUser 4321" ) )->getUserIdentity();
// Set wgMaxNameChars to 2 so that both users fail to be valid.
$this->overrideConfigValue( MainConfigNames::MaxNameChars, 2 );
// Set the batch size to 1 to test multiple batches (as there are two users)
$this->maintenance->setOption( 'batch-size', 1 );
$this->maintenance->execute();
$this->expectOutputString(
sprintf( "Found: %6d: '%s'\n", $testUser1->getId(), $testUser1->getName() ) .
sprintf( "Found: %6d: '%s'\n", $testUser2->getId(), $testUser2->getName() )
);
}
}