2 namespace TYPO3\CMS\Core\Tests\Unit\TypoScript\Parser
;
5 * This file is part of the TYPO3 CMS project.
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
18 * Test case for \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
20 class TypoScriptParserTest
extends \TYPO3\CMS\Core\Tests\UnitTestCase
{
23 * @var \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
25 protected $typoScriptParser = NULL;
32 protected function setUp() {
33 $accessibleClassName = $this->buildAccessibleProxy('TYPO3\\CMS\\Core\\TypoScript\\Parser\\TypoScriptParser');
34 $this->typoScriptParser
= new $accessibleClassName();
38 * Data provider for executeValueModifierReturnsModifiedResult
40 * @return array modifier name, modifier arguments, current value, expected result
42 public function executeValueModifierDataProvider() {
44 'prependString with string' => array(
50 'prependString with empty string' => array(
56 'appendString with string' => array(
62 'appendString with empty string' => array(
68 'removeString removes simple string' => array(
74 'removeString removes nothing if no match' => array(
80 'removeString removes multiple matches' => array(
86 'replaceString replaces simple match' => array(
92 'replaceString replaces simple match with nothing' => array(
98 'replaceString replaces multiple matches' => array(
104 'addToList adds at end of existing list' => array(
110 'addToList adds nothing' => array(
114 '123,456,', // This result is probably not what we want (appended comma) ... fix it?
116 'addToList adds to empty list' => array(
122 'removeFromList removes value from list' => array(
128 'removeFromList removes value at beginning of list' => array(
134 'removeFromList removes value at end of list' => array(
140 'removeFromList removes multiple values from list' => array(
146 'removeFromList removes empty values' => array(
152 'uniqueList removes duplicates' => array(
154 '123,456,abc,456,456',
158 'uniqueList removes duplicate empty list values' => array(
164 'reverseList returns list reversed' => array(
170 'reverseList keeps empty values' => array(
172 ',123,,456,abc,,456',
174 '456,,abc,456,,123,',
176 'reverseList does not change single element' => array(
182 'sortList sorts a list' => array(
188 'sortList sorts a list numeric' => array(
194 'sortList sorts a list descending' => array(
196 '10,100,0,20,abc,-20',
198 'abc,100,20,10,0,-20',
200 'sortList sorts a list numeric descending' => array(
202 '10,100,0,20,abc,-20',
203 'descending,numeric',
204 '100,20,10,0,abc,-20',
206 'sortList ignores invalid modifier arguments' => array(
209 'foo,descending,bar',
217 * @dataProvider executeValueModifierDataProvider
219 public function executeValueModifierReturnsModifiedResult($modifierName, $currentValue, $modifierArgument, $expected) {
220 $actualValue = $this->typoScriptParser
->_call('executeValueModifier', $modifierName, $modifierArgument, $currentValue);
221 $this->assertEquals($expected, $actualValue);
225 * @param string $typoScript
226 * @param array $expected
227 * @dataProvider typoScriptIsParsedToArrayDataProvider
230 public function typoScriptIsParsedToArray($typoScript, array $expected) {
231 $this->typoScriptParser
->parse($typoScript);
232 $this->assertEquals($expected, $this->typoScriptParser
->setup
);
238 public function typoScriptIsParsedToArrayDataProvider() {
240 'simple assignment' => array(
246 'simple assignment with escaped dot at the beginning' => array(
252 'simple assignment with protected escaped dot at the beginning' => array(
260 'nested assignment' => array(
268 'nested assignment with escaped key' => array(
271 'lib.key' => 'value',
274 'nested assignment with escaped key and escaped dot at the beginning' => array(
275 '\\.lib\\.key = value',
277 '.lib.key' => 'value',
280 'nested assignment with protected escaped key' => array(
281 'lib\\\\.key = value',
283 'lib\\.' => array('key' => 'value'),
286 'nested assignment with protected escaped key and protected escaped dot at the beginning' => array(
287 '\\\\.lib\\\\.key = value',
290 'lib\\.' => array('key' => 'value'),
294 'assignment with escaped an non escaped keys' => array(
295 'firstkey.secondkey\\.thirdkey.setting = value',
297 'firstkey.' => array(
298 'secondkey.thirdkey.' => array(
304 'nested structured assignment' => array(
314 'nested structured assignment with escaped key inside' => array(
316 'key\\.nextkey = value' . LF
.
320 'key.nextkey' => 'value',
324 'nested structured assignment with escaped key inside and escaped dots at the beginning' => array(
326 '\\.key\\.nextkey = value' . LF
.
330 '.key.nextkey' => 'value',
334 'nested structured assignment with protected escaped key inside' => array(
336 'key\\\\.nextkey = value' . LF
.
340 'key\\.' => array('nextkey' => 'value'),
344 'nested structured assignment with protected escaped key inside and protected escaped dots at the beginning' => array(
346 '\\\\.key\\\\.nextkey = value' . LF
.
352 'key\\.' => array('nextkey' => 'value'),
358 'nested structured assignment with escaped key' => array(
359 'lib\\.anotherkey {' . LF
.
363 'lib.anotherkey.' => array(
368 'nested structured assignment with protected escaped key' => array(
369 'lib\\\\.anotherkey {' . LF
.
374 'anotherkey.' => array(
380 'multiline assignment' => array(
386 'key' => 'first' . LF
. 'second',
389 'multiline assignment with escaped key' => array(
390 'key\\.nextkey (' . LF
.
395 'key.nextkey' => 'first' . LF
. 'second',
398 'multiline assignment with protected escaped key' => array(
399 'key\\\\.nextkey (' . LF
.
404 'key\\.' => array('nextkey' => 'first' . LF
. 'second'),
407 'copying values' => array(
408 'lib.default = value' . LF
.
409 'lib.copy < lib.default',
412 'default' => 'value',
417 'copying values with escaped key' => array(
418 'lib\\.default = value' . LF
.
419 'lib.copy < lib\\.default',
421 'lib.default' => 'value',
427 'copying values with protected escaped key' => array(
428 'lib\\\\.default = value' . LF
.
429 'lib.copy < lib\\\\.default',
431 'lib\\.' => array('default' => 'value'),
437 'one-line hash comment' => array(
439 '# ignore = me' . LF
.
446 'one-line slash comment' => array(
448 '// ignore = me' . LF
.
455 'multi-line slash comment' => array(
466 'nested assignment repeated segment names' => array(
467 'test.test.test = 1',
476 'simple assignment operator with tab character before "="' => array(
479 'test' => 'someValue',
482 'simple assignment operator character as value "="' => array(
488 'nested assignment operator character as value "="' => array(
496 'simple assignment character as value "<"' => array(
502 'nested assignment character as value "<"' => array(
510 'simple assignment character as value ">"' => array(
516 'nested assignment character as value ">"' => array(
524 'nested assignment repeated segment names with whitespaces' => array(
525 'test.test.test = 1' . " \t",
534 'simple assignment operator character as value "=" with whitespaces' => array(
535 'test = =TEST=' . " \t",
540 'nested assignment operator character as value "=" with whitespaces' => array(
541 'test.test = =TEST=' . " \t",
548 'simple assignment character as value "<" with whitespaces' => array(
549 'test = <TEST>' . " \t",
554 'nested assignment character as value "<" with whitespaces' => array(
555 'test.test = <TEST>' . " \t",
562 'simple assignment character as value ">" with whitespaces' => array(
563 'test = >TEST<' . " \t",
568 'nested assignment character as value ">" with whitespaces' => array(
569 'test.test = >TEST<',
576 'CSC example #1' => array(
577 'linkParams.ATagParams.dataWrap = class="{$styles.content.imgtext.linkWrap.lightboxCssClass}" rel="{$styles.content.imgtext.linkWrap.lightboxRelAttribute}"',
579 'linkParams.' => array(
580 'ATagParams.' => array(
581 'dataWrap' => 'class="{$styles.content.imgtext.linkWrap.lightboxCssClass}" rel="{$styles.content.imgtext.linkWrap.lightboxRelAttribute}"',
586 'CSC example #2' => array(
587 'linkParams.ATagParams {' . LF
.
588 'dataWrap = class="{$styles.content.imgtext.linkWrap.lightboxCssClass}" rel="{$styles.content.imgtext.linkWrap.lightboxRelAttribute}"' . LF
.
591 'linkParams.' => array(
592 'ATagParams.' => array(
593 'dataWrap' => 'class="{$styles.content.imgtext.linkWrap.lightboxCssClass}" rel="{$styles.content.imgtext.linkWrap.lightboxRelAttribute}"',
598 'CSC example #3' => array(
599 'linkParams.ATagParams.dataWrap (' . LF
.
600 'class="{$styles.content.imgtext.linkWrap.lightboxCssClass}" rel="{$styles.content.imgtext.linkWrap.lightboxRelAttribute}"' . LF
.
603 'linkParams.' => array(
604 'ATagParams.' => array(
605 'dataWrap' => 'class="{$styles.content.imgtext.linkWrap.lightboxCssClass}" rel="{$styles.content.imgtext.linkWrap.lightboxRelAttribute}"',
616 public function setValCanBeCalledWithArrayValueParameter() {
620 $this->typoScriptParser
->setVal($string, $setup, $value);
626 public function setValCanBeCalledWithStringValueParameter() {
630 $this->typoScriptParser
->setVal($string, $setup, $value);
635 * @dataProvider parseNextKeySegmentReturnsCorrectNextKeySegmentDataProvider
637 public function parseNextKeySegmentReturnsCorrectNextKeySegment($key, $expectedKeySegment, $expectedRemainingKey) {
638 list($keySegment, $remainingKey) = $this->typoScriptParser
->_call('parseNextKeySegment', $key);
639 $this->assertSame($expectedKeySegment, $keySegment);
640 $this->assertSame($expectedRemainingKey, $remainingKey);
646 public function parseNextKeySegmentReturnsCorrectNextKeySegmentDataProvider() {
648 'key without separator' => array(
653 'key with normal separator' => array(
658 'key with multiple normal separators' => array(
663 'key with separator and escape character' => array(
668 'key with escaped separators' => array(
669 'test\\.key\\.subkey',
673 'key with escaped and unescaped separator 1' => array(
678 'key with escaped and unescaped separator 2' => array(
679 'test\\.test.key\\.key2',
683 'key with escaped escape character' => array(
688 'key with escaped separator and additional escape character' => array(
694 'multiple escape characters within the key are preserved' => array(