Revert "Xml: Fix Xml::fieldset() when $content is not given"
authorBartosz Dziewoński <matma.rex@gmail.com>
Sun, 17 Sep 2017 17:05:40 +0000 (17:05 +0000)
committerBartosz Dziewoński <matma.rex@gmail.com>
Sun, 17 Sep 2017 17:25:01 +0000 (19:25 +0200)
Apparently that is intentional and documented. Huh. Whoops.

This reverts commit 0f1cc3bb6e7c3be9b86d2c8736f7458cd40588f2.

Also add test cases for this bizarre function.

Change-Id: I0311f7c85cd575f2a66d50589ec364072be486fb

includes/Xml.php
tests/phpunit/includes/XmlTest.php

index eadc7d1..0091513 100644 (file)
@@ -615,9 +615,9 @@ class Xml {
 
                if ( $content !== false ) {
                        $s .= $content . "\n";
+                       $s .= self::closeElement( 'fieldset' ) . "\n";
                }
 
-               $s .= self::closeElement( 'fieldset' ) . "\n";
                return $s;
        }
 
index 25b754d..c5572b4 100644 (file)
@@ -477,4 +477,55 @@ class XmlTest extends MediaWikiTestCase {
                        ] )
                );
        }
+
+       /**
+        * @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'
+               );
+       }
 }