From 8f242ca8585e41c297e63b019344a8f1736f88c7 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 3 Apr 2012 09:45:11 +0200 Subject: [PATCH] made usage of mergeContextWithGlobals in macros --- lib/Twig/Node/Macro.php | 2 +- test/Twig/Tests/Fixtures/functions/dump.test | 4 +++- test/Twig/Tests/Fixtures/tags/include/only.test | 8 ++++---- test/Twig/Tests/Node/MacroTest.php | 2 +- test/Twig/Tests/integrationTest.php | 1 + 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/Twig/Node/Macro.php b/lib/Twig/Node/Macro.php index 5db1bf1..11f388b 100644 --- a/lib/Twig/Node/Macro.php +++ b/lib/Twig/Node/Macro.php @@ -44,7 +44,7 @@ class Twig_Node_Macro extends Twig_Node $compiler->write("\$context = \$this->env->getGlobals();\n\n"); } else { $compiler - ->write("\$context = array_merge(\$this->env->getGlobals(), array(\n") + ->write("\$context = \$this->mergeContextWithGlobals(array(\n") ->indent() ; diff --git a/test/Twig/Tests/Fixtures/functions/dump.test b/test/Twig/Tests/Fixtures/functions/dump.test index 1b3c453..cf6acf8 100644 --- a/test/Twig/Tests/Fixtures/functions/dump.test +++ b/test/Twig/Tests/Fixtures/functions/dump.test @@ -9,11 +9,13 @@ return array('foo' => 'foo', 'bar' => 'bar') --CONFIG-- return array('debug' => true, 'autoescape' => false); --EXPECT-- -array(2) { +array(3) { ["foo"]=> string(3) "foo" ["bar"]=> string(3) "bar" + ["global"]=> + string(6) "global" } string(3) "foo" diff --git a/test/Twig/Tests/Fixtures/tags/include/only.test b/test/Twig/Tests/Fixtures/tags/include/only.test index 22e3d0f..77760a0 100644 --- a/test/Twig/Tests/Fixtures/tags/include/only.test +++ b/test/Twig/Tests/Fixtures/tags/include/only.test @@ -10,7 +10,7 @@ --DATA-- return array('foo' => 'bar') --EXPECT-- -foo,_parent, -_parent, -foo,foo1,_parent, -foo1,_parent, +foo,global,_parent, +global,_parent, +foo,global,foo1,_parent, +foo1,global,_parent, diff --git a/test/Twig/Tests/Node/MacroTest.php b/test/Twig/Tests/Node/MacroTest.php index ddb67d1..f61c698 100644 --- a/test/Twig/Tests/Node/MacroTest.php +++ b/test/Twig/Tests/Node/MacroTest.php @@ -46,7 +46,7 @@ class Twig_Tests_Node_MacroTest extends Twig_Tests_Node_TestCase array($node, <<env->getGlobals(), array( + \$context = \$this->mergeContextWithGlobals(array( "foo" => \$foo, )); diff --git a/test/Twig/Tests/integrationTest.php b/test/Twig/Tests/integrationTest.php index cb60a82..866e86c 100644 --- a/test/Twig/Tests/integrationTest.php +++ b/test/Twig/Tests/integrationTest.php @@ -70,6 +70,7 @@ class Twig_Tests_IntegrationTest extends PHPUnit_Framework_TestCase $twig->addExtension(new Twig_Extension_Debug()); $policy = new Twig_Sandbox_SecurityPolicy(array(), array(), array(), array(), array()); $twig->addExtension(new Twig_Extension_Sandbox($policy, false)); + $twig->addGlobal('global', 'global'); try { $template = $twig->loadTemplate('index.twig'); -- 1.7.2.5