Merge "Clarify comment in traditional gallery"
[lhc/web/wiklou.git] / tests / phpunit / includes / HtmlTest.php
1 <?php
2 /** tests for includes/Html.php */
3
4 class HtmlTest extends MediaWikiTestCase {
5
6 protected function setUp() {
7 parent::setUp();
8
9 $this->setMwGlobals( [
10 'wgUseMediaWikiUIEverywhere' => false,
11 ] );
12
13 $langObj = Language::factory( 'en' );
14
15 // Hardcode namespaces during test runs,
16 // so that html output based on existing namespaces
17 // can be properly evaluated.
18 $langObj->setNamespaces( [
19 -2 => 'Media',
20 -1 => 'Special',
21 0 => '',
22 1 => 'Talk',
23 2 => 'User',
24 3 => 'User_talk',
25 4 => 'MyWiki',
26 5 => 'MyWiki_Talk',
27 6 => 'File',
28 7 => 'File_talk',
29 8 => 'MediaWiki',
30 9 => 'MediaWiki_talk',
31 10 => 'Template',
32 11 => 'Template_talk',
33 14 => 'Category',
34 15 => 'Category_talk',
35 100 => 'Custom',
36 101 => 'Custom_talk',
37 ] );
38 $this->setUserLang( $langObj );
39 $this->setContentLang( $langObj );
40 }
41
42 /**
43 * @covers Html::element
44 */
45 public function testElementBasics() {
46 $this->assertEquals(
47 '<img/>',
48 Html::element( 'img', null, '' ),
49 'Self-closing tag for short-tag elements'
50 );
51
52 $this->assertEquals(
53 '<element></element>',
54 Html::element( 'element', null, null ),
55 'Close tag for empty element (null, null)'
56 );
57
58 $this->assertEquals(
59 '<element></element>',
60 Html::element( 'element', [], '' ),
61 'Close tag for empty element (array, string)'
62 );
63 }
64
65 public function dataXmlMimeType() {
66 return [
67 // ( $mimetype, $isXmlMimeType )
68 # HTML is not an XML MimeType
69 [ 'text/html', false ],
70 # XML is an XML MimeType
71 [ 'text/xml', true ],
72 [ 'application/xml', true ],
73 # XHTML is an XML MimeType
74 [ 'application/xhtml+xml', true ],
75 # Make sure other +xml MimeTypes are supported
76 # SVG is another random MimeType even though we don't use it
77 [ 'image/svg+xml', true ],
78 # Complete random other MimeTypes are not XML
79 [ 'text/plain', false ],
80 ];
81 }
82
83 /**
84 * @dataProvider dataXmlMimeType
85 * @covers Html::isXmlMimeType
86 */
87 public function testXmlMimeType( $mimetype, $isXmlMimeType ) {
88 $this->assertEquals( $isXmlMimeType, Html::isXmlMimeType( $mimetype ) );
89 }
90
91 /**
92 * @covers Html::expandAttributes
93 */
94 public function testExpandAttributesSkipsNullAndFalse() {
95
96 # ## EMPTY ########
97 $this->assertEmpty(
98 Html::expandAttributes( [ 'foo' => null ] ),
99 'skip keys with null value'
100 );
101 $this->assertEmpty(
102 Html::expandAttributes( [ 'foo' => false ] ),
103 'skip keys with false value'
104 );
105 $this->assertEquals(
106 ' foo=""',
107 Html::expandAttributes( [ 'foo' => '' ] ),
108 'keep keys with an empty string'
109 );
110 }
111
112 /**
113 * @covers Html::expandAttributes
114 */
115 public function testExpandAttributesForBooleans() {
116 $this->assertEquals(
117 '',
118 Html::expandAttributes( [ 'selected' => false ] ),
119 'Boolean attributes do not generates output when value is false'
120 );
121 $this->assertEquals(
122 '',
123 Html::expandAttributes( [ 'selected' => null ] ),
124 'Boolean attributes do not generates output when value is null'
125 );
126
127 $this->assertEquals(
128 ' selected=""',
129 Html::expandAttributes( [ 'selected' => true ] ),
130 'Boolean attributes have no value when value is true'
131 );
132 $this->assertEquals(
133 ' selected=""',
134 Html::expandAttributes( [ 'selected' ] ),
135 'Boolean attributes have no value when value is true (passed as numerical array)'
136 );
137 }
138
139 /**
140 * @covers Html::expandAttributes
141 */
142 public function testExpandAttributesForNumbers() {
143 $this->assertEquals(
144 ' value="1"',
145 Html::expandAttributes( [ 'value' => 1 ] ),
146 'Integer value is cast to a string'
147 );
148 $this->assertEquals(
149 ' value="1.1"',
150 Html::expandAttributes( [ 'value' => 1.1 ] ),
151 'Float value is cast to a string'
152 );
153 }
154
155 /**
156 * @covers Html::expandAttributes
157 */
158 public function testExpandAttributesForObjects() {
159 $this->assertEquals(
160 ' value="stringValue"',
161 Html::expandAttributes( [ 'value' => new HtmlTestValue() ] ),
162 'Object value is converted to a string'
163 );
164 }
165
166 /**
167 * Test for Html::expandAttributes()
168 * Please note it output a string prefixed with a space!
169 * @covers Html::expandAttributes
170 */
171 public function testExpandAttributesVariousExpansions() {
172 # ## NOT EMPTY ####
173 $this->assertEquals(
174 ' empty_string=""',
175 Html::expandAttributes( [ 'empty_string' => '' ] ),
176 'Empty string is always quoted'
177 );
178 $this->assertEquals(
179 ' key="value"',
180 Html::expandAttributes( [ 'key' => 'value' ] ),
181 'Simple string value needs no quotes'
182 );
183 $this->assertEquals(
184 ' one="1"',
185 Html::expandAttributes( [ 'one' => 1 ] ),
186 'Number 1 value needs no quotes'
187 );
188 $this->assertEquals(
189 ' zero="0"',
190 Html::expandAttributes( [ 'zero' => 0 ] ),
191 'Number 0 value needs no quotes'
192 );
193
194 }
195
196 /**
197 * Html::expandAttributes has special features for HTML
198 * attributes that use space separated lists and also
199 * allows arrays to be used as values.
200 * @covers Html::expandAttributes
201 */
202 public function testExpandAttributesListValueAttributes() {
203 # ## STRING VALUES
204 $this->assertEquals(
205 ' class="redundant spaces here"',
206 Html::expandAttributes( [ 'class' => ' redundant spaces here ' ] ),
207 'Normalization should strip redundant spaces'
208 );
209 $this->assertEquals(
210 ' class="foo bar"',
211 Html::expandAttributes( [ 'class' => 'foo bar foo bar bar' ] ),
212 'Normalization should remove duplicates in string-lists'
213 );
214 # ## "EMPTY" ARRAY VALUES
215 $this->assertEquals(
216 ' class=""',
217 Html::expandAttributes( [ 'class' => [] ] ),
218 'Value with an empty array'
219 );
220 $this->assertEquals(
221 ' class=""',
222 Html::expandAttributes( [ 'class' => [ null, '', ' ', ' ' ] ] ),
223 'Array with null, empty string and spaces'
224 );
225 # ## NON-EMPTY ARRAY VALUES
226 $this->assertEquals(
227 ' class="foo bar"',
228 Html::expandAttributes( [ 'class' => [
229 'foo',
230 'bar',
231 'foo',
232 'bar',
233 'bar',
234 ] ] ),
235 'Normalization should remove duplicates in the array'
236 );
237 $this->assertEquals(
238 ' class="foo bar"',
239 Html::expandAttributes( [ 'class' => [
240 'foo bar',
241 'bar foo',
242 'foo',
243 'bar bar',
244 ] ] ),
245 'Normalization should remove duplicates in string-lists in the array'
246 );
247 }
248
249 /**
250 * Test feature added by r96188, let pass attributes values as
251 * a PHP array. Restricted to class,rel, accesskey.
252 * @covers Html::expandAttributes
253 */
254 public function testExpandAttributesSpaceSeparatedAttributesWithBoolean() {
255 $this->assertEquals(
256 ' class="booltrue one"',
257 Html::expandAttributes( [ 'class' => [
258 'booltrue' => true,
259 'one' => 1,
260
261 # Method use isset() internally, make sure we do discard
262 # attributes values which have been assigned well known values
263 'emptystring' => '',
264 'boolfalse' => false,
265 'zero' => 0,
266 'null' => null,
267 ] ] )
268 );
269 }
270
271 /**
272 * How do we handle duplicate keys in HTML attributes expansion?
273 * We could pass a "class" the values: 'GREEN' and array( 'GREEN' => false )
274 * The latter will take precedence.
275 *
276 * Feature added by r96188
277 * @covers Html::expandAttributes
278 */
279 public function testValueIsAuthoritativeInSpaceSeparatedAttributesArrays() {
280 $this->assertEquals(
281 ' class=""',
282 Html::expandAttributes( [ 'class' => [
283 'GREEN',
284 'GREEN' => false,
285 'GREEN',
286 ] ] )
287 );
288 }
289
290 /**
291 * @covers Html::expandAttributes
292 * @expectedException MWException
293 */
294 public function testExpandAttributes_ArrayOnNonListValueAttribute_ThrowsException() {
295 // Real-life test case found in the Popups extension (see Gerrit cf0fd64),
296 // when used with an outdated BetaFeatures extension (see Gerrit deda1e7)
297 Html::expandAttributes( [
298 'src' => [
299 'ltr' => 'ltr.svg',
300 'rtl' => 'rtl.svg'
301 ]
302 ] );
303 }
304
305 /**
306 * @covers Html::namespaceSelector
307 */
308 public function testNamespaceSelector() {
309 $this->assertEquals(
310 '<select id="namespace" name="namespace">' . "\n" .
311 '<option value="0">(Main)</option>' . "\n" .
312 '<option value="1">Talk</option>' . "\n" .
313 '<option value="2">User</option>' . "\n" .
314 '<option value="3">User talk</option>' . "\n" .
315 '<option value="4">MyWiki</option>' . "\n" .
316 '<option value="5">MyWiki Talk</option>' . "\n" .
317 '<option value="6">File</option>' . "\n" .
318 '<option value="7">File talk</option>' . "\n" .
319 '<option value="8">MediaWiki</option>' . "\n" .
320 '<option value="9">MediaWiki talk</option>' . "\n" .
321 '<option value="10">Template</option>' . "\n" .
322 '<option value="11">Template talk</option>' . "\n" .
323 '<option value="14">Category</option>' . "\n" .
324 '<option value="15">Category talk</option>' . "\n" .
325 '<option value="100">Custom</option>' . "\n" .
326 '<option value="101">Custom talk</option>' . "\n" .
327 '</select>',
328 Html::namespaceSelector(),
329 'Basic namespace selector without custom options'
330 );
331
332 $this->assertEquals(
333 '<label for="mw-test-namespace">Select a namespace:</label>&#160;' .
334 '<select id="mw-test-namespace" name="wpNamespace">' . "\n" .
335 '<option value="all">all</option>' . "\n" .
336 '<option value="0">(Main)</option>' . "\n" .
337 '<option value="1">Talk</option>' . "\n" .
338 '<option value="2" selected="">User</option>' . "\n" .
339 '<option value="3">User talk</option>' . "\n" .
340 '<option value="4">MyWiki</option>' . "\n" .
341 '<option value="5">MyWiki Talk</option>' . "\n" .
342 '<option value="6">File</option>' . "\n" .
343 '<option value="7">File talk</option>' . "\n" .
344 '<option value="8">MediaWiki</option>' . "\n" .
345 '<option value="9">MediaWiki talk</option>' . "\n" .
346 '<option value="10">Template</option>' . "\n" .
347 '<option value="11">Template talk</option>' . "\n" .
348 '<option value="14">Category</option>' . "\n" .
349 '<option value="15">Category talk</option>' . "\n" .
350 '<option value="100">Custom</option>' . "\n" .
351 '<option value="101">Custom talk</option>' . "\n" .
352 '</select>',
353 Html::namespaceSelector(
354 [ 'selected' => '2', 'all' => 'all', 'label' => 'Select a namespace:' ],
355 [ 'name' => 'wpNamespace', 'id' => 'mw-test-namespace' ]
356 ),
357 'Basic namespace selector with custom values'
358 );
359
360 $this->assertEquals(
361 '<label for="namespace">Select a namespace:</label>&#160;' .
362 '<select id="namespace" name="namespace">' . "\n" .
363 '<option value="0">(Main)</option>' . "\n" .
364 '<option value="1">Talk</option>' . "\n" .
365 '<option value="2">User</option>' . "\n" .
366 '<option value="3">User talk</option>' . "\n" .
367 '<option value="4">MyWiki</option>' . "\n" .
368 '<option value="5">MyWiki Talk</option>' . "\n" .
369 '<option value="6">File</option>' . "\n" .
370 '<option value="7">File talk</option>' . "\n" .
371 '<option value="8">MediaWiki</option>' . "\n" .
372 '<option value="9">MediaWiki talk</option>' . "\n" .
373 '<option value="10">Template</option>' . "\n" .
374 '<option value="11">Template talk</option>' . "\n" .
375 '<option value="14">Category</option>' . "\n" .
376 '<option value="15">Category talk</option>' . "\n" .
377 '<option value="100">Custom</option>' . "\n" .
378 '<option value="101">Custom talk</option>' . "\n" .
379 '</select>',
380 Html::namespaceSelector(
381 [ 'label' => 'Select a namespace:' ]
382 ),
383 'Basic namespace selector with a custom label but no id attribtue for the <select>'
384 );
385 }
386
387 public function testCanFilterOutNamespaces() {
388 $this->assertEquals(
389 '<select id="namespace" name="namespace">' . "\n" .
390 '<option value="2">User</option>' . "\n" .
391 '<option value="4">MyWiki</option>' . "\n" .
392 '<option value="5">MyWiki Talk</option>' . "\n" .
393 '<option value="6">File</option>' . "\n" .
394 '<option value="7">File talk</option>' . "\n" .
395 '<option value="8">MediaWiki</option>' . "\n" .
396 '<option value="9">MediaWiki talk</option>' . "\n" .
397 '<option value="10">Template</option>' . "\n" .
398 '<option value="11">Template talk</option>' . "\n" .
399 '<option value="14">Category</option>' . "\n" .
400 '<option value="15">Category talk</option>' . "\n" .
401 '</select>',
402 Html::namespaceSelector(
403 [ 'exclude' => [ 0, 1, 3, 100, 101 ] ]
404 ),
405 'Namespace selector namespace filtering.'
406 );
407 }
408
409 public function testCanDisableANamespaces() {
410 $this->assertEquals(
411 '<select id="namespace" name="namespace">' . "\n" .
412 '<option disabled="" value="0">(Main)</option>' . "\n" .
413 '<option disabled="" value="1">Talk</option>' . "\n" .
414 '<option disabled="" value="2">User</option>' . "\n" .
415 '<option disabled="" value="3">User talk</option>' . "\n" .
416 '<option disabled="" value="4">MyWiki</option>' . "\n" .
417 '<option value="5">MyWiki Talk</option>' . "\n" .
418 '<option value="6">File</option>' . "\n" .
419 '<option value="7">File talk</option>' . "\n" .
420 '<option value="8">MediaWiki</option>' . "\n" .
421 '<option value="9">MediaWiki talk</option>' . "\n" .
422 '<option value="10">Template</option>' . "\n" .
423 '<option value="11">Template talk</option>' . "\n" .
424 '<option value="14">Category</option>' . "\n" .
425 '<option value="15">Category talk</option>' . "\n" .
426 '<option value="100">Custom</option>' . "\n" .
427 '<option value="101">Custom talk</option>' . "\n" .
428 '</select>',
429 Html::namespaceSelector( [
430 'disable' => [ 0, 1, 2, 3, 4 ]
431 ] ),
432 'Namespace selector namespace disabling'
433 );
434 }
435
436 /**
437 * @dataProvider provideHtml5InputTypes
438 * @covers Html::element
439 */
440 public function testHtmlElementAcceptsNewHtml5TypesInHtml5Mode( $HTML5InputType ) {
441 $this->assertEquals(
442 '<input type="' . $HTML5InputType . '"/>',
443 Html::element( 'input', [ 'type' => $HTML5InputType ] ),
444 'In HTML5, Html::element() should accept type="' . $HTML5InputType . '"'
445 );
446 }
447
448 /**
449 * List of input element types values introduced by HTML5
450 * Full list at http://www.w3.org/TR/html-markup/input.html
451 */
452 public static function provideHtml5InputTypes() {
453 $types = [
454 'datetime',
455 'datetime-local',
456 'date',
457 'month',
458 'time',
459 'week',
460 'number',
461 'range',
462 'email',
463 'url',
464 'search',
465 'tel',
466 'color',
467 ];
468 $cases = [];
469 foreach ( $types as $type ) {
470 $cases[] = [ $type ];
471 }
472
473 return $cases;
474 }
475
476 /**
477 * Test out Html::element drops or enforces default value
478 * @covers Html::dropDefaults
479 * @dataProvider provideElementsWithAttributesHavingDefaultValues
480 */
481 public function testDropDefaults( $expected, $element, $attribs, $message = '' ) {
482 $this->assertEquals( $expected, Html::element( $element, $attribs ), $message );
483 }
484
485 public static function provideElementsWithAttributesHavingDefaultValues() {
486 # Use cases in a concise format:
487 # <expected>, <element name>, <array of attributes> [, <message>]
488 # Will be mapped to Html::element()
489 $cases = [];
490
491 # ## Generic cases, match $attribDefault static array
492 $cases[] = [ '<area/>',
493 'area', [ 'shape' => 'rect' ]
494 ];
495
496 $cases[] = [ '<button type="submit"></button>',
497 'button', [ 'formaction' => 'GET' ]
498 ];
499 $cases[] = [ '<button type="submit"></button>',
500 'button', [ 'formenctype' => 'application/x-www-form-urlencoded' ]
501 ];
502
503 $cases[] = [ '<canvas></canvas>',
504 'canvas', [ 'height' => '150' ]
505 ];
506 $cases[] = [ '<canvas></canvas>',
507 'canvas', [ 'width' => '300' ]
508 ];
509 # Also check with numeric values
510 $cases[] = [ '<canvas></canvas>',
511 'canvas', [ 'height' => 150 ]
512 ];
513 $cases[] = [ '<canvas></canvas>',
514 'canvas', [ 'width' => 300 ]
515 ];
516
517 $cases[] = [ '<form></form>',
518 'form', [ 'action' => 'GET' ]
519 ];
520 $cases[] = [ '<form></form>',
521 'form', [ 'autocomplete' => 'on' ]
522 ];
523 $cases[] = [ '<form></form>',
524 'form', [ 'enctype' => 'application/x-www-form-urlencoded' ]
525 ];
526
527 $cases[] = [ '<input/>',
528 'input', [ 'formaction' => 'GET' ]
529 ];
530 $cases[] = [ '<input/>',
531 'input', [ 'type' => 'text' ]
532 ];
533
534 $cases[] = [ '<keygen/>',
535 'keygen', [ 'keytype' => 'rsa' ]
536 ];
537
538 $cases[] = [ '<link/>',
539 'link', [ 'media' => 'all' ]
540 ];
541
542 $cases[] = [ '<menu></menu>',
543 'menu', [ 'type' => 'list' ]
544 ];
545
546 $cases[] = [ '<script></script>',
547 'script', [ 'type' => 'text/javascript' ]
548 ];
549
550 $cases[] = [ '<style></style>',
551 'style', [ 'media' => 'all' ]
552 ];
553 $cases[] = [ '<style></style>',
554 'style', [ 'type' => 'text/css' ]
555 ];
556
557 $cases[] = [ '<textarea></textarea>',
558 'textarea', [ 'wrap' => 'soft' ]
559 ];
560
561 # ## SPECIFIC CASES
562
563 # <link type="text/css">
564 $cases[] = [ '<link/>',
565 'link', [ 'type' => 'text/css' ]
566 ];
567
568 # <input> specific handling
569 $cases[] = [ '<input type="checkbox"/>',
570 'input', [ 'type' => 'checkbox', 'value' => 'on' ],
571 'Default value "on" is stripped of checkboxes',
572 ];
573 $cases[] = [ '<input type="radio"/>',
574 'input', [ 'type' => 'radio', 'value' => 'on' ],
575 'Default value "on" is stripped of radio buttons',
576 ];
577 $cases[] = [ '<input type="submit" value="Submit"/>',
578 'input', [ 'type' => 'submit', 'value' => 'Submit' ],
579 'Default value "Submit" is kept on submit buttons (for possible l10n issues)',
580 ];
581 $cases[] = [ '<input type="color"/>',
582 'input', [ 'type' => 'color', 'value' => '' ],
583 ];
584 $cases[] = [ '<input type="range"/>',
585 'input', [ 'type' => 'range', 'value' => '' ],
586 ];
587
588 # <button> specific handling
589 # see remarks on http://msdn.microsoft.com/en-us/library/ie/ms535211%28v=vs.85%29.aspx
590 $cases[] = [ '<button type="submit"></button>',
591 'button', [ 'type' => 'submit' ],
592 'According to standard the default type is "submit". '
593 . 'Depending on compatibility mode IE might use "button", instead.',
594 ];
595
596 # <select> specific handling
597 $cases[] = [ '<select multiple=""></select>',
598 'select', [ 'size' => '4', 'multiple' => true ],
599 ];
600 # .. with numeric value
601 $cases[] = [ '<select multiple=""></select>',
602 'select', [ 'size' => 4, 'multiple' => true ],
603 ];
604 $cases[] = [ '<select></select>',
605 'select', [ 'size' => '1', 'multiple' => false ],
606 ];
607 # .. with numeric value
608 $cases[] = [ '<select></select>',
609 'select', [ 'size' => 1, 'multiple' => false ],
610 ];
611
612 # Passing an array as value
613 $cases[] = [ '<a class="css-class-one css-class-two"></a>',
614 'a', [ 'class' => [ 'css-class-one', 'css-class-two' ] ],
615 "dropDefaults accepts values given as an array"
616 ];
617
618 # FIXME: doDropDefault should remove defaults given in an array
619 # Expected should be '<a></a>'
620 $cases[] = [ '<a class=""></a>',
621 'a', [ 'class' => [ '', '' ] ],
622 "dropDefaults accepts values given as an array"
623 ];
624
625 # Craft the Html elements
626 $ret = [];
627 foreach ( $cases as $case ) {
628 $ret[] = [
629 $case[0],
630 $case[1], $case[2],
631 isset( $case[3] ) ? $case[3] : ''
632 ];
633 }
634
635 return $ret;
636 }
637
638 /**
639 * @covers Html::expandAttributes
640 */
641 public function testFormValidationBlacklist() {
642 $this->assertEmpty(
643 Html::expandAttributes( [
644 'min' => 1,
645 'max' => 100,
646 'pattern' => 'abc',
647 'required' => true,
648 'step' => 2
649 ] ),
650 'Blacklist form validation attributes.'
651 );
652 $this->assertEquals(
653 ' step="any"',
654 Html::expandAttributes(
655 [
656 'min' => 1,
657 'max' => 100,
658 'pattern' => 'abc',
659 'required' => true,
660 'step' => 'any'
661 ],
662 'Allow special case "step=any".'
663 )
664 );
665 }
666
667 public function testWrapperInput() {
668 $this->assertEquals(
669 '<input type="radio" value="testval" name="testname"/>',
670 Html::input( 'testname', 'testval', 'radio' ),
671 'Input wrapper with type and value.'
672 );
673 $this->assertEquals(
674 '<input name="testname"/>',
675 Html::input( 'testname' ),
676 'Input wrapper with all default values.'
677 );
678 }
679
680 public function testWrapperCheck() {
681 $this->assertEquals(
682 '<input type="checkbox" value="1" name="testname"/>',
683 Html::check( 'testname' ),
684 'Checkbox wrapper unchecked.'
685 );
686 $this->assertEquals(
687 '<input checked="" type="checkbox" value="1" name="testname"/>',
688 Html::check( 'testname', true ),
689 'Checkbox wrapper checked.'
690 );
691 $this->assertEquals(
692 '<input type="checkbox" value="testval" name="testname"/>',
693 Html::check( 'testname', false, [ 'value' => 'testval' ] ),
694 'Checkbox wrapper with a value override.'
695 );
696 }
697
698 public function testWrapperRadio() {
699 $this->assertEquals(
700 '<input type="radio" value="1" name="testname"/>',
701 Html::radio( 'testname' ),
702 'Radio wrapper unchecked.'
703 );
704 $this->assertEquals(
705 '<input checked="" type="radio" value="1" name="testname"/>',
706 Html::radio( 'testname', true ),
707 'Radio wrapper checked.'
708 );
709 $this->assertEquals(
710 '<input type="radio" value="testval" name="testname"/>',
711 Html::radio( 'testname', false, [ 'value' => 'testval' ] ),
712 'Radio wrapper with a value override.'
713 );
714 }
715
716 public function testWrapperLabel() {
717 $this->assertEquals(
718 '<label for="testid">testlabel</label>',
719 Html::label( 'testlabel', 'testid' ),
720 'Label wrapper'
721 );
722 }
723
724 public static function provideSrcSetImages() {
725 return [
726 [ [], '', 'when there are no images, return empty string' ],
727 [
728 [ '1x' => '1x.png', '1.5x' => '1_5x.png', '2x' => '2x.png' ],
729 '1x.png 1x, 1_5x.png 1.5x, 2x.png 2x',
730 'pixel depth keys may include a trailing "x"'
731 ],
732 [
733 [ '1' => '1x.png', '1.5' => '1_5x.png', '2' => '2x.png' ],
734 '1x.png 1x, 1_5x.png 1.5x, 2x.png 2x',
735 'pixel depth keys may omit a trailing "x"'
736 ],
737 [
738 [ '1' => 'small.png', '1.5' => 'large.png', '2' => 'large.png' ],
739 'small.png 1x, large.png 1.5x',
740 'omit larger duplicates'
741 ],
742 [
743 [ '1' => 'small.png', '2' => 'large.png', '1.5' => 'large.png' ],
744 'small.png 1x, large.png 1.5x',
745 'omit larger duplicates in irregular order'
746 ],
747 ];
748 }
749
750 /**
751 * @dataProvider provideSrcSetImages
752 * @covers Html::srcSet
753 */
754 public function testSrcSet( $images, $expected, $message ) {
755 $this->assertEquals( Html::srcSet( $images ), $expected, $message );
756 }
757 }
758
759 class HtmlTestValue {
760 function __toString() {
761 return 'stringValue';
762 }
763 }