+
+ /**
+ * @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',
+ ],
+ ] )
+ );
+ }
+
+ /**
+ * @covers Xml::fieldset
+ */
+ public function testFieldset() {
+ $this->assertEquals(
+ "<fieldset>\n",
+ Xml::fieldset(),
+ 'Opening tag'
+ );
+ $this->assertEquals(
+ "<fieldset>\n",
+ Xml::fieldset( false ),
+ 'Opening tag (false means no legend)'
+ );
+ $this->assertEquals(
+ "<fieldset>\n",
+ Xml::fieldset( '' ),
+ 'Opening tag (empty string also means no legend)'
+ );
+ $this->assertEquals(
+ "<fieldset>\n<legend>Foo</legend>\n",
+ Xml::fieldset( 'Foo' ),
+ 'Opening tag with legend'
+ );
+ $this->assertEquals(
+ "<fieldset>\n<legend>Foo</legend>\nBar\n</fieldset>\n",
+ Xml::fieldset( 'Foo', 'Bar' ),
+ 'Entire element with legend'
+ );
+ $this->assertEquals(
+ "<fieldset>\n<legend>Foo</legend>\n",
+ Xml::fieldset( 'Foo', false ),
+ 'Opening tag with legend (false means no content and no closing tag)'
+ );
+ $this->assertEquals(
+ "<fieldset>\n<legend>Foo</legend>\n\n</fieldset>\n",
+ Xml::fieldset( 'Foo', '' ),
+ 'Entire element with legend but no content (empty string generates a closing tag)'
+ );
+ $this->assertEquals(
+ "<fieldset class=\"bar\">\n<legend>Foo</legend>\nBar\n</fieldset>\n",
+ Xml::fieldset( 'Foo', 'Bar', [ 'class' => 'bar' ] ),
+ 'Opening tag with legend and attributes'
+ );
+ $this->assertEquals(
+ "<fieldset class=\"bar\">\n<legend>Foo</legend>\n",
+ Xml::fieldset( 'Foo', false, [ 'class' => 'bar' ] ),
+ 'Entire element with legend and attributes'
+ );
+ }
+
+ /**
+ * @covers Xml::testBuildTable
+ */
+ public function testBuildTable() {
+ $firstRow = [ 'foo', 'bar' ];
+ $secondRow = [ 'Berlin', 'Tehran' ];
+ $headers = [ 'header1', 'header2' ];
+ $expected = '<table id="testTable"><thead id="testTable"><th>header1</th>' .
+ '<th>header2</th></thead><tr><td>foo</td><td>bar</td></tr><tr><td>Berlin</td>' .
+ '<td>Tehran</td></tr></table>';
+ $this->assertEquals(
+ $expected,
+ Xml::buildTable(
+ [ $firstRow, $secondRow ],
+ [ 'id' => 'testTable' ],
+ $headers
+ )
+ );
+ }
+
+ /**
+ * @covers Xml::testBuildTableRow
+ */
+ public function testBuildTableRow() {
+ $this->assertEquals(
+ '<tr id="testRow"><td>foo</td><td>bar</td></tr>',
+ Xml::buildTableRow( [ 'id' => 'testRow' ], [ 'foo', 'bar' ] )
+ );
+ }