public function AttachedAssetsTest::testDynamicLibrary in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php \Drupal\KernelTests\Core\Asset\AttachedAssetsTest::testDynamicLibrary()
Dynamically defines an asset library and alters it.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Asset/ AttachedAssetsTest.php, line 440
Class
- AttachedAssetsTest
- Tests #attached assets: attached asset libraries and JavaScript settings.
Namespace
Drupal\KernelTests\Core\AssetCode
public function testDynamicLibrary() {
/** @var \Drupal\Core\Asset\LibraryDiscoveryInterface $library_discovery */
$library_discovery = \Drupal::service('library.discovery');
// Retrieve a dynamic library definition.
// @see common_test_library_info_build()
\Drupal::state()
->set('common_test.library_info_build_test', TRUE);
$library_discovery
->clearCachedDefinitions();
$dynamic_library = $library_discovery
->getLibraryByName('common_test', 'dynamic_library');
$this
->assertIsArray($dynamic_library);
$this
->assertArrayHasKey('version', $dynamic_library);
$this
->assertSame('1.0', $dynamic_library['version']);
// Make sure the dynamic library definition could be altered.
// @see common_test_library_info_alter()
$this
->assertArrayHasKey('dependencies', $dynamic_library);
$this
->assertSame([
'core/jquery',
], $dynamic_library['dependencies']);
}