mediawiki-extensions-Gadgets/tests/phpunit/integration/GadgetHooksTest.php
Umherirrender e9f6ea3492 Reduce message parse in GadgetHooks::getPreferences (second time)
Multiselect can build by message keys only and allows to parse them.

This reverts fix for T32182, there is no way to handle the dir on each
item/checkbox at the moment

Reintroduce Iccd6202c443bd699aa3a911c8ba36a2b7bcdcfed (reverted by
I1cf3c7c61e9e90567587350639590691add1af34)

Bug: T58633
Bug: T278650
Depends-On: I8f52f21ae2641ddcad1aa85ce6bf14de1a09ab4b
Change-Id: If71008195f58faff9f302f7ea2bf9dbb1a527844
2021-05-28 20:52:58 +02:00

62 lines
1.5 KiB
PHP

<?php
use Wikimedia\TestingAccessWrapper;
/**
* @group Gadgets
*/
class GadgetHooksTest extends MediaWikiIntegrationTestCase {
/**
* @var User
*/
protected $user;
public function setUp() : void {
global $wgGroupPermissions;
parent::setUp();
$wgGroupPermissions['unittesters'] = [
'test' => true,
];
$this->user = $this->getTestUser( [ 'unittesters' ] )->getUser();
}
public function tearDown() : void {
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 );
$options = $prefs['gadgets']['options-messages'];
$this->assertArrayNotHasKey( 'gadget-section-remove-section', $options,
'Must not show empty sections' );
$this->assertArrayHasKey( 'gadget-section-keep-section1', $options );
$this->assertArrayHasKey( 'gadget-section-keep-section2', $options );
}
}