[Html::namespaceSelector] Remove default id/name attributes
[lhc/web/wiklou.git] / tests / phpunit / includes / HtmlTest.php
index 9e2deb1..8b019d7 100644 (file)
@@ -215,7 +215,7 @@ class HtmlTest extends MediaWikiTestCase {
 
        function testNamespaceSelector() {
                $this->assertEquals(
-                       '<select id="namespace" name="namespace">' . "\n" .
+                       '<select>' . "\n" .
 '<option value="0">(Main)</option>' . "\n" .
 '<option value="1">Talk</option>' . "\n" .
 '<option value="2">User</option>' . "\n" .
@@ -236,6 +236,7 @@ class HtmlTest extends MediaWikiTestCase {
                        Html::namespaceSelector(),
                        'Basic namespace selector without custom options'
                );
+
                $this->assertEquals(
                        '<label for="mw-test-namespace">Select a namespace:</label>&#160;' .
 '<select id="mw-test-namespace" name="wpNamespace">' . "\n" .
@@ -263,11 +264,37 @@ class HtmlTest extends MediaWikiTestCase {
                        ),
                        'Basic namespace selector with custom values'
                );
-               }
 
-               function testCanFilterOutNamespaces() {
-                       $this->assertEquals(
-'<select id="namespace" name="namespace">' . "\n" .
+               $this->assertEquals(
+                       '<label>Select a namespace:</label>&#160;' .
+'<select>' . "\n" .
+'<option value="0">(Main)</option>' . "\n" .
+'<option value="1">Talk</option>' . "\n" .
+'<option value="2">User</option>' . "\n" .
+'<option value="3">User talk</option>' . "\n" .
+'<option value="4">MyWiki</option>' . "\n" .
+'<option value="5">MyWiki Talk</option>' . "\n" .
+'<option value="6">File</option>' . "\n" .
+'<option value="7">File talk</option>' . "\n" .
+'<option value="8">MediaWiki</option>' . "\n" .
+'<option value="9">MediaWiki talk</option>' . "\n" .
+'<option value="10">Template</option>' . "\n" .
+'<option value="11">Template talk</option>' . "\n" .
+'<option value="14">Category</option>' . "\n" .
+'<option value="15">Category talk</option>' . "\n" .
+'<option value="100">Custom</option>' . "\n" .
+'<option value="101">Custom talk</option>' . "\n" .
+'</select>',
+                       Html::namespaceSelector(
+                               array( 'label' => 'Select a namespace:' )
+                       ),
+                       'Basic namespace selector with a custom label but no id attribtue for the <select>'
+               );
+       }
+
+       function testCanFilterOutNamespaces() {
+               $this->assertEquals(
+'<select>' . "\n" .
 '<option value="2">User</option>' . "\n" .
 '<option value="4">MyWiki</option>' . "\n" .
 '<option value="5">MyWiki Talk</option>' . "\n" .
@@ -285,11 +312,11 @@ class HtmlTest extends MediaWikiTestCase {
                        ),
                        'Namespace selector namespace filtering.'
                );
-               }
+       }
 
-               function testCanDisableANamespaces() {
-                       $this->assertEquals(
-'<select id="namespace" name="namespace">' . "\n" .
+       function testCanDisableANamespaces() {
+               $this->assertEquals(
+'<select>' . "\n" .
 '<option disabled="" value="0">(Main)</option>' . "\n" .
 '<option disabled="" value="1">Talk</option>' . "\n" .
 '<option disabled="" value="2">User</option>' . "\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 <select> attributes generated by Html::namespaceSelector()
-        * This helper expect the Html method to use 'namespace' as a default value for
-        * both 'id' and 'name' attributes.
-        *
-        * @param String $expectedId <select> id attribute value
-        * @param String $expectedName <select> name attribute value
-        * @param String $html Output of a call to Html::namespaceSelector()
-        * @param String $msg Optional message (default: '')
-       */
-       function assertNsSelectorIdAndName( $expectedId, $expectedName, $html, $msg = '' ) {
-               $actualId = 'namespace';
-               if( 1 === preg_match( '/id="(.+?)"/', $html, $m ) ) {
-                       $actualId = $m[1];
-               }
-
-               $actualName = 'namespace';
-               if( 1 === preg_match( '/name="(.+?)"/', $html, $m ) ) {
-                       $actualName = $m[1];
-               }
-               $this->assertEquals(
-                       array( #expected
-                               'id'   => $expectedId,
-                               'name' => $expectedName,
-                       ),
-                       array( #actual
-                               'id'   => $actualId,
-                               'name' => $actualName,
-                       ),
-                       'Html::namespaceSelector() got wrong id and/or name attribute(s). ' . $msg
-               );
-       }
-
 }