3 namespace MediaWiki\Tests\Maintenance
;
5 use MediaWiki\Request\FauxRequest
;
6 use MediaWiki\Tests\User\TempUser\TempUserTestTrait
;
7 use PopulateUserIsTemp
;
10 * @covers \PopulateUserIsTemp
13 class PopulateUserIsTempTest
extends MaintenanceBaseTestCase
{
14 use TempUserTestTrait
;
16 protected function getMaintenanceClass() {
17 return PopulateUserIsTemp
::class;
20 public function testDoDBUpdates() {
21 $this->enableAutoCreateTempUser( [
22 'matchPattern' => [ '*$1', '~$1' ],
24 $this->maintenance
->setOption( 'batch-size', 2 );
27 (int)$this->getDb()->newSelectQueryBuilder()
28 ->select( 'COUNT(*)' )
30 ->where( [ 'user_is_temp' => 1 ] )
32 'The database should have 2 users with user_is_temp set to 1 before the execute method is called.'
35 $this->maintenance
->execute(),
36 'The execute method did not return true as expected.'
40 (int)$this->getDb()->newSelectQueryBuilder()
41 ->select( 'COUNT(*)' )
43 ->where( [ 'user_is_temp' => 1 ] )
45 'The number of users with user_is_temp set to 1 is not as expected.'
49 public function addDBData() {
52 // Create some temporary users and then set the user table to have user_is_temp as 0 for some of them.
53 $this->enableAutoCreateTempUser( [
54 'matchPattern' => [ '*$1', '~$1' ],
56 $tempUserCreator = $this->getServiceContainer()->getTempUserCreator();
57 $tempUserCreator->create( '*Unregistered 1', new FauxRequest() );
58 $tempUserCreator->create( '*Unregistered 2', new FauxRequest() );
59 $tempUserCreator->create( '~Unregistered 3', new FauxRequest() );
60 $tempUserCreator->create( '~Unregistered 4567', new FauxRequest() );
61 $tempUserCreator->create( '~Unregistered 456789', new FauxRequest() );
62 $this->getDb()->newUpdateQueryBuilder()
64 ->set( [ 'user_is_temp' => 0 ] )
65 ->where( [ 'user_name' => [ '*Unregistered 2', '~Unregistered 3', '~Unregistered 456789' ] ] )