|
| setUp () |
|
| getEnvironment ($sandboxed, $options, $templates, $tags=array(), $filters=array(), $methods=array(), $properties=array(), $functions=array()) |
|
Definition at line 12 of file SandboxTest.php.
◆ getEnvironment()
Twig_Tests_Extension_SandboxTest::getEnvironment |
( |
|
$sandboxed, |
|
|
|
$options, |
|
|
|
$templates, |
|
|
|
$tags = array() , |
|
|
|
$filters = array() , |
|
|
|
$methods = array() , |
|
|
|
$properties = array() , |
|
|
|
$functions = array() |
|
) |
| |
|
protected |
Definition at line 281 of file SandboxTest.php.
References PHPMailer\PHPMailer\$options, $tags, and $templates.
Referenced by testMacrosInASandbox(), testSandboxAllowFilter(), testSandboxAllowFunction(), testSandboxAllowFunctionsCaseInsensitive(), testSandboxAllowMethodFoo(), testSandboxAllowMethodToString(), testSandboxAllowMethodToStringDisabled(), testSandboxAllowProperty(), testSandboxAllowRangeOperator(), testSandboxAllowTag(), testSandboxDisabledAfterIncludeFunctionError(), testSandboxGloballySet(), testSandboxLocallySetForAnInclude(), testSandboxUnallowedFilter(), testSandboxUnallowedFunction(), testSandboxUnallowedMethodAccessor(), testSandboxUnallowedProperty(), testSandboxUnallowedRangeOperator(), testSandboxUnallowedTag(), testSandboxUnallowedToString(), testSandboxUnallowedToStringArray(), and testSandboxWithInheritance().
284 $twig =
new Twig_Environment($loader, array_merge(array(
'debug' =>
true,
'cache' =>
false,
'autoescape' =>
false),
$options));
Represents a security policy which need to be enforced when sandbox mode is enabled.
Stores the Twig configuration.
Loads a template from an array.
◆ setUp()
Twig_Tests_Extension_SandboxTest::setUp |
( |
| ) |
|
|
protected |
Definition at line 17 of file SandboxTest.php.
References PHPMailer\PHPMailer\$params.
25 self::$templates = array(
26 '1_basic1' =>
'{{ obj.foo }}',
27 '1_basic2' =>
'{{ name|upper }}',
28 '1_basic3' =>
'{% if name %}foo{% endif %}',
29 '1_basic4' =>
'{{ obj.bar }}',
30 '1_basic5' =>
'{{ obj }}',
31 '1_basic6' =>
'{{ arr.obj }}',
32 '1_basic7' =>
'{{ cycle(["foo","bar"], 1) }}',
33 '1_basic8' =>
'{{ obj.getfoobar }}{{ obj.getFooBar }}',
34 '1_basic9' =>
'{{ obj.foobar }}{{ obj.fooBar }}',
35 '1_basic' =>
'{% if obj.foo %}{{ obj.foo|upper }}{% endif %}',
36 '1_layout' =>
'{% block content %}{% endblock %}',
37 '1_child' =>
"{% extends \"1_layout\" %}\n{% block content %}\n{{ \"a\"|json_encode }}\n{% endblock %}",
38 '1_include' =>
'{{ include("1_basic1", sandboxed=true) }}',
39 '1_range_operator' =>
'{{ (1..2)[0] }}',
◆ testMacrosInASandbox()
Twig_Tests_Extension_SandboxTest::testMacrosInASandbox |
( |
| ) |
|
Definition at line 250 of file SandboxTest.php.
References EOF, getEnvironment(), and test().
252 $twig = $this->
getEnvironment(
true, array(
'autoescape' =>
'html'), array(
'index' => <<<
EOF 253 {%-
import _self as macros %}
255 {%- macro
test(text) %}<
p>{{ text }}</
p>{% endmacro %}
257 {{- macros.test(
'username') }}
259 ), array(
'macro',
'import'), array(
'escape'));
261 $this->assertEquals(
'<p>username</p>', $twig->loadTemplate(
'index')->render(array()));
getEnvironment($sandboxed, $options, $templates, $tags=array(), $filters=array(), $methods=array(), $properties=array(), $functions=array())
const EOF
How fgetc() reports an End Of File.
◆ testSandboxAllowFilter()
Twig_Tests_Extension_SandboxTest::testSandboxAllowFilter |
( |
| ) |
|
Definition at line 183 of file SandboxTest.php.
References PHPMailer\PHPMailer\$params, and getEnvironment().
185 $twig = $this->
getEnvironment(
true, array(), self::$templates, array(), array(
'upper'));
186 $this->assertEquals(
'FABIEN', $twig->loadTemplate(
'1_basic2')->render(
self::$params),
'Sandbox allow some filters');
getEnvironment($sandboxed, $options, $templates, $tags=array(), $filters=array(), $methods=array(), $properties=array(), $functions=array())
◆ testSandboxAllowFunction()
Twig_Tests_Extension_SandboxTest::testSandboxAllowFunction |
( |
| ) |
|
Definition at line 201 of file SandboxTest.php.
References PHPMailer\PHPMailer\$params, and getEnvironment().
203 $twig = $this->
getEnvironment(
true, array(), self::$templates, array(), array(), array(), array(), array(
'cycle'));
204 $this->assertEquals(
'bar', $twig->loadTemplate(
'1_basic7')->render(
self::$params),
'Sandbox allow some functions');
getEnvironment($sandboxed, $options, $templates, $tags=array(), $filters=array(), $methods=array(), $properties=array(), $functions=array())
◆ testSandboxAllowFunctionsCaseInsensitive()
Twig_Tests_Extension_SandboxTest::testSandboxAllowFunctionsCaseInsensitive |
( |
| ) |
|
Definition at line 213 of file SandboxTest.php.
References FooObject\$called, $name, PHPMailer\PHPMailer\$params, getEnvironment(), and FooObject\reset().
215 foreach (array(
'getfoobar',
'getFoobar',
'getFooBar') as
$name) {
216 $twig = $this->
getEnvironment(
true, array(), self::$templates, array(), array(), array(
'FooObject' => $name));
218 $this->assertEquals(
'foobarfoobar', $twig->loadTemplate(
'1_basic8')->render(
self::$params),
'Sandbox allow methods in a case-insensitive way');
219 $this->assertEquals(2,
FooObject::$called[
'getFooBar'],
'Sandbox only calls method once');
221 $this->assertEquals(
'foobarfoobar', $twig->loadTemplate(
'1_basic9')->render(
self::$params),
'Sandbox allow methods via shortcut names (ie. without get/set)');
getEnvironment($sandboxed, $options, $templates, $tags=array(), $filters=array(), $methods=array(), $properties=array(), $functions=array())
◆ testSandboxAllowMethodFoo()
Twig_Tests_Extension_SandboxTest::testSandboxAllowMethodFoo |
( |
| ) |
|
Definition at line 159 of file SandboxTest.php.
References FooObject\$called, PHPMailer\PHPMailer\$params, getEnvironment(), and FooObject\reset().
161 $twig = $this->
getEnvironment(
true, array(), self::$templates, array(), array(), array(
'FooObject' =>
'foo'));
163 $this->assertEquals(
'foo', $twig->loadTemplate(
'1_basic1')->render(
self::$params),
'Sandbox allow some methods');
getEnvironment($sandboxed, $options, $templates, $tags=array(), $filters=array(), $methods=array(), $properties=array(), $functions=array())
◆ testSandboxAllowMethodToString()
Twig_Tests_Extension_SandboxTest::testSandboxAllowMethodToString |
( |
| ) |
|
Definition at line 167 of file SandboxTest.php.
References FooObject\$called, PHPMailer\PHPMailer\$params, getEnvironment(), and FooObject\reset().
169 $twig = $this->
getEnvironment(
true, array(), self::$templates, array(), array(), array(
'FooObject' =>
'__toString'));
171 $this->assertEquals(
'foo', $twig->loadTemplate(
'1_basic5')->render(
self::$params),
'Sandbox allow some methods');
172 $this->assertEquals(1,
FooObject::$called[
'__toString'],
'Sandbox only calls method once');
getEnvironment($sandboxed, $options, $templates, $tags=array(), $filters=array(), $methods=array(), $properties=array(), $functions=array())
◆ testSandboxAllowMethodToStringDisabled()
Twig_Tests_Extension_SandboxTest::testSandboxAllowMethodToStringDisabled |
( |
| ) |
|
Definition at line 175 of file SandboxTest.php.
References FooObject\$called, PHPMailer\PHPMailer\$params, getEnvironment(), and FooObject\reset().
179 $this->assertEquals(
'foo', $twig->loadTemplate(
'1_basic5')->render(
self::$params),
'Sandbox allows __toString when sandbox disabled');
180 $this->assertEquals(1,
FooObject::$called[
'__toString'],
'Sandbox only calls method once');
getEnvironment($sandboxed, $options, $templates, $tags=array(), $filters=array(), $methods=array(), $properties=array(), $functions=array())
◆ testSandboxAllowProperty()
Twig_Tests_Extension_SandboxTest::testSandboxAllowProperty |
( |
| ) |
|
Definition at line 195 of file SandboxTest.php.
References PHPMailer\PHPMailer\$params, and getEnvironment().
197 $twig = $this->
getEnvironment(
true, array(), self::$templates, array(), array(), array(), array(
'FooObject' =>
'bar'));
198 $this->assertEquals(
'bar', $twig->loadTemplate(
'1_basic4')->render(
self::$params),
'Sandbox allow some properties');
getEnvironment($sandboxed, $options, $templates, $tags=array(), $filters=array(), $methods=array(), $properties=array(), $functions=array())
◆ testSandboxAllowRangeOperator()
Twig_Tests_Extension_SandboxTest::testSandboxAllowRangeOperator |
( |
| ) |
|
Definition at line 207 of file SandboxTest.php.
References PHPMailer\PHPMailer\$params, and getEnvironment().
209 $twig = $this->
getEnvironment(
true, array(), self::$templates, array(), array(), array(), array(), array(
'range'));
210 $this->assertEquals(
'1', $twig->loadTemplate(
'1_range_operator')->render(
self::$params),
'Sandbox allow the range operator');
getEnvironment($sandboxed, $options, $templates, $tags=array(), $filters=array(), $methods=array(), $properties=array(), $functions=array())
◆ testSandboxAllowTag()
Twig_Tests_Extension_SandboxTest::testSandboxAllowTag |
( |
| ) |
|
Definition at line 189 of file SandboxTest.php.
References PHPMailer\PHPMailer\$params, and getEnvironment().
191 $twig = $this->
getEnvironment(
true, array(), self::$templates, array(
'if'));
192 $this->assertEquals(
'foo', $twig->loadTemplate(
'1_basic3')->render(
self::$params),
'Sandbox allow some tags');
getEnvironment($sandboxed, $options, $templates, $tags=array(), $filters=array(), $methods=array(), $properties=array(), $functions=array())
◆ testSandboxDisabledAfterIncludeFunctionError()
Twig_Tests_Extension_SandboxTest::testSandboxDisabledAfterIncludeFunctionError |
( |
| ) |
|
Definition at line 264 of file SandboxTest.php.
References PHPMailer\PHPMailer\$params, and getEnvironment().
275 $this->fail(
'An exception should be thrown for this test to be valid.');
278 $this->assertFalse($twig->getExtension(
'Twig_Extension_Sandbox')->isSandboxed(),
'Sandboxed include() function call should not leave Sandbox enabled when an error occurs.');
getEnvironment($sandboxed, $options, $templates, $tags=array(), $filters=array(), $methods=array(), $properties=array(), $functions=array())
◆ testSandboxGloballySet()
Twig_Tests_Extension_SandboxTest::testSandboxGloballySet |
( |
| ) |
|
Definition at line 53 of file SandboxTest.php.
References PHPMailer\PHPMailer\$params, and getEnvironment().
56 $this->assertEquals(
'FOO', $twig->loadTemplate(
'1_basic')->render(
self::$params),
'Sandbox does nothing if it is disabled globally');
getEnvironment($sandboxed, $options, $templates, $tags=array(), $filters=array(), $methods=array(), $properties=array(), $functions=array())
◆ testSandboxLocallySetForAnInclude()
Twig_Tests_Extension_SandboxTest::testSandboxLocallySetForAnInclude |
( |
| ) |
|
Definition at line 225 of file SandboxTest.php.
References PHPMailer\PHPMailer\$params, and getEnvironment().
227 self::$templates = array(
228 '2_basic' =>
'{{ obj.foo }}{% include "2_included" %}{{ obj.foo }}',
229 '2_included' =>
'{% if obj.foo %}{{ obj.foo|upper }}{% endif %}',
233 $this->assertEquals(
'fooFOOfoo', $twig->loadTemplate(
'2_basic')->render(
self::$params),
'Sandbox does nothing if disabled globally and sandboxed not used for the include');
235 self::$templates = array(
236 '3_basic' =>
'{{ obj.foo }}{% sandbox %}{% include "3_included" %}{% endsandbox %}{{ obj.foo }}',
237 '3_included' =>
'{% if obj.foo %}{{ obj.foo|upper }}{% endif %}',
243 $this->fail(
'Sandbox throws a SecurityError exception when the included file is sandboxed');
245 $this->assertInstanceOf(
'Twig_Sandbox_SecurityNotAllowedTagError', $e,
'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedTagError');
246 $this->assertEquals(
'sandbox', $e->getTagName());
Exception thrown when a security error occurs at runtime.
getEnvironment($sandboxed, $options, $templates, $tags=array(), $filters=array(), $methods=array(), $properties=array(), $functions=array())
◆ testSandboxUnallowedFilter()
Twig_Tests_Extension_SandboxTest::testSandboxUnallowedFilter |
( |
| ) |
|
Definition at line 72 of file SandboxTest.php.
References PHPMailer\PHPMailer\$params, and getEnvironment().
77 $this->fail(
'Sandbox throws a SecurityError exception if an unallowed filter is called');
79 $this->assertInstanceOf(
'Twig_Sandbox_SecurityNotAllowedFilterError', $e,
'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFilterError');
80 $this->assertEquals(
'upper', $e->getFilterName(),
'Exception should be raised on the "upper" filter');
Exception thrown when a security error occurs at runtime.
getEnvironment($sandboxed, $options, $templates, $tags=array(), $filters=array(), $methods=array(), $properties=array(), $functions=array())
◆ testSandboxUnallowedFunction()
Twig_Tests_Extension_SandboxTest::testSandboxUnallowedFunction |
( |
| ) |
|
Definition at line 135 of file SandboxTest.php.
References PHPMailer\PHPMailer\$params, and getEnvironment().
140 $this->fail(
'Sandbox throws a SecurityError exception if an unallowed function is called in the template');
142 $this->assertInstanceOf(
'Twig_Sandbox_SecurityNotAllowedFunctionError', $e,
'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFunctionError');
143 $this->assertEquals(
'cycle', $e->getFunctionName(),
'Exception should be raised on the "cycle" function');
Exception thrown when a security error occurs at runtime.
getEnvironment($sandboxed, $options, $templates, $tags=array(), $filters=array(), $methods=array(), $properties=array(), $functions=array())
◆ testSandboxUnallowedMethodAccessor()
Twig_Tests_Extension_SandboxTest::testSandboxUnallowedMethodAccessor |
( |
| ) |
|
Definition at line 59 of file SandboxTest.php.
References PHPMailer\PHPMailer\$params, and getEnvironment().
64 $this->fail(
'Sandbox throws a SecurityError exception if an unallowed method is called');
66 $this->assertInstanceOf(
'Twig_Sandbox_SecurityNotAllowedMethodError', $e,
'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError');
67 $this->assertEquals(
'FooObject', $e->getClassName(),
'Exception should be raised on the "FooObject" class');
68 $this->assertEquals(
'foo', $e->getMethodName(),
'Exception should be raised on the "foo" method');
Exception thrown when a security error occurs at runtime.
getEnvironment($sandboxed, $options, $templates, $tags=array(), $filters=array(), $methods=array(), $properties=array(), $functions=array())
◆ testSandboxUnallowedProperty()
Twig_Tests_Extension_SandboxTest::testSandboxUnallowedProperty |
( |
| ) |
|
Definition at line 96 of file SandboxTest.php.
References PHPMailer\PHPMailer\$params, and getEnvironment().
101 $this->fail(
'Sandbox throws a SecurityError exception if an unallowed property is called in the template');
103 $this->assertInstanceOf(
'Twig_Sandbox_SecurityNotAllowedPropertyError', $e,
'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedPropertyError');
104 $this->assertEquals(
'FooObject', $e->getClassName(),
'Exception should be raised on the "FooObject" class');
105 $this->assertEquals(
'bar', $e->getPropertyName(),
'Exception should be raised on the "bar" property');
Exception thrown when a security error occurs at runtime.
getEnvironment($sandboxed, $options, $templates, $tags=array(), $filters=array(), $methods=array(), $properties=array(), $functions=array())
◆ testSandboxUnallowedRangeOperator()
Twig_Tests_Extension_SandboxTest::testSandboxUnallowedRangeOperator |
( |
| ) |
|
Definition at line 147 of file SandboxTest.php.
References PHPMailer\PHPMailer\$params, and getEnvironment().
151 $twig->loadTemplate(
'1_range_operator')->render(
self::$params);
152 $this->fail(
'Sandbox throws a SecurityError exception if the unallowed range operator is called');
154 $this->assertInstanceOf(
'Twig_Sandbox_SecurityNotAllowedFunctionError', $e,
'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFunctionError');
155 $this->assertEquals(
'range', $e->getFunctionName(),
'Exception should be raised on the "range" function');
Exception thrown when a security error occurs at runtime.
getEnvironment($sandboxed, $options, $templates, $tags=array(), $filters=array(), $methods=array(), $properties=array(), $functions=array())
◆ testSandboxUnallowedTag()
Twig_Tests_Extension_SandboxTest::testSandboxUnallowedTag |
( |
| ) |
|
Definition at line 84 of file SandboxTest.php.
References PHPMailer\PHPMailer\$params, and getEnvironment().
89 $this->fail(
'Sandbox throws a SecurityError exception if an unallowed tag is used in the template');
91 $this->assertInstanceOf(
'Twig_Sandbox_SecurityNotAllowedTagError', $e,
'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedTagError');
92 $this->assertEquals(
'if', $e->getTagName(),
'Exception should be raised on the "if" tag');
Exception thrown when a security error occurs at runtime.
getEnvironment($sandboxed, $options, $templates, $tags=array(), $filters=array(), $methods=array(), $properties=array(), $functions=array())
◆ testSandboxUnallowedToString()
Twig_Tests_Extension_SandboxTest::testSandboxUnallowedToString |
( |
| ) |
|
Definition at line 109 of file SandboxTest.php.
References PHPMailer\PHPMailer\$params, and getEnvironment().
114 $this->fail(
'Sandbox throws a SecurityError exception if an unallowed method (__toString()) is called in the template');
116 $this->assertInstanceOf(
'Twig_Sandbox_SecurityNotAllowedMethodError', $e,
'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError');
117 $this->assertEquals(
'FooObject', $e->getClassName(),
'Exception should be raised on the "FooObject" class');
118 $this->assertEquals(
'__tostring', $e->getMethodName(),
'Exception should be raised on the "__toString" method');
Exception thrown when a security error occurs at runtime.
getEnvironment($sandboxed, $options, $templates, $tags=array(), $filters=array(), $methods=array(), $properties=array(), $functions=array())
◆ testSandboxUnallowedToStringArray()
Twig_Tests_Extension_SandboxTest::testSandboxUnallowedToStringArray |
( |
| ) |
|
Definition at line 122 of file SandboxTest.php.
References PHPMailer\PHPMailer\$params, and getEnvironment().
127 $this->fail(
'Sandbox throws a SecurityError exception if an unallowed method (__toString()) is called in the template');
129 $this->assertInstanceOf(
'Twig_Sandbox_SecurityNotAllowedMethodError', $e,
'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError');
130 $this->assertEquals(
'FooObject', $e->getClassName(),
'Exception should be raised on the "FooObject" class');
131 $this->assertEquals(
'__tostring', $e->getMethodName(),
'Exception should be raised on the "__toString" method');
Exception thrown when a security error occurs at runtime.
getEnvironment($sandboxed, $options, $templates, $tags=array(), $filters=array(), $methods=array(), $properties=array(), $functions=array())
◆ testSandboxWithInheritance()
Twig_Tests_Extension_SandboxTest::testSandboxWithInheritance |
( |
| ) |
|
Twig_Sandbox_SecurityError Filter "json_encode" is not allowed in "1_child" at line 3.
Definition at line 47 of file SandboxTest.php.
References getEnvironment().
49 $twig = $this->
getEnvironment(
true, array(), self::$templates, array(
'block'));
50 $twig->loadTemplate(
'1_child')->render(array());
getEnvironment($sandboxed, $options, $templates, $tags=array(), $filters=array(), $methods=array(), $properties=array(), $functions=array())
◆ $params
Twig_Tests_Extension_SandboxTest::$params |
|
staticprotected |
◆ $templates
Twig_Tests_Extension_SandboxTest::$templates |
|
staticprotected |
The documentation for this class was generated from the following file: