function ThemeUiTest::testInstalledIncompatibleTheme

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Theme/ThemeUiTest.php \Drupal\Tests\system\Functional\Theme\ThemeUiTest::testInstalledIncompatibleTheme()
  2. 10 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 334

Class

ThemeUiTest
Tests the theme UI.

Namespace

Drupal\Tests\system\Functional\Theme

Code

public function testInstalledIncompatibleTheme() : void {
    $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',
    ];
    $this->writeInfoFile($file_path, $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");
    $this->writeInfoFile($file_path, $incompatible_info);
    $this->drupalGet('admin/appearance');
    $this->assertSession()
        ->pageTextContains($incompatible_themes_message);
    $this->writeInfoFile($file_path, $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);
    $this->writeInfoFile($file_path, $incompatible_info);
    $this->drupalGet('admin/appearance');
    $this->assertSession()
        ->pageTextNotContains($incompatible_themes_message);
}

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