public function LibraryDiscoveryParserTest::testLibraryWithLicenses in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryParserTest::testLibraryWithLicenses()
- 9 core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryParserTest::testLibraryWithLicenses()
Tests a library with various licenses, some GPL-compatible, some not.
@covers ::buildByExtension
File
- core/
tests/ Drupal/ Tests/ Core/ Asset/ LibraryDiscoveryParserTest.php, line 531 - Contains \Drupal\Tests\Core\Asset\LibraryDiscoveryParserTest.
Class
- LibraryDiscoveryParserTest
- @coversDefaultClass \Drupal\Core\Asset\LibraryDiscoveryParser @group Asset
Namespace
Drupal\Tests\Core\AssetCode
public function testLibraryWithLicenses() {
$this->moduleHandler
->expects($this
->atLeastOnce())
->method('moduleExists')
->with('licenses')
->will($this
->returnValue(TRUE));
$path = __DIR__ . '/library_test_files';
$path = substr($path, strlen($this->root) + 1);
$this->extensionPathResolver
->expects($this
->atLeastOnce())
->method('getPath')
->with('module', 'licenses')
->willReturn($path);
$libraries = $this->libraryDiscoveryParser
->buildByExtension('licenses');
// For libraries without license info, the default license is applied.
$library = $libraries['no-license-info'];
$this
->assertCount(1, $library['css']);
$this
->assertCount(1, $library['js']);
$this
->assertTrue(isset($library['license']));
$default_license = [
'name' => 'GNU-GPL-2.0-or-later',
'url' => 'https://www.drupal.org/licensing/faq',
'gpl-compatible' => TRUE,
];
$this
->assertEquals($library['license'], $default_license);
// GPL2-licensed libraries.
$library = $libraries['gpl2'];
$this
->assertCount(1, $library['css']);
$this
->assertCount(1, $library['js']);
$expected_license = [
'name' => 'gpl2',
'url' => 'https://url-to-gpl2-license',
'gpl-compatible' => TRUE,
];
$this
->assertEquals($library['license'], $expected_license);
// MIT-licensed libraries.
$library = $libraries['mit'];
$this
->assertCount(1, $library['css']);
$this
->assertCount(1, $library['js']);
$expected_license = [
'name' => 'MIT',
'url' => 'https://url-to-mit-license',
'gpl-compatible' => TRUE,
];
$this
->assertEquals($library['license'], $expected_license);
// Libraries in the Public Domain.
$library = $libraries['public-domain'];
$this
->assertCount(1, $library['css']);
$this
->assertCount(1, $library['js']);
$expected_license = [
'name' => 'Public Domain',
'url' => 'https://url-to-public-domain-license',
'gpl-compatible' => TRUE,
];
$this
->assertEquals($library['license'], $expected_license);
// Apache-licensed libraries.
$library = $libraries['apache'];
$this
->assertCount(1, $library['css']);
$this
->assertCount(1, $library['js']);
$expected_license = [
'name' => 'apache',
'url' => 'https://url-to-apache-license',
'gpl-compatible' => FALSE,
];
$this
->assertEquals($library['license'], $expected_license);
// Copyrighted libraries.
$library = $libraries['copyright'];
$this
->assertCount(1, $library['css']);
$this
->assertCount(1, $library['js']);
$expected_license = [
'name' => '© Some company',
'gpl-compatible' => FALSE,
];
$this
->assertEquals($library['license'], $expected_license);
}