You are here

public function ThemeUiTest::testInstalledIncompatibleTheme in Drupal 9

Tests that incompatible themes message is shown.

File

core/modules/system/tests/src/Functional/Theme/ThemeUiTest.php, line 328

Class

ThemeUiTest
Tests the theme UI.

Namespace

Drupal\Tests\system\Functional\Theme

Code

public function testInstalledIncompatibleTheme() {
  $page = $this
    ->getSession()
    ->getPage();
  $assert_session = $this
    ->assertSession();
  $incompatible_themes_message = 'There are errors with some installed themes. Visit the status report page for more information.';
  $path = \Drupal::getContainer()
    ->getParameter('site.path') . "/themes/changing_theme";
  mkdir($path, 0777, TRUE);
  $file_path = "{$path}/changing_theme.info.yml";
  $theme_name = 'Theme that changes';
  $info = [
    'name' => $theme_name,
    'type' => 'theme',
    'base theme' => FALSE,
  ];
  $compatible_info = $info + [
    'core_version_requirement' => '*',
  ];
  file_put_contents($file_path, Yaml::encode($compatible_info));
  $this
    ->drupalGet('admin/appearance');
  $this
    ->assertSession()
    ->pageTextNotContains($incompatible_themes_message);
  $page
    ->clickLink("Install {$theme_name} theme");
  $assert_session
    ->addressEquals('admin/appearance');
  $assert_session
    ->pageTextContains("The {$theme_name} theme has been installed");
  $incompatible_updates = [
    [
      'core_version_requirement' => '^1',
    ],
    [
      'core' => '8.x',
    ],
  ];
  foreach ($incompatible_updates as $incompatible_update) {
    $incompatible_info = $info + $incompatible_update;
    file_put_contents($file_path, Yaml::encode($incompatible_info));
    $this
      ->drupalGet('admin/appearance');
    $this
      ->assertSession()
      ->pageTextContains($incompatible_themes_message);
    file_put_contents($file_path, Yaml::encode($compatible_info));
    $this
      ->drupalGet('admin/appearance');
    $this
      ->assertSession()
      ->pageTextNotContains($incompatible_themes_message);
  }

  // Uninstall the theme and ensure that incompatible themes message is not
  // displayed for themes that are not installed.
  $this
    ->uninstallTheme($theme_name);
  foreach ($incompatible_updates as $incompatible_update) {
    $incompatible_info = $info + $incompatible_update;
    file_put_contents($file_path, Yaml::encode($incompatible_info));
    $this
      ->drupalGet('admin/appearance');
    $this
      ->assertSession()
      ->pageTextNotContains($incompatible_themes_message);
  }
}