ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Twig_Tests_ExpressionParserTest Class Reference
+ Inheritance diagram for Twig_Tests_ExpressionParserTest:
+ Collaboration diagram for Twig_Tests_ExpressionParserTest:

Public Member Functions

 testCanOnlyAssignToNames ($template)
 Twig_Error_Syntax getFailingTestsForAssignment More...
 
 getFailingTestsForAssignment ()
 
 testArrayExpression ($template, $expected)
 getTestsForArray More...
 
 testArraySyntaxError ($template)
 Twig_Error_Syntax getFailingTestsForArray More...
 
 getFailingTestsForArray ()
 
 getTestsForArray ()
 
 testStringExpressionDoesNotConcatenateTwoConsecutiveStrings ()
 Twig_Error_Syntax More...
 
 testStringExpression ($template, $expected)
 getTestsForString More...
 
 getTestsForString ()
 
 testAttributeCallDoesNotSupportNamedArguments ()
 Twig_Error_Syntax More...
 
 testMacroCallDoesNotSupportNamedArguments ()
 Twig_Error_Syntax More...
 
 testMacroDefinitionDoesNotSupportNonNameVariableName ()
 Twig_Error_Syntax An argument must be a name. More...
 
 testMacroDefinitionDoesNotSupportNonConstantDefaultValues ($template)
 Twig_Error_Syntax A default value for an argument must be a constant (a boolean, a string, a number, or an array) in "index" at line 1 getMacroDefinitionDoesNotSupportNonConstantDefaultValues More...
 
 getMacroDefinitionDoesNotSupportNonConstantDefaultValues ()
 
 testMacroDefinitionSupportsConstantDefaultValues ($template)
 getMacroDefinitionSupportsConstantDefaultValues More...
 
 getMacroDefinitionSupportsConstantDefaultValues ()
 
 testUnknownFunction ()
 Twig_Error_Syntax Unknown "cycl" function. More...
 
 testUnknownFunctionWithoutSuggestions ()
 Twig_Error_Syntax Unknown "foobar" function in "index" at line 1. More...
 
 testUnknownFilter ()
 Twig_Error_Syntax Unknown "lowe" filter. More...
 
 testUnknownFilterWithoutSuggestions ()
 Twig_Error_Syntax Unknown "foobar" filter in "index" at line 1. More...
 
 testUnknownTest ()
 Twig_Error_Syntax Unknown "nul" test. More...
 
 testUnknownTestWithoutSuggestions ()
 Twig_Error_Syntax 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(
101  new Twig_Node_Expression_Constant('a', 1),
102  new Twig_Node_Expression_Constant('b', 1),
103 
104  new Twig_Node_Expression_Constant('b', 1),
105  new Twig_Node_Expression_Constant('c', 1),
106  ), 1),
107  ),
108 
109  // hash with trailing ,
110  array('{{ {"a": "b", "b": "c", } }}', new Twig_Node_Expression_Array(array(
111  new Twig_Node_Expression_Constant('a', 1),
112  new Twig_Node_Expression_Constant('b', 1),
113 
114  new Twig_Node_Expression_Constant('b', 1),
115  new Twig_Node_Expression_Constant('c', 1),
116  ), 1),
117  ),
118 
119  // hash in an array
120  array('{{ [1, {"a": "b", "b": "c"}] }}', new Twig_Node_Expression_Array(array(
123 
125  new Twig_Node_Expression_Array(array(
126  new Twig_Node_Expression_Constant('a', 1),
127  new Twig_Node_Expression_Constant('b', 1),
128 
129  new Twig_Node_Expression_Constant('b', 1),
130  new Twig_Node_Expression_Constant('c', 1),
131  ), 1),
132  ), 1),
133  ),
134 
135  // array in a hash
136  array('{{ {"a": [1, 2], "b": "c"} }}', new Twig_Node_Expression_Array(array(
137  new Twig_Node_Expression_Constant('a', 1),
138  new Twig_Node_Expression_Array(array(
141 
144  ), 1),
145  new Twig_Node_Expression_Constant('b', 1),
146  new Twig_Node_Expression_Constant('c', 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 
)

getTestsForArray

Definition at line 47 of file ExpressionParserTest.php.

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

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

◆ testArraySyntaxError()

Twig_Tests_ExpressionParserTest::testArraySyntaxError (   $template)

Twig_Error_Syntax getFailingTestsForArray

Definition at line 60 of file ExpressionParserTest.php.

References $env, $parser, and $template.

61  {
62  $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
63  $parser = new Twig_Parser($env);
64 
65  $parser->parse($env->tokenize(new Twig_Source($template, 'index')));
66  }
$template
Default parser implementation.
Definition: Parser.php:18
$env
$parser
Definition: BPMN2Parser.php:23
Holds information about a non-compiled Twig template.
Definition: Source.php:19
Stores the Twig configuration.
Definition: Environment.php:17

◆ testAttributeCallDoesNotSupportNamedArguments()

Twig_Tests_ExpressionParserTest::testAttributeCallDoesNotSupportNamedArguments ( )

Twig_Error_Syntax

Definition at line 226 of file ExpressionParserTest.php.

References $env, and $parser.

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  }
Default parser implementation.
Definition: Parser.php:18
$env
$parser
Definition: BPMN2Parser.php:23
Holds information about a non-compiled Twig template.
Definition: Source.php:19
Stores the Twig configuration.
Definition: Environment.php:17

◆ testCanOnlyAssignToNames()

Twig_Tests_ExpressionParserTest::testCanOnlyAssignToNames (   $template)

Twig_Error_Syntax getFailingTestsForAssignment

Definition at line 18 of file ExpressionParserTest.php.

References $env, $parser, and $template.

19  {
20  $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
21  $parser = new Twig_Parser($env);
22 
23  $parser->parse($env->tokenize(new Twig_Source($template, 'index')));
24  }
$template
Default parser implementation.
Definition: Parser.php:18
$env
$parser
Definition: BPMN2Parser.php:23
Holds information about a non-compiled Twig template.
Definition: Source.php:19
Stores the Twig configuration.
Definition: Environment.php:17

◆ testMacroCallDoesNotSupportNamedArguments()

Twig_Tests_ExpressionParserTest::testMacroCallDoesNotSupportNamedArguments ( )

Twig_Error_Syntax

Definition at line 237 of file ExpressionParserTest.php.

References $env, and $parser.

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  }
Default parser implementation.
Definition: Parser.php:18
$env
$parser
Definition: BPMN2Parser.php:23
Holds information about a non-compiled Twig template.
Definition: Source.php:19
Stores the Twig configuration.
Definition: Environment.php:17

◆ testMacroDefinitionDoesNotSupportNonConstantDefaultValues()

Twig_Tests_ExpressionParserTest::testMacroDefinitionDoesNotSupportNonConstantDefaultValues (   $template)

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

Definition at line 262 of file ExpressionParserTest.php.

References $env, $parser, and $template.

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  }
$template
Default parser implementation.
Definition: Parser.php:18
$env
$parser
Definition: BPMN2Parser.php:23
Holds information about a non-compiled Twig template.
Definition: Source.php:19
Stores the Twig configuration.
Definition: Environment.php:17

◆ testMacroDefinitionDoesNotSupportNonNameVariableName()

Twig_Tests_ExpressionParserTest::testMacroDefinitionDoesNotSupportNonNameVariableName ( )

Twig_Error_Syntax 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.

References $env, and $parser.

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  }
Default parser implementation.
Definition: Parser.php:18
$env
$parser
Definition: BPMN2Parser.php:23
Holds information about a non-compiled Twig template.
Definition: Source.php:19
Stores the Twig configuration.
Definition: Environment.php:17

◆ testMacroDefinitionSupportsConstantDefaultValues()

Twig_Tests_ExpressionParserTest::testMacroDefinitionSupportsConstantDefaultValues (   $template)

getMacroDefinitionSupportsConstantDefaultValues

Definition at line 281 of file ExpressionParserTest.php.

References $env, $parser, and $template.

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  }
$template
Default parser implementation.
Definition: Parser.php:18
$env
$parser
Definition: BPMN2Parser.php:23
Holds information about a non-compiled Twig template.
Definition: Source.php:19
Stores the Twig configuration.
Definition: Environment.php:17

◆ testStringExpression()

Twig_Tests_ExpressionParserTest::testStringExpression (   $template,
  $expected 
)

getTestsForString

Definition at line 167 of file ExpressionParserTest.php.

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

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  }
$template
Default parser implementation.
Definition: Parser.php:18
$stream
PHP stream implementation.
$env
$parser
Definition: BPMN2Parser.php:23
Holds information about a non-compiled Twig template.
Definition: Source.php:19
Stores the Twig configuration.
Definition: Environment.php:17

◆ testStringExpressionDoesNotConcatenateTwoConsecutiveStrings()

Twig_Tests_ExpressionParserTest::testStringExpressionDoesNotConcatenateTwoConsecutiveStrings ( )

Twig_Error_Syntax

Definition at line 155 of file ExpressionParserTest.php.

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

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  }
Default parser implementation.
Definition: Parser.php:18
$stream
PHP stream implementation.
$env
$parser
Definition: BPMN2Parser.php:23
Holds information about a non-compiled Twig template.
Definition: Source.php:19
Stores the Twig configuration.
Definition: Environment.php:17

◆ testUnknownFilter()

Twig_Tests_ExpressionParserTest::testUnknownFilter ( )

Twig_Error_Syntax Unknown "lowe" filter.

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

Definition at line 334 of file ExpressionParserTest.php.

References $env, and $parser.

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  }
Default parser implementation.
Definition: Parser.php:18
$env
$parser
Definition: BPMN2Parser.php:23
Holds information about a non-compiled Twig template.
Definition: Source.php:19
Stores the Twig configuration.
Definition: Environment.php:17

◆ testUnknownFilterWithoutSuggestions()

Twig_Tests_ExpressionParserTest::testUnknownFilterWithoutSuggestions ( )

Twig_Error_Syntax Unknown "foobar" filter in "index" at line 1.

Definition at line 346 of file ExpressionParserTest.php.

References $env, and $parser.

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  }
Default parser implementation.
Definition: Parser.php:18
$env
$parser
Definition: BPMN2Parser.php:23
Holds information about a non-compiled Twig template.
Definition: Source.php:19
Stores the Twig configuration.
Definition: Environment.php:17

◆ testUnknownFunction()

Twig_Tests_ExpressionParserTest::testUnknownFunction ( )

Twig_Error_Syntax Unknown "cycl" function.

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

Definition at line 310 of file ExpressionParserTest.php.

References $env, and $parser.

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  }
Default parser implementation.
Definition: Parser.php:18
$env
$parser
Definition: BPMN2Parser.php:23
Holds information about a non-compiled Twig template.
Definition: Source.php:19
Stores the Twig configuration.
Definition: Environment.php:17

◆ testUnknownFunctionWithoutSuggestions()

Twig_Tests_ExpressionParserTest::testUnknownFunctionWithoutSuggestions ( )

Twig_Error_Syntax Unknown "foobar" function in "index" at line 1.

Definition at line 322 of file ExpressionParserTest.php.

References $env, and $parser.

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  }
Default parser implementation.
Definition: Parser.php:18
$env
$parser
Definition: BPMN2Parser.php:23
Holds information about a non-compiled Twig template.
Definition: Source.php:19
Stores the Twig configuration.
Definition: Environment.php:17

◆ testUnknownTest()

Twig_Tests_ExpressionParserTest::testUnknownTest ( )

Twig_Error_Syntax Unknown "nul" test.

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

Definition at line 358 of file ExpressionParserTest.php.

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

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  }
Default parser implementation.
Definition: Parser.php:18
$stream
PHP stream implementation.
$env
$parser
Definition: BPMN2Parser.php:23
Holds information about a non-compiled Twig template.
Definition: Source.php:19
Stores the Twig configuration.
Definition: Environment.php:17

◆ testUnknownTestWithoutSuggestions()

Twig_Tests_ExpressionParserTest::testUnknownTestWithoutSuggestions ( )

Twig_Error_Syntax Unknown "foobar" test in "index" at line 1.

Definition at line 370 of file ExpressionParserTest.php.

References $env, and $parser.

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  }
Default parser implementation.
Definition: Parser.php:18
$env
$parser
Definition: BPMN2Parser.php:23
Holds information about a non-compiled Twig template.
Definition: Source.php:19
Stores the Twig configuration.
Definition: Environment.php:17

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