MediaWiki  1.28.1
ResourceLoaderImageModuleTest.php
Go to the documentation of this file.
1 <?php
2 
7 
8  public static $commonImageData = [
9  'add' => 'add.gif',
10  'remove' => [
11  'file' => 'remove.svg',
12  'variants' => [ 'destructive' ],
13  ],
14  'next' => [
15  'file' => [
16  'ltr' => 'next.svg',
17  'rtl' => 'prev.svg'
18  ],
19  ],
20  'help' => [
21  'file' => [
22  'ltr' => 'help-ltr.svg',
23  'rtl' => 'help-rtl.svg',
24  'lang' => [
25  'he' => 'help-ltr.svg',
26  ]
27  ],
28  ],
29  'bold' => [
30  'file' => [
31  'default' => 'bold-a.svg',
32  'lang' => [
33  'en' => 'bold-b.svg',
34  'ar,de' => 'bold-f.svg',
35  ]
36  ],
37  ]
38  ];
39 
40  public static $commonImageVariants = [
41  'invert' => [
42  'color' => '#FFFFFF',
43  'global' => true,
44  ],
45  'primary' => [
46  'color' => '#598AD1',
47  ],
48  'constructive' => [
49  'color' => '#00C697',
50  ],
51  'destructive' => [
52  'color' => '#E81915',
53  ],
54  ];
55 
56  public static function providerGetModules() {
57  return [
58  [
59  [
60  'class' => 'ResourceLoaderImageModule',
61  'prefix' => 'oo-ui-icon',
62  'variants' => self::$commonImageVariants,
63  'images' => self::$commonImageData,
64  ],
65  '.oo-ui-icon-add {
66  ...
67 }
68 .oo-ui-icon-add-invert {
69  ...
70 }
71 .oo-ui-icon-remove {
72  ...
73 }
74 .oo-ui-icon-remove-invert {
75  ...
76 }
77 .oo-ui-icon-remove-destructive {
78  ...
79 }
80 .oo-ui-icon-next {
81  ...
82 }
83 .oo-ui-icon-next-invert {
84  ...
85 }
86 .oo-ui-icon-help {
87  ...
88 }
89 .oo-ui-icon-help-invert {
90  ...
91 }
92 .oo-ui-icon-bold {
93  ...
94 }
95 .oo-ui-icon-bold-invert {
96  ...
97 }',
98  ],
99  [
100  [
101  'class' => 'ResourceLoaderImageModule',
102  'selectorWithoutVariant' => '.mw-ui-icon-{name}:after, .mw-ui-icon-{name}:before',
103  'selectorWithVariant' =>
104  '.mw-ui-icon-{name}-{variant}:after, .mw-ui-icon-{name}-{variant}:before',
105  'variants' => self::$commonImageVariants,
106  'images' => self::$commonImageData,
107  ],
108  '.mw-ui-icon-add:after, .mw-ui-icon-add:before {
109  ...
110 }
111 .mw-ui-icon-add-invert:after, .mw-ui-icon-add-invert:before {
112  ...
113 }
114 .mw-ui-icon-remove:after, .mw-ui-icon-remove:before {
115  ...
116 }
117 .mw-ui-icon-remove-invert:after, .mw-ui-icon-remove-invert:before {
118  ...
119 }
120 .mw-ui-icon-remove-destructive:after, .mw-ui-icon-remove-destructive:before {
121  ...
122 }
123 .mw-ui-icon-next:after, .mw-ui-icon-next:before {
124  ...
125 }
126 .mw-ui-icon-next-invert:after, .mw-ui-icon-next-invert:before {
127  ...
128 }
129 .mw-ui-icon-help:after, .mw-ui-icon-help:before {
130  ...
131 }
132 .mw-ui-icon-help-invert:after, .mw-ui-icon-help-invert:before {
133  ...
134 }
135 .mw-ui-icon-bold:after, .mw-ui-icon-bold:before {
136  ...
137 }
138 .mw-ui-icon-bold-invert:after, .mw-ui-icon-bold-invert:before {
139  ...
140 }',
141  ],
142  ];
143  }
144 
149  public function testGetStyles( $module, $expected ) {
150  $module = new ResourceLoaderImageModuleTestable(
151  $module,
152  __DIR__ . '/../../data/resourceloader'
153  );
154  $styles = $module->getStyles( $this->getResourceLoaderContext() );
155  $this->assertEquals( $expected, $styles['all'] );
156  }
157 
161  public function testContext() {
163  $this->assertFalse( $context->getImageObj(), 'Missing image parameter' );
164 
166  'image' => 'example',
167  ] ) );
168  $this->assertFalse( $context->getImageObj(), 'Missing module parameter' );
169 
170  $context = new ResourceLoaderContext( new EmptyResourceLoader(), new FauxRequest( [
171  'modules' => 'unknown',
172  'image' => 'example',
173  ] ) );
174  $this->assertFalse( $context->getImageObj(), 'Not an image module' );
175 
176  $rl = new EmptyResourceLoader();
177  $rl->register( 'test', [
179  'prefix' => 'test',
180  'images' => [ 'example' => 'example.png' ],
181  ] );
182  $context = new ResourceLoaderContext( $rl, new FauxRequest( [
183  'modules' => 'test',
184  'image' => 'unknown',
185  ] ) );
186  $this->assertFalse( $context->getImageObj(), 'Unknown image' );
187 
188  $rl = new EmptyResourceLoader();
189  $rl->register( 'test', [
191  'prefix' => 'test',
192  'images' => [ 'example' => 'example.png' ],
193  ] );
194  $context = new ResourceLoaderContext( $rl, new FauxRequest( [
195  'modules' => 'test',
196  'image' => 'example',
197  ] ) );
198  $this->assertInstanceOf( ResourceLoaderImage::class, $context->getImageObj() );
199  }
200 }
201 
206  protected function getCssDeclarations( $primary, $fallback ) {
207  return [ '...' ];
208  }
209 }
$context
Definition: load.php:50
ResourceLoader module for generated and embedded images.
testGetStyles($module, $expected)
providerGetModules ResourceLoaderImageModule::getStyles
getCssDeclarations($primary, $fallback)
Replace with a stub to make test cases easier to write.
getResourceLoaderContext($lang= 'en', $dir= 'ltr')
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
testContext()
ResourceLoaderContext::getImageObj.
$fallback
Definition: MessagesAb.php:11
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
Object passed around to modules which contains information about the state of a specific loader reque...