3 namespace MediaWiki\Tests\Maintenance
;
5 use FixUserRegistration
;
6 use MediaWiki\Title\Title
;
7 use Wikimedia\Timestamp\ConvertibleTimestamp
;
10 * @covers \FixUserRegistration
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()
24 ->set( [ 'user_registration' => $this->getDb()->timestamp( '20220405060708' ) ] )
25 ->where( [ 'user_id' => $userWithValidRegistration->getId() ] )
27 ConvertibleTimestamp
::setFakeTime( '20230405060708' );
28 $userWithNullRegistrationButNoEdits = $this->getMutableTestUser()->getUser();
29 $userWithNullRegistrationAndEdits = $this->getMutableTestUser()->getUser();
30 $this->getDb()->newUpdateQueryBuilder()
32 ->set( [ 'user_registration' => null ] )
33 ->where( [ 'user_id' => [
34 $userWithNullRegistrationButNoEdits->getId(), $userWithNullRegistrationAndEdits->getId()
37 // Make a testing edit for the $userWithNullRegistrationAndEdits
38 ConvertibleTimestamp
::setFakeTime( '20230505060708' );
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.
46 [ $userWithValidRegistration->getId(), $this->getDb()->timestamp( '20220405060708' ) ],
47 [ $userWithNullRegistrationButNoEdits->getId(), null ],
48 [ $userWithNullRegistrationAndEdits->getId(), null ],
50 $this->newSelectQueryBuilder()
51 ->select( [ 'user_id', 'user_registration' ] )
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 );
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' ] )
68 ->orderBy( 'user_id' )
69 ->assertResultSet( $expectedRows );