3use Wikimedia\TestingAccessWrapper;
22 $this->user = $this->
getTestUser( [
'unittesters' ] )->getUser();
36 $g = $repo->newFromDefinition(
$line,
'misc' );
37 $this->assertInstanceOf( Gadget::class, $g );
42 $module = TestingAccessWrapper::newFromObject(
54 $this->assertFalse( $repo->newFromDefinition(
'',
'misc' ) );
55 $this->assertFalse( $repo->newFromDefinition(
'<foo|bar>',
'misc' ) );
63 $g = $this->
create(
'* foo bar| foo.css|foo.js|foo.bar' );
64 $this->assertEquals(
'foo_bar', $g->getName() );
66 $this->assertEquals( [
'MediaWiki:Gadget-foo.js' ], $g->getScripts() );
67 $this->assertEquals( [
'MediaWiki:Gadget-foo.css' ], $g->getStyles() );
68 $this->assertEquals( [
'MediaWiki:Gadget-foo.js',
'MediaWiki:Gadget-foo.css' ],
69 $g->getScriptsAndStyles() );
70 $this->assertEquals( [
'MediaWiki:Gadget-foo.js' ], $g->getLegacyScripts() );
71 $this->assertFalse( $g->supportsResourceLoader() );
72 $this->assertTrue( $g->hasModule() );
81 $g = $this->
create(
'*foo [ResourceLoader]|foo.js|foo.css' );
82 $this->assertEquals(
'foo', $g->getName() );
83 $this->assertTrue( $g->supportsResourceLoader() );
84 $this->assertEquals( 0, count( $g->getLegacyScripts() ) );
92 $gUnset = $this->
create(
'*foo[ResourceLoader]|foo.js' );
93 $gAllowed = $this->
create(
'*bar[ResourceLoader|rights=test]|bar.js' );
94 $gNotAllowed = $this->
create(
'*baz[ResourceLoader|rights=nope]|baz.js' );
95 $this->assertTrue( $gUnset->isAllowed( $this->user ) );
96 $this->assertTrue( $gAllowed->isAllowed( $this->user ) );
97 $this->assertFalse( $gNotAllowed->isAllowed( $this->user ) );
105 $gUnset = $this->
create(
'*foo[ResourceLoader]|foo.js' );
106 $gSkinSupported = $this->
create(
'*bar[ResourceLoader|skins=fallback]|bar.js' );
107 $gSkinNotSupported = $this->
create(
'*baz[ResourceLoader|skins=bar]|baz.js' );
109 $this->assertTrue( $gUnset->isSkinSupported( $skin ) );
110 $this->assertTrue( $gSkinSupported->isSkinSupported( $skin ) );
111 $this->assertFalse( $gSkinNotSupported->isSkinSupported( $skin ) );
119 $g = $this->
create(
'* foo[ResourceLoader|dependencies=jquery.ui]|bar.js' );
120 $this->assertEquals( [
'MediaWiki:Gadget-bar.js' ], $g->getScripts() );
121 $this->assertTrue( $g->supportsResourceLoader() );
122 $this->assertEquals( [
'jquery.ui' ], $g->getDependencies() );
129 '* foo[ResourceLoader]|bar.css|bar.js',
134 'Default (styles only)',
135 '* foo[ResourceLoader]|bar.css',
140 'Default (scripts only)',
141 '* foo[ResourceLoader]|bar.js',
146 'Default (styles only with dependencies)',
147 '* foo[ResourceLoader|dependencies=jquery.ui]|bar.css',
152 'Styles type (mixed)',
153 '* foo[ResourceLoader|type=styles]|bar.css|bar.js',
158 'Styles type (styles only)',
159 '* foo[ResourceLoader|type=styles]|bar.css',
164 'Styles type (scripts only)',
165 '* foo[ResourceLoader|type=styles]|bar.js',
170 'General type (mixed)',
171 '* foo[ResourceLoader|type=general]|bar.css|bar.js',
176 'General type (styles only)',
177 '* foo[ResourceLoader|type=general]|bar.css',
182 'General type (scripts only)',
183 '* foo[ResourceLoader|type=general]|bar.js',
196 public function testType( $message, $definition, $gType, $mType ) {
197 $g = $this->
create( $definition );
198 $this->assertEquals( $gType, $g->getType(),
"Gadget: $message" );
199 $this->assertEquals( $mType, $this->
getModule( $g )->getType(),
"Module: $message" );
207 $g = $this->
create(
'* foo[hidden]|bar.js' );
208 $this->assertTrue( $g->isHidden() );
210 $g = $this->
create(
'* foo[ResourceLoader|hidden]|bar.js' );
211 $this->assertTrue( $g->isHidden() );
213 $g = $this->
create(
'* foo[ResourceLoader]|bar.js' );
214 $this->assertFalse( $g->isHidden() );
229 $gadgets = $repo->fetchStructuredList(
'* foo | foo.js
233* baz [rights=embezzle] |baz.js
235* quux [rights=test] | quux.js' );
236 $this->assertGreaterThanOrEqual( 2, count( $gadgets ),
"Gadget list parsed" );
238 $repo->definitionCache = $gadgets;
240 'GetPrefences hook should return true' );
242 $options = $prefs[
'gadgets'][
'options'];
243 $this->assertArrayNotHasKey(
'⧼gadget-section-remove-section⧽',
$options,
244 'Must not show empty sections' );
245 $this->assertArrayHasKey(
'⧼gadget-section-keep-section1⧽',
$options );
246 $this->assertArrayHasKey(
'⧼gadget-section-keep-section2⧽',
$options );
$wgGroupPermissions['sysop']['replacetext']
static getPreferences( $user, &$preferences)
GetPreferences hook handler.
static setSingleton( $repo=null)
Should only be used by unit tests.
Class representing a list of resources for one gadget, basically a wrapper around the Gadget class.
testDependencies()
MediaWikiGadgetsDefinitionRepo::newFromDefinition Gadget::getDependencies.
testPreferences()
Gadget GadgetHooks::getPreferences GadgetRepo MediaWikiGadgetsDefinitionRepo.
testType( $message, $definition, $gType, $mType)
provideGetType MediaWikiGadgetsDefinitionRepo::newFromDefinition Gadget::getType GadgetResourceLoader...
testInvalidLines()
MediaWikiGadgetsDefinitionRepo::newFromDefinition.
testRLtag()
MediaWikiGadgetsDefinitionRepo::newFromDefinition Gadget::supportsResourceLoader Gadget::getLegacyScr...
testSkinsTag()
MediaWikiGadgetsDefinitionRepo::newFromDefinition Gadget::isSkinSupported.
testSimpleCases()
MediaWikiGadgetsDefinitionRepo::newFromDefinition Gadget.
testisAllowed()
MediaWikiGadgetsDefinitionRepo::newFromDefinition Gadget::isAllowed.
testIsHidden()
MediaWikiGadgetsDefinitionRepo::newFromDefinition Gadget::isHidden.
static getModuleName( $id)
SkinTemplate class for the fallback skin.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options