From: Amir Sarabadani Date: Mon, 25 Dec 2017 01:54:25 +0000 (+0100) Subject: Add tests for several methods of Xml X-Git-Tag: 1.31.0-rc.0~1107 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=389fa13ff875975cb79be8f5181270ddf79224bd Add tests for several methods of Xml Added tests for methods: monthSelector, span, buildTable, buildTableRow Change-Id: I5ca6bb231b5ed95f57f649a92d659245a4852c85 --- diff --git a/tests/phpunit/includes/XmlTest.php b/tests/phpunit/includes/XmlTest.php index 4d4fa7bb9a..d26f3ec150 100644 --- a/tests/phpunit/includes/XmlTest.php +++ b/tests/phpunit/includes/XmlTest.php @@ -141,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 */ @@ -533,4 +584,34 @@ class XmlTest extends MediaWikiTestCase { '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' ] ) + ); + } }