You are here

public function ThemeInstallerTest::testThemeInfoAlter in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Theme/ThemeInstallerTest.php \Drupal\KernelTests\Core\Theme\ThemeInstallerTest::testThemeInfoAlter()
  2. 10 core/tests/Drupal/KernelTests/Core/Theme/ThemeInstallerTest.php \Drupal\KernelTests\Core\Theme\ThemeInstallerTest::testThemeInfoAlter()

Tests that theme info can be altered by a module.

See also

module_test_system_info_alter()

File

core/tests/Drupal/KernelTests/Core/Theme/ThemeInstallerTest.php, line 380

Class

ThemeInstallerTest
Tests installing and uninstalling of themes.

Namespace

Drupal\KernelTests\Core\Theme

Code

public function testThemeInfoAlter() {
  $name = 'seven';
  $this->container
    ->get('state')
    ->set('module_test.hook_system_info_alter', TRUE);
  $this
    ->themeInstaller()
    ->install([
    $name,
  ]);
  $themes = $this
    ->themeHandler()
    ->listInfo();
  $this
    ->assertFalse(isset($themes[$name]->info['regions']['test_region']));

  // Install module_test.
  $this
    ->moduleInstaller()
    ->install([
    'module_test',
  ], FALSE);
  $this
    ->assertTrue($this
    ->moduleHandler()
    ->moduleExists('module_test'));
  $themes = $this
    ->themeHandler()
    ->listInfo();
  $this
    ->assertTrue(isset($themes[$name]->info['regions']['test_region']));

  // Legacy assertions.
  // @todo Remove once theme initialization/info has been modernized.
  // @see https://www.drupal.org/node/2228093
  $info = \Drupal::service('extension.list.theme')
    ->getExtensionInfo($name);
  $this
    ->assertTrue(isset($info['regions']['test_region']));
  $regions = system_region_list($name);
  $this
    ->assertTrue(isset($regions['test_region']));
  $theme_list = \Drupal::service('theme_handler')
    ->listInfo();
  $this
    ->assertTrue(isset($theme_list[$name]->info['regions']['test_region']));
  $this
    ->moduleInstaller()
    ->uninstall([
    'module_test',
  ]);
  $this
    ->assertFalse($this
    ->moduleHandler()
    ->moduleExists('module_test'));
  $themes = $this
    ->themeHandler()
    ->listInfo();
  $this
    ->assertFalse(isset($themes[$name]->info['regions']['test_region']));

  // Legacy assertions.
  // @todo Remove once theme initialization/info has been modernized.
  // @see https://www.drupal.org/node/2228093
  $info = \Drupal::service('extension.list.theme')
    ->getExtensionInfo($name);
  $this
    ->assertFalse(isset($info['regions']['test_region']));
  $regions = system_region_list($name);
  $this
    ->assertFalse(isset($regions['test_region']));
  $theme_list = \Drupal::service('theme_handler')
    ->listInfo();
  $this
    ->assertFalse(isset($theme_list[$name]->info['regions']['test_region']));
}