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