MediaWiki REL1_32
HtmlTest.php
Go to the documentation of this file.
1<?php
2
5
6 protected function setUp() {
7 parent::setUp();
8
9 $this->setMwGlobals( [
10 'wgUseMediaWikiUIEverywhere' => false,
11 ] );
12
13 $contLangObj = 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 $contLangObj->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->setContentLang( $contLangObj );
39
40 $userLangObj = Language::factory( 'es' );
41 $userLangObj->setNamespaces( [
42 -2 => "Medio",
43 -1 => "Especial",
44 0 => "",
45 1 => "Discusión",
46 2 => "Usuario",
47 3 => "Usuario discusión",
48 4 => "Wiki",
49 5 => "Wiki discusión",
50 6 => "Archivo",
51 7 => "Archivo discusión",
52 8 => "MediaWiki",
53 9 => "MediaWiki discusión",
54 10 => "Plantilla",
55 11 => "Plantilla discusión",
56 12 => "Ayuda",
57 13 => "Ayuda discusión",
58 14 => "Categoría",
59 15 => "Categoría discusión",
60 100 => "Personalizado",
61 101 => "Personalizado discusión",
62 ] );
63 $this->setUserLang( $userLangObj );
64
65 $this->restoreWarnings = false;
66 }
67
68 protected function tearDown() {
69 Language::factory( 'en' )->resetNamespaces();
70
71 if ( $this->restoreWarnings ) {
72 $this->restoreWarnings = false;
73 Wikimedia\restoreWarnings();
74 }
75
76 parent::tearDown();
77 }
78
85 public function testElementBasics() {
86 $this->assertEquals(
87 '<img/>',
88 Html::element( 'img', null, '' ),
89 'Self-closing tag for short-tag elements'
90 );
91
92 $this->assertEquals(
93 '<element></element>',
94 Html::element( 'element', null, null ),
95 'Close tag for empty element (null, null)'
96 );
97
98 $this->assertEquals(
99 '<element></element>',
100 Html::element( 'element', [], '' ),
101 'Close tag for empty element (array, string)'
102 );
103 }
104
105 public function dataXmlMimeType() {
106 return [
107 // ( $mimetype, $isXmlMimeType )
108 # HTML is not an XML MimeType
109 [ 'text/html', false ],
110 # XML is an XML MimeType
111 [ 'text/xml', true ],
112 [ 'application/xml', true ],
113 # XHTML is an XML MimeType
114 [ 'application/xhtml+xml', true ],
115 # Make sure other +xml MimeTypes are supported
116 # SVG is another random MimeType even though we don't use it
117 [ 'image/svg+xml', true ],
118 # Complete random other MimeTypes are not XML
119 [ 'text/plain', false ],
120 ];
121 }
122
127 public function testXmlMimeType( $mimetype, $isXmlMimeType ) {
128 $this->assertEquals( $isXmlMimeType, Html::isXmlMimeType( $mimetype ) );
129 }
130
135 # ## EMPTY ########
136 $this->assertEmpty(
137 Html::expandAttributes( [ 'foo' => null ] ),
138 'skip keys with null value'
139 );
140 $this->assertEmpty(
141 Html::expandAttributes( [ 'foo' => false ] ),
142 'skip keys with false value'
143 );
144 $this->assertEquals(
145 ' foo=""',
146 Html::expandAttributes( [ 'foo' => '' ] ),
147 'keep keys with an empty string'
148 );
149 }
150
155 $this->assertEquals(
156 '',
157 Html::expandAttributes( [ 'selected' => false ] ),
158 'Boolean attributes do not generates output when value is false'
159 );
160 $this->assertEquals(
161 '',
162 Html::expandAttributes( [ 'selected' => null ] ),
163 'Boolean attributes do not generates output when value is null'
164 );
165
166 $this->assertEquals(
167 ' selected=""',
168 Html::expandAttributes( [ 'selected' => true ] ),
169 'Boolean attributes have no value when value is true'
170 );
171 $this->assertEquals(
172 ' selected=""',
173 Html::expandAttributes( [ 'selected' ] ),
174 'Boolean attributes have no value when value is true (passed as numerical array)'
175 );
176 }
177
182 $this->assertEquals(
183 ' value="1"',
184 Html::expandAttributes( [ 'value' => 1 ] ),
185 'Integer value is cast to a string'
186 );
187 $this->assertEquals(
188 ' value="1.1"',
189 Html::expandAttributes( [ 'value' => 1.1 ] ),
190 'Float value is cast to a string'
191 );
192 }
193
198 $this->assertEquals(
199 ' value="stringValue"',
200 Html::expandAttributes( [ 'value' => new HtmlTestValue() ] ),
201 'Object value is converted to a string'
202 );
203 }
204
211 # ## NOT EMPTY ####
212 $this->assertEquals(
213 ' empty_string=""',
214 Html::expandAttributes( [ 'empty_string' => '' ] ),
215 'Empty string is always quoted'
216 );
217 $this->assertEquals(
218 ' key="value"',
219 Html::expandAttributes( [ 'key' => 'value' ] ),
220 'Simple string value needs no quotes'
221 );
222 $this->assertEquals(
223 ' one="1"',
224 Html::expandAttributes( [ 'one' => 1 ] ),
225 'Number 1 value needs no quotes'
226 );
227 $this->assertEquals(
228 ' zero="0"',
229 Html::expandAttributes( [ 'zero' => 0 ] ),
230 'Number 0 value needs no quotes'
231 );
232 }
233
241 # ## STRING VALUES
242 $this->assertEquals(
243 ' class="redundant spaces here"',
244 Html::expandAttributes( [ 'class' => ' redundant spaces here ' ] ),
245 'Normalization should strip redundant spaces'
246 );
247 $this->assertEquals(
248 ' class="foo bar"',
249 Html::expandAttributes( [ 'class' => 'foo bar foo bar bar' ] ),
250 'Normalization should remove duplicates in string-lists'
251 );
252 # ## "EMPTY" ARRAY VALUES
253 $this->assertEquals(
254 ' class=""',
255 Html::expandAttributes( [ 'class' => [] ] ),
256 'Value with an empty array'
257 );
258 $this->assertEquals(
259 ' class=""',
260 Html::expandAttributes( [ 'class' => [ null, '', ' ', ' ' ] ] ),
261 'Array with null, empty string and spaces'
262 );
263 # ## NON-EMPTY ARRAY VALUES
264 $this->assertEquals(
265 ' class="foo bar"',
266 Html::expandAttributes( [ 'class' => [
267 'foo',
268 'bar',
269 'foo',
270 'bar',
271 'bar',
272 ] ] ),
273 'Normalization should remove duplicates in the array'
274 );
275 $this->assertEquals(
276 ' class="foo bar"',
277 Html::expandAttributes( [ 'class' => [
278 'foo bar',
279 'bar foo',
280 'foo',
281 'bar bar',
282 ] ] ),
283 'Normalization should remove duplicates in string-lists in the array'
284 );
285 }
286
293 $this->assertEquals(
294 ' class="booltrue one"',
295 Html::expandAttributes( [ 'class' => [
296 'booltrue' => true,
297 'one' => 1,
298
299 # Method use isset() internally, make sure we do discard
300 # attributes values which have been assigned well known values
301 'emptystring' => '',
302 'boolfalse' => false,
303 'zero' => 0,
304 'null' => null,
305 ] ] )
306 );
307 }
308
318 $this->assertEquals(
319 ' class=""',
320 Html::expandAttributes( [ 'class' => [
321 'GREEN',
322 'GREEN' => false,
323 'GREEN',
324 ] ] )
325 );
326 }
327
333 // Real-life test case found in the Popups extension (see Gerrit cf0fd64),
334 // when used with an outdated BetaFeatures extension (see Gerrit deda1e7)
335 Html::expandAttributes( [
336 'src' => [
337 'ltr' => 'ltr.svg',
338 'rtl' => 'rtl.svg'
339 ]
340 ] );
341 }
342
347 public function testNamespaceSelector() {
348 $this->assertEquals(
349 '<select id="namespace" name="namespace">' . "\n" .
350 '<option value="0">(Principal)</option>' . "\n" .
351 '<option value="1">Talk</option>' . "\n" .
352 '<option value="2">User</option>' . "\n" .
353 '<option value="3">User talk</option>' . "\n" .
354 '<option value="4">MyWiki</option>' . "\n" .
355 '<option value="5">MyWiki Talk</option>' . "\n" .
356 '<option value="6">File</option>' . "\n" .
357 '<option value="7">File talk</option>' . "\n" .
358 '<option value="8">MediaWiki</option>' . "\n" .
359 '<option value="9">MediaWiki talk</option>' . "\n" .
360 '<option value="10">Template</option>' . "\n" .
361 '<option value="11">Template talk</option>' . "\n" .
362 '<option value="14">Category</option>' . "\n" .
363 '<option value="15">Category talk</option>' . "\n" .
364 '<option value="100">Custom</option>' . "\n" .
365 '<option value="101">Custom talk</option>' . "\n" .
366 '</select>',
367 Html::namespaceSelector(),
368 'Basic namespace selector without custom options'
369 );
370
371 $this->assertEquals(
372 '<label for="mw-test-namespace">Select a namespace:</label>' . "\u{00A0}" .
373 '<select id="mw-test-namespace" name="wpNamespace">' . "\n" .
374 '<option value="all">todos</option>' . "\n" .
375 '<option value="0">(Principal)</option>' . "\n" .
376 '<option value="1">Talk</option>' . "\n" .
377 '<option value="2" selected="">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 [ 'selected' => '2', 'all' => 'all', 'label' => 'Select a namespace:' ],
394 [ 'name' => 'wpNamespace', 'id' => 'mw-test-namespace' ]
395 ),
396 'Basic namespace selector with custom values'
397 );
398
399 $this->assertEquals(
400 '<label for="namespace">Select a namespace:</label>' . "\u{00A0}" .
401 '<select id="namespace" name="namespace">' . "\n" .
402 '<option value="0">(Principal)</option>' . "\n" .
403 '<option value="1">Talk</option>' . "\n" .
404 '<option value="2">User</option>' . "\n" .
405 '<option value="3">User talk</option>' . "\n" .
406 '<option value="4">MyWiki</option>' . "\n" .
407 '<option value="5">MyWiki Talk</option>' . "\n" .
408 '<option value="6">File</option>' . "\n" .
409 '<option value="7">File talk</option>' . "\n" .
410 '<option value="8">MediaWiki</option>' . "\n" .
411 '<option value="9">MediaWiki talk</option>' . "\n" .
412 '<option value="10">Template</option>' . "\n" .
413 '<option value="11">Template talk</option>' . "\n" .
414 '<option value="14">Category</option>' . "\n" .
415 '<option value="15">Category talk</option>' . "\n" .
416 '<option value="100">Custom</option>' . "\n" .
417 '<option value="101">Custom talk</option>' . "\n" .
418 '</select>',
419 Html::namespaceSelector(
420 [ 'label' => 'Select a namespace:' ]
421 ),
422 'Basic namespace selector with a custom label but no id attribtue for the <select>'
423 );
424 }
425
429 public function testCanFilterOutNamespaces() {
430 $this->assertEquals(
431 '<select id="namespace" name="namespace">' . "\n" .
432 '<option value="2">User</option>' . "\n" .
433 '<option value="4">MyWiki</option>' . "\n" .
434 '<option value="5">MyWiki Talk</option>' . "\n" .
435 '<option value="6">File</option>' . "\n" .
436 '<option value="7">File talk</option>' . "\n" .
437 '<option value="8">MediaWiki</option>' . "\n" .
438 '<option value="9">MediaWiki talk</option>' . "\n" .
439 '<option value="10">Template</option>' . "\n" .
440 '<option value="11">Template talk</option>' . "\n" .
441 '<option value="14">Category</option>' . "\n" .
442 '<option value="15">Category talk</option>' . "\n" .
443 '</select>',
444 Html::namespaceSelector(
445 [ 'exclude' => [ 0, 1, 3, 100, 101 ] ]
446 ),
447 'Namespace selector namespace filtering.'
448 );
449 }
450
454 public function testCanDisableANamespaces() {
455 $this->assertEquals(
456 '<select id="namespace" name="namespace">' . "\n" .
457 '<option disabled="" value="0">(Principal)</option>' . "\n" .
458 '<option disabled="" value="1">Talk</option>' . "\n" .
459 '<option disabled="" value="2">User</option>' . "\n" .
460 '<option disabled="" value="3">User talk</option>' . "\n" .
461 '<option disabled="" value="4">MyWiki</option>' . "\n" .
462 '<option value="5">MyWiki Talk</option>' . "\n" .
463 '<option value="6">File</option>' . "\n" .
464 '<option value="7">File talk</option>' . "\n" .
465 '<option value="8">MediaWiki</option>' . "\n" .
466 '<option value="9">MediaWiki talk</option>' . "\n" .
467 '<option value="10">Template</option>' . "\n" .
468 '<option value="11">Template talk</option>' . "\n" .
469 '<option value="14">Category</option>' . "\n" .
470 '<option value="15">Category talk</option>' . "\n" .
471 '<option value="100">Custom</option>' . "\n" .
472 '<option value="101">Custom talk</option>' . "\n" .
473 '</select>',
474 Html::namespaceSelector( [
475 'disable' => [ 0, 1, 2, 3, 4 ]
476 ] ),
477 'Namespace selector namespace disabling'
478 );
479 }
480
485 public function testHtmlElementAcceptsNewHtml5TypesInHtml5Mode( $HTML5InputType ) {
486 $this->assertEquals(
487 '<input type="' . $HTML5InputType . '"/>',
488 Html::element( 'input', [ 'type' => $HTML5InputType ] ),
489 'In HTML5, Html::element() should accept type="' . $HTML5InputType . '"'
490 );
491 }
492
497 public function testWarningBox() {
498 $this->assertEquals(
499 Html::warningBox( 'warn' ),
500 '<div class="warningbox">warn</div>'
501 );
502 }
503
508 public function testErrorBox() {
509 $this->assertEquals(
510 Html::errorBox( 'err' ),
511 '<div class="errorbox">err</div>'
512 );
513 $this->assertEquals(
514 Html::errorBox( 'err', 'heading' ),
515 '<div class="errorbox"><h2>heading</h2>err</div>'
516 );
517 $this->assertEquals(
518 Html::errorBox( 'err', '0' ),
519 '<div class="errorbox"><h2>0</h2>err</div>'
520 );
521 }
522
527 public function testSuccessBox() {
528 $this->assertEquals(
529 Html::successBox( 'great' ),
530 '<div class="successbox">great</div>'
531 );
532 $this->assertEquals(
533 Html::successBox( '<script>beware no escaping!</script>' ),
534 '<div class="successbox"><script>beware no escaping!</script></div>'
535 );
536 }
537
542 public static function provideHtml5InputTypes() {
543 $types = [
544 'datetime',
545 'datetime-local',
546 'date',
547 'month',
548 'time',
549 'week',
550 'number',
551 'range',
552 'email',
553 'url',
554 'search',
555 'tel',
556 'color',
557 ];
558 $cases = [];
559 foreach ( $types as $type ) {
560 $cases[] = [ $type ];
561 }
562
563 return $cases;
564 }
565
571 public function testDropDefaults( $expected, $element, $attribs, $message = '' ) {
572 $this->assertEquals( $expected, Html::element( $element, $attribs ), $message );
573 }
574
576 # Use cases in a concise format:
577 # <expected>, <element name>, <array of attributes> [, <message>]
578 # Will be mapped to Html::element()
579 $cases = [];
580
581 # ## Generic cases, match $attribDefault static array
582 $cases[] = [ '<area/>',
583 'area', [ 'shape' => 'rect' ]
584 ];
585
586 $cases[] = [ '<button type="submit"></button>',
587 'button', [ 'formaction' => 'GET' ]
588 ];
589 $cases[] = [ '<button type="submit"></button>',
590 'button', [ 'formenctype' => 'application/x-www-form-urlencoded' ]
591 ];
592
593 $cases[] = [ '<canvas></canvas>',
594 'canvas', [ 'height' => '150' ]
595 ];
596 $cases[] = [ '<canvas></canvas>',
597 'canvas', [ 'width' => '300' ]
598 ];
599 # Also check with numeric values
600 $cases[] = [ '<canvas></canvas>',
601 'canvas', [ 'height' => 150 ]
602 ];
603 $cases[] = [ '<canvas></canvas>',
604 'canvas', [ 'width' => 300 ]
605 ];
606
607 $cases[] = [ '<form></form>',
608 'form', [ 'action' => 'GET' ]
609 ];
610 $cases[] = [ '<form></form>',
611 'form', [ 'autocomplete' => 'on' ]
612 ];
613 $cases[] = [ '<form></form>',
614 'form', [ 'enctype' => 'application/x-www-form-urlencoded' ]
615 ];
616
617 $cases[] = [ '<input/>',
618 'input', [ 'formaction' => 'GET' ]
619 ];
620 $cases[] = [ '<input/>',
621 'input', [ 'type' => 'text' ]
622 ];
623
624 $cases[] = [ '<keygen/>',
625 'keygen', [ 'keytype' => 'rsa' ]
626 ];
627
628 $cases[] = [ '<link/>',
629 'link', [ 'media' => 'all' ]
630 ];
631
632 $cases[] = [ '<menu></menu>',
633 'menu', [ 'type' => 'list' ]
634 ];
635
636 $cases[] = [ '<script></script>',
637 'script', [ 'type' => 'text/javascript' ]
638 ];
639
640 $cases[] = [ '<style></style>',
641 'style', [ 'media' => 'all' ]
642 ];
643 $cases[] = [ '<style></style>',
644 'style', [ 'type' => 'text/css' ]
645 ];
646
647 $cases[] = [ '<textarea></textarea>',
648 'textarea', [ 'wrap' => 'soft' ]
649 ];
650
651 # ## SPECIFIC CASES
652
653 # <link type="text/css">
654 $cases[] = [ '<link/>',
655 'link', [ 'type' => 'text/css' ]
656 ];
657
658 # <input> specific handling
659 $cases[] = [ '<input type="checkbox"/>',
660 'input', [ 'type' => 'checkbox', 'value' => 'on' ],
661 'Default value "on" is stripped of checkboxes',
662 ];
663 $cases[] = [ '<input type="radio"/>',
664 'input', [ 'type' => 'radio', 'value' => 'on' ],
665 'Default value "on" is stripped of radio buttons',
666 ];
667 $cases[] = [ '<input type="submit" value="Submit"/>',
668 'input', [ 'type' => 'submit', 'value' => 'Submit' ],
669 'Default value "Submit" is kept on submit buttons (for possible l10n issues)',
670 ];
671 $cases[] = [ '<input type="color"/>',
672 'input', [ 'type' => 'color', 'value' => '' ],
673 ];
674 $cases[] = [ '<input type="range"/>',
675 'input', [ 'type' => 'range', 'value' => '' ],
676 ];
677
678 # <button> specific handling
679 # see remarks on https://msdn.microsoft.com/library/ms535211(v=vs.85).aspx
680 $cases[] = [ '<button type="submit"></button>',
681 'button', [ 'type' => 'submit' ],
682 'According to standard the default type is "submit". '
683 . 'Depending on compatibility mode IE might use "button", instead.',
684 ];
685
686 # <select> specific handling
687 $cases[] = [ '<select multiple=""></select>',
688 'select', [ 'size' => '4', 'multiple' => true ],
689 ];
690 # .. with numeric value
691 $cases[] = [ '<select multiple=""></select>',
692 'select', [ 'size' => 4, 'multiple' => true ],
693 ];
694 $cases[] = [ '<select></select>',
695 'select', [ 'size' => '1', 'multiple' => false ],
696 ];
697 # .. with numeric value
698 $cases[] = [ '<select></select>',
699 'select', [ 'size' => 1, 'multiple' => false ],
700 ];
701
702 # Passing an array as value
703 $cases[] = [ '<a class="css-class-one css-class-two"></a>',
704 'a', [ 'class' => [ 'css-class-one', 'css-class-two' ] ],
705 "dropDefaults accepts values given as an array"
706 ];
707
708 # FIXME: doDropDefault should remove defaults given in an array
709 # Expected should be '<a></a>'
710 $cases[] = [ '<a class=""></a>',
711 'a', [ 'class' => [ '', '' ] ],
712 "dropDefaults accepts values given as an array"
713 ];
714
715 # Craft the Html elements
716 $ret = [];
717 foreach ( $cases as $case ) {
718 $ret[] = [
719 $case[0],
720 $case[1], $case[2],
721 $case[3] ?? ''
722 ];
723 }
724
725 return $ret;
726 }
727
731 public function testWrapperInput() {
732 $this->assertEquals(
733 '<input type="radio" value="testval" name="testname"/>',
734 Html::input( 'testname', 'testval', 'radio' ),
735 'Input wrapper with type and value.'
736 );
737 $this->assertEquals(
738 '<input name="testname"/>',
739 Html::input( 'testname' ),
740 'Input wrapper with all default values.'
741 );
742 }
743
747 public function testWrapperCheck() {
748 $this->assertEquals(
749 '<input type="checkbox" value="1" name="testname"/>',
750 Html::check( 'testname' ),
751 'Checkbox wrapper unchecked.'
752 );
753 $this->assertEquals(
754 '<input checked="" type="checkbox" value="1" name="testname"/>',
755 Html::check( 'testname', true ),
756 'Checkbox wrapper checked.'
757 );
758 $this->assertEquals(
759 '<input type="checkbox" value="testval" name="testname"/>',
760 Html::check( 'testname', false, [ 'value' => 'testval' ] ),
761 'Checkbox wrapper with a value override.'
762 );
763 }
764
768 public function testWrapperRadio() {
769 $this->assertEquals(
770 '<input type="radio" value="1" name="testname"/>',
771 Html::radio( 'testname' ),
772 'Radio wrapper unchecked.'
773 );
774 $this->assertEquals(
775 '<input checked="" type="radio" value="1" name="testname"/>',
776 Html::radio( 'testname', true ),
777 'Radio wrapper checked.'
778 );
779 $this->assertEquals(
780 '<input type="radio" value="testval" name="testname"/>',
781 Html::radio( 'testname', false, [ 'value' => 'testval' ] ),
782 'Radio wrapper with a value override.'
783 );
784 }
785
789 public function testWrapperLabel() {
790 $this->assertEquals(
791 '<label for="testid">testlabel</label>',
792 Html::label( 'testlabel', 'testid' ),
793 'Label wrapper'
794 );
795 }
796
797 public static function provideSrcSetImages() {
798 return [
799 [ [], '', 'when there are no images, return empty string' ],
800 [
801 [ '1x' => '1x.png', '1.5x' => '1_5x.png', '2x' => '2x.png' ],
802 '1x.png 1x, 1_5x.png 1.5x, 2x.png 2x',
803 'pixel depth keys may include a trailing "x"'
804 ],
805 [
806 [ '1' => '1x.png', '1.5' => '1_5x.png', '2' => '2x.png' ],
807 '1x.png 1x, 1_5x.png 1.5x, 2x.png 2x',
808 'pixel depth keys may omit a trailing "x"'
809 ],
810 [
811 [ '1' => 'small.png', '1.5' => 'large.png', '2' => 'large.png' ],
812 'small.png 1x, large.png 1.5x',
813 'omit larger duplicates'
814 ],
815 [
816 [ '1' => 'small.png', '2' => 'large.png', '1.5' => 'large.png' ],
817 'small.png 1x, large.png 1.5x',
818 'omit larger duplicates in irregular order'
819 ],
820 ];
821 }
822
827 public function testSrcSet( $images, $expected, $message ) {
828 $this->assertEquals( Html::srcSet( $images ), $expected, $message );
829 }
830
831 public static function provideInlineScript() {
832 return [
833 'Empty' => [
834 '',
835 '<script></script>'
836 ],
837 'Simple' => [
838 'EXAMPLE.label("foo");',
839 '<script>EXAMPLE.label("foo");</script>'
840 ],
841 'Ampersand' => [
842 'EXAMPLE.is(a && b);',
843 '<script>EXAMPLE.is(a && b);</script>'
844 ],
845 'HTML' => [
846 'EXAMPLE.label("<a>");',
847 '<script>EXAMPLE.label("<a>");</script>'
848 ],
849 'Script closing string (lower)' => [
850 'EXAMPLE.label("</script>");',
851 '<script>/* ERROR: Invalid script */</script>',
852 true,
853 ],
854 'Script closing with non-standard attributes (mixed)' => [
855 'EXAMPLE.label("</SCriPT and STyLE>");',
856 '<script>/* ERROR: Invalid script */</script>',
857 true,
858 ],
859 'HTML-comment-open and script-open' => [
860 // In HTML, <script> contents aren't just plain CDATA until </script>,
861 // there are levels of escaping modes, and the below sequence puts an
862 // HTML parser in a state where </script> would *not* close the script.
863 // https://html.spec.whatwg.org/multipage/parsing.html#script-data-double-escape-end-state
864 'var a = "<!--<script>";',
865 '<script>/* ERROR: Invalid script */</script>',
866 true,
867 ],
868 ];
869 }
870
875 public function testInlineScript( $code, $expected, $error = false ) {
876 if ( $error ) {
877 Wikimedia\suppressWarnings();
878 $this->restoreWarnings = true;
879 }
880 $this->assertSame( Html::inlineScript( $code ), $expected );
881 }
882}
883
885 function __toString() {
886 return 'stringValue';
887 }
888}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
page as well
testExpandAttributesSkipsNullAndFalse()
Html::expandAttributes.
Definition HtmlTest.php:134
testCanDisableANamespaces()
Html::namespaceSelector.
Definition HtmlTest.php:454
static provideInlineScript()
Definition HtmlTest.php:831
testSuccessBox()
Html::successBox Html::messageBox.
Definition HtmlTest.php:527
testValueIsAuthoritativeInSpaceSeparatedAttributesArrays()
How do we handle duplicate keys in HTML attributes expansion? We could pass a "class" the values: 'GR...
Definition HtmlTest.php:317
testExpandAttributesForObjects()
Html::expandAttributes.
Definition HtmlTest.php:197
testXmlMimeType( $mimetype, $isXmlMimeType)
dataXmlMimeType Html::isXmlMimeType
Definition HtmlTest.php:127
testWrapperRadio()
Html::radio.
Definition HtmlTest.php:768
testWrapperLabel()
Html::label.
Definition HtmlTest.php:789
static provideElementsWithAttributesHavingDefaultValues()
Definition HtmlTest.php:575
testExpandAttributesListValueAttributes()
Html::expandAttributes has special features for HTML attributes that use space separated lists and al...
Definition HtmlTest.php:240
static provideSrcSetImages()
Definition HtmlTest.php:797
testNamespaceSelector()
Html::namespaceSelector Html::namespaceSelectorOptions.
Definition HtmlTest.php:347
dataXmlMimeType()
Definition HtmlTest.php:105
testExpandAttributesVariousExpansions()
Test for Html::expandAttributes() Please note it output a string prefixed with a space!...
Definition HtmlTest.php:210
testErrorBox()
Html::errorBox Html::messageBox.
Definition HtmlTest.php:508
testInlineScript( $code, $expected, $error=false)
provideInlineScript Html::inlineScript
Definition HtmlTest.php:875
testExpandAttributesSpaceSeparatedAttributesWithBoolean()
Test feature added by r96188, let pass attributes values as a PHP array.
Definition HtmlTest.php:292
testExpandAttributes_ArrayOnNonListValueAttribute_ThrowsException()
Html::expandAttributes MWException.
Definition HtmlTest.php:332
testCanFilterOutNamespaces()
Html::namespaceSelector.
Definition HtmlTest.php:429
testDropDefaults( $expected, $element, $attribs, $message='')
Test out Html::element drops or enforces default value Html::dropDefaults provideElementsWithAttribut...
Definition HtmlTest.php:571
testExpandAttributesForBooleans()
Html::expandAttributes.
Definition HtmlTest.php:154
testSrcSet( $images, $expected, $message)
provideSrcSetImages Html::srcSet
Definition HtmlTest.php:827
testWrapperCheck()
Html::check.
Definition HtmlTest.php:747
testExpandAttributesForNumbers()
Html::expandAttributes.
Definition HtmlTest.php:181
testWrapperInput()
Html::input.
Definition HtmlTest.php:731
testElementBasics()
Html::element Html::rawElement Html::openElement Html::closeElement.
Definition HtmlTest.php:85
$restoreWarnings
Definition HtmlTest.php:4
testHtmlElementAcceptsNewHtml5TypesInHtml5Mode( $HTML5InputType)
provideHtml5InputTypes Html::element
Definition HtmlTest.php:485
testWarningBox()
Html::warningBox Html::messageBox.
Definition HtmlTest.php:497
static provideHtml5InputTypes()
List of input element types values introduced by HTML5 Full list at https://www.w3....
Definition HtmlTest.php:542
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible values
Definition hooks.txt:179
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
Definition hooks.txt:895
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition hooks.txt:2055
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition hooks.txt:2054
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition hooks.txt:2063
processing should stop and the error should be shown to the user * false
Definition hooks.txt:187
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37