diff --git a/core/tests/Drupal/KernelTests/Core/Theme/TwigEnvironmentTest.php b/core/tests/Drupal/KernelTests/Core/Theme/TwigEnvironmentTest.php index c3e7af6..12bfd73 100644 --- a/core/tests/Drupal/KernelTests/Core/Theme/TwigEnvironmentTest.php +++ b/core/tests/Drupal/KernelTests/Core/Theme/TwigEnvironmentTest.php @@ -116,6 +116,20 @@ public function testCacheFilename() { // static cache. $environment = \Drupal::service('twig'); + // A template basename greater than the constant + // TwigPhpStorageCache::SUFFIX_SUBSTRING_LENGTH should get truncated. + $cache = $environment->getCache(); + $long_name = 'core/modules/system/templates/block--system-messages-block.html.twig'; + $this->assertGreaterThan(TwigPhpStorageCache::SUFFIX_SUBSTRING_LENGTH, strlen(basename($long_name))); + $class = $environment->getTemplateClass($long_name); + $key = $cache->generateKey($long_name, $class); + $prefix = $environment->getTwigCachePrefix(); + // The key should consist of the prefix, an underscore, and two strings + // each truncated to length TwigPhpStorageCache::SUFFIX_SUBSTRING_LENGTH + // separated by an underscore. + $expected = strlen($prefix) + 2 + 2 * TwigPhpStorageCache::SUFFIX_SUBSTRING_LENGTH; + $this->assertEquals($expected, strlen($key)); + $original_filename = $environment->getCacheFilename('core/modules/system/templates/container.html.twig'); \Drupal::getContainer()->set('twig', NULL);