test: full coverage of Html::dropDefaults()
authorAntoine Musso <hashar@free.fr>
Thu, 30 Aug 2012 10:49:57 +0000 (12:49 +0200)
committerAntoine Musso <hashar@free.fr>
Sat, 15 Sep 2012 04:26:56 +0000 (21:26 -0700)
This closely match Html::dropDefaults() logic and hopefully test out
all default dropping.

Introduce a test case that match a failure in f34547ab where attribute
default values passed in an array are not cleaned up.

Change-Id: If8d16b066015ed1bcaf38408511ac3713eaa6540

includes/Html.php
tests/phpunit/includes/HtmlTest.php

index 35aa2c0..83af24a 100644 (file)
@@ -303,6 +303,8 @@ class Html {
                        return $attribs;
                }
 
+               # Whenever altering this array, please provide a covering test case
+               # in HtmlTest::provideElementsWithAttributesHavingDefaultValues
                static $attribDefaults = array(
                        'area' => array( 'shape' => 'rect' ),
                        'button' => array(
index a4ddf85..a18f792 100644 (file)
@@ -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 ) {