// Hardcode namespaces during test runs,
// so that html output based on existing namespaces
// can be properly evaluated.
- $langObj->setNamespaces( array(
+ $langObj->setNamespaces( [
-2 => 'Media',
-1 => 'Special',
0 => '',
15 => 'Category_talk',
100 => 'Custom',
101 => 'Custom_talk',
- ) );
+ ] );
- $this->setMwGlobals( array(
+ $this->setMwGlobals( [
'wgLanguageCode' => $langCode,
'wgContLang' => $langObj,
'wgLang' => $langObj,
'wgWellFormedXml' => false,
- ) );
+ ] );
}
/**
$this->assertEquals(
'<element></element>',
- Html::element( 'element', array(), '' ),
+ Html::element( 'element', [], '' ),
'Close tag for empty element (array, string)'
);
}
public function dataXmlMimeType() {
- return array(
+ return [
// ( $mimetype, $isXmlMimeType )
# HTML is not an XML MimeType
- array( 'text/html', false ),
+ [ 'text/html', false ],
# XML is an XML MimeType
- array( 'text/xml', true ),
- array( 'application/xml', true ),
+ [ 'text/xml', true ],
+ [ 'application/xml', true ],
# XHTML is an XML MimeType
- array( 'application/xhtml+xml', true ),
+ [ 'application/xhtml+xml', true ],
# Make sure other +xml MimeTypes are supported
# SVG is another random MimeType even though we don't use it
- array( 'image/svg+xml', true ),
+ [ 'image/svg+xml', true ],
# Complete random other MimeTypes are not XML
- array( 'text/plain', false ),
- );
+ [ 'text/plain', false ],
+ ];
}
/**
# ## EMPTY ########
$this->assertEmpty(
- Html::expandAttributes( array( 'foo' => null ) ),
+ Html::expandAttributes( [ 'foo' => null ] ),
'skip keys with null value'
);
$this->assertEmpty(
- Html::expandAttributes( array( 'foo' => false ) ),
+ Html::expandAttributes( [ 'foo' => false ] ),
'skip keys with false value'
);
$this->assertEquals(
' foo=""',
- Html::expandAttributes( array( 'foo' => '' ) ),
+ Html::expandAttributes( [ 'foo' => '' ] ),
'keep keys with an empty string'
);
}
public function testExpandAttributesForBooleans() {
$this->assertEquals(
'',
- Html::expandAttributes( array( 'selected' => false ) ),
+ Html::expandAttributes( [ 'selected' => false ] ),
'Boolean attributes do not generates output when value is false'
);
$this->assertEquals(
'',
- Html::expandAttributes( array( 'selected' => null ) ),
+ Html::expandAttributes( [ 'selected' => null ] ),
'Boolean attributes do not generates output when value is null'
);
$this->assertEquals(
' selected',
- Html::expandAttributes( array( 'selected' => true ) ),
+ Html::expandAttributes( [ 'selected' => true ] ),
'Boolean attributes have no value when value is true'
);
$this->assertEquals(
' selected',
- Html::expandAttributes( array( 'selected' ) ),
+ Html::expandAttributes( [ 'selected' ] ),
'Boolean attributes have no value when value is true (passed as numerical array)'
);
$this->assertEquals(
' selected=""',
- Html::expandAttributes( array( 'selected' => true ) ),
+ Html::expandAttributes( [ 'selected' => true ] ),
'Boolean attributes have empty string value when value is true (wgWellFormedXml)'
);
}
public function testExpandAttributesForNumbers() {
$this->assertEquals(
' value=1',
- Html::expandAttributes( array( 'value' => 1 ) ),
+ Html::expandAttributes( [ 'value' => 1 ] ),
'Integer value is cast to a string'
);
$this->assertEquals(
' value=1.1',
- Html::expandAttributes( array( 'value' => 1.1 ) ),
+ Html::expandAttributes( [ 'value' => 1.1 ] ),
'Float value is cast to a string'
);
}
public function testExpandAttributesForObjects() {
$this->assertEquals(
' value=stringValue',
- Html::expandAttributes( array( 'value' => new HtmlTestValue() ) ),
+ Html::expandAttributes( [ 'value' => new HtmlTestValue() ] ),
'Object value is converted to a string'
);
}
# ## NOT EMPTY ####
$this->assertEquals(
' empty_string=""',
- Html::expandAttributes( array( 'empty_string' => '' ) ),
+ Html::expandAttributes( [ 'empty_string' => '' ] ),
'Empty string is always quoted'
);
$this->assertEquals(
' key=value',
- Html::expandAttributes( array( 'key' => 'value' ) ),
+ Html::expandAttributes( [ 'key' => 'value' ] ),
'Simple string value needs no quotes'
);
$this->assertEquals(
' one=1',
- Html::expandAttributes( array( 'one' => 1 ) ),
+ Html::expandAttributes( [ 'one' => 1 ] ),
'Number 1 value needs no quotes'
);
$this->assertEquals(
' zero=0',
- Html::expandAttributes( array( 'zero' => 0 ) ),
+ Html::expandAttributes( [ 'zero' => 0 ] ),
'Number 0 value needs no quotes'
);
$this->assertEquals(
' empty_string=""',
- Html::expandAttributes( array( 'empty_string' => '' ) ),
+ Html::expandAttributes( [ 'empty_string' => '' ] ),
'Attribute values are always quoted (wgWellFormedXml): Empty string'
);
$this->assertEquals(
' key="value"',
- Html::expandAttributes( array( 'key' => 'value' ) ),
+ Html::expandAttributes( [ 'key' => 'value' ] ),
'Attribute values are always quoted (wgWellFormedXml): Simple string'
);
$this->assertEquals(
' one="1"',
- Html::expandAttributes( array( 'one' => 1 ) ),
+ Html::expandAttributes( [ 'one' => 1 ] ),
'Attribute values are always quoted (wgWellFormedXml): Number 1'
);
$this->assertEquals(
' zero="0"',
- Html::expandAttributes( array( 'zero' => 0 ) ),
+ Html::expandAttributes( [ 'zero' => 0 ] ),
'Attribute values are always quoted (wgWellFormedXml): Number 0'
);
}
# ## STRING VALUES
$this->assertEquals(
' class="redundant spaces here"',
- Html::expandAttributes( array( 'class' => ' redundant spaces here ' ) ),
+ Html::expandAttributes( [ 'class' => ' redundant spaces here ' ] ),
'Normalization should strip redundant spaces'
);
$this->assertEquals(
' class="foo bar"',
- Html::expandAttributes( array( 'class' => 'foo bar foo bar bar' ) ),
+ Html::expandAttributes( [ 'class' => 'foo bar foo bar bar' ] ),
'Normalization should remove duplicates in string-lists'
);
# ## "EMPTY" ARRAY VALUES
$this->assertEquals(
' class=""',
- Html::expandAttributes( array( 'class' => array() ) ),
+ Html::expandAttributes( [ 'class' => [] ] ),
'Value with an empty array'
);
$this->assertEquals(
' class=""',
- Html::expandAttributes( array( 'class' => array( null, '', ' ', ' ' ) ) ),
+ Html::expandAttributes( [ 'class' => [ null, '', ' ', ' ' ] ] ),
'Array with null, empty string and spaces'
);
# ## NON-EMPTY ARRAY VALUES
$this->assertEquals(
' class="foo bar"',
- Html::expandAttributes( array( 'class' => array(
+ Html::expandAttributes( [ 'class' => [
'foo',
'bar',
'foo',
'bar',
'bar',
- ) ) ),
+ ] ] ),
'Normalization should remove duplicates in the array'
);
$this->assertEquals(
' class="foo bar"',
- Html::expandAttributes( array( 'class' => array(
+ Html::expandAttributes( [ 'class' => [
'foo bar',
'bar foo',
'foo',
'bar bar',
- ) ) ),
+ ] ] ),
'Normalization should remove duplicates in string-lists in the array'
);
}
public function testExpandAttributesSpaceSeparatedAttributesWithBoolean() {
$this->assertEquals(
' class="booltrue one"',
- Html::expandAttributes( array( 'class' => array(
+ Html::expandAttributes( [ 'class' => [
'booltrue' => true,
'one' => 1,
'boolfalse' => false,
'zero' => 0,
'null' => null,
- ) ) )
+ ] ] )
);
}
public function testValueIsAuthoritativeInSpaceSeparatedAttributesArrays() {
$this->assertEquals(
' class=""',
- Html::expandAttributes( array( 'class' => array(
+ Html::expandAttributes( [ 'class' => [
'GREEN',
'GREEN' => false,
'GREEN',
- ) ) )
+ ] ] )
);
}
public function testExpandAttributes_ArrayOnNonListValueAttribute_ThrowsException() {
// Real-life test case found in the Popups extension (see Gerrit cf0fd64),
// when used with an outdated BetaFeatures extension (see Gerrit deda1e7)
- Html::expandAttributes( array(
- 'src' => array(
+ Html::expandAttributes( [
+ 'src' => [
'ltr' => 'ltr.svg',
'rtl' => 'rtl.svg'
- )
- ) );
+ ]
+ ] );
}
/**
'<option value=101>Custom talk</option>' . "\n" .
'</select>',
Html::namespaceSelector(
- array( 'selected' => '2', 'all' => 'all', 'label' => 'Select a namespace:' ),
- array( 'name' => 'wpNamespace', 'id' => 'mw-test-namespace' )
+ [ 'selected' => '2', 'all' => 'all', 'label' => 'Select a namespace:' ],
+ [ 'name' => 'wpNamespace', 'id' => 'mw-test-namespace' ]
),
'Basic namespace selector with custom values'
);
'<option value=101>Custom talk</option>' . "\n" .
'</select>',
Html::namespaceSelector(
- array( 'label' => 'Select a namespace:' )
+ [ 'label' => 'Select a namespace:' ]
),
'Basic namespace selector with a custom label but no id attribtue for the <select>'
);
'<option value=15>Category talk</option>' . "\n" .
'</select>',
Html::namespaceSelector(
- array( 'exclude' => array( 0, 1, 3, 100, 101 ) )
+ [ 'exclude' => [ 0, 1, 3, 100, 101 ] ]
),
'Namespace selector namespace filtering.'
);
'<option value=100>Custom</option>' . "\n" .
'<option value=101>Custom talk</option>' . "\n" .
'</select>',
- Html::namespaceSelector( array(
- 'disable' => array( 0, 1, 2, 3, 4 )
- ) ),
+ Html::namespaceSelector( [
+ 'disable' => [ 0, 1, 2, 3, 4 ]
+ ] ),
'Namespace selector namespace disabling'
);
}
public function testHtmlElementAcceptsNewHtml5TypesInHtml5Mode( $HTML5InputType ) {
$this->assertEquals(
'<input type=' . $HTML5InputType . '>',
- Html::element( 'input', array( 'type' => $HTML5InputType ) ),
+ Html::element( 'input', [ 'type' => $HTML5InputType ] ),
'In HTML5, Html::element() should accept type="' . $HTML5InputType . '"'
);
}
* Full list at http://www.w3.org/TR/html-markup/input.html
*/
public static function provideHtml5InputTypes() {
- $types = array(
+ $types = [
'datetime',
'datetime-local',
'date',
'search',
'tel',
'color',
- );
- $cases = array();
+ ];
+ $cases = [];
foreach ( $types as $type ) {
- $cases[] = array( $type );
+ $cases[] = [ $type ];
}
return $cases;
# Use cases in a concise format:
# <expected>, <element name>, <array of attributes> [, <message>]
# Will be mapped to Html::element()
- $cases = array();
+ $cases = [];
# ## Generic cases, match $attribDefault static array
- $cases[] = array( '<area>',
- 'area', array( 'shape' => 'rect' )
- );
-
- $cases[] = array( '<button type=submit></button>',
- 'button', array( 'formaction' => 'GET' )
- );
- $cases[] = array( '<button type=submit></button>',
- 'button', array( 'formenctype' => 'application/x-www-form-urlencoded' )
- );
-
- $cases[] = array( '<canvas></canvas>',
- 'canvas', array( 'height' => '150' )
- );
- $cases[] = array( '<canvas></canvas>',
- 'canvas', array( 'width' => '300' )
- );
+ $cases[] = [ '<area>',
+ 'area', [ 'shape' => 'rect' ]
+ ];
+
+ $cases[] = [ '<button type=submit></button>',
+ 'button', [ 'formaction' => 'GET' ]
+ ];
+ $cases[] = [ '<button type=submit></button>',
+ 'button', [ 'formenctype' => 'application/x-www-form-urlencoded' ]
+ ];
+
+ $cases[] = [ '<canvas></canvas>',
+ 'canvas', [ 'height' => '150' ]
+ ];
+ $cases[] = [ '<canvas></canvas>',
+ 'canvas', [ 'width' => '300' ]
+ ];
# Also check with numeric values
- $cases[] = array( '<canvas></canvas>',
- 'canvas', array( 'height' => 150 )
- );
- $cases[] = array( '<canvas></canvas>',
- 'canvas', array( 'width' => 300 )
- );
-
- $cases[] = array( '<command>',
- 'command', array( 'type' => 'command' )
- );
-
- $cases[] = array( '<form></form>',
- 'form', array( 'action' => 'GET' )
- );
- $cases[] = array( '<form></form>',
- 'form', array( 'autocomplete' => 'on' )
- );
- $cases[] = array( '<form></form>',
- 'form', array( 'enctype' => 'application/x-www-form-urlencoded' )
- );
-
- $cases[] = array( '<input>',
- 'input', array( 'formaction' => 'GET' )
- );
- $cases[] = array( '<input>',
- 'input', array( 'type' => 'text' )
- );
-
- $cases[] = array( '<keygen>',
- 'keygen', array( 'keytype' => 'rsa' )
- );
-
- $cases[] = array( '<link>',
- 'link', array( 'media' => 'all' )
- );
-
- $cases[] = array( '<menu></menu>',
- 'menu', array( 'type' => 'list' )
- );
-
- $cases[] = array( '<script></script>',
- 'script', array( 'type' => 'text/javascript' )
- );
-
- $cases[] = array( '<style></style>',
- 'style', array( 'media' => 'all' )
- );
- $cases[] = array( '<style></style>',
- 'style', array( 'type' => 'text/css' )
- );
-
- $cases[] = array( '<textarea></textarea>',
- 'textarea', array( 'wrap' => 'soft' )
- );
+ $cases[] = [ '<canvas></canvas>',
+ 'canvas', [ 'height' => 150 ]
+ ];
+ $cases[] = [ '<canvas></canvas>',
+ 'canvas', [ 'width' => 300 ]
+ ];
+
+ $cases[] = [ '<command>',
+ 'command', [ 'type' => 'command' ]
+ ];
+
+ $cases[] = [ '<form></form>',
+ 'form', [ 'action' => 'GET' ]
+ ];
+ $cases[] = [ '<form></form>',
+ 'form', [ 'autocomplete' => 'on' ]
+ ];
+ $cases[] = [ '<form></form>',
+ 'form', [ 'enctype' => 'application/x-www-form-urlencoded' ]
+ ];
+
+ $cases[] = [ '<input>',
+ 'input', [ 'formaction' => 'GET' ]
+ ];
+ $cases[] = [ '<input>',
+ 'input', [ 'type' => 'text' ]
+ ];
+
+ $cases[] = [ '<keygen>',
+ 'keygen', [ 'keytype' => 'rsa' ]
+ ];
+
+ $cases[] = [ '<link>',
+ 'link', [ 'media' => 'all' ]
+ ];
+
+ $cases[] = [ '<menu></menu>',
+ 'menu', [ 'type' => 'list' ]
+ ];
+
+ $cases[] = [ '<script></script>',
+ 'script', [ 'type' => 'text/javascript' ]
+ ];
+
+ $cases[] = [ '<style></style>',
+ 'style', [ 'media' => 'all' ]
+ ];
+ $cases[] = [ '<style></style>',
+ 'style', [ 'type' => 'text/css' ]
+ ];
+
+ $cases[] = [ '<textarea></textarea>',
+ 'textarea', [ 'wrap' => 'soft' ]
+ ];
# ## SPECIFIC CASES
# <link type="text/css">
- $cases[] = array( '<link>',
- 'link', array( 'type' => 'text/css' )
- );
+ $cases[] = [ '<link>',
+ 'link', [ 'type' => 'text/css' ]
+ ];
# <input> specific handling
- $cases[] = array( '<input type=checkbox>',
- 'input', array( 'type' => 'checkbox', 'value' => 'on' ),
+ $cases[] = [ '<input type=checkbox>',
+ 'input', [ 'type' => 'checkbox', 'value' => 'on' ],
'Default value "on" is stripped of checkboxes',
- );
- $cases[] = array( '<input type=radio>',
- 'input', array( 'type' => 'radio', 'value' => 'on' ),
+ ];
+ $cases[] = [ '<input type=radio>',
+ 'input', [ 'type' => 'radio', 'value' => 'on' ],
'Default value "on" is stripped of radio buttons',
- );
- $cases[] = array( '<input type=submit value=Submit>',
- 'input', array( 'type' => 'submit', 'value' => 'Submit' ),
+ ];
+ $cases[] = [ '<input type=submit value=Submit>',
+ 'input', [ 'type' => 'submit', 'value' => 'Submit' ],
'Default value "Submit" is kept on submit buttons (for possible l10n issues)',
- );
- $cases[] = array( '<input type=color>',
- 'input', array( 'type' => 'color', 'value' => '' ),
- );
- $cases[] = array( '<input type=range>',
- 'input', array( 'type' => 'range', 'value' => '' ),
- );
+ ];
+ $cases[] = [ '<input type=color>',
+ 'input', [ 'type' => 'color', 'value' => '' ],
+ ];
+ $cases[] = [ '<input type=range>',
+ 'input', [ 'type' => 'range', 'value' => '' ],
+ ];
# <button> specific handling
# see remarks on http://msdn.microsoft.com/en-us/library/ie/ms535211%28v=vs.85%29.aspx
- $cases[] = array( '<button type=submit></button>',
- 'button', array( 'type' => 'submit' ),
+ $cases[] = [ '<button type=submit></button>',
+ 'button', [ 'type' => 'submit' ],
'According to standard the default type is "submit". '
. 'Depending on compatibility mode IE might use "button", instead.',
- );
+ ];
# <select> specific handling
- $cases[] = array( '<select multiple></select>',
- 'select', array( 'size' => '4', 'multiple' => true ),
- );
+ $cases[] = [ '<select multiple></select>',
+ 'select', [ 'size' => '4', 'multiple' => true ],
+ ];
# .. with numeric value
- $cases[] = array( '<select multiple></select>',
- 'select', array( 'size' => 4, 'multiple' => true ),
- );
- $cases[] = array( '<select></select>',
- 'select', array( 'size' => '1', 'multiple' => false ),
- );
+ $cases[] = [ '<select multiple></select>',
+ 'select', [ 'size' => 4, 'multiple' => true ],
+ ];
+ $cases[] = [ '<select></select>',
+ 'select', [ 'size' => '1', 'multiple' => false ],
+ ];
# .. with numeric value
- $cases[] = array( '<select></select>',
- 'select', array( 'size' => 1, 'multiple' => false ),
- );
+ $cases[] = [ '<select></select>',
+ 'select', [ 'size' => 1, 'multiple' => false ],
+ ];
# Passing an array as value
- $cases[] = array( '<a class="css-class-one css-class-two"></a>',
- 'a', array( 'class' => array( 'css-class-one', 'css-class-two' ) ),
+ $cases[] = [ '<a class="css-class-one css-class-two"></a>',
+ 'a', [ 'class' => [ 'css-class-one', 'css-class-two' ] ],
"dropDefaults accepts values given as an array"
- );
+ ];
# FIXME: doDropDefault should remove defaults given in an array
# Expected should be '<a></a>'
- $cases[] = array( '<a class=""></a>',
- 'a', array( 'class' => array( '', '' ) ),
+ $cases[] = [ '<a class=""></a>',
+ 'a', [ 'class' => [ '', '' ] ],
"dropDefaults accepts values given as an array"
- );
+ ];
# Craft the Html elements
- $ret = array();
+ $ret = [];
foreach ( $cases as $case ) {
- $ret[] = array(
+ $ret[] = [
$case[0],
$case[1], $case[2],
isset( $case[3] ) ? $case[3] : ''
- );
+ ];
}
return $ret;
*/
public function testFormValidationBlacklist() {
$this->assertEmpty(
- Html::expandAttributes( array(
+ Html::expandAttributes( [
'min' => 1,
'max' => 100,
'pattern' => 'abc',
'required' => true,
'step' => 2
- ) ),
+ ] ),
'Blacklist form validation attributes.'
);
$this->assertEquals(
' step=any',
Html::expandAttributes(
- array(
+ [
'min' => 1,
'max' => 100,
'pattern' => 'abc',
'required' => true,
'step' => 'any'
- ),
+ ],
'Allow special case "step=any".'
)
);
);
$this->assertEquals(
'<input type=checkbox value=testval name=testname>',
- Html::check( 'testname', false, array( 'value' => 'testval' ) ),
+ Html::check( 'testname', false, [ 'value' => 'testval' ] ),
'Checkbox wrapper with a value override.'
);
}
);
$this->assertEquals(
'<input type=radio value=testval name=testname>',
- Html::radio( 'testname', false, array( 'value' => 'testval' ) ),
+ Html::radio( 'testname', false, [ 'value' => 'testval' ] ),
'Radio wrapper with a value override.'
);
}
}
public static function provideSrcSetImages() {
- return array(
- array( array(), '', 'when there are no images, return empty string' ),
- array(
- array( '1x' => '1x.png', '1.5x' => '1_5x.png', '2x' => '2x.png' ),
+ return [
+ [ [], '', 'when there are no images, return empty string' ],
+ [
+ [ '1x' => '1x.png', '1.5x' => '1_5x.png', '2x' => '2x.png' ],
'1x.png 1x, 1_5x.png 1.5x, 2x.png 2x',
'pixel depth keys may include a trailing "x"'
- ),
- array(
- array( '1' => '1x.png', '1.5' => '1_5x.png', '2' => '2x.png' ),
+ ],
+ [
+ [ '1' => '1x.png', '1.5' => '1_5x.png', '2' => '2x.png' ],
'1x.png 1x, 1_5x.png 1.5x, 2x.png 2x',
'pixel depth keys may omit a trailing "x"'
- ),
- );
+ ],
+ ];
}
/**