diff --git a/composer.lock b/composer.lock index ed629ce39a..c7d888c31a 100644 --- a/composer.lock +++ b/composer.lock @@ -2442,16 +2442,16 @@ }, { "name": "twig/twig", - "version": "v2.0.0", + "version": "v2.1.0", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "2a86dde1288d7270169083d0e078dc7ebe0f48b6" + "reference": "9062992538bc5855a683c6737257bfa18d25a4b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/2a86dde1288d7270169083d0e078dc7ebe0f48b6", - "reference": "2a86dde1288d7270169083d0e078dc7ebe0f48b6", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/9062992538bc5855a683c6737257bfa18d25a4b8", + "reference": "9062992538bc5855a683c6737257bfa18d25a4b8", "shasum": "" }, "require": { @@ -2465,7 +2465,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "2.1-dev" } }, "autoload": { @@ -2500,7 +2500,7 @@ "keywords": [ "templating" ], - "time": "2017-01-05 17:12:02" + "time": "2017-01-11 19:39:01" }, { "name": "wikimedia/composer-merge-plugin", diff --git a/core/lib/Drupal/Core/Template/TwigEnvironment.php b/core/lib/Drupal/Core/Template/TwigEnvironment.php index 22c628b8f2..91df9fbafb 100644 --- a/core/lib/Drupal/Core/Template/TwigEnvironment.php +++ b/core/lib/Drupal/Core/Template/TwigEnvironment.php @@ -136,7 +136,7 @@ public function getTemplateClass($name, $index = NULL) { public function renderInline($template_string, array $context = array()) { // Prefix all inline templates with a special comment. $template_string = '{# inline_template_start #}' . $template_string; - return Markup::create($this->loadTemplate($template_string, NULL)->render($context)); + return Markup::create($this->createTemplate($template_string)->render($context)); } } diff --git a/core/tests/Drupal/Tests/Core/Template/AttributeTest.php b/core/tests/Drupal/Tests/Core/Template/AttributeTest.php index 3ffd46da3b..c13f6da8d2 100644 --- a/core/tests/Drupal/Tests/Core/Template/AttributeTest.php +++ b/core/tests/Drupal/Tests/Core/Template/AttributeTest.php @@ -263,10 +263,10 @@ public function testChainAddRemoveClasses() { * @covers ::addClass */ public function testTwigAddRemoveClasses($template, $expected, $seed_attributes = array()) { - $loader = new \Twig_Loader_Array($template); + $loader = new \Twig_Loader_Array([]); $twig = new \Twig_Environment($loader); $data = array('attributes' => new Attribute($seed_attributes)); - $result = $twig->render($template, $data); + $result = $twig->createTemplate($template)->render($data); $this->assertEquals($expected, $result); } @@ -279,7 +279,7 @@ public function testTwigAddRemoveClasses($template, $expected, $seed_attributes */ public function providerTestAttributeClassHelpers() { return array( - array("{{ attributes.class }}", ''), + array("{{ attributes }}", ''), array("{{ attributes.addClass('everest').class }}", 'everest'), array("{{ attributes.addClass(['k2', 'kangchenjunga']).class }}", 'k2 kangchenjunga'), array("{{ attributes.addClass('lhotse', 'makalu', 'cho-oyu').class }}", 'lhotse makalu cho-oyu'), diff --git a/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php b/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php index eb8cfb34b6..30f0cb590a 100644 --- a/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php +++ b/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php @@ -97,7 +97,8 @@ public function testEscaping($template, $expected) { )); $twig->addExtension($this->systemUnderTest); - $nodes = $twig->parse($twig->tokenize($template)); + $name = sprintf('__string_template__%s', hash('sha256', uniqid(mt_rand(), true), false)); + $nodes = $twig->parse($twig->tokenize(new \Twig_Source($template, $name))); $this->assertSame($expected, $nodes->getNode('body') ->getNode(0) @@ -149,10 +150,11 @@ public function testActiveTheme() { ->method('getActiveTheme') ->willReturn($active_theme); - $loader = new \Twig_Loader_Array([]); + $name = sprintf('__string_template__%s', hash('sha256', uniqid(mt_rand(), true), false)); + $loader = new \Twig_Loader_Array([$name => '{{ active_theme() }}']); $twig = new \Twig_Environment($loader); $twig->addExtension($this->systemUnderTest); - $result = $twig->render('{{ active_theme() }}'); + $result = $twig->render($name); $this->assertEquals('test_theme', $result); } @@ -186,10 +188,11 @@ public function testActiveThemePath() { ->method('getActiveTheme') ->willReturn($active_theme); - $loader = new \Twig_Loader_Array([]); + $name = sprintf('__string_template__%s', hash('sha256', uniqid(mt_rand(), true), false)); + $loader = new \Twig_Loader_Array([$name => '{{ active_theme_path() }}']); $twig = new \Twig_Environment($loader); $twig->addExtension($this->systemUnderTest); - $result = $twig->render('{{ active_theme_path() }}'); + $result = $twig->render($name); $this->assertEquals('foo/bar', $result); } @@ -344,7 +347,8 @@ public function testRenderVarWithGeneratedLink() { * @covers ::createAttribute */ public function testCreateAttribute() { - $loader = new \Twig_Loader_Array([]); + $name = sprintf('__string_template__%s', hash('sha256', uniqid(mt_rand(), true), false)); + $loader = new \Twig_Loader_Array([$name => "{% for iteration in iterations %}{% endfor %}"]); $twig = new \Twig_Environment($loader); $twig->addExtension($this->systemUnderTest); @@ -353,12 +357,15 @@ public function testCreateAttribute() { ['id' => 'puppies', 'data-value' => 'foo', 'data-lang' => 'en'], [], ]; - $result = $twig->render("{% for iteration in iterations %}{% endfor %}", ['iterations' => $iterations]); + $result = $twig->render($name, ['iterations' => $iterations]); $expected = '
'; $this->assertEquals($expected, $result); // Test default creation of empty attribute object and using its method. - $result = $twig->render(""); + $name = sprintf('__string_template__%s', hash('sha256', uniqid(mt_rand(), true), false)); + $loader = new \Twig_Loader_Array(array($name => "")); + $twig->setLoader($loader); + $result = $twig->render($name); $expected = '
'; $this->assertEquals($expected, $result); }