protected function ThemeNotUsingClassyLibraryTest::confirmNoClassyAssets in Drupal 8
Confirms a library is not loading any Classy assets.
Parameters
string $library_name: The library name.
string[][] $library_definition: The data for a library, as defined in a theme's `.libraries.yml` file.
string $type: The type of asset, either 'js' or 'css'.
1 call to ThemeNotUsingClassyLibraryTest::confirmNoClassyAssets()
- ThemeNotUsingClassyLibraryTest::testThemeNotUsingClassyLibraries in core/
tests/ Drupal/ KernelTests/ Core/ Theme/ ThemeNotUsingClassyLibraryTest.php - Ensures that a theme is decoupled from Classy libraries.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Theme/ ThemeNotUsingClassyLibraryTest.php, line 310
Class
- ThemeNotUsingClassyLibraryTest
- Tests that themes do not depend on Classy libraries.
Namespace
Drupal\KernelTests\Core\ThemeCode
protected function confirmNoClassyAssets($library_name, array $library_definition, $type) {
// Get the Classy version of the library being overridden.
$classy_library = $this->classyLibraries[str_replace('classy/', '', $library_name)];
// Get a list of all CSS or JS files loaded by the Classy library.
$files_used_in_classy_library = array_map(function ($item) {
return str_replace('core/themes/classy/', '', $item['data']);
}, $classy_library[$type]);
$files_used_by_library_override = [];
if ($type === 'js') {
foreach ($library_definition[$type] as $js_file => $options) {
$files_used_by_library_override[] = $js_file;
}
}
elseif ($type === 'css') {
foreach ([
'component',
'layout',
] as $category) {
if (isset($library_definition[$type][$category])) {
foreach ($library_definition[$type][$category] as $css_file => $options) {
$files_used_by_library_override[] = $css_file;
}
}
}
}
$classy_files_still_loading = array_diff($files_used_in_classy_library, $files_used_by_library_override);
$this
->assertEmpty($classy_files_still_loading, "{$library_name} is overridden, but the theme is still loading these files from Classy. " . print_r($classy_files_still_loading, 1));
}