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