TYPO3 CMS  TYPO3_6-2
TemplateParserTest.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License, either version 3 *
9  * of the License, or (at your option) any later version. *
10  * *
11  * The TYPO3 project - inspiring people to share! *
12  * */
13 
21 
27  $templateParser = new \TYPO3\CMS\Fluid\Core\Parser\TemplateParser();
28  $templateParser->parse(123);
29  }
30 
35  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('dummy'));
36  $templateParser->_call('extractNamespaceDefinitions', ' \\{namespace f4=F7\\Rocks} {namespace f4=TYPO3\Rocks\Really}');
37  $expected = array(
38  'f' => 'TYPO3\CMS\Fluid\ViewHelpers',
39  'f4' => 'TYPO3\Rocks\Really'
40  );
41  $this->assertEquals($expected, $templateParser->getNamespaces(), 'Namespaces do not match.');
42  }
43 
48  $mockSettings = array(
49  'namespaces' => array(
50  'http://domain.tld/ns/my/viewhelpers' => 'My\Namespace',
51  'http://otherdomain.tld/ns/other/viewhelpers' => 'My\Other\Namespace'
52  )
53  );
54  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('dummy'));
55  $templateParser->injectSettings($mockSettings);
56  $templateParser->_call('extractNamespaceDefinitions', 'Some content <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f5="http://domain.tld/ns/my/viewhelpers"
57  xmlns:xyz="http://otherdomain.tld/ns/other/viewhelpers" />');
58  $expected = array(
59  'f' => 'TYPO3\CMS\Fluid\ViewHelpers',
60  'f5' => 'My\Namespace',
61  'xyz' => 'My\Other\Namespace'
62  );
63  $this->assertEquals($expected, $templateParser->getNamespaces(), 'Namespaces do not match.');
64  }
65 
70  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('dummy'));
71  $templateParser->_call('extractNamespaceDefinitions', '<xml xmlns="http://www.w3.org/1999/xhtml" xmlns:xyz="http://typo3.org/ns/Some/Package/ViewHelpers" />');
72  $expected = array(
73  'f' => 'TYPO3\CMS\Fluid\ViewHelpers',
74  'xyz' => 'Some\Package\ViewHelpers'
75  );
76  $this->assertEquals($expected, $templateParser->getNamespaces(), 'Namespaces do not match.');
77  }
78 
83  $mockSettings = array(
84  'namespaces' => array(
85  'http://domain.tld/ns/my/viewhelpers' => 'My\Namespace'
86  )
87  );
88  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('dummy'));
89  $templateParser->injectSettings($mockSettings);
90  $templateParser->_call('extractNamespaceDefinitions', '<xml xmlns="http://www.w3.org/1999/xhtml" xmlns:f5="http://domain.tld/ns/my/viewhelpers"
91  xmlns:xyz="http://otherdomain.tld/ns/other/viewhelpers" />');
92  $expected = array(
93  'f' => 'TYPO3\CMS\Fluid\ViewHelpers',
94  'f5' => 'My\Namespace'
95  );
96  $this->assertEquals($expected, $templateParser->getNamespaces(), 'Namespaces do not match.');
97  }
98 
103  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('dummy'));
104  $templateParser->_call('extractNamespaceDefinitions', '<foo xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://domain.tld/this/will/be/ignored" />');
105  $expected = array(
106  'f' => 'TYPO3\CMS\Fluid\ViewHelpers'
107  );
108  $this->assertEquals($expected, $templateParser->getNamespaces(), 'Namespaces do not match.');
109  }
110 
116  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('dummy'));
117  $templateParser->_call('extractNamespaceDefinitions', '{namespace typo3=TYPO3\CMS\Fluid\Blablubb} {namespace typo3= TYPO3\Rocks\Blu}');
118  }
119 
125  $mockSettings = array(
126  'namespaces' => array(
127  'http://domain.tld/ns/my/viewhelpers' => 'My\Namespace'
128  )
129  );
130  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('dummy'));
131  $templateParser->injectSettings($mockSettings);
132  $templateParser->_call('extractNamespaceDefinitions', '<foo xmlns="http://www.w3.org/1999/xhtml" xmlns:typo3="http://domain.tld/ns/my/viewhelpers" />{namespace typo3=TYPO3\CMS\Fluid\Blablubb}');
133  }
134 
140  $mockSettings = array(
141  'namespaces' => array(
142  'http://domain.tld/ns/my/viewhelpers' => 'My\Namespace'
143  )
144  );
145  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('dummy'));
146  $templateParser->injectSettings($mockSettings);
147  $templateParser->_call('extractNamespaceDefinitions', '{namespace typo3=TYPO3\CMS\Fluid\Blablubb} <foo xmlns="http://www.w3.org/1999/xhtml" xmlns:typo3="http://domain.tld/ns/my/viewhelpers" />');
148  }
149 
154  $mockTemplateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('dummy'), array(), '', FALSE);
155  $result = $mockTemplateParser->_call('resolveViewHelperName', 'f', 'foo.bar.baz');
156  $expected = 'TYPO3\CMS\Fluid\ViewHelpers\Foo\Bar\BazViewHelper';
157  $this->assertEquals($expected, $result, 'The name of the View Helper Name could not be resolved.');
158  }
159 
164  $mockTemplateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('dummy'), array(), '', FALSE);
165  $actual = $mockTemplateParser->_call('resolveViewHelperName', 'f', 'myown');
166  $expected = 'TYPO3\CMS\Fluid\ViewHelpers\MyownViewHelper';
167  $this->assertEquals($expected, $actual);
168  }
169 
172  public function quotedStrings() {
173  return array(
174  array('"no quotes here"', 'no quotes here'),
175  array("'no quotes here'", 'no quotes here'),
176  array("'this \"string\" had \\'quotes\\' in it'", 'this "string" had \'quotes\' in it'),
177  array('"this \\"string\\" had \'quotes\' in it"', 'this "string" had \'quotes\' in it'),
178  array('"a weird \"string\" \'with\' *freaky* \\\\stuff', 'a weird "string" \'with\' *freaky* \\stuff'),
179  array('\'\\\'escaped quoted string in string\\\'\'', '\'escaped quoted string in string\'')
180  );
181  }
182 
187  public function unquoteStringReturnsUnquotedStrings($quoted, $unquoted) {
188  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('dummy'));
189  $this->assertEquals($unquoted, $templateParser->_call('unquoteString', $quoted));
190  }
191 
194  public function templatesToSplit() {
195  return array(
196  array('TemplateParserTestFixture01-shorthand'),
197  array('TemplateParserTestFixture06'),
198  array('TemplateParserTestFixture14')
199  );
200  }
201 
207  $template = file_get_contents(__DIR__ . '/Fixtures/' . $templateName . '.html', FILE_TEXT);
208  $expectedResult = require(__DIR__ . '/Fixtures/' . $templateName . '-split.php');
209  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('dummy'));
210  $this->assertSame($expectedResult, $templateParser->_call('splitTemplateAtDynamicTags', $template), 'Filed for ' . $templateName);
211  }
212 
217  $mockRootNode = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\RootNode');
218 
219  $mockState = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsingState');
220  $mockState->expects($this->once())->method('setRootNode')->with($mockRootNode);
221  $mockState->expects($this->once())->method('pushNodeToStack')->with($mockRootNode);
222  $mockState->expects($this->once())->method('countNodeStack')->will($this->returnValue(1));
223 
224  $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
225  $mockObjectManager->expects($this->at(0))->method('get')->with('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsingState')->will($this->returnValue($mockState));
226  $mockObjectManager->expects($this->at(1))->method('get')->with('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\RootNode')->will($this->returnValue($mockRootNode));
227 
228  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('dummy'));
229  $templateParser->_set('objectManager', $mockObjectManager);
230  $templateParser->_call('buildObjectTree', array(), \TYPO3\CMS\Fluid\Core\Parser\TemplateParser::CONTEXT_OUTSIDE_VIEWHELPER_ARGUMENTS);
231  }
232 
238  $mockRootNode = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\RootNode');
239 
240  $mockState = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsingState');
241  $mockState->expects($this->once())->method('countNodeStack')->will($this->returnValue(2));
242 
243  $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
244  $mockObjectManager->expects($this->at(0))->method('get')->with('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsingState')->will($this->returnValue($mockState));
245  $mockObjectManager->expects($this->at(1))->method('get')->with('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\RootNode')->will($this->returnValue($mockRootNode));
246 
247  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('dummy'));
248  $templateParser->_set('objectManager', $mockObjectManager);
249  $templateParser->_call('buildObjectTree', array(), \TYPO3\CMS\Fluid\Core\Parser\TemplateParser::CONTEXT_OUTSIDE_VIEWHELPER_ARGUMENTS);
250  }
251 
256  $mockRootNode = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\RootNode');
257  $mockState = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsingState');
258  $mockState->expects($this->once())->method('countNodeStack')->will($this->returnValue(1));
259  $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
260  $mockObjectManager->expects($this->at(0))->method('get')->with('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsingState')->will($this->returnValue($mockState));
261  $mockObjectManager->expects($this->at(1))->method('get')->with('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\RootNode')->will($this->returnValue($mockRootNode));
262 
263  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('textHandler', 'openingViewHelperTagHandler', 'closingViewHelperTagHandler', 'textAndShorthandSyntaxHandler'));
264  $templateParser->_set('objectManager', $mockObjectManager);
265  $templateParser->expects($this->at(0))->method('textAndShorthandSyntaxHandler')->with($mockState, 'The first part is simple');
266  $templateParser->expects($this->at(1))->method('textHandler')->with($mockState, '<f:for each="{a: {a: 0, b: 2, c: 4}}" as="array"><f:for each="{array}" as="value">{value} </f:for>');
267  $templateParser->expects($this->at(2))->method('openingViewHelperTagHandler')->with($mockState, 'f', 'format.printf', ' arguments="{number : 362525200}"', FALSE);
268  $templateParser->expects($this->at(3))->method('textAndShorthandSyntaxHandler')->with($mockState, '%.3e');
269  $templateParser->expects($this->at(4))->method('closingViewHelperTagHandler')->with($mockState, 'f', 'format.printf');
270  $templateParser->expects($this->at(5))->method('textAndShorthandSyntaxHandler')->with($mockState, 'and here goes some {text} that could have {shorthand}');
271 
272  $splitTemplate = $templateParser->_call('splitTemplateAtDynamicTags', 'The first part is simple<![CDATA[<f:for each="{a: {a: 0, b: 2, c: 4}}" as="array"><f:for each="{array}" as="value">{value} </f:for>]]><f:format.printf arguments="{number : 362525200}">%.3e</f:format.printf>and here goes some {text} that could have {shorthand}');
273  $templateParser->_call('buildObjectTree', $splitTemplate, \TYPO3\CMS\Fluid\Core\Parser\TemplateParser::CONTEXT_OUTSIDE_VIEWHELPER_ARGUMENTS);
274  }
275 
280  $mockState = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsingState');
281  $mockState->expects($this->never())->method('popNodeFromStack');
282 
283  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('parseArguments', 'initializeViewHelperAndAddItToStack'));
284  $templateParser->expects($this->once())->method('parseArguments')->with(array('arguments'))->will($this->returnValue(array('parsedArguments')));
285  $templateParser->expects($this->once())->method('initializeViewHelperAndAddItToStack')->with($mockState, 'namespaceIdentifier', 'methodIdentifier', array('parsedArguments'));
286 
287  $templateParser->_call('openingViewHelperTagHandler', $mockState, 'namespaceIdentifier', 'methodIdentifier', array('arguments'), FALSE);
288  }
289 
294  $mockState = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsingState');
295  $mockState->expects($this->once())->method('popNodeFromStack')->will($this->returnValue($this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\NodeInterface')));
296 
297  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('parseArguments', 'initializeViewHelperAndAddItToStack'));
298 
299  $templateParser->_call('openingViewHelperTagHandler', $mockState, '', '', array(), TRUE);
300  }
301 
306  $mockViewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\AbstractViewHelper');
307  $mockViewHelperNode = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode', array(), array(), '', FALSE);
308 
309  $mockNodeOnStack = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\NodeInterface');
310  $mockNodeOnStack->expects($this->once())->method('addChildNode')->with($mockViewHelperNode);
311 
312  $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
313  $mockObjectManager->expects($this->at(0))->method('get')->with('TYPO3\\CMS\\Fluid\\ViewHelpers\\MyownViewHelper')->will($this->returnValue($mockViewHelper));
314  $mockObjectManager->expects($this->at(1))->method('get')->with('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode')->will($this->returnValue($mockViewHelperNode));
315 
316  $mockState = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsingState');
317  $mockState->expects($this->once())->method('getNodeFromStack')->will($this->returnValue($mockNodeOnStack));
318  $mockState->expects($this->once())->method('pushNodeToStack')->with($mockViewHelperNode);
319 
320  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('abortIfUnregisteredArgumentsExist', 'abortIfRequiredArgumentsAreMissing', 'rewriteBooleanNodesInArgumentsObjectTree'));
321  $templateParser->_set('objectManager', $mockObjectManager);
322 
323  $templateParser->_call('initializeViewHelperAndAddItToStack', $mockState, 'f', 'myown', array('arguments'));
324  }
325 
330  $expectedArguments = array('expectedArguments');
331  $argumentsObjectTree = array('arguments');
332 
333  $mockViewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\AbstractViewHelper');
334  $mockViewHelper->expects($this->once())->method('prepareArguments')->will($this->returnValue($expectedArguments));
335  $mockViewHelperNode = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode', array(), array(), '', FALSE);
336 
337  $mockNodeOnStack = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\NodeInterface');
338 
339  $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
340  $mockObjectManager->expects($this->at(0))->method('get')->with('TYPO3\\CMS\\Fluid\\ViewHelpers\\MyownViewHelper')->will($this->returnValue($mockViewHelper));
341  $mockObjectManager->expects($this->at(1))->method('get')->with('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode')->will($this->returnValue($mockViewHelperNode));
342 
343  $mockState = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsingState');
344  $mockState->expects($this->once())->method('getNodeFromStack')->will($this->returnValue($mockNodeOnStack));
345 
346  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('abortIfUnregisteredArgumentsExist', 'abortIfRequiredArgumentsAreMissing', 'rewriteBooleanNodesInArgumentsObjectTree'));
347  $templateParser->_set('objectManager', $mockObjectManager);
348  $templateParser->expects($this->once())->method('abortIfUnregisteredArgumentsExist')->with($expectedArguments, $argumentsObjectTree);
349  $templateParser->expects($this->once())->method('abortIfRequiredArgumentsAreMissing')->with($expectedArguments, $argumentsObjectTree);
350 
351  $templateParser->_call('initializeViewHelperAndAddItToStack', $mockState, 'f', 'myown', $argumentsObjectTree);
352  }
353 
358  $mockViewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\Tests\\Unit\\Core\\Parser\\Fixtures\\PostParseFacetViewHelper', array('prepareArguments'));
359  $mockViewHelperNode = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode', array(), array(), '', FALSE);
360 
361  $mockNodeOnStack = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\NodeInterface');
362  $mockNodeOnStack->expects($this->once())->method('addChildNode')->with($mockViewHelperNode);
363 
364  $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
365  $mockObjectManager->expects($this->at(0))->method('get')->with('TYPO3\\CMS\\Fluid\\ViewHelpers\\MyownViewHelper')->will($this->returnValue($mockViewHelper));
366  $mockObjectManager->expects($this->at(1))->method('get')->with('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode')->will($this->returnValue($mockViewHelperNode));
367 
368  $mockState = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsingState');
369  $mockState->expects($this->once())->method('getNodeFromStack')->will($this->returnValue($mockNodeOnStack));
370  $mockState->expects($this->once())->method('getVariableContainer')->will($this->returnValue($this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TemplateVariableContainer')));
371 
372  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('abortIfUnregisteredArgumentsExist', 'abortIfRequiredArgumentsAreMissing', 'rewriteBooleanNodesInArgumentsObjectTree'));
373  $templateParser->_set('objectManager', $mockObjectManager);
374 
375  $templateParser->_call('initializeViewHelperAndAddItToStack', $mockState, 'f', 'myown', array('arguments'));
376  $this->assertTrue(\TYPO3\CMS\Fluid\Tests\Unit\Core\Parser\Fixtures\PostParseFacetViewHelper::$wasCalled, 'PostParse was not called!');
377  }
378 
384  $expected = array(new \TYPO3\CMS\Fluid\Core\ViewHelper\ArgumentDefinition('firstArgument', 'string', '', FALSE));
385  $actual = array('firstArgument' => 'foo', 'secondArgument' => 'bar');
386 
387  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('dummy'));
388 
389  $templateParser->_call('abortIfUnregisteredArgumentsExist', $expected, $actual);
390  }
391 
396  $expectedArguments = array(
397  new \TYPO3\CMS\Fluid\Core\ViewHelper\ArgumentDefinition('name1', 'string', 'desc', FALSE),
398  new \TYPO3\CMS\Fluid\Core\ViewHelper\ArgumentDefinition('name2', 'string', 'desc', TRUE)
399  );
400  $actualArguments = array(
401  'name1' => 'bla'
402  );
403 
404  $mockTemplateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('dummy'));
405 
406  $mockTemplateParser->_call('abortIfUnregisteredArgumentsExist', $expectedArguments, $actualArguments);
407  // dummy assertion to avoid "did not perform any assertions" error
408  $this->assertTrue(TRUE);
409  }
410 
416  $expected = array(
417  new \TYPO3\CMS\Fluid\Core\ViewHelper\ArgumentDefinition('firstArgument', 'string', '', FALSE),
418  new \TYPO3\CMS\Fluid\Core\ViewHelper\ArgumentDefinition('secondArgument', 'string', '', TRUE)
419  );
420 
421  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('dummy'));
422 
423  $templateParser->_call('abortIfRequiredArgumentsAreMissing', $expected, array());
424  }
425 
430  $expectedArguments = array(
431  new \TYPO3\CMS\Fluid\Core\ViewHelper\ArgumentDefinition('name1', 'string', 'desc', FALSE),
432  new \TYPO3\CMS\Fluid\Core\ViewHelper\ArgumentDefinition('name2', 'string', 'desc', TRUE)
433  );
434  $actualArguments = array(
435  'name2' => 'bla'
436  );
437 
438  $mockTemplateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('dummy'));
439 
440  $mockTemplateParser->_call('abortIfRequiredArgumentsAreMissing', $expectedArguments, $actualArguments);
441  // dummy assertion to avoid "did not perform any assertions" error
442  $this->assertTrue(TRUE);
443  }
444 
450  $mockNodeOnStack = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\NodeInterface', array(), array(), '', FALSE);
451  $mockState = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsingState');
452  $mockState->expects($this->once())->method('popNodeFromStack')->will($this->returnValue($mockNodeOnStack));
453 
454  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('dummy'));
455 
456  $templateParser->_call('closingViewHelperTagHandler', $mockState, 'f', 'method');
457  }
458 
464  $mockNodeOnStack = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ViewHelperNode', array(), array(), '', FALSE);
465  $mockState = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsingState');
466  $mockState->expects($this->once())->method('popNodeFromStack')->will($this->returnValue($mockNodeOnStack));
467 
468  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('dummy'));
469 
470  $templateParser->_call('closingViewHelperTagHandler', $mockState, 'f', 'method');
471  }
472 
477  $mockState = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsingState');
478  $mockState->expects($this->exactly(2))->method('popNodeFromStack')->will($this->returnValue($this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\NodeInterface')));
479 
480  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('recursiveArrayHandler', 'postProcessArgumentsForObjectAccessor', 'initializeViewHelperAndAddItToStack'));
481  $templateParser->expects($this->at(0))->method('recursiveArrayHandler')->with('format: "H:i"')->will($this->returnValue(array('format' => 'H:i')));
482  $templateParser->expects($this->at(1))->method('postProcessArgumentsForObjectAccessor')->with(array('format' => 'H:i'))->will($this->returnValue(array('processedArguments')));
483  $templateParser->expects($this->at(2))->method('initializeViewHelperAndAddItToStack')->with($mockState, 'f', 'format.date', array('processedArguments'));
484  $templateParser->expects($this->at(3))->method('initializeViewHelperAndAddItToStack')->with($mockState, 'f', 'base', array());
485 
486  $templateParser->_call('objectAccessorHandler', $mockState, '', '', 'f:base() f:format.date(format: "H:i")', '');
487  }
488 
493  $objectAccessorNode = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ObjectAccessorNode', array(), array(), '', FALSE);
494 
495  $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
496  $mockObjectManager->expects($this->once())->method('get')->with('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ObjectAccessorNode', 'objectAccessorString')->will($this->returnValue($objectAccessorNode));
497 
498  $mockNodeOnStack = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\AbstractNode', array(), array(), '', FALSE);
499  $mockNodeOnStack->expects($this->once())->method('addChildNode')->with($objectAccessorNode);
500  $mockState = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsingState');
501  $mockState->expects($this->once())->method('getNodeFromStack')->will($this->returnValue($mockNodeOnStack));
502 
503  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('dummy'));
504  $templateParser->_set('objectManager', $mockObjectManager);
505 
506  $templateParser->_call('objectAccessorHandler', $mockState, 'objectAccessorString', '', '', '');
507  }
508 
513  $objectAccessorNode = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ObjectAccessorNode', array(), array(), '', FALSE);
514  $objectAccessorNodeInterceptor = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\InterceptorInterface');
515  $objectAccessorNodeInterceptor->expects($this->once())->method('process')->with($objectAccessorNode)->will($this->returnArgument(0));
516 
517  $parserConfiguration = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\Configuration');
518  $parserConfiguration->expects($this->once())->method('getInterceptors')->with(\TYPO3\CMS\Fluid\Core\Parser\InterceptorInterface::INTERCEPT_OBJECTACCESSOR)->will($this->returnValue(array($objectAccessorNodeInterceptor)));
519 
520  $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
521  $mockObjectManager->expects($this->once())->method('get')->will($this->returnValue($objectAccessorNode));
522 
523  $mockNodeOnStack = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\AbstractNode', array(), array(), '', FALSE);
524  $mockState = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsingState');
525  $mockState->expects($this->once())->method('getNodeFromStack')->will($this->returnValue($mockNodeOnStack));
526 
527  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('dummy'));
528  $templateParser->_set('objectManager', $mockObjectManager);
529  $templateParser->_set('configuration', $parserConfiguration);
530 
531  $templateParser->_call('objectAccessorHandler', $mockState, 'objectAccessorString', '', '', '');
532  }
533 
536  public function argumentsStrings() {
537  return array(
538  array('a="2"', array('a' => '2')),
539  array('a="2" b="foobar \' with \\" quotes"', array('a' => '2', 'b' => 'foobar \' with " quotes')),
540  array(' arguments="{number : 362525200}"', array('arguments' => '{number : 362525200}'))
541  );
542  }
543 
550  public function parseArgumentsWorksAsExpected($argumentsString, array $expected) {
551  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('buildArgumentObjectTree'));
552  $templateParser->expects($this->any())->method('buildArgumentObjectTree')->will($this->returnArgument(0));
553 
554  $this->assertSame($expected, $templateParser->_call('parseArguments', $argumentsString));
555  }
556 
561  $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
562  $mockObjectManager->expects($this->once())->method('get')->with('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\TextNode', 'a very plain string')->will($this->returnValue('theTextNode'));
563 
564  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('dummy'));
565  $templateParser->_set('objectManager', $mockObjectManager);
566 
567  $this->assertEquals('theTextNode', $templateParser->_call('buildArgumentObjectTree', 'a very plain string'));
568  }
569 
574  $objectTree = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsingState');
575  $objectTree->expects($this->once())->method('getRootNode')->will($this->returnValue('theRootNode'));
576 
577  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('splitTemplateAtDynamicTags', 'buildObjectTree'));
578  $templateParser->expects($this->at(0))->method('splitTemplateAtDynamicTags')->with('a <very> {complex} string')->will($this->returnValue('split string'));
579  $templateParser->expects($this->at(1))->method('buildObjectTree')->with('split string')->will($this->returnValue($objectTree));
580 
581  $this->assertEquals('theRootNode', $templateParser->_call('buildArgumentObjectTree', 'a <very> {complex} string'));
582  }
583 
588  $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
589  $mockObjectManager->expects($this->any())->method('get')->will($this->returnArgument(1));
590  $mockState = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsingState');
591 
592  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('objectAccessorHandler', 'arrayHandler', 'textHandler'));
593  $templateParser->_set('objectManager', $mockObjectManager);
594  $templateParser->expects($this->at(0))->method('objectAccessorHandler')->with($mockState, 'someThing.absolutely', '', '', '');
595  $templateParser->expects($this->at(1))->method('textHandler')->with($mockState, ' "fishy" is \'going\' ');
596  $templateParser->expects($this->at(2))->method('arrayHandler')->with($mockState, 'on: "here"');
597 
598  $text = '{someThing.absolutely} "fishy" is \'going\' {on: "here"}';
599  $templateParser->_call('textAndShorthandSyntaxHandler', $mockState, $text, \TYPO3\CMS\Fluid\Core\Parser\TemplateParser::CONTEXT_INSIDE_VIEWHELPER_ARGUMENTS);
600  }
601 
606  $arrayNode = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ArrayNode', array(), array(array()));
607  $mockNodeOnStack = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\AbstractNode', array(), array(), '', FALSE);
608  $mockNodeOnStack->expects($this->once())->method('addChildNode')->with($arrayNode);
609  $mockState = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsingState');
610  $mockState->expects($this->once())->method('getNodeFromStack')->will($this->returnValue($mockNodeOnStack));
611 
612  $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
613  $mockObjectManager->expects($this->once())->method('get')->with('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ArrayNode', 'processedArrayText')->will($this->returnValue($arrayNode));
614 
615  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('recursiveArrayHandler'));
616  $templateParser->_set('objectManager', $mockObjectManager);
617  $templateParser->expects($this->once())->method('recursiveArrayHandler')->with('arrayText')->will($this->returnValue('processedArrayText'));
618 
619  $templateParser->_call('arrayHandler', $mockState, 'arrayText');
620  }
621 
624  public function arrayTexts() {
625  return array(
626  array(
627  'key1: "foo", key2: \'bar\', key3: someVar, key4: 123, key5: { key6: "baz" }',
628  array('key1' => 'foo', 'key2' => 'bar', 'key3' => 'someVar', 'key4' => 123.0, 'key5' => array('key6' => 'baz'))
629  ),
630  array(
631  'key1: "\'foo\'", key2: \'\\\'bar\\\'\'',
632  array('key1' => '\'foo\'', 'key2' => '\'bar\'')
633  )
634  );
635  }
636 
641  public function recursiveArrayHandlerReturnsExpectedArray($arrayText, $expectedArray) {
642  $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
643  $mockObjectManager->expects($this->any())->method('get')->will($this->returnArgument(1));
644 
645  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('buildArgumentObjectTree'));
646  $templateParser->_set('objectManager', $mockObjectManager);
647  $templateParser->expects($this->any())->method('buildArgumentObjectTree')->will($this->returnArgument(0));
648 
649  $this->assertSame($expectedArray, $templateParser->_call('recursiveArrayHandler', $arrayText));
650  }
651 
656  $textNode = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\TextNode', array(), array(), '', FALSE);
657  $textInterceptor = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\InterceptorInterface');
658  $textInterceptor->expects($this->once())->method('process')->with($textNode)->will($this->returnArgument(0));
659 
660  $parserConfiguration = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\Configuration');
661  $parserConfiguration->expects($this->once())->method('getInterceptors')->with(\TYPO3\CMS\Fluid\Core\Parser\InterceptorInterface::INTERCEPT_TEXT)->will($this->returnValue(array($textInterceptor)));
662 
663  $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
664  $mockObjectManager->expects($this->once())->method('get')->with('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\TextNode', 'string')->will($this->returnValue($textNode));
665 
666  $mockNodeOnStack = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\AbstractNode', array(), array(), '', FALSE);
667  $mockNodeOnStack->expects($this->once())->method('addChildNode')->with($textNode);
668  $mockState = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsingState');
669  $mockState->expects($this->once())->method('getNodeFromStack')->will($this->returnValue($mockNodeOnStack));
670 
671  $templateParser = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser', array('splitTemplateAtDynamicTags', 'buildObjectTree'));
672  $templateParser->_set('objectManager', $mockObjectManager);
673  $templateParser->_set('configuration', $parserConfiguration);
674 
675  $templateParser->_call('textHandler', $mockState, 'string');
676  }
677 }
parseArgumentsWorksAsExpected($argumentsString, array $expected)
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.