ResourceLoaderImageModule: Remove 'type' stuff
[lhc/web/wiklou.git] / tests / phpunit / includes / resourceloader / ResourceLoaderImageModuleTest.php
1 <?php
2
3 /**
4 * @group ResourceLoader
5 */
6 class ResourceLoaderImageModuleTest extends ResourceLoaderTestCase {
7
8 public static function providerGetModules() {
9 $commonVariants = array(
10 'invert' => array(
11 'color' => '#FFFFFF',
12 'global' => true,
13 ),
14 'primary' => array(
15 'color' => '#598AD1',
16 ),
17 'constructive' => array(
18 'color' => '#00C697',
19 ),
20 'destructive' => array(
21 'color' => '#E81915',
22 ),
23 );
24
25 $commonImageData = array(
26 'advanced' => 'advanced.svg',
27 'remove' => array(
28 'image' => 'remove.svg',
29 'variants' => array( 'destructive' ),
30 ),
31 'next' => array(
32 'image' => array(
33 'ltr' => 'next.svg',
34 'rtl' => 'prev.svg'
35 ),
36 ),
37 'help' => array(
38 'image' => array(
39 'ltr' => 'help-ltr.svg',
40 'rtl' => 'help-rtl.svg',
41 'lang' => array(
42 'he' => 'help-ltr.svg',
43 )
44 ),
45 ),
46 'bold' => array(
47 'image' => array(
48 'default' => 'bold-a.svg',
49 'lang' => array(
50 'en' => 'bold-b.svg',
51 'de' => 'bold-f.svg',
52 )
53 ),
54 )
55 );
56
57 return array(
58 array(
59 array(
60 'class' => 'ResourceLoaderImageModule',
61 'prefix' => 'oo-ui-icon',
62 'variants' => $commonVariants,
63 'images' => $commonImageData,
64 ),
65 '.oo-ui-icon-advanced {
66 ...
67 }
68 .oo-ui-icon-advanced-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 array(
100 array(
101 'class' => 'ResourceLoaderImageModule',
102 'selectorWithoutVariant' => '.mw-ui-icon-{name}:after, .mw-ui-icon-{name}:before',
103 'selectorWithVariant' => '.mw-ui-icon-{name}-{variant}:after, .mw-ui-icon-{name}-{variant}:before',
104 'variants' => $commonVariants,
105 'images' => $commonImageData,
106 ),
107 '.mw-ui-icon-advanced:after, .mw-ui-icon-advanced:before {
108 ...
109 }
110 .mw-ui-icon-advanced-invert:after, .mw-ui-icon-advanced-invert:before {
111 ...
112 }
113 .mw-ui-icon-remove:after, .mw-ui-icon-remove:before {
114 ...
115 }
116 .mw-ui-icon-remove-invert:after, .mw-ui-icon-remove-invert:before {
117 ...
118 }
119 .mw-ui-icon-remove-destructive:after, .mw-ui-icon-remove-destructive:before {
120 ...
121 }
122 .mw-ui-icon-next:after, .mw-ui-icon-next:before {
123 ...
124 }
125 .mw-ui-icon-next-invert:after, .mw-ui-icon-next-invert:before {
126 ...
127 }
128 .mw-ui-icon-help:after, .mw-ui-icon-help:before {
129 ...
130 }
131 .mw-ui-icon-help-invert:after, .mw-ui-icon-help-invert:before {
132 ...
133 }
134 .mw-ui-icon-bold:after, .mw-ui-icon-bold:before {
135 ...
136 }
137 .mw-ui-icon-bold-invert:after, .mw-ui-icon-bold-invert:before {
138 ...
139 }',
140 ),
141 );
142 }
143
144 /**
145 * @dataProvider providerGetModules
146 * @covers ResourceLoaderImageModule::getStyles
147 */
148 public function testGetStyles( $module, $expected ) {
149 $module = new ResourceLoaderImageModuleTestable( $module );
150 $styles = $module->getStyles( $this->getResourceLoaderContext() );
151 $this->assertEquals( $expected, $styles['all'] );
152 }
153 }
154
155 class ResourceLoaderImageModuleTestable extends ResourceLoaderImageModule {
156 /**
157 * Replace with a stub to make test cases easier to write.
158 */
159 protected function getCssDeclarations( $primary, $fallback ) {
160 return array( '...' );
161 }
162
163 /**
164 * Return mock ResourceLoaderImages that don't call file_get_contents and such.
165 */
166 public function getImages() {
167 $images = parent::getImages();
168 foreach ( $images as $name => &$image ) {
169 $image = new ResourceLoaderImageWrapper( $image );
170 }
171 return $images;
172 }
173 }
174
175 /**
176 * Wraps a ResourceLoaderImage not to call file_get_contents and such.
177 */
178 class ResourceLoaderImageWrapper extends ResourceLoaderImage {
179 public function __construct( ResourceLoaderImage $image ) {
180 $this->image = $image;
181 }
182
183 public function getUrl( ResourceLoaderContext $context, $script, $variant, $format ) {
184 return null;
185 }
186
187 public function getDataUri( ResourceLoaderContext $context, $variant, $format ) {
188 return null;
189 }
190
191 public function __call( $method, $arguments ) {
192 return call_user_func_array( array( $this->image, $method ), $arguments );
193 }
194
195 public function __get( $name ) {
196 return $this->image->$name;
197 }
198 }