View source
<?php
namespace Drupal\Tests\libraries\Kernel\ExternalLibrary\Asset;
use Drupal\Tests\libraries\Kernel\ExternalLibrary\TestLibraryFilesStream;
class AssetLibraryTest extends AssetLibraryTestBase {
protected function getLibraryTypeId() {
return 'asset';
}
public function testAttachableAssetInfo() {
$library_type = $this
->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));
}
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);
}
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);
}
}