3use Wikimedia\TestingAccessWrapper;
16 $g = $repo->newFromDefinition(
$line,
'misc' );
17 $this->assertInstanceOf(
'Gadget', $g );
22 $module = TestingAccessWrapper::newFromObject(
31 $this->assertFalse( $repo->newFromDefinition(
'',
'misc' ) );
32 $this->assertFalse( $repo->newFromDefinition(
'<foo|bar>',
'misc' ) );
36 $g = $this->
create(
'* foo bar| foo.css|foo.js|foo.bar' );
37 $this->assertEquals(
'foo_bar', $g->getName() );
39 $this->assertEquals( [
'MediaWiki:Gadget-foo.js' ], $g->getScripts() );
40 $this->assertEquals( [
'MediaWiki:Gadget-foo.css' ], $g->getStyles() );
41 $this->assertEquals( [
'MediaWiki:Gadget-foo.js',
'MediaWiki:Gadget-foo.css' ],
42 $g->getScriptsAndStyles() );
43 $this->assertEquals( [
'MediaWiki:Gadget-foo.js' ], $g->getLegacyScripts() );
44 $this->assertFalse( $g->supportsResourceLoader() );
45 $this->assertTrue( $g->hasModule() );
49 $g = $this->
create(
'*foo [ResourceLoader]|foo.js|foo.css' );
50 $this->assertEquals(
'foo', $g->getName() );
51 $this->assertTrue( $g->supportsResourceLoader() );
52 $this->assertEquals( 0, count( $g->getLegacyScripts() ) );
56 $g = $this->
create(
'* foo[ResourceLoader|dependencies=jquery.ui]|bar.js' );
57 $this->assertEquals( [
'MediaWiki:Gadget-bar.js' ], $g->getScripts() );
58 $this->assertTrue( $g->supportsResourceLoader() );
59 $this->assertEquals( [
'jquery.ui' ], $g->getDependencies() );
66 '* foo[ResourceLoader]|bar.css|bar.js',
71 'Default (styles only)',
72 '* foo[ResourceLoader]|bar.css',
77 'Default (scripts only)',
78 '* foo[ResourceLoader]|bar.js',
83 'Default (styles only with dependencies)',
84 '* foo[ResourceLoader|dependencies=jquery.ui]|bar.css',
89 'Styles type (mixed)',
90 '* foo[ResourceLoader|type=styles]|bar.css|bar.js',
95 'Styles type (styles only)',
96 '* foo[ResourceLoader|type=styles]|bar.css',
101 'Styles type (scripts only)',
102 '* foo[ResourceLoader|type=styles]|bar.js',
107 'General type (mixed)',
108 '* foo[ResourceLoader|type=general]|bar.css|bar.js',
113 'General type (styles only)',
114 '* foo[ResourceLoader|type=general]|bar.css',
119 'General type (scripts only)',
120 '* foo[ResourceLoader|type=general]|bar.js',
130 public function testType( $message, $definition, $gType, $mType ) {
131 $g = $this->
create( $definition );
132 $this->assertEquals( $gType, $g->getType(),
"Gadget: $message" );
133 $this->assertEquals( $mType, $this->
getModule( $g )->getType(),
"Module: $message" );
137 $g = $this->
create(
'* foo[hidden]|bar.js' );
138 $this->assertTrue( $g->isHidden() );
140 $g = $this->
create(
'* foo[ResourceLoader|hidden]|bar.js' );
141 $this->assertTrue( $g->isHidden() );
143 $g = $this->
create(
'* foo[ResourceLoader]|bar.js' );
144 $this->assertFalse( $g->isHidden() );
153 $gadgets = $repo->fetchStructuredList(
'* foo | foo.js
157* baz [rights=embezzle] |baz.js
159* quux [rights=read] | quux.js' );
160 $this->assertGreaterThanOrEqual( 2, count( $gadgets ),
"Gadget list parsed" );
162 $repo->definitionCache = $gadgets;
164 'GetPrefences hook should return true' );
166 $options = $prefs[
'gadgets'][
'options'];
167 $this->assertArrayNotHasKey(
'⧼gadget-section-remove-section⧽',
$options,
168 'Must not show empty sections' );
169 $this->assertArrayHasKey(
'⧼gadget-section-keep-section1⧽',
$options );
170 $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.
static getModuleName( $id)
testType( $message, $definition, $gType, $mType)
provideGetType
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