Add tablesUsed to RevisionStoreDbTest
[lhc/web/wiklou.git] / tests / phpunit / includes / HtmlTest.php
1 <?php
2
3 class HtmlTest extends MediaWikiTestCase {
4
5 protected function setUp() {
6 parent::setUp();
7
8 $this->setMwGlobals( [
9 'wgUseMediaWikiUIEverywhere' => false,
10 ] );
11
12 $langObj = Language::factory( 'en' );
13
14 // Hardcode namespaces during test runs,
15 // so that html output based on existing namespaces
16 // can be properly evaluated.
17 $langObj->setNamespaces( [
18 -2 => 'Media',
19 -1 => 'Special',
20 0 => '',
21 1 => 'Talk',
22 2 => 'User',
23 3 => 'User_talk',
24 4 => 'MyWiki',
25 5 => 'MyWiki_Talk',
26 6 => 'File',
27 7 => 'File_talk',
28 8 => 'MediaWiki',
29 9 => 'MediaWiki_talk',
30 10 => 'Template',
31 11 => 'Template_talk',
32 14 => 'Category',
33 15 => 'Category_talk',
34 100 => 'Custom',
35 101 => 'Custom_talk',
36 ] );
37 $this->setUserLang( $langObj );
38 $this->setContentLang( $langObj );
39 }
40
41 /**
42 * @covers Html::element
43 * @covers Html::rawElement
44 * @covers Html::openElement
45 * @covers Html::closeElement
46 */
47 public function testElementBasics() {
48 $this->assertEquals(
49 '<img/>',
50 Html::element( 'img', null, '' ),
51 'Self-closing tag for short-tag elements'
52 );
53
54 $this->assertEquals(
55 '<element></element>',
56 Html::element( 'element', null, null ),
57 'Close tag for empty element (null, null)'
58 );
59
60 $this->assertEquals(
61 '<element></element>',
62 Html::element( 'element', [], '' ),
63 'Close tag for empty element (array, string)'
64 );
65 }
66
67 public function dataXmlMimeType() {
68 return [
69 // ( $mimetype, $isXmlMimeType )
70 # HTML is not an XML MimeType
71 [ 'text/html', false ],
72 # XML is an XML MimeType
73 [ 'text/xml', true ],
74 [ 'application/xml', true ],
75 # XHTML is an XML MimeType
76 [ 'application/xhtml+xml', true ],
77 # Make sure other +xml MimeTypes are supported
78 # SVG is another random MimeType even though we don't use it
79 [ 'image/svg+xml', true ],
80 # Complete random other MimeTypes are not XML
81 [ 'text/plain', false ],
82 ];
83 }
84
85 /**
86 * @dataProvider dataXmlMimeType
87 * @covers Html::isXmlMimeType
88 */
89 public function testXmlMimeType( $mimetype, $isXmlMimeType ) {
90 $this->assertEquals( $isXmlMimeType, Html::isXmlMimeType( $mimetype ) );
91 }
92
93 /**
94 * @covers Html::expandAttributes
95 */
96 public function testExpandAttributesSkipsNullAndFalse() {
97 # ## EMPTY ########
98 $this->assertEmpty(
99 Html::expandAttributes( [ 'foo' => null ] ),
100 'skip keys with null value'
101 );
102 $this->assertEmpty(
103 Html::expandAttributes( [ 'foo' => false ] ),
104 'skip keys with false value'
105 );
106 $this->assertEquals(
107 ' foo=""',
108 Html::expandAttributes( [ 'foo' => '' ] ),
109 'keep keys with an empty string'
110 );
111 }
112
113 /**
114 * @covers Html::expandAttributes
115 */
116 public function testExpandAttributesForBooleans() {
117 $this->assertEquals(
118 '',
119 Html::expandAttributes( [ 'selected' => false ] ),
120 'Boolean attributes do not generates output when value is false'
121 );
122 $this->assertEquals(
123 '',
124 Html::expandAttributes( [ 'selected' => null ] ),
125 'Boolean attributes do not generates output when value is null'
126 );
127
128 $this->assertEquals(
129 ' selected=""',
130 Html::expandAttributes( [ 'selected' => true ] ),
131 'Boolean attributes have no value when value is true'
132 );
133 $this->assertEquals(
134 ' selected=""',
135 Html::expandAttributes( [ 'selected' ] ),
136 'Boolean attributes have no value when value is true (passed as numerical array)'
137 );
138 }
139
140 /**
141 * @covers Html::expandAttributes
142 */
143 public function testExpandAttributesForNumbers() {
144 $this->assertEquals(
145 ' value="1"',
146 Html::expandAttributes( [ 'value' => 1 ] ),
147 'Integer value is cast to a string'
148 );
149 $this->assertEquals(
150 ' value="1.1"',
151 Html::expandAttributes( [ 'value' => 1.1 ] ),
152 'Float value is cast to a string'
153 );
154 }
155
156 /**
157 * @covers Html::expandAttributes
158 */
159 public function testExpandAttributesForObjects() {
160 $this->assertEquals(
161 ' value="stringValue"',
162 Html::expandAttributes( [ 'value' => new HtmlTestValue() ] ),
163 'Object value is converted to a string'
164 );
165 }
166
167 /**
168 * Test for Html::expandAttributes()
169 * Please note it output a string prefixed with a space!
170 * @covers Html::expandAttributes
171 */
172 public function testExpandAttributesVariousExpansions() {
173 # ## NOT EMPTY ####
174 $this->assertEquals(
175 ' empty_string=""',
176 Html::expandAttributes( [ 'empty_string' => '' ] ),
177 'Empty string is always quoted'
178 );
179 $this->assertEquals(
180 ' key="value"',
181 Html::expandAttributes( [ 'key' => 'value' ] ),
182 'Simple string value needs no quotes'
183 );
184 $this->assertEquals(
185 ' one="1"',
186 Html::expandAttributes( [ 'one' => 1 ] ),
187 'Number 1 value needs no quotes'
188 );
189 $this->assertEquals(
190 ' zero="0"',
191 Html::expandAttributes( [ 'zero' => 0 ] ),
192 'Number 0 value needs no quotes'
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 * @covers Html::namespaceSelectorOptions
308 */
309 public function testNamespaceSelector() {
310 $this->assertEquals(
311 '<select id="namespace" name="namespace">' . "\n" .
312 '<option value="0">(Main)</option>' . "\n" .
313 '<option value="1">Talk</option>' . "\n" .
314 '<option value="2">User</option>' . "\n" .
315 '<option value="3">User talk</option>' . "\n" .
316 '<option value="4">MyWiki</option>' . "\n" .
317 '<option value="5">MyWiki Talk</option>' . "\n" .
318 '<option value="6">File</option>' . "\n" .
319 '<option value="7">File talk</option>' . "\n" .
320 '<option value="8">MediaWiki</option>' . "\n" .
321 '<option value="9">MediaWiki talk</option>' . "\n" .
322 '<option value="10">Template</option>' . "\n" .
323 '<option value="11">Template talk</option>' . "\n" .
324 '<option value="14">Category</option>' . "\n" .
325 '<option value="15">Category talk</option>' . "\n" .
326 '<option value="100">Custom</option>' . "\n" .
327 '<option value="101">Custom talk</option>' . "\n" .
328 '</select>',
329 Html::namespaceSelector(),
330 'Basic namespace selector without custom options'
331 );
332
333 $this->assertEquals(
334 '<label for="mw-test-namespace">Select a namespace:</label>&#160;' .
335 '<select id="mw-test-namespace" name="wpNamespace">' . "\n" .
336 '<option value="all">all</option>' . "\n" .
337 '<option value="0">(Main)</option>' . "\n" .
338 '<option value="1">Talk</option>' . "\n" .
339 '<option value="2" selected="">User</option>' . "\n" .
340 '<option value="3">User talk</option>' . "\n" .
341 '<option value="4">MyWiki</option>' . "\n" .
342 '<option value="5">MyWiki Talk</option>' . "\n" .
343 '<option value="6">File</option>' . "\n" .
344 '<option value="7">File talk</option>' . "\n" .
345 '<option value="8">MediaWiki</option>' . "\n" .
346 '<option value="9">MediaWiki talk</option>' . "\n" .
347 '<option value="10">Template</option>' . "\n" .
348 '<option value="11">Template talk</option>' . "\n" .
349 '<option value="14">Category</option>' . "\n" .
350 '<option value="15">Category talk</option>' . "\n" .
351 '<option value="100">Custom</option>' . "\n" .
352 '<option value="101">Custom talk</option>' . "\n" .
353 '</select>',
354 Html::namespaceSelector(
355 [ 'selected' => '2', 'all' => 'all', 'label' => 'Select a namespace:' ],
356 [ 'name' => 'wpNamespace', 'id' => 'mw-test-namespace' ]
357 ),
358 'Basic namespace selector with custom values'
359 );
360
361 $this->assertEquals(
362 '<label for="namespace">Select a namespace:</label>&#160;' .
363 '<select id="namespace" name="namespace">' . "\n" .
364 '<option value="0">(Main)</option>' . "\n" .
365 '<option value="1">Talk</option>' . "\n" .
366 '<option value="2">User</option>' . "\n" .
367 '<option value="3">User talk</option>' . "\n" .
368 '<option value="4">MyWiki</option>' . "\n" .
369 '<option value="5">MyWiki Talk</option>' . "\n" .
370 '<option value="6">File</option>' . "\n" .
371 '<option value="7">File talk</option>' . "\n" .
372 '<option value="8">MediaWiki</option>' . "\n" .
373 '<option value="9">MediaWiki talk</option>' . "\n" .
374 '<option value="10">Template</option>' . "\n" .
375 '<option value="11">Template talk</option>' . "\n" .
376 '<option value="14">Category</option>' . "\n" .
377 '<option value="15">Category talk</option>' . "\n" .
378 '<option value="100">Custom</option>' . "\n" .
379 '<option value="101">Custom talk</option>' . "\n" .
380 '</select>',
381 Html::namespaceSelector(
382 [ 'label' => 'Select a namespace:' ]
383 ),
384 'Basic namespace selector with a custom label but no id attribtue for the <select>'
385 );
386 }
387
388 /**
389 * @covers Html::namespaceSelector
390 */
391 public function testCanFilterOutNamespaces() {
392 $this->assertEquals(
393 '<select id="namespace" name="namespace">' . "\n" .
394 '<option value="2">User</option>' . "\n" .
395 '<option value="4">MyWiki</option>' . "\n" .
396 '<option value="5">MyWiki Talk</option>' . "\n" .
397 '<option value="6">File</option>' . "\n" .
398 '<option value="7">File talk</option>' . "\n" .
399 '<option value="8">MediaWiki</option>' . "\n" .
400 '<option value="9">MediaWiki talk</option>' . "\n" .
401 '<option value="10">Template</option>' . "\n" .
402 '<option value="11">Template talk</option>' . "\n" .
403 '<option value="14">Category</option>' . "\n" .
404 '<option value="15">Category talk</option>' . "\n" .
405 '</select>',
406 Html::namespaceSelector(
407 [ 'exclude' => [ 0, 1, 3, 100, 101 ] ]
408 ),
409 'Namespace selector namespace filtering.'
410 );
411 }
412
413 /**
414 * @covers Html::namespaceSelector
415 */
416 public function testCanDisableANamespaces() {
417 $this->assertEquals(
418 '<select id="namespace" name="namespace">' . "\n" .
419 '<option disabled="" value="0">(Main)</option>' . "\n" .
420 '<option disabled="" value="1">Talk</option>' . "\n" .
421 '<option disabled="" value="2">User</option>' . "\n" .
422 '<option disabled="" value="3">User talk</option>' . "\n" .
423 '<option disabled="" value="4">MyWiki</option>' . "\n" .
424 '<option value="5">MyWiki Talk</option>' . "\n" .
425 '<option value="6">File</option>' . "\n" .
426 '<option value="7">File talk</option>' . "\n" .
427 '<option value="8">MediaWiki</option>' . "\n" .
428 '<option value="9">MediaWiki talk</option>' . "\n" .
429 '<option value="10">Template</option>' . "\n" .
430 '<option value="11">Template talk</option>' . "\n" .
431 '<option value="14">Category</option>' . "\n" .
432 '<option value="15">Category talk</option>' . "\n" .
433 '<option value="100">Custom</option>' . "\n" .
434 '<option value="101">Custom talk</option>' . "\n" .
435 '</select>',
436 Html::namespaceSelector( [
437 'disable' => [ 0, 1, 2, 3, 4 ]
438 ] ),
439 'Namespace selector namespace disabling'
440 );
441 }
442
443 /**
444 * @dataProvider provideHtml5InputTypes
445 * @covers Html::element
446 */
447 public function testHtmlElementAcceptsNewHtml5TypesInHtml5Mode( $HTML5InputType ) {
448 $this->assertEquals(
449 '<input type="' . $HTML5InputType . '"/>',
450 Html::element( 'input', [ 'type' => $HTML5InputType ] ),
451 'In HTML5, Html::element() should accept type="' . $HTML5InputType . '"'
452 );
453 }
454
455 /**
456 * @covers Html::warningBox
457 * @covers Html::messageBox
458 */
459 public function testWarningBox() {
460 $this->assertEquals(
461 Html::warningBox( 'warn' ),
462 '<div class="warningbox">warn</div>'
463 );
464 }
465
466 /**
467 * @covers Html::errorBox
468 * @covers Html::messageBox
469 */
470 public function testErrorBox() {
471 $this->assertEquals(
472 Html::errorBox( 'err' ),
473 '<div class="errorbox">err</div>'
474 );
475 $this->assertEquals(
476 Html::errorBox( 'err', 'heading' ),
477 '<div class="errorbox"><h2>heading</h2>err</div>'
478 );
479 }
480
481 /**
482 * @covers Html::successBox
483 * @covers Html::messageBox
484 */
485 public function testSuccessBox() {
486 $this->assertEquals(
487 Html::successBox( 'great' ),
488 '<div class="successbox">great</div>'
489 );
490 $this->assertEquals(
491 Html::successBox( '<script>beware no escaping!</script>' ),
492 '<div class="successbox"><script>beware no escaping!</script></div>'
493 );
494 }
495
496 /**
497 * List of input element types values introduced by HTML5
498 * Full list at https://www.w3.org/TR/html-markup/input.html
499 */
500 public static function provideHtml5InputTypes() {
501 $types = [
502 'datetime',
503 'datetime-local',
504 'date',
505 'month',
506 'time',
507 'week',
508 'number',
509 'range',
510 'email',
511 'url',
512 'search',
513 'tel',
514 'color',
515 ];
516 $cases = [];
517 foreach ( $types as $type ) {
518 $cases[] = [ $type ];
519 }
520
521 return $cases;
522 }
523
524 /**
525 * Test out Html::element drops or enforces default value
526 * @covers Html::dropDefaults
527 * @dataProvider provideElementsWithAttributesHavingDefaultValues
528 */
529 public function testDropDefaults( $expected, $element, $attribs, $message = '' ) {
530 $this->assertEquals( $expected, Html::element( $element, $attribs ), $message );
531 }
532
533 public static function provideElementsWithAttributesHavingDefaultValues() {
534 # Use cases in a concise format:
535 # <expected>, <element name>, <array of attributes> [, <message>]
536 # Will be mapped to Html::element()
537 $cases = [];
538
539 # ## Generic cases, match $attribDefault static array
540 $cases[] = [ '<area/>',
541 'area', [ 'shape' => 'rect' ]
542 ];
543
544 $cases[] = [ '<button type="submit"></button>',
545 'button', [ 'formaction' => 'GET' ]
546 ];
547 $cases[] = [ '<button type="submit"></button>',
548 'button', [ 'formenctype' => 'application/x-www-form-urlencoded' ]
549 ];
550
551 $cases[] = [ '<canvas></canvas>',
552 'canvas', [ 'height' => '150' ]
553 ];
554 $cases[] = [ '<canvas></canvas>',
555 'canvas', [ 'width' => '300' ]
556 ];
557 # Also check with numeric values
558 $cases[] = [ '<canvas></canvas>',
559 'canvas', [ 'height' => 150 ]
560 ];
561 $cases[] = [ '<canvas></canvas>',
562 'canvas', [ 'width' => 300 ]
563 ];
564
565 $cases[] = [ '<form></form>',
566 'form', [ 'action' => 'GET' ]
567 ];
568 $cases[] = [ '<form></form>',
569 'form', [ 'autocomplete' => 'on' ]
570 ];
571 $cases[] = [ '<form></form>',
572 'form', [ 'enctype' => 'application/x-www-form-urlencoded' ]
573 ];
574
575 $cases[] = [ '<input/>',
576 'input', [ 'formaction' => 'GET' ]
577 ];
578 $cases[] = [ '<input/>',
579 'input', [ 'type' => 'text' ]
580 ];
581
582 $cases[] = [ '<keygen/>',
583 'keygen', [ 'keytype' => 'rsa' ]
584 ];
585
586 $cases[] = [ '<link/>',
587 'link', [ 'media' => 'all' ]
588 ];
589
590 $cases[] = [ '<menu></menu>',
591 'menu', [ 'type' => 'list' ]
592 ];
593
594 $cases[] = [ '<script></script>',
595 'script', [ 'type' => 'text/javascript' ]
596 ];
597
598 $cases[] = [ '<style></style>',
599 'style', [ 'media' => 'all' ]
600 ];
601 $cases[] = [ '<style></style>',
602 'style', [ 'type' => 'text/css' ]
603 ];
604
605 $cases[] = [ '<textarea></textarea>',
606 'textarea', [ 'wrap' => 'soft' ]
607 ];
608
609 # ## SPECIFIC CASES
610
611 # <link type="text/css">
612 $cases[] = [ '<link/>',
613 'link', [ 'type' => 'text/css' ]
614 ];
615
616 # <input> specific handling
617 $cases[] = [ '<input type="checkbox"/>',
618 'input', [ 'type' => 'checkbox', 'value' => 'on' ],
619 'Default value "on" is stripped of checkboxes',
620 ];
621 $cases[] = [ '<input type="radio"/>',
622 'input', [ 'type' => 'radio', 'value' => 'on' ],
623 'Default value "on" is stripped of radio buttons',
624 ];
625 $cases[] = [ '<input type="submit" value="Submit"/>',
626 'input', [ 'type' => 'submit', 'value' => 'Submit' ],
627 'Default value "Submit" is kept on submit buttons (for possible l10n issues)',
628 ];
629 $cases[] = [ '<input type="color"/>',
630 'input', [ 'type' => 'color', 'value' => '' ],
631 ];
632 $cases[] = [ '<input type="range"/>',
633 'input', [ 'type' => 'range', 'value' => '' ],
634 ];
635
636 # <button> specific handling
637 # see remarks on https://msdn.microsoft.com/library/ms535211(v=vs.85).aspx
638 $cases[] = [ '<button type="submit"></button>',
639 'button', [ 'type' => 'submit' ],
640 'According to standard the default type is "submit". '
641 . 'Depending on compatibility mode IE might use "button", instead.',
642 ];
643
644 # <select> specific handling
645 $cases[] = [ '<select multiple=""></select>',
646 'select', [ 'size' => '4', 'multiple' => true ],
647 ];
648 # .. with numeric value
649 $cases[] = [ '<select multiple=""></select>',
650 'select', [ 'size' => 4, 'multiple' => true ],
651 ];
652 $cases[] = [ '<select></select>',
653 'select', [ 'size' => '1', 'multiple' => false ],
654 ];
655 # .. with numeric value
656 $cases[] = [ '<select></select>',
657 'select', [ 'size' => 1, 'multiple' => false ],
658 ];
659
660 # Passing an array as value
661 $cases[] = [ '<a class="css-class-one css-class-two"></a>',
662 'a', [ 'class' => [ 'css-class-one', 'css-class-two' ] ],
663 "dropDefaults accepts values given as an array"
664 ];
665
666 # FIXME: doDropDefault should remove defaults given in an array
667 # Expected should be '<a></a>'
668 $cases[] = [ '<a class=""></a>',
669 'a', [ 'class' => [ '', '' ] ],
670 "dropDefaults accepts values given as an array"
671 ];
672
673 # Craft the Html elements
674 $ret = [];
675 foreach ( $cases as $case ) {
676 $ret[] = [
677 $case[0],
678 $case[1], $case[2],
679 isset( $case[3] ) ? $case[3] : ''
680 ];
681 }
682
683 return $ret;
684 }
685
686 /**
687 * @covers Html::input
688 */
689 public function testWrapperInput() {
690 $this->assertEquals(
691 '<input type="radio" value="testval" name="testname"/>',
692 Html::input( 'testname', 'testval', 'radio' ),
693 'Input wrapper with type and value.'
694 );
695 $this->assertEquals(
696 '<input name="testname"/>',
697 Html::input( 'testname' ),
698 'Input wrapper with all default values.'
699 );
700 }
701
702 /**
703 * @covers Html::check
704 */
705 public function testWrapperCheck() {
706 $this->assertEquals(
707 '<input type="checkbox" value="1" name="testname"/>',
708 Html::check( 'testname' ),
709 'Checkbox wrapper unchecked.'
710 );
711 $this->assertEquals(
712 '<input checked="" type="checkbox" value="1" name="testname"/>',
713 Html::check( 'testname', true ),
714 'Checkbox wrapper checked.'
715 );
716 $this->assertEquals(
717 '<input type="checkbox" value="testval" name="testname"/>',
718 Html::check( 'testname', false, [ 'value' => 'testval' ] ),
719 'Checkbox wrapper with a value override.'
720 );
721 }
722
723 /**
724 * @covers Html::radio
725 */
726 public function testWrapperRadio() {
727 $this->assertEquals(
728 '<input type="radio" value="1" name="testname"/>',
729 Html::radio( 'testname' ),
730 'Radio wrapper unchecked.'
731 );
732 $this->assertEquals(
733 '<input checked="" type="radio" value="1" name="testname"/>',
734 Html::radio( 'testname', true ),
735 'Radio wrapper checked.'
736 );
737 $this->assertEquals(
738 '<input type="radio" value="testval" name="testname"/>',
739 Html::radio( 'testname', false, [ 'value' => 'testval' ] ),
740 'Radio wrapper with a value override.'
741 );
742 }
743
744 /**
745 * @covers Html::label
746 */
747 public function testWrapperLabel() {
748 $this->assertEquals(
749 '<label for="testid">testlabel</label>',
750 Html::label( 'testlabel', 'testid' ),
751 'Label wrapper'
752 );
753 }
754
755 public static function provideSrcSetImages() {
756 return [
757 [ [], '', 'when there are no images, return empty string' ],
758 [
759 [ '1x' => '1x.png', '1.5x' => '1_5x.png', '2x' => '2x.png' ],
760 '1x.png 1x, 1_5x.png 1.5x, 2x.png 2x',
761 'pixel depth keys may include a trailing "x"'
762 ],
763 [
764 [ '1' => '1x.png', '1.5' => '1_5x.png', '2' => '2x.png' ],
765 '1x.png 1x, 1_5x.png 1.5x, 2x.png 2x',
766 'pixel depth keys may omit a trailing "x"'
767 ],
768 [
769 [ '1' => 'small.png', '1.5' => 'large.png', '2' => 'large.png' ],
770 'small.png 1x, large.png 1.5x',
771 'omit larger duplicates'
772 ],
773 [
774 [ '1' => 'small.png', '2' => 'large.png', '1.5' => 'large.png' ],
775 'small.png 1x, large.png 1.5x',
776 'omit larger duplicates in irregular order'
777 ],
778 ];
779 }
780
781 /**
782 * @dataProvider provideSrcSetImages
783 * @covers Html::srcSet
784 */
785 public function testSrcSet( $images, $expected, $message ) {
786 $this->assertEquals( Html::srcSet( $images ), $expected, $message );
787 }
788 }
789
790 class HtmlTestValue {
791 function __toString() {
792 return 'stringValue';
793 }
794 }