$module = new ResourceLoaderFileTestModule( [
'localBasePath' => $basePath,
'styles' => [ 'styles.less' ],
- ], [
'lessVars' => [ 'foo' => '2px', 'Foo' => '#eeeeee' ]
] );
$module->setName( 'test.less' );
$this->assertStringEqualsFile( $basePath . '/styles.css', $styles['all'] );
}
+ public function provideGetVersionHash() {
+ $a = [];
+ $b = [
+ 'lessVars' => [ 'key' => 'value' ],
+ ];
+ yield 'with and without Less variables' => [ $a, $b, false ];
+
+ $a = [
+ 'lessVars' => [ 'key' => 'value1' ],
+ ];
+ $b = [
+ 'lessVars' => [ 'key' => 'value2' ],
+ ];
+ yield 'different Less variables' => [ $a, $b, false ];
+
+ $x = [
+ '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 ];
+ }
+
/**
+ * @dataProvider provideGetVersionHash
* @covers ResourceLoaderFileModule::getDefinitionSummary
* @covers ResourceLoaderFileModule::getFileHashes
*/
- public function testGetVersionHash() {
+ public function testGetVersionHash( $a, $b, $isEqual ) {
$context = $this->getResourceLoaderContext();
- // Less variables
- $module = new ResourceLoaderFileTestModule();
- $version = $module->getVersionHash( $context );
- $module = new ResourceLoaderFileTestModule( [], [
- 'lessVars' => [ 'key' => 'value' ],
- ] );
- $this->assertNotEquals(
- $version,
- $module->getVersionHash( $context ),
- 'Using less variables is significant'
+ $moduleA = new ResourceLoaderFileTestModule( $a );
+ $versionA = $moduleA->getVersionHash( $context );
+ $moduleB = new ResourceLoaderFileTestModule( $b );
+ $versionB = $moduleB->getVersionHash( $context );
+
+ $this->assertSame(
+ $isEqual,
+ ( $versionA === $versionB ),
+ 'Whether versions hashes are equal'
);
}
- public function providerGetScriptPackageFiles() {
+ public function provideGetScriptPackageFiles() {
$basePath = __DIR__ . '/../../data/resourceloader';
$base = [ 'localBasePath' => $basePath ];
$commentScript = file_get_contents( "$basePath/script-comment.js" );
'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' ]
}
/**
- * @dataProvider providerGetScriptPackageFiles
+ * @dataProvider provideGetScriptPackageFiles
* @covers ResourceLoaderFileModule::getScript
* @covers ResourceLoaderFileModule::getPackageFiles
* @covers ResourceLoaderFileModule::expandPackageFiles