You are here

public function ThemeUiTest::testInstalledIncompatibleTheme in Drupal 10

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

Tests that incompatible themes message is shown.

File

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

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' => '*',
  ];
  $incompatible_info = $info + [
    'core_version_requirement' => '^1',
  ];
  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");
  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);
  file_put_contents($file_path, Yaml::encode($incompatible_info));
  $this
    ->drupalGet('admin/appearance');
  $this
    ->assertSession()
    ->pageTextNotContains($incompatible_themes_message);
}