3use Wikimedia\TestingAccessWrapper;
21 $g = $repo->newFromDefinition(
$line,
'misc' );
22 $this->assertInstanceOf( Gadget::class, $g );
27 $module = TestingAccessWrapper::newFromObject(
39 $this->assertFalse( $repo->newFromDefinition(
'',
'misc' ) );
40 $this->assertFalse( $repo->newFromDefinition(
'<foo|bar>',
'misc' ) );
50 $g = $this->
create(
'* foo bar| foo.css|foo.js|foo.bar' );
51 $this->assertEquals(
'foo_bar', $g->getName() );
53 $this->assertEquals( [
'MediaWiki:Gadget-foo.js' ], $g->getScripts() );
54 $this->assertEquals( [
'MediaWiki:Gadget-foo.css' ], $g->getStyles() );
55 $this->assertEquals( [
'MediaWiki:Gadget-foo.js',
'MediaWiki:Gadget-foo.css' ],
56 $g->getScriptsAndStyles() );
57 $this->assertEquals( [
'MediaWiki:Gadget-foo.js' ], $g->getLegacyScripts() );
58 $this->assertFalse( $g->supportsResourceLoader() );
59 $this->assertTrue( $g->hasModule() );
68 $g = $this->
create(
'*foo [ResourceLoader]|foo.js|foo.css' );
69 $this->assertEquals(
'foo', $g->getName() );
70 $this->assertTrue( $g->supportsResourceLoader() );
71 $this->assertEquals( 0, count( $g->getLegacyScripts() ) );
79 $g = $this->
create(
'* foo[ResourceLoader|dependencies=jquery.ui]|bar.js' );
80 $this->assertEquals( [
'MediaWiki:Gadget-bar.js' ], $g->getScripts() );
81 $this->assertTrue( $g->supportsResourceLoader() );
82 $this->assertEquals( [
'jquery.ui' ], $g->getDependencies() );
89 '* foo[ResourceLoader]|bar.css|bar.js',
94 'Default (styles only)',
95 '* foo[ResourceLoader]|bar.css',
100 'Default (scripts only)',
101 '* foo[ResourceLoader]|bar.js',
106 'Default (styles only with dependencies)',
107 '* foo[ResourceLoader|dependencies=jquery.ui]|bar.css',
112 'Styles type (mixed)',
113 '* foo[ResourceLoader|type=styles]|bar.css|bar.js',
118 'Styles type (styles only)',
119 '* foo[ResourceLoader|type=styles]|bar.css',
124 'Styles type (scripts only)',
125 '* foo[ResourceLoader|type=styles]|bar.js',
130 'General type (mixed)',
131 '* foo[ResourceLoader|type=general]|bar.css|bar.js',
136 'General type (styles only)',
137 '* foo[ResourceLoader|type=general]|bar.css',
142 'General type (scripts only)',
143 '* foo[ResourceLoader|type=general]|bar.js',
156 public function testType( $message, $definition, $gType, $mType ) {
157 $g = $this->
create( $definition );
158 $this->assertEquals( $gType, $g->getType(),
"Gadget: $message" );
159 $this->assertEquals( $mType, $this->
getModule( $g )->getType(),
"Module: $message" );
167 $g = $this->
create(
'* foo[hidden]|bar.js' );
168 $this->assertTrue( $g->isHidden() );
170 $g = $this->
create(
'* foo[ResourceLoader|hidden]|bar.js' );
171 $this->assertTrue( $g->isHidden() );
173 $g = $this->
create(
'* foo[ResourceLoader]|bar.js' );
174 $this->assertFalse( $g->isHidden() );
187 $gadgets = $repo->fetchStructuredList(
'* foo | foo.js
191* baz [rights=embezzle] |baz.js
193* quux [rights=read] | quux.js' );
194 $this->assertGreaterThanOrEqual( 2, count( $gadgets ),
"Gadget list parsed" );
196 $repo->definitionCache = $gadgets;
198 'GetPrefences hook should return true' );
200 $options = $prefs[
'gadgets'][
'options'];
201 $this->assertArrayNotHasKey(
'⧼gadget-section-remove-section⧽',
$options,
202 'Must not show empty sections' );
203 $this->assertArrayHasKey(
'⧼gadget-section-keep-section1⧽',
$options );
204 $this->assertArrayHasKey(
'⧼gadget-section-keep-section2⧽',
$options );
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()
MediaWikiGadgetsDefinitionRepo::fetchStructuredList GadgetHooks::getPreferences.
testType( $message, $definition, $gType, $mType)
provideGetType MediaWikiGadgetsDefinitionRepo::newFromDefinition Gadget::getType GadgetResourceLoader...
testInvalidLines()
MediaWikiGadgetsDefinitionRepo::newFromDefinition.
testRLtag()
MediaWikiGadgetsDefinitionRepo::newFromDefinition Gadget::supportsResourceLoader Gadget::getLegacyScr...
testSimpleCases()
MediaWikiGadgetsDefinitionRepo::newFromDefinition Gadget::__construct Gadget::getName Gadget::getModu...
testIsHidden()
MediaWikiGadgetsDefinitionRepo::newFromDefinition Gadget::isHidden.
static getModuleName( $id)
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