You are here

public function RegistryTest::testGetRegistryForModule in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/Theme/RegistryTest.php \Drupal\Tests\Core\Theme\RegistryTest::testGetRegistryForModule()

Tests getting the theme registry defined by a module.

File

core/tests/Drupal/Tests/Core/Theme/RegistryTest.php, line 88
Contains \Drupal\Tests\Core\Theme\RegistryTest.

Class

RegistryTest
@coversDefaultClass \Drupal\Core\Theme\Registry @group Theme

Namespace

Drupal\Tests\Core\Theme

Code

public function testGetRegistryForModule() {
  $this
    ->setupTheme('test_theme');
  $this->registry
    ->setTheme(new ActiveTheme([
    'name' => 'test_theme',
    'path' => 'core/modules/system/tests/themes/test_theme/test_theme.info.yml',
    'engine' => 'twig',
    'owner' => 'twig',
    'stylesheets_remove' => [],
    'libraries_override' => [],
    'libraries_extend' => [],
    'libraries' => [],
    'extension' => '.twig',
    'base_themes' => [],
  ]));

  // Include the module so that hook_theme can be called.
  include_once $this->root . '/core/modules/system/tests/modules/theme_test/theme_test.module';
  $this->moduleHandler
    ->expects($this
    ->once())
    ->method('getImplementations')
    ->with('theme')
    ->will($this
    ->returnValue(array(
    'theme_test',
  )));
  $this->moduleHandler
    ->expects($this
    ->atLeastOnce())
    ->method('getModuleList')
    ->willReturn([]);
  $registry = $this->registry
    ->get();

  // Ensure that the registry entries from the module are found.
  $this
    ->assertArrayHasKey('theme_test', $registry);
  $this
    ->assertArrayHasKey('theme_test_template_test', $registry);
  $this
    ->assertArrayHasKey('theme_test_template_test_2', $registry);
  $this
    ->assertArrayHasKey('theme_test_suggestion_provided', $registry);
  $this
    ->assertArrayHasKey('theme_test_specific_suggestions', $registry);
  $this
    ->assertArrayHasKey('theme_test_suggestions', $registry);
  $this
    ->assertArrayHasKey('theme_test_function_suggestions', $registry);
  $this
    ->assertArrayHasKey('theme_test_foo', $registry);
  $this
    ->assertArrayHasKey('theme_test_render_element', $registry);
  $this
    ->assertArrayHasKey('theme_test_render_element_children', $registry);
  $this
    ->assertArrayHasKey('theme_test_function_template_override', $registry);
  $this
    ->assertArrayNotHasKey('test_theme_not_existing_function', $registry);
  $info = $registry['theme_test_function_suggestions'];
  $this
    ->assertEquals('module', $info['type']);
  $this
    ->assertEquals('core/modules/system/tests/modules/theme_test', $info['theme path']);
  $this
    ->assertEquals('theme_theme_test_function_suggestions', $info['function']);
  $this
    ->assertEquals(array(), $info['variables']);
}