X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Flibraries%2Ftests%2Fsrc%2FKernel%2FExternalLibrary%2FAsset%2FAssetLibraryTest.php;fp=web%2Fmodules%2Fcontrib%2Flibraries%2Ftests%2Fsrc%2FKernel%2FExternalLibrary%2FAsset%2FAssetLibraryTest.php;h=cb2551e22fcd2132a1b8b1b8f267c246be1d67b8;hp=0000000000000000000000000000000000000000;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35 diff --git a/web/modules/contrib/libraries/tests/src/Kernel/ExternalLibrary/Asset/AssetLibraryTest.php b/web/modules/contrib/libraries/tests/src/Kernel/ExternalLibrary/Asset/AssetLibraryTest.php new file mode 100644 index 000000000..cb2551e22 --- /dev/null +++ b/web/modules/contrib/libraries/tests/src/Kernel/ExternalLibrary/Asset/AssetLibraryTest.php @@ -0,0 +1,114 @@ +getLibraryType(); + $library = $this->getLibrary(); + $expected = [ + 'test_asset_library' => [ + 'version' => '1.0.0', + 'css' => ['base' => ['http://example.com/example.css' => []]], + 'js' => ['http://example.com/example.js' => []], + 'dependencies' => [], + ], + ]; + $this->assertEquals($expected, $library_type->getAttachableAssetLibraries($library, $this->libraryManager)); + } + + /** + * Tests that a remote asset library is registered as a core asset library. + * + * @see \Drupal\libraries\Extension\Extension + * @see \Drupal\libraries\Extension\ExtensionHandler + * @see \Drupal\libraries\ExternalLibrary\Asset\AssetLibrary + * @see \Drupal\libraries\ExternalLibrary\Asset\AssetLibraryTrait + * @see \Drupal\libraries\ExternalLibrary\ExternalLibraryManager + * @see \Drupal\libraries\ExternalLibrary\ExternalLibraryTrait + * @see \Drupal\libraries\ExternalLibrary\Registry\ExternalLibraryRegistry + */ + public function testAssetLibraryRemote() { + $library = $this->coreLibraryDiscovery->getLibraryByName('libraries', 'test_asset_library'); + $expected = [ + 'version' => '1.0.0', + 'css' => [[ + 'weight' => -200, + 'group' => 0, + 'type' => 'external', + 'data' => 'http://example.com/example.css', + 'version' => '1.0.0', + ]], + 'js' => [[ + 'group' => -100, + 'type' => 'external', + 'data' => 'http://example.com/example.js', + 'version' => '1.0.0', + ]], + 'dependencies' => [], + 'license' => [ + 'name' => 'GNU-GPL-2.0-or-later', + 'url' => 'https://www.drupal.org/licensing/faq', + 'gpl-compatible' => TRUE, + ] + ]; + $this->assertEquals($expected, $library); + } + + /** + * Tests that a local asset library is registered as a core asset library. + */ + public function testAssetLibraryLocal() { + $this->container->set('stream_wrapper.asset_libraries', new TestLibraryFilesStream( + $this->container->get('module_handler'), + $this->container->get('string_translation'), + 'assets/vendor' + )); + $this->coreLibraryDiscovery->clearCachedDefinitions(); + $library = $this->coreLibraryDiscovery->getLibraryByName('libraries', 'test_asset_library'); + $expected = [ + 'version' => '1.0.0', + 'css' => [[ + 'weight' => -200, + 'group' => 0, + 'type' => 'file', + 'data' => $this->modulePath . '/tests/assets/vendor/test_asset_library/example.css', + 'version' => '1.0.0', + ]], + 'js' => [[ + 'group' => -100, + 'type' => 'file', + 'data' => $this->modulePath . '/tests/assets/vendor/test_asset_library/example.js', + 'version' => '1.0.0', + 'minified' => FALSE, + ]], + 'dependencies' => [], + 'license' => [ + 'name' => 'GNU-GPL-2.0-or-later', + 'url' => 'https://www.drupal.org/licensing/faq', + 'gpl-compatible' => TRUE, + ] + ]; + $this->assertEquals($expected, $library); + } + +}