|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Sylius\Bundle\UiBundle\Tests\DependencyInjection; |
|
15
|
|
|
|
|
16
|
|
|
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait; |
|
17
|
|
|
use PHPUnit\Framework\TestCase; |
|
18
|
|
|
use Sylius\Bundle\UiBundle\DependencyInjection\Configuration; |
|
19
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
20
|
|
|
|
|
21
|
|
|
final class ConfigurationTest extends TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
use ConfigurationTestCaseTrait; |
|
24
|
|
|
|
|
25
|
|
|
/** @test */ |
|
26
|
|
|
public function empty_configuration_triggers_no_errors(): void |
|
27
|
|
|
{ |
|
28
|
|
|
$this->assertConfigurationIsValid([[]], 'events'); |
|
29
|
|
|
$this->assertConfigurationIsValid([['events' => []]], 'events'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** @test */ |
|
33
|
|
|
public function empty_events_configuration_triggers_no_errors(): void |
|
34
|
|
|
{ |
|
35
|
|
|
$this->assertConfigurationIsValid([['events' => ['event_name' => []]]], 'events'); |
|
36
|
|
|
$this->assertConfigurationIsValid([['events' => ['event_name' => ['blocks' => []]]]], 'events'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** @test */ |
|
40
|
|
|
public function multiple_events_might_be_configured(): void |
|
41
|
|
|
{ |
|
42
|
|
|
$this->assertConfigurationIsValid([['events' => ['first_event' => [], 'second_event' => []]]], 'events'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** @test */ |
|
46
|
|
|
public function consecutive_event_configuration_are_merged(): void |
|
47
|
|
|
{ |
|
48
|
|
|
$this->assertProcessedConfigurationEquals( |
|
49
|
|
|
[ |
|
50
|
|
|
['events' => ['first_event' => []]], |
|
51
|
|
|
['events' => ['second_event' => []]], |
|
52
|
|
|
], |
|
53
|
|
|
['events' => ['first_event' => ['blocks' => []], 'second_event' => ['blocks' => []]]], |
|
54
|
|
|
'events' |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** @test */ |
|
59
|
|
|
public function event_configuration_has_block_configuration(): void |
|
60
|
|
|
{ |
|
61
|
|
|
$this->assertConfigurationIsValid( |
|
62
|
|
|
[['events' => ['event_name' => ['blocks' => ['block_name' => ['template' => 'block.html.twig']]]]]], |
|
63
|
|
|
'events' |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** @test */ |
|
68
|
|
|
public function multiple_blocks_can_be_configured_for_an_event(): void |
|
69
|
|
|
{ |
|
70
|
|
|
$this->assertConfigurationIsValid( |
|
71
|
|
|
[['events' => ['event_name' => ['blocks' => [ |
|
72
|
|
|
'first_block' => ['template' => 'block.html.twig'], |
|
73
|
|
|
'second_block' => ['template' => 'block.html.twig'], |
|
74
|
|
|
]]]]], |
|
75
|
|
|
'events' |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** @test */ |
|
80
|
|
|
public function block_configuration_requires_template_to_be_defined(): void |
|
81
|
|
|
{ |
|
82
|
|
|
$this->assertPartialConfigurationIsInvalid( |
|
83
|
|
|
[['events' => ['event_name' => ['blocks' => ['block_name' => []]]]]], |
|
84
|
|
|
'events.*.blocks' |
|
85
|
|
|
); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** @test */ |
|
89
|
|
|
public function block_has_default_priority_set_to_zero(): void |
|
90
|
|
|
{ |
|
91
|
|
|
$this->assertProcessedConfigurationEquals( |
|
92
|
|
|
[['events' => ['event_name' => ['blocks' => ['block_name' => []]]]]], |
|
93
|
|
|
['events' => ['event_name' => ['blocks' => ['block_name' => ['priority' => 0]]]]], |
|
94
|
|
|
'events.*.blocks.*.priority' |
|
95
|
|
|
); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** @test */ |
|
99
|
|
|
public function block_priority_is_set_within_its_configuration(): void |
|
100
|
|
|
{ |
|
101
|
|
|
$this->assertProcessedConfigurationEquals( |
|
102
|
|
|
[['events' => ['event_name' => ['blocks' => ['block_name' => ['priority' => 100]]]]]], |
|
103
|
|
|
['events' => ['event_name' => ['blocks' => ['block_name' => ['priority' => 100]]]]], |
|
104
|
|
|
'events.*.blocks.*.priority' |
|
105
|
|
|
); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** @test */ |
|
109
|
|
|
public function block_is_enabled_by_default(): void |
|
110
|
|
|
{ |
|
111
|
|
|
$this->assertProcessedConfigurationEquals( |
|
112
|
|
|
[['events' => ['event_name' => ['blocks' => ['block_name' => []]]]]], |
|
113
|
|
|
['events' => ['event_name' => ['blocks' => ['block_name' => ['enabled' => true]]]]], |
|
114
|
|
|
'events.*.blocks.*.enabled' |
|
115
|
|
|
); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** @test */ |
|
119
|
|
|
public function block_can_be_disabled_within_its_configuration(): void |
|
120
|
|
|
{ |
|
121
|
|
|
$this->assertProcessedConfigurationEquals( |
|
122
|
|
|
[['events' => ['event_name' => ['blocks' => ['block_name' => ['enabled' => false]]]]]], |
|
123
|
|
|
['events' => ['event_name' => ['blocks' => ['block_name' => ['enabled' => false]]]]], |
|
124
|
|
|
'events.*.blocks.*.enabled' |
|
125
|
|
|
); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** @test */ |
|
129
|
|
|
public function block_configuration_can_be_shortened_to_template_string_only(): void |
|
130
|
|
|
{ |
|
131
|
|
|
$this->assertProcessedConfigurationEquals( |
|
132
|
|
|
[['events' => ['event_name' => ['blocks' => ['block_name' => 'template.html.twig']]]]], |
|
133
|
|
|
['events' => ['event_name' => ['blocks' => ['block_name' => ['template' => 'template.html.twig']]]]], |
|
134
|
|
|
'events.*.blocks.*.template' |
|
135
|
|
|
); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** @test */ |
|
139
|
|
|
public function consecutive_block_configurations_can_change_the_template(): void |
|
140
|
|
|
{ |
|
141
|
|
|
$this->assertProcessedConfigurationEquals( |
|
142
|
|
|
[ |
|
143
|
|
|
['events' => ['event_name' => ['blocks' => ['block_name' => 'template.html.twig']]]], |
|
144
|
|
|
['events' => ['event_name' => ['blocks' => ['block_name' => ['template' => 'another_template.html.twig']]]]], |
|
145
|
|
|
], |
|
146
|
|
|
['events' => ['event_name' => ['blocks' => ['block_name' => ['template' => 'another_template.html.twig']]]]], |
|
147
|
|
|
'events.*.blocks.*.template' |
|
148
|
|
|
); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** @test */ |
|
152
|
|
|
public function consecutive_block_configurations_can_change_the_priority(): void |
|
153
|
|
|
{ |
|
154
|
|
|
$this->assertProcessedConfigurationEquals( |
|
155
|
|
|
[ |
|
156
|
|
|
['events' => ['event_name' => ['blocks' => ['block_name' => ['priority' => 42]]]]], |
|
157
|
|
|
['events' => ['event_name' => ['blocks' => ['block_name' => ['priority' => 13]]]]], |
|
158
|
|
|
], |
|
159
|
|
|
['events' => ['event_name' => ['blocks' => ['block_name' => ['priority' => 13]]]]], |
|
160
|
|
|
'events.*.blocks.*.priority' |
|
161
|
|
|
); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** @test */ |
|
165
|
|
|
public function consecutive_block_configurations_can_disable_it(): void |
|
166
|
|
|
{ |
|
167
|
|
|
$this->assertProcessedConfigurationEquals( |
|
168
|
|
|
[ |
|
169
|
|
|
['events' => ['event_name' => ['blocks' => ['block_name' => ['enabled' => true]]]]], |
|
170
|
|
|
['events' => ['event_name' => ['blocks' => ['block_name' => ['enabled' => false]]]]], |
|
171
|
|
|
], |
|
172
|
|
|
['events' => ['event_name' => ['blocks' => ['block_name' => ['enabled' => false]]]]], |
|
173
|
|
|
'events.*.blocks.*.enabled' |
|
174
|
|
|
); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** @test */ |
|
178
|
|
|
public function consecutive_block_configurations_are_merged(): void |
|
179
|
|
|
{ |
|
180
|
|
|
$this->assertProcessedConfigurationEquals( |
|
181
|
|
|
[ |
|
182
|
|
|
['events' => ['event_name' => ['blocks' => ['first_block' => 'first.html.twig']]]], |
|
183
|
|
|
['events' => ['event_name' => ['blocks' => ['second_block' => 'second.html.twig']]]], |
|
184
|
|
|
], |
|
185
|
|
|
['events' => ['event_name' => ['blocks' => [ |
|
186
|
|
|
'first_block' => ['template' => 'first.html.twig'], |
|
187
|
|
|
'second_block' => ['template' => 'second.html.twig'], |
|
188
|
|
|
]]]], |
|
189
|
|
|
'events.*.blocks.*.template' |
|
190
|
|
|
); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** @test */ |
|
194
|
|
|
public function context_can_be_passed_to_the_block(): void |
|
195
|
|
|
{ |
|
196
|
|
|
$this->assertProcessedConfigurationEquals( |
|
197
|
|
|
[['events' => ['event_name' => ['blocks' => ['block_name' => ['context' => ['foo' => 'bar']]]]]]], |
|
198
|
|
|
['events' => ['event_name' => ['blocks' => ['block_name' => ['context' => ['foo' => 'bar']]]]]], |
|
199
|
|
|
'events.*.blocks.*.context' |
|
200
|
|
|
); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** @test */ |
|
204
|
|
|
public function consecutive_block_context_configuration_is_shallowly_merged(): void |
|
205
|
|
|
{ |
|
206
|
|
|
$this->assertProcessedConfigurationEquals( |
|
207
|
|
|
[ |
|
208
|
|
|
['events' => ['event_name' => ['blocks' => ['block_name' => ['context' => ['foo' => 'bar']]]]]], |
|
209
|
|
|
['events' => ['event_name' => ['blocks' => ['block_name' => ['context' => ['bar' => 'baz']]]]]], |
|
210
|
|
|
], |
|
211
|
|
|
['events' => ['event_name' => ['blocks' => ['block_name' => ['context' => ['foo' => 'bar', 'bar' => 'baz']]]]]], |
|
212
|
|
|
'events.*.blocks.*.context' |
|
213
|
|
|
); |
|
214
|
|
|
|
|
215
|
|
|
$this->assertProcessedConfigurationEquals( |
|
216
|
|
|
[ |
|
217
|
|
|
['events' => ['event_name' => ['blocks' => ['block_name' => ['context' => ['foo' => ['bar']]]]]]], |
|
218
|
|
|
['events' => ['event_name' => ['blocks' => ['block_name' => ['context' => ['foo' => ['baz']]]]]]], |
|
219
|
|
|
], |
|
220
|
|
|
['events' => ['event_name' => ['blocks' => ['block_name' => ['context' => ['foo' => ['baz']]]]]]], |
|
221
|
|
|
'events.*.blocks.*.context' |
|
222
|
|
|
); |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
protected function getConfiguration(): ConfigurationInterface |
|
226
|
|
|
{ |
|
227
|
|
|
return new Configuration(); |
|
228
|
|
|
} |
|
229
|
|
|
} |
|
230
|
|
|
|