Merge "Phase out tests/jasmine; Update mediawiki i18n tests"
[lhc/web/wiklou.git] / tests / phpunit / includes / HtmlTest.php
index a4ddf85..05dea35 100644 (file)
@@ -9,14 +9,14 @@ class HtmlTest extends MediaWikiTestCase {
        private static $oldHTML5;
 
        public function setUp() {
-               global $wgLang, $wgContLang, $wgLanguageCode, $wgHTML5;
+               global $wgLang, $wgContLang, $wgLanguageCode, $wgHtml5;
 
                // Save globals
                self::$oldLang = $wgLang;
                self::$oldContLang = $wgContLang;
                self::$oldNamespaces = $wgContLang->getNamespaces();
                self::$oldLanguageCode = $wgLanguageCode;
-               self::$oldHTML5 = $wgHTML5;
+               self::$oldHTML5 = $wgHtml5;
 
                $wgLanguageCode = 'en';
                $wgContLang = $wgLang = Language::factory( $wgLanguageCode );
@@ -47,33 +47,33 @@ class HtmlTest extends MediaWikiTestCase {
        }
 
        public function tearDown() {
-               global $wgLang, $wgContLang, $wgLanguageCode, $wgHTML5;
+               global $wgLang, $wgContLang, $wgLanguageCode, $wgHtml5;
 
                // Restore globals
                $wgContLang->setNamespaces( self::$oldNamespaces );
                $wgLang = self::$oldLang;
                $wgContLang = self::$oldContLang;
                $wgLanguageCode = self::$oldLanguageCode;
-               $wgHTML5 = self::$oldHTML5;
+               $wgHtml5 = self::$oldHTML5;
        }
 
        /**
-        * Wrapper to easily set $wgHTML5 = true.
+        * Wrapper to easily set $wgHtml5 = true.
         * Original value will be restored after test completion.
         * @todo Move to MediaWikiTestCase
         */
        public function enableHTML5() {
-               global $wgHTML5;
-               $wgHTML5 = true;
+               global $wgHtml5;
+               $wgHtml5 = true;
        }
        /**
-        * Wrapper to easily set $wgHTML5 = false
+        * Wrapper to easily set $wgHtml5 = false
         * Original value will be restored after test completion.
         * @todo Move to MediaWikiTestCase
         */
        public function disableHTML5() {
-               global $wgHTML5;
-               $wgHTML5 = false;
+               global $wgHtml5;
+               $wgHtml5 = false;
        }
 
        public function testExpandAttributesSkipsNullAndFalse() {
@@ -239,7 +239,7 @@ class HtmlTest extends MediaWikiTestCase {
 
        function testNamespaceSelector() {
                $this->assertEquals(
-                       '<select>' . "\n" .
+                       '<select id="namespace" name="namespace">' . "\n" .
 '<option value="0">(Main)</option>' . "\n" .
 '<option value="1">Talk</option>' . "\n" .
 '<option value="2">User</option>' . "\n" .
@@ -290,8 +290,8 @@ class HtmlTest extends MediaWikiTestCase {
                );
 
                $this->assertEquals(
-                       '<label>Select a namespace:</label>&#160;' .
-'<select>' . "\n" .
+                       '<label for="namespace">Select a namespace:</label>&#160;' .
+'<select id="namespace" name="namespace">' . "\n" .
 '<option value="0">(Main)</option>' . "\n" .
 '<option value="1">Talk</option>' . "\n" .
 '<option value="2">User</option>' . "\n" .
@@ -318,7 +318,7 @@ class HtmlTest extends MediaWikiTestCase {
 
        function testCanFilterOutNamespaces() {
                $this->assertEquals(
-'<select>' . "\n" .
+'<select id="namespace" name="namespace">' . "\n" .
 '<option value="2">User</option>' . "\n" .
 '<option value="4">MyWiki</option>' . "\n" .
 '<option value="5">MyWiki Talk</option>' . "\n" .
@@ -340,7 +340,7 @@ class HtmlTest extends MediaWikiTestCase {
 
        function testCanDisableANamespaces() {
                $this->assertEquals(
-'<select>' . "\n" .
+'<select id="namespace" name="namespace">' . "\n" .
 '<option disabled="" value="0">(Main)</option>' . "\n" .
 '<option disabled="" value="1">Talk</option>' . "\n" .
 '<option disabled="" value="2">User</option>' . "\n" .
@@ -372,7 +372,7 @@ class HtmlTest extends MediaWikiTestCase {
                $this->enableHTML5();
                $this->assertEquals(
                        '<input type="' . $HTML5InputType . '" />',
-                       HTML::element( 'input', array( 'type' => $HTML5InputType ) ),
+                       Html::element( 'input', array( 'type' => $HTML5InputType ) ),
                        'In HTML5, HTML::element() should accept type="' . $HTML5InputType . '"'
                );
        }
@@ -419,6 +419,92 @@ class HtmlTest extends MediaWikiTestCase {
                # <expected>, <element name>, <array of attributes> [, <message>]
                # Will be mapped to Html::element()
                $cases = array();
+
+               ### Generic cases, match $attribDefault static array
+               $cases[] = array( '<area />',
+                       'area', array( 'shape' => 'rect' )
+               );
+
+               $cases[] = array( '<button></button>',
+                       'button', array( 'formaction' => 'GET' )
+               );
+               $cases[] = array( '<button></button>',
+                       'button', array( 'formenctype' => 'application/x-www-form-urlencoded' )
+               );
+               $cases[] = array( '<button></button>',
+                       'button', array( 'type' => 'submit' )
+               );
+
+               $cases[] = array( '<canvas></canvas>',
+                       'canvas', array( 'height' => '150' )
+               );
+               $cases[] = array( '<canvas></canvas>',
+                       'canvas', array( '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' )
+               );
+
+               ### SPECIFIC CASES
+
+               # <link type="text/css" />
+               $cases[] = array( '<link />',
+                       'link', array( 'type' => 'text/css' )
+               );
+
+               # <input /> specific handling
                $cases[] = array( '<input type="checkbox" />',
                        'input', array( 'type' => 'checkbox', 'value' => 'on' ),
                        'Default value "on" is stripped of checkboxes',
@@ -438,6 +524,36 @@ class HtmlTest extends MediaWikiTestCase {
                        'input', array( 'type' => 'range', 'value' => '' ),
                );
 
+               # <select /> specifc handling
+               $cases[] = array( '<select multiple=""></select>',
+                       'select', array( '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 ),
+               );
+               # .. with numeric value
+               $cases[] = array( '<select></select>',
+                       'select', array( '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' ) ),
+                       "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( '', '' ) ),
+                       "dropDefaults accepts values given as an array"
+               );
+
+
                # Craft the Html elements
                $ret = array();
                foreach( $cases as $case ) {