Further modules included.
[yaffs-website] / web / modules / contrib / libraries / tests / src / Kernel / ExternalLibrary / Asset / AssetLibraryTest.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 are registered as core asset libraries.
9  *
10  * @group libraries
11  */
12 class AssetLibraryTest extends AssetLibraryTestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   protected function getLibraryTypeId() {
18     return 'asset';
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_library' => [
30         'version' => '1.0.0',
31         'css' => ['base' => ['http://example.com/example.css' => []]],
32         'js' => ['http://example.com/example.js' => []],
33         'dependencies' => [],
34       ],
35     ];
36     $this->assertEquals($expected, $library_type->getAttachableAssetLibraries($library, $this->libraryManager));
37   }
38
39   /**
40    * Tests that a remote asset library is registered as a core asset library.
41    *
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
49    */
50   public function testAssetLibraryRemote() {
51     $library = $this->coreLibraryDiscovery->getLibraryByName('libraries', 'test_asset_library');
52     $expected = [
53       'version' => '1.0.0',
54       'css' => [[
55         'weight' => -200,
56         'group' => 0,
57         'type' => 'external',
58         'data' => 'http://example.com/example.css',
59         'version' => '1.0.0',
60       ]],
61       'js' => [[
62         'group' => -100,
63         'type' => 'external',
64         'data' => 'http://example.com/example.js',
65         'version' => '1.0.0',
66       ]],
67       'dependencies' => [],
68       'license' => [
69         'name' => 'GNU-GPL-2.0-or-later',
70         'url' => 'https://www.drupal.org/licensing/faq',
71         'gpl-compatible' => TRUE,
72       ]
73     ];
74     $this->assertEquals($expected, $library);
75   }
76
77   /**
78    * Tests that a local asset library is registered as a core asset library.
79    */
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'),
84       'assets/vendor'
85     ));
86     $this->coreLibraryDiscovery->clearCachedDefinitions();
87     $library = $this->coreLibraryDiscovery->getLibraryByName('libraries', 'test_asset_library');
88     $expected = [
89       'version' => '1.0.0',
90       'css' => [[
91         'weight' => -200,
92         'group' => 0,
93         'type' => 'file',
94         'data' => $this->modulePath . '/tests/assets/vendor/test_asset_library/example.css',
95         'version' => '1.0.0',
96       ]],
97       'js' => [[
98         'group' => -100,
99         'type' => 'file',
100         'data' => $this->modulePath . '/tests/assets/vendor/test_asset_library/example.js',
101         'version' => '1.0.0',
102         'minified' => FALSE,
103       ]],
104       'dependencies' => [],
105       'license' => [
106         'name' => 'GNU-GPL-2.0-or-later',
107         'url' => 'https://www.drupal.org/licensing/faq',
108         'gpl-compatible' => TRUE,
109       ]
110     ];
111     $this->assertEquals($expected, $library);
112   }
113
114 }