function AttachedAssetsTest::testDynamicLibrary
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php \Drupal\KernelTests\Core\Asset\AttachedAssetsTest::testDynamicLibrary()
- 8.9.x core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php \Drupal\KernelTests\Core\Asset\AttachedAssetsTest::testDynamicLibrary()
- 11.x 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 419
Class
- AttachedAssetsTest
- Tests #attached assets: attached asset libraries and JavaScript settings.
Namespace
Drupal\KernelTests\Core\AssetCode
public function testDynamicLibrary() : void {
/** @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']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.