You are here

public function Twig_Tests_TemplateTest::testGetAttributeWithSandbox in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/twig/twig/test/Twig/Tests/TemplateTest.php \Twig_Tests_TemplateTest::testGetAttributeWithSandbox()

@dataProvider getGetAttributeWithSandbox

File

vendor/twig/twig/test/Twig/Tests/TemplateTest.php, line 97

Class

Twig_Tests_TemplateTest

Code

public function testGetAttributeWithSandbox($object, $item, $allowed, $useExt) {
  $twig = new Twig_Environment($this
    ->getMock('Twig_LoaderInterface'));
  $policy = new Twig_Sandbox_SecurityPolicy(array(), array(), array(), array(), array());
  $twig
    ->addExtension(new Twig_Extension_Sandbox($policy, !$allowed));
  $template = new Twig_TemplateTest($twig, $useExt);
  try {
    $template
      ->getAttribute($object, $item, array(), 'any');
    if (!$allowed) {
      $this
        ->fail();
    }
  } catch (Twig_Sandbox_SecurityError $e) {
    if ($allowed) {
      $this
        ->fail();
    }
    $this
      ->assertContains('is not allowed', $e
      ->getMessage());
  }
}