public function Twig_Tests_Extension_SandboxTest::testSandboxLocallySetForAnInclude in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/twig/twig/test/Twig/Tests/Extension/SandboxTest.php \Twig_Tests_Extension_SandboxTest::testSandboxLocallySetForAnInclude()
File
- vendor/
twig/ twig/ test/ Twig/ Tests/ Extension/ SandboxTest.php, line 141
Class
Code
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, array(), 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, array(), 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) {
}
}