-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathExamplesTest.php
More file actions
276 lines (268 loc) · 11.7 KB
/
Copy pathExamplesTest.php
File metadata and controls
276 lines (268 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<?php
namespace TYPO3Fluid\Fluid\Tests\Functional;
/*
* This file belongs to the package "TYPO3 Fluid".
* See LICENSE.txt that was shipped with this package.
*/
use org\bovigo\vfs\vfsStream;
use TYPO3Fluid\Fluid\Tests\BaseTestCase;
/**
* Class ExamplesTest
*/
class ExamplesTest extends BaseTestCase
{
/**
* @return void
*/
public static function setUpBeforeClass(): void
{
vfsStream::setup('fakecache/');
}
/**
* @dataProvider getExampleScriptTestValues
* @param string $script
* @param array $expectedOutputs
* @param string $expectedException
*/
public function testExampleScriptFileWithoutCache($script, array $expectedOutputs, $expectedException = null)
{
if ($expectedException !== null) {
$this->setExpectedException($expectedException);
}
$this->runExampleScriptTest($script, $expectedOutputs, false);
}
/**
* @dataProvider getExampleScriptTestValues
* @param string $script
* @param array $expectedOutputs
* @param string $expectedException
*/
public function testExampleScriptFileWithCache($script, array $expectedOutputs, $expectedException = null)
{
if ($expectedException !== null) {
$this->setExpectedException($expectedException);
}
$cache = vfsStream::url('fakecache/');
$this->runExampleScriptTest($script, $expectedOutputs, $cache);
$this->runExampleScriptTest($script, $expectedOutputs, $cache);
}
/**
* @param string $script
* @param array $expectedOutputs
* @param string $FLUID_CACHE_DIRECTORY
*/
protected function runExampleScriptTest($script, array $expectedOutputs, $FLUID_CACHE_DIRECTORY)
{
$scriptFile = __DIR__ . '/../../examples/' . $script;
$self = $this;
$this->setOutputCallback(function ($output) use ($self, $expectedOutputs) {
foreach ($expectedOutputs as $expectedOutput) {
$self->assertContains($expectedOutput, $output);
}
});
include $scriptFile;
unset($FLUID_CACHE_DIRECTORY);
}
/**
* @return array
*/
public function getExampleScriptTestValues()
{
return [
'example_conditions.php' => [
'example_conditions.php',
[
'Standard ternary expression: The ternary expression is TRUE',
'Negated ternary expression without then case: The ternary expression is FALSE',
'Negated ternary expression: The ternary expression is FALSE',
'Ternary expression without then case: The ternary expression is TRUE',
'1 === TRUE',
'(0) === FALSE',
'(1) === TRUE',
'0 && 0 === FALSE',
'0 || 0 === FALSE',
'1 && 0 === FALSE',
'0 && 1 === FALSE',
'1 || 0 === TRUE',
'0 || 1 === TRUE',
'0 || 1 && 0 === FALSE',
'0 || 1 && 1 === TRUE',
'$varfalse === FALSE',
'$vartrue === TRUE',
'!($vartrue) === FALSE',
'$vararray1 == $vararray2 === FALSE',
'($vararray1 == $vararray1) && $vartrue === TRUE',
'$varfalse == $varfalse === TRUE',
'$varfalse != $varfalse === FALSE',
'$vararray1 == $vararray1 === TRUE',
'\'thisstring\' != \'thatstring\' === TRUE'
]
],
'example_customresolving.php' => [
'example_customresolving.php',
[
var_export(['foo' => 'bar'], true),
var_export(['bar' => 'foo'], true),
]
],
'example_format.php' => [
'example_format.php',
[
'"layout": "Default.json",',
'"foobar": "Variable foobar"'
]
],
'example_layoutless.php' => [
'example_layoutless.php',
[
'This section is rendered below',
'This text is rendered because it is outside the section'
]
],
'example_math.php' => [
'example_math.php',
[
'Expression: $numberten % 4 = 2',
'Expression: 4 * $numberten = 40',
'Expression: 4 / $numberten = ' . (0.4), // NOTE: concat'ing a float + string LC-casts the float to localized comma/t-sep. Hence, let PHP also cast the expected value.
'Expression: $numberone / $numberten = ' . (0.1), // NOTE: concat'ing a float + string LC-casts the float to localized comma/t-sep. Hence, let PHP also cast the expected value.
'Expression: 10 ^ $numberten = 10000000000'
]
],
'example_multiplepaths.php' => [
'example_multiplepaths.php',
[
'Rendered via overridden Layout, section "Main":',
'Overridden Default template.',
'Value of "foobar": This is foobar.',
'Contents of FirstPartial.html',
'Overridden contents of SecondPartial.html',
]
],
'example_mvc.php' => [
'example_mvc.php',
[
'I am the template belonging to the "Default" controller, action "Default".',
'I am the template belonging to the "Other" controller, action "Default".',
'I am the template belonging to the "Other" controller, action "List".',
'Value of "foobar": MVC template.'
]
],
'example_namespaces.php' => [
'example_namespaces.php',
[
'Namespaces template',
'<invalid:vh>This tag will be shown</invalid:vh>'
]
],
'example_namespaceresolving.php' => [
'example_namespaceresolving.php',
[
'NamespaceResolving template from Singles.',
'Argument passed to CustomViewHelper:',
'123'
]
],
'example_single.php' => [
'example_single.php',
[
'Value of "foobar": Single template'
]
],
'example_escapingmodifier.php' => [
'example_escapingmodifier.php',
[
'Value of "html": <strong>This is not escaped</strong>',
'From partial: <strong>This is not escaped</strong>',
]
],
'example_structures.php' => [
'example_structures.php',
[
'Tag: "Dynamic"',
'Pass: "Dynamic"',
'Pipe: "Dynamic"',
'Pipe, multiple levels: "Dynamic"',
'This section exists and is rendered: Valid section',
'Expects no output because section name is invalid: ' . "\n",
'Dynamic section name: Dynamically suffixed section',
'Bad dynamic section name, expects fallback: Just a section',
'Will render: Just a section',
'Will render, clause reversed: Just a section',
'Will not render: ' . "\n",
'This `f:else` was rendered',
'The value was "3"',
'The unmatched value case triggered',
'The "b" nested switch case was triggered'
]
],
'example_variables.php' => [
'example_variables.php',
[
'Simple variable: string foo',
'A string with numbers in it: 132',
'Ditto, with type name stored in variable: 132',
'A comma-separated value iterated as array:' . "\n\t- one\n\t- two",
'String variable name with dynamic1 part: String using $dynamic1.',
'String variable name with dynamic2 part: String using $dynamic2.',
'Array member in $array[$dynamic1]: Dynamic key in $array[$dynamic1]',
'Array member in $array[$dynamic2]: Dynamic key in $array[$dynamic2]',
'Output of variable whose name is stored in a variable: string foo',
'Direct access of numeric prefixed variable: Numeric prefixed variable',
'Aliased access of numeric prefixed variable: Numeric prefixed variable',
'Escaped ternary expression: <b>Unescaped string</b>',
'Escaped cast expression: <b>Unescaped string</b>',
'Received $array.foobar with value <b>Unescaped string</b> (same using "value" argument: <b>Unescaped string</b>)',
'Received $array.printf with formatted string Formatted string, value: formatted',
'Received $array.baz with value 42',
'Received $array.xyz.foobar with value Escaped sub-string',
'Received $myVariable with value Nice string'
]
],
'example_variableprovider.php' => [
'example_variableprovider.php',
[
'VariableProvider template from Singles.',
'Random: random',
]
],
'example_dynamiclayout.php' => [
'example_dynamiclayout.php',
[
'Rendered via DynamicLayout, section "Main":',
]
],
'example_layoutcontentas.php' => [
'example_layoutcontentas.php',
[
'Content from layout via contentAs',
]
],
'example_cachestatic.php' => [
'example_cachestatic.php',
[
'Cached as static text 1',
'Cached as static text 2',
'Cached as static text 3',
]
],
'example_passthrough.php' => [
'example_passthrough.php',
[
'<f:format.raw>This does not get parsed; the source is passed through with Fluid markup</f:format.raw>'
]
],
'example_errorhandling.php' => [
'example_errorhandling.php',
[
'View error: The Fluid template files',
'Section rendering error: Section "DoesNotExist" does not exist. Section rendering is mandatory; "optional" is false.',
'ViewHelper error: Undeclared arguments passed to ViewHelper TYPO3Fluid\Fluid\ViewHelpers\IfViewHelper: notregistered. Valid arguments are: then, else, condition - Offending code: <f:if notregistered="1" />',
'Parser error: The ViewHelper "<f:invalid>" could not be resolved.',
'Based on your spelling, the system would load the class "TYPO3Fluid\Fluid\ViewHelpers\InvalidViewHelper", however this class does not exist. Offending code: <f:invalid />',
'Invalid expression: Invalid target conversion type "invalidtype" specified in casting expression "{foobar as invalidtype}".',
]
]
];
}
}