You are here

public function ThemeTest::testInvalidTheme 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::testInvalidTheme()

Test 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 375

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
    ->assertText(t('This theme requires the base theme @base_theme to operate correctly.', [
    '@base_theme' => 'not_real_test_basetheme',
  ]));
  $this
    ->assertText(t('This theme requires the base theme @base_theme to operate correctly.', [
    '@base_theme' => 'test_invalid_basetheme',
  ]));
  $this
    ->assertText(t('This theme requires the theme engine @theme_engine to operate correctly.', [
    '@theme_engine' => 'not_real_engine',
  ]));

  // 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 core version', $incompatible_core_message);
  $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
    ->assertText("This theme is missing a 'content' region.");
}