forked from TYPO3/Fluid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraySyntaxTest.php
More file actions
119 lines (112 loc) · 4.55 KB
/
Copy pathArraySyntaxTest.php
File metadata and controls
119 lines (112 loc) · 4.55 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
<?php
declare(strict_types=1);
/*
* This file belongs to the package "TYPO3 Fluid".
* See LICENSE.txt that was shipped with this package.
*/
namespace TYPO3Fluid\Fluid\Tests\Functional\Cases\Parsing;
use TYPO3Fluid\Fluid\Tests\Functional\AbstractFunctionalTestCase;
use TYPO3Fluid\Fluid\View\TemplateView;
final class ArraySyntaxTest extends AbstractFunctionalTestCase
{
public static function arraySyntaxDataProvider(): array
{
return [
// Edge case: Fluid treats this expression as an object accessor instead of an array
'single array spread without whitespace' => [
'<f:variable name="result" value="{...input1}" />',
[
'input1' => ['abc' => 1, 'def' => 2],
],
null,
],
// Edge case: Fluid treats this expression as an object accessor instead of an array
'single array spread with whitespace after' => [
'<f:variable name="result" value="{...input1 }" />',
[
'input1' => ['abc' => 1, 'def' => 2],
],
null,
],
'single array spread with whitespace before' => [
'<f:variable name="result" value="{ ...input1}" />',
[
'input1' => ['abc' => 1, 'def' => 2],
],
['abc' => 1, 'def' => 2],
],
'single array spread' => [
'<f:variable name="result" value="{ ...input1 }" />',
[
'input1' => ['abc' => 1, 'def' => 2],
],
['abc' => 1, 'def' => 2],
],
'multiple array spreads' => [
'<f:variable name="result" value="{ ...input1, ...input2 }" />',
[
'input1' => ['abc' => 1, 'def' => 2],
'input2' => ['ghi' => 3],
],
['abc' => 1, 'def' => 2, 'ghi' => 3],
],
'multiple array spreads mixed with other items' => [
'<f:variable name="result" value="{ first: 1, ...input1, middle: \'middle value\', ...input2, last: { sub: 1 } }" />',
[
'input1' => ['abc' => 1, 'def' => 2],
'input2' => ['ghi' => 3],
],
['first' => 1, 'abc' => 1, 'def' => 2, 'middle' => 'middle value', 'ghi' => 3, 'last' => ['sub' => 1]],
],
'overwrite static value' => [
'<f:variable name="result" value="{ abc: 10, ...input1 }" />',
[
'input1' => ['abc' => 1, 'def' => 2],
],
['abc' => 1, 'def' => 2],
],
'overwrite spreaded value' => [
'<f:variable name="result" value="{ ...input1, abc: 10 }" />',
[
'input1' => ['abc' => 1, 'def' => 2],
],
['abc' => 10, 'def' => 2],
],
'overwrite spreaded value with spreaded value' => [
'<f:variable name="result" value="{ ...input1, ...input2 }" />',
[
'input1' => ['abc' => 1, 'def' => 2],
'input2' => ['abc' => 10],
],
['abc' => 10, 'def' => 2],
],
'whitespace variants' => [
'<f:variable name="result" value="{... input1 , ... input2}" />',
[
'input1' => ['abc' => 1, 'def' => 2],
'input2' => ['ghi' => 3],
],
['abc' => 1, 'def' => 2, 'ghi' => 3],
]
];
}
/**
* @test
* @dataProvider arraySyntaxDataProvider
*/
public function arraySyntax(string $source, array $variables, $expected): void
{
$view = new TemplateView();
$view->getRenderingContext()->setCache(self::$cache);
$view->getRenderingContext()->getTemplatePaths()->setTemplateSource($source);
$view->assignMultiple($variables);
$view->render();
self::assertSame($view->getRenderingContext()->getVariableProvider()->get('result'), $expected);
$view = new TemplateView();
$view->getRenderingContext()->setCache(self::$cache);
$view->getRenderingContext()->getTemplatePaths()->setTemplateSource($source);
$view->assignMultiple($variables);
$view->render();
self::assertSame($view->getRenderingContext()->getVariableProvider()->get('result'), $expected);
}
}