Xml: Add test for listDropDown and remove unused getArrayFromWikiTextList
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 18 Mar 2017 01:25:12 +0000 (18:25 -0700)
committerKrinkle <krinklemail@gmail.com>
Mon, 20 Mar 2017 22:47:19 +0000 (22:47 +0000)
Follows-up 4b49705613 and 8c7095be85 (T34950).

Change-Id: I95b7f7ce03b2cbe68215a7ff17afc1997a54f9b1

includes/Xml.php
tests/phpunit/includes/XmlTest.php

index d24a27c..4e87967 100644 (file)
@@ -563,36 +563,6 @@ class Xml {
                        . Xml::closeElement( 'select' );
        }
 
-       /**
-        * Converts textual drop-down list to array
-        *
-        * @param string $list Correctly formatted text (newline delimited) to be
-        *   used to generate the options.
-        * @return array
-        */
-       public static function getArrayFromWikiTextList( $list = '' ) {
-               $options = [];
-
-               foreach ( explode( "\n", $list ) as $option ) {
-                       $value = trim( $option );
-                       if ( $value == '' ) {
-                               continue;
-                       } elseif ( substr( $value, 0, 1 ) == '*' && substr( $value, 1, 1 ) != '*' ) {
-                               // A new group is starting ...
-                               $value = trim( substr( $value, 1 ) );
-                               $options[] = $value;
-                       } elseif ( substr( $value, 0, 2 ) == '**' ) {
-                               // groupmember
-                               $value = trim( substr( $value, 2 ) );
-                               $options[] = $value;
-                       } else {
-                               // groupless reason list
-                               $options[] = $value;
-                       }
-               }
-               return $options;
-       }
-
        /**
         * Shortcut for creating fieldsets.
         *
index 184dd43..6c059ec 100644 (file)
@@ -397,4 +397,33 @@ class XmlTest extends MediaWikiTestCase {
                        'encodeJsVar() with float-like string'
                );
        }
+
+       /**
+        * @covers Xml::listDropDown
+        */
+       public function testListDropDown() {
+               $this->assertEquals(
+                       '<select id="test-name" name="test-name" class="test-css" tabindex="2">' . "\n" .
+                               '<option value="other">other reasons</option>' .
+                               '<optgroup label="Foo"><option value="Foo 1">Foo 1</option>' .
+                               '<option value="Example" selected="">Example</option>' .
+                               '</optgroup><optgroup label="Bar">' .
+                               '<option value="Bar 1">Bar 1</option></optgroup>' . "\n" .
+                               '</select>',
+                       Xml::listDropDown(
+                               // name
+                               'test-name',
+                               // source list
+                               "* Foo\n** Foo 1\n** Example\n* Bar\n** Bar 1",
+                               // other
+                               'other reasons',
+                               // selected
+                               'Example',
+                               // class
+                               'test-css',
+                               // tabindex
+                               2
+                       )
+               );
+       }
 }