mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Gadgets
synced 2024-12-18 18:00:36 +00:00
6f452d11b9
Locally these tests are failing for me on master every time. In WMF CI, it seems they are passing right now, although they too would start failing as of Ib27fd34fbfe7a7. My guess is that my change there causes the service container to be initialised earlier and thus causes the modified global to no longer be seen. At the very least this should have been using setMwGlobals(), which would have also avoided the issue by ensuring a service reset, however use setGroupPermissions() since it's tailor made for this purpose, and avoids potential problems later with default groups not existing. Change-Id: I8f02ffc996d6077ca6e7433229b1ea5d8fc6ce7c
64 lines
1.7 KiB
PHP
64 lines
1.7 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Extension\Gadgets\GadgetRepo;
|
|
use MediaWiki\Extension\Gadgets\Hooks as GadgetHooks;
|
|
use MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo;
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
/**
|
|
* @group Gadgets
|
|
*/
|
|
class GadgetHooksTest extends MediaWikiIntegrationTestCase {
|
|
/**
|
|
* @var User
|
|
*/
|
|
protected $user;
|
|
|
|
public function setUp(): void {
|
|
parent::setUp();
|
|
|
|
$this->setGroupPermissions( [
|
|
'unittesters' => [
|
|
'test' => true,
|
|
],
|
|
] );
|
|
$this->user = $this->getTestUser( [ 'unittesters' ] )->getUser();
|
|
}
|
|
|
|
public function tearDown(): void {
|
|
GadgetRepo::setSingleton();
|
|
parent::tearDown();
|
|
}
|
|
|
|
/**
|
|
* @covers \MediaWiki\Extension\Gadgets\Gadget
|
|
* @covers \MediaWiki\Extension\Gadgets\Hooks::getPreferences
|
|
* @covers \MediaWiki\Extension\Gadgets\GadgetRepo
|
|
* @covers \MediaWiki\Extension\Gadgets\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 );
|
|
|
|
$this->assertArrayHasKey( 'gadget-bar', $prefs );
|
|
$this->assertArrayNotHasKey( 'gadget-baz', $prefs,
|
|
'Must not show unavailable gadgets' );
|
|
$this->assertEquals( 'gadgets/gadget-section-keep-section2', $prefs['gadget-quux']['section'] );
|
|
}
|
|
}
|