Merge "PreferencesFormOOUI: Avoid Phan warning with weird signature of TabPanelLayout"
[lhc/web/wiklou.git] / tests / phpunit / includes / XmlTest.php
index e46fc67..ab9abbb 100644 (file)
@@ -97,8 +97,8 @@ class XmlTest extends MediaWikiTestCase {
         */
        public function testElementEscaping() {
                $this->assertEquals(
-                       '<element>hello &lt;there&gt; you &amp; you</element>',
-                       Xml::element( 'element', null, 'hello <there> you & you' ),
+                       '<element>"hello &lt;there&gt; your\'s &amp; you"</element>',
+                       Xml::element( 'element', null, '"hello <there> 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
         */