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