MediaWiki  REL1_31
ResourceLoaderSkinModuleTest.php
Go to the documentation of this file.
1 <?php
2 
6 class ResourceLoaderSkinModuleTest extends PHPUnit\Framework\TestCase {
7 
8  use MediaWikiCoversValidator;
9 
10  public static function provideGetStyles() {
11  // phpcs:disable Generic.Files.LineLength
12  return [
13  [
14  'parent' => [],
15  'logo' => '/logo.png',
16  'expected' => [
17  'all' => [ '.mw-wiki-logo { background-image: url(/logo.png); }' ],
18  ],
19  ],
20  [
21  'parent' => [
22  'screen' => '.example {}',
23  ],
24  'logo' => '/logo.png',
25  'expected' => [
26  'screen' => [ '.example {}' ],
27  'all' => [ '.mw-wiki-logo { background-image: url(/logo.png); }' ],
28  ],
29  ],
30  [
31  'parent' => [],
32  'logo' => [
33  '1x' => '/logo.png',
34  '1.5x' => '/logo@1.5x.png',
35  '2x' => '/logo@2x.png',
36  ],
37  'expected' => [
38  'all' => [ <<<CSS
39 .mw-wiki-logo { background-image: url(/logo.png); }
40 CSS
41  ],
42  '(-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (min-resolution: 1.5dppx), (min-resolution: 144dpi)' => [ <<<CSS
43 .mw-wiki-logo { background-image: url(/logo@1.5x.png);background-size: 135px auto; }
44 CSS
45  ],
46  '(-webkit-min-device-pixel-ratio: 2), (min--moz-device-pixel-ratio: 2), (min-resolution: 2dppx), (min-resolution: 192dpi)' => [ <<<CSS
47 .mw-wiki-logo { background-image: url(/logo@2x.png);background-size: 135px auto; }
48 CSS
49  ],
50  ],
51  ],
52  [
53  'parent' => [],
54  'logo' => [
55  '1x' => '/logo.png',
56  'svg' => '/logo.svg',
57  ],
58  'expected' => [
59  'all' => [ <<<CSS
60 .mw-wiki-logo { background-image: url(/logo.png); }
61 CSS
62  , <<<CSS
63 .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; }
64 CSS
65  ],
66  ],
67  ],
68  ];
69  // phpcs:enable
70  }
71 
77  public function testGetStyles( $parent, $logo, $expected ) {
78  $module = $this->getMockBuilder( ResourceLoaderSkinModule::class )
79  ->disableOriginalConstructor()
80  ->setMethods( [ 'readStyleFiles', 'getConfig', 'getLogoData' ] )
81  ->getMock();
82  $module->expects( $this->once() )->method( 'readStyleFiles' )
83  ->willReturn( $parent );
84  $module->expects( $this->once() )->method( 'getConfig' )
85  ->willReturn( new HashConfig() );
86  $module->expects( $this->once() )->method( 'getLogoData' )
87  ->willReturn( $logo );
88 
89  $ctx = $this->getMockBuilder( ResourceLoaderContext::class )
90  ->disableOriginalConstructor()->getMock();
91 
92  $this->assertEquals(
93  $expected,
94  $module->getStyles( $ctx )
95  );
96  }
97 
101  public function testIsKnownEmpty() {
102  $module = $this->getMockBuilder( ResourceLoaderSkinModule::class )
103  ->disableOriginalConstructor()->setMethods( null )->getMock();
104  $ctx = $this->getMockBuilder( ResourceLoaderContext::class )
105  ->disableOriginalConstructor()->getMock();
106 
107  $this->assertFalse( $module->isKnownEmpty( $ctx ) );
108  }
109 
114  public function testGetLogo( $config, $expected, $baseDir = null ) {
115  if ( $baseDir ) {
116  $oldIP = $GLOBALS['IP'];
117  $GLOBALS['IP'] = $baseDir;
118  $teardown = new Wikimedia\ScopedCallback( function () use ( $oldIP ) {
119  $GLOBALS['IP'] = $oldIP;
120  } );
121  }
122 
123  $this->assertEquals(
124  $expected,
126  );
127  }
128 
129  public function provideGetLogo() {
130  return [
131  'simple' => [
132  'config' => [
133  'ResourceBasePath' => '/w',
134  'Logo' => '/img/default.png',
135  'LogoHD' => false,
136  ],
137  'expected' => '/img/default.png',
138  ],
139  'default and 2x' => [
140  'config' => [
141  'ResourceBasePath' => '/w',
142  'Logo' => '/img/default.png',
143  'LogoHD' => [
144  '2x' => '/img/two-x.png',
145  ],
146  ],
147  'expected' => [
148  '1x' => '/img/default.png',
149  '2x' => '/img/two-x.png',
150  ],
151  ],
152  'default and all HiDPIs' => [
153  'config' => [
154  'ResourceBasePath' => '/w',
155  'Logo' => '/img/default.png',
156  'LogoHD' => [
157  '1.5x' => '/img/one-point-five.png',
158  '2x' => '/img/two-x.png',
159  ],
160  ],
161  'expected' => [
162  '1x' => '/img/default.png',
163  '1.5x' => '/img/one-point-five.png',
164  '2x' => '/img/two-x.png',
165  ],
166  ],
167  'default and SVG' => [
168  'config' => [
169  'ResourceBasePath' => '/w',
170  'Logo' => '/img/default.png',
171  'LogoHD' => [
172  'svg' => '/img/vector.svg',
173  ],
174  ],
175  'expected' => [
176  '1x' => '/img/default.png',
177  'svg' => '/img/vector.svg',
178  ],
179  ],
180  'everything' => [
181  'config' => [
182  'ResourceBasePath' => '/w',
183  'Logo' => '/img/default.png',
184  'LogoHD' => [
185  '1.5x' => '/img/one-point-five.png',
186  '2x' => '/img/two-x.png',
187  'svg' => '/img/vector.svg',
188  ],
189  ],
190  'expected' => [
191  '1x' => '/img/default.png',
192  'svg' => '/img/vector.svg',
193  ],
194  ],
195  'versioned url' => [
196  'config' => [
197  'ResourceBasePath' => '/w',
198  'Logo' => '/w/test.jpg',
199  'LogoHD' => false,
200  'UploadPath' => '/w/images',
201  ],
202  'expected' => '/w/test.jpg?edcf2',
203  'baseDir' => dirname( dirname( __DIR__ ) ) . '/data/media',
204  ],
205  ];
206  }
207 }
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
HashConfig
A Config instance which stores all settings as a member variable.
Definition: HashConfig.php:28
ResourceLoaderSkinModuleTest\testIsKnownEmpty
testIsKnownEmpty()
ResourceLoaderSkinModule::isKnownEmpty.
Definition: ResourceLoaderSkinModuleTest.php:101
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:27
ResourceLoaderSkinModuleTest\testGetStyles
testGetStyles( $parent, $logo, $expected)
provideGetStyles ResourceLoaderSkinModule::normalizeStyles ResourceLoaderSkinModule::getStyles
Definition: ResourceLoaderSkinModuleTest.php:77
ResourceLoaderSkinModuleTest\testGetLogo
testGetLogo( $config, $expected, $baseDir=null)
provideGetLogo ResourceLoaderSkinModule::getLogo
Definition: ResourceLoaderSkinModuleTest.php:114
ResourceLoaderSkinModuleTest\provideGetStyles
static provideGetStyles()
Definition: ResourceLoaderSkinModuleTest.php:10
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:37
ResourceLoaderSkinModuleTest
ResourceLoader.
Definition: ResourceLoaderSkinModuleTest.php:6
ResourceLoaderSkinModule\getLogo
static getLogo(Config $conf)
Definition: ResourceLoaderSkinModule.php:111
ResourceLoaderSkinModuleTest\provideGetLogo
provideGetLogo()
Definition: ResourceLoaderSkinModuleTest.php:129
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:56
$GLOBALS
$GLOBALS['IP']
Definition: ComposerHookHandler.php:6