function RegistryLegacyTest::testGetLegacyThemeFunctionRegistryForModule

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Theme/RegistryLegacyTest.php \Drupal\Tests\Core\Theme\RegistryLegacyTest::testGetLegacyThemeFunctionRegistryForModule()

Tests getting legacy theme function registry data defined by a module.

@expectedDeprecation Theme functions are deprecated in drupal:8.0.0 and are removed from drupal:10.0.0. Use Twig templates instead of theme_theme_test(). See https://www.drupal.org/node/1831138

File

core/tests/Drupal/Tests/Core/Theme/RegistryLegacyTest.php, line 88

Class

RegistryLegacyTest
@coversDefaultClass \Drupal\Core\Theme\Registry @group Theme @group legacy

Namespace

Drupal\Tests\Core\Theme

Code

public function testGetLegacyThemeFunctionRegistryForModule() {
    $test_theme = new ActiveTheme([
        'name' => 'test_legacy_theme',
        'path' => 'core/modules/system/tests/themes/test_legacy_theme/test_legacy_theme.info.yml',
        'engine' => 'twig',
        'owner' => 'twig',
        'stylesheets_remove' => [],
        'libraries_override' => [],
        'libraries_extend' => [],
        'libraries' => [],
        'extension' => '.twig',
        'base_theme_extensions' => [],
    ]);
    $this->themeManager
        ->expects($this->once())
        ->method('getActiveTheme')
        ->willReturn($test_theme);
    // Include the module and theme files so that hook_theme can be called.
    include_once $this->root . '/core/modules/system/tests/modules/theme_legacy_test/theme_legacy_test.module';
    $this->moduleHandler
        ->expects($this->once())
        ->method('getImplementations')
        ->with('theme')
        ->will($this->returnValue([
        'theme_legacy_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_function_suggestions', $registry);
    $this->assertArrayHasKey('theme_test_foo', $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_legacy_test', $info['theme path']);
    $this->assertEquals('theme_theme_test_function_suggestions', $info['function']);
    $this->assertEquals([], $info['variables']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.