From: Antoine Musso Date: Thu, 30 Aug 2012 10:49:57 +0000 (+0200) Subject: test: full coverage of Html::dropDefaults() X-Git-Tag: 1.31.0-rc.0~22375 X-Git-Url: https://git.cyclocoop.org/?a=commitdiff_plain;h=1a7da4f625bd24ba760e2f3055ea2c62f08e36ba;p=lhc%2Fweb%2Fwiklou.git test: full coverage of Html::dropDefaults() 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 --- diff --git a/includes/Html.php b/includes/Html.php index 35aa2c01c8..83af24aff3 100644 --- a/includes/Html.php +++ b/includes/Html.php @@ -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( diff --git a/tests/phpunit/includes/HtmlTest.php b/tests/phpunit/includes/HtmlTest.php index a4ddf85cee..a18f7922f0 100644 --- a/tests/phpunit/includes/HtmlTest.php +++ b/tests/phpunit/includes/HtmlTest.php @@ -419,6 +419,92 @@ class HtmlTest extends MediaWikiTestCase { # , , [, ] # Will be mapped to Html::element() $cases = array(); + + ### Generic cases, match $attribDefault static array + $cases[] = array( '', + 'area', array( 'shape' => 'rect' ) + ); + + $cases[] = array( '', + 'button', array( 'formaction' => 'GET' ) + ); + $cases[] = array( '', + 'button', array( 'formenctype' => 'application/x-www-form-urlencoded' ) + ); + $cases[] = array( '', + 'button', array( 'type' => 'submit' ) + ); + + $cases[] = array( '', + 'canvas', array( 'height' => '150' ) + ); + $cases[] = array( '', + 'canvas', array( 'width' => '300' ) + ); + # Also check with numeric values + $cases[] = array( '', + 'canvas', array( 'height' => 150 ) + ); + $cases[] = array( '', + 'canvas', array( 'width' => 300 ) + ); + + $cases[] = array( '', + 'command', array( 'type' => 'command' ) + ); + + $cases[] = array( '
', + 'form', array( 'action' => 'GET' ) + ); + $cases[] = array( '
', + 'form', array( 'autocomplete' => 'on' ) + ); + $cases[] = array( '
', + 'form', array( 'enctype' => 'application/x-www-form-urlencoded' ) + ); + + $cases[] = array( '', + 'input', array( 'formaction' => 'GET' ) + ); + $cases[] = array( '', + 'input', array( 'type' => 'text' ) + ); + + $cases[] = array( '', + 'keygen', array( 'keytype' => 'rsa' ) + ); + + $cases[] = array( '', + 'link', array( 'media' => 'all' ) + ); + + $cases[] = array( '', + 'menu', array( 'type' => 'list' ) + ); + + $cases[] = array( '', + 'script', array( 'type' => 'text/javascript' ) + ); + + $cases[] = array( '', + 'style', array( 'media' => 'all' ) + ); + $cases[] = array( '', + 'style', array( 'type' => 'text/css' ) + ); + + $cases[] = array( '', + 'textarea', array( 'wrap' => 'soft' ) + ); + + ### SPECIFIC CASES + + # + $cases[] = array( '', + 'link', array( 'type' => 'text/css' ) + ); + + # specific handling $cases[] = array( '', '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', array( 'size' => '4', 'multiple' => true ), + ); + # .. with numeric value + $cases[] = array( '', + 'select', array( 'size' => 4, 'multiple' => true ), + ); + $cases[] = array( '', + 'select', array( 'size' => '1', 'multiple' => false ), + ); + # .. with numeric value + $cases[] = array( '', + 'select', array( 'size' => 1, 'multiple' => false ), + ); + + # Passing an array as value + $cases[] = array( '', + '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 '' + $cases[] = array( '', + 'a', array( 'class' => array( '', '' ) ), + "dropDefaults accepts values given as an array" + ); + + # Craft the Html elements $ret = array(); foreach( $cases as $case ) {