function TwigEnvironmentTest::testTemplateClassname
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Theme/TwigEnvironmentTest.php \Drupal\KernelTests\Core\Theme\TwigEnvironmentTest::testTemplateClassname()
- 10 core/tests/Drupal/KernelTests/Core/Theme/TwigEnvironmentTest.php \Drupal\KernelTests\Core\Theme\TwigEnvironmentTest::testTemplateClassname()
- 11.x core/tests/Drupal/KernelTests/Core/Theme/TwigEnvironmentTest.php \Drupal\KernelTests\Core\Theme\TwigEnvironmentTest::testTemplateClassname()
Ensures that templates resolve to the same class name and cache file.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Theme/ TwigEnvironmentTest.php, line 117
Class
- TwigEnvironmentTest
- Tests the twig environment.
Namespace
Drupal\KernelTests\Core\ThemeCode
public function testTemplateClassname() {
/** @var \Drupal\Core\Template\TwigEnvironment $environment */
$environment = \Drupal::service('twig');
// Test using an include template path.
$name_include = 'container.html.twig';
$class_include = $environment->getTemplateClass($name_include);
$key_include = $environment->getCache()
->generateKey($name_include, $class_include);
// Test using a namespaced template path.
$name_namespaced = '@system/container.html.twig';
$class_namespaced = $environment->getTemplateClass($name_namespaced);
$key_namespaced = $environment->getCache()
->generateKey($name_namespaced, $class_namespaced);
// Test using a direct filesystem template path.
$name_direct = 'core/modules/system/templates/container.html.twig';
$class_direct = $environment->getTemplateClass($name_direct);
$key_direct = $environment->getCache()
->generateKey($name_direct, $class_direct);
// All three should be equal for both cases.
$this->assertEqual($class_include, $class_namespaced);
$this->assertEqual($class_namespaced, $class_direct);
$this->assertEqual($key_include, $key_namespaced);
$this->assertEqual($key_namespaced, $key_direct);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.