X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FXmlTest.php;h=d26f3ec15059fff68382eed47178337643eebfb3;hp=25b754d2bc1c012c9441dbd8d8e63c5f13a2b760;hb=389fa13ff875975cb79be8f5181270ddf79224bd;hpb=971a50c4f3c61fb3a4bec60cd712317bb8ddcb9a diff --git a/tests/phpunit/includes/XmlTest.php b/tests/phpunit/includes/XmlTest.php index 25b754d2bc..d26f3ec150 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 */ @@ -136,6 +141,57 @@ class XmlTest extends MediaWikiTestCase { $this->assertEquals( '', Xml::closeElement( 'element' ), 'closeElement() shortcut' ); } + public function provideMonthSelector() { + global $wgLang; + + $header = ''; + $monthsString = ''; + for ( $i = 1; $i < 13; $i++ ) { + $monthName = $wgLang->getMonthName( $i ); + $monthsString .= ""; + if ( $i !== 12 ) { + $monthsString .= "\n"; + } + } + $monthsString2 = str_replace( + '', + '', + $monthsString + ); + $end = ''; + + $allMonths = "\n"; + return [ + [ $header . $monthsString . $end, '', null, 'month' ], + [ $header . $monthsString2 . $end, 12, null, 'month' ], + [ $header2 . $monthsString . $end, '', null, 'monthSelector' ], + [ $header . $allMonths . $monthsString . $end, '', 'AllMonths', 'month' ], + + ]; + } + + /** + * @covers Xml::monthSelector + * @dataProvider provideMonthSelector + */ + public function testMonthSelector( $expected, $selected, $allmonths, $id ) { + $this->assertEquals( + $expected, + Xml::monthSelector( $selected, $allmonths, $id ) + ); + } + + /** + * @covers Xml::span + */ + public function testSpan() { + $this->assertEquals( + 'element', + Xml::span( 'element', 'foo', [ 'id' => 'testSpan' ] ) + ); + } + /** * @covers Xml::dateMenu */ @@ -477,4 +533,85 @@ class XmlTest extends MediaWikiTestCase { ] ) ); } + + /** + * @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' + ); + } + + /** + * @covers Xml::testBuildTable + */ + public function testBuildTable() { + $firstRow = [ 'foo', 'bar' ]; + $secondRow = [ 'Berlin', 'Tehran' ]; + $headers = [ 'header1', 'header2' ]; + $expected = '' . + '' . + '
header1header2
foobar
BerlinTehran
'; + $this->assertEquals( + $expected, + Xml::buildTable( + [ $firstRow, $secondRow ], + [ 'id' => 'testTable' ], + $headers + ) + ); + } + + /** + * @covers Xml::testBuildTableRow + */ + public function testBuildTableRow() { + $this->assertEquals( + 'foobar', + Xml::buildTableRow( [ 'id' => 'testRow' ], [ 'foo', 'bar' ] ) + ); + } }