You are here

public function ThemeTest::testInstallAndSetAsDefault in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/System/ThemeTest.php \Drupal\Tests\system\Functional\System\ThemeTest::testInstallAndSetAsDefault()

Tests installing a theme and setting it as default.

File

core/modules/system/tests/src/Functional/System/ThemeTest.php, line 456

Class

ThemeTest
Tests the theme interface functionality by enabling and switching themes, and using an administration theme.

Namespace

Drupal\Tests\system\Functional\System

Code

public function testInstallAndSetAsDefault() {
  $themes = [
    'bartik' => 'Bartik',
    'test_core_semver' => 'Theme test with semver core version',
  ];
  foreach ($themes as $theme_machine_name => $theme_name) {
    $this
      ->drupalGet('admin/appearance');
    $this
      ->getSession()
      ->getPage()
      ->findLink("Install {$theme_name} as default theme")
      ->click();

    // Test the confirmation message.
    $this
      ->assertText("{$theme_name} is now the default theme.");

    // Make sure the theme is now set as the default theme in config.
    $this
      ->assertEqual($this
      ->config('system.theme')
      ->get('default'), $theme_machine_name);

    // This checks for a regression. See https://www.drupal.org/node/2498691.
    $this
      ->assertNoText("The {$theme_machine_name} theme was not found.");
    $themes = \Drupal::service('theme_handler')
      ->rebuildThemeData();
    $version = $themes[$theme_machine_name]->info['version'];

    // Confirm the theme is indicated as the default theme and administration
    // theme because the admin theme is the default theme.
    $out = $this
      ->getSession()
      ->getPage()
      ->getContent();
    $this
      ->assertTrue((bool) preg_match("/{$theme_name} " . preg_quote($version) . '\\s{2,}\\(default theme, administration theme\\)/', $out));
  }
}