function LibraryDiscoveryParserTest::testBuildByExtensionWithTheme

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryParserTest::testBuildByExtensionWithTheme()
  2. 8.9.x core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryParserTest::testBuildByExtensionWithTheme()
  3. 11.x 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 167

Class

LibraryDiscoveryParserTest
@coversDefaultClass \Drupal\Core\Asset\LibraryDiscoveryParser[[api-linebreak]] @group Asset

Namespace

Drupal\Tests\Core\Asset

Code

public function testBuildByExtensionWithTheme() : void {
  $this->moduleHandler
    ->expects($this->atLeastOnce())
    ->method('moduleExists')
    ->with('example_theme')
    ->willReturn(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']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.