X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FHtmlTest.php;h=05dea35d8142bdfe9c72b88f3c0ddb995c342273;hb=9ca68b1a0fb52fc05288635da72c1304d6b8ff27;hp=0dd85c19e3fbbc102166cd49589b53604c3df0bc;hpb=987319a54adf9f6208534b5ac3b60d6f88bbf7e4;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/HtmlTest.php b/tests/phpunit/includes/HtmlTest.php index 0dd85c19e3..05dea35d81 100644 --- a/tests/phpunit/includes/HtmlTest.php +++ b/tests/phpunit/includes/HtmlTest.php @@ -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( - '' . "\n" . '' . "\n" . '' . "\n" . '' . "\n" . @@ -290,8 +290,8 @@ class HtmlTest extends MediaWikiTestCase { ); $this->assertEquals( - ' ' . -'' . "\n" . '' . "\n" . '' . "\n" . '' . "\n" . @@ -318,7 +318,7 @@ class HtmlTest extends MediaWikiTestCase { function testCanFilterOutNamespaces() { $this->assertEquals( -'' . "\n" . '' . "\n" . '' . "\n" . '' . "\n" . @@ -340,7 +340,7 @@ class HtmlTest extends MediaWikiTestCase { function testCanDisableANamespaces() { $this->assertEquals( -'' . "\n" . '' . "\n" . '' . "\n" . '' . "\n" . @@ -365,4 +365,204 @@ class HtmlTest extends MediaWikiTestCase { ); } + /** + * @dataProvider providesHtml5InputTypes + */ + function testHtmlElementAcceptsNewHtml5TypesInHtml5Mode( $HTML5InputType ) { + $this->enableHTML5(); + $this->assertEquals( + '', + Html::element( 'input', array( 'type' => $HTML5InputType ) ), + 'In HTML5, HTML::element() should accept type="' . $HTML5InputType . '"' + ); + } + + /** + * List of input element types values introduced by HTML5 + * Full list at http://www.w3.org/TR/html-markup/input.html + */ + function providesHtml5InputTypes() { + $types = array( + 'datetime', + 'datetime-local', + 'date', + 'month', + 'time', + 'week', + 'number', + 'range', + 'email', + 'url', + 'search', + 'tel', + 'color', + ); + $cases = array(); + foreach( $types as $type ) { + $cases[] = array( $type ); + } + return $cases; + } + + /** + * Test out Html::element drops default value + * @cover Html::dropDefaults + * @dataProvider provideElementsWithAttributesHavingDefaultValues + */ + function testDropDefaults( $expected, $element, $message = '' ) { + $this->enableHTML5(); + $this->assertEquals( $expected, $element, $message ); + } + + function provideElementsWithAttributesHavingDefaultValues() { + # Use cases in a concise format: + # , , [, ] + # 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', + ); + $cases[] = array( '', + 'input', array( 'type' => 'radio', 'value' => 'on' ), + 'Default value "on" is stripped of radio buttons', + ); + $cases[] = array( '', + 'input', array( 'type' => 'submit', 'value' => 'Submit' ), + 'Default value "Submit" is kept on submit buttons (for possible l10n issues)', + ); + $cases[] = array( '', + 'input', array( 'type' => 'color', 'value' => '' ), + ); + $cases[] = array( '', + '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 ) { + $ret[] = array( + $case[0], + Html::element( $case[1], $case[2] ) + ); + } + return $ret; + } + }