5 protected function setUp() {
9 'wgUseMediaWikiUIEverywhere' =>
false,
12 $langObj = Language::factory(
'en' );
17 $langObj->setNamespaces( [
29 9 =>
'MediaWiki_talk',
31 11 =>
'Template_talk',
33 15 =>
'Category_talk',
50 Html::element(
'img',
null,
'' ),
51 'Self-closing tag for short-tag elements'
55 '<element></element>',
56 Html::element(
'element',
null,
null ),
57 'Close tag for empty element (null, null)'
61 '<element></element>',
62 Html::element(
'element', [],
'' ),
63 'Close tag for empty element (array, string)'
70 # HTML is not an XML MimeType
71 [
'text/html',
false ],
72 # XML is an XML MimeType
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 ],
90 $this->assertEquals( $isXmlMimeType, Html::isXmlMimeType( $mimetype ) );
99 Html::expandAttributes( [
'foo' =>
null ] ),
100 'skip keys with null value'
103 Html::expandAttributes( [
'foo' =>
false ] ),
104 'skip keys with false value'
108 Html::expandAttributes( [
'foo' =>
'' ] ),
109 'keep keys with an empty string'
119 Html::expandAttributes( [
'selected' =>
false ] ),
120 'Boolean attributes do not generates output when value is false'
124 Html::expandAttributes( [
'selected' =>
null ] ),
125 'Boolean attributes do not generates output when value is null'
130 Html::expandAttributes( [
'selected' =>
true ] ),
131 'Boolean attributes have no value when value is true'
135 Html::expandAttributes( [
'selected' ] ),
136 'Boolean attributes have no value when value is true (passed as numerical array)'
146 Html::expandAttributes( [
'value' => 1 ] ),
147 'Integer value is cast to a string'
151 Html::expandAttributes( [
'value' => 1.1 ] ),
152 'Float value is cast to a string'
161 ' value="stringValue"',
162 Html::expandAttributes( [
'value' =>
new HtmlTestValue() ] ),
163 'Object value is converted to a string'
176 Html::expandAttributes( [
'empty_string' =>
'' ] ),
177 'Empty string is always quoted'
181 Html::expandAttributes( [
'key' =>
'value' ] ),
182 'Simple string value needs no quotes'
186 Html::expandAttributes( [
'one' => 1 ] ),
187 'Number 1 value needs no quotes'
191 Html::expandAttributes( [
'zero' => 0 ] ),
192 'Number 0 value needs no quotes'
205 ' class="redundant spaces here"',
206 Html::expandAttributes( [
'class' =>
' redundant spaces here ' ] ),
207 'Normalization should strip redundant spaces'
211 Html::expandAttributes( [
'class' =>
'foo bar foo bar bar' ] ),
212 'Normalization should remove duplicates in string-lists'
214 # ## "EMPTY" ARRAY VALUES
217 Html::expandAttributes( [
'class' => [] ] ),
218 'Value with an empty array'
222 Html::expandAttributes( [
'class' => [
null,
'',
' ',
' ' ] ] ),
223 'Array with null, empty string and spaces'
225 # ## NON-EMPTY ARRAY VALUES
228 Html::expandAttributes( [
'class' => [
235 'Normalization should remove duplicates in the array'
239 Html::expandAttributes( [
'class' => [
245 'Normalization should remove duplicates in string-lists in the array'
256 ' class="booltrue one"',
257 Html::expandAttributes( [
'class' => [
261 # Method use isset() internally, make sure we
do discard
262 # attributes
values which have been assigned well known
values
264 'boolfalse' =>
false,
282 Html::expandAttributes( [
'class' => [
297 Html::expandAttributes( [
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" .
329 Html::namespaceSelector(),
330 'Basic namespace selector without custom options'
334 '<label for="mw-test-namespace">Select a namespace:</label> ' .
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" .
354 Html::namespaceSelector(
355 [
'selected' =>
'2',
'all' =>
'all',
'label' =>
'Select a namespace:' ],
356 [
'name' =>
'wpNamespace',
'id' =>
'mw-test-namespace' ]
358 'Basic namespace selector with custom values'
362 '<label for="namespace">Select a namespace:</label> ' .
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" .
381 Html::namespaceSelector(
382 [
'label' =>
'Select a namespace:' ]
384 'Basic namespace selector with a custom label but no id attribtue for the <select>'
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" .
406 Html::namespaceSelector(
407 [
'exclude' => [ 0, 1, 3, 100, 101 ] ]
409 'Namespace selector namespace filtering.'
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" .
436 Html::namespaceSelector( [
437 'disable' => [ 0, 1, 2, 3, 4 ]
439 'Namespace selector namespace disabling'
449 '<input type="' . $HTML5InputType .
'"/>',
450 Html::element(
'input', [
'type' => $HTML5InputType ] ),
451 'In HTML5, Html::element() should accept type="' . $HTML5InputType .
'"'
461 Html::warningBox(
'warn' ),
462 '<div class="warningbox">warn</div>'
472 Html::errorBox(
'err' ),
473 '<div class="errorbox">err</div>'
476 Html::errorBox(
'err',
'heading' ),
477 '<div class="errorbox"><h2>heading</h2>err</div>'
487 Html::successBox(
'great' ),
488 '<div class="successbox">great</div>'
491 Html::successBox(
'<script>beware no escaping!</script>' ),
492 '<div class="successbox"><script>beware no escaping!</script></div>'
517 foreach ( $types as
$type ) {
518 $cases[] = [
$type ];
530 $this->assertEquals( $expected, Html::element( $element,
$attribs ), $message );
534 # Use cases in a concise format:
535 # <expected>, <element name>, <array of attributes> [, <message>]
536 # Will be mapped to Html::element()
539 # ## Generic cases, match $attribDefault static array
540 $cases[] = [
'<area/>',
541 'area', [
'shape' =>
'rect' ]
544 $cases[] = [
'<button type="submit"></button>',
545 'button', [
'formaction' =>
'GET' ]
547 $cases[] = [
'<button type="submit"></button>',
548 'button', [
'formenctype' =>
'application/x-www-form-urlencoded' ]
551 $cases[] = [
'<canvas></canvas>',
552 'canvas', [
'height' =>
'150' ]
554 $cases[] = [
'<canvas></canvas>',
555 'canvas', [
'width' =>
'300' ]
557 # Also check with numeric values
558 $cases[] = [
'<canvas></canvas>',
559 'canvas', [
'height' => 150 ]
561 $cases[] = [
'<canvas></canvas>',
562 'canvas', [
'width' => 300 ]
565 $cases[] = [
'<form></form>',
566 'form', [
'action' =>
'GET' ]
568 $cases[] = [
'<form></form>',
569 'form', [
'autocomplete' =>
'on' ]
571 $cases[] = [
'<form></form>',
572 'form', [
'enctype' =>
'application/x-www-form-urlencoded' ]
575 $cases[] = [
'<input/>',
576 'input', [
'formaction' =>
'GET' ]
578 $cases[] = [
'<input/>',
579 'input', [
'type' =>
'text' ]
582 $cases[] = [
'<keygen/>',
583 'keygen', [
'keytype' =>
'rsa' ]
586 $cases[] = [
'<link/>',
587 'link', [
'media' =>
'all' ]
590 $cases[] = [
'<menu></menu>',
591 'menu', [
'type' =>
'list' ]
594 $cases[] = [
'<script></script>',
595 'script', [
'type' =>
'text/javascript' ]
598 $cases[] = [
'<style></style>',
599 'style', [
'media' =>
'all' ]
601 $cases[] = [
'<style></style>',
602 'style', [
'type' =>
'text/css' ]
605 $cases[] = [
'<textarea></textarea>',
606 'textarea', [
'wrap' =>
'soft' ]
611 # <link type="text/css">
612 $cases[] = [
'<link/>',
613 'link', [
'type' =>
'text/css' ]
616 # <input> specific handling
617 $cases[] = [
'<input type="checkbox"/>',
618 'input', [
'type' =>
'checkbox',
'value' =>
'on' ],
619 'Default value "on" is stripped of checkboxes',
621 $cases[] = [
'<input type="radio"/>',
622 'input', [
'type' =>
'radio',
'value' =>
'on' ],
623 'Default value "on" is stripped of radio buttons',
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)',
629 $cases[] = [
'<input type="color"/>',
630 'input', [
'type' =>
'color',
'value' =>
'' ],
632 $cases[] = [
'<input type="range"/>',
633 'input', [
'type' =>
'range',
'value' =>
'' ],
636 # <button> specific handling
637 # see remarks on https:
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.',
644 # <select> specific handling
645 $cases[] = [
'<select multiple=""></select>',
646 'select', [
'size' =>
'4',
'multiple' =>
true ],
648 # .. with numeric value
649 $cases[] = [
'<select multiple=""></select>',
650 'select', [
'size' => 4,
'multiple' =>
true ],
652 $cases[] = [
'<select></select>',
653 'select', [
'size' =>
'1',
'multiple' =>
false ],
655 # .. with numeric value
656 $cases[] = [
'<select></select>',
657 'select', [
'size' => 1,
'multiple' =>
false ],
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"
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"
673 # Craft the Html elements
675 foreach ( $cases as $case ) {
679 isset( $case[3] ) ? $case[3] :
''
691 '<input type="radio" value="testval" name="testname"/>',
692 Html::input(
'testname',
'testval',
'radio' ),
693 'Input wrapper with type and value.'
696 '<input name="testname"/>',
697 Html::input(
'testname' ),
698 'Input wrapper with all default values.'
707 '<input type="checkbox" value="1" name="testname"/>',
708 Html::check(
'testname' ),
709 'Checkbox wrapper unchecked.'
712 '<input checked="" type="checkbox" value="1" name="testname"/>',
713 Html::check(
'testname',
true ),
714 'Checkbox wrapper checked.'
717 '<input type="checkbox" value="testval" name="testname"/>',
718 Html::check(
'testname',
false, [
'value' =>
'testval' ] ),
719 'Checkbox wrapper with a value override.'
728 '<input type="radio" value="1" name="testname"/>',
729 Html::radio(
'testname' ),
730 'Radio wrapper unchecked.'
733 '<input checked="" type="radio" value="1" name="testname"/>',
734 Html::radio(
'testname',
true ),
735 'Radio wrapper checked.'
738 '<input type="radio" value="testval" name="testname"/>',
739 Html::radio(
'testname',
false, [
'value' =>
'testval' ] ),
740 'Radio wrapper with a value override.'
749 '<label for="testid">testlabel</label>',
750 Html::label(
'testlabel',
'testid' ),
757 [ [],
'',
'when there are no images, return empty string' ],
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"'
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"'
769 [
'1' =>
'small.png',
'1.5' =>
'large.png',
'2' =>
'large.png' ],
770 'small.png 1x, large.png 1.5x',
771 'omit larger duplicates'
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'
786 $this->assertEquals( Html::srcSet( $images ), $expected, $message );
792 return 'stringValue';
testExpandAttributesSkipsNullAndFalse()
Html::expandAttributes.
testCanDisableANamespaces()
Html::namespaceSelector.
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.
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
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