MediaWiki  1.33.0
ResourceLoaderSkinModuleTest.php
Go to the documentation of this file.
1 <?php
2 
3 use Wikimedia\TestingAccessWrapper;
4 
9 
10  use MediaWikiCoversValidator;
11 
12  public static function provideGetStyles() {
13  // phpcs:disable Generic.Files.LineLength
14  return [
15  [
16  'parent' => [],
17  'logo' => '/logo.png',
18  'expected' => [
19  'all' => [ '.mw-wiki-logo { background-image: url(/logo.png); }' ],
20  ],
21  ],
22  [
23  'parent' => [
24  'screen' => '.example {}',
25  ],
26  'logo' => '/logo.png',
27  'expected' => [
28  'screen' => [ '.example {}' ],
29  'all' => [ '.mw-wiki-logo { background-image: url(/logo.png); }' ],
30  ],
31  ],
32  [
33  'parent' => [],
34  'logo' => [
35  '1x' => '/logo.png',
36  '1.5x' => '/logo@1.5x.png',
37  '2x' => '/logo@2x.png',
38  ],
39  'expected' => [
40  'all' => [ <<<CSS
41 .mw-wiki-logo { background-image: url(/logo.png); }
42 CSS
43  ],
44  '(-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (min-resolution: 1.5dppx), (min-resolution: 144dpi)' => [ <<<CSS
45 .mw-wiki-logo { background-image: url(/logo@1.5x.png);background-size: 135px auto; }
46 CSS
47  ],
48  '(-webkit-min-device-pixel-ratio: 2), (min--moz-device-pixel-ratio: 2), (min-resolution: 2dppx), (min-resolution: 192dpi)' => [ <<<CSS
49 .mw-wiki-logo { background-image: url(/logo@2x.png);background-size: 135px auto; }
50 CSS
51  ],
52  ],
53  ],
54  [
55  'parent' => [],
56  'logo' => [
57  '1x' => '/logo.png',
58  'svg' => '/logo.svg',
59  ],
60  'expected' => [
61  'all' => [ <<<CSS
62 .mw-wiki-logo { background-image: url(/logo.png); }
63 CSS
64  , <<<CSS
65 .mw-wiki-logo { background-image: -webkit-linear-gradient(transparent, transparent), url(/logo.svg); background-image: linear-gradient(transparent, transparent), url(/logo.svg);background-size: 135px auto; }
66 CSS
67  ],
68  ],
69  ],
70  ];
71  // phpcs:enable
72  }
73 
78  public function testGetStyles( $parent, $logo, $expected ) {
79  $module = $this->getMockBuilder( ResourceLoaderSkinModule::class )
80  ->disableOriginalConstructor()
81  ->setMethods( [ 'readStyleFiles', 'getConfig', 'getLogoData' ] )
82  ->getMock();
83  $module->expects( $this->once() )->method( 'readStyleFiles' )
84  ->willReturn( $parent );
85  $module->expects( $this->once() )->method( 'getConfig' )
86  ->willReturn( new HashConfig() );
87  $module->expects( $this->once() )->method( 'getLogoData' )
88  ->willReturn( $logo );
89 
90  $ctx = $this->getMockBuilder( ResourceLoaderContext::class )
91  ->disableOriginalConstructor()->getMock();
92 
93  $this->assertEquals(
94  $expected,
95  $module->getStyles( $ctx )
96  );
97  }
98 
102  public function testIsKnownEmpty() {
103  $module = $this->getMockBuilder( ResourceLoaderSkinModule::class )
104  ->disableOriginalConstructor()->setMethods( null )->getMock();
105  $ctx = $this->getMockBuilder( ResourceLoaderContext::class )
106  ->disableOriginalConstructor()->getMock();
107 
108  $this->assertFalse( $module->isKnownEmpty( $ctx ) );
109  }
110 
115  public function testGetLogoData( $config, $expected, $baseDir = null ) {
116  if ( $baseDir ) {
117  $this->setMwGlobals( 'IP', $baseDir );
118  }
119  // Allow testing of protected method
120  $module = TestingAccessWrapper::newFromObject( new ResourceLoaderSkinModule() );
121 
122  $this->assertEquals(
123  $expected,
124  $module->getLogoData( new HashConfig( $config ) )
125  );
126  }
127 
128  public function provideGetLogoData() {
129  return [
130  'simple' => [
131  'config' => [
132  'ResourceBasePath' => '/w',
133  'Logo' => '/img/default.png',
134  'LogoHD' => false,
135  ],
136  'expected' => '/img/default.png',
137  ],
138  'default and 2x' => [
139  'config' => [
140  'ResourceBasePath' => '/w',
141  'Logo' => '/img/default.png',
142  'LogoHD' => [
143  '2x' => '/img/two-x.png',
144  ],
145  ],
146  'expected' => [
147  '1x' => '/img/default.png',
148  '2x' => '/img/two-x.png',
149  ],
150  ],
151  'default and all HiDPIs' => [
152  'config' => [
153  'ResourceBasePath' => '/w',
154  'Logo' => '/img/default.png',
155  'LogoHD' => [
156  '1.5x' => '/img/one-point-five.png',
157  '2x' => '/img/two-x.png',
158  ],
159  ],
160  'expected' => [
161  '1x' => '/img/default.png',
162  '1.5x' => '/img/one-point-five.png',
163  '2x' => '/img/two-x.png',
164  ],
165  ],
166  'default and SVG' => [
167  'config' => [
168  'ResourceBasePath' => '/w',
169  'Logo' => '/img/default.png',
170  'LogoHD' => [
171  'svg' => '/img/vector.svg',
172  ],
173  ],
174  'expected' => [
175  '1x' => '/img/default.png',
176  'svg' => '/img/vector.svg',
177  ],
178  ],
179  'everything' => [
180  'config' => [
181  'ResourceBasePath' => '/w',
182  'Logo' => '/img/default.png',
183  'LogoHD' => [
184  '1.5x' => '/img/one-point-five.png',
185  '2x' => '/img/two-x.png',
186  'svg' => '/img/vector.svg',
187  ],
188  ],
189  'expected' => [
190  '1x' => '/img/default.png',
191  'svg' => '/img/vector.svg',
192  ],
193  ],
194  'versioned url' => [
195  'config' => [
196  'ResourceBasePath' => '/w',
197  'Logo' => '/w/test.jpg',
198  'LogoHD' => false,
199  'UploadPath' => '/w/images',
200  ],
201  'expected' => '/w/test.jpg?edcf2',
202  'baseDir' => dirname( dirname( __DIR__ ) ) . '/data/media',
203  ],
204  ];
205  }
206 
213  public function testPreloadLinkHeaders( $config, $result ) {
214  $this->setMwGlobals( $config );
215  $ctx = $this->getMockBuilder( ResourceLoaderContext::class )
216  ->disableOriginalConstructor()->getMock();
217  $module = new ResourceLoaderSkinModule();
218 
219  $this->assertEquals( [ $result ], $module->getHeaders( $ctx ) );
220  }
221 
222  public function providePreloadLinks() {
223  return [
224  [
225  [
226  'wgResourceBasePath' => '/w',
227  'wgLogo' => '/img/default.png',
228  'wgLogoHD' => [
229  '1.5x' => '/img/one-point-five.png',
230  '2x' => '/img/two-x.png',
231  ],
232  ],
233  'Link: </img/default.png>;rel=preload;as=image;media=' .
234  'not all and (min-resolution: 1.5dppx),' .
235  '</img/one-point-five.png>;rel=preload;as=image;media=' .
236  '(min-resolution: 1.5dppx) and (max-resolution: 1.999999dppx),' .
237  '</img/two-x.png>;rel=preload;as=image;media=(min-resolution: 2dppx)'
238  ],
239  [
240  [
241  'wgResourceBasePath' => '/w',
242  'wgLogo' => '/img/default.png',
243  'wgLogoHD' => false,
244  ],
245  'Link: </img/default.png>;rel=preload;as=image'
246  ],
247  [
248  [
249  'wgResourceBasePath' => '/w',
250  'wgLogo' => '/img/default.png',
251  'wgLogoHD' => [
252  '2x' => '/img/two-x.png',
253  ],
254  ],
255  'Link: </img/default.png>;rel=preload;as=image;media=' .
256  'not all and (min-resolution: 2dppx),' .
257  '</img/two-x.png>;rel=preload;as=image;media=(min-resolution: 2dppx)'
258  ],
259  [
260  [
261  'wgResourceBasePath' => '/w',
262  'wgLogo' => '/img/default.png',
263  'wgLogoHD' => [
264  'svg' => '/img/vector.svg',
265  ],
266  ],
267  'Link: </img/vector.svg>;rel=preload;as=image'
268 
269  ],
270  [
271  [
272  'wgResourceBasePath' => '/w',
273  'wgLogo' => '/w/test.jpg',
274  'wgLogoHD' => false,
275  'wgUploadPath' => '/w/images',
276  'IP' => dirname( dirname( __DIR__ ) ) . '/data/media',
277  ],
278  'Link: </w/test.jpg?edcf2>;rel=preload;as=image',
279  ],
280  ];
281  }
282 }
HashConfig
A Config instance which stores all settings as a member variable.
Definition: HashConfig.php:28
ResourceLoaderSkinModuleTest\testIsKnownEmpty
testIsKnownEmpty()
ResourceLoaderSkinModule::isKnownEmpty.
Definition: ResourceLoaderSkinModuleTest.php:102
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED since 1.28! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1983
wiki
Prior to maintenance scripts were a hodgepodge of code that had no cohesion or formal method of action Beginning maintenance scripts have been cleaned up to use a unified class Directory structure How to run a script How to write your own DIRECTORY STRUCTURE The maintenance directory of a MediaWiki installation contains several all of which have unique purposes HOW TO RUN A SCRIPT Ridiculously just call php someScript php that s in the top level maintenance directory if not default wiki
Definition: maintenance.txt:1
ResourceLoaderSkinModuleTest\provideGetLogoData
provideGetLogoData()
Definition: ResourceLoaderSkinModuleTest.php:128
ResourceLoaderSkinModuleTest\testGetStyles
testGetStyles( $parent, $logo, $expected)
provideGetStyles ResourceLoaderSkinModule
Definition: ResourceLoaderSkinModuleTest.php:78
ResourceLoaderSkinModuleTest\provideGetStyles
static provideGetStyles()
Definition: ResourceLoaderSkinModuleTest.php:12
ResourceLoaderSkinModuleTest\testPreloadLinkHeaders
testPreloadLinkHeaders( $config, $result)
providePreloadLinks ResourceLoaderSkinModule::getPreloadLinks ResourceLoaderSkinModule::getLogoPreloa...
Definition: ResourceLoaderSkinModuleTest.php:213
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:709
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
ResourceLoaderSkinModuleTest
ResourceLoader.
Definition: ResourceLoaderSkinModuleTest.php:8
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
ResourceLoaderSkinModuleTest\providePreloadLinks
providePreloadLinks()
Definition: ResourceLoaderSkinModuleTest.php:222
$parent
$parent
Definition: pageupdater.txt:71
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
ResourceLoaderSkinModuleTest\testGetLogoData
testGetLogoData( $config, $expected, $baseDir=null)
provideGetLogoData ResourceLoaderSkinModule::getLogoData
Definition: ResourceLoaderSkinModuleTest.php:115
ResourceLoaderSkinModule
Definition: ResourceLoaderSkinModule.php:24