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\GridBundle\Tests\DependencyInjection; |
15
|
|
|
|
16
|
|
|
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait; |
17
|
|
|
use PHPUnit\Framework\TestCase; |
18
|
|
|
use Sylius\Bundle\GridBundle\DependencyInjection\Configuration; |
19
|
|
|
use Sylius\Bundle\GridBundle\Doctrine\ORM\Driver; |
20
|
|
|
|
21
|
|
|
final class ConfigurationTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
use ConfigurationTestCaseTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @test |
27
|
|
|
*/ |
28
|
|
|
public function it_requires_only_grid_name(): void |
29
|
|
|
{ |
30
|
|
|
$this->assertProcessedConfigurationEquals( |
31
|
|
|
[[ |
32
|
|
|
'grids' => [ |
33
|
|
|
'sylius_admin_tax_category' => null, |
34
|
|
|
], |
35
|
|
|
]], |
36
|
|
|
[ |
37
|
|
|
'grids' => [ |
38
|
|
|
'sylius_admin_tax_category' => [ |
39
|
|
|
'driver' => [ |
40
|
|
|
'name' => Driver::NAME, |
41
|
|
|
'options' => [], |
42
|
|
|
], |
43
|
|
|
'sorting' => [], |
44
|
|
|
'limits' => [10, 25, 50], |
45
|
|
|
'fields' => [], |
46
|
|
|
'filters' => [], |
47
|
|
|
'actions' => [], |
48
|
|
|
], |
49
|
|
|
], |
50
|
|
|
], |
51
|
|
|
'grids' |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @test |
57
|
|
|
*/ |
58
|
|
|
public function it_uses_doctrine_orm_as_default_driver(): void |
59
|
|
|
{ |
60
|
|
|
$this->assertProcessedConfigurationEquals( |
61
|
|
|
[[]], |
62
|
|
|
['drivers' => ['doctrine/orm']], |
63
|
|
|
'drivers' |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @test |
69
|
|
|
*/ |
70
|
|
|
public function it_has_empty_action_and_filter_templates_by_default(): void |
71
|
|
|
{ |
72
|
|
|
$this->assertProcessedConfigurationEquals( |
73
|
|
|
[[]], |
74
|
|
|
[ |
75
|
|
|
'templates' => [ |
76
|
|
|
'action' => [], |
77
|
|
|
'filter' => [], |
78
|
|
|
], |
79
|
|
|
], |
80
|
|
|
'templates' |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @test |
86
|
|
|
*/ |
87
|
|
|
public function its_driver_cannot_be_empty(): void |
88
|
|
|
{ |
89
|
|
|
$this->assertConfigurationIsInvalid([[ |
90
|
|
|
'grids' => [ |
91
|
|
|
'sylius_admin_tax_category' => [ |
92
|
|
|
'driver' => [ |
93
|
|
|
'name' => null, |
94
|
|
|
], |
95
|
|
|
], |
96
|
|
|
], |
97
|
|
|
]]); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @test |
102
|
|
|
*/ |
103
|
|
|
public function it_requires_field_type_to_be_defined(): void |
104
|
|
|
{ |
105
|
|
|
$this->assertConfigurationIsInvalid([[ |
106
|
|
|
'grids' => [ |
107
|
|
|
'sylius_admin_tax_category' => [ |
108
|
|
|
'fields' => [ |
109
|
|
|
'code' => [ |
110
|
|
|
'label' => 'Internal code', |
111
|
|
|
], |
112
|
|
|
], |
113
|
|
|
], |
114
|
|
|
], |
115
|
|
|
]]); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @test |
120
|
|
|
*/ |
121
|
|
|
public function its_base_sorting_can_be_overwritten(): void |
122
|
|
|
{ |
123
|
|
|
$this->assertProcessedConfigurationEquals( |
124
|
|
|
[ |
125
|
|
|
['grids' => [ |
126
|
|
|
'sylius_admin_tax_category' => [ |
127
|
|
|
'sorting' => ['code' => 'asc'], |
128
|
|
|
], |
129
|
|
|
]], |
130
|
|
|
['grids' => [ |
131
|
|
|
'sylius_admin_tax_category' => [ |
132
|
|
|
'sorting' => ['name' => 'desc'], |
133
|
|
|
], |
134
|
|
|
]], |
135
|
|
|
], |
136
|
|
|
['grids' => [ |
137
|
|
|
'sylius_admin_tax_category' => [ |
138
|
|
|
'sorting' => ['name' => 'desc'], |
139
|
|
|
], |
140
|
|
|
]], |
141
|
|
|
'grids.*.sorting' |
142
|
|
|
); |
143
|
|
|
|
144
|
|
|
$this->assertProcessedConfigurationEquals( |
145
|
|
|
[ |
146
|
|
|
['grids' => [ |
147
|
|
|
'sylius_admin_tax_category' => [ |
148
|
|
|
'sorting' => ['code' => 'asc'], |
149
|
|
|
], |
150
|
|
|
]], |
151
|
|
|
['grids' => [ |
152
|
|
|
'sylius_admin_tax_category' => [ |
153
|
|
|
'sorting' => null, |
154
|
|
|
], |
155
|
|
|
]], |
156
|
|
|
], |
157
|
|
|
['grids' => [ |
158
|
|
|
'sylius_admin_tax_category' => [ |
159
|
|
|
'sorting' => [], |
160
|
|
|
], |
161
|
|
|
]], |
162
|
|
|
'grids.*.sorting' |
163
|
|
|
); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @test |
168
|
|
|
*/ |
169
|
|
|
public function its_sorting_order_can_be_only_ascending_or_descending(): void |
170
|
|
|
{ |
171
|
|
|
$this->assertConfigurationIsValid([[ |
172
|
|
|
'grids' => [ |
173
|
|
|
'sylius_admin_tax_category' => [ |
174
|
|
|
'sorting' => ['code' => 'asc'], |
175
|
|
|
], |
176
|
|
|
], |
177
|
|
|
]]); |
178
|
|
|
|
179
|
|
|
$this->assertConfigurationIsValid([[ |
180
|
|
|
'grids' => [ |
181
|
|
|
'sylius_admin_tax_category' => [ |
182
|
|
|
'sorting' => ['code' => 'desc'], |
183
|
|
|
], |
184
|
|
|
], |
185
|
|
|
]]); |
186
|
|
|
|
187
|
|
|
$this->assertConfigurationIsInvalid([[ |
188
|
|
|
'grids' => [ |
189
|
|
|
'sylius_admin_tax_category' => [ |
190
|
|
|
'sorting' => ['code' => 'left'], |
191
|
|
|
], |
192
|
|
|
], |
193
|
|
|
]]); |
194
|
|
|
|
195
|
|
|
$this->assertConfigurationIsInvalid([[ |
196
|
|
|
'grids' => [ |
197
|
|
|
'sylius_admin_tax_category' => [ |
198
|
|
|
'sorting' => ['code' => null], |
199
|
|
|
], |
200
|
|
|
], |
201
|
|
|
]]); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @test |
206
|
|
|
*/ |
207
|
|
|
public function its_limits_can_only_be_a_collection_of_integers(): void |
208
|
|
|
{ |
209
|
|
|
$this->assertConfigurationIsValid([[ |
210
|
|
|
'grids' => [ |
211
|
|
|
'sylius_admin_tax_category' => [ |
212
|
|
|
'limits' => [10], |
213
|
|
|
], |
214
|
|
|
], |
215
|
|
|
]]); |
216
|
|
|
|
217
|
|
|
$this->assertConfigurationIsValid([[ |
218
|
|
|
'grids' => [ |
219
|
|
|
'sylius_admin_tax_category' => [ |
220
|
|
|
'limits' => [10, 25], |
221
|
|
|
], |
222
|
|
|
], |
223
|
|
|
]]); |
224
|
|
|
|
225
|
|
|
$this->assertConfigurationIsInvalid([[ |
226
|
|
|
'grids' => [ |
227
|
|
|
'sylius_admin_tax_category' => [ |
228
|
|
|
'limits' => [10.0, 25.0], |
229
|
|
|
], |
230
|
|
|
], |
231
|
|
|
]]); |
232
|
|
|
|
233
|
|
|
$this->assertConfigurationIsInvalid([[ |
234
|
|
|
'grids' => [ |
235
|
|
|
'sylius_admin_tax_category' => [ |
236
|
|
|
'limits' => [10, 25, 'surprise!'], |
237
|
|
|
], |
238
|
|
|
], |
239
|
|
|
]]); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @test |
244
|
|
|
*/ |
245
|
|
|
public function its_base_limits_can_be_overwritten(): void |
246
|
|
|
{ |
247
|
|
|
$this->assertProcessedConfigurationEquals( |
248
|
|
|
[ |
249
|
|
|
['grids' => [ |
250
|
|
|
'sylius_admin_tax_category' => [ |
251
|
|
|
'limits' => [10, 25], |
252
|
|
|
], |
253
|
|
|
]], |
254
|
|
|
['grids' => [ |
255
|
|
|
'sylius_admin_tax_category' => [ |
256
|
|
|
'limits' => [6, 12, 24], |
257
|
|
|
], |
258
|
|
|
]], |
259
|
|
|
], |
260
|
|
|
['grids' => [ |
261
|
|
|
'sylius_admin_tax_category' => [ |
262
|
|
|
'limits' => [6, 12, 24], |
263
|
|
|
], |
264
|
|
|
]], |
265
|
|
|
'grids.*.limits' |
266
|
|
|
); |
267
|
|
|
|
268
|
|
|
$this->assertProcessedConfigurationEquals( |
269
|
|
|
[ |
270
|
|
|
['grids' => [ |
271
|
|
|
'sylius_admin_tax_category' => [ |
272
|
|
|
'limits' => [10, 25, 50], |
273
|
|
|
], |
274
|
|
|
]], |
275
|
|
|
['grids' => [ |
276
|
|
|
'sylius_admin_tax_category' => [ |
277
|
|
|
'limits' => null, |
278
|
|
|
], |
279
|
|
|
]], |
280
|
|
|
], |
281
|
|
|
['grids' => [ |
282
|
|
|
'sylius_admin_tax_category' => [ |
283
|
|
|
'limits' => [], |
284
|
|
|
], |
285
|
|
|
]], |
286
|
|
|
'grids.*.limits' |
287
|
|
|
); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @test |
292
|
|
|
*/ |
293
|
|
|
public function it_should_throw_an_exception_if_an_invalid_driver_is_enabled(): void |
294
|
|
|
{ |
295
|
|
|
$this->assertConfigurationIsInvalid([[ |
296
|
|
|
'drivers' => ['doctrine/orm', 'foo/invalid'], |
297
|
|
|
]]); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* {@inheritdoc} |
302
|
|
|
*/ |
303
|
|
|
protected function getConfiguration(): Configuration |
304
|
|
|
{ |
305
|
|
|
return new Configuration(); |
306
|
|
|
} |
307
|
|
|
} |
308
|
|
|
|