You are here

public function ThemeTest::testInvalidTheme in Drupal 9

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

Tests themes can't be installed when the base theme or engine is missing.

Include test for themes that have a missing base theme somewhere further up the chain than the immediate base theme.

File

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

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 testInvalidTheme() {

  // theme_page_test_system_info_alter() un-hides all hidden themes.
  $this->container
    ->get('module_installer')
    ->install([
    'theme_page_test',
  ]);

  // Clear the system_list() and theme listing cache to pick up the change.
  $this->container
    ->get('theme_handler')
    ->reset();
  $this
    ->drupalGet('admin/appearance');
  $this
    ->assertSession()
    ->pageTextContains('This theme requires the base theme not_real_test_basetheme to operate correctly.');
  $this
    ->assertSession()
    ->pageTextContains('This theme requires the base theme test_invalid_basetheme to operate correctly.');
  $this
    ->assertSession()
    ->pageTextContains('This theme requires the theme engine not_real_engine to operate correctly.');

  // Check for the error text of a theme with the wrong core version
  // using 7.x and ^7.
  $incompatible_core_message = 'This theme is not compatible with Drupal ' . \Drupal::VERSION . ". Check that the .info.yml file contains a compatible 'core' or 'core_version_requirement' value.";
  $this
    ->assertThemeIncompatibleText('Theme test with invalid semver core version', $incompatible_core_message);

  // Check for the error text of a theme without a content region.
  $this
    ->assertSession()
    ->pageTextContains("This theme is missing a 'content' region.");
}