function FunctionalTestSetupTrait::installDefaultThemeFromClassProperty

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php \Drupal\Core\Test\FunctionalTestSetupTrait::installDefaultThemeFromClassProperty()
  2. 10 core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php \Drupal\Core\Test\FunctionalTestSetupTrait::installDefaultThemeFromClassProperty()
  3. 11.x core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php \Drupal\Core\Test\FunctionalTestSetupTrait::installDefaultThemeFromClassProperty()

Installs the default theme defined by `static::$defaultTheme` when needed.

To install a test theme outside of the testing environment, add

$settings['extension_discovery_scan_tests'] = TRUE;

to your settings.php.

Parameters

\Symfony\Component\DependencyInjection\ContainerInterface $container: The container.

3 calls to FunctionalTestSetupTrait::installDefaultThemeFromClassProperty()
BrowserTestBase::installDrupal in core/tests/Drupal/Tests/BrowserTestBase.php
Installs Drupal into the Simpletest site.
InstallerTestBase::setUp in core/tests/Drupal/FunctionalTests/Installer/InstallerTestBase.php
WebTestBase::setUp in core/modules/simpletest/src/WebTestBase.php
Sets up a Drupal site for running functional and integration tests.

File

core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php, line 415

Class

FunctionalTestSetupTrait
Defines a trait for shared functional test setup functionality.

Namespace

Drupal\Core\Test

Code

protected function installDefaultThemeFromClassProperty(ContainerInterface $container) {
    // Use the install profile to determine the default theme if configured and
    // not already specified.
    $profile = $container->getParameter('install_profile');
    $default_sync_path = drupal_get_path('profile', $profile) . '/config/sync';
    $profile_config_storage = new FileStorage($default_sync_path, StorageInterface::DEFAULT_COLLECTION);
    if (!isset($this->defaultTheme) && $profile_config_storage->exists('system.theme')) {
        $this->defaultTheme = $profile_config_storage->read('system.theme')['default'];
    }
    $default_install_path = drupal_get_path('profile', $profile) . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
    $profile_config_storage = new FileStorage($default_install_path, StorageInterface::DEFAULT_COLLECTION);
    if (!isset($this->defaultTheme) && $profile_config_storage->exists('system.theme')) {
        $this->defaultTheme = $profile_config_storage->read('system.theme')['default'];
    }
    // Require a default theme to be specified at this point.
    if (!isset($this->defaultTheme)) {
        // For backwards compatibility, tests using the 'testing' install profile
        // on Drupal 8 automatically get 'classy' set, and other profiles use
        // 'stark'.
        @trigger_error('Drupal\\Tests\\BrowserTestBase::$defaultTheme is required in drupal:9.0.0 when using an install profile that does not set a default theme. See https://www.drupal.org/node/3083055, which includes recommendations on which theme to use.', E_USER_DEPRECATED);
        $this->defaultTheme = $profile === 'testing' ? 'classy' : 'stark';
    }
    // Ensure the default theme is installed.
    $container->get('theme_installer')
        ->install([
        $this->defaultTheme,
    ], TRUE);
    $system_theme_config = $container->get('config.factory')
        ->getEditable('system.theme');
    if ($system_theme_config->get('default') !== $this->defaultTheme) {
        $system_theme_config->set('default', $this->defaultTheme)
            ->save();
    }
}

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