2 namespace TYPO3\CMS\Fluid\Tests\Unit\Core\Parser;
25 $this->assertEquals(preg_match($pattern,
'{namespace acme=Tx_AcmeMyPackage_Bla_blubb}'), 1,
'The SCAN_PATTERN_NAMESPACEDECLARATION pattern did not match a namespace declaration (1).');
26 $this->assertEquals(preg_match($pattern,
'{namespace acme=Tx_AcmeMyPackage_Bla_Blubb }'), 1,
'The SCAN_PATTERN_NAMESPACEDECLARATION pattern did not match a namespace declaration (2).');
27 $this->assertEquals(preg_match($pattern,
' {namespace foo = Tx_Foo_Bla3_Blubb } '), 1,
'The SCAN_PATTERN_NAMESPACEDECLARATION pattern did not match a namespace declaration (3).');
28 $this->assertEquals(preg_match($pattern,
' \\{namespace fblubb = Tx_Fluid_Bla3_Blubb }'), 0,
'The SCAN_PATTERN_NAMESPACEDECLARATION pattern did match a namespace declaration even if it was escaped. (1)');
29 $this->assertEquals(preg_match($pattern,
'\\{namespace typo3 = Tx_TYPO3_Bla3_Blubb }'), 0,
'The SCAN_PATTERN_NAMESPACEDECLARATION pattern did match a namespace declaration even if it was escaped. (2)');
38 $this->assertEquals(preg_match($pattern,
'{namespace acme=Acme.MyPackage\Bla\blubb}'), 1,
'The SCAN_PATTERN_NAMESPACEDECLARATION pattern did not match a namespace declaration (1).');
39 $this->assertEquals(preg_match($pattern,
'{namespace acme=Acme.MyPackage\Bla\Blubb }'), 1,
'The SCAN_PATTERN_NAMESPACEDECLARATION pattern did not match a namespace declaration (2).');
40 $this->assertEquals(preg_match($pattern,
' {namespace foo = Foo\Bla3\Blubb } '), 1,
'The SCAN_PATTERN_NAMESPACEDECLARATION pattern did not match a namespace declaration (3).');
41 $this->assertEquals(preg_match($pattern,
' \\{namespace fblubb = TYPO3.Fluid\Bla3\Blubb }'), 0,
'The SCAN_PATTERN_NAMESPACEDECLARATION pattern did match a namespace declaration even if it was escaped. (1)');
42 $this->assertEquals(preg_match($pattern,
'\\{namespace typo3 = TYPO3.TYPO3\Bla3\Blubb }'), 0,
'The SCAN_PATTERN_NAMESPACEDECLARATION pattern did match a namespace declaration even if it was escaped. (2)');
52 $source =
'<html><head> <f:a.testing /> <f:blablubb> {testing}</f4:blz> </t3:hi.jo>';
53 $expected = array(
'<html><head> ',
'<f:a.testing />',
' ',
'<f:blablubb>',
' {testing}</f4:blz> ',
'</t3:hi.jo>');
54 $this->assertEquals(preg_split($pattern, $source, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY), $expected,
'The SPLIT_PATTERN_DYNAMICTAGS pattern did not split the input string correctly with simple tags.');
56 $source =
'hi<f:testing attribute="Hallo>{yep}" nested:attribute="jup" />ja';
57 $expected = array(
'hi',
'<f:testing attribute="Hallo>{yep}" nested:attribute="jup" />',
'ja');
58 $this->assertEquals(preg_split($pattern, $source, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY), $expected,
'The SPLIT_PATTERN_DYNAMICTAGS pattern did not split the input string correctly with > inside an attribute.');
60 $source =
'hi<f:testing attribute="Hallo\\"{yep}" nested:attribute="jup" />ja';
61 $expected = array(
'hi',
'<f:testing attribute="Hallo\\"{yep}" nested:attribute="jup" />',
'ja');
62 $this->assertEquals(preg_split($pattern, $source, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY), $expected,
'The SPLIT_PATTERN_DYNAMICTAGS pattern did not split the input string correctly if a " is inside a double-quoted string.');
64 $source =
'hi<f:testing attribute=\'Hallo>{yep}\' nested:attribute="jup" />ja';
65 $expected = array(
'hi',
'<f:testing attribute=\'Hallo>{yep}\' nested:attribute="jup" />',
'ja');
66 $this->assertEquals(preg_split($pattern, $source, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY), $expected,
'The SPLIT_PATTERN_DYNAMICTAGS pattern did not split the input string correctly with single quotes as attribute delimiters.');
68 $source =
'hi<f:testing attribute=\'Hallo\\\'{yep}\' nested:attribute="jup" />ja';
69 $expected = array(
'hi',
'<f:testing attribute=\'Hallo\\\'{yep}\' nested:attribute="jup" />',
'ja');
70 $this->assertEquals(preg_split($pattern, $source, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY), $expected,
'The SPLIT_PATTERN_DYNAMICTAGS pattern did not split the input string correctly if \' is inside a single-quoted attribute.');
72 $source =
'Hallo <f:testing><![CDATA[<f:notparsed>]]></f:testing>';
73 $expected = array(
'Hallo ',
'<f:testing>',
'<![CDATA[<f:notparsed>]]>',
'</f:testing>');
74 $this->assertEquals(preg_split($pattern, $source, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY), $expected,
'The SPLIT_PATTERN_DYNAMICTAGS pattern did not split the input string correctly if there is a CDATA section the parser should ignore.');
76 $veryLongViewHelper =
'<f:form enctype="multipart/form-data" onsubmit="void(0)" onreset="void(0)" action="someAction" arguments="{arg1: \'val1\', arg2: \'val2\'}" controller="someController" package="YourCompanyName.somePackage" subpackage="YourCompanyName.someSubpackage" section="someSection" format="txt" additionalParams="{param1: \'val1\', param2: \'val2\'}" absolute="true" addQueryString="true" argumentsToBeExcludedFromQueryString="{0: \'foo\'}" />';
77 $source = $veryLongViewHelper .
'Begin' . $veryLongViewHelper .
'End';
78 $expected = array($veryLongViewHelper,
'Begin', $veryLongViewHelper,
'End');
79 $this->assertEquals(preg_split($pattern, $source, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY), $expected,
'The SPLIT_PATTERN_DYNAMICTAGS pattern did not split the input string correctly if the VH has lots of arguments.');
81 $source =
'<f:a.testing data-bar="foo"> <f:a.testing>';
82 $expected = array(
'<f:a.testing data-bar="foo">',
' ',
'<f:a.testing>');
83 $this->assertEquals(preg_split($pattern, $source, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY), $expected,
'The SPLIT_PATTERN_DYNAMICTAGS pattern did not split the input string correctly with data- attribute.');
92 $source =
'<f:crop attribute="Hallo">';
94 0 =>
'<f:crop attribute="Hallo">',
95 'NamespaceIdentifier' =>
'f',
97 'MethodIdentifier' =>
'crop',
99 'Attributes' =>
' attribute="Hallo"',
100 3 =>
' attribute="Hallo"',
104 preg_match($pattern, $source, $matches);
105 $this->assertEquals($expected, $matches,
'The SCAN_PATTERN_DYNAMICTAG does not match correctly.');
108 $source =
'<f:crop data-attribute="Hallo">';
110 0 =>
'<f:crop data-attribute="Hallo">',
111 'NamespaceIdentifier' =>
'f',
113 'MethodIdentifier' =>
'crop',
115 'Attributes' =>
' data-attribute="Hallo"',
116 3 =>
' data-attribute="Hallo"',
120 preg_match($pattern, $source, $matches);
121 $this->assertEquals($expected, $matches,
'The SCAN_PATTERN_DYNAMICTAG does not match correctly with data- attributes.');
123 $source =
'<f:base />';
126 'NamespaceIdentifier' =>
'f',
128 'MethodIdentifier' =>
'base',
132 'Selfclosing' =>
'/',
135 preg_match($pattern, $source, $matches);
136 $this->assertEquals($expected, $matches,
'The SCAN_PATTERN_DYNAMICTAG does not match correctly when there is a space before the self-closing tag.');
138 $source =
'<f:crop attribute="Ha\\"llo"/>';
140 0 =>
'<f:crop attribute="Ha\\"llo"/>',
141 'NamespaceIdentifier' =>
'f',
143 'MethodIdentifier' =>
'crop',
145 'Attributes' =>
' attribute="Ha\\"llo"',
146 3 =>
' attribute="Ha\\"llo"',
147 'Selfclosing' =>
'/',
150 preg_match($pattern, $source, $matches);
151 $this->assertEquals($expected, $matches,
'The SCAN_PATTERN_DYNAMICTAG does not match correctly with self-closing tags.');
153 $source =
'<f:link.uriTo complex:attribute="Ha>llo" a="b" c=\'d\'/>';
155 0 =>
'<f:link.uriTo complex:attribute="Ha>llo" a="b" c=\'d\'/>',
156 'NamespaceIdentifier' =>
'f',
158 'MethodIdentifier' =>
'link.uriTo',
160 'Attributes' =>
' complex:attribute="Ha>llo" a="b" c=\'d\'',
161 3 =>
' complex:attribute="Ha>llo" a="b" c=\'d\'',
162 'Selfclosing' =>
'/',
165 preg_match($pattern, $source, $matches);
166 $this->assertEquals($expected, $matches,
'The SCAN_PATTERN_DYNAMICTAG does not match correctly with complex attributes and > inside the attributes.');
175 $this->assertEquals(preg_match($pattern,
'</f:bla>'), 1,
'The SCAN_PATTERN_CLOSINGDYNAMICTAG does not match a tag it should match.');
176 $this->assertEquals(preg_match($pattern,
'</f:bla.a >'), 1,
'The SCAN_PATTERN_CLOSINGDYNAMICTAG does not match a tag (with spaces included) it should match.');
177 $this->assertEquals(preg_match($pattern,
'</t:bla>'), 0,
'The SCAN_PATTERN_CLOSINGDYNAMICTAG does match match a tag it should not match.');
185 $pattern = \TYPO3\CMS\Fluid\Core\Parser\TemplateParser::$SPLIT_PATTERN_TAGARGUMENTS;
186 $source =
' test="Hallo" argument:post="\'Web" other=\'Single"Quoted\' data-foo="bar"';
187 $this->assertEquals(preg_match_all($pattern, $source, $matches, PREG_SET_ORDER), 4,
'The SPLIT_PATTERN_TAGARGUMENTS does not match correctly.');
188 $this->assertEquals(
'data-foo', $matches[3][
'Argument']);
198 $source =
'some string{Object.bla}here as well';
199 $expected = array(
'some string',
'{Object.bla}',
'here as well');
200 $this->assertEquals(preg_split($pattern, $source, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY), $expected,
'The SPLIT_PATTERN_SHORTHANDSYNTAX pattern did not split the input string correctly with a simple example.');
202 $source =
'some {}string\\{Object.bla}here as well';
203 $expected = array(
'some {}string\\',
'{Object.bla}',
'here as well');
204 $this->assertEquals(preg_split($pattern, $source, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY), $expected,
'The SPLIT_PATTERN_SHORTHANDSYNTAX pattern did not split the input string correctly with an escaped example. (1)');
206 $source =
'some {f:viewHelper()} as well';
207 $expected = array(
'some ',
'{f:viewHelper()}',
' as well');
208 $this->assertEquals(preg_split($pattern, $source, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY), $expected,
'The SPLIT_PATTERN_SHORTHANDSYNTAX pattern did not split the input string correctly with an escaped example. (2)');
210 $source =
'abc {f:for(arg1: post)} def';
211 $expected = array(
'abc ',
'{f:for(arg1: post)}',
' def');
212 $this->assertEquals(preg_split($pattern, $source, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY), $expected,
'The SPLIT_PATTERN_SHORTHANDSYNTAX pattern did not split the input string correctly with an escaped example.(3)');
214 $source =
'abc {bla.blubb->f:for(param:42)} def';
215 $expected = array(
'abc ',
'{bla.blubb->f:for(param:42)}',
' def');
216 $this->assertEquals(preg_split($pattern, $source, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY), $expected,
'The SPLIT_PATTERN_SHORTHANDSYNTAX pattern did not split the input string correctly with an escaped example.(4)');
219 $source =
'abc {f:for(bla:"post{{")} def';
220 $expected = array(
'abc ',
'{f:for(bla:"post{{")}',
' def');
221 $this->assertEquals(preg_split($pattern, $source, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY), $expected,
'The SPLIT_PATTERN_SHORTHANDSYNTAX pattern did not split the input string correctly with an escaped example.(5)');
223 $source =
'abc {f:for(param:"abc\\"abc")} def';
224 $expected = array(
'abc ',
'{f:for(param:"abc\\"abc")}',
' def');
225 $this->assertEquals(preg_split($pattern, $source, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY), $expected,
'The SPLIT_PATTERN_SHORTHANDSYNTAX pattern did not split the input string correctly with an escaped example.(6)');
233 $pattern = \TYPO3\CMS\Fluid\Core\Parser\TemplateParser::$SPLIT_PATTERN_SHORTHANDSYNTAX_VIEWHELPER;
235 $source =
'f:for(each: bla)';
238 0 =>
'f:for(each: bla)',
240 'NamespaceIdentifier' =>
'f',
242 'MethodIdentifier' =>
'for',
244 'ViewHelperArguments' =>
'each: bla'
247 preg_match_all($pattern, $source, $matches, PREG_SET_ORDER);
248 $this->assertEquals($matches, $expected,
'The SPLIT_PATTERN_SHORTHANDSYNTAX_VIEWHELPER');
250 $source =
'f:for(each: bla)->g:bla(a:"b\\"->(f:a()", cd: {a:b})';
253 0 =>
'f:for(each: bla)',
255 'NamespaceIdentifier' =>
'f',
257 'MethodIdentifier' =>
'for',
259 'ViewHelperArguments' =>
'each: bla'
262 0 =>
'g:bla(a:"b\\"->(f:a()", cd: {a:b})',
264 'NamespaceIdentifier' =>
'g',
266 'MethodIdentifier' =>
'bla',
267 3 =>
'a:"b\\"->(f:a()", cd: {a:b}',
268 'ViewHelperArguments' =>
'a:"b\\"->(f:a()", cd: {a:b}'
271 preg_match_all($pattern, $source, $matches, PREG_SET_ORDER);
272 $this->assertEquals($matches, $expected,
'The SPLIT_PATTERN_SHORTHANDSYNTAX_VIEWHELPER');
280 $pattern = \TYPO3\CMS\Fluid\Core\Parser\TemplateParser::$SCAN_PATTERN_SHORTHANDSYNTAX_OBJECTACCESSORS;
281 $this->assertEquals(preg_match($pattern,
'{object}'), 1,
'Object accessor not identified!');
282 $this->assertEquals(preg_match($pattern,
'{oBject1}'), 1,
'Object accessor not identified if there is a number and capitals inside!');
283 $this->assertEquals(preg_match($pattern,
'{object.recursive}'), 1,
'Object accessor not identified if there is a dot inside!');
284 $this->assertEquals(preg_match($pattern,
'{object-with-dash.recursive_value}'), 1,
'Object accessor not identified if there is a _ or - inside!');
285 $this->assertEquals(preg_match($pattern,
'{f:for()}'), 1,
'Object accessor not identified if it contains only of a ViewHelper.');
286 $this->assertEquals(preg_match($pattern,
'{f:for()->f:for2()}'), 1,
'Object accessor not identified if it contains only of a ViewHelper (nested).');
287 $this->assertEquals(preg_match($pattern,
'{abc->f:for()}'), 1,
'Object accessor not identified if there is a ViewHelper inside!');
288 $this->assertEquals(preg_match($pattern,
'{bla-blubb.recursive_value->f:for()->f:for()}'), 1,
'Object accessor not identified if there is a recursive ViewHelper inside!');
289 $this->assertEquals(preg_match($pattern,
'{f:for(arg1:arg1value, arg2: "bla\\"blubb")}'), 1,
'Object accessor not identified if there is an argument inside!');
290 $this->assertEquals(preg_match($pattern,
'{dash:value}'), 0,
'Object accessor identified, but was array!');
299 $pattern = \TYPO3\CMS\Fluid\Core\Parser\TemplateParser::$SCAN_PATTERN_SHORTHANDSYNTAX_ARRAYS;
300 $this->assertEquals(preg_match($pattern,
'{a:b}'), 1,
'Array syntax not identified!');
301 $this->assertEquals(preg_match($pattern,
'{a:b, c : d}'), 1,
'Array syntax not identified in case there are multiple properties!');
302 $this->assertEquals(preg_match($pattern,
'{a : 123}'), 1,
'Array syntax not identified when a number is passed as argument!');
303 $this->assertEquals(preg_match($pattern,
'{a:"String"}'), 1,
'Array syntax not identified in case of a double quoted string!');
304 $this->assertEquals(preg_match($pattern,
'{a:\'String\'}'), 1,
'Array syntax not identified in case of a single quoted string!');
306 $expected =
'{a:{bla:{x:z}, b: a}}';
307 preg_match($pattern, $expected, $match);
308 $this->assertEquals($match[0], $expected,
'If nested arrays appear, the string is not parsed correctly.');
310 $expected =
'{a:"{bla{{}"}';
311 preg_match($pattern, $expected, $match);
312 $this->assertEquals($match[0], $expected,
'If nested strings with {} inside appear, the string is not parsed correctly.');
320 $pattern = \TYPO3\CMS\Fluid\Core\Parser\TemplateParser::$SPLIT_PATTERN_SHORTHANDSYNTAX_ARRAY_PARTS;
322 $source =
'{a: b, e: {c:d, e:f}}';
323 preg_match_all($pattern, $source, $matches, PREG_SET_ORDER);
328 'ArrayPart' =>
'a: b',
332 'QuotedString' =>
'',
334 'VariableIdentifier' =>
'b',
338 0 =>
'e: {c:d, e:f}',
339 'ArrayPart' =>
'e: {c:d, e:f}',
340 1 =>
'e: {c:d, e:f}',
343 'QuotedString' =>
'',
345 'VariableIdentifier' =>
'',
349 'Subarray' =>
'c:d, e:f',
353 $this->assertEquals($matches, $expected,
'The regular expression splitting the array apart does not work!');
363 $pattern = \TYPO3\CMS\Fluid\Core\Parser\TemplateParser::$SCAN_PATTERN_CDATA;
364 $this->assertEquals(preg_match($pattern,
'<!-- Test -->'), 0,
'The SCAN_PATTERN_CDATA matches a comment, but it should not.');
365 $this->assertEquals(preg_match($pattern,
'<![CDATA[This is some ]]>'), 1,
'The SCAN_PATTERN_CDATA does not match a simple CDATA string.');
366 $this->assertEquals(preg_match($pattern,
'<![CDATA[This is<bla:test> some ]]>'), 1,
'The SCAN_PATTERN_CDATA does not match a CDATA string with tags inside..');
378 return str_replace(
'NAMESPACE', implode(
'|', $namespace), $regularExpression);