From 4a1c7381d2a3d1a9632de141f20af8f19408c07f Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Fri, 17 Mar 2017 18:25:12 -0700 Subject: [PATCH] Xml: Add test for listDropDown and remove unused getArrayFromWikiTextList Follows-up 4b49705613 and 8c7095be85 (T34950). Change-Id: I95b7f7ce03b2cbe68215a7ff17afc1997a54f9b1 --- includes/Xml.php | 30 ------------------------------ tests/phpunit/includes/XmlTest.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/includes/Xml.php b/includes/Xml.php index d24a27cfa8..4e8796744c 100644 --- a/includes/Xml.php +++ b/includes/Xml.php @@ -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. * diff --git a/tests/phpunit/includes/XmlTest.php b/tests/phpunit/includes/XmlTest.php index 184dd438d2..6c059ec5fd 100644 --- a/tests/phpunit/includes/XmlTest.php +++ b/tests/phpunit/includes/XmlTest.php @@ -397,4 +397,33 @@ class XmlTest extends MediaWikiTestCase { 'encodeJsVar() with float-like string' ); } + + /** + * @covers Xml::listDropDown + */ + public function testListDropDown() { + $this->assertEquals( + '', + 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 + ) + ); + } } -- 2.20.1