function RegistryTest::testSuggestionPreprocessFunctions
Same name in other branches
- 8.9.x core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php \Drupal\KernelTests\Core\Theme\RegistryTest::testSuggestionPreprocessFunctions()
- 10 core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php \Drupal\KernelTests\Core\Theme\RegistryTest::testSuggestionPreprocessFunctions()
- 11.x core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php \Drupal\KernelTests\Core\Theme\RegistryTest::testSuggestionPreprocessFunctions()
Tests the theme registry with suggestions.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Theme/ RegistryTest.php, line 109
Class
- RegistryTest
- Tests the behavior of the ThemeRegistry class.
Namespace
Drupal\KernelTests\Core\ThemeCode
public function testSuggestionPreprocessFunctions() {
$theme_handler = \Drupal::service('theme_handler');
\Drupal::service('theme_installer')->install([
'test_theme',
]);
$extension_list = $this->container
->get('extension.list.module');
assert($extension_list instanceof ModuleExtensionList);
$registry_theme = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), \Drupal::service('cache.bootstrap'), $extension_list, 'test_theme');
$registry_theme->setThemeManager(\Drupal::theme());
$suggestions = [
'__kitten',
'__flamingo',
];
$expected_preprocess_functions = [
'template_preprocess',
'theme_test_preprocess_theme_test_preprocess_suggestions',
];
$suggestion = '';
$hook = 'theme_test_preprocess_suggestions';
do {
$hook .= "{$suggestion}";
$expected_preprocess_functions[] = "test_theme_preprocess_{$hook}";
$preprocess_functions = $registry_theme->get()[$hook]['preprocess functions'];
$this->assertSame($expected_preprocess_functions, $preprocess_functions, "{$hook} has correct preprocess functions.");
} while ($suggestion = array_shift($suggestions));
$expected_preprocess_functions = [
'template_preprocess',
'theme_test_preprocess_theme_test_preprocess_suggestions',
'test_theme_preprocess_theme_test_preprocess_suggestions',
'test_theme_preprocess_theme_test_preprocess_suggestions__kitten',
];
$preprocess_functions = $registry_theme->get()['theme_test_preprocess_suggestions__kitten__bearcat']['preprocess functions'];
$this->assertSame($expected_preprocess_functions, $preprocess_functions, 'Suggestion implemented as a template correctly inherits preprocess functions.');
$this->assertTrue(isset($registry_theme->get()['theme_test_preprocess_suggestions__kitten__meerkat__tarsier__moose']), 'Preprocess function with an unimplemented lower-level suggestion is added to the registry.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.