File: FixUserRegistrationTest.php

package info (click to toggle)
mediawiki 1%3A1.43.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 417,464 kB
  • sloc: php: 1,062,949; javascript: 664,290; sql: 9,714; python: 5,458; xml: 3,489; sh: 1,131; makefile: 64
file content (71 lines) | stat: -rw-r--r-- 2,693 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php

namespace MediaWiki\Tests\Maintenance;

use FixUserRegistration;
use MediaWiki\Title\Title;
use Wikimedia\Timestamp\ConvertibleTimestamp;

/**
 * @covers \FixUserRegistration
 * @group Database
 * @author Dreamy Jazz
 */
class FixUserRegistrationTest extends MaintenanceBaseTestCase {

	protected function getMaintenanceClass() {
		return FixUserRegistration::class;
	}

	public function testExecute() {
		$userWithValidRegistration = $this->getMutableTestUser()->getUser();
		$this->getDb()->newUpdateQueryBuilder()
			->update( 'user' )
			->set( [ 'user_registration' => $this->getDb()->timestamp( '20220405060708' ) ] )
			->where( [ 'user_id' => $userWithValidRegistration->getId() ] )
			->execute();
		ConvertibleTimestamp::setFakeTime( '20230405060708' );
		$userWithNullRegistrationButNoEdits = $this->getMutableTestUser()->getUser();
		$userWithNullRegistrationAndEdits = $this->getMutableTestUser()->getUser();
		$this->getDb()->newUpdateQueryBuilder()
			->update( 'user' )
			->set( [ 'user_registration' => null ] )
			->where( [ 'user_id' => [
				$userWithNullRegistrationButNoEdits->getId(), $userWithNullRegistrationAndEdits->getId()
			] ] )
			->execute();
		// Make a testing edit for the $userWithNullRegistrationAndEdits
		ConvertibleTimestamp::setFakeTime( '20230505060708' );
		$this->editPage(
			Title::newFromText( 'Test' ), "testcontent", '',
			NS_MAIN, $userWithNullRegistrationAndEdits
		);
		ConvertibleTimestamp::setFakeTime( false );
		// Verify that the user_registration column is set up correctly for the test.
		$expectedRows = [
			[ $userWithValidRegistration->getId(), $this->getDb()->timestamp( '20220405060708' ) ],
			[ $userWithNullRegistrationButNoEdits->getId(), null ],
			[ $userWithNullRegistrationAndEdits->getId(), null ],
		];
		$this->newSelectQueryBuilder()
			->select( [ 'user_id', 'user_registration' ] )
			->from( 'user' )
			->orderBy( 'user_id' )
			->assertResultSet( $expectedRows );
		// Run the maintenance script
		$this->maintenance->execute();
		$expectedOutputRegex = '/Could not find registration for #2[\s\S]*Set registration for #3 to ' .
			preg_quote( $this->getDb()->timestamp( '20230505060708' ), '/' ) . '/';
		$this->expectOutputRegex( $expectedOutputRegex );
		$expectedRows = [
			[ $userWithValidRegistration->getId(), $this->getDb()->timestamp( '20220405060708' ) ],
			[ $userWithNullRegistrationButNoEdits->getId(), null ],
			[ $userWithNullRegistrationAndEdits->getId(), $this->getDb()->timestamp( '20230505060708' ) ],
		];
		$this->newSelectQueryBuilder()
			->select( [ 'user_id', 'user_registration' ] )
			->from( 'user' )
			->orderBy( 'user_id' )
			->assertResultSet( $expectedRows );
	}
}