diff --git a/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php b/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php new file mode 100644 index 0000000..827bf65 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Template/TwigSandboxTest.php @@ -0,0 +1,60 @@ +addExtension($sandbox); + + $entity = $this->getMock('Drupal\Core\Entity\EntityInterface'); + + $catched = FALSE; + try { + $twig->render('{{ entity.delete }}', ['entity' => $entity]); + } catch (\Twig_Sandbox_SecurityError $e) { + $catched = TRUE; + } + $this->assertTrue($catched, '\Twig_sandbox_security exception was thrown when entity was tried to be removed.'); + + $catched = FALSE; + try { + $twig->render('{{ entity.save }}', ['entity' => $entity]); + } catch (\Twig_Sandbox_SecurityError $e) { + $catched = TRUE; + } + $this->assertTrue($catched, '\Twig_sandbox_security exception was thrown when entity was tried to be saved.'); + + $catched = FALSE; + try { + $twig->render('{{ entity.create }}', ['entity' => $entity]); + } catch (\Twig_Sandbox_SecurityError $e) { + $catched = TRUE; + } + $this->assertTrue($catched, '\Twig_sandbox_security exception was thrown when new entity was tried to be created.'); + + } + +}