resourceloader: Add coverage for empty case in makeModuleResponse
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 29 May 2018 02:03:31 +0000 (03:03 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Tue, 29 May 2018 02:05:41 +0000 (03:05 +0100)
Adds coverage for line 1049-1056.

Also, follow-up 6292d54dff by simpliying the regex by using /s modifier to
enable PCRE_DOTALL which includes matching of new lines.

Change-Id: Icec34dfe107d418951b3d155234295c79410ffaa

tests/phpunit/includes/resourceloader/ResourceLoaderTest.php

index 71a6339..4ff7719 100644 (file)
@@ -737,6 +737,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 +824,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