mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Gadgets
synced 2024-12-18 18:00:36 +00:00
ea786ce9dc
Previously attempted in82281d82d0
, reverted in7c4ac597e2
. This gives each section and each gadget's entry an `id` attribute, which can be used for linking, as requested in T126962. Existing user options still match the new preferences. It also probably makes future improvements easier. No one understands multiselects with subsections. Bug: T126962 Change-Id: Ie96fd94c994d05ab8507920fa560c7ed9c1f9b69
61 lines
1.5 KiB
PHP
61 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 );
|
|
|
|
$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'] );
|
|
}
|
|
}
|