X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmes_infos.php?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FXmlTest.php;h=ab9abbb429be10cb059f10a0c1f63854afb89e04;hb=9f2ffdfbd4c289446f2baf8a168cbe89fa122157;hp=e46fc67f73658f60f072f1e7bfccd5bb10ae3cb6;hpb=f673cfd18a0fa8eb1c9ef0a34e2c1eb9c124a5e9;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/XmlTest.php b/tests/phpunit/includes/XmlTest.php index e46fc67f73..ab9abbb429 100644 --- a/tests/phpunit/includes/XmlTest.php +++ b/tests/phpunit/includes/XmlTest.php @@ -97,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' ); } @@ -454,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 */