3 namespace Drupal\Tests\libraries\Kernel\ExternalLibrary\Asset;
5 use Drupal\Tests\libraries\Kernel\ExternalLibrary\TestLibraryFilesStream;
8 * Tests that external asset libraries are registered as core asset libraries.
12 class AssetLibraryTest extends AssetLibraryTestBase {
17 protected function getLibraryTypeId() {
22 * Tests that attachable asset library info is correctly gathered.
24 public function testAttachableAssetInfo() {
25 /** @var \Drupal\libraries\ExternalLibrary\Asset\AttachableAssetLibraryRegistrationInterface $library_type */
26 $library_type = $this->getLibraryType();
27 $library = $this->getLibrary();
29 'test_asset_library' => [
31 'css' => ['base' => ['http://example.com/example.css' => []]],
32 'js' => ['http://example.com/example.js' => []],
36 $this->assertEquals($expected, $library_type->getAttachableAssetLibraries($library, $this->libraryManager));
40 * Tests that a remote asset library is registered as a core asset library.
42 * @see \Drupal\libraries\Extension\Extension
43 * @see \Drupal\libraries\Extension\ExtensionHandler
44 * @see \Drupal\libraries\ExternalLibrary\Asset\AssetLibrary
45 * @see \Drupal\libraries\ExternalLibrary\Asset\AssetLibraryTrait
46 * @see \Drupal\libraries\ExternalLibrary\ExternalLibraryManager
47 * @see \Drupal\libraries\ExternalLibrary\ExternalLibraryTrait
48 * @see \Drupal\libraries\ExternalLibrary\Registry\ExternalLibraryRegistry
50 public function testAssetLibraryRemote() {
51 $library = $this->coreLibraryDiscovery->getLibraryByName('libraries', 'test_asset_library');
58 'data' => 'http://example.com/example.css',
64 'data' => 'http://example.com/example.js',
69 'name' => 'GNU-GPL-2.0-or-later',
70 'url' => 'https://www.drupal.org/licensing/faq',
71 'gpl-compatible' => TRUE,
74 $this->assertEquals($expected, $library);
78 * Tests that a local asset library is registered as a core asset library.
80 public function testAssetLibraryLocal() {
81 $this->container->set('stream_wrapper.asset_libraries', new TestLibraryFilesStream(
82 $this->container->get('module_handler'),
83 $this->container->get('string_translation'),
86 $this->coreLibraryDiscovery->clearCachedDefinitions();
87 $library = $this->coreLibraryDiscovery->getLibraryByName('libraries', 'test_asset_library');
94 'data' => $this->modulePath . '/tests/assets/vendor/test_asset_library/example.css',
100 'data' => $this->modulePath . '/tests/assets/vendor/test_asset_library/example.js',
101 'version' => '1.0.0',
104 'dependencies' => [],
106 'name' => 'GNU-GPL-2.0-or-later',
107 'url' => 'https://www.drupal.org/licensing/faq',
108 'gpl-compatible' => TRUE,
111 $this->assertEquals($expected, $library);