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

Public Member Functions

 testLegacyConstructorSignature ()
 @group legacy More...
 
 testNameLabelForTag ()
 
 testNameLabelForFunction ()
 
 testBracketsNesting ()
 
 testLineDirective ()
 
 testLineDirectiveInline ()
 
 testLongComments ()
 
 testLongVerbatim ()
 
 testLongVar ()
 
 testLongBlock ()
 
 testBigNumbers ()
 
 testStringWithEscapedDelimiter ()
 
 testStringWithInterpolation ()
 
 testStringWithEscapedInterpolation ()
 
 testStringWithHash ()
 
 testStringWithUnterminatedInterpolation ()
 @expectedException Twig_Error_Syntax @expectedExceptionMessage Unclosed """ More...
 
 testStringWithNestedInterpolations ()
 
 testStringWithNestedInterpolationsInBlock ()
 
 testOperatorEndingWithALetterAtTheEndOfALine ()
 
 testUnterminatedVariable ()
 @expectedException Twig_Error_Syntax @expectedExceptionMessage Unclosed "variable" in "index" at line 3 More...
 
 testUnterminatedBlock ()
 @expectedException Twig_Error_Syntax @expectedExceptionMessage Unclosed "block" in "index" at line 3 More...
 

Protected Member Functions

 countToken ($template, $type, $value=null)
 

Detailed Description

Definition at line 11 of file LexerTest.php.

Member Function Documentation

◆ countToken()

Twig_Tests_LexerTest::countToken (   $template,
  $type,
  $value = null 
)
protected

Definition at line 54 of file LexerTest.php.

55 {
56 $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
57 $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
58
59 $count = 0;
60 while (!$stream->isEOF()) {
61 $token = $stream->next();
62 if ($type === $token->getType()) {
63 if (null === $value || $value === $token->getValue()) {
64 ++$count;
65 }
66 }
67 }
68
69 return $count;
70 }
Stores the Twig configuration.
Definition: Environment.php:18
Lexes a template string.
Definition: Lexer.php:19
Holds information about a non-compiled Twig template.
Definition: Source.php:20
$template
$stream
PHP stream implementation.
$type

References GuzzleHttp\Psr7\$stream, $template, PHPMailer\PHPMailer\$token, and $type.

Referenced by testBracketsNesting().

+ Here is the caller graph for this function:

◆ testBigNumbers()

Twig_Tests_LexerTest::testBigNumbers ( )

Definition at line 160 of file LexerTest.php.

161 {
162 $template = '{{ 922337203685477580700 }}';
163
164 $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
165 $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
166 $stream->next();
167 $node = $stream->next();
168 $this->assertEquals('922337203685477580700', $node->getValue());
169 }

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

◆ testBracketsNesting()

Twig_Tests_LexerTest::testBracketsNesting ( )

Definition at line 46 of file LexerTest.php.

47 {
48 $template = '{{ {"a":{"b":"c"}} }}';
49
50 $this->assertEquals(2, $this->countToken($template, Twig_Token::PUNCTUATION_TYPE, '{'));
51 $this->assertEquals(2, $this->countToken($template, Twig_Token::PUNCTUATION_TYPE, '}'));
52 }
countToken($template, $type, $value=null)
Definition: LexerTest.php:54
const PUNCTUATION_TYPE
Definition: Token.php:36

References $template, countToken(), and Twig_Token\PUNCTUATION_TYPE.

+ Here is the call graph for this function:

◆ testLegacyConstructorSignature()

Twig_Tests_LexerTest::testLegacyConstructorSignature ( )

@group legacy

Definition at line 16 of file LexerTest.php.

17 {
18 $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
19 $stream = $lexer->tokenize('{{ foo }}', 'foo');
20 $this->assertEquals('foo', $stream->getFilename());
21 $this->assertEquals('{{ foo }}', $stream->getSource());
22 }

References GuzzleHttp\Psr7\$stream.

◆ testLineDirective()

Twig_Tests_LexerTest::testLineDirective ( )

Definition at line 72 of file LexerTest.php.

73 {
74 $template = "foo\n"
75 ."bar\n"
76 ."{% line 10 %}\n"
77 ."{{\n"
78 ."baz\n"
79 ."}}\n";
80
81 $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
82 $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
83
84 // foo\nbar\n
85 $this->assertSame(1, $stream->expect(Twig_Token::TEXT_TYPE)->getLine());
86 // \n (after {% line %})
87 $this->assertSame(10, $stream->expect(Twig_Token::TEXT_TYPE)->getLine());
88 // {{
89 $this->assertSame(11, $stream->expect(Twig_Token::VAR_START_TYPE)->getLine());
90 // baz
91 $this->assertSame(12, $stream->expect(Twig_Token::NAME_TYPE)->getLine());
92 }
const VAR_START_TYPE
Definition: Token.php:29
const TEXT_TYPE
Definition: Token.php:27
const NAME_TYPE
Definition: Token.php:32

References GuzzleHttp\Psr7\$stream, $template, Twig_Token\NAME_TYPE, Twig_Token\TEXT_TYPE, and Twig_Token\VAR_START_TYPE.

◆ testLineDirectiveInline()

Twig_Tests_LexerTest::testLineDirectiveInline ( )

Definition at line 94 of file LexerTest.php.

95 {
96 $template = "foo\n"
97 ."bar{% line 10 %}{{\n"
98 ."baz\n"
99 ."}}\n";
100
101 $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
102 $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
103
104 // foo\nbar
105 $this->assertSame(1, $stream->expect(Twig_Token::TEXT_TYPE)->getLine());
106 // {{
107 $this->assertSame(10, $stream->expect(Twig_Token::VAR_START_TYPE)->getLine());
108 // baz
109 $this->assertSame(11, $stream->expect(Twig_Token::NAME_TYPE)->getLine());
110 }

References GuzzleHttp\Psr7\$stream, $template, Twig_Token\NAME_TYPE, Twig_Token\TEXT_TYPE, and Twig_Token\VAR_START_TYPE.

◆ testLongBlock()

Twig_Tests_LexerTest::testLongBlock ( )

Definition at line 148 of file LexerTest.php.

149 {
150 $template = '{% '.str_repeat('x', 100000).' %}';
151
152 $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
153 $lexer->tokenize(new Twig_Source($template, 'index'));
154
155 // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
156 // can be executed without throwing any exceptions
157 $this->addToAssertionCount(1);
158 }

References $template.

◆ testLongComments()

Twig_Tests_LexerTest::testLongComments ( )

Definition at line 112 of file LexerTest.php.

113 {
114 $template = '{# '.str_repeat('*', 100000).' #}';
115
116 $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
117 $lexer->tokenize(new Twig_Source($template, 'index'));
118
119 // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
120 // can be executed without throwing any exceptions
121 $this->addToAssertionCount(1);
122 }

References $template.

◆ testLongVar()

Twig_Tests_LexerTest::testLongVar ( )

Definition at line 136 of file LexerTest.php.

137 {
138 $template = '{{ '.str_repeat('x', 100000).' }}';
139
140 $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
141 $lexer->tokenize(new Twig_Source($template, 'index'));
142
143 // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
144 // can be executed without throwing any exceptions
145 $this->addToAssertionCount(1);
146 }

References $template.

◆ testLongVerbatim()

Twig_Tests_LexerTest::testLongVerbatim ( )

Definition at line 124 of file LexerTest.php.

125 {
126 $template = '{% verbatim %}'.str_repeat('*', 100000).'{% endverbatim %}';
127
128 $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
129 $lexer->tokenize(new Twig_Source($template, 'index'));
130
131 // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
132 // can be executed without throwing any exceptions
133 $this->addToAssertionCount(1);
134 }

References $template.

◆ testNameLabelForFunction()

Twig_Tests_LexerTest::testNameLabelForFunction ( )

Definition at line 35 of file LexerTest.php.

36 {
37 $template = '{{ §() }}';
38
39 $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
40 $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
41
43 $this->assertSame('§', $stream->expect(Twig_Token::NAME_TYPE)->getValue());
44 }

References GuzzleHttp\Psr7\$stream, $template, Twig_Token\NAME_TYPE, and Twig_Token\VAR_START_TYPE.

◆ testNameLabelForTag()

Twig_Tests_LexerTest::testNameLabelForTag ( )

Definition at line 24 of file LexerTest.php.

25 {
26 $template = '{% § %}';
27
28 $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
29 $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
30
32 $this->assertSame('§', $stream->expect(Twig_Token::NAME_TYPE)->getValue());
33 }
const BLOCK_START_TYPE
Definition: Token.php:28

References GuzzleHttp\Psr7\$stream, $template, Twig_Token\BLOCK_START_TYPE, and Twig_Token\NAME_TYPE.

◆ testOperatorEndingWithALetterAtTheEndOfALine()

Twig_Tests_LexerTest::testOperatorEndingWithALetterAtTheEndOfALine ( )

Definition at line 295 of file LexerTest.php.

296 {
297 $template = "{{ 1 and\n0}}";
298
299 $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
300 $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
303 $stream->expect(Twig_Token::OPERATOR_TYPE, 'and');
304
305 // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
306 // can be executed without throwing any exceptions
307 $this->addToAssertionCount(1);
308 }
const NUMBER_TYPE
Definition: Token.php:33
const OPERATOR_TYPE
Definition: Token.php:35

References GuzzleHttp\Psr7\$stream, $template, Twig_Token\NUMBER_TYPE, Twig_Token\OPERATOR_TYPE, and Twig_Token\VAR_START_TYPE.

◆ testStringWithEscapedDelimiter()

Twig_Tests_LexerTest::testStringWithEscapedDelimiter ( )

Definition at line 171 of file LexerTest.php.

172 {
173 $tests = array(
174 "{{ 'foo \' bar' }}" => 'foo \' bar',
175 '{{ "foo \" bar" }}' => 'foo " bar',
176 );
177 $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
178 foreach ($tests as $template => $expected) {
179 $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
181 $stream->expect(Twig_Token::STRING_TYPE, $expected);
182
183 // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
184 // can be executed without throwing any exceptions
185 $this->addToAssertionCount(1);
186 }
187 }
const STRING_TYPE
Definition: Token.php:34
$tests
Definition: bench.php:104

References GuzzleHttp\Psr7\$stream, $template, $tests, Twig_Token\STRING_TYPE, and Twig_Token\VAR_START_TYPE.

◆ testStringWithEscapedInterpolation()

Twig_Tests_LexerTest::testStringWithEscapedInterpolation ( )

Definition at line 210 of file LexerTest.php.

211 {
212 $template = '{{ "bar \#{baz+1}" }}';
213
214 $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
215 $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
217 $stream->expect(Twig_Token::STRING_TYPE, 'bar #{baz+1}');
219
220 // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
221 // can be executed without throwing any exceptions
222 $this->addToAssertionCount(1);
223 }
const VAR_END_TYPE
Definition: Token.php:31

References GuzzleHttp\Psr7\$stream, $template, Twig_Token\STRING_TYPE, Twig_Token\VAR_END_TYPE, and Twig_Token\VAR_START_TYPE.

◆ testStringWithHash()

Twig_Tests_LexerTest::testStringWithHash ( )

Definition at line 225 of file LexerTest.php.

226 {
227 $template = '{{ "bar # baz" }}';
228
229 $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
230 $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
232 $stream->expect(Twig_Token::STRING_TYPE, 'bar # baz');
234
235 // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
236 // can be executed without throwing any exceptions
237 $this->addToAssertionCount(1);
238 }

References GuzzleHttp\Psr7\$stream, $template, Twig_Token\STRING_TYPE, Twig_Token\VAR_END_TYPE, and Twig_Token\VAR_START_TYPE.

◆ testStringWithInterpolation()

Twig_Tests_LexerTest::testStringWithInterpolation ( )

Definition at line 189 of file LexerTest.php.

190 {
191 $template = 'foo {{ "bar #{ baz + 1 }" }}';
192
193 $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
194 $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
195 $stream->expect(Twig_Token::TEXT_TYPE, 'foo ');
197 $stream->expect(Twig_Token::STRING_TYPE, 'bar ');
199 $stream->expect(Twig_Token::NAME_TYPE, 'baz');
201 $stream->expect(Twig_Token::NUMBER_TYPE, '1');
204
205 // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
206 // can be executed without throwing any exceptions
207 $this->addToAssertionCount(1);
208 }
const INTERPOLATION_START_TYPE
Definition: Token.php:37
const INTERPOLATION_END_TYPE
Definition: Token.php:38

References GuzzleHttp\Psr7\$stream, $template, Twig_Token\INTERPOLATION_END_TYPE, Twig_Token\INTERPOLATION_START_TYPE, Twig_Token\NAME_TYPE, Twig_Token\NUMBER_TYPE, Twig_Token\OPERATOR_TYPE, Twig_Token\STRING_TYPE, Twig_Token\TEXT_TYPE, Twig_Token\VAR_END_TYPE, and Twig_Token\VAR_START_TYPE.

◆ testStringWithNestedInterpolations()

Twig_Tests_LexerTest::testStringWithNestedInterpolations ( )

Definition at line 252 of file LexerTest.php.

253 {
254 $template = '{{ "bar #{ "foo#{bar}" }" }}';
255
256 $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
257 $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
259 $stream->expect(Twig_Token::STRING_TYPE, 'bar ');
261 $stream->expect(Twig_Token::STRING_TYPE, 'foo');
263 $stream->expect(Twig_Token::NAME_TYPE, 'bar');
267
268 // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
269 // can be executed without throwing any exceptions
270 $this->addToAssertionCount(1);
271 }

References GuzzleHttp\Psr7\$stream, $template, Twig_Token\INTERPOLATION_END_TYPE, Twig_Token\INTERPOLATION_START_TYPE, Twig_Token\NAME_TYPE, Twig_Token\STRING_TYPE, Twig_Token\VAR_END_TYPE, and Twig_Token\VAR_START_TYPE.

◆ testStringWithNestedInterpolationsInBlock()

Twig_Tests_LexerTest::testStringWithNestedInterpolationsInBlock ( )

Definition at line 273 of file LexerTest.php.

274 {
275 $template = '{% foo "bar #{ "foo#{bar}" }" %}';
276
277 $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
278 $stream = $lexer->tokenize(new Twig_Source($template, 'index'));
280 $stream->expect(Twig_Token::NAME_TYPE, 'foo');
281 $stream->expect(Twig_Token::STRING_TYPE, 'bar ');
283 $stream->expect(Twig_Token::STRING_TYPE, 'foo');
285 $stream->expect(Twig_Token::NAME_TYPE, 'bar');
289
290 // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
291 // can be executed without throwing any exceptions
292 $this->addToAssertionCount(1);
293 }
const BLOCK_END_TYPE
Definition: Token.php:30

References GuzzleHttp\Psr7\$stream, $template, Twig_Token\BLOCK_END_TYPE, Twig_Token\BLOCK_START_TYPE, Twig_Token\INTERPOLATION_END_TYPE, Twig_Token\INTERPOLATION_START_TYPE, Twig_Token\NAME_TYPE, and Twig_Token\STRING_TYPE.

◆ testStringWithUnterminatedInterpolation()

Twig_Tests_LexerTest::testStringWithUnterminatedInterpolation ( )

@expectedException Twig_Error_Syntax @expectedExceptionMessage Unclosed """

Definition at line 244 of file LexerTest.php.

245 {
246 $template = '{{ "bar #{x" }}';
247
248 $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
249 $lexer->tokenize(new Twig_Source($template, 'index'));
250 }

References $template.

◆ testUnterminatedBlock()

Twig_Tests_LexerTest::testUnterminatedBlock ( )

@expectedException Twig_Error_Syntax @expectedExceptionMessage Unclosed "block" in "index" at line 3

Definition at line 333 of file LexerTest.php.

334 {
335 $template = '
336
337{%
338
339bar
340
341
342';
343
344 $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
345 $lexer->tokenize(new Twig_Source($template, 'index'));
346 }

References $template.

◆ testUnterminatedVariable()

Twig_Tests_LexerTest::testUnterminatedVariable ( )

@expectedException Twig_Error_Syntax @expectedExceptionMessage Unclosed "variable" in "index" at line 3

Definition at line 314 of file LexerTest.php.

315 {
316 $template = '
317
318{{
319
320bar
321
322
323';
324
325 $lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
326 $lexer->tokenize(new Twig_Source($template, 'index'));
327 }

References $template.


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