You are here

public function LibraryDiscoveryParserTest::testBuildByExtensionWithTheme 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::testBuildByExtensionWithTheme()
  2. 10 core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryParserTest::testBuildByExtensionWithTheme()

Tests that a theme can be used instead of a module.

@covers ::buildByExtension

File

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

Class

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

Namespace

Drupal\Tests\Core\Asset

Code

public function testBuildByExtensionWithTheme() {
  $this->moduleHandler
    ->expects($this
    ->atLeastOnce())
    ->method('moduleExists')
    ->with('example_theme')
    ->will($this
    ->returnValue(FALSE));
  $path = __DIR__ . '/library_test_files';
  $path = substr($path, strlen($this->root) + 1);
  $this->extensionPathResolver
    ->expects($this
    ->atLeastOnce())
    ->method('getPath')
    ->with('theme', 'example_theme')
    ->willReturn($path);
  $libraries = $this->libraryDiscoveryParser
    ->buildByExtension('example_theme');
  $library = $libraries['example'];
  $this
    ->assertCount(0, $library['js']);
  $this
    ->assertCount(1, $library['css']);
  $this
    ->assertCount(0, $library['dependencies']);
  $this
    ->assertEquals($path . '/css/example.css', $library['css'][0]['data']);
}