function LibraryDiscoveryParserTest::testLibraryOverride

Same name in other branches
  1. 10 core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryParserTest::testLibraryOverride()
  2. 11.x 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

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')
        ->willReturn(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']);
}

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