function LibraryDiscoveryParserTest::testBuildByExtensionSimple

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryParserTest::testBuildByExtensionSimple()
  2. 8.9.x core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryParserTest::testBuildByExtensionSimple()
  3. 11.x core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryParserTest::testBuildByExtensionSimple()

Tests that basic functionality works for getLibraryByName.

@covers ::buildByExtension

@runInSeparateProcess

File

core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php, line 127

Class

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

Namespace

Drupal\Tests\Core\Asset

Code

public function testBuildByExtensionSimple() : void {
    FileCacheFactory::setPrefix('testing');
    // Use the default file cache configuration.
    FileCacheFactory::setConfiguration([
        'library_parser' => [],
    ]);
    $this->libraryDiscoveryParser = new TestLibraryDiscoveryParser($this->root, $this->moduleHandler, $this->themeManager, $this->streamWrapperManager, $this->librariesDirectoryFileFinder, $this->extensionPathResolver, $this->componentPluginManager);
    $this->moduleHandler
        ->expects($this->atLeastOnce())
        ->method('moduleExists')
        ->with('example_module')
        ->willReturn(TRUE);
    $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);
    $libraries = $this->libraryDiscoveryParser
        ->buildByExtension('example_module');
    $library = $libraries['example'];
    $this->assertCount(0, $library['js']);
    $this->assertCount(2, $library['css']);
    $this->assertCount(0, $library['dependencies']);
    $this->assertEquals($path . '/css/example.css', $library['css'][0]['data']);
    // Ensures that VERSION is replaced by the current core version.
    $this->assertEquals(\Drupal::VERSION, $library['version']);
    // Ensure that the expected FileCache entry exists.
    $cache = FileCacheFactory::get('library_parser')->get($path . '/example_module.libraries.yml');
    $this->assertArrayHasKey('example', $cache);
}

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