Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / maintenance / UserOptionsMaintenanceTest.php
blob068f808f7c3005f5f27f703fb677cc78a1a711e7
1 <?php
3 namespace MediaWiki\Tests\Maintenance;
5 use MediaWiki\User\Options\StaticUserOptionsLookup;
6 use UserOptionsMaintenance;
8 /**
9 * @covers \UserOptionsMaintenance
10 * @group Database
11 * @author Dreamy Jazz
13 class UserOptionsMaintenanceTest extends MaintenanceBaseTestCase {
15 protected function getMaintenanceClass() {
16 return UserOptionsMaintenance::class;
19 /** @dataProvider provideExecuteForFatalError */
20 public function testExecuteForFatalError( $options, $optionNameArg, $expectedOutputRegex ) {
21 foreach ( $options as $name => $value ) {
22 $this->maintenance->setOption( $name, $value );
24 $this->maintenance->setArg( 0, $optionNameArg );
25 $this->maintenance->getParameters()->setName( 'userOptions.php' );
26 $this->expectCallToFatalError();
27 $this->expectOutputRegex( $expectedOutputRegex );
28 $this->maintenance->execute();
31 public static function provideExecuteForFatalError() {
32 return [
33 '--delete-defaults with no option argument' => [
34 [ 'delete-defaults' => 1 ], null, '/Option name is required/',
36 '--usage with invalid option argument' => [ [ 'usage' => 1 ], 'invalidoption', '/Invalid user option/' ],
37 'No options provided' => [
38 [], 'option',
39 // Check that the description is outputted, as this is the start of the help output
40 '/Pass through all users and change or delete one of their options/',
45 public function testListOptions() {
46 $this->setService( 'UserOptionsLookup', new StaticUserOptionsLookup(
47 [], [ 'requireemail' => 1, 'disablemail' => 0 ]
48 ) );
49 $this->maintenance->setOption( 'list', 1 );
50 $this->maintenance->execute();
51 $this->expectOutputString( "disablemail : 0\nrequireemail: 1\n" );
54 /** @dataProvider provideShowUsageStats */
55 public function testShowUsageStats( $optionArgName, $expectedOutputString ) {
56 $testUser1 = $this->getMutableTestUser()->getUserIdentity();
57 $testUser2 = $this->getMutableTestUser()->getUserIdentity();
58 $this->setService( 'UserOptionsLookup', new StaticUserOptionsLookup(
60 $testUser1->getName() => [ 'requireemail' => 0 ],
61 $testUser2->getName() => [ 'disablemail' => 1 ],
63 [ 'requireemail' => 1, 'disablemail' => 0 ]
64 ) );
65 $this->maintenance->setOption( 'usage', 1 );
66 $this->maintenance->setArg( 0, $optionArgName );
67 $this->maintenance->execute();
68 $this->expectOutputString( $expectedOutputString );
71 public static function provideShowUsageStats() {
72 return [
73 'All options' => [
74 null,
75 "Usage for <requireemail> (default: '1'):\n 1 user(s): '0'\n\n" .
76 "Usage for <disablemail> (default: '0'):\n 1 user(s): '1'\n\n",
78 'Only the "requireemail" option' => [
79 'requireemail',
80 "Usage for <requireemail> (default: '1'):\n 1 user(s): '0'\n\n",