6 protected function setUp() {
10 'wgUseMediaWikiUIEverywhere' =>
false,
13 $contLangObj = Language::factory(
'en' );
18 $contLangObj->setNamespaces( [
30 9 =>
'MediaWiki_talk',
32 11 =>
'Template_talk',
34 15 =>
'Category_talk',
40 $userLangObj = Language::factory(
'es' );
41 $userLangObj->setNamespaces( [
47 3 =>
"Usuario discusión",
49 5 =>
"Wiki discusión",
51 7 =>
"Archivo discusión",
53 9 =>
"MediaWiki discusión",
55 11 =>
"Plantilla discusión",
57 13 =>
"Ayuda discusión",
59 15 =>
"Categoría discusión",
60 100 =>
"Personalizado",
61 101 =>
"Personalizado discusión",
65 $this->restoreWarnings =
false;
69 Language::factory(
'en' )->resetNamespaces();
71 if ( $this->restoreWarnings ) {
72 $this->restoreWarnings =
false;
73 Wikimedia\restoreWarnings();
88 Html::element(
'img',
null,
'' ),
89 'Self-closing tag for short-tag elements'
93 '<element></element>',
94 Html::element(
'element',
null,
null ),
95 'Close tag for empty element (null, null)'
99 '<element></element>',
100 Html::element(
'element', [],
'' ),
101 'Close tag for empty element (array, string)'
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 ],
128 $this->assertEquals( $isXmlMimeType, Html::isXmlMimeType( $mimetype ) );
137 Html::expandAttributes( [
'foo' =>
null ] ),
138 'skip keys with null value'
141 Html::expandAttributes( [
'foo' =>
false ] ),
142 'skip keys with false value'
146 Html::expandAttributes( [
'foo' =>
'' ] ),
147 'keep keys with an empty string'
157 Html::expandAttributes( [
'selected' =>
false ] ),
158 'Boolean attributes do not generates output when value is false'
162 Html::expandAttributes( [
'selected' =>
null ] ),
163 'Boolean attributes do not generates output when value is null'
168 Html::expandAttributes( [
'selected' =>
true ] ),
169 'Boolean attributes have no value when value is true'
173 Html::expandAttributes( [
'selected' ] ),
174 'Boolean attributes have no value when value is true (passed as numerical array)'
184 Html::expandAttributes( [
'value' => 1 ] ),
185 'Integer value is cast to a string'
189 Html::expandAttributes( [
'value' => 1.1 ] ),
190 'Float value is cast to a string'
199 ' value="stringValue"',
200 Html::expandAttributes( [
'value' =>
new HtmlTestValue() ] ),
201 'Object value is converted to a string'
214 Html::expandAttributes( [
'empty_string' =>
'' ] ),
215 'Empty string is always quoted'
219 Html::expandAttributes( [
'key' =>
'value' ] ),
220 'Simple string value needs no quotes'
224 Html::expandAttributes( [
'one' => 1 ] ),
225 'Number 1 value needs no quotes'
229 Html::expandAttributes( [
'zero' => 0 ] ),
230 'Number 0 value needs no quotes'
243 ' class="redundant spaces here"',
244 Html::expandAttributes( [
'class' =>
' redundant spaces here ' ] ),
245 'Normalization should strip redundant spaces'
249 Html::expandAttributes( [
'class' =>
'foo bar foo bar bar' ] ),
250 'Normalization should remove duplicates in string-lists'
252 # ## "EMPTY" ARRAY VALUES
255 Html::expandAttributes( [
'class' => [] ] ),
256 'Value with an empty array'
260 Html::expandAttributes( [
'class' => [
null,
'',
' ',
' ' ] ] ),
261 'Array with null, empty string and spaces'
263 # ## NON-EMPTY ARRAY VALUES
266 Html::expandAttributes( [
'class' => [
273 'Normalization should remove duplicates in the array'
277 Html::expandAttributes( [
'class' => [
283 'Normalization should remove duplicates in string-lists in the array'
294 ' class="booltrue one"',
295 Html::expandAttributes( [
'class' => [
299 # Method use isset() internally, make sure we
do discard
300 # attributes
values which have been assigned well known
values
302 'boolfalse' =>
false,
320 Html::expandAttributes( [
'class' => [
335 Html::expandAttributes( [
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" .
367 Html::namespaceSelector(),
368 'Basic namespace selector without custom options'
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" .
392 Html::namespaceSelector(
393 [
'selected' =>
'2',
'all' =>
'all',
'label' =>
'Select a namespace:' ],
394 [
'name' =>
'wpNamespace',
'id' =>
'mw-test-namespace' ]
396 'Basic namespace selector with custom values'
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" .
419 Html::namespaceSelector(
420 [
'label' =>
'Select a namespace:' ]
422 'Basic namespace selector with a custom label but no id attribtue for the <select>'
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" .
444 Html::namespaceSelector(
445 [
'exclude' => [ 0, 1, 3, 100, 101 ] ]
447 'Namespace selector namespace filtering.'
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" .
474 Html::namespaceSelector( [
475 'disable' => [ 0, 1, 2, 3, 4 ]
477 'Namespace selector namespace disabling'
487 '<input type="' . $HTML5InputType .
'"/>',
488 Html::element(
'input', [
'type' => $HTML5InputType ] ),
489 'In HTML5, Html::element() should accept type="' . $HTML5InputType .
'"'
499 Html::warningBox(
'warn' ),
500 '<div class="warningbox">warn</div>'
510 Html::errorBox(
'err' ),
511 '<div class="errorbox">err</div>'
514 Html::errorBox(
'err',
'heading' ),
515 '<div class="errorbox"><h2>heading</h2>err</div>'
518 Html::errorBox(
'err',
'0' ),
519 '<div class="errorbox"><h2>0</h2>err</div>'
529 Html::successBox(
'great' ),
530 '<div class="successbox">great</div>'
533 Html::successBox(
'<script>beware no escaping!</script>' ),
534 '<div class="successbox"><script>beware no escaping!</script></div>'
559 foreach ( $types as
$type ) {
560 $cases[] = [
$type ];
572 $this->assertEquals( $expected, Html::element( $element,
$attribs ), $message );
576 # Use cases in a concise format:
577 # <expected>, <element name>, <array of attributes> [, <message>]
578 # Will be mapped to Html::element()
581 # ## Generic cases, match $attribDefault static array
582 $cases[] = [
'<area/>',
583 'area', [
'shape' =>
'rect' ]
586 $cases[] = [
'<button type="submit"></button>',
587 'button', [
'formaction' =>
'GET' ]
589 $cases[] = [
'<button type="submit"></button>',
590 'button', [
'formenctype' =>
'application/x-www-form-urlencoded' ]
593 $cases[] = [
'<canvas></canvas>',
594 'canvas', [
'height' =>
'150' ]
596 $cases[] = [
'<canvas></canvas>',
597 'canvas', [
'width' =>
'300' ]
599 # Also check with numeric values
600 $cases[] = [
'<canvas></canvas>',
601 'canvas', [
'height' => 150 ]
603 $cases[] = [
'<canvas></canvas>',
604 'canvas', [
'width' => 300 ]
607 $cases[] = [
'<form></form>',
608 'form', [
'action' =>
'GET' ]
610 $cases[] = [
'<form></form>',
611 'form', [
'autocomplete' =>
'on' ]
613 $cases[] = [
'<form></form>',
614 'form', [
'enctype' =>
'application/x-www-form-urlencoded' ]
617 $cases[] = [
'<input/>',
618 'input', [
'formaction' =>
'GET' ]
620 $cases[] = [
'<input/>',
621 'input', [
'type' =>
'text' ]
624 $cases[] = [
'<keygen/>',
625 'keygen', [
'keytype' =>
'rsa' ]
628 $cases[] = [
'<link/>',
629 'link', [
'media' =>
'all' ]
632 $cases[] = [
'<menu></menu>',
633 'menu', [
'type' =>
'list' ]
636 $cases[] = [
'<script></script>',
637 'script', [
'type' =>
'text/javascript' ]
640 $cases[] = [
'<style></style>',
641 'style', [
'media' =>
'all' ]
643 $cases[] = [
'<style></style>',
644 'style', [
'type' =>
'text/css' ]
647 $cases[] = [
'<textarea></textarea>',
648 'textarea', [
'wrap' =>
'soft' ]
653 # <link type="text/css">
654 $cases[] = [
'<link/>',
655 'link', [
'type' =>
'text/css' ]
658 # <input> specific handling
659 $cases[] = [
'<input type="checkbox"/>',
660 'input', [
'type' =>
'checkbox',
'value' =>
'on' ],
661 'Default value "on" is stripped of checkboxes',
663 $cases[] = [
'<input type="radio"/>',
664 'input', [
'type' =>
'radio',
'value' =>
'on' ],
665 'Default value "on" is stripped of radio buttons',
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)',
671 $cases[] = [
'<input type="color"/>',
672 'input', [
'type' =>
'color',
'value' =>
'' ],
674 $cases[] = [
'<input type="range"/>',
675 'input', [
'type' =>
'range',
'value' =>
'' ],
678 # <button> specific handling
679 # see remarks on https:
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.',
686 # <select> specific handling
687 $cases[] = [
'<select multiple=""></select>',
688 'select', [
'size' =>
'4',
'multiple' =>
true ],
690 # .. with numeric value
691 $cases[] = [
'<select multiple=""></select>',
692 'select', [
'size' => 4,
'multiple' =>
true ],
694 $cases[] = [
'<select></select>',
695 'select', [
'size' =>
'1',
'multiple' =>
false ],
697 # .. with numeric value
698 $cases[] = [
'<select></select>',
699 'select', [
'size' => 1,
'multiple' =>
false ],
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"
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"
715 # Craft the Html elements
717 foreach ( $cases as $case ) {
733 '<input type="radio" value="testval" name="testname"/>',
734 Html::input(
'testname',
'testval',
'radio' ),
735 'Input wrapper with type and value.'
738 '<input name="testname"/>',
739 Html::input(
'testname' ),
740 'Input wrapper with all default values.'
749 '<input type="checkbox" value="1" name="testname"/>',
750 Html::check(
'testname' ),
751 'Checkbox wrapper unchecked.'
754 '<input checked="" type="checkbox" value="1" name="testname"/>',
755 Html::check(
'testname',
true ),
756 'Checkbox wrapper checked.'
759 '<input type="checkbox" value="testval" name="testname"/>',
760 Html::check(
'testname',
false, [
'value' =>
'testval' ] ),
761 'Checkbox wrapper with a value override.'
770 '<input type="radio" value="1" name="testname"/>',
771 Html::radio(
'testname' ),
772 'Radio wrapper unchecked.'
775 '<input checked="" type="radio" value="1" name="testname"/>',
776 Html::radio(
'testname',
true ),
777 'Radio wrapper checked.'
780 '<input type="radio" value="testval" name="testname"/>',
781 Html::radio(
'testname',
false, [
'value' =>
'testval' ] ),
782 'Radio wrapper with a value override.'
791 '<label for="testid">testlabel</label>',
792 Html::label(
'testlabel',
'testid' ),
799 [ [],
'',
'when there are no images, return empty string' ],
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"'
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"'
811 [
'1' =>
'small.png',
'1.5' =>
'large.png',
'2' =>
'large.png' ],
812 'small.png 1x, large.png 1.5x',
813 'omit larger duplicates'
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'
828 $this->assertEquals( Html::srcSet( $images ), $expected, $message );
838 'EXAMPLE.label("foo");',
839 '<script>EXAMPLE.label("foo");</script>'
842 'EXAMPLE.is(a && b);',
843 '<script>EXAMPLE.is(a && b);</script>'
846 'EXAMPLE.label("<a>");',
847 '<script>EXAMPLE.label("<a>");</script>'
849 'Script closing string (lower)' => [
850 'EXAMPLE.label("</script>");',
851 '<script>/* ERROR: Invalid script */</script>',
854 'Script closing with non-standard attributes (mixed)' => [
855 'EXAMPLE.label("</SCriPT and STyLE>");',
856 '<script>/* ERROR: Invalid script */</script>',
859 'HTML-comment-open and script-open' => [
864 'var a = "<!--<script>";',
865 '<script>/* ERROR: Invalid script */</script>',
877 Wikimedia\suppressWarnings();
878 $this->restoreWarnings =
true;
880 $this->assertSame( Html::inlineScript(
$code ), $expected );
886 return 'stringValue';
testExpandAttributesSkipsNullAndFalse()
Html::expandAttributes.
testCanDisableANamespaces()
Html::namespaceSelector.
static provideInlineScript()
testSuccessBox()
Html::successBox Html::messageBox.
testValueIsAuthoritativeInSpaceSeparatedAttributesArrays()
How do we handle duplicate keys in HTML attributes expansion? We could pass a "class" the values: 'GR...
testExpandAttributesForObjects()
Html::expandAttributes.
testXmlMimeType( $mimetype, $isXmlMimeType)
dataXmlMimeType Html::isXmlMimeType
testWrapperRadio()
Html::radio.
testWrapperLabel()
Html::label.
static provideElementsWithAttributesHavingDefaultValues()
testExpandAttributesListValueAttributes()
Html::expandAttributes has special features for HTML attributes that use space separated lists and al...
static provideSrcSetImages()
testNamespaceSelector()
Html::namespaceSelector Html::namespaceSelectorOptions.
testExpandAttributesVariousExpansions()
Test for Html::expandAttributes() Please note it output a string prefixed with a space!...
testErrorBox()
Html::errorBox Html::messageBox.
testInlineScript( $code, $expected, $error=false)
provideInlineScript Html::inlineScript
testExpandAttributesSpaceSeparatedAttributesWithBoolean()
Test feature added by r96188, let pass attributes values as a PHP array.
testExpandAttributes_ArrayOnNonListValueAttribute_ThrowsException()
Html::expandAttributes MWException.
testCanFilterOutNamespaces()
Html::namespaceSelector.
testDropDefaults( $expected, $element, $attribs, $message='')
Test out Html::element drops or enforces default value Html::dropDefaults provideElementsWithAttribut...
testExpandAttributesForBooleans()
Html::expandAttributes.
testSrcSet( $images, $expected, $message)
provideSrcSetImages Html::srcSet
testWrapperCheck()
Html::check.
testExpandAttributesForNumbers()
Html::expandAttributes.
testWrapperInput()
Html::input.
testElementBasics()
Html::element Html::rawElement Html::openElement Html::closeElement.
testHtmlElementAcceptsNewHtml5TypesInHtml5Mode( $HTML5InputType)
provideHtml5InputTypes Html::element
testWarningBox()
Html::warningBox Html::messageBox.
static provideHtml5InputTypes()
List of input element types values introduced by HTML5 Full list at https://www.w3....
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible values
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
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
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
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
processing should stop and the error should be shown to the user * false