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
|
|
|
'bulk_action' => [], |
79
|
|
|
], |
80
|
|
|
], |
81
|
|
|
'templates' |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @test |
87
|
|
|
*/ |
88
|
|
|
public function its_driver_cannot_be_empty(): void |
89
|
|
|
{ |
90
|
|
|
$this->assertConfigurationIsInvalid([[ |
91
|
|
|
'grids' => [ |
92
|
|
|
'sylius_admin_tax_category' => [ |
93
|
|
|
'driver' => [ |
94
|
|
|
'name' => null, |
95
|
|
|
], |
96
|
|
|
], |
97
|
|
|
], |
98
|
|
|
]]); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @test |
103
|
|
|
*/ |
104
|
|
|
public function it_requires_field_type_to_be_defined(): void |
105
|
|
|
{ |
106
|
|
|
$this->assertConfigurationIsInvalid([[ |
107
|
|
|
'grids' => [ |
108
|
|
|
'sylius_admin_tax_category' => [ |
109
|
|
|
'fields' => [ |
110
|
|
|
'code' => [ |
111
|
|
|
'label' => 'Internal code', |
112
|
|
|
], |
113
|
|
|
], |
114
|
|
|
], |
115
|
|
|
], |
116
|
|
|
]]); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @test |
121
|
|
|
*/ |
122
|
|
|
public function its_base_sorting_can_be_overwritten(): void |
123
|
|
|
{ |
124
|
|
|
$this->assertProcessedConfigurationEquals( |
125
|
|
|
[ |
126
|
|
|
['grids' => [ |
127
|
|
|
'sylius_admin_tax_category' => [ |
128
|
|
|
'sorting' => ['code' => 'asc'], |
129
|
|
|
], |
130
|
|
|
]], |
131
|
|
|
['grids' => [ |
132
|
|
|
'sylius_admin_tax_category' => [ |
133
|
|
|
'sorting' => ['name' => 'desc'], |
134
|
|
|
], |
135
|
|
|
]], |
136
|
|
|
], |
137
|
|
|
['grids' => [ |
138
|
|
|
'sylius_admin_tax_category' => [ |
139
|
|
|
'sorting' => ['name' => 'desc'], |
140
|
|
|
], |
141
|
|
|
]], |
142
|
|
|
'grids.*.sorting' |
143
|
|
|
); |
144
|
|
|
|
145
|
|
|
$this->assertProcessedConfigurationEquals( |
146
|
|
|
[ |
147
|
|
|
['grids' => [ |
148
|
|
|
'sylius_admin_tax_category' => [ |
149
|
|
|
'sorting' => ['code' => 'asc'], |
150
|
|
|
], |
151
|
|
|
]], |
152
|
|
|
['grids' => [ |
153
|
|
|
'sylius_admin_tax_category' => [ |
154
|
|
|
'sorting' => null, |
155
|
|
|
], |
156
|
|
|
]], |
157
|
|
|
], |
158
|
|
|
['grids' => [ |
159
|
|
|
'sylius_admin_tax_category' => [ |
160
|
|
|
'sorting' => [], |
161
|
|
|
], |
162
|
|
|
]], |
163
|
|
|
'grids.*.sorting' |
164
|
|
|
); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @test |
169
|
|
|
*/ |
170
|
|
|
public function its_sorting_order_can_be_only_ascending_or_descending(): void |
171
|
|
|
{ |
172
|
|
|
$this->assertConfigurationIsValid([[ |
173
|
|
|
'grids' => [ |
174
|
|
|
'sylius_admin_tax_category' => [ |
175
|
|
|
'sorting' => ['code' => 'asc'], |
176
|
|
|
], |
177
|
|
|
], |
178
|
|
|
]]); |
179
|
|
|
|
180
|
|
|
$this->assertConfigurationIsValid([[ |
181
|
|
|
'grids' => [ |
182
|
|
|
'sylius_admin_tax_category' => [ |
183
|
|
|
'sorting' => ['code' => 'desc'], |
184
|
|
|
], |
185
|
|
|
], |
186
|
|
|
]]); |
187
|
|
|
|
188
|
|
|
$this->assertConfigurationIsInvalid([[ |
189
|
|
|
'grids' => [ |
190
|
|
|
'sylius_admin_tax_category' => [ |
191
|
|
|
'sorting' => ['code' => 'left'], |
192
|
|
|
], |
193
|
|
|
], |
194
|
|
|
]]); |
195
|
|
|
|
196
|
|
|
$this->assertConfigurationIsInvalid([[ |
197
|
|
|
'grids' => [ |
198
|
|
|
'sylius_admin_tax_category' => [ |
199
|
|
|
'sorting' => ['code' => null], |
200
|
|
|
], |
201
|
|
|
], |
202
|
|
|
]]); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @test |
207
|
|
|
*/ |
208
|
|
|
public function its_limits_can_only_be_a_collection_of_integers(): void |
209
|
|
|
{ |
210
|
|
|
$this->assertConfigurationIsValid([[ |
211
|
|
|
'grids' => [ |
212
|
|
|
'sylius_admin_tax_category' => [ |
213
|
|
|
'limits' => [10], |
214
|
|
|
], |
215
|
|
|
], |
216
|
|
|
]]); |
217
|
|
|
|
218
|
|
|
$this->assertConfigurationIsValid([[ |
219
|
|
|
'grids' => [ |
220
|
|
|
'sylius_admin_tax_category' => [ |
221
|
|
|
'limits' => [10, 25], |
222
|
|
|
], |
223
|
|
|
], |
224
|
|
|
]]); |
225
|
|
|
|
226
|
|
|
$this->assertConfigurationIsInvalid([[ |
227
|
|
|
'grids' => [ |
228
|
|
|
'sylius_admin_tax_category' => [ |
229
|
|
|
'limits' => [10.0, 25.0], |
230
|
|
|
], |
231
|
|
|
], |
232
|
|
|
]]); |
233
|
|
|
|
234
|
|
|
$this->assertConfigurationIsInvalid([[ |
235
|
|
|
'grids' => [ |
236
|
|
|
'sylius_admin_tax_category' => [ |
237
|
|
|
'limits' => [10, 25, 'surprise!'], |
238
|
|
|
], |
239
|
|
|
], |
240
|
|
|
]]); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* @test |
245
|
|
|
*/ |
246
|
|
|
public function its_base_limits_can_be_overwritten(): void |
247
|
|
|
{ |
248
|
|
|
$this->assertProcessedConfigurationEquals( |
249
|
|
|
[ |
250
|
|
|
['grids' => [ |
251
|
|
|
'sylius_admin_tax_category' => [ |
252
|
|
|
'limits' => [10, 25], |
253
|
|
|
], |
254
|
|
|
]], |
255
|
|
|
['grids' => [ |
256
|
|
|
'sylius_admin_tax_category' => [ |
257
|
|
|
'limits' => [6, 12, 24], |
258
|
|
|
], |
259
|
|
|
]], |
260
|
|
|
], |
261
|
|
|
['grids' => [ |
262
|
|
|
'sylius_admin_tax_category' => [ |
263
|
|
|
'limits' => [6, 12, 24], |
264
|
|
|
], |
265
|
|
|
]], |
266
|
|
|
'grids.*.limits' |
267
|
|
|
); |
268
|
|
|
|
269
|
|
|
$this->assertProcessedConfigurationEquals( |
270
|
|
|
[ |
271
|
|
|
['grids' => [ |
272
|
|
|
'sylius_admin_tax_category' => [ |
273
|
|
|
'limits' => [10, 25, 50], |
274
|
|
|
], |
275
|
|
|
]], |
276
|
|
|
['grids' => [ |
277
|
|
|
'sylius_admin_tax_category' => [ |
278
|
|
|
'limits' => null, |
279
|
|
|
], |
280
|
|
|
]], |
281
|
|
|
], |
282
|
|
|
['grids' => [ |
283
|
|
|
'sylius_admin_tax_category' => [ |
284
|
|
|
'limits' => [], |
285
|
|
|
], |
286
|
|
|
]], |
287
|
|
|
'grids.*.limits' |
288
|
|
|
); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* @test |
293
|
|
|
*/ |
294
|
|
|
public function it_should_throw_an_exception_if_an_invalid_driver_is_enabled(): void |
295
|
|
|
{ |
296
|
|
|
$this->assertConfigurationIsInvalid([[ |
297
|
|
|
'drivers' => ['doctrine/orm', 'foo/invalid'], |
298
|
|
|
]]); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* {@inheritdoc} |
303
|
|
|
*/ |
304
|
|
|
protected function getConfiguration(): Configuration |
305
|
|
|
{ |
306
|
|
|
return new Configuration(); |
307
|
|
|
} |
308
|
|
|
} |
309
|
|
|
|