You are here

public function LibraryDiscoveryParserTest::testExternalLibraries in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryParserTest::testExternalLibraries()
  2. 10 core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryParserTest::testExternalLibraries()

Tests that the version property of external libraries is handled.

@covers ::buildByExtension

File

core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php, line 296
Contains \Drupal\Tests\Core\Asset\LibraryDiscoveryParserTest.

Class

LibraryDiscoveryParserTest
@coversDefaultClass \Drupal\Core\Asset\LibraryDiscoveryParser @group Asset

Namespace

Drupal\Tests\Core\Asset

Code

public function testExternalLibraries() {
  $this->moduleHandler
    ->expects($this
    ->atLeastOnce())
    ->method('moduleExists')
    ->with('external')
    ->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', 'external')
    ->willReturn($path);
  $libraries = $this->libraryDiscoveryParser
    ->buildByExtension('external');
  $library = $libraries['example_external'];
  $this
    ->assertEquals('http://example.com/css/example_external.css', $library['css'][0]['data']);
  $this
    ->assertEquals('http://example.com/example_external.js', $library['js'][0]['data']);
  $this
    ->assertEquals('3.14', $library['version']);
}