X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FXmlTest.php;h=4d4fa7bb9a0d3e280a9750ad46d4dec778b0c620;hb=2917f7b6cd3b16068309c5ee369f946c17bfe0bb;hp=6c059ec5fd0af73d3c68e0d592afd6714e9ae1a9;hpb=eb72adcb4e28eedc1806d845355856bd6f97dadb;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/XmlTest.php b/tests/phpunit/includes/XmlTest.php index 6c059ec5fd..4d4fa7bb9a 100644 --- a/tests/phpunit/includes/XmlTest.php +++ b/tests/phpunit/includes/XmlTest.php @@ -34,6 +34,11 @@ class XmlTest extends MediaWikiTestCase { ] ); } + protected function tearDown() { + Language::factory( 'en' )->resetNamespaces(); + parent::tearDown(); + } + /** * @covers Xml::expandAttributes */ @@ -403,12 +408,15 @@ class XmlTest extends MediaWikiTestCase { */ public function testListDropDown() { $this->assertEquals( - '' . + '' . "\n" . + '' . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . + '' . "\n" . + '' . '', Xml::listDropDown( // name @@ -426,4 +434,103 @@ class XmlTest extends MediaWikiTestCase { ) ); } + + /** + * @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( + "
\n", + Xml::fieldset(), + 'Opening tag' + ); + $this->assertEquals( + "
\n", + Xml::fieldset( false ), + 'Opening tag (false means no legend)' + ); + $this->assertEquals( + "
\n", + Xml::fieldset( '' ), + 'Opening tag (empty string also means no legend)' + ); + $this->assertEquals( + "
\nFoo\n", + Xml::fieldset( 'Foo' ), + 'Opening tag with legend' + ); + $this->assertEquals( + "
\nFoo\nBar\n
\n", + Xml::fieldset( 'Foo', 'Bar' ), + 'Entire element with legend' + ); + $this->assertEquals( + "
\nFoo\n", + Xml::fieldset( 'Foo', false ), + 'Opening tag with legend (false means no content and no closing tag)' + ); + $this->assertEquals( + "
\nFoo\n\n
\n", + Xml::fieldset( 'Foo', '' ), + 'Entire element with legend but no content (empty string generates a closing tag)' + ); + $this->assertEquals( + "
\nFoo\nBar\n
\n", + Xml::fieldset( 'Foo', 'Bar', [ 'class' => 'bar' ] ), + 'Opening tag with legend and attributes' + ); + $this->assertEquals( + "
\nFoo\n", + Xml::fieldset( 'Foo', false, [ 'class' => 'bar' ] ), + 'Entire element with legend and attributes' + ); + } }