You are here

public function LibraryDiscoveryCollectorTest::testLibrariesExtend in Drupal 10

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryCollectorTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryCollectorTest::testLibrariesExtend()

Tests library with an extend.

@covers ::applyLibrariesExtend

File

core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryCollectorTest.php, line 175

Class

LibraryDiscoveryCollectorTest
@coversDefaultClass \Drupal\Core\Asset\LibraryDiscoveryCollector @group Asset

Namespace

Drupal\Tests\Core\Asset

Code

public function testLibrariesExtend() {
  $this->activeTheme = $this
    ->getMockBuilder(ActiveTheme::class)
    ->disableOriginalConstructor()
    ->getMock();
  $this->themeManager
    ->expects($this
    ->any())
    ->method('getActiveTheme')
    ->willReturn($this->activeTheme);
  $this->activeTheme
    ->expects($this
    ->once())
    ->method('getName')
    ->willReturn('kitten_theme');
  $this->activeTheme
    ->expects($this
    ->atLeastOnce())
    ->method('getLibrariesExtend')
    ->willReturn([
    'test/test_3' => [
      'kitten_theme/extend',
    ],
  ]);
  $this->libraryDiscoveryParser
    ->expects($this
    ->exactly(2))
    ->method('buildByExtension')
    ->willReturnMap([
    [
      'test',
      $this->libraryData,
    ],
    [
      'kitten_theme',
      [
        'extend' => [
          'css' => [
            'theme' => [
              'baz.css' => [],
            ],
          ],
        ],
      ],
    ],
  ]);
  $library_discovery_collector = new LibraryDiscoveryCollector($this->cache, $this->lock, $this->libraryDiscoveryParser, $this->themeManager);
  $libraries = $library_discovery_collector
    ->get('test');
  $this
    ->assertSame([
    'foo.css',
    'baz.css',
  ], array_keys($libraries['test_3']['css']['theme']));
}