Merge "API: Warn when unsupported PHP array syntax is used"
[lhc/web/wiklou.git] / tests / phpunit / includes / HtmlTest.php
index b6e23ab..e934965 100644 (file)
@@ -37,14 +37,14 @@ class HtmlTest extends MediaWikiTestCase {
                        'wgLanguageCode' => $langCode,
                        'wgContLang' => $langObj,
                        'wgLang' => $langObj,
-                       'wgHtml5' => true,
                        'wgWellFormedXml' => false,
                ) );
        }
 
+       /**
+        * @covers Html::element
+        */
        public function testElementBasics() {
-               global $wgWellFormedXml;
-
                $this->assertEquals(
                        '<img>',
                        Html::element( 'img', null, '' ),
@@ -63,7 +63,7 @@ class HtmlTest extends MediaWikiTestCase {
                        'Close tag for empty element (array, string)'
                );
 
-               $wgWellFormedXml = true;
+               $this->setMwGlobals( 'wgWellFormedXml', true );
 
                $this->assertEquals(
                        '<img />',
@@ -72,6 +72,35 @@ class HtmlTest extends MediaWikiTestCase {
                );
        }
 
+       public function dataXmlMimeType() {
+               return array(
+                       // ( $mimetype, $isXmlMimeType )
+                       # HTML is not an XML MimeType
+                       array( 'text/html', false ),
+                       # XML is an XML MimeType
+                       array( 'text/xml', true ),
+                       array( 'application/xml', true ),
+                       # XHTML is an XML MimeType
+                       array( '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 ),
+                       # Complete random other MimeTypes are not XML
+                       array( 'text/plain', false ),
+               );
+       }
+
+       /**
+        * @dataProvider dataXmlMimeType
+        * @covers Html::isXmlMimeType
+        */
+       public function testXmlMimeType( $mimetype, $isXmlMimeType ) {
+               $this->assertEquals( $isXmlMimeType, Html::isXmlMimeType( $mimetype ) );
+       }
+
+       /**
+        * @covers HTML::expandAttributes
+        */
        public function testExpandAttributesSkipsNullAndFalse() {
 
                ### EMPTY ########
@@ -89,9 +118,10 @@ class HtmlTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @covers HTML::expandAttributes
+        */
        public function testExpandAttributesForBooleans() {
-               global $wgHtml5, $wgWellFormedXml;
-
                $this->assertEquals(
                        '',
                        Html::expandAttributes( array( 'selected' => false ) ),
@@ -114,30 +144,21 @@ class HtmlTest extends MediaWikiTestCase {
                        'Boolean attributes have no value when value is true (passed as numerical array)'
                );
 
-               $wgWellFormedXml = true;
+               $this->setMwGlobals( 'wgWellFormedXml', true );
 
                $this->assertEquals(
                        ' selected=""',
                        Html::expandAttributes( array( 'selected' => true ) ),
                        'Boolean attributes have empty string value when value is true (wgWellFormedXml)'
                );
-
-               $wgHtml5 = false;
-
-               $this->assertEquals(
-                       ' selected="selected"',
-                       Html::expandAttributes( array( 'selected' => true ) ),
-                       'Boolean attributes have their key as value when value is true (wgWellFormedXml, wgHTML5 = false)'
-               );
        }
 
        /**
         * Test for Html::expandAttributes()
         * Please note it output a string prefixed with a space!
+        * @covers Html::expandAttributes
         */
        public function testExpandAttributesVariousExpansions() {
-               global $wgWellFormedXml;
-
                ### NOT EMPTY ####
                $this->assertEquals(
                        ' empty_string=""',
@@ -160,7 +181,7 @@ class HtmlTest extends MediaWikiTestCase {
                        'Number 0 value needs no quotes'
                );
 
-               $wgWellFormedXml = true;
+               $this->setMwGlobals( 'wgWellFormedXml', true );
 
                $this->assertEquals(
                        ' empty_string=""',
@@ -188,6 +209,7 @@ class HtmlTest extends MediaWikiTestCase {
         * Html::expandAttributes has special features for HTML
         * attributes that use space separated lists and also
         * allows arrays to be used as values.
+        * @covers Html::expandAttributes
         */
        public function testExpandAttributesListValueAttributes() {
                ### STRING VALUES
@@ -239,8 +261,9 @@ class HtmlTest extends MediaWikiTestCase {
        /**
         * Test feature added by r96188, let pass attributes values as
         * a PHP array. Restricted to class,rel, accesskey.
+        * @covers Html::expandAttributes
         */
-       function testExpandAttributesSpaceSeparatedAttributesWithBoolean() {
+       public function testExpandAttributesSpaceSeparatedAttributesWithBoolean() {
                $this->assertEquals(
                        ' class="booltrue one"',
                        Html::expandAttributes( array( 'class' => array(
@@ -263,8 +286,9 @@ class HtmlTest extends MediaWikiTestCase {
         * The later will take precedence.
         *
         * Feature added by r96188
+        * @covers Html::expandAttributes
         */
-       function testValueIsAuthoritativeInSpaceSeparatedAttributesArrays() {
+       public function testValueIsAuthoritativeInSpaceSeparatedAttributesArrays() {
                $this->assertEquals(
                        ' class=""',
                        Html::expandAttributes( array( 'class' => array(
@@ -275,7 +299,10 @@ class HtmlTest extends MediaWikiTestCase {
                );
        }
 
-       function testNamespaceSelector() {
+       /**
+        * @covers Html::namespaceSelector
+        */
+       public function testNamespaceSelector() {
                $this->assertEquals(
                        '<select id=namespace name=namespace>' . "\n" .
                                '<option value=0>(Main)</option>' . "\n" .
@@ -354,7 +381,7 @@ class HtmlTest extends MediaWikiTestCase {
                );
        }
 
-       function testCanFilterOutNamespaces() {
+       public function testCanFilterOutNamespaces() {
                $this->assertEquals(
                        '<select id=namespace name=namespace>' . "\n" .
                                '<option value=2>User</option>' . "\n" .
@@ -376,7 +403,7 @@ class HtmlTest extends MediaWikiTestCase {
                );
        }
 
-       function testCanDisableANamespaces() {
+       public function testCanDisableANamespaces() {
                $this->assertEquals(
                        '<select id=namespace name=namespace>' . "\n" .
                                '<option disabled value=0>(Main)</option>' . "\n" .
@@ -405,8 +432,9 @@ class HtmlTest extends MediaWikiTestCase {
 
        /**
         * @dataProvider provideHtml5InputTypes
+        * @covers Html::element
         */
-       function testHtmlElementAcceptsNewHtml5TypesInHtml5Mode( $HTML5InputType ) {
+       public function testHtmlElementAcceptsNewHtml5TypesInHtml5Mode( $HTML5InputType ) {
                $this->assertEquals(
                        '<input type=' . $HTML5InputType . '>',
                        Html::element( 'input', array( 'type' => $HTML5InputType ) ),
@@ -418,7 +446,7 @@ class HtmlTest extends MediaWikiTestCase {
         * List of input element types values introduced by HTML5
         * Full list at http://www.w3.org/TR/html-markup/input.html
         */
-       function provideHtml5InputTypes() {
+       public static function provideHtml5InputTypes() {
                $types = array(
                        'datetime',
                        'datetime-local',
@@ -438,15 +466,16 @@ class HtmlTest extends MediaWikiTestCase {
                foreach ( $types as $type ) {
                        $cases[] = array( $type );
                }
+
                return $cases;
        }
 
        /**
         * Test out Html::element drops or enforces default value
-        * @cover Html::dropDefaults
+        * @covers Html::dropDefaults
         * @dataProvider provideElementsWithAttributesHavingDefaultValues
         */
-       function testDropDefaults( $expected, $element, $attribs, $message = '' ) {
+       public function testDropDefaults( $expected, $element, $attribs, $message = '' ) {
                $this->assertEquals( $expected, Html::element( $element, $attribs ), $message );
        }
 
@@ -561,7 +590,8 @@ class HtmlTest extends MediaWikiTestCase {
                # 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' ),
-                       'According to standard the default type is "submit". Depending on compatibility mode IE might use "button", instead.',
+                       'According to standard the default type is "submit". '
+                               . 'Depending on compatibility mode IE might use "button", instead.',
                );
 
                # <select> specifc handling
@@ -602,19 +632,36 @@ class HtmlTest extends MediaWikiTestCase {
                                isset( $case[3] ) ? $case[3] : ''
                        );
                }
+
                return $ret;
        }
 
+       /**
+        * @covers Html::expandAttributes
+        */
        public function testFormValidationBlacklist() {
                $this->assertEmpty(
-                       Html::expandAttributes( array( 'min' => 1, 'max' => 100, 'pattern' => 'abc', 'required' => true, 'step' => 2 ) ),
+                       Html::expandAttributes( array(
+                               '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".'
+                       Html::expandAttributes(
+                               array(
+                                       'min' => 1,
+                                       'max' => 100,
+                                       'pattern' => 'abc',
+                                       'required' => true,
+                                       'step' => 'any'
+                               ),
+                               'Allow special case "step=any".'
+                       )
                );
        }
-
 }