ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Twig_Tests_ExpressionParserTest Class Reference
+ Inheritance diagram for Twig_Tests_ExpressionParserTest:
+ Collaboration diagram for Twig_Tests_ExpressionParserTest:

Public Member Functions

 testCanOnlyAssignToNames ($template)
 @expectedException Twig_Error_Syntax @dataProvider getFailingTestsForAssignment More...
 
 getFailingTestsForAssignment ()
 
 testArrayExpression ($template, $expected)
 @dataProvider getTestsForArray More...
 
 testArraySyntaxError ($template)
 @expectedException Twig_Error_Syntax @dataProvider getFailingTestsForArray More...
 
 getFailingTestsForArray ()
 
 getTestsForArray ()
 
 testStringExpressionDoesNotConcatenateTwoConsecutiveStrings ()
 @expectedException Twig_Error_Syntax More...
 
 testStringExpression ($template, $expected)
 @dataProvider getTestsForString More...
 
 getTestsForString ()
 
 testAttributeCallDoesNotSupportNamedArguments ()
 @expectedException Twig_Error_Syntax More...
 
 testMacroCallDoesNotSupportNamedArguments ()
 @expectedException Twig_Error_Syntax More...
 
 testMacroDefinitionDoesNotSupportNonNameVariableName ()
 @expectedException Twig_Error_Syntax @expectedExceptionMessage An argument must be a name. More...
 
 testMacroDefinitionDoesNotSupportNonConstantDefaultValues ($template)
 @expectedException Twig_Error_Syntax @expectedExceptionMessage A default value for an argument must be a constant (a boolean, a string, a number, or an array) in "index" at line 1 @dataProvider getMacroDefinitionDoesNotSupportNonConstantDefaultValues More...
 
 getMacroDefinitionDoesNotSupportNonConstantDefaultValues ()
 
 testMacroDefinitionSupportsConstantDefaultValues ($template)
 @dataProvider getMacroDefinitionSupportsConstantDefaultValues More...
 
 getMacroDefinitionSupportsConstantDefaultValues ()
 
 testUnknownFunction ()
 @expectedException Twig_Error_Syntax @expectedExceptionMessage Unknown "cycl" function. More...
 
 testUnknownFunctionWithoutSuggestions ()
 @expectedException Twig_Error_Syntax @expectedExceptionMessage Unknown "foobar" function in "index" at line 1. More...
 
 testUnknownFilter ()
 @expectedException Twig_Error_Syntax @expectedExceptionMessage Unknown "lowe" filter. More...
 
 testUnknownFilterWithoutSuggestions ()
 @expectedException Twig_Error_Syntax @expectedExceptionMessage Unknown "foobar" filter in "index" at line 1. More...
 
 testUnknownTest ()
 @expectedException Twig_Error_Syntax @expectedExceptionMessage Unknown "nul" test. More...
 
 testUnknownTestWithoutSuggestions ()
 @expectedException Twig_Error_Syntax @expectedExceptionMessage Unknown "foobar" test in "index" at line 1. More...
 

Detailed Description

Definition at line 12 of file ExpressionParserTest.php.

Member Function Documentation

◆ getFailingTestsForArray()

Twig_Tests_ExpressionParserTest::getFailingTestsForArray ( )

Definition at line 68 of file ExpressionParserTest.php.

69 {
70 return array(
71 array('{{ [1, "a": "b"] }}'),
72 array('{{ {"a": "b", 2} }}'),
73 );
74 }

◆ getFailingTestsForAssignment()

Twig_Tests_ExpressionParserTest::getFailingTestsForAssignment ( )

Definition at line 26 of file ExpressionParserTest.php.

27 {
28 return array(
29 array('{% set false = "foo" %}'),
30 array('{% set FALSE = "foo" %}'),
31 array('{% set true = "foo" %}'),
32 array('{% set TRUE = "foo" %}'),
33 array('{% set none = "foo" %}'),
34 array('{% set NONE = "foo" %}'),
35 array('{% set null = "foo" %}'),
36 array('{% set NULL = "foo" %}'),
37 array('{% set 3 = "foo" %}'),
38 array('{% set 1 + 2 = "foo" %}'),
39 array('{% set "bar" = "foo" %}'),
40 array('{% set %}{% endset %}'),
41 );
42 }

◆ getMacroDefinitionDoesNotSupportNonConstantDefaultValues()

Twig_Tests_ExpressionParserTest::getMacroDefinitionDoesNotSupportNonConstantDefaultValues ( )

Definition at line 270 of file ExpressionParserTest.php.

271 {
272 return array(
273 array('{% macro foo(name = "a #{foo} a") %}{% endmacro %}'),
274 array('{% macro foo(name = [["b", "a #{foo} a"]]) %}{% endmacro %}'),
275 );
276 }

◆ getMacroDefinitionSupportsConstantDefaultValues()

Twig_Tests_ExpressionParserTest::getMacroDefinitionSupportsConstantDefaultValues ( )

Definition at line 293 of file ExpressionParserTest.php.

294 {
295 return array(
296 array('{% macro foo(name = "aa") %}{% endmacro %}'),
297 array('{% macro foo(name = 12) %}{% endmacro %}'),
298 array('{% macro foo(name = true) %}{% endmacro %}'),
299 array('{% macro foo(name = ["a"]) %}{% endmacro %}'),
300 array('{% macro foo(name = [["a"]]) %}{% endmacro %}'),
301 array('{% macro foo(name = {a: "a"}) %}{% endmacro %}'),
302 array('{% macro foo(name = {a: {b: "a"}}) %}{% endmacro %}'),
303 );
304 }

◆ getTestsForArray()

Twig_Tests_ExpressionParserTest::getTestsForArray ( )

Definition at line 76 of file ExpressionParserTest.php.

77 {
78 return array(
79 // simple array
80 array('{{ [1, 2] }}', new Twig_Node_Expression_Array(array(
83
86 ), 1),
87 ),
88
89 // array with trailing ,
90 array('{{ [1, 2, ] }}', new Twig_Node_Expression_Array(array(
93
96 ), 1),
97 ),
98
99 // simple hash
100 array('{{ {"a": "b", "b": "c"} }}', new Twig_Node_Expression_Array(array(
103
106 ), 1),
107 ),
108
109 // hash with trailing ,
110 array('{{ {"a": "b", "b": "c", } }}', new Twig_Node_Expression_Array(array(
113
116 ), 1),
117 ),
118
119 // hash in an array
120 array('{{ [1, {"a": "b", "b": "c"}] }}', new Twig_Node_Expression_Array(array(
123
128
131 ), 1),
132 ), 1),
133 ),
134
135 // array in a hash
136 array('{{ {"a": [1, 2], "b": "c"} }}', new Twig_Node_Expression_Array(array(
141
144 ), 1),
147 ), 1),
148 ),
149 );
150 }

◆ getTestsForString()

Twig_Tests_ExpressionParserTest::getTestsForString ( )

Definition at line 176 of file ExpressionParserTest.php.

177 {
178 return array(
179 array(
180 '{{ "foo" }}', new Twig_Node_Expression_Constant('foo', 1),
181 ),
182 array(
183 '{{ "foo #{bar}" }}', new Twig_Node_Expression_Binary_Concat(
184 new Twig_Node_Expression_Constant('foo ', 1),
185 new Twig_Node_Expression_Name('bar', 1),
186 1
187 ),
188 ),
189 array(
190 '{{ "foo #{bar} baz" }}', new Twig_Node_Expression_Binary_Concat(
192 new Twig_Node_Expression_Constant('foo ', 1),
193 new Twig_Node_Expression_Name('bar', 1),
194 1
195 ),
196 new Twig_Node_Expression_Constant(' baz', 1),
197 1
198 ),
199 ),
200
201 array(
202 '{{ "foo #{"foo #{bar} baz"} baz" }}', new Twig_Node_Expression_Binary_Concat(
204 new Twig_Node_Expression_Constant('foo ', 1),
207 new Twig_Node_Expression_Constant('foo ', 1),
208 new Twig_Node_Expression_Name('bar', 1),
209 1
210 ),
211 new Twig_Node_Expression_Constant(' baz', 1),
212 1
213 ),
214 1
215 ),
216 new Twig_Node_Expression_Constant(' baz', 1),
217 1
218 ),
219 ),
220 );
221 }

◆ testArrayExpression()

Twig_Tests_ExpressionParserTest::testArrayExpression (   $template,
  $expected 
)

@dataProvider getTestsForArray

Definition at line 47 of file ExpressionParserTest.php.

48 {
49 $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
50 $stream = $env->tokenize(new Twig_Source($template, ''));
52
53 $this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)->getNode('expr'));
54 }
$parser
Definition: BPMN2Parser.php:23
$env
Stores the Twig configuration.
Definition: Environment.php:18
Default parser implementation.
Definition: Parser.php:19
Holds information about a non-compiled Twig template.
Definition: Source.php:20
$template
$stream
PHP stream implementation.

References $env, $parser, GuzzleHttp\Psr7\$stream, and $template.

◆ testArraySyntaxError()

Twig_Tests_ExpressionParserTest::testArraySyntaxError (   $template)

@expectedException Twig_Error_Syntax @dataProvider getFailingTestsForArray

Definition at line 60 of file ExpressionParserTest.php.

61 {
62 $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
64
65 $parser->parse($env->tokenize(new Twig_Source($template, 'index')));
66 }

References $env, $parser, and $template.

◆ testAttributeCallDoesNotSupportNamedArguments()

Twig_Tests_ExpressionParserTest::testAttributeCallDoesNotSupportNamedArguments ( )

@expectedException Twig_Error_Syntax

Definition at line 226 of file ExpressionParserTest.php.

227 {
228 $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
229 $parser = new Twig_Parser($env);
230
231 $parser->parse($env->tokenize(new Twig_Source('{{ foo.bar(name="Foo") }}', 'index')));
232 }

References $env, and $parser.

◆ testCanOnlyAssignToNames()

Twig_Tests_ExpressionParserTest::testCanOnlyAssignToNames (   $template)

@expectedException Twig_Error_Syntax @dataProvider getFailingTestsForAssignment

Definition at line 18 of file ExpressionParserTest.php.

19 {
20 $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
22
23 $parser->parse($env->tokenize(new Twig_Source($template, 'index')));
24 }

References $env, $parser, and $template.

◆ testMacroCallDoesNotSupportNamedArguments()

Twig_Tests_ExpressionParserTest::testMacroCallDoesNotSupportNamedArguments ( )

@expectedException Twig_Error_Syntax

Definition at line 237 of file ExpressionParserTest.php.

238 {
239 $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
240 $parser = new Twig_Parser($env);
241
242 $parser->parse($env->tokenize(new Twig_Source('{% from _self import foo %}{% macro foo() %}{% endmacro %}{{ foo(name="Foo") }}', 'index')));
243 }

References $env, and $parser.

◆ testMacroDefinitionDoesNotSupportNonConstantDefaultValues()

Twig_Tests_ExpressionParserTest::testMacroDefinitionDoesNotSupportNonConstantDefaultValues (   $template)

@expectedException Twig_Error_Syntax @expectedExceptionMessage A default value for an argument must be a constant (a boolean, a string, a number, or an array) in "index" at line 1 @dataProvider getMacroDefinitionDoesNotSupportNonConstantDefaultValues

Definition at line 262 of file ExpressionParserTest.php.

263 {
264 $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
265 $parser = new Twig_Parser($env);
266
267 $parser->parse($env->tokenize(new Twig_Source($template, 'index')));
268 }

References $env, $parser, and $template.

◆ testMacroDefinitionDoesNotSupportNonNameVariableName()

Twig_Tests_ExpressionParserTest::testMacroDefinitionDoesNotSupportNonNameVariableName ( )

@expectedException Twig_Error_Syntax @expectedExceptionMessage An argument must be a name.

Unexpected token "string" of value "a" ("name" expected) in "index" at line 1.

Definition at line 249 of file ExpressionParserTest.php.

250 {
251 $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
252 $parser = new Twig_Parser($env);
253
254 $parser->parse($env->tokenize(new Twig_Source('{% macro foo("a") %}{% endmacro %}', 'index')));
255 }

References $env, and $parser.

◆ testMacroDefinitionSupportsConstantDefaultValues()

Twig_Tests_ExpressionParserTest::testMacroDefinitionSupportsConstantDefaultValues (   $template)

@dataProvider getMacroDefinitionSupportsConstantDefaultValues

Definition at line 281 of file ExpressionParserTest.php.

282 {
283 $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
284 $parser = new Twig_Parser($env);
285
286 $parser->parse($env->tokenize(new Twig_Source($template, 'index')));
287
288 // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
289 // can be executed without throwing any exceptions
290 $this->addToAssertionCount(1);
291 }

References $env, $parser, and $template.

◆ testStringExpression()

Twig_Tests_ExpressionParserTest::testStringExpression (   $template,
  $expected 
)

@dataProvider getTestsForString

Definition at line 167 of file ExpressionParserTest.php.

168 {
169 $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
170 $stream = $env->tokenize(new Twig_Source($template, ''));
171 $parser = new Twig_Parser($env);
172
173 $this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)->getNode('expr'));
174 }

References $env, $parser, GuzzleHttp\Psr7\$stream, and $template.

◆ testStringExpressionDoesNotConcatenateTwoConsecutiveStrings()

Twig_Tests_ExpressionParserTest::testStringExpressionDoesNotConcatenateTwoConsecutiveStrings ( )

@expectedException Twig_Error_Syntax

Definition at line 155 of file ExpressionParserTest.php.

156 {
157 $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
158 $stream = $env->tokenize(new Twig_Source('{{ "a" "b" }}', 'index'));
159 $parser = new Twig_Parser($env);
160
161 $parser->parse($stream);
162 }

References $env, $parser, and GuzzleHttp\Psr7\$stream.

◆ testUnknownFilter()

Twig_Tests_ExpressionParserTest::testUnknownFilter ( )

@expectedException Twig_Error_Syntax @expectedExceptionMessage Unknown "lowe" filter.

Did you mean "lower" in "index" at line 1?

Definition at line 334 of file ExpressionParserTest.php.

335 {
336 $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
337 $parser = new Twig_Parser($env);
338
339 $parser->parse($env->tokenize(new Twig_Source('{{ 1|lowe }}', 'index')));
340 }

References $env, and $parser.

◆ testUnknownFilterWithoutSuggestions()

Twig_Tests_ExpressionParserTest::testUnknownFilterWithoutSuggestions ( )

@expectedException Twig_Error_Syntax @expectedExceptionMessage Unknown "foobar" filter in "index" at line 1.

Definition at line 346 of file ExpressionParserTest.php.

347 {
348 $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
349 $parser = new Twig_Parser($env);
350
351 $parser->parse($env->tokenize(new Twig_Source('{{ 1|foobar }}', 'index')));
352 }

References $env, and $parser.

◆ testUnknownFunction()

Twig_Tests_ExpressionParserTest::testUnknownFunction ( )

@expectedException Twig_Error_Syntax @expectedExceptionMessage Unknown "cycl" function.

Did you mean "cycle" in "index" at line 1?

Definition at line 310 of file ExpressionParserTest.php.

311 {
312 $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
313 $parser = new Twig_Parser($env);
314
315 $parser->parse($env->tokenize(new Twig_Source('{{ cycl() }}', 'index')));
316 }

References $env, and $parser.

◆ testUnknownFunctionWithoutSuggestions()

Twig_Tests_ExpressionParserTest::testUnknownFunctionWithoutSuggestions ( )

@expectedException Twig_Error_Syntax @expectedExceptionMessage Unknown "foobar" function in "index" at line 1.

Definition at line 322 of file ExpressionParserTest.php.

323 {
324 $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
325 $parser = new Twig_Parser($env);
326
327 $parser->parse($env->tokenize(new Twig_Source('{{ foobar() }}', 'index')));
328 }

References $env, and $parser.

◆ testUnknownTest()

Twig_Tests_ExpressionParserTest::testUnknownTest ( )

@expectedException Twig_Error_Syntax @expectedExceptionMessage Unknown "nul" test.

Did you mean "null" in "index" at line 1

Definition at line 358 of file ExpressionParserTest.php.

359 {
360 $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
361 $parser = new Twig_Parser($env);
362 $stream = $env->tokenize(new Twig_Source('{{ 1 is nul }}', 'index'));
363 $parser->parse($stream);
364 }

References $env, $parser, and GuzzleHttp\Psr7\$stream.

◆ testUnknownTestWithoutSuggestions()

Twig_Tests_ExpressionParserTest::testUnknownTestWithoutSuggestions ( )

@expectedException Twig_Error_Syntax @expectedExceptionMessage Unknown "foobar" test in "index" at line 1.

Definition at line 370 of file ExpressionParserTest.php.

371 {
372 $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
373 $parser = new Twig_Parser($env);
374
375 $parser->parse($env->tokenize(new Twig_Source('{{ 1 is foobar }}', 'index')));
376 }

References $env, and $parser.


The documentation for this class was generated from the following file: