Merge "Some cleanups to MWExceptionHandler::handleException"
[lhc/web/wiklou.git] / tests / phpunit / includes / resourceloader / ResourceLoaderTest.php
index d756ce3..ca7307e 100644 (file)
@@ -5,8 +5,6 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
        protected function setUp() {
                parent::setUp();
 
-               // $wgResourceLoaderLESSFunctions, $wgResourceLoaderLESSImportPaths; $wgResourceLoaderLESSVars;
-
                $this->setMwGlobals( array(
                        'wgResourceLoaderLESSFunctions' => array(
                                'test-sum' => function ( $frame, $less ) {
@@ -28,15 +26,12 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
                ) );
        }
 
-       /* Provider Methods */
        public static function provideValidModules() {
                return array(
                        array( 'TEST.validModule1', new ResourceLoaderTestModule() ),
                );
        }
 
-       /* Test Methods */
-
        /**
         * Ensures that the ResourceLoaderRegisterModules hook is called when a new
         * ResourceLoader object is constructed.
@@ -95,42 +90,10 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
         * @param string $css
         * @return string
         */
-       private function stripNoflip( $css ) {
+       private static function stripNoflip( $css ) {
                return str_replace( '/*@noflip*/ ', '', $css );
        }
 
-       /**
-        * What happens when you mix @embed and @noflip?
-        * This really is an integration test, but oh well.
-        */
-       public function testMixedCssAnnotations(  ) {
-               $basePath = __DIR__ . '/../../data/css';
-               $testModule = new ResourceLoaderFileModule( array(
-                       'localBasePath' => $basePath,
-                       'styles' => array( 'test.css' ),
-               ) );
-               $expectedModule = new ResourceLoaderFileModule( array(
-                       'localBasePath' => $basePath,
-                       'styles' => array( 'expected.css' ),
-               ) );
-
-               $contextLtr = $this->getResourceLoaderContext( 'en', 'ltr' );
-               $contextRtl = $this->getResourceLoaderContext( 'he', 'rtl' );
-
-               // Since we want to compare the effect of @noflip+@embed against the effect of just @embed, and
-               // the @noflip annotations are always preserved, we need to strip them first.
-               $this->assertEquals(
-                       $expectedModule->getStyles( $contextLtr ),
-                       $this->stripNoflip( $testModule->getStyles( $contextLtr ) ),
-                       "/*@noflip*/ with /*@embed*/ gives correct results in LTR mode"
-               );
-               $this->assertEquals(
-                       $expectedModule->getStyles( $contextLtr ),
-                       $this->stripNoflip( $testModule->getStyles( $contextRtl ) ),
-                       "/*@noflip*/ with /*@embed*/ gives correct results in RTL mode"
-               );
-       }
-
        /**
         * @dataProvider providePackedModules
         * @covers ResourceLoader::makePackedModulesString
@@ -192,6 +155,7 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
        /**
         * @dataProvider provideAddSource
         * @covers ResourceLoader::addSource
+        * @covers ResourceLoader::getSources
         */
        public function testAddSource( $name, $info, $expected ) {
                $rl = new ResourceLoader;
@@ -222,6 +186,106 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
                );
        }
 
+       public static function provideLoaderImplement() {
+               return array(
+                       array( array(
+                               'title' => 'Implement scripts, styles and messages',
+
+                               'name' => 'test.example',
+                               'scripts' => 'mw.example();',
+                               'styles' => array( 'css' => array( '.mw-example {}' ) ),
+                               'messages' => array( 'example' => '' ),
+                               'templates' => array(),
+
+                               'expected' => 'mw.loader.implement( "test.example", function ( $, jQuery ) {
+mw.example();
+}, {
+    "css": [
+        ".mw-example {}"
+    ]
+}, {
+    "example": ""
+} );',
+                       ) ),
+                       array( array(
+                               'title' => 'Implement scripts',
+
+                               'name' => 'test.example',
+                               'scripts' => 'mw.example();',
+                               'styles' => array(),
+                               'messages' => new XmlJsCode( '{}' ),
+                               'templates' => array(),
+                               'title' => 'scripts, styles and messags',
+
+                               'expected' => 'mw.loader.implement( "test.example", function ( $, jQuery ) {
+mw.example();
+} );',
+                       ) ),
+                       array( array(
+                               'title' => 'Implement styles',
+
+                               'name' => 'test.example',
+                               'scripts' => array(),
+                               'styles' => array( 'css' => array( '.mw-example {}' ) ),
+                               'messages' => new XmlJsCode( '{}' ),
+                               'templates' => array(),
+
+                               'expected' => 'mw.loader.implement( "test.example", [], {
+    "css": [
+        ".mw-example {}"
+    ]
+} );',
+                       ) ),
+                       array( array(
+                               'title' => 'Implement scripts and messages',
+
+                               'name' => 'test.example',
+                               'scripts' => 'mw.example();',
+                               'styles' => array(),
+                               'messages' => array( 'example' => '' ),
+                               'templates' => array(),
+
+                               'expected' => 'mw.loader.implement( "test.example", function ( $, jQuery ) {
+mw.example();
+}, {}, {
+    "example": ""
+} );',
+                       ) ),
+                       array( array(
+                               'title' => 'Implement scripts and templates',
+
+                               'name' => 'test.example',
+                               'scripts' => 'mw.example();',
+                               'styles' => array(),
+                               'messages' => new XmlJsCode( '{}' ),
+                               'templates' => array( 'example.html' => '' ),
+
+                               'expected' => 'mw.loader.implement( "test.example", function ( $, jQuery ) {
+mw.example();
+}, {}, {}, {
+    "example.html": ""
+} );',
+                       ) ),
+               );
+       }
+
+       /**
+        * @dataProvider provideLoaderImplement
+        * @covers ResourceLoader::makeLoaderImplementScript
+        */
+       public function testMakeLoaderImplementScript( $case ) {
+               $this->assertEquals(
+                       $case['expected'],
+                       ResourceLoader::makeLoaderImplementScript(
+                               $case['name'],
+                               $case['scripts'],
+                               $case['styles'],
+                               $case['messages'],
+                               $case['templates']
+                       )
+               );
+       }
+
        /**
         * @covers ResourceLoader::getLoadScript
         */