コード例 #1
0
 public function testSandboxLocallySetForAnInclude()
 {
     self::$templates = array('2_basic' => '{{ obj.foo }}{% include "2_included" %}{{ obj.foo }}', '2_included' => '{% if obj.foo %}{{ obj.foo|upper }}{% endif %}');
     $twig = $this->getEnvironment(false, self::$templates);
     $this->assertEquals('fooFOOfoo', $twig->loadTemplate('2_basic')->render(self::$params), 'Sandbox does nothing if disabled globally and sandboxed not used for the include');
     self::$templates = array('3_basic' => '{{ obj.foo }}{% sandbox %}{% include "3_included" %}{% endsandbox %}{{ obj.foo }}', '3_included' => '{% if obj.foo %}{{ obj.foo|upper }}{% endif %}');
     $twig = $this->getEnvironment(true, self::$templates);
     try {
         $twig->loadTemplate('3_basic')->render(self::$params);
         $this->fail('Sandbox throws a SecurityError exception when the included file is sandboxed');
     } catch (Twig_Sandbox_SecurityError $e) {
     }
 }
コード例 #2
0
 protected function setUp()
 {
     self::$params = array('name' => 'Fabien', 'obj' => new FooObject(), 'arr' => array('obj' => new FooObject()));
     self::$templates = array('1_basic1' => '{{ obj.foo }}', '1_basic2' => '{{ name|upper }}', '1_basic3' => '{% if name %}foo{% endif %}', '1_basic4' => '{{ obj.bar }}', '1_basic5' => '{{ obj }}', '1_basic6' => '{{ arr.obj }}', '1_basic7' => '{{ cycle(["foo","bar"], 1) }}', '1_basic8' => '{{ obj.getfoobar }}{{ obj.getFooBar }}', '1_basic9' => '{{ obj.foobar }}{{ obj.fooBar }}', '1_basic' => '{% if obj.foo %}{{ obj.foo|upper }}{% endif %}', '1_layout' => '{% block content %}{% endblock %}', '1_child' => "{% extends \"1_layout\" %}\n{% block content %}\n{{ \"a\"|json_encode }}\n{% endblock %}");
 }