Further modules included.
[yaffs-website] / web / modules / contrib / libraries / tests / src / Kernel / ExternalLibrary / Asset / MultipleAssetLibraryTest.php
1 <?php
2
3 namespace Drupal\Tests\libraries\Kernel\ExternalLibrary\Asset;
4
5 use Drupal\Tests\libraries\Kernel\ExternalLibrary\TestLibraryFilesStream;
6
7 /**
8  * Tests that external asset libraries can register multiple core libraries.
9  *
10  * @group libraries
11  */
12 class MultipleAssetLibraryTest extends AssetLibraryTestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   protected function getLibraryTypeId() {
18     return 'asset_multiple';
19   }
20
21   /**
22    * Tests that attachable asset library info is correctly gathered.
23    */
24   public function testAttachableAssetInfo() {
25     /** @var \Drupal\libraries\ExternalLibrary\Asset\AttachableAssetLibraryRegistrationInterface $library_type */
26     $library_type = $this->getLibraryType();
27     $library = $this->getLibrary();
28     $expected = [
29       'test_asset_multiple_library.first' => [
30         'version' => '1.0.0',
31         'css' => ['base' => ['http://example.com/example.first.css' => []]],
32         'js' => ['http://example.com/example.first.js' => []],
33         'dependencies' => [],
34       ],
35       'test_asset_multiple_library.second' => [
36         'version' => '1.0.0',
37         'css' => ['base' => ['http://example.com/example.second.css' => []]],
38         'js' => ['http://example.com/example.second.js' => []],
39         'dependencies' => [],
40       ],
41     ];
42     $this->assertEquals($expected, $library_type->getAttachableAssetLibraries($library, $this->libraryManager));
43   }
44
45   /**
46    * Tests that a remote asset library is registered as a core asset library.
47    *
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
55    */
56   public function testAssetLibraryRemote() {
57     $library = $this->coreLibraryDiscovery->getLibraryByName('libraries', 'test_asset_multiple_library.first');
58     $expected = [
59       'version' => '1.0.0',
60       'css' => [[
61         'weight' => -200,
62         'group' => 0,
63         'type' => 'external',
64         'data' => 'http://example.com/example.first.css',
65         'version' => '1.0.0',
66       ]],
67       'js' => [[
68         'group' => -100,
69         'type' => 'external',
70         'data' => 'http://example.com/example.first.js',
71         'version' => '1.0.0',
72       ]],
73       'dependencies' => [],
74       'license' => [
75         'name' => 'GNU-GPL-2.0-or-later',
76         'url' => 'https://www.drupal.org/licensing/faq',
77         'gpl-compatible' => TRUE,
78       ]
79     ];
80     $this->assertEquals($expected, $library);
81
82     $library = $this->coreLibraryDiscovery->getLibraryByName('libraries', 'test_asset_multiple_library.second');
83     $expected = [
84       'version' => '1.0.0',
85       'css' => [[
86         'weight' => -200,
87         'group' => 0,
88         'type' => 'external',
89         'data' => 'http://example.com/example.second.css',
90         'version' => '1.0.0',
91       ]],
92       'js' => [[
93         'group' => -100,
94         'type' => 'external',
95         'data' => 'http://example.com/example.second.js',
96         'version' => '1.0.0',
97       ]],
98       'dependencies' => [],
99       'license' => [
100         'name' => 'GNU-GPL-2.0-or-later',
101         'url' => 'https://www.drupal.org/licensing/faq',
102         'gpl-compatible' => TRUE,
103       ]
104     ];
105     $this->assertEquals($expected, $library);
106   }
107
108   /**
109    * Tests that a local asset library is registered as a core asset library.
110    */
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'),
115       'assets/vendor'
116     ));
117     $this->coreLibraryDiscovery->clearCachedDefinitions();
118
119     $library = $this->coreLibraryDiscovery->getLibraryByName('libraries', 'test_asset_multiple_library.first');
120     $expected = [
121       'version' => '1.0.0',
122       'css' => [[
123         'weight' => -200,
124         'group' => 0,
125         'type' => 'file',
126         'data' => $this->modulePath . '/tests/assets/vendor/test_asset_multiple_library/example.first.css',
127         'version' => '1.0.0',
128       ]],
129       'js' => [[
130         'group' => -100,
131         'type' => 'file',
132         'data' => $this->modulePath . '/tests/assets/vendor/test_asset_multiple_library/example.first.js',
133         'version' => '1.0.0',
134         'minified' => FALSE,
135       ]],
136       'dependencies' => [],
137       'license' => [
138         'name' => 'GNU-GPL-2.0-or-later',
139         'url' => 'https://www.drupal.org/licensing/faq',
140         'gpl-compatible' => TRUE,
141       ]
142     ];
143     $this->assertEquals($expected, $library);
144
145     $library = $this->coreLibraryDiscovery->getLibraryByName('libraries', 'test_asset_multiple_library.second');
146     $expected = [
147       'version' => '1.0.0',
148       'css' => [[
149         'weight' => -200,
150         'group' => 0,
151         'type' => 'file',
152         'data' => $this->modulePath . '/tests/assets/vendor/test_asset_multiple_library/example.second.css',
153         'version' => '1.0.0',
154       ]],
155       'js' => [[
156         'group' => -100,
157         'type' => 'file',
158         'data' => $this->modulePath . '/tests/assets/vendor/test_asset_multiple_library/example.second.js',
159         'version' => '1.0.0',
160         'minified' => FALSE,
161       ]],
162       'dependencies' => [],
163       'license' => [
164         'name' => 'GNU-GPL-2.0-or-later',
165         'url' => 'https://www.drupal.org/licensing/faq',
166         'gpl-compatible' => TRUE,
167       ]
168     ];
169     $this->assertEquals($expected, $library);
170   }
171
172 }