3use Wikimedia\TestingAccessWrapper;
15 $g = $repo->newFromDefinition(
$line,
'misc' );
16 $this->assertInstanceOf( Gadget::class, $g );
21 $module = TestingAccessWrapper::newFromObject(
33 $this->assertFalse( $repo->newFromDefinition(
'',
'misc' ) );
34 $this->assertFalse( $repo->newFromDefinition(
'<foo|bar>',
'misc' ) );
42 $g = $this->
create(
'* foo bar| foo.css|foo.js|foo.bar' );
43 $this->assertEquals(
'foo_bar', $g->getName() );
45 $this->assertEquals( [
'MediaWiki:Gadget-foo.js' ], $g->getScripts() );
46 $this->assertEquals( [
'MediaWiki:Gadget-foo.css' ], $g->getStyles() );
47 $this->assertEquals( [
'MediaWiki:Gadget-foo.js',
'MediaWiki:Gadget-foo.css' ],
48 $g->getScriptsAndStyles() );
49 $this->assertEquals( [
'MediaWiki:Gadget-foo.js' ], $g->getLegacyScripts() );
50 $this->assertFalse( $g->supportsResourceLoader() );
51 $this->assertTrue( $g->hasModule() );
60 $g = $this->
create(
'*foo [ResourceLoader]|foo.js|foo.css' );
61 $this->assertEquals(
'foo', $g->getName() );
62 $this->assertTrue( $g->supportsResourceLoader() );
63 $this->assertEquals( 0, count( $g->getLegacyScripts() ) );
71 $user = $this->getMockBuilder( User::class )
72 ->setMethods( [
'isAllowedAll' ] )
74 $user->method(
'isAllowedAll' )
76 function ( ...$rights ) {
77 return array_diff( $rights, [
'test' ] ) === [];
82 $gUnset = $this->
create(
'*foo[ResourceLoader]|foo.js' );
83 $gAllowed = $this->
create(
'*bar[ResourceLoader|rights=test]|bar.js' );
84 $gNotAllowed = $this->
create(
'*baz[ResourceLoader|rights=nope]|baz.js' );
85 $this->assertTrue( $gUnset->isAllowed( $user ) );
86 $this->assertTrue( $gAllowed->isAllowed( $user ) );
87 $this->assertFalse( $gNotAllowed->isAllowed( $user ) );
95 $gUnset = $this->
create(
'*foo[ResourceLoader]|foo.js' );
96 $gSkinSupported = $this->
create(
'*bar[ResourceLoader|skins=fallback]|bar.js' );
97 $gSkinNotSupported = $this->
create(
'*baz[ResourceLoader|skins=bar]|baz.js' );
99 $this->assertTrue( $gUnset->isSkinSupported( $skin ) );
100 $this->assertTrue( $gSkinSupported->isSkinSupported( $skin ) );
101 $this->assertFalse( $gSkinNotSupported->isSkinSupported( $skin ) );
109 $g = $this->
create(
'* foo[ResourceLoader|dependencies=jquery.ui]|bar.js' );
110 $this->assertEquals( [
'MediaWiki:Gadget-bar.js' ], $g->getScripts() );
111 $this->assertTrue( $g->supportsResourceLoader() );
112 $this->assertEquals( [
'jquery.ui' ], $g->getDependencies() );
119 '* foo[ResourceLoader]|bar.css|bar.js',
121 ResourceLoaderModule::LOAD_GENERAL,
124 'Default (styles only)',
125 '* foo[ResourceLoader]|bar.css',
127 ResourceLoaderModule::LOAD_STYLES,
130 'Default (scripts only)',
131 '* foo[ResourceLoader]|bar.js',
133 ResourceLoaderModule::LOAD_GENERAL,
136 'Default (styles only with dependencies)',
137 '* foo[ResourceLoader|dependencies=jquery.ui]|bar.css',
139 ResourceLoaderModule::LOAD_GENERAL,
142 'Styles type (mixed)',
143 '* foo[ResourceLoader|type=styles]|bar.css|bar.js',
145 ResourceLoaderModule::LOAD_STYLES,
148 'Styles type (styles only)',
149 '* foo[ResourceLoader|type=styles]|bar.css',
151 ResourceLoaderModule::LOAD_STYLES,
154 'Styles type (scripts only)',
155 '* foo[ResourceLoader|type=styles]|bar.js',
157 ResourceLoaderModule::LOAD_STYLES,
160 'General type (mixed)',
161 '* foo[ResourceLoader|type=general]|bar.css|bar.js',
163 ResourceLoaderModule::LOAD_GENERAL,
166 'General type (styles only)',
167 '* foo[ResourceLoader|type=general]|bar.css',
169 ResourceLoaderModule::LOAD_GENERAL,
172 'General type (scripts only)',
173 '* foo[ResourceLoader|type=general]|bar.js',
175 ResourceLoaderModule::LOAD_GENERAL,
186 public function testType( $message, $definition, $gType, $mType ) {
187 $g = $this->
create( $definition );
188 $this->assertEquals( $gType, $g->getType(),
"Gadget: $message" );
189 $this->assertEquals( $mType, $this->
getModule( $g )->getType(),
"Module: $message" );
197 $g = $this->
create(
'* foo[hidden]|bar.js' );
198 $this->assertTrue( $g->isHidden() );
200 $g = $this->
create(
'* foo[ResourceLoader|hidden]|bar.js' );
201 $this->assertTrue( $g->isHidden() );
203 $g = $this->
create(
'* foo[ResourceLoader]|bar.js' );
204 $this->assertFalse( $g->isHidden() );
Class representing a list of resources for one gadget, basically a wrapper around the Gadget class.
testDependencies()
@covers MediaWikiGadgetsDefinitionRepo::newFromDefinition @covers Gadget::getDependencies
testType( $message, $definition, $gType, $mType)
@dataProvider provideGetType @covers MediaWikiGadgetsDefinitionRepo::newFromDefinition @covers Gadget...
testInvalidLines()
@covers MediaWikiGadgetsDefinitionRepo::newFromDefinition
testIsAllowed()
@covers MediaWikiGadgetsDefinitionRepo::newFromDefinition @covers Gadget::isAllowed
testRLtag()
@covers MediaWikiGadgetsDefinitionRepo::newFromDefinition @covers Gadget::supportsResourceLoader @cov...
testSkinsTag()
@covers MediaWikiGadgetsDefinitionRepo::newFromDefinition @covers Gadget::isSkinSupported
testSimpleCases()
@covers MediaWikiGadgetsDefinitionRepo::newFromDefinition @covers Gadget
testIsHidden()
@covers MediaWikiGadgetsDefinitionRepo::newFromDefinition @covers 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,...
isAllowed( $action='')
Internal mechanics of testing a permission.