3 namespace Drupal\Tests\libraries\Kernel\ExternalLibrary\Asset;
5 use Drupal\Tests\libraries\Kernel\ExternalLibrary\TestLibraryFilesStream;
8 * Tests that external asset libraries can register multiple core libraries.
12 class MultipleAssetLibraryTest extends AssetLibraryTestBase {
17 protected function getLibraryTypeId() {
18 return 'asset_multiple';
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_multiple_library.first' => [
31 'css' => ['base' => ['http://example.com/example.first.css' => []]],
32 'js' => ['http://example.com/example.first.js' => []],
35 'test_asset_multiple_library.second' => [
37 'css' => ['base' => ['http://example.com/example.second.css' => []]],
38 'js' => ['http://example.com/example.second.js' => []],
42 $this->assertEquals($expected, $library_type->getAttachableAssetLibraries($library, $this->libraryManager));
46 * Tests that a remote asset library is registered as a core asset library.
48 * @see \Drupal\libraries\Extension\Extension
49 * @see \Drupal\libraries\Extension\ExtensionHandler
50 * @see \Drupal\libraries\ExternalLibrary\Asset\AssetLibrary
51 * @see \Drupal\libraries\ExternalLibrary\Asset\AssetLibraryTrait
52 * @see \Drupal\libraries\ExternalLibrary\ExternalLibraryManager
53 * @see \Drupal\libraries\ExternalLibrary\ExternalLibraryTrait
54 * @see \Drupal\libraries\ExternalLibrary\Registry\ExternalLibraryRegistry
56 public function testAssetLibraryRemote() {
57 $library = $this->coreLibraryDiscovery->getLibraryByName('libraries', 'test_asset_multiple_library.first');
64 'data' => 'http://example.com/example.first.css',
70 'data' => 'http://example.com/example.first.js',
75 'name' => 'GNU-GPL-2.0-or-later',
76 'url' => 'https://www.drupal.org/licensing/faq',
77 'gpl-compatible' => TRUE,
80 $this->assertEquals($expected, $library);
82 $library = $this->coreLibraryDiscovery->getLibraryByName('libraries', 'test_asset_multiple_library.second');
89 'data' => 'http://example.com/example.second.css',
95 'data' => 'http://example.com/example.second.js',
100 'name' => 'GNU-GPL-2.0-or-later',
101 'url' => 'https://www.drupal.org/licensing/faq',
102 'gpl-compatible' => TRUE,
105 $this->assertEquals($expected, $library);
109 * Tests that a local asset library is registered as a core asset library.
111 public function testAssetLibraryLocal() {
112 $this->container->set('stream_wrapper.asset_libraries', new TestLibraryFilesStream(
113 $this->container->get('module_handler'),
114 $this->container->get('string_translation'),
117 $this->coreLibraryDiscovery->clearCachedDefinitions();
119 $library = $this->coreLibraryDiscovery->getLibraryByName('libraries', 'test_asset_multiple_library.first');
121 'version' => '1.0.0',
126 'data' => $this->modulePath . '/tests/assets/vendor/test_asset_multiple_library/example.first.css',
127 'version' => '1.0.0',
132 'data' => $this->modulePath . '/tests/assets/vendor/test_asset_multiple_library/example.first.js',
133 'version' => '1.0.0',
136 'dependencies' => [],
138 'name' => 'GNU-GPL-2.0-or-later',
139 'url' => 'https://www.drupal.org/licensing/faq',
140 'gpl-compatible' => TRUE,
143 $this->assertEquals($expected, $library);
145 $library = $this->coreLibraryDiscovery->getLibraryByName('libraries', 'test_asset_multiple_library.second');
147 'version' => '1.0.0',
152 'data' => $this->modulePath . '/tests/assets/vendor/test_asset_multiple_library/example.second.css',
153 'version' => '1.0.0',
158 'data' => $this->modulePath . '/tests/assets/vendor/test_asset_multiple_library/example.second.js',
159 'version' => '1.0.0',
162 'dependencies' => [],
164 'name' => 'GNU-GPL-2.0-or-later',
165 'url' => 'https://www.drupal.org/licensing/faq',
166 'gpl-compatible' => TRUE,
169 $this->assertEquals($expected, $library);