MediaWiki  1.34.0
GadgetHooksTest.php
Go to the documentation of this file.
1 <?php
2 
3 use Wikimedia\TestingAccessWrapper;
4 
8 class GadgetHooksTest extends MediaWikiIntegrationTestCase {
12  protected $user;
13 
14  public function setUp() {
15  global $wgGroupPermissions;
16 
17  parent::setUp();
18 
19  $wgGroupPermissions['unittesters'] = [
20  'test' => true,
21  ];
22  $this->user = $this->getTestUser( [ 'unittesters' ] )->getUser();
23  }
24 
25  public function tearDown() {
27  parent::tearDown();
28  }
29 
36  public function testPreferences() {
37  $prefs = [];
38  $repo = TestingAccessWrapper::newFromObject( new MediaWikiGadgetsDefinitionRepo() );
39  // Force usage of a MediaWikiGadgetsDefinitionRepo
40  GadgetRepo::setSingleton( $repo );
41 
43  $gadgets = $repo->fetchStructuredList( '* foo | foo.js
44 ==keep-section1==
45 * bar| bar.js
46 ==remove-section==
47 * baz [rights=embezzle] |baz.js
48 ==keep-section2==
49 * quux [rights=test] | quux.js' );
50  $this->assertGreaterThanOrEqual( 2, count( $gadgets ), "Gadget list parsed" );
51 
52  $repo->definitionCache = $gadgets;
53  GadgetHooks::getPreferences( $this->user, $prefs );
54 
55  $options = $prefs['gadgets']['options'];
56  $this->assertArrayNotHasKey( '⧼gadget-section-remove-section⧽', $options,
57  'Must not show empty sections' );
58  $this->assertArrayHasKey( '⧼gadget-section-keep-section1⧽', $options );
59  $this->assertArrayHasKey( '⧼gadget-section-keep-section2⧽', $options );
60  }
61 }
MediaWikiGadgetsDefinitionRepo
Gadgets repo powered by MediaWiki:Gadgets-definition.
Definition: MediaWikiGadgetsDefinitionRepo.php:10
GadgetHooksTest\tearDown
tearDown()
Definition: GadgetHooksTest.php:25
GadgetHooksTest\$user
User $user
Definition: GadgetHooksTest.php:12
GadgetHooksTest\testPreferences
testPreferences()
@covers Gadget @covers GadgetHooks::getPreferences @covers GadgetRepo @covers MediaWikiGadgetsDefinit...
Definition: GadgetHooksTest.php:36
GadgetHooksTest\setUp
setUp()
Definition: GadgetHooksTest.php:14
GadgetHooksTest
@group Gadgets
Definition: GadgetHooksTest.php:8
GadgetHooks\getPreferences
static getPreferences(User $user, array &$preferences)
GetPreferences hook handler.
Definition: GadgetHooks.php:66
MediaWikiGadgetsDefinitionRepo\fetchStructuredList
fetchStructuredList( $forceNewText=null)
Fetch list of gadgets and returns it as associative array of sections with gadgets e....
Definition: MediaWikiGadgetsDefinitionRepo.php:135
GadgetRepo\setSingleton
static setSingleton( $repo=null)
Should only be used by unit tests.
Definition: GadgetRepo.php:101
$wgGroupPermissions
$wgGroupPermissions['sysop']['replacetext']
Definition: ReplaceText.php:56
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:51