function ThemeTest::testRegistryRebuild

Ensures the theme registry is rebuilt when modules are disabled/enabled.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTest.php, line 198
Definition of Drupal\system\Tests\Theme\ThemeTest.

Class

ThemeTest
Tests low-level theme functions.

Namespace

Drupal\system\Tests\Theme

Code

function testRegistryRebuild() {
  $this
    ->assertIdentical(theme('theme_test_foo', array(
    'foo' => 'a',
  )), 'a', 'The theme registry contains theme_test_foo.');
  module_disable(array(
    'theme_test',
  ), FALSE);

  // After enabling/disabling a module during a test, we need to rebuild the
  // container and ensure the extension handler is loaded, otherwise theme()
  // throws an exception.
  $this
    ->rebuildContainer();
  $this->container
    ->get('module_handler')
    ->loadAll();
  $this
    ->assertIdentical(theme('theme_test_foo', array(
    'foo' => 'b',
  )), '', 'The theme registry does not contain theme_test_foo, because the module is disabled.');
  module_enable(array(
    'theme_test',
  ), FALSE);

  // After enabling/disabling a module during a test, we need to rebuild the
  // container and ensure the extension handler is loaded, otherwise theme()
  // throws an exception.
  $this
    ->rebuildContainer();
  $this->container
    ->get('module_handler')
    ->loadAll();
  $this
    ->assertIdentical(theme('theme_test_foo', array(
    'foo' => 'c',
  )), 'c', 'The theme registry contains theme_test_foo again after re-enabling the module.');
}