Xml: Add test for listDropDown and remove unused getArrayFromWikiTextList

Follows-up 4b49705613 and 8c7095be85 (T34950).

Change-Id: I95b7f7ce03b2cbe68215a7ff17afc1997a54f9b1
This commit is contained in:
Timo Tijhof 2017-03-17 18:25:12 -07:00 committed by Krinkle
parent e27ed2f378
commit 4a1c7381d2
2 changed files with 29 additions and 30 deletions

View 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.
*

View 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
)
);
}
}