aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php
diff options
context:
space:
mode:
authorLucas Werkmeister <lucas.werkmeister@wikimedia.de>2021-07-20 12:10:21 +0200
committerLucas Werkmeister <lucas.werkmeister@wikimedia.de>2021-07-20 17:04:17 +0200
commit7c8a39c9dcede3f15cd6bb2f723bbbae2835bca2 (patch)
tree14df16eb3b1d6104d236fee1164bb80e1e13b95f /tests/phpunit/includes/resourceloader/ResourceLoaderTest.php
parentedd6ed7c5ec2126bc375c9b5a05a58e66e60c06b (diff)
downloadmediawikicore-7c8a39c9dcede3f15cd6bb2f723bbbae2835bca2.tar.gz
mediawikicore-7c8a39c9dcede3f15cd6bb2f723bbbae2835bca2.zip
Ensure newlines when wrapping ResourceLoader scripts
We’re appending at least a closing brace to the source code, so if that code ends with a line comment, we need to have a line break between the end of the code and our appended brace. Bug: T286996 Change-Id: I4e93b10f31445f6dab76c1614e546fb41fd6c0f6
Diffstat (limited to 'tests/phpunit/includes/resourceloader/ResourceLoaderTest.php')
-rw-r--r--tests/phpunit/includes/resourceloader/ResourceLoaderTest.php40
1 files changed, 38 insertions, 2 deletions
diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php
index ca312e0aeb17..a468a0177e65 100644
--- a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php
+++ b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php
@@ -554,6 +554,38 @@ mw.example( 3 );
} );
END
] ],
+ [ [
+ 'title' => 'Implement multi-file script, non-debug mode',
+
+ 'name' => 'test.multifile',
+ 'debug' => 'false',
+ 'scripts' => [
+ 'files' => [
+ 'one.js' => [
+ 'type' => 'script',
+ 'content' => 'mw.example( 1 );',
+ ],
+ 'two.json' => [
+ 'type' => 'data',
+ 'content' => [ 'n' => 2 ],
+ ],
+ 'three.js' => [
+ 'type' => 'script',
+ 'content' => 'mw.example( 3 );//'
+ ],
+ ],
+ 'main' => 'three.js',
+ ],
+
+ 'expected' => implode( '', [
+ 'mw.loader.implement("test.multifile",',
+ '{"main":"three.js","files":{',
+ '"one.js":function(require,module){mw.example( 1 );' . "\n" . '},',
+ '"two.json":{"n":2},',
+ '"three.js":function(require,module){mw.example( 3 );//' . "\n" . '}',
+ '}});',
+ ] ),
+ ] ],
];
}
@@ -565,11 +597,15 @@ END
public function testMakeLoaderImplementScript( $case ) {
$case += [
'wrap' => true,
- 'styles' => [], 'templates' => [], 'messages' => new XmlJsCode( '{}' ), 'packageFiles' => [],
+ 'styles' => [],
+ 'templates' => [],
+ 'messages' => new XmlJsCode( '{}' ),
+ 'packageFiles' => [],
+ 'debug' => 'true',
];
$rl = TestingAccessWrapper::newFromClass( ResourceLoader::class );
$context = new ResourceLoaderContext( new EmptyResourceLoader(), new FauxRequest( [
- 'debug' => 'true',
+ 'debug' => $case['debug'],
] ) );
$this->assertEquals(
$case['expected'],