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 spec\Sylius\Bundle\ResourceBundle\Routing; |
15
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
17
|
|
|
use Sylius\Bundle\ResourceBundle\Routing\RouteFactoryInterface; |
18
|
|
|
use Sylius\Component\Resource\Metadata\MetadataInterface; |
19
|
|
|
use Sylius\Component\Resource\Metadata\RegistryInterface; |
20
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
21
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
22
|
|
|
use Symfony\Component\Routing\Route; |
23
|
|
|
use Symfony\Component\Routing\RouteCollection; |
24
|
|
|
|
25
|
|
|
final class ResourceLoaderSpec extends ObjectBehavior |
26
|
|
|
{ |
27
|
|
|
function let(RegistryInterface $resourceRegistry, RouteFactoryInterface $routeFactory): void |
28
|
|
|
{ |
29
|
|
|
$this->beConstructedWith($resourceRegistry, $routeFactory); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
function it_is_a_Symfony_routing_loader(): void |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
$this->shouldImplement(LoaderInterface::class); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
function it_processes_configuration_and_throws_exception_if_invalid(): void |
38
|
|
|
{ |
39
|
|
|
$configuration = |
40
|
|
|
<<<EOT |
41
|
|
|
foo: bar |
42
|
|
|
only: string |
43
|
|
|
EOT; |
44
|
|
|
|
45
|
|
|
$this |
46
|
|
|
->shouldThrow(InvalidConfigurationException::class) |
47
|
|
|
->during('load', [$configuration, 'sylius.resource']); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
function it_throws_an_exception_if_invalid_resource_configured(RegistryInterface $resourceRegistry): void |
51
|
|
|
{ |
52
|
|
|
$resourceRegistry->get('sylius.foo')->willThrow(new \InvalidArgumentException()); |
|
|
|
|
53
|
|
|
|
54
|
|
|
$configuration = |
55
|
|
|
<<<EOT |
56
|
|
|
alias: sylius.foo |
57
|
|
|
EOT; |
58
|
|
|
|
59
|
|
|
$this |
60
|
|
|
->shouldThrow(\InvalidArgumentException::class) |
61
|
|
|
->during('load', [$configuration, 'sylius.resource']); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
function it_generates_routing_based_on_resource_configuration( |
65
|
|
|
RegistryInterface $resourceRegistry, |
66
|
|
|
MetadataInterface $metadata, |
67
|
|
|
RouteFactoryInterface $routeFactory, |
68
|
|
|
RouteCollection $routeCollection, |
69
|
|
|
Route $showRoute, |
70
|
|
|
Route $indexRoute, |
71
|
|
|
Route $createRoute, |
72
|
|
|
Route $updateRoute, |
73
|
|
|
Route $deleteRoute |
74
|
|
|
): void { |
75
|
|
|
$resourceRegistry->get('sylius.product')->willReturn($metadata); |
|
|
|
|
76
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
77
|
|
|
$metadata->getName()->willReturn('product'); |
78
|
|
|
$metadata->getPluralName()->willReturn('products'); |
79
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
80
|
|
|
|
81
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
82
|
|
|
|
83
|
|
|
$configuration = |
84
|
|
|
<<<EOT |
85
|
|
|
alias: sylius.product |
86
|
|
|
EOT; |
87
|
|
|
|
88
|
|
|
$showDefaults = [ |
89
|
|
|
'_controller' => 'sylius.controller.product:showAction', |
90
|
|
|
'_sylius' => [ |
91
|
|
|
'permission' => false, |
92
|
|
|
], |
93
|
|
|
]; |
94
|
|
|
$routeFactory->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
95
|
|
|
$routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled(); |
96
|
|
|
|
97
|
|
|
$indexDefaults = [ |
98
|
|
|
'_controller' => 'sylius.controller.product:indexAction', |
99
|
|
|
'_sylius' => [ |
100
|
|
|
'permission' => false, |
101
|
|
|
], |
102
|
|
|
]; |
103
|
|
|
$routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
104
|
|
|
$routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
105
|
|
|
|
106
|
|
|
$createDefaults = [ |
107
|
|
|
'_controller' => 'sylius.controller.product:createAction', |
108
|
|
|
'_sylius' => [ |
109
|
|
|
'permission' => false, |
110
|
|
|
], |
111
|
|
|
]; |
112
|
|
|
$routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
113
|
|
|
$routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
114
|
|
|
|
115
|
|
|
$updateDefaults = [ |
116
|
|
|
'_controller' => 'sylius.controller.product:updateAction', |
117
|
|
|
'_sylius' => [ |
118
|
|
|
'permission' => false, |
119
|
|
|
], |
120
|
|
|
]; |
121
|
|
|
$routeFactory->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
122
|
|
|
$routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
123
|
|
|
|
124
|
|
|
$deleteDefaults = [ |
125
|
|
|
'_controller' => 'sylius.controller.product:deleteAction', |
126
|
|
|
'_sylius' => [ |
127
|
|
|
'permission' => false, |
128
|
|
|
], |
129
|
|
|
]; |
130
|
|
|
$routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
131
|
|
|
$routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled(); |
132
|
|
|
|
133
|
|
|
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
function it_generates_urlized_paths_for_resources_with_multiple_words_in_name( |
137
|
|
|
RegistryInterface $resourceRegistry, |
138
|
|
|
MetadataInterface $metadata, |
139
|
|
|
RouteFactoryInterface $routeFactory, |
140
|
|
|
RouteCollection $routeCollection, |
141
|
|
|
Route $showRoute, |
142
|
|
|
Route $indexRoute, |
143
|
|
|
Route $createRoute, |
144
|
|
|
Route $updateRoute, |
145
|
|
|
Route $deleteRoute |
146
|
|
|
): void { |
147
|
|
|
$resourceRegistry->get('sylius.product_option')->willReturn($metadata); |
|
|
|
|
148
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
149
|
|
|
$metadata->getName()->willReturn('product_option'); |
150
|
|
|
$metadata->getPluralName()->willReturn('product_options'); |
151
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product_option'); |
152
|
|
|
|
153
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
154
|
|
|
|
155
|
|
|
$configuration = |
156
|
|
|
<<<EOT |
157
|
|
|
alias: sylius.product_option |
158
|
|
|
EOT; |
159
|
|
|
|
160
|
|
|
$showDefaults = [ |
161
|
|
|
'_controller' => 'sylius.controller.product_option:showAction', |
162
|
|
|
'_sylius' => [ |
163
|
|
|
'permission' => false, |
164
|
|
|
], |
165
|
|
|
]; |
166
|
|
|
$routeFactory->createRoute('/product-options/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
167
|
|
|
$routeCollection->add('sylius_product_option_show', $showRoute)->shouldBeCalled(); |
168
|
|
|
|
169
|
|
|
$indexDefaults = [ |
170
|
|
|
'_controller' => 'sylius.controller.product_option:indexAction', |
171
|
|
|
'_sylius' => [ |
172
|
|
|
'permission' => false, |
173
|
|
|
], |
174
|
|
|
]; |
175
|
|
|
$routeFactory->createRoute('/product-options/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
176
|
|
|
$routeCollection->add('sylius_product_option_index', $indexRoute)->shouldBeCalled(); |
177
|
|
|
|
178
|
|
|
$createDefaults = [ |
179
|
|
|
'_controller' => 'sylius.controller.product_option:createAction', |
180
|
|
|
'_sylius' => [ |
181
|
|
|
'permission' => false, |
182
|
|
|
], |
183
|
|
|
]; |
184
|
|
|
$routeFactory->createRoute('/product-options/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
185
|
|
|
$routeCollection->add('sylius_product_option_create', $createRoute)->shouldBeCalled(); |
186
|
|
|
|
187
|
|
|
$updateDefaults = [ |
188
|
|
|
'_controller' => 'sylius.controller.product_option:updateAction', |
189
|
|
|
'_sylius' => [ |
190
|
|
|
'permission' => false, |
191
|
|
|
], |
192
|
|
|
]; |
193
|
|
|
$routeFactory->createRoute('/product-options/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
194
|
|
|
$routeCollection->add('sylius_product_option_update', $updateRoute)->shouldBeCalled(); |
195
|
|
|
|
196
|
|
|
$deleteDefaults = [ |
197
|
|
|
'_controller' => 'sylius.controller.product_option:deleteAction', |
198
|
|
|
'_sylius' => [ |
199
|
|
|
'permission' => false, |
200
|
|
|
], |
201
|
|
|
]; |
202
|
|
|
$routeFactory->createRoute('/product-options/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
203
|
|
|
$routeCollection->add('sylius_product_option_delete', $deleteRoute)->shouldBeCalled(); |
204
|
|
|
|
205
|
|
|
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
function it_generates_urlized_paths_for_resources_with_custom_identifier( |
209
|
|
|
RegistryInterface $resourceRegistry, |
210
|
|
|
MetadataInterface $metadata, |
211
|
|
|
RouteFactoryInterface $routeFactory, |
212
|
|
|
RouteCollection $routeCollection, |
213
|
|
|
Route $showRoute, |
214
|
|
|
Route $indexRoute, |
215
|
|
|
Route $createRoute, |
216
|
|
|
Route $updateRoute, |
217
|
|
|
Route $deleteRoute |
218
|
|
|
): void { |
219
|
|
|
$resourceRegistry->get('sylius.product_option')->willReturn($metadata); |
|
|
|
|
220
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
221
|
|
|
$metadata->getName()->willReturn('product_option'); |
222
|
|
|
$metadata->getPluralName()->willReturn('product_options'); |
223
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product_option'); |
224
|
|
|
|
225
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
226
|
|
|
|
227
|
|
|
$configuration = |
228
|
|
|
<<<EOT |
229
|
|
|
alias: sylius.product_option |
230
|
|
|
identifier: code |
231
|
|
|
criteria: |
232
|
|
|
code: \$code |
233
|
|
|
filterable: true |
234
|
|
|
EOT; |
235
|
|
|
|
236
|
|
|
$showDefaults = [ |
237
|
|
|
'_controller' => 'sylius.controller.product_option:showAction', |
238
|
|
|
'_sylius' => [ |
239
|
|
|
'permission' => false, |
240
|
|
|
'criteria' => [ |
241
|
|
|
'code' => '$code', |
242
|
|
|
], |
243
|
|
|
'filterable' => true, |
244
|
|
|
], |
245
|
|
|
]; |
246
|
|
|
$routeFactory->createRoute('/product-options/{code}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
247
|
|
|
$routeCollection->add('sylius_product_option_show', $showRoute)->shouldBeCalled(); |
248
|
|
|
|
249
|
|
|
$indexDefaults = [ |
250
|
|
|
'_controller' => 'sylius.controller.product_option:indexAction', |
251
|
|
|
'_sylius' => [ |
252
|
|
|
'permission' => false, |
253
|
|
|
'criteria' => [ |
254
|
|
|
'code' => '$code', |
255
|
|
|
], |
256
|
|
|
'filterable' => true, |
257
|
|
|
], |
258
|
|
|
]; |
259
|
|
|
$routeFactory->createRoute('/product-options/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
260
|
|
|
$routeCollection->add('sylius_product_option_index', $indexRoute)->shouldBeCalled(); |
261
|
|
|
|
262
|
|
|
$createDefaults = [ |
263
|
|
|
'_controller' => 'sylius.controller.product_option:createAction', |
264
|
|
|
'_sylius' => [ |
265
|
|
|
'permission' => false, |
266
|
|
|
'criteria' => [ |
267
|
|
|
'code' => '$code', |
268
|
|
|
], |
269
|
|
|
'filterable' => true, |
270
|
|
|
], |
271
|
|
|
]; |
272
|
|
|
$routeFactory->createRoute('/product-options/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
273
|
|
|
$routeCollection->add('sylius_product_option_create', $createRoute)->shouldBeCalled(); |
274
|
|
|
|
275
|
|
|
$updateDefaults = [ |
276
|
|
|
'_controller' => 'sylius.controller.product_option:updateAction', |
277
|
|
|
'_sylius' => [ |
278
|
|
|
'permission' => false, |
279
|
|
|
'criteria' => [ |
280
|
|
|
'code' => '$code', |
281
|
|
|
], |
282
|
|
|
'filterable' => true, |
283
|
|
|
], |
284
|
|
|
]; |
285
|
|
|
$routeFactory->createRoute('/product-options/{code}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
286
|
|
|
$routeCollection->add('sylius_product_option_update', $updateRoute)->shouldBeCalled(); |
287
|
|
|
|
288
|
|
|
$deleteDefaults = [ |
289
|
|
|
'_controller' => 'sylius.controller.product_option:deleteAction', |
290
|
|
|
'_sylius' => [ |
291
|
|
|
'permission' => false, |
292
|
|
|
'criteria' => [ |
293
|
|
|
'code' => '$code', |
294
|
|
|
], |
295
|
|
|
'filterable' => true, |
296
|
|
|
], |
297
|
|
|
]; |
298
|
|
|
$routeFactory->createRoute('/product-options/{code}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
299
|
|
|
$routeCollection->add('sylius_product_option_delete', $deleteRoute)->shouldBeCalled(); |
300
|
|
|
|
301
|
|
|
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
function it_generates_routing_with_custom_path_if_specified( |
305
|
|
|
RegistryInterface $resourceRegistry, |
306
|
|
|
MetadataInterface $metadata, |
307
|
|
|
RouteFactoryInterface $routeFactory, |
308
|
|
|
RouteCollection $routeCollection, |
309
|
|
|
Route $showRoute, |
310
|
|
|
Route $indexRoute, |
311
|
|
|
Route $createRoute, |
312
|
|
|
Route $updateRoute, |
313
|
|
|
Route $deleteRoute |
314
|
|
|
): void { |
315
|
|
|
$resourceRegistry->get('sylius.product')->willReturn($metadata); |
|
|
|
|
316
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
317
|
|
|
$metadata->getName()->willReturn('product'); |
318
|
|
|
$metadata->getPluralName()->willReturn('products'); |
319
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
320
|
|
|
|
321
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
322
|
|
|
|
323
|
|
|
$configuration = |
324
|
|
|
<<<EOT |
325
|
|
|
alias: sylius.product |
326
|
|
|
path: super-duper-products |
327
|
|
|
EOT; |
328
|
|
|
|
329
|
|
|
$showDefaults = [ |
330
|
|
|
'_controller' => 'sylius.controller.product:showAction', |
331
|
|
|
'_sylius' => [ |
332
|
|
|
'permission' => false, |
333
|
|
|
], |
334
|
|
|
]; |
335
|
|
|
$routeFactory->createRoute('/super-duper-products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
336
|
|
|
$routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled(); |
337
|
|
|
|
338
|
|
|
$indexDefaults = [ |
339
|
|
|
'_controller' => 'sylius.controller.product:indexAction', |
340
|
|
|
'_sylius' => [ |
341
|
|
|
'permission' => false, |
342
|
|
|
], |
343
|
|
|
]; |
344
|
|
|
$routeFactory->createRoute('/super-duper-products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
345
|
|
|
$routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
346
|
|
|
|
347
|
|
|
$createDefaults = [ |
348
|
|
|
'_controller' => 'sylius.controller.product:createAction', |
349
|
|
|
'_sylius' => [ |
350
|
|
|
'permission' => false, |
351
|
|
|
], |
352
|
|
|
]; |
353
|
|
|
$routeFactory->createRoute('/super-duper-products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
354
|
|
|
$routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
355
|
|
|
|
356
|
|
|
$updateDefaults = [ |
357
|
|
|
'_controller' => 'sylius.controller.product:updateAction', |
358
|
|
|
'_sylius' => [ |
359
|
|
|
'permission' => false, |
360
|
|
|
], |
361
|
|
|
]; |
362
|
|
|
$routeFactory->createRoute('/super-duper-products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
363
|
|
|
$routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
364
|
|
|
|
365
|
|
|
$deleteDefaults = [ |
366
|
|
|
'_controller' => 'sylius.controller.product:deleteAction', |
367
|
|
|
'_sylius' => [ |
368
|
|
|
'permission' => false, |
369
|
|
|
], |
370
|
|
|
]; |
371
|
|
|
$routeFactory->createRoute('/super-duper-products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
372
|
|
|
$routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled(); |
373
|
|
|
|
374
|
|
|
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
function it_generates_routing_with_custom_form_if_specified( |
378
|
|
|
RegistryInterface $resourceRegistry, |
379
|
|
|
MetadataInterface $metadata, |
380
|
|
|
RouteFactoryInterface $routeFactory, |
381
|
|
|
RouteCollection $routeCollection, |
382
|
|
|
Route $showRoute, |
383
|
|
|
Route $indexRoute, |
384
|
|
|
Route $createRoute, |
385
|
|
|
Route $updateRoute, |
386
|
|
|
Route $deleteRoute |
387
|
|
|
): void { |
388
|
|
|
$resourceRegistry->get('sylius.product')->willReturn($metadata); |
|
|
|
|
389
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
390
|
|
|
$metadata->getName()->willReturn('product'); |
391
|
|
|
$metadata->getPluralName()->willReturn('products'); |
392
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
393
|
|
|
|
394
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
395
|
|
|
|
396
|
|
|
$configuration = |
397
|
|
|
<<<EOT |
398
|
|
|
alias: sylius.product |
399
|
|
|
form: sylius_product_custom |
400
|
|
|
EOT; |
401
|
|
|
|
402
|
|
|
$showDefaults = [ |
403
|
|
|
'_controller' => 'sylius.controller.product:showAction', |
404
|
|
|
'_sylius' => [ |
405
|
|
|
'permission' => false, |
406
|
|
|
], |
407
|
|
|
]; |
408
|
|
|
$routeFactory->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
409
|
|
|
$routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled(); |
410
|
|
|
|
411
|
|
|
$indexDefaults = [ |
412
|
|
|
'_controller' => 'sylius.controller.product:indexAction', |
413
|
|
|
'_sylius' => [ |
414
|
|
|
'permission' => false, |
415
|
|
|
], |
416
|
|
|
]; |
417
|
|
|
$routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
418
|
|
|
$routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
419
|
|
|
|
420
|
|
|
$createDefaults = [ |
421
|
|
|
'_controller' => 'sylius.controller.product:createAction', |
422
|
|
|
'_sylius' => [ |
423
|
|
|
'form' => 'sylius_product_custom', |
424
|
|
|
'permission' => false, |
425
|
|
|
], |
426
|
|
|
]; |
427
|
|
|
$routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
428
|
|
|
$routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
429
|
|
|
|
430
|
|
|
$updateDefaults = [ |
431
|
|
|
'_controller' => 'sylius.controller.product:updateAction', |
432
|
|
|
'_sylius' => [ |
433
|
|
|
'form' => 'sylius_product_custom', |
434
|
|
|
'permission' => false, |
435
|
|
|
], |
436
|
|
|
]; |
437
|
|
|
$routeFactory->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
438
|
|
|
$routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
439
|
|
|
|
440
|
|
|
$deleteDefaults = [ |
441
|
|
|
'_controller' => 'sylius.controller.product:deleteAction', |
442
|
|
|
'_sylius' => [ |
443
|
|
|
'permission' => false, |
444
|
|
|
], |
445
|
|
|
]; |
446
|
|
|
$routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
447
|
|
|
$routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled(); |
448
|
|
|
|
449
|
|
|
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
function it_generates_routing_for_a_section( |
453
|
|
|
RegistryInterface $resourceRegistry, |
454
|
|
|
MetadataInterface $metadata, |
455
|
|
|
RouteFactoryInterface $routeFactory, |
456
|
|
|
RouteCollection $routeCollection, |
457
|
|
|
Route $showRoute, |
458
|
|
|
Route $indexRoute, |
459
|
|
|
Route $createRoute, |
460
|
|
|
Route $updateRoute, |
461
|
|
|
Route $deleteRoute |
462
|
|
|
): void { |
463
|
|
|
$resourceRegistry->get('sylius.product')->willReturn($metadata); |
|
|
|
|
464
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
465
|
|
|
$metadata->getName()->willReturn('product'); |
466
|
|
|
$metadata->getPluralName()->willReturn('products'); |
467
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
468
|
|
|
|
469
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
470
|
|
|
|
471
|
|
|
$configuration = |
472
|
|
|
<<<EOT |
473
|
|
|
alias: sylius.product |
474
|
|
|
section: admin |
475
|
|
|
EOT; |
476
|
|
|
|
477
|
|
|
$showDefaults = [ |
478
|
|
|
'_controller' => 'sylius.controller.product:showAction', |
479
|
|
|
'_sylius' => [ |
480
|
|
|
'section' => 'admin', |
481
|
|
|
'permission' => false, |
482
|
|
|
], |
483
|
|
|
]; |
484
|
|
|
$routeFactory->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
485
|
|
|
$routeCollection->add('sylius_admin_product_show', $showRoute)->shouldBeCalled(); |
486
|
|
|
|
487
|
|
|
$indexDefaults = [ |
488
|
|
|
'_controller' => 'sylius.controller.product:indexAction', |
489
|
|
|
'_sylius' => [ |
490
|
|
|
'section' => 'admin', |
491
|
|
|
'permission' => false, |
492
|
|
|
], |
493
|
|
|
]; |
494
|
|
|
$routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
495
|
|
|
$routeCollection->add('sylius_admin_product_index', $indexRoute)->shouldBeCalled(); |
496
|
|
|
|
497
|
|
|
$createDefaults = [ |
498
|
|
|
'_controller' => 'sylius.controller.product:createAction', |
499
|
|
|
'_sylius' => [ |
500
|
|
|
'section' => 'admin', |
501
|
|
|
'permission' => false, |
502
|
|
|
], |
503
|
|
|
]; |
504
|
|
|
$routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
505
|
|
|
$routeCollection->add('sylius_admin_product_create', $createRoute)->shouldBeCalled(); |
506
|
|
|
|
507
|
|
|
$updateDefaults = [ |
508
|
|
|
'_controller' => 'sylius.controller.product:updateAction', |
509
|
|
|
'_sylius' => [ |
510
|
|
|
'section' => 'admin', |
511
|
|
|
'permission' => false, |
512
|
|
|
], |
513
|
|
|
]; |
514
|
|
|
$routeFactory->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
515
|
|
|
$routeCollection->add('sylius_admin_product_update', $updateRoute)->shouldBeCalled(); |
516
|
|
|
|
517
|
|
|
$deleteDefaults = [ |
518
|
|
|
'_controller' => 'sylius.controller.product:deleteAction', |
519
|
|
|
'_sylius' => [ |
520
|
|
|
'section' => 'admin', |
521
|
|
|
'permission' => false, |
522
|
|
|
], |
523
|
|
|
]; |
524
|
|
|
$routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
525
|
|
|
$routeCollection->add('sylius_admin_product_delete', $deleteRoute)->shouldBeCalled(); |
526
|
|
|
|
527
|
|
|
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
528
|
|
|
} |
529
|
|
|
|
530
|
|
|
function it_generates_routing_with_custom_templates_namespace( |
531
|
|
|
RegistryInterface $resourceRegistry, |
532
|
|
|
MetadataInterface $metadata, |
533
|
|
|
RouteFactoryInterface $routeFactory, |
534
|
|
|
RouteCollection $routeCollection, |
535
|
|
|
Route $showRoute, |
536
|
|
|
Route $indexRoute, |
537
|
|
|
Route $createRoute, |
538
|
|
|
Route $updateRoute, |
539
|
|
|
Route $deleteRoute |
540
|
|
|
): void { |
541
|
|
|
$resourceRegistry->get('sylius.product')->willReturn($metadata); |
|
|
|
|
542
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
543
|
|
|
$metadata->getName()->willReturn('product'); |
544
|
|
|
$metadata->getPluralName()->willReturn('products'); |
545
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
546
|
|
|
|
547
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
548
|
|
|
|
549
|
|
|
$configuration = |
550
|
|
|
<<<EOT |
551
|
|
|
alias: sylius.product |
552
|
|
|
templates: SyliusAdminBundle:Product |
553
|
|
|
EOT; |
554
|
|
|
|
555
|
|
|
$showDefaults = [ |
556
|
|
|
'_controller' => 'sylius.controller.product:showAction', |
557
|
|
|
'_sylius' => [ |
558
|
|
|
'template' => 'SyliusAdminBundle:Product:show.html.twig', |
559
|
|
|
'permission' => false, |
560
|
|
|
], |
561
|
|
|
]; |
562
|
|
|
$routeFactory->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
563
|
|
|
$routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled(); |
564
|
|
|
|
565
|
|
|
$indexDefaults = [ |
566
|
|
|
'_controller' => 'sylius.controller.product:indexAction', |
567
|
|
|
'_sylius' => [ |
568
|
|
|
'template' => 'SyliusAdminBundle:Product:index.html.twig', |
569
|
|
|
'permission' => false, |
570
|
|
|
], |
571
|
|
|
]; |
572
|
|
|
$routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
573
|
|
|
$routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
574
|
|
|
|
575
|
|
|
$createDefaults = [ |
576
|
|
|
'_controller' => 'sylius.controller.product:createAction', |
577
|
|
|
'_sylius' => [ |
578
|
|
|
'template' => 'SyliusAdminBundle:Product:create.html.twig', |
579
|
|
|
'permission' => false, |
580
|
|
|
], |
581
|
|
|
]; |
582
|
|
|
$routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
583
|
|
|
$routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
584
|
|
|
|
585
|
|
|
$updateDefaults = [ |
586
|
|
|
'_controller' => 'sylius.controller.product:updateAction', |
587
|
|
|
'_sylius' => [ |
588
|
|
|
'template' => 'SyliusAdminBundle:Product:update.html.twig', |
589
|
|
|
'permission' => false, |
590
|
|
|
], |
591
|
|
|
]; |
592
|
|
|
$routeFactory->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
593
|
|
|
$routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
594
|
|
|
|
595
|
|
|
$deleteDefaults = [ |
596
|
|
|
'_controller' => 'sylius.controller.product:deleteAction', |
597
|
|
|
'_sylius' => [ |
598
|
|
|
'permission' => false, |
599
|
|
|
], |
600
|
|
|
]; |
601
|
|
|
$routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
602
|
|
|
$routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled(); |
603
|
|
|
|
604
|
|
|
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
605
|
|
|
} |
606
|
|
|
|
607
|
|
|
function it_excludes_specific_routes_if_configured( |
608
|
|
|
RegistryInterface $resourceRegistry, |
609
|
|
|
MetadataInterface $metadata, |
610
|
|
|
RouteFactoryInterface $routeFactory, |
611
|
|
|
RouteCollection $routeCollection, |
612
|
|
|
Route $indexRoute, |
613
|
|
|
Route $createRoute, |
614
|
|
|
Route $updateRoute |
615
|
|
|
): void { |
616
|
|
|
$resourceRegistry->get('sylius.product')->willReturn($metadata); |
|
|
|
|
617
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
618
|
|
|
$metadata->getName()->willReturn('product'); |
619
|
|
|
$metadata->getPluralName()->willReturn('products'); |
620
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
621
|
|
|
|
622
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
623
|
|
|
|
624
|
|
|
$configuration = |
625
|
|
|
<<<EOT |
626
|
|
|
alias: sylius.product |
627
|
|
|
except: ['show', 'delete'] |
628
|
|
|
EOT; |
629
|
|
|
|
630
|
|
|
$indexDefaults = [ |
631
|
|
|
'_controller' => 'sylius.controller.product:indexAction', |
632
|
|
|
'_sylius' => [ |
633
|
|
|
'permission' => false, |
634
|
|
|
], |
635
|
|
|
]; |
636
|
|
|
$routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
637
|
|
|
$routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
638
|
|
|
|
639
|
|
|
$createDefaults = [ |
640
|
|
|
'_controller' => 'sylius.controller.product:createAction', |
641
|
|
|
'_sylius' => [ |
642
|
|
|
'permission' => false, |
643
|
|
|
], |
644
|
|
|
]; |
645
|
|
|
$routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
646
|
|
|
$routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
647
|
|
|
|
648
|
|
|
$updateDefaults = [ |
649
|
|
|
'_controller' => 'sylius.controller.product:updateAction', |
650
|
|
|
'_sylius' => [ |
651
|
|
|
'permission' => false, |
652
|
|
|
], |
653
|
|
|
]; |
654
|
|
|
$routeFactory->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
655
|
|
|
$routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
656
|
|
|
|
657
|
|
|
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
658
|
|
|
} |
659
|
|
|
|
660
|
|
|
function it_includes_only_specific_routes_if_configured( |
661
|
|
|
RegistryInterface $resourceRegistry, |
662
|
|
|
MetadataInterface $metadata, |
663
|
|
|
RouteFactoryInterface $routeFactory, |
664
|
|
|
RouteCollection $routeCollection, |
665
|
|
|
Route $indexRoute, |
666
|
|
|
Route $createRoute |
667
|
|
|
): void { |
668
|
|
|
$resourceRegistry->get('sylius.product')->willReturn($metadata); |
|
|
|
|
669
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
670
|
|
|
$metadata->getName()->willReturn('product'); |
671
|
|
|
$metadata->getPluralName()->willReturn('products'); |
672
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
673
|
|
|
|
674
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
675
|
|
|
|
676
|
|
|
$configuration = |
677
|
|
|
<<<EOT |
678
|
|
|
alias: sylius.product |
679
|
|
|
only: ['create', 'index'] |
680
|
|
|
EOT; |
681
|
|
|
|
682
|
|
|
$indexDefaults = [ |
683
|
|
|
'_controller' => 'sylius.controller.product:indexAction', |
684
|
|
|
'_sylius' => [ |
685
|
|
|
'permission' => false, |
686
|
|
|
], |
687
|
|
|
]; |
688
|
|
|
$routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
689
|
|
|
$routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
690
|
|
|
|
691
|
|
|
$createDefaults = [ |
692
|
|
|
'_controller' => 'sylius.controller.product:createAction', |
693
|
|
|
'_sylius' => [ |
694
|
|
|
'permission' => false, |
695
|
|
|
], |
696
|
|
|
]; |
697
|
|
|
$routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
698
|
|
|
$routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
699
|
|
|
|
700
|
|
|
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
701
|
|
|
} |
702
|
|
|
|
703
|
|
|
function it_throws_an_exception_if_both_excluded_and_includes_routes_configured(): void |
704
|
|
|
{ |
705
|
|
|
$configuration = |
706
|
|
|
<<<EOT |
707
|
|
|
alias: sylius.product |
708
|
|
|
except: ['show', 'delete'] |
709
|
|
|
only: ['create'] |
710
|
|
|
EOT; |
711
|
|
|
|
712
|
|
|
$this |
713
|
|
|
->shouldThrow(\InvalidArgumentException::class) |
714
|
|
|
->during('load', [$configuration, 'sylius.resource']); |
715
|
|
|
} |
716
|
|
|
|
717
|
|
|
function it_generates_routing_with_custom_redirect_if_specified( |
718
|
|
|
RegistryInterface $resourceRegistry, |
719
|
|
|
MetadataInterface $metadata, |
720
|
|
|
RouteFactoryInterface $routeFactory, |
721
|
|
|
RouteCollection $routeCollection, |
722
|
|
|
Route $showRoute, |
723
|
|
|
Route $indexRoute, |
724
|
|
|
Route $createRoute, |
725
|
|
|
Route $updateRoute, |
726
|
|
|
Route $deleteRoute |
727
|
|
|
): void { |
728
|
|
|
$resourceRegistry->get('sylius.product')->willReturn($metadata); |
|
|
|
|
729
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
730
|
|
|
$metadata->getName()->willReturn('product'); |
731
|
|
|
$metadata->getPluralName()->willReturn('products'); |
732
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
733
|
|
|
|
734
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
735
|
|
|
|
736
|
|
|
$configuration = |
737
|
|
|
<<<EOT |
738
|
|
|
alias: sylius.product |
739
|
|
|
redirect: update |
740
|
|
|
EOT; |
741
|
|
|
|
742
|
|
|
$showDefaults = [ |
743
|
|
|
'_controller' => 'sylius.controller.product:showAction', |
744
|
|
|
'_sylius' => [ |
745
|
|
|
'permission' => false, |
746
|
|
|
], |
747
|
|
|
]; |
748
|
|
|
$routeFactory->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
749
|
|
|
$routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled(); |
750
|
|
|
|
751
|
|
|
$indexDefaults = [ |
752
|
|
|
'_controller' => 'sylius.controller.product:indexAction', |
753
|
|
|
'_sylius' => [ |
754
|
|
|
'permission' => false, |
755
|
|
|
], |
756
|
|
|
]; |
757
|
|
|
$routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
758
|
|
|
$routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
759
|
|
|
|
760
|
|
|
$createDefaults = [ |
761
|
|
|
'_controller' => 'sylius.controller.product:createAction', |
762
|
|
|
'_sylius' => [ |
763
|
|
|
'redirect' => 'sylius_product_update', |
764
|
|
|
'permission' => false, |
765
|
|
|
], |
766
|
|
|
]; |
767
|
|
|
$routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
768
|
|
|
$routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
769
|
|
|
|
770
|
|
|
$updateDefaults = [ |
771
|
|
|
'_controller' => 'sylius.controller.product:updateAction', |
772
|
|
|
'_sylius' => [ |
773
|
|
|
'redirect' => 'sylius_product_update', |
774
|
|
|
'permission' => false, |
775
|
|
|
], |
776
|
|
|
]; |
777
|
|
|
$routeFactory->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
778
|
|
|
$routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
779
|
|
|
|
780
|
|
|
$deleteDefaults = [ |
781
|
|
|
'_controller' => 'sylius.controller.product:deleteAction', |
782
|
|
|
'_sylius' => [ |
783
|
|
|
'permission' => false, |
784
|
|
|
], |
785
|
|
|
]; |
786
|
|
|
$routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
787
|
|
|
$routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled(); |
788
|
|
|
|
789
|
|
|
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
790
|
|
|
} |
791
|
|
|
|
792
|
|
|
function it_generates_api_routing_based_on_resource_configuration( |
793
|
|
|
RegistryInterface $resourceRegistry, |
794
|
|
|
MetadataInterface $metadata, |
795
|
|
|
RouteFactoryInterface $routeFactory, |
796
|
|
|
RouteCollection $routeCollection, |
797
|
|
|
Route $showRoute, |
798
|
|
|
Route $indexRoute, |
799
|
|
|
Route $createRoute, |
800
|
|
|
Route $updateRoute, |
801
|
|
|
Route $deleteRoute |
802
|
|
|
): void { |
803
|
|
|
$resourceRegistry->get('sylius.product')->willReturn($metadata); |
|
|
|
|
804
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
805
|
|
|
$metadata->getName()->willReturn('product'); |
806
|
|
|
$metadata->getPluralName()->willReturn('products'); |
807
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
808
|
|
|
|
809
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
810
|
|
|
|
811
|
|
|
$configuration = |
812
|
|
|
<<<EOT |
813
|
|
|
alias: sylius.product |
814
|
|
|
EOT; |
815
|
|
|
|
816
|
|
|
$showDefaults = [ |
817
|
|
|
'_controller' => 'sylius.controller.product:showAction', |
818
|
|
|
'_sylius' => [ |
819
|
|
|
'serialization_groups' => ['Default', 'Detailed'], |
820
|
|
|
'permission' => false, |
821
|
|
|
], |
822
|
|
|
]; |
823
|
|
|
$routeFactory->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
824
|
|
|
$routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled(); |
825
|
|
|
|
826
|
|
|
$indexDefaults = [ |
827
|
|
|
'_controller' => 'sylius.controller.product:indexAction', |
828
|
|
|
'_sylius' => [ |
829
|
|
|
'serialization_groups' => ['Default'], |
830
|
|
|
'permission' => false, |
831
|
|
|
], |
832
|
|
|
]; |
833
|
|
|
$routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
834
|
|
|
$routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
835
|
|
|
|
836
|
|
|
$createDefaults = [ |
837
|
|
|
'_controller' => 'sylius.controller.product:createAction', |
838
|
|
|
'_sylius' => [ |
839
|
|
|
'serialization_groups' => ['Default', 'Detailed'], |
840
|
|
|
'permission' => false, |
841
|
|
|
], |
842
|
|
|
]; |
843
|
|
|
$routeFactory->createRoute('/products/', $createDefaults, [], [], '', [], ['POST'])->willReturn($createRoute); |
844
|
|
|
$routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
845
|
|
|
|
846
|
|
|
$updateDefaults = [ |
847
|
|
|
'_controller' => 'sylius.controller.product:updateAction', |
848
|
|
|
'_sylius' => [ |
849
|
|
|
'serialization_groups' => ['Default', 'Detailed'], |
850
|
|
|
'permission' => false, |
851
|
|
|
], |
852
|
|
|
]; |
853
|
|
|
$routeFactory->createRoute('/products/{id}', $updateDefaults, [], [], '', [], ['PUT', 'PATCH'])->willReturn($updateRoute); |
854
|
|
|
$routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
855
|
|
|
|
856
|
|
|
$deleteDefaults = [ |
857
|
|
|
'_controller' => 'sylius.controller.product:deleteAction', |
858
|
|
|
'_sylius' => [ |
859
|
|
|
'permission' => false, |
860
|
|
|
'csrf_protection' => false, |
861
|
|
|
], |
862
|
|
|
]; |
863
|
|
|
$routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
864
|
|
|
$routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled(); |
865
|
|
|
|
866
|
|
|
$this->load($configuration, 'sylius.resource_api')->shouldReturn($routeCollection); |
867
|
|
|
} |
868
|
|
|
|
869
|
|
|
function it_configures_grid_for_index_action_if_specified( |
870
|
|
|
RegistryInterface $resourceRegistry, |
871
|
|
|
MetadataInterface $metadata, |
872
|
|
|
RouteFactoryInterface $routeFactory, |
873
|
|
|
RouteCollection $routeCollection, |
874
|
|
|
Route $indexRoute, |
875
|
|
|
Route $createRoute |
876
|
|
|
): void { |
877
|
|
|
$resourceRegistry->get('sylius.product')->willReturn($metadata); |
|
|
|
|
878
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
879
|
|
|
$metadata->getName()->willReturn('product'); |
880
|
|
|
$metadata->getPluralName()->willReturn('products'); |
881
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
882
|
|
|
|
883
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
884
|
|
|
|
885
|
|
|
$configuration = |
886
|
|
|
<<<EOT |
887
|
|
|
alias: sylius.product |
888
|
|
|
only: ['create', 'index'] |
889
|
|
|
grid: sylius_admin_product |
890
|
|
|
EOT; |
891
|
|
|
|
892
|
|
|
$indexDefaults = [ |
893
|
|
|
'_controller' => 'sylius.controller.product:indexAction', |
894
|
|
|
'_sylius' => [ |
895
|
|
|
'grid' => 'sylius_admin_product', |
896
|
|
|
'permission' => false, |
897
|
|
|
], |
898
|
|
|
]; |
899
|
|
|
$routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
900
|
|
|
$routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
901
|
|
|
|
902
|
|
|
$createDefaults = [ |
903
|
|
|
'_controller' => 'sylius.controller.product:createAction', |
904
|
|
|
'_sylius' => [ |
905
|
|
|
'permission' => false, |
906
|
|
|
], |
907
|
|
|
]; |
908
|
|
|
$routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
909
|
|
|
$routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
910
|
|
|
|
911
|
|
|
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
912
|
|
|
} |
913
|
|
|
|
914
|
|
|
function it_generates_routing_with_custom_variables( |
915
|
|
|
RegistryInterface $resourceRegistry, |
916
|
|
|
MetadataInterface $metadata, |
917
|
|
|
RouteFactoryInterface $routeFactory, |
918
|
|
|
RouteCollection $routeCollection, |
919
|
|
|
Route $showRoute, |
920
|
|
|
Route $indexRoute, |
921
|
|
|
Route $createRoute, |
922
|
|
|
Route $updateRoute, |
923
|
|
|
Route $deleteRoute |
924
|
|
|
): void { |
925
|
|
|
$resourceRegistry->get('sylius.product')->willReturn($metadata); |
|
|
|
|
926
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
927
|
|
|
$metadata->getName()->willReturn('product'); |
928
|
|
|
$metadata->getPluralName()->willReturn('products'); |
929
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
930
|
|
|
|
931
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
932
|
|
|
|
933
|
|
|
$configuration = |
934
|
|
|
<<<EOT |
935
|
|
|
alias: sylius.product |
936
|
|
|
vars: |
937
|
|
|
all: |
938
|
|
|
foo: bar |
939
|
|
|
create: |
940
|
|
|
bar: foo |
941
|
|
|
update: |
942
|
|
|
abc: xyz |
943
|
|
|
EOT; |
944
|
|
|
|
945
|
|
|
$showDefaults = [ |
946
|
|
|
'_controller' => 'sylius.controller.product:showAction', |
947
|
|
|
'_sylius' => [ |
948
|
|
|
'permission' => false, |
949
|
|
|
'vars' => [ |
950
|
|
|
'foo' => 'bar', |
951
|
|
|
], |
952
|
|
|
], |
953
|
|
|
]; |
954
|
|
|
$routeFactory->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
955
|
|
|
$routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled(); |
956
|
|
|
|
957
|
|
|
$indexDefaults = [ |
958
|
|
|
'_controller' => 'sylius.controller.product:indexAction', |
959
|
|
|
'_sylius' => [ |
960
|
|
|
'permission' => false, |
961
|
|
|
'vars' => [ |
962
|
|
|
'foo' => 'bar', |
963
|
|
|
], |
964
|
|
|
], |
965
|
|
|
]; |
966
|
|
|
$routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
967
|
|
|
$routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
968
|
|
|
|
969
|
|
|
$createDefaults = [ |
970
|
|
|
'_controller' => 'sylius.controller.product:createAction', |
971
|
|
|
'_sylius' => [ |
972
|
|
|
'permission' => false, |
973
|
|
|
'vars' => [ |
974
|
|
|
'foo' => 'bar', |
975
|
|
|
'bar' => 'foo', |
976
|
|
|
], |
977
|
|
|
], |
978
|
|
|
]; |
979
|
|
|
$routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
980
|
|
|
$routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
981
|
|
|
|
982
|
|
|
$updateDefaults = [ |
983
|
|
|
'_controller' => 'sylius.controller.product:updateAction', |
984
|
|
|
'_sylius' => [ |
985
|
|
|
'permission' => false, |
986
|
|
|
'vars' => [ |
987
|
|
|
'foo' => 'bar', |
988
|
|
|
'abc' => 'xyz', |
989
|
|
|
], |
990
|
|
|
], |
991
|
|
|
]; |
992
|
|
|
$routeFactory->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
993
|
|
|
$routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
994
|
|
|
|
995
|
|
|
$deleteDefaults = [ |
996
|
|
|
'_controller' => 'sylius.controller.product:deleteAction', |
997
|
|
|
'_sylius' => [ |
998
|
|
|
'permission' => false, |
999
|
|
|
'vars' => [ |
1000
|
|
|
'foo' => 'bar', |
1001
|
|
|
], |
1002
|
|
|
], |
1003
|
|
|
]; |
1004
|
|
|
$routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
1005
|
|
|
$routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled(); |
1006
|
|
|
|
1007
|
|
|
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
1008
|
|
|
} |
1009
|
|
|
|
1010
|
|
|
function it_generates_routing_with_custom_permission( |
1011
|
|
|
RegistryInterface $resourceRegistry, |
1012
|
|
|
MetadataInterface $metadata, |
1013
|
|
|
RouteFactoryInterface $routeFactory, |
1014
|
|
|
RouteCollection $routeCollection, |
1015
|
|
|
Route $showRoute, |
1016
|
|
|
Route $indexRoute, |
1017
|
|
|
Route $createRoute, |
1018
|
|
|
Route $updateRoute, |
1019
|
|
|
Route $deleteRoute |
1020
|
|
|
): void { |
1021
|
|
|
$resourceRegistry->get('sylius.product')->willReturn($metadata); |
|
|
|
|
1022
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
1023
|
|
|
$metadata->getName()->willReturn('product'); |
1024
|
|
|
$metadata->getPluralName()->willReturn('products'); |
1025
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
1026
|
|
|
|
1027
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
1028
|
|
|
|
1029
|
|
|
$configuration = |
1030
|
|
|
<<<EOT |
1031
|
|
|
alias: sylius.product |
1032
|
|
|
permission: true |
1033
|
|
|
EOT; |
1034
|
|
|
|
1035
|
|
|
$showDefaults = [ |
1036
|
|
|
'_controller' => 'sylius.controller.product:showAction', |
1037
|
|
|
'_sylius' => [ |
1038
|
|
|
'permission' => true, |
1039
|
|
|
], |
1040
|
|
|
]; |
1041
|
|
|
$routeFactory->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
1042
|
|
|
$routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled(); |
1043
|
|
|
|
1044
|
|
|
$indexDefaults = [ |
1045
|
|
|
'_controller' => 'sylius.controller.product:indexAction', |
1046
|
|
|
'_sylius' => [ |
1047
|
|
|
'permission' => true, |
1048
|
|
|
], |
1049
|
|
|
]; |
1050
|
|
|
$routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
1051
|
|
|
$routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
1052
|
|
|
|
1053
|
|
|
$createDefaults = [ |
1054
|
|
|
'_controller' => 'sylius.controller.product:createAction', |
1055
|
|
|
'_sylius' => [ |
1056
|
|
|
'permission' => true, |
1057
|
|
|
], |
1058
|
|
|
]; |
1059
|
|
|
$routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST']) |
1060
|
|
|
->willReturn($createRoute); |
1061
|
|
|
$routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
1062
|
|
|
|
1063
|
|
|
$updateDefaults = [ |
1064
|
|
|
'_controller' => 'sylius.controller.product:updateAction', |
1065
|
|
|
'_sylius' => [ |
1066
|
|
|
'permission' => true, |
1067
|
|
|
], |
1068
|
|
|
]; |
1069
|
|
|
$routeFactory->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH']) |
1070
|
|
|
->willReturn($updateRoute); |
1071
|
|
|
$routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
1072
|
|
|
|
1073
|
|
|
$deleteDefaults = [ |
1074
|
|
|
'_controller' => 'sylius.controller.product:deleteAction', |
1075
|
|
|
'_sylius' => [ |
1076
|
|
|
'permission' => true, |
1077
|
|
|
], |
1078
|
|
|
]; |
1079
|
|
|
$routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE']) |
1080
|
|
|
->willReturn($deleteRoute); |
1081
|
|
|
$routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled(); |
1082
|
|
|
|
1083
|
|
|
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
1084
|
|
|
} |
1085
|
|
|
|
1086
|
|
|
function it_supports_sylius_resource_type(): void |
1087
|
|
|
{ |
1088
|
|
|
$this->supports('sylius.product', 'sylius.resource')->shouldReturn(true); |
1089
|
|
|
$this->supports('sylius.product', 'sylius.resource_api')->shouldReturn(true); |
1090
|
|
|
$this->supports('sylius.product', 'abc')->shouldReturn(false); |
1091
|
|
|
} |
1092
|
|
|
} |
1093
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.