2019-07-22 08:34:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group Gadgets
|
|
|
|
*/
|
|
|
|
class GadgetHooksTest extends MediaWikiIntegrationTestCase {
|
|
|
|
/**
|
|
|
|
* @var User
|
|
|
|
*/
|
|
|
|
protected $user;
|
|
|
|
|
2021-07-22 09:18:47 +00:00
|
|
|
public function setUp(): void {
|
2019-07-22 08:34:21 +00:00
|
|
|
global $wgGroupPermissions;
|
|
|
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$wgGroupPermissions['unittesters'] = [
|
|
|
|
'test' => true,
|
|
|
|
];
|
|
|
|
$this->user = $this->getTestUser( [ 'unittesters' ] )->getUser();
|
|
|
|
}
|
|
|
|
|
2021-07-22 09:18:47 +00:00
|
|
|
public function tearDown(): void {
|
2019-07-22 08:34:21 +00:00
|
|
|
GadgetRepo::setSingleton();
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers Gadget
|
|
|
|
* @covers GadgetHooks::getPreferences
|
|
|
|
* @covers GadgetRepo
|
|
|
|
* @covers MediaWikiGadgetsDefinitionRepo
|
|
|
|
*/
|
|
|
|
public function testPreferences() {
|
|
|
|
$prefs = [];
|
|
|
|
$repo = TestingAccessWrapper::newFromObject( new MediaWikiGadgetsDefinitionRepo() );
|
|
|
|
// Force usage of a MediaWikiGadgetsDefinitionRepo
|
|
|
|
GadgetRepo::setSingleton( $repo );
|
|
|
|
|
|
|
|
/** @var MediaWikiGadgetsDefinitionRepo $repo */
|
|
|
|
$gadgets = $repo->fetchStructuredList( '* foo | foo.js
|
|
|
|
==keep-section1==
|
|
|
|
* bar| bar.js
|
|
|
|
==remove-section==
|
|
|
|
* baz [rights=embezzle] |baz.js
|
|
|
|
==keep-section2==
|
|
|
|
* quux [rights=test] | quux.js' );
|
|
|
|
$this->assertGreaterThanOrEqual( 2, count( $gadgets ), "Gadget list parsed" );
|
|
|
|
|
|
|
|
$repo->definitionCache = $gadgets;
|
|
|
|
GadgetHooks::getPreferences( $this->user, $prefs );
|
|
|
|
|
2021-05-28 18:00:46 +00:00
|
|
|
$options = $prefs['gadgets']['options-messages'];
|
|
|
|
$this->assertArrayNotHasKey( 'gadget-section-remove-section', $options,
|
2019-07-22 08:34:21 +00:00
|
|
|
'Must not show empty sections' );
|
2021-05-28 18:00:46 +00:00
|
|
|
$this->assertArrayHasKey( 'gadget-section-keep-section1', $options );
|
|
|
|
$this->assertArrayHasKey( 'gadget-section-keep-section2', $options );
|
2019-07-22 08:34:21 +00:00
|
|
|
}
|
|
|
|
}
|