X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=vendor%2Ftwig%2Ftwig%2Ftest%2FTwig%2FTests%2FExtension%2FSandboxTest.php;h=e268115c24a64584ff586ab4639524d03e35339e;hb=5e458ff8cb4924fd5fa03b80d8edfcc52fe43479;hp=0b2158269f2774c2ca432585d70cfe867db3f977;hpb=eba34333e3c89f208d2f72fa91351ad019a71583;p=yaffs-website diff --git a/vendor/twig/twig/test/Twig/Tests/Extension/SandboxTest.php b/vendor/twig/twig/test/Twig/Tests/Extension/SandboxTest.php index 0b2158269..e268115c2 100644 --- a/vendor/twig/twig/test/Twig/Tests/Extension/SandboxTest.php +++ b/vendor/twig/twig/test/Twig/Tests/Extension/SandboxTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -class Twig_Tests_Extension_SandboxTest extends PHPUnit_Framework_TestCase +class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase { protected static $params; protected static $templates; @@ -36,6 +36,7 @@ class Twig_Tests_Extension_SandboxTest extends PHPUnit_Framework_TestCase '1_layout' => '{% block content %}{% endblock %}', '1_child' => "{% extends \"1_layout\" %}\n{% block content %}\n{{ \"a\"|json_encode }}\n{% endblock %}", '1_include' => '{{ include("1_basic1", sandboxed=true) }}', + '1_range_operator' => '{{ (1..2)[0] }}', ); } @@ -143,6 +144,18 @@ class Twig_Tests_Extension_SandboxTest extends PHPUnit_Framework_TestCase } } + public function testSandboxUnallowedRangeOperator() + { + $twig = $this->getEnvironment(true, array(), self::$templates); + try { + $twig->loadTemplate('1_range_operator')->render(self::$params); + $this->fail('Sandbox throws a SecurityError exception if the unallowed range operator is called'); + } catch (Twig_Sandbox_SecurityError $e) { + $this->assertInstanceOf('Twig_Sandbox_SecurityNotAllowedFunctionError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFunctionError'); + $this->assertEquals('range', $e->getFunctionName(), 'Exception should be raised on the "range" function'); + } + } + public function testSandboxAllowMethodFoo() { $twig = $this->getEnvironment(true, array(), self::$templates, array(), array(), array('FooObject' => 'foo')); @@ -191,6 +204,12 @@ class Twig_Tests_Extension_SandboxTest extends PHPUnit_Framework_TestCase $this->assertEquals('bar', $twig->loadTemplate('1_basic7')->render(self::$params), 'Sandbox allow some functions'); } + public function testSandboxAllowRangeOperator() + { + $twig = $this->getEnvironment(true, array(), self::$templates, array(), array(), array(), array(), array('range')); + $this->assertEquals('1', $twig->loadTemplate('1_range_operator')->render(self::$params), 'Sandbox allow the range operator'); + } + public function testSandboxAllowFunctionsCaseInsensitive() { foreach (array('getfoobar', 'getFoobar', 'getFooBar') as $name) { @@ -252,7 +271,7 @@ EOF } catch (Throwable $e) { } catch (Exception $e) { } - if ($e === null) { + if (null === $e) { $this->fail('An exception should be thrown for this test to be valid.'); }