Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / maintenance / InitUserPreferenceTest.php
blob3931d68df1fae1f16345f5c2eb6bb91c618d100b
1 <?php
3 namespace MediaWiki\Tests\Maintenance;
5 use InitUserPreference;
7 /**
8 * @covers \InitUserPreference
9 * @group Database
10 * @author Dreamy Jazz
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' )
21 ->rows( [
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' ],
28 ] )
29 ->caller( __METHOD__ )
30 ->execute();
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
36 // as expected.
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__ )
45 ->assertResultSet( [
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' ],
55 ] );