function AssetResolverTest::setUp

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

Overrides UnitTestCase::setUp

File

core/tests/Drupal/Tests/Core/Asset/AssetResolverTest.php, line 96

Class

AssetResolverTest
@coversDefaultClass \Drupal\Core\Asset\AssetResolver @group Asset

Namespace

Drupal\Tests\Core\Asset

Code

protected function setUp() : void {
    parent::setUp();
    $this->libraryDiscovery = $this->getMockBuilder('Drupal\\Core\\Asset\\LibraryDiscovery')
        ->disableOriginalConstructor()
        ->getMock();
    $this->libraryDiscovery
        ->expects($this->any())
        ->method('getLibraryByName')
        ->willReturnCallback(function ($extension, $name) {
        return $this->libraries[$extension . '/' . $name];
    });
    $this->libraries = [
        'core/drupal' => [
            'version' => '1.0.0',
            'css' => [],
            'js' => [
                'core/misc/drupal.js' => [
                    'data' => 'core/misc/drupal.js',
                    'preprocess' => TRUE,
                ],
            ],
            'license' => '',
        ],
        'core/jquery' => [
            'version' => '1.0.0',
            'css' => [],
            'js' => [
                'core/misc/jquery.js' => [
                    'data' => 'core/misc/jquery.js',
                    'minified' => TRUE,
                ],
            ],
            'license' => '',
        ],
        'llama/css' => [
            'version' => '1.0.0',
            'css' => [
                'core/misc/llama.css' => [
                    'data' => 'core/misc/llama.css',
                ],
            ],
            'js' => [],
            'license' => '',
        ],
        'piggy/css' => [
            'version' => '1.0.0',
            'css' => [
                'core/misc/piggy.css' => [
                    'data' => 'core/misc/piggy.css',
                ],
            ],
            'js' => [],
            'license' => '',
        ],
        'core/ckeditor5' => [
            'remote' => 'https://github.com/ckeditor/ckeditor5',
            'version' => '1.0.0',
            'license' => '',
            'js' => [
                'assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js' => [
                    'data' => 'assets/vendor/ckeditor5/ckeditor5-dll/ckeditor5-dll.js',
                    'preprocess' => FALSE,
                    'minified' => TRUE,
                ],
            ],
        ],
        'piggy/ckeditor' => [
            'version' => '1.0.0',
            'css' => [
                'core/misc/ckeditor.css' => [
                    'data' => 'core/misc/ckeditor.css',
                ],
            ],
            'js' => [],
            'license' => '',
            'dependencies' => [
                'core/ckeditor5',
            ],
        ],
    ];
    $this->libraryDependencyResolver = new LibraryDependencyResolver($this->libraryDiscovery);
    $this->moduleHandler = $this->createMock('\\Drupal\\Core\\Extension\\ModuleHandlerInterface');
    $this->themeManager = $this->createMock('\\Drupal\\Core\\Theme\\ThemeManagerInterface');
    $active_theme = $this->getMockBuilder('\\Drupal\\Core\\Theme\\ActiveTheme')
        ->disableOriginalConstructor()
        ->getMock();
    $this->themeManager
        ->expects($this->any())
        ->method('getActiveTheme')
        ->willReturn($active_theme);
    $this->languageManager = $this->createMock('\\Drupal\\Core\\Language\\LanguageManagerInterface');
    $english = $this->createMock('\\Drupal\\Core\\Language\\LanguageInterface');
    $english->expects($this->any())
        ->method('getId')
        ->willReturn('en');
    $this->english = $english;
    $japanese = $this->createMock('\\Drupal\\Core\\Language\\LanguageInterface');
    $japanese->expects($this->any())
        ->method('getId')
        ->willReturn('jp');
    $this->japanese = $japanese;
    $this->languageManager = $this->createMock('\\Drupal\\Core\\Language\\LanguageManagerInterface');
    $this->languageManager
        ->expects($this->any())
        ->method('getCurrentLanguage')
        ->willReturn($english, $english, $japanese, $japanese);
    $this->cache = new TestMemoryBackend(new Time());
    $this->themeHandler = $this->createMock('\\Drupal\\Core\\Extension\\ThemeHandlerInterface');
    $this->assetResolver = new AssetResolver($this->libraryDiscovery, $this->libraryDependencyResolver, $this->moduleHandler, $this->themeManager, $this->languageManager, $this->cache, $this->themeHandler);
}

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