X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FXmlTest.php;h=ab9abbb429be10cb059f10a0c1f63854afb89e04;hb=3b0effb20334f19f662aed6760ddfe7d4b43c6d6;hp=c5572b46c6c79a68fa255152bfc80d47ae39261f;hpb=232cb19c0a27ee306984bda5bcd5c6c1815734e2;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/XmlTest.php b/tests/phpunit/includes/XmlTest.php index c5572b46c6..ab9abbb429 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 */ @@ -50,7 +55,7 @@ class XmlTest extends MediaWikiTestCase { * @covers Xml::expandAttributes */ public function testExpandAttributesException() { - $this->setExpectedException( 'MWException' ); + $this->setExpectedException( MWException::class ); Xml::expandAttributes( 'string' ); } @@ -92,8 +97,8 @@ class XmlTest extends MediaWikiTestCase { */ public function testElementEscaping() { $this->assertEquals( - 'hello <there> you & you', - Xml::element( 'element', null, 'hello you & you' ), + '"hello <there> your\'s & you"', + Xml::element( 'element', null, '"hello your\'s & you"' ), 'Element with no attributes and content that needs escaping' ); } @@ -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 */ @@ -398,6 +454,34 @@ class XmlTest extends MediaWikiTestCase { ); } + /** + * @covers Xml::encodeJsVar + */ + public function testXmlJsCode() { + $code = 'function () { foo( 42 ); }'; + $this->assertEquals( + $code, + Xml::encodeJsVar( new XmlJsCode( $code ) ) + ); + } + + /** + * @covers Xml::encodeJsVar + * @covers XmlJsCode::encodeObject + */ + public function testEncodeObject() { + $codeA = 'function () { foo( 42 ); }'; + $codeB = 'function ( jQuery ) { bar( 142857 ); }'; + $obj = XmlJsCode::encodeObject( [ + 'a' => new XmlJsCode( $codeA ), + 'b' => new XmlJsCode( $codeB ) + ] ); + $this->assertEquals( + "{\"a\":$codeA,\"b\":$codeB}", + Xml::encodeJsVar( $obj ) + ); + } + /** * @covers Xml::listDropDown */ @@ -528,4 +612,34 @@ class XmlTest extends MediaWikiTestCase { 'Entire element with legend and attributes' ); } + + /** + * @covers Xml::buildTable + */ + 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::buildTableRow + */ + public function testBuildTableRow() { + $this->assertEquals( + 'foobar', + Xml::buildTableRow( [ 'id' => 'testRow' ], [ 'foo', 'bar' ] ) + ); + } }