You are here

public function LibraryDiscoveryParserTest::testLibraryOverride in Drupal 9

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

Tests libraries with overrides.

@covers ::applyLibrariesOverride

File

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

Class

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

Namespace

Drupal\Tests\Core\Asset

Code

public function testLibraryOverride() {
  $mock_theme_path = 'mocked_themes/kittens';
  $this->themeManager = $this
    ->createMock(ThemeManagerInterface::class);
  $this->activeTheme = $this
    ->getMockBuilder(ActiveTheme::class)
    ->disableOriginalConstructor()
    ->getMock();
  $this->activeTheme
    ->expects($this
    ->atLeastOnce())
    ->method('getLibrariesOverride')
    ->willReturn([
    $mock_theme_path => [
      'example_module/example' => [
        'css' => [
          'theme' => [
            'css/example.css' => 'css/overridden.css',
            'css/example2.css' => FALSE,
          ],
        ],
      ],
    ],
  ]);
  $this->themeManager
    ->expects($this
    ->any())
    ->method('getActiveTheme')
    ->willReturn($this->activeTheme);
  $path = __DIR__ . '/library_test_files';
  $path = substr($path, strlen($this->root) + 1);
  $this->extensionPathResolver
    ->expects($this
    ->atLeastOnce())
    ->method('getPath')
    ->with('module', 'example_module')
    ->willReturn($path);
  $this->libraryDiscoveryParser = new TestLibraryDiscoveryParser($this->root, $this->moduleHandler, $this->themeManager, $this->streamWrapperManager, $this->librariesDirectoryFileFinder, $this->extensionPathResolver);
  $this->moduleHandler
    ->expects($this
    ->atLeastOnce())
    ->method('moduleExists')
    ->with('example_module')
    ->will($this
    ->returnValue(TRUE));
  $libraries = $this->libraryDiscoveryParser
    ->buildByExtension('example_module');
  $library = $libraries['example'];
  $this
    ->assertCount(0, $library['js']);
  $this
    ->assertCount(1, $library['css']);
  $this
    ->assertCount(0, $library['dependencies']);
  $this
    ->assertEquals($mock_theme_path . '/css/overridden.css', $library['css'][0]['data']);
}