From 1e5689852ba4d49e80e24f214cd501164a0b4ebd Mon Sep 17 00:00:00 2001 From: Krinkle Date: Wed, 7 Mar 2012 19:14:20 +0000 Subject: [PATCH] [Html::namespaceSelector] Remove default id/name attributes * Remove default id/name attributes * Remove now redundant tests introduced in r110274 * Add tests to make sure label has no 'for' attribute when label isn't null but name/id are unset * Update tests to not include id="" and name="" when calling with no arguments * Updating calls to add name/id if needed, and while at it remove useless 'null' params * Context: -- Introduced in r109990, r111376, r111315 -- No callers exist that assume these defaults. Forcing an ID that should be unique is annoying and redundant. The name used in the query when submitting a form should be mentioned in the same file where it is used from the submission, never assume what name="" is from unrelated code -- Same for ID, this is often used in CSS or JavaScript, shouldn't be assumed. (It should be simple to but two simple namespace selectors on a page without getting DOM conflicts) --- includes/Html.php | 21 ++-- includes/specials/SpecialContributions.php | 1 - includes/specials/SpecialPrefixindex.php | 2 - tests/phpunit/includes/HtmlTest.php | 116 +++++++-------------- 4 files changed, 48 insertions(+), 92 deletions(-) diff --git a/includes/Html.php b/includes/Html.php index 26a40cd80a..3986a7b100 100644 --- a/includes/Html.php +++ b/includes/Html.php @@ -718,11 +718,6 @@ class Html { public static function namespaceSelector( Array $params = array(), Array $selectAttribs = array() ) { global $wgContLang; - // Default 'id' & 'name' diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index 2a465739b9..501ccee517 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -447,7 +447,6 @@ class SpecialContributions extends SpecialPage { Html::namespaceSelector( array( 'selected' => $this->opts['namespace'], 'all' => '', - 'label' => null, ), array( 'name' => 'namespace', 'id' => 'namespace', diff --git a/includes/specials/SpecialPrefixindex.php b/includes/specials/SpecialPrefixindex.php index 5779cadd43..3202c00966 100644 --- a/includes/specials/SpecialPrefixindex.php +++ b/includes/specials/SpecialPrefixindex.php @@ -109,8 +109,6 @@ class SpecialPrefixindex extends SpecialAllpages { " . Html::namespaceSelector( array( 'selected' => $namespace, - 'all' => null, - 'label' => null, ), array( 'name' => 'namespace', 'id' => 'namespace', diff --git a/tests/phpunit/includes/HtmlTest.php b/tests/phpunit/includes/HtmlTest.php index 9e2deb14a9..8b019d78e6 100644 --- a/tests/phpunit/includes/HtmlTest.php +++ b/tests/phpunit/includes/HtmlTest.php @@ -215,7 +215,7 @@ class HtmlTest extends MediaWikiTestCase { function testNamespaceSelector() { $this->assertEquals( - '' . "\n" . '' . "\n" . '' . "\n" . '' . "\n" . @@ -236,6 +236,7 @@ class HtmlTest extends MediaWikiTestCase { Html::namespaceSelector(), 'Basic namespace selector without custom options' ); + $this->assertEquals( ' ' . '' . "\n" . + $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" . @@ -285,11 +312,11 @@ class HtmlTest extends MediaWikiTestCase { ), 'Namespace selector namespace filtering.' ); - } + } - function testCanDisableANamespaces() { - $this->assertEquals( -'' . "\n" . '' . "\n" . '' . "\n" . '' . "\n" . @@ -314,75 +341,4 @@ class HtmlTest extends MediaWikiTestCase { ); } - function testNamespaceSelectorIdAndNameDefaultsAttributes() { - - $this->assertNsSelectorIdAndName( - 'namespace', 'namespace', - Html::namespaceSelector( array(), array( - # neither 'id' nor 'name' key given - )), - "Neither 'id' nor 'name' key given" - ); - - $this->assertNsSelectorIdAndName( - 'namespace', 'select_name', - Html::namespaceSelector( array(), array( - 'name' => 'select_name', - # no 'id' key given - )), - "No 'id' key given, 'name' given" - ); - - $this->assertNsSelectorIdAndName( - 'select_id', 'namespace', - Html::namespaceSelector( array(), array( - 'id' => 'select_id', - # no 'name' key given - )), - "'id' given, no 'name' key given" - ); - - $this->assertNsSelectorIdAndName( - 'select_id', 'select_name', - Html::namespaceSelector( array(), array( - 'id' => 'select_id', - 'name' => 'select_name', - )), - "Both 'id' and 'name' given" - ); - } - - /** - * Helper to verify id attribute value - * @param String $expectedName