Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / maintenance / FixUserRegistrationTest.php
blob2f60ed152afa5ee0ed021fa7c6f28561d5cf87bc
1 <?php
3 namespace MediaWiki\Tests\Maintenance;
5 use FixUserRegistration;
6 use MediaWiki\Title\Title;
7 use Wikimedia\Timestamp\ConvertibleTimestamp;
9 /**
10 * @covers \FixUserRegistration
11 * @group Database
12 * @author Dreamy Jazz
14 class FixUserRegistrationTest extends MaintenanceBaseTestCase {
16 protected function getMaintenanceClass() {
17 return FixUserRegistration::class;
20 public function testExecute() {
21 $userWithValidRegistration = $this->getMutableTestUser()->getUser();
22 $this->getDb()->newUpdateQueryBuilder()
23 ->update( 'user' )
24 ->set( [ 'user_registration' => $this->getDb()->timestamp( '20220405060708' ) ] )
25 ->where( [ 'user_id' => $userWithValidRegistration->getId() ] )
26 ->execute();
27 ConvertibleTimestamp::setFakeTime( '20230405060708' );
28 $userWithNullRegistrationButNoEdits = $this->getMutableTestUser()->getUser();
29 $userWithNullRegistrationAndEdits = $this->getMutableTestUser()->getUser();
30 $this->getDb()->newUpdateQueryBuilder()
31 ->update( 'user' )
32 ->set( [ 'user_registration' => null ] )
33 ->where( [ 'user_id' => [
34 $userWithNullRegistrationButNoEdits->getId(), $userWithNullRegistrationAndEdits->getId()
35 ] ] )
36 ->execute();
37 // Make a testing edit for the $userWithNullRegistrationAndEdits
38 ConvertibleTimestamp::setFakeTime( '20230505060708' );
39 $this->editPage(
40 Title::newFromText( 'Test' ), "testcontent", '',
41 NS_MAIN, $userWithNullRegistrationAndEdits
43 ConvertibleTimestamp::setFakeTime( false );
44 // Verify that the user_registration column is set up correctly for the test.
45 $expectedRows = [
46 [ $userWithValidRegistration->getId(), $this->getDb()->timestamp( '20220405060708' ) ],
47 [ $userWithNullRegistrationButNoEdits->getId(), null ],
48 [ $userWithNullRegistrationAndEdits->getId(), null ],
50 $this->newSelectQueryBuilder()
51 ->select( [ 'user_id', 'user_registration' ] )
52 ->from( 'user' )
53 ->orderBy( 'user_id' )
54 ->assertResultSet( $expectedRows );
55 // Run the maintenance script
56 $this->maintenance->execute();
57 $expectedOutputRegex = '/Could not find registration for #2[\s\S]*Set registration for #3 to ' .
58 preg_quote( $this->getDb()->timestamp( '20230505060708' ), '/' ) . '/';
59 $this->expectOutputRegex( $expectedOutputRegex );
60 $expectedRows = [
61 [ $userWithValidRegistration->getId(), $this->getDb()->timestamp( '20220405060708' ) ],
62 [ $userWithNullRegistrationButNoEdits->getId(), null ],
63 [ $userWithNullRegistrationAndEdits->getId(), $this->getDb()->timestamp( '20230505060708' ) ],
65 $this->newSelectQueryBuilder()
66 ->select( [ 'user_id', 'user_registration' ] )
67 ->from( 'user' )
68 ->orderBy( 'user_id' )
69 ->assertResultSet( $expectedRows );