3 namespace MediaWiki\Tests\Maintenance
;
5 use InitUserPreference
;
8 * @covers \InitUserPreference
12 class InitUserPreferenceTest
extends MaintenanceBaseTestCase
{
13 public function getMaintenanceClass() {
14 return InitUserPreference
::class;
17 public function testExecute() {
18 // Insert some testing data
19 $this->getDb()->newInsertQueryBuilder()
20 ->insertInto( 'user_properties' )
22 [ 'up_user' => 1, 'up_property' => 'preference-one', 'up_value' => 'first-value' ],
23 [ 'up_user' => 2, 'up_property' => 'preference-one', 'up_value' => 'second-value' ],
24 [ 'up_user' => 3, 'up_property' => 'preference-one', 'up_value' => '1' ],
25 [ 'up_user' => 6, 'up_property' => 'preference-one', 'up_value' => '0' ],
26 [ 'up_user' => 10, 'up_property' => 'preference-one', 'up_value' => null ],
27 [ 'up_user' => 5, 'up_property' => 'preference-two', 'up_value' => 'ignored' ],
29 ->caller( __METHOD__
)
31 // Run the maintenance script to copy the values from preference-one to preference-one-new
32 $this->maintenance
->setOption( 'target', 'preference-one-new' );
33 $this->maintenance
->setOption( 'source', 'preference-one' );
34 $this->maintenance
->execute();
35 // Check that the maintenance script executed as intended by asserting that the user_properties table is
37 $this->expectOutputString(
38 "Initializing 'preference-one-new' based on the value of 'preference-one'\n" .
39 "Processed 3 user(s)\nFinished!\n"
41 $this->newSelectQueryBuilder()
42 ->select( [ 'up_property', 'up_user', 'up_value' ] )
43 ->from( 'user_properties' )
44 ->caller( __METHOD__
)
46 [ 'preference-one', 1, 'first-value' ],
47 [ 'preference-one', 2, 'second-value' ],
48 [ 'preference-one', 3, '1' ],
49 [ 'preference-one', 6, '0' ],
50 [ 'preference-one', 10, null ],
51 [ 'preference-one-new', 1, 'first-value' ],
52 [ 'preference-one-new', 2, 'second-value' ],
53 [ 'preference-one-new', 3, '1' ],
54 [ 'preference-two', 5, 'ignored' ],