. 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.
*
'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
+ )
+ );
+ }
}