MediaWiki REL1_34
GadgetHooksTest.php
Go to the documentation of this file.
1<?php
2
3use Wikimedia\TestingAccessWrapper;
4
8class GadgetHooksTest extends MediaWikiIntegrationTestCase {
12 protected $user;
13
14 public function setUp() {
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
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}
$wgGroupPermissions['sysop']['replacetext']
@group Gadgets
testPreferences()
@covers Gadget @covers GadgetHooks::getPreferences @covers GadgetRepo @covers MediaWikiGadgetsDefinit...
static getPreferences(User $user, array &$preferences)
GetPreferences hook handler.
static setSingleton( $repo=null)
Should only be used by unit tests.
Gadgets repo powered by MediaWiki:Gadgets-definition.
fetchStructuredList( $forceNewText=null)
Fetch list of gadgets and returns it as associative array of sections with gadgets e....
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:51