API: Remove deprecated response values from action=login
[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 later 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[] = [ '<command/>',
518 'command', [ 'type' => 'command' ]
519 ];
520
521 $cases[] = [ '<form></form>',
522 'form', [ 'action' => 'GET' ]
523 ];
524 $cases[] = [ '<form></form>',
525 'form', [ 'autocomplete' => 'on' ]
526 ];
527 $cases[] = [ '<form></form>',
528 'form', [ 'enctype' => 'application/x-www-form-urlencoded' ]
529 ];
530
531 $cases[] = [ '<input/>',
532 'input', [ 'formaction' => 'GET' ]
533 ];
534 $cases[] = [ '<input/>',
535 'input', [ 'type' => 'text' ]
536 ];
537
538 $cases[] = [ '<keygen/>',
539 'keygen', [ 'keytype' => 'rsa' ]
540 ];
541
542 $cases[] = [ '<link/>',
543 'link', [ 'media' => 'all' ]
544 ];
545
546 $cases[] = [ '<menu></menu>',
547 'menu', [ 'type' => 'list' ]
548 ];
549
550 $cases[] = [ '<script></script>',
551 'script', [ 'type' => 'text/javascript' ]
552 ];
553
554 $cases[] = [ '<style></style>',
555 'style', [ 'media' => 'all' ]
556 ];
557 $cases[] = [ '<style></style>',
558 'style', [ 'type' => 'text/css' ]
559 ];
560
561 $cases[] = [ '<textarea></textarea>',
562 'textarea', [ 'wrap' => 'soft' ]
563 ];
564
565 # ## SPECIFIC CASES
566
567 # <link type="text/css">
568 $cases[] = [ '<link/>',
569 'link', [ 'type' => 'text/css' ]
570 ];
571
572 # <input> specific handling
573 $cases[] = [ '<input type="checkbox"/>',
574 'input', [ 'type' => 'checkbox', 'value' => 'on' ],
575 'Default value "on" is stripped of checkboxes',
576 ];
577 $cases[] = [ '<input type="radio"/>',
578 'input', [ 'type' => 'radio', 'value' => 'on' ],
579 'Default value "on" is stripped of radio buttons',
580 ];
581 $cases[] = [ '<input type="submit" value="Submit"/>',
582 'input', [ 'type' => 'submit', 'value' => 'Submit' ],
583 'Default value "Submit" is kept on submit buttons (for possible l10n issues)',
584 ];
585 $cases[] = [ '<input type="color"/>',
586 'input', [ 'type' => 'color', 'value' => '' ],
587 ];
588 $cases[] = [ '<input type="range"/>',
589 'input', [ 'type' => 'range', 'value' => '' ],
590 ];
591
592 # <button> specific handling
593 # see remarks on http://msdn.microsoft.com/en-us/library/ie/ms535211%28v=vs.85%29.aspx
594 $cases[] = [ '<button type="submit"></button>',
595 'button', [ 'type' => 'submit' ],
596 'According to standard the default type is "submit". '
597 . 'Depending on compatibility mode IE might use "button", instead.',
598 ];
599
600 # <select> specific handling
601 $cases[] = [ '<select multiple=""></select>',
602 'select', [ 'size' => '4', 'multiple' => true ],
603 ];
604 # .. with numeric value
605 $cases[] = [ '<select multiple=""></select>',
606 'select', [ 'size' => 4, 'multiple' => true ],
607 ];
608 $cases[] = [ '<select></select>',
609 'select', [ 'size' => '1', 'multiple' => false ],
610 ];
611 # .. with numeric value
612 $cases[] = [ '<select></select>',
613 'select', [ 'size' => 1, 'multiple' => false ],
614 ];
615
616 # Passing an array as value
617 $cases[] = [ '<a class="css-class-one css-class-two"></a>',
618 'a', [ 'class' => [ 'css-class-one', 'css-class-two' ] ],
619 "dropDefaults accepts values given as an array"
620 ];
621
622 # FIXME: doDropDefault should remove defaults given in an array
623 # Expected should be '<a></a>'
624 $cases[] = [ '<a class=""></a>',
625 'a', [ 'class' => [ '', '' ] ],
626 "dropDefaults accepts values given as an array"
627 ];
628
629 # Craft the Html elements
630 $ret = [];
631 foreach ( $cases as $case ) {
632 $ret[] = [
633 $case[0],
634 $case[1], $case[2],
635 isset( $case[3] ) ? $case[3] : ''
636 ];
637 }
638
639 return $ret;
640 }
641
642 /**
643 * @covers Html::expandAttributes
644 */
645 public function testFormValidationBlacklist() {
646 $this->assertEmpty(
647 Html::expandAttributes( [
648 'min' => 1,
649 'max' => 100,
650 'pattern' => 'abc',
651 'required' => true,
652 'step' => 2
653 ] ),
654 'Blacklist form validation attributes.'
655 );
656 $this->assertEquals(
657 ' step="any"',
658 Html::expandAttributes(
659 [
660 'min' => 1,
661 'max' => 100,
662 'pattern' => 'abc',
663 'required' => true,
664 'step' => 'any'
665 ],
666 'Allow special case "step=any".'
667 )
668 );
669 }
670
671 public function testWrapperInput() {
672 $this->assertEquals(
673 '<input type="radio" value="testval" name="testname"/>',
674 Html::input( 'testname', 'testval', 'radio' ),
675 'Input wrapper with type and value.'
676 );
677 $this->assertEquals(
678 '<input name="testname"/>',
679 Html::input( 'testname' ),
680 'Input wrapper with all default values.'
681 );
682 }
683
684 public function testWrapperCheck() {
685 $this->assertEquals(
686 '<input type="checkbox" value="1" name="testname"/>',
687 Html::check( 'testname' ),
688 'Checkbox wrapper unchecked.'
689 );
690 $this->assertEquals(
691 '<input checked="" type="checkbox" value="1" name="testname"/>',
692 Html::check( 'testname', true ),
693 'Checkbox wrapper checked.'
694 );
695 $this->assertEquals(
696 '<input type="checkbox" value="testval" name="testname"/>',
697 Html::check( 'testname', false, [ 'value' => 'testval' ] ),
698 'Checkbox wrapper with a value override.'
699 );
700 }
701
702 public function testWrapperRadio() {
703 $this->assertEquals(
704 '<input type="radio" value="1" name="testname"/>',
705 Html::radio( 'testname' ),
706 'Radio wrapper unchecked.'
707 );
708 $this->assertEquals(
709 '<input checked="" type="radio" value="1" name="testname"/>',
710 Html::radio( 'testname', true ),
711 'Radio wrapper checked.'
712 );
713 $this->assertEquals(
714 '<input type="radio" value="testval" name="testname"/>',
715 Html::radio( 'testname', false, [ 'value' => 'testval' ] ),
716 'Radio wrapper with a value override.'
717 );
718 }
719
720 public function testWrapperLabel() {
721 $this->assertEquals(
722 '<label for="testid">testlabel</label>',
723 Html::label( 'testlabel', 'testid' ),
724 'Label wrapper'
725 );
726 }
727
728 public static function provideSrcSetImages() {
729 return [
730 [ [], '', 'when there are no images, return empty string' ],
731 [
732 [ '1x' => '1x.png', '1.5x' => '1_5x.png', '2x' => '2x.png' ],
733 '1x.png 1x, 1_5x.png 1.5x, 2x.png 2x',
734 'pixel depth keys may include a trailing "x"'
735 ],
736 [
737 [ '1' => '1x.png', '1.5' => '1_5x.png', '2' => '2x.png' ],
738 '1x.png 1x, 1_5x.png 1.5x, 2x.png 2x',
739 'pixel depth keys may omit a trailing "x"'
740 ],
741 [
742 [ '1' => 'small.png', '1.5' => 'large.png', '2' => 'large.png' ],
743 'small.png 1x, large.png 1.5x',
744 'omit larger duplicates'
745 ],
746 [
747 [ '1' => 'small.png', '2' => 'large.png', '1.5' => 'large.png' ],
748 'small.png 1x, large.png 1.5x',
749 'omit larger duplicates in irregular order'
750 ],
751 ];
752 }
753
754 /**
755 * @dataProvider provideSrcSetImages
756 * @covers Html::srcSet
757 */
758 public function testSrcSet( $images, $expected, $message ) {
759 $this->assertEquals( Html::srcSet( $images ), $expected, $message );
760 }
761 }
762
763 class HtmlTestValue {
764 function __toString() {
765 return 'stringValue';
766 }
767 }