<?php
/**
- * @group Database
* @group ResourceLoader
*/
class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase {
}
);
$this->setService( 'SkinFactory', $skinFactory );
+
+ // This test is not expected to query any database
+ MediaWiki\MediaWikiServices::disableStorageBackend();
}
private static function getModules() {
$base = [
- 'localBasePath' => realpath( __DIR__ ),
+ 'localBasePath' => __DIR__,
];
return [
*/
public function testMixedCssAnnotations() {
$basePath = __DIR__ . '/../../data/css';
- $testModule = new ResourceLoaderFileModule( [
+ $testModule = new ResourceLoaderFileTestModule( [
'localBasePath' => $basePath,
'styles' => [ 'test.css' ],
] );
$testModule->setName( 'testing' );
- $expectedModule = new ResourceLoaderFileModule( [
+ $expectedModule = new ResourceLoaderFileTestModule( [
'localBasePath' => $basePath,
'styles' => [ 'expected.css' ],
] );
*/
public function testBomConcatenation() {
$basePath = __DIR__ . '/../../data/css';
- $testModule = new ResourceLoaderFileModule( [
+ $testModule = new ResourceLoaderFileTestModule( [
'localBasePath' => $basePath,
'styles' => [ 'bom.css' ],
] );
'lessVars' => [ 'key' => 'value' ],
];
yield 'identical Less variables' => [ $x, $x, true ];
+
+ $a = [
+ 'packageFiles' => [ [ 'name' => 'data.json', 'callback' => function () {
+ return [ 'aaa' ];
+ } ] ]
+ ];
+ $b = [
+ 'packageFiles' => [ [ 'name' => 'data.json', 'callback' => function () {
+ return [ 'bbb' ];
+ } ] ]
+ ];
+ yield 'packageFiles with different callback' => [ $a, $b, false ];
+
+ $a = [
+ 'packageFiles' => [ [ 'name' => 'aaa.json', 'callback' => function () {
+ return [ 'x' ];
+ } ] ]
+ ];
+ $b = [
+ 'packageFiles' => [ [ 'name' => 'bbb.json', 'callback' => function () {
+ return [ 'x' ];
+ } ] ]
+ ];
+ yield 'packageFiles with different file name and a callback' => [ $a, $b, false ];
+
+ $a = [
+ 'packageFiles' => [ [ 'name' => 'data.json', 'versionCallback' => function () {
+ return [ 'A-version' ];
+ }, 'callback' => function () {
+ throw new Exception( 'Unexpected computation' );
+ } ] ]
+ ];
+ $b = [
+ 'packageFiles' => [ [ 'name' => 'data.json', 'versionCallback' => function () {
+ return [ 'B-version' ];
+ }, 'callback' => function () {
+ throw new Exception( 'Unexpected computation' );
+ } ] ]
+ ];
+ yield 'packageFiles with different versionCallback' => [ $a, $b, false ];
+
+ $a = [
+ 'packageFiles' => [ [ 'name' => 'aaa.json',
+ 'versionCallback' => function () {
+ return [ 'X-version' ];
+ },
+ 'callback' => function () {
+ throw new Exception( 'Unexpected computation' );
+ }
+ ] ]
+ ];
+ $b = [
+ 'packageFiles' => [ [ 'name' => 'bbb.json',
+ 'versionCallback' => function () {
+ return [ 'X-version' ];
+ },
+ 'callback' => function () {
+ throw new Exception( 'Unexpected computation' );
+ }
+ ] ]
+ ];
+ yield 'packageFiles with different file name and a versionCallback' => [ $a, $b, false ];
}
/**
'main' => 'init.js'
]
],
- [
+ 'package file with callback' => [
$base + [
'packageFiles' => [
[ 'name' => 'foo.json', 'content' => [ 'Hello' => 'world' ] ],
'lang' => 'fy'
]
],
+ 'package file with callback and versionCallback' => [
+ $base + [
+ 'packageFiles' => [
+ [ 'name' => 'bar.js', 'content' => "console.log('Hello');" ],
+ [ 'name' => 'data.json', 'versionCallback' => function ( $context ) {
+ return $context->getLanguage();
+ }, 'callback' => function ( $context ) {
+ return [ 'langCode' => $context->getLanguage() ];
+ } ],
+ ]
+ ],
+ [
+ 'files' => [
+ 'bar.js' => [
+ 'type' => 'script',
+ 'content' => "console.log('Hello');",
+ ],
+ 'data.json' => [
+ 'type' => 'data',
+ 'content' => [ 'langCode' => 'fy' ]
+ ],
+ ],
+ 'main' => 'bar.js'
+ ],
+ [
+ 'lang' => 'fy'
+ ]
+ ],
[
$base + [
'packageFiles' => [
],
false
],
- [
+ 'package file with invalid callback' => [
$base + [
'packageFiles' => [
[ 'name' => 'foo.json', 'callback' => 'functionThatDoesNotExist142857' ]