* For instance, it will omit quotation marks if $wgWellFormedXml is false,
* and will treat boolean attributes specially.
*
- * Attributes that should contain space-separated lists (such as 'class') array
+ * Attributes that can contain space-separated lists ('class', 'accesskey' and 'rel') array
* values are allowed as well, which will automagically be normalized
* and converted to a space-separated string. In addition to a numerical
* array, the attribute value may also be an associative array. See the
* A value of false means to omit the attribute. For boolean attributes,
* you can omit the key, e.g., array( 'checked' ) instead of
* array( 'checked' => 'checked' ) or such.
+ *
+ * @throws MWException if an attribute that doesn't allow lists is set to an array
* @return string HTML fragment that goes between element name and '>'
* (starting with a space if at least one attribute is output)
*/
// Remove duplicates and create the string
$value = implode( ' ', array_unique( $value ) );
+ } else if ( is_array( $value ) ) {
+ throw new MWException( "HTML attribute $key can not contain a list of values" );
}
// See the "Attributes" section in the HTML syntax part of HTML5,
margin-left: 20px;
}
-.tipsy {
- padding: 5px 5px 10px;
- font-size: 12px;
- position: absolute;
- z-index: 100000;
- overflow: visible;
-}
-
-.tipsy-inner {
- padding: 5px 8px 4px 8px;
- background-color: #d6f3ff;
- color: black;
- border: 1px solid #5dc9f4;
- max-width: 300px;
- text-align: left;
-}
-
-.tipsy-arrow {
- position: absolute;
- /* @embed */
- background: url(images/tipsy-arrow.gif) no-repeat top left;
- width: 13px;
- height: 13px;
-}
-
-.tipsy-se .tipsy-arrow {
- bottom: -2px;
- right: 10px;
- background-position: 0% 100%;
-}
-
#mw-clearyourcache,
#mw-sitecsspreview,
#mw-sitejspreview,
Html::expandAttributes( array( 'foo' => false ) ),
'skip keys with false value'
);
- $this->assertNotEmpty(
+ $this->assertEquals(
+ ' foo=""',
Html::expandAttributes( array( 'foo' => '' ) ),
'keep keys with an empty string'
);
);
}
+ /**
+ * @covers HTML::expandAttributes
+ */
+ public function testExpandAttributesForNumbers() {
+ $this->assertEquals(
+ ' value=1',
+ Html::expandAttributes( array( 'value' => 1 ) ),
+ 'Integer value is cast to a string'
+ );
+ $this->assertEquals(
+ ' value=1.1',
+ Html::expandAttributes( array( 'value' => 1.1 ) ),
+ 'Float value is cast to a string'
+ );
+ }
+
+ /**
+ * @covers HTML::expandAttributes
+ */
+ public function testExpandAttributesForObjects() {
+ $this->assertEquals(
+ ' value=stringValue',
+ Html::expandAttributes( array( 'value' => new HtmlTestValue() ) ),
+ 'Object value is converted to a string'
+ );
+ }
+
/**
* Test for Html::expandAttributes()
* Please note it output a string prefixed with a space!
);
}
+ /**
+ * @covers Html::expandAttributes
+ * @expectedException MWException
+ */
+ 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(
+ 'ltr' => 'ltr.svg',
+ 'rtl' => 'rtl.svg'
+ )
+ ) );
+ }
+
/**
* @covers Html::namespaceSelector
*/
);
}
}
+
+class HtmlTestValue {
+ function __toString() {
+ return 'stringValue';
+ }
+}