Merge "Remove incorrect timezone conversion from date parameters"
[lhc/web/wiklou.git] / tests / phpunit / includes / resourceloader / ResourceLoaderTest.php
index 71a6339..d9ad711 100644 (file)
@@ -8,16 +8,6 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
                parent::setUp();
 
                $this->setMwGlobals( [
-                       'wgResourceLoaderLESSImportPaths' => [],
-                       'wgResourceLoaderLESSVars' => [
-                               'foo'  => '2px',
-                               'Foo' => '#eeeeee',
-                               'bar' => 5,
-                       ],
-                       // Clear ResourceLoaderGetConfigVars hooks (called by StartupModule)
-                       // to avoid notices during testMakeModuleResponse for missing
-                       // wgResourceLoaderLESSVars keys in extension hooks.
-                       'wgHooks' => [],
                        'wgShowExceptionDetails' => true,
                ] );
        }
@@ -247,27 +237,12 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
                );
        }
 
-       /**
-        * @covers ResourceLoaderFileModule::compileLessFile
-        */
-       public function testLessFileCompilation() {
-               $context = $this->getResourceLoaderContext();
-               $basePath = __DIR__ . '/../../data/less/module';
-               $module = new ResourceLoaderFileModule( [
-                       'localBasePath' => $basePath,
-                       'styles' => [ 'styles.less' ],
-               ] );
-               $module->setName( 'test.less' );
-               $styles = $module->getStyles( $context );
-               $this->assertStringEqualsFile( $basePath . '/styles.css', $styles['all'] );
-       }
-
        /**
         * @covers ResourceLoader::getLessCompiler
         */
        public function testLessImportDirs() {
                $rl = new EmptyResourceLoader();
-               $lc = $rl->getLessCompiler( $rl->getLessVars() );
+               $lc = $rl->getLessCompiler( [ 'foo'  => '2px', 'Foo' => '#eeeeee' ] );
                $basePath = dirname( dirname( __DIR__ ) ) . '/data/less';
                $lc->SetImportDirs( [
                         "$basePath/common" => '',
@@ -737,6 +712,21 @@ mw.example();
                $this->assertEquals( $expected, $response, $message ?: 'Response' );
        }
 
+       /**
+        * @covers ResourceLoader::makeModuleResponse
+        */
+       public function testMakeModuleResponseEmpty() {
+               $rl = new EmptyResourceLoader();
+               $context = $this->getResourceLoaderContext(
+                       [ 'modules' => '', 'only' => 'scripts' ],
+                       $rl
+               );
+
+               $response = $rl->makeModuleResponse( $context, [] );
+               $this->assertSame( [], $rl->getErrors(), 'Errors' );
+               $this->assertRegExp( '/^\/\*.+no modules were requested.+\*\/$/ms', $response );
+       }
+
        /**
         * Verify that when building module content in a load.php response,
         * an exception from one module will not break script output from
@@ -809,7 +799,7 @@ mw.example();
 
                $this->assertCount( 2, $errors );
                $this->assertRegExp( '/Ferry not found/', $errors[0] );
-               $this->assertRegExp( '/Problem.+\n\s*"ferry":\s*"error"/m', $errors[1] );
+               $this->assertRegExp( '/Problem.+"ferry":\s*"error"/ms', $errors[1] );
                $this->assertEquals(
                        '.foo{}.bar{}',
                        $response
@@ -948,7 +938,7 @@ mw.example();
        /**
         * @covers ResourceLoader::respond
         */
-       public function testRespond() {
+       public function testRespondEmpty() {
                $rl = $this->getMockBuilder( EmptyResourceLoader::class )
                        ->setMethods( [
                                'tryRespondNotModified',
@@ -964,6 +954,66 @@ mw.example();
                $rl->respond( $context );
        }
 
+       /**
+        * @covers ResourceLoader::respond
+        */
+       public function testRespondSimple() {
+               $module = new ResourceLoaderTestModule( [ 'script' => 'foo();' ] );
+               $rl = $this->getMockBuilder( EmptyResourceLoader::class )
+                       ->setMethods( [
+                               'measureResponseTime',
+                               'tryRespondNotModified',
+                               'sendResponseHeaders',
+                               'makeModuleResponse',
+                       ] )
+                       ->getMock();
+               $rl->register( 'test', $module );
+               $context = $this->getResourceLoaderContext(
+                       [ 'modules' => 'test', 'only' => null ],
+                       $rl
+               );
+
+               $rl->expects( $this->once() )->method( 'makeModuleResponse' )
+                       ->with( $context, [ 'test' => $module ] )
+                       ->willReturn( 'implement_foo;' );
+               $this->expectOutputRegex( '/^implement_foo;/' );
+
+               $rl->respond( $context );
+       }
+
+       /**
+        * @covers ResourceLoader::respond
+        */
+       public function testRespondInternalFailures() {
+               $module = new ResourceLoaderTestModule( [ 'script' => 'foo();' ] );
+               $rl = $this->getMockBuilder( EmptyResourceLoader::class )
+                       ->setMethods( [
+                               'measureResponseTime',
+                               'preloadModuleInfo',
+                               'getCombinedVersion',
+                               'tryRespondNotModified',
+                               'makeModuleResponse',
+                               'sendResponseHeaders',
+                       ] )
+                       ->getMock();
+               $rl->register( 'test', $module );
+               $context = $this->getResourceLoaderContext( [ 'modules' => 'test' ], $rl );
+               // Disable logging from outputErrorAndLog
+               $this->setLogger( 'exception', new Psr\Log\NullLogger() );
+
+               $rl->expects( $this->once() )->method( 'preloadModuleInfo' )
+                       ->willThrowException( new Exception( 'Preload error' ) );
+               $rl->expects( $this->once() )->method( 'getCombinedVersion' )
+                       ->willThrowException( new Exception( 'Version error' ) );
+               $rl->expects( $this->once() )->method( 'makeModuleResponse' )
+                       ->with( $context, [ 'test' => $module ] )
+                       ->willReturn( 'foo;' );
+               // Internal errors should be caught and logged without affecting module output
+               $this->expectOutputRegex( '/^\/\*.+Preload error.+Version error.+\*\/.*foo;/ms' );
+
+               $rl->respond( $context );
+       }
+
        /**
         * @covers ResourceLoader::measureResponseTime
         */