diff --git a/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php b/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php index 0bc52d0..f818637 100644 --- a/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php +++ b/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php @@ -120,13 +120,18 @@ public function testCacheFilename() { // Note: Later we refetch the twig service in order to bypass its internal // static cache. $environment = \Drupal::service('twig'); + $template_path = 'core/modules/system/templates/container.html.twig'; - $original_filename = $environment->getCacheFilename('core/modules/system/templates/container.html.twig'); + $cache = $environment->getCache(); + $class = $environment->getTemplateClass($template_path); + $original_filename = $cache->generateKey($template_path, $class); \Drupal::getContainer()->set('twig', NULL); \Drupal::service('module_installer')->install(['twig_extension_test']); $environment = \Drupal::service('twig'); - $new_extension_filename = $environment->getCacheFilename('core/modules/system/templates/container.html.twig'); + $cache = $environment->getCache(); + $class = $environment->getTemplateClass($template_path); + $new_extension_filename = $cache->generateKey($template_path, $class); \Drupal::getContainer()->set('twig', NULL); $this->assertNotEqual($new_extension_filename, $original_filename); diff --git a/core/modules/system/src/Tests/Theme/TwigSettingsTest.php b/core/modules/system/src/Tests/Theme/TwigSettingsTest.php index f581fa62..74a517b 100644 --- a/core/modules/system/src/Tests/Theme/TwigSettingsTest.php +++ b/core/modules/system/src/Tests/Theme/TwigSettingsTest.php @@ -101,7 +101,11 @@ function testTwigCacheOverride() { // theme_test.template_test.html.twig. $info = $templates->get('theme_test_template_test'); $template_filename = $info['path'] . '/' . $info['template'] . $extension; - $cache_filename = $this->container->get('twig')->getCacheFilename($template_filename); + + $environment = $this->container->get('twig'); + $cache = $environment->getCache(); + $class = $environment->getTemplateClass($template_filename); + $cache_filename = $cache->generateKey($template_filename, $class); // Navigate to the page and make sure the template gets cached. $this->drupalGet('theme-test/template-test'); diff --git a/core/modules/system/tests/modules/twig_extension_test/src/TwigExtension/TestExtension.php b/core/modules/system/tests/modules/twig_extension_test/src/TwigExtension/TestExtension.php index 3c2b851..c4c6025 100644 --- a/core/modules/system/tests/modules/twig_extension_test/src/TwigExtension/TestExtension.php +++ b/core/modules/system/tests/modules/twig_extension_test/src/TwigExtension/TestExtension.php @@ -12,7 +12,7 @@ /** * A test Twig extension that adds a custom function and a custom filter. */ -class TestExtension extends TwigExtension { +class TestExtension extends \Twig_Extension { /** * Generates a list of all Twig functions that this extension defines. @@ -27,9 +27,9 @@ class TestExtension extends TwigExtension { * The value is a standard PHP callback that defines what the function does. */ public function getFunctions() { - return array( - 'testfunc' => new \Twig_Function_Function(array('Drupal\twig_extension_test\TwigExtension\TestExtension', 'testFunction')), - ); + return [ + new \Twig_SimpleFunction('testfunc', [$this, 'testFunction']), + ]; } /** @@ -45,9 +45,9 @@ public function getFunctions() { * The value is a standard PHP callback that defines what the filter does. */ public function getFilters() { - return array( - 'testfilter' => new \Twig_Filter_Function(array('Drupal\twig_extension_test\TwigExtension\TestExtension', 'testFilter')), - ); + return [ + new \Twig_SimpleFilter('testfilter', [$this, 'testFilter']), + ]; } /** diff --git a/core/modules/system/tests/modules/twig_extension_test/twig_extension_test.services.yml b/core/modules/system/tests/modules/twig_extension_test/twig_extension_test.services.yml index 491d1e8..8784c0f 100644 --- a/core/modules/system/tests/modules/twig_extension_test/twig_extension_test.services.yml +++ b/core/modules/system/tests/modules/twig_extension_test/twig_extension_test.services.yml @@ -1,6 +1,5 @@ services: twig_extension_test.twig.test_extension: - arguments: ['@renderer'] class: Drupal\twig_extension_test\TwigExtension\TestExtension tags: - { name: twig.extension } diff --git a/core/tests/Drupal/Tests/Core/Template/AttributeTest.php b/core/tests/Drupal/Tests/Core/Template/AttributeTest.php index 69941a9..3f7a5f1 100644 --- a/core/tests/Drupal/Tests/Core/Template/AttributeTest.php +++ b/core/tests/Drupal/Tests/Core/Template/AttributeTest.php @@ -12,6 +12,7 @@ use Drupal\Core\Template\Attribute; use Drupal\Core\Template\AttributeArray; use Drupal\Core\Template\AttributeString; +use Drupal\Core\Template\Loader\StringLoader; use Drupal\Tests\UnitTestCase; use Drupal\Component\Render\MarkupInterface; @@ -268,7 +269,7 @@ public function testChainAddRemoveClasses() { * @covers ::addClass */ public function testTwigAddRemoveClasses($template, $expected, $seed_attributes = array()) { - $loader = new \Twig_Loader_String(); + $loader = new StringLoader(); $twig = new \Twig_Environment($loader); $data = array('attributes' => new Attribute($seed_attributes)); $result = $twig->render($template, $data); diff --git a/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php b/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php index 6b9525e..bb3f4c4 100644 --- a/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php +++ b/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php @@ -5,7 +5,7 @@ * Contains \Drupal\Tests\Core\Template\TwigExtensionTest. */ -namespace Drupal\Tests\Core\Template; +namespace Drupal\Tests\Core\Template { use Drupal\Core\Render\RenderableInterface; use Drupal\Core\Render\RendererInterface; @@ -31,7 +31,8 @@ class TwigExtensionTest extends UnitTestCase { */ public function testEscaping($template, $expected) { $renderer = $this->getMock('\Drupal\Core\Render\RendererInterface'); - $twig = new \Twig_Environment(NULL, array( + $loader = new \Twig_Loader_Filesystem(); + $twig = new \Twig_Environment($loader, array( 'debug' => TRUE, 'cache' => FALSE, 'autoescape' => 'html', @@ -97,7 +98,7 @@ public function testActiveTheme() { ->willReturn($active_theme); $extension->setThemeManager($theme_manager); - $loader = new \Twig_Loader_String(); + $loader = new StringLoader(); $twig = new \Twig_Environment($loader); $twig->addExtension($extension); $result = $twig->render('{{ active_theme() }}'); @@ -145,7 +146,7 @@ public function testActiveThemePath() { ->willReturn($active_theme); $extension->setThemeManager($theme_manager); - $loader = new \Twig_Loader_String(); + $loader = new StringLoader(); $twig = new \Twig_Environment($loader); $twig->addExtension($extension); $result = $twig->render('{{ active_theme_path() }}'); @@ -159,7 +160,8 @@ public function testActiveThemePath() { */ public function testSafeStringEscaping() { $renderer = $this->getMock('\Drupal\Core\Render\RendererInterface'); - $twig = new \Twig_Environment(NULL, array( + $loader = new \Twig_Loader_Filesystem(); + $twig = new \Twig_Environment($loader, array( 'debug' => TRUE, 'cache' => FALSE, 'autoescape' => 'html', @@ -241,3 +243,16 @@ public function __toString() { } } + +} + +namespace { + if (!function_exists('t')) { + function t($string, array $args = []) { + return strtr($string, $args); + } + } + if (!function_exists('file_create_url')) { + function file_create_url() {} + } +}