From 63601400e476c6cf43d985f3e7b9864681695ed4 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Fri, 18 Jan 2013 16:46:04 +0100 Subject: Update to MediaWiki 1.20.2 this update includes: * adjusted Arch Linux skin * updated FluxBBAuthPlugin * patch for https://bugzilla.wikimedia.org/show_bug.cgi?id=44024 --- tests/phpunit/includes/HtmlTest.php | 361 +++++++++++++++++++++++++++++------- 1 file changed, 298 insertions(+), 63 deletions(-) (limited to 'tests/phpunit/includes/HtmlTest.php') diff --git a/tests/phpunit/includes/HtmlTest.php b/tests/phpunit/includes/HtmlTest.php index 67b60d32..a18f7922 100644 --- a/tests/phpunit/includes/HtmlTest.php +++ b/tests/phpunit/includes/HtmlTest.php @@ -6,15 +6,18 @@ class HtmlTest extends MediaWikiTestCase { private static $oldContLang; private static $oldLanguageCode; private static $oldNamespaces; + private static $oldHTML5; public function setUp() { - global $wgLang, $wgContLang, $wgLanguageCode; - + global $wgLang, $wgContLang, $wgLanguageCode, $wgHTML5; + + // Save globals self::$oldLang = $wgLang; self::$oldContLang = $wgContLang; self::$oldNamespaces = $wgContLang->getNamespaces(); self::$oldLanguageCode = $wgLanguageCode; - + self::$oldHTML5 = $wgHTML5; + $wgLanguageCode = 'en'; $wgContLang = $wgLang = Language::factory( $wgLanguageCode ); @@ -36,18 +39,41 @@ class HtmlTest extends MediaWikiTestCase { 9 => 'MediaWiki_talk', 10 => 'Template', 11 => 'Template_talk', + 14 => 'Category', + 15 => 'Category_talk', 100 => 'Custom', 101 => 'Custom_talk', ) ); } - + public function tearDown() { - global $wgLang, $wgContLang, $wgLanguageCode; + global $wgLang, $wgContLang, $wgLanguageCode, $wgHTML5; + // Restore globals $wgContLang->setNamespaces( self::$oldNamespaces ); $wgLang = self::$oldLang; $wgContLang = self::$oldContLang; $wgLanguageCode = self::$oldLanguageCode; + $wgHTML5 = self::$oldHTML5; + } + + /** + * 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; + } + /** + * 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; } public function testExpandAttributesSkipsNullAndFalse() { @@ -213,7 +239,7 @@ class HtmlTest extends MediaWikiTestCase { function testNamespaceSelector() { $this->assertEquals( - '' . "\n" . '' . "\n" . '' . "\n" . '' . "\n" . @@ -226,12 +252,15 @@ class HtmlTest extends MediaWikiTestCase { '' . "\n" . '' . "\n" . '' . "\n" . +'' . "\n" . +'' . "\n" . '' . "\n" . '' . "\n" . '', Html::namespaceSelector(), 'Basic namespace selector without custom options' ); + $this->assertEquals( ' ' . '', @@ -257,77 +288,281 @@ class HtmlTest extends MediaWikiTestCase { ), 'Basic namespace selector with custom values' ); - } - function testNamespaceSelectorIdAndNameDefaultsAttributes() { - - $this->assertNsSelectorIdAndName( - 'namespace', 'namespace', - Html::namespaceSelector( array(), array( - # neither 'id' nor 'name' key given - )), - "Neither 'id' nor 'name' key given" + $this->assertEquals( + ' ' . +'', + Html::namespaceSelector( + array( 'label' => 'Select a namespace:' ) + ), + 'Basic namespace selector with a custom label but no id attribtue for the ' . "\n" . +'' . "\n" . +'' . "\n" . +'' . "\n" . +'' . "\n" . +'' . "\n" . +'' . "\n" . +'' . "\n" . +'' . "\n" . +'' . "\n" . +'' . "\n" . +'' . "\n" . +'', + Html::namespaceSelector( + array( 'exclude' => array( 0, 1, 3, 100, 101 ) ) + ), + 'Namespace selector namespace filtering.' ); + } - $this->assertNsSelectorIdAndName( - 'select_id', 'namespace', - Html::namespaceSelector( array(), array( - 'id' => 'select_id', - # no 'name' key given - )), - "'id' given, no 'name' key given" + function testCanDisableANamespaces() { + $this->assertEquals( +'', + Html::namespaceSelector( array( + 'disable' => array( 0, 1, 2, 3, 4 ) + ) ), + 'Namespace selector namespace disabling' ); + } - $this->assertNsSelectorIdAndName( - 'select_id', 'select_name', - Html::namespaceSelector( array(), array( - 'id' => 'select_id', - 'name' => 'select_name', - )), - "Both 'id' and 'name' given" + /** + * @dataProvider providesHtml5InputTypes + */ + function testHtmlElementAcceptsNewHtml5TypesInHtml5Mode( $HTML5InputType ) { + $this->enableHTML5(); + $this->assertEquals( + '', + HTML::element( 'input', array( 'type' => $HTML5InputType ) ), + 'In HTML5, HTML::element() should accept type="' . $HTML5InputType . '"' ); } /** - * Helper to verify id attribute value - * @param String $expectedName ', + '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; } } -- cgit v1.2.2