Reduce code duplication for parsing messages into dropdown menus
[lhc/web/wiklou.git] / tests / phpunit / includes / XmlTest.php
index 18ff1f4..25b754d 100644 (file)
@@ -83,7 +83,7 @@ class XmlTest extends MediaWikiTestCase {
                $this->assertEquals(
                        '<input name="name" value="0" />',
                        Xml::input( 'name', false, 0 ),
-                       'Input with a value of 0 (bug 23797)'
+                       'Input with a value of 0 (T25797)'
                );
        }
 
@@ -397,4 +397,84 @@ class XmlTest extends MediaWikiTestCase {
                        'encodeJsVar() with float-like string'
                );
        }
+
+       /**
+        * @covers Xml::listDropDown
+        */
+       public function testListDropDown() {
+               $this->assertEquals(
+                       '<select name="test-name" id="test-name" class="test-css" tabindex="2">' .
+                               '<option value="other">other reasons</option>' . "\n" .
+                               '<optgroup label="Foo">' .
+                               '<option value="Foo 1">Foo 1</option>' . "\n" .
+                               '<option value="Example" selected="">Example</option>' . "\n" .
+                               '</optgroup>' . "\n" .
+                               '<optgroup label="Bar">' .
+                               '<option value="Bar 1">Bar 1</option>' . "\n" .
+                               '</optgroup>' .
+                               '</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
+                       )
+               );
+       }
+
+       /**
+        * @covers Xml::listDropDownOptions
+        */
+       public function testListDropDownOptions() {
+               $this->assertEquals(
+                       [
+                               'other reasons' => 'other',
+                               'Foo' => [
+                                       'Foo 1' => 'Foo 1',
+                                       'Example' => 'Example',
+                               ],
+                               'Bar' => [
+                                       'Bar 1' => 'Bar 1',
+                               ],
+                       ],
+                       Xml::listDropDownOptions(
+                               "* Foo\n** Foo 1\n** Example\n* Bar\n** Bar 1",
+                               [ 'other' => 'other reasons' ]
+                       )
+               );
+       }
+
+       /**
+        * @covers Xml::listDropDownOptionsOoui
+        */
+       public function testListDropDownOptionsOoui() {
+               $this->assertEquals(
+                       [
+                               [ 'data' => 'other', 'label' => 'other reasons' ],
+                               [ 'optgroup' => 'Foo' ],
+                               [ 'data' => 'Foo 1', 'label' => 'Foo 1' ],
+                               [ 'data' => 'Example', 'label' => 'Example' ],
+                               [ 'optgroup' => 'Bar' ],
+                               [ 'data' => 'Bar 1', 'label' => 'Bar 1' ],
+                       ],
+                       Xml::listDropDownOptionsOoui( [
+                               'other reasons' => 'other',
+                               'Foo' => [
+                                       'Foo 1' => 'Foo 1',
+                                       'Example' => 'Example',
+                               ],
+                               'Bar' => [
+                                       'Bar 1' => 'Bar 1',
+                               ],
+                       ] )
+               );
+       }
 }