mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Gadgets
synced 2024-12-23 20:22:55 +00:00
b504a6f496
Bug: T271014 Change-Id: I50d42df04038d1214fd9835c3d3b0f602037ac62
64 lines
1.8 KiB
PHP
64 lines
1.8 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::onGetPreferences
|
|
* @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->definitions = $gadgets;
|
|
( new GadgetHooks() )->onGetPreferences( $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'] );
|
|
}
|
|
}
|