Merge "Services: Convert LocalisationCache's static to a const now HHVM is gone"...
[lhc/web/wiklou.git] / tests / phpunit / includes / XmlTest.php
index 4556473..f95505b 100644 (file)
@@ -46,7 +46,7 @@ class XmlTest extends MediaWikiTestCase {
                $this->assertNull( Xml::expandAttributes( null ),
                        'Converting a null list of attributes'
                );
-               $this->assertEquals( '', Xml::expandAttributes( [] ),
+               $this->assertSame( '', Xml::expandAttributes( [] ),
                        'Converting an empty list of attributes'
                );
        }
@@ -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
         */