Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / maintenance / PopulateUserIsTempTest.php
blobe4301d8f43aee40c2a7888a8b1f58caae9ca0bd1
1 <?php
3 namespace MediaWiki\Tests\Maintenance;
5 use MediaWiki\Request\FauxRequest;
6 use MediaWiki\Tests\User\TempUser\TempUserTestTrait;
7 use PopulateUserIsTemp;
9 /**
10 * @covers \PopulateUserIsTemp
11 * @group Database
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' ],
23 ] );
24 $this->maintenance->setOption( 'batch-size', 2 );
25 $this->assertSame(
27 (int)$this->getDb()->newSelectQueryBuilder()
28 ->select( 'COUNT(*)' )
29 ->from( 'user' )
30 ->where( [ 'user_is_temp' => 1 ] )
31 ->fetchField(),
32 'The database should have 2 users with user_is_temp set to 1 before the execute method is called.'
34 $this->assertTrue(
35 $this->maintenance->execute(),
36 'The execute method did not return true as expected.'
38 $this->assertSame(
40 (int)$this->getDb()->newSelectQueryBuilder()
41 ->select( 'COUNT(*)' )
42 ->from( 'user' )
43 ->where( [ 'user_is_temp' => 1 ] )
44 ->fetchField(),
45 'The number of users with user_is_temp set to 1 is not as expected.'
49 public function addDBData() {
50 parent::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' ],
55 ] );
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()
63 ->update( 'user' )
64 ->set( [ 'user_is_temp' => 0 ] )
65 ->where( [ 'user_name' => [ '*Unregistered 2', '~Unregistered 3', '~Unregistered 456789' ] ] )
66 ->execute();