Merge "Feature file styles should precede module defined ones"
This commit is contained in:
commit
1a94be9c2a
2 changed files with 79 additions and 55 deletions
|
|
@ -251,11 +251,15 @@ class ResourceLoaderSkinModule extends ResourceLoaderLessVarFileModule {
|
|||
}
|
||||
}
|
||||
|
||||
foreach ( $featureFilePaths as $mediaType => $paths ) {
|
||||
$styles[$mediaType] = array_merge( $paths, $styles[$mediaType] ?? [] );
|
||||
// Styles defines in options are added to the $featureFilePaths to ensure
|
||||
// that $featureFilePaths styles precede module defined ones.
|
||||
// This is particularly important given the `normalize` styles need to be the first
|
||||
// outputted (see T269618).
|
||||
foreach ( $styles as $mediaType => $paths ) {
|
||||
$featureFilePaths[$mediaType] = array_merge( $featureFilePaths[$mediaType] ?? [], $paths );
|
||||
}
|
||||
|
||||
return $styles;
|
||||
return $featureFilePaths;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -421,73 +421,93 @@ CSS
|
|||
}
|
||||
}
|
||||
|
||||
public static function provideGetStyleFilesFeatureStylesOrder() {
|
||||
list( $defaultLocalBasePath, $defaultRemoteBasePath ) =
|
||||
ResourceLoaderFileModule::extractBasePaths();
|
||||
$featureFiles = ( new ReflectionClass( ResourceLoaderSkinModule::class ) )
|
||||
->getConstant( 'FEATURE_FILES' );
|
||||
|
||||
$normalizePath = new ResourceLoaderFilePath(
|
||||
$featureFiles['normalize']['all'][0],
|
||||
$defaultLocalBasePath,
|
||||
$defaultRemoteBasePath
|
||||
);
|
||||
$elementsPath = new ResourceLoaderFilePath(
|
||||
$featureFiles['elements']['screen'][0],
|
||||
$defaultLocalBasePath,
|
||||
$defaultRemoteBasePath
|
||||
);
|
||||
|
||||
return [
|
||||
[
|
||||
[ 'elements', 'normalize' ],
|
||||
[
|
||||
'test.styles/styles.css' => [
|
||||
'media' => 'screen'
|
||||
]
|
||||
],
|
||||
[ $normalizePath ],
|
||||
[ $elementsPath, 'test.styles/styles.css' ],
|
||||
'opt-out by default policy results in correct order'
|
||||
],
|
||||
[
|
||||
[
|
||||
'elements' => true,
|
||||
'normalize' => true,
|
||||
'toc' => false,
|
||||
],
|
||||
[
|
||||
'test.styles/styles.css' => [
|
||||
'media' => 'screen'
|
||||
]
|
||||
],
|
||||
[ $normalizePath ],
|
||||
[ $elementsPath, 'test.styles/styles.css' ],
|
||||
'opt-in by default policy results in correct order'
|
||||
],
|
||||
|
||||
[
|
||||
[ 'normalize' ],
|
||||
[ 'test.styles/styles.css' => [ 'media' => 'screen' ] ],
|
||||
[ $normalizePath ],
|
||||
[ 'test.styles/styles.css' ],
|
||||
'module provided styles come after skin defined'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ResourceLoaderSkinModule::getStyleFiles
|
||||
* @dataProvider provideGetStyleFilesFeatureStylesOrder
|
||||
* @param array $features
|
||||
* @param array $styles
|
||||
* @param array $expectedAllStyles array of styles
|
||||
* @param array $expectedScreenStyles array of styles
|
||||
* @param string $msg to show for debugging
|
||||
*/
|
||||
public function testGetStyleFilesFeatureStylesOrder() : void {
|
||||
public function testGetStyleFilesFeatureStylesOrder(
|
||||
$features, $styles, $expectedAllStyles, $expectedScreenStyles, $msg
|
||||
) : void {
|
||||
$ctx = $this->createMock( ResourceLoaderContext::class );
|
||||
$module = new ResourceLoaderSkinModule(
|
||||
[
|
||||
// The ordering should be controlled by ResourceLoaderSkinModule
|
||||
// `normalize` will be outputted before `elements` despite the ordering
|
||||
'features' => [ 'elements', 'normalize' ],
|
||||
'styles' => [
|
||||
'test.styles/styles.css' => [
|
||||
'media' => 'screen'
|
||||
]
|
||||
]
|
||||
'features' => $features,
|
||||
'styles' => $styles,
|
||||
]
|
||||
);
|
||||
|
||||
$moduleFeaturesObject = new ResourceLoaderSkinModule(
|
||||
[
|
||||
// The ordering should be controlled by ResourceLoaderSkinModule
|
||||
// `normalize` will be outputted before `elements` despite the ordering
|
||||
'features' => [
|
||||
'elements' => true,
|
||||
'normalize' => true,
|
||||
'toc' => false,
|
||||
],
|
||||
'styles' => [
|
||||
'test.styles/styles.css' => [
|
||||
'media' => 'screen'
|
||||
]
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
list( $defaultLocalBasePath, $defaultRemoteBasePath ) =
|
||||
ResourceLoaderFileModule::extractBasePaths();
|
||||
|
||||
$featureFiles = ( new ReflectionClass( ResourceLoaderSkinModule::class ) )
|
||||
->getConstant( 'FEATURE_FILES' );
|
||||
|
||||
$expected = [
|
||||
'all' => [
|
||||
new ResourceLoaderFilePath(
|
||||
$featureFiles['normalize']['all'][0],
|
||||
$defaultLocalBasePath,
|
||||
$defaultRemoteBasePath
|
||||
),
|
||||
],
|
||||
'screen' => [
|
||||
new ResourceLoaderFilePath(
|
||||
$featureFiles['elements']['screen'][0],
|
||||
$defaultLocalBasePath,
|
||||
$defaultRemoteBasePath
|
||||
),
|
||||
'test.styles/styles.css'
|
||||
]
|
||||
'all' => $expectedAllStyles,
|
||||
'screen' => $expectedScreenStyles,
|
||||
];
|
||||
|
||||
$actual = $module->getStyleFiles( $ctx );
|
||||
unset( $actual['print'] ); // not testing print for now
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$moduleFeaturesObject->getStyleFiles( $ctx )
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$module->getStyleFiles( $ctx )
|
||||
array_values( $expected ),
|
||||
array_values( $actual )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue