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
|
|
|
namespace spec\Sylius\Bundle\ResourceBundle\Routing; |
13
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
15
|
|
|
use Sylius\Bundle\ResourceBundle\Routing\ResourceLoader; |
16
|
|
|
use Sylius\Bundle\ResourceBundle\Routing\RouteFactoryInterface; |
17
|
|
|
use Sylius\Component\Resource\Metadata\MetadataInterface; |
18
|
|
|
use Sylius\Component\Resource\Metadata\RegistryInterface; |
19
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
20
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
21
|
|
|
use Symfony\Component\Routing\Route; |
22
|
|
|
use Symfony\Component\Routing\RouteCollection; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @mixin ResourceLoader |
26
|
|
|
* |
27
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
28
|
|
|
*/ |
29
|
|
|
class ResourceLoaderSpec extends ObjectBehavior |
30
|
|
|
{ |
31
|
|
|
function let(RegistryInterface $resourceRegistry, RouteFactoryInterface $routeFactory) |
32
|
|
|
{ |
33
|
|
|
$this->beConstructedWith($resourceRegistry, $routeFactory); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
function it_is_initializable() |
37
|
|
|
{ |
38
|
|
|
$this->shouldHaveType('Sylius\Bundle\ResourceBundle\Routing\ResourceLoader'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
function it_is_a_Symfony_routing_loader() |
42
|
|
|
{ |
43
|
|
|
$this->shouldImplement(LoaderInterface::class); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
function it_processes_configuration_and_throws_exception_if_invalid() |
47
|
|
|
{ |
48
|
|
|
$configuration = |
49
|
|
|
<<<EOT |
50
|
|
|
foo: bar |
51
|
|
|
only: string |
52
|
|
|
EOT; |
53
|
|
|
|
54
|
|
|
$this |
55
|
|
|
->shouldThrow(InvalidConfigurationException::class) |
56
|
|
|
->during('load', [$configuration, 'sylius.resource']) |
57
|
|
|
; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
function it_throws_an_exception_if_invalid_resource_configured(RegistryInterface $resourceRegistry) |
61
|
|
|
{ |
62
|
|
|
$resourceRegistry->get('sylius.foo')->willThrow(new \InvalidArgumentException()); |
63
|
|
|
|
64
|
|
|
$configuration = |
65
|
|
|
<<<EOT |
66
|
|
|
alias: sylius.foo |
67
|
|
|
EOT; |
68
|
|
|
|
69
|
|
|
$this |
70
|
|
|
->shouldThrow(\InvalidArgumentException::class) |
71
|
|
|
->during('load', [$configuration, 'sylius.resource']) |
72
|
|
|
; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
function it_generates_routing_based_on_resource_configuration( |
76
|
|
|
RegistryInterface $resourceRegistry, |
77
|
|
|
MetadataInterface $metadata, |
78
|
|
|
RouteFactoryInterface $routeFactory, |
79
|
|
|
RouteCollection $routeCollection, |
80
|
|
|
Route $showRoute, |
81
|
|
|
Route $indexRoute, |
82
|
|
|
Route $createRoute, |
83
|
|
|
Route $updateRoute, |
84
|
|
|
Route $deleteRoute |
85
|
|
|
) { |
86
|
|
|
$resourceRegistry->get('sylius.product')->willReturn($metadata); |
87
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
88
|
|
|
$metadata->getName()->willReturn('product'); |
89
|
|
|
$metadata->getPluralName()->willReturn('products'); |
90
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
91
|
|
|
|
92
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
93
|
|
|
|
94
|
|
|
$configuration = |
95
|
|
|
<<<EOT |
96
|
|
|
alias: sylius.product |
97
|
|
|
EOT; |
98
|
|
|
|
99
|
|
|
$showDefaults = [ |
100
|
|
|
'_controller' => 'sylius.controller.product:showAction', |
101
|
|
|
]; |
102
|
|
|
$routeFactory->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
103
|
|
|
$routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled(); |
104
|
|
|
|
105
|
|
|
$indexDefaults = [ |
106
|
|
|
'_controller' => 'sylius.controller.product:indexAction', |
107
|
|
|
]; |
108
|
|
|
$routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
109
|
|
|
$routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
110
|
|
|
|
111
|
|
|
$createDefaults = [ |
112
|
|
|
'_controller' => 'sylius.controller.product:createAction', |
113
|
|
|
]; |
114
|
|
|
$routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
115
|
|
|
$routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
116
|
|
|
|
117
|
|
|
$updateDefaults = [ |
118
|
|
|
'_controller' => 'sylius.controller.product:updateAction', |
119
|
|
|
]; |
120
|
|
|
$routeFactory->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
121
|
|
|
$routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
122
|
|
|
|
123
|
|
|
$deleteDefaults = [ |
124
|
|
|
'_controller' => 'sylius.controller.product:deleteAction', |
125
|
|
|
]; |
126
|
|
|
$routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
127
|
|
|
$routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled(); |
128
|
|
|
|
129
|
|
|
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
function it_generates_urlized_paths_for_resources_with_multiple_words_in_name( |
133
|
|
|
RegistryInterface $resourceRegistry, |
134
|
|
|
MetadataInterface $metadata, |
135
|
|
|
RouteFactoryInterface $routeFactory, |
136
|
|
|
RouteCollection $routeCollection, |
137
|
|
|
Route $showRoute, |
138
|
|
|
Route $indexRoute, |
139
|
|
|
Route $createRoute, |
140
|
|
|
Route $updateRoute, |
141
|
|
|
Route $deleteRoute |
142
|
|
|
) { |
143
|
|
|
$resourceRegistry->get('sylius.product_option')->willReturn($metadata); |
144
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
145
|
|
|
$metadata->getName()->willReturn('product_option'); |
146
|
|
|
$metadata->getPluralName()->willReturn('product_options'); |
147
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product_option'); |
148
|
|
|
|
149
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
150
|
|
|
|
151
|
|
|
$configuration = |
152
|
|
|
<<<EOT |
153
|
|
|
alias: sylius.product_option |
154
|
|
|
EOT; |
155
|
|
|
|
156
|
|
|
$showDefaults = [ |
157
|
|
|
'_controller' => 'sylius.controller.product_option:showAction', |
158
|
|
|
]; |
159
|
|
|
$routeFactory->createRoute('/product-options/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
160
|
|
|
$routeCollection->add('sylius_product_option_show', $showRoute)->shouldBeCalled(); |
161
|
|
|
|
162
|
|
|
$indexDefaults = [ |
163
|
|
|
'_controller' => 'sylius.controller.product_option:indexAction', |
164
|
|
|
]; |
165
|
|
|
$routeFactory->createRoute('/product-options/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
166
|
|
|
$routeCollection->add('sylius_product_option_index', $indexRoute)->shouldBeCalled(); |
167
|
|
|
|
168
|
|
|
$createDefaults = [ |
169
|
|
|
'_controller' => 'sylius.controller.product_option:createAction', |
170
|
|
|
]; |
171
|
|
|
$routeFactory->createRoute('/product-options/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
172
|
|
|
$routeCollection->add('sylius_product_option_create', $createRoute)->shouldBeCalled(); |
173
|
|
|
|
174
|
|
|
$updateDefaults = [ |
175
|
|
|
'_controller' => 'sylius.controller.product_option:updateAction', |
176
|
|
|
]; |
177
|
|
|
$routeFactory->createRoute('/product-options/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
178
|
|
|
$routeCollection->add('sylius_product_option_update', $updateRoute)->shouldBeCalled(); |
179
|
|
|
|
180
|
|
|
$deleteDefaults = [ |
181
|
|
|
'_controller' => 'sylius.controller.product_option:deleteAction', |
182
|
|
|
]; |
183
|
|
|
$routeFactory->createRoute('/product-options/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
184
|
|
|
$routeCollection->add('sylius_product_option_delete', $deleteRoute)->shouldBeCalled(); |
185
|
|
|
|
186
|
|
|
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
function it_generates_routing_with_custom_path_if_specified( |
190
|
|
|
RegistryInterface $resourceRegistry, |
191
|
|
|
MetadataInterface $metadata, |
192
|
|
|
RouteFactoryInterface $routeFactory, |
193
|
|
|
RouteCollection $routeCollection, |
194
|
|
|
Route $showRoute, |
195
|
|
|
Route $indexRoute, |
196
|
|
|
Route $createRoute, |
197
|
|
|
Route $updateRoute, |
198
|
|
|
Route $deleteRoute |
199
|
|
|
) { |
200
|
|
|
$resourceRegistry->get('sylius.product')->willReturn($metadata); |
201
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
202
|
|
|
$metadata->getName()->willReturn('product'); |
203
|
|
|
$metadata->getPluralName()->willReturn('products'); |
204
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
205
|
|
|
|
206
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
207
|
|
|
|
208
|
|
|
$configuration = |
209
|
|
|
<<<EOT |
210
|
|
|
alias: sylius.product |
211
|
|
|
path: super-duper-products |
212
|
|
|
EOT; |
213
|
|
|
|
214
|
|
|
$showDefaults = [ |
215
|
|
|
'_controller' => 'sylius.controller.product:showAction', |
216
|
|
|
]; |
217
|
|
|
$routeFactory->createRoute('/super-duper-products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
218
|
|
|
$routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled(); |
219
|
|
|
|
220
|
|
|
$indexDefaults = [ |
221
|
|
|
'_controller' => 'sylius.controller.product:indexAction', |
222
|
|
|
]; |
223
|
|
|
$routeFactory->createRoute('/super-duper-products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
224
|
|
|
$routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
225
|
|
|
|
226
|
|
|
$createDefaults = [ |
227
|
|
|
'_controller' => 'sylius.controller.product:createAction', |
228
|
|
|
]; |
229
|
|
|
$routeFactory->createRoute('/super-duper-products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
230
|
|
|
$routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
231
|
|
|
|
232
|
|
|
$updateDefaults = [ |
233
|
|
|
'_controller' => 'sylius.controller.product:updateAction', |
234
|
|
|
]; |
235
|
|
|
$routeFactory->createRoute('/super-duper-products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
236
|
|
|
$routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
237
|
|
|
|
238
|
|
|
$deleteDefaults = [ |
239
|
|
|
'_controller' => 'sylius.controller.product:deleteAction', |
240
|
|
|
]; |
241
|
|
|
$routeFactory->createRoute('/super-duper-products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
242
|
|
|
$routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled(); |
243
|
|
|
|
244
|
|
|
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
function it_generates_routing_with_custom_form_if_specified( |
248
|
|
|
RegistryInterface $resourceRegistry, |
249
|
|
|
MetadataInterface $metadata, |
250
|
|
|
RouteFactoryInterface $routeFactory, |
251
|
|
|
RouteCollection $routeCollection, |
252
|
|
|
Route $showRoute, |
253
|
|
|
Route $indexRoute, |
254
|
|
|
Route $createRoute, |
255
|
|
|
Route $updateRoute, |
256
|
|
|
Route $deleteRoute |
257
|
|
|
) { |
258
|
|
|
$resourceRegistry->get('sylius.product')->willReturn($metadata); |
259
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
260
|
|
|
$metadata->getName()->willReturn('product'); |
261
|
|
|
$metadata->getPluralName()->willReturn('products'); |
262
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
263
|
|
|
|
264
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
265
|
|
|
|
266
|
|
|
$configuration = |
267
|
|
|
<<<EOT |
268
|
|
|
alias: sylius.product |
269
|
|
|
form: sylius_product_custom |
270
|
|
|
EOT; |
271
|
|
|
|
272
|
|
|
$showDefaults = [ |
273
|
|
|
'_controller' => 'sylius.controller.product:showAction', |
274
|
|
|
]; |
275
|
|
|
$routeFactory->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
276
|
|
|
$routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled(); |
277
|
|
|
|
278
|
|
|
$indexDefaults = [ |
279
|
|
|
'_controller' => 'sylius.controller.product:indexAction', |
280
|
|
|
]; |
281
|
|
|
$routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
282
|
|
|
$routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
283
|
|
|
|
284
|
|
|
$createDefaults = [ |
285
|
|
|
'_controller' => 'sylius.controller.product:createAction', |
286
|
|
|
'_sylius' => [ |
287
|
|
|
'form' => 'sylius_product_custom', |
288
|
|
|
], |
289
|
|
|
]; |
290
|
|
|
$routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
291
|
|
|
$routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
292
|
|
|
|
293
|
|
|
$updateDefaults = [ |
294
|
|
|
'_controller' => 'sylius.controller.product:updateAction', |
295
|
|
|
'_sylius' => [ |
296
|
|
|
'form' => 'sylius_product_custom', |
297
|
|
|
], |
298
|
|
|
]; |
299
|
|
|
$routeFactory->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
300
|
|
|
$routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
301
|
|
|
|
302
|
|
|
$deleteDefaults = [ |
303
|
|
|
'_controller' => 'sylius.controller.product:deleteAction', |
304
|
|
|
]; |
305
|
|
|
$routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
306
|
|
|
$routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled(); |
307
|
|
|
|
308
|
|
|
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
function it_generates_routing_for_a_section( |
312
|
|
|
RegistryInterface $resourceRegistry, |
313
|
|
|
MetadataInterface $metadata, |
314
|
|
|
RouteFactoryInterface $routeFactory, |
315
|
|
|
RouteCollection $routeCollection, |
316
|
|
|
Route $showRoute, |
317
|
|
|
Route $indexRoute, |
318
|
|
|
Route $createRoute, |
319
|
|
|
Route $updateRoute, |
320
|
|
|
Route $deleteRoute |
321
|
|
|
) { |
322
|
|
|
$resourceRegistry->get('sylius.product')->willReturn($metadata); |
323
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
324
|
|
|
$metadata->getName()->willReturn('product'); |
325
|
|
|
$metadata->getPluralName()->willReturn('products'); |
326
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
327
|
|
|
|
328
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
329
|
|
|
|
330
|
|
|
$configuration = |
331
|
|
|
<<<EOT |
332
|
|
|
alias: sylius.product |
333
|
|
|
section: admin |
334
|
|
|
EOT; |
335
|
|
|
|
336
|
|
|
$showDefaults = [ |
337
|
|
|
'_controller' => 'sylius.controller.product:showAction', |
338
|
|
|
'_sylius' => [ |
339
|
|
|
'section' => 'admin', |
340
|
|
|
], |
341
|
|
|
]; |
342
|
|
|
$routeFactory->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
343
|
|
|
$routeCollection->add('sylius_admin_product_show', $showRoute)->shouldBeCalled(); |
344
|
|
|
|
345
|
|
|
$indexDefaults = [ |
346
|
|
|
'_controller' => 'sylius.controller.product:indexAction', |
347
|
|
|
'_sylius' => [ |
348
|
|
|
'section' => 'admin', |
349
|
|
|
], |
350
|
|
|
]; |
351
|
|
|
$routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
352
|
|
|
$routeCollection->add('sylius_admin_product_index', $indexRoute)->shouldBeCalled(); |
353
|
|
|
|
354
|
|
|
$createDefaults = [ |
355
|
|
|
'_controller' => 'sylius.controller.product:createAction', |
356
|
|
|
'_sylius' => [ |
357
|
|
|
'section' => 'admin', |
358
|
|
|
], |
359
|
|
|
]; |
360
|
|
|
$routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
361
|
|
|
$routeCollection->add('sylius_admin_product_create', $createRoute)->shouldBeCalled(); |
362
|
|
|
|
363
|
|
|
$updateDefaults = [ |
364
|
|
|
'_controller' => 'sylius.controller.product:updateAction', |
365
|
|
|
'_sylius' => [ |
366
|
|
|
'section' => 'admin', |
367
|
|
|
], |
368
|
|
|
]; |
369
|
|
|
$routeFactory->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
370
|
|
|
$routeCollection->add('sylius_admin_product_update', $updateRoute)->shouldBeCalled(); |
371
|
|
|
|
372
|
|
|
$deleteDefaults = [ |
373
|
|
|
'_controller' => 'sylius.controller.product:deleteAction', |
374
|
|
|
'_sylius' => [ |
375
|
|
|
'section' => 'admin', |
376
|
|
|
], |
377
|
|
|
]; |
378
|
|
|
$routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
379
|
|
|
$routeCollection->add('sylius_admin_product_delete', $deleteRoute)->shouldBeCalled(); |
380
|
|
|
|
381
|
|
|
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
function it_generates_routing_with_custom_templates_namespace( |
385
|
|
|
RegistryInterface $resourceRegistry, |
386
|
|
|
MetadataInterface $metadata, |
387
|
|
|
RouteFactoryInterface $routeFactory, |
388
|
|
|
RouteCollection $routeCollection, |
389
|
|
|
Route $showRoute, |
390
|
|
|
Route $indexRoute, |
391
|
|
|
Route $createRoute, |
392
|
|
|
Route $updateRoute, |
393
|
|
|
Route $deleteRoute |
394
|
|
|
) { |
395
|
|
|
$resourceRegistry->get('sylius.product')->willReturn($metadata); |
396
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
397
|
|
|
$metadata->getName()->willReturn('product'); |
398
|
|
|
$metadata->getPluralName()->willReturn('products'); |
399
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
400
|
|
|
|
401
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
402
|
|
|
|
403
|
|
|
$configuration = |
404
|
|
|
<<<EOT |
405
|
|
|
alias: sylius.product |
406
|
|
|
templates: SyliusAdminBundle:Product |
407
|
|
|
EOT; |
408
|
|
|
|
409
|
|
|
$showDefaults = [ |
410
|
|
|
'_controller' => 'sylius.controller.product:showAction', |
411
|
|
|
'_sylius' => [ |
412
|
|
|
'template' => 'SyliusAdminBundle:Product:show.html.twig', |
413
|
|
|
], |
414
|
|
|
]; |
415
|
|
|
$routeFactory->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
416
|
|
|
$routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled(); |
417
|
|
|
|
418
|
|
|
$indexDefaults = [ |
419
|
|
|
'_controller' => 'sylius.controller.product:indexAction', |
420
|
|
|
'_sylius' => [ |
421
|
|
|
'template' => 'SyliusAdminBundle:Product:index.html.twig', |
422
|
|
|
], |
423
|
|
|
]; |
424
|
|
|
$routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
425
|
|
|
$routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
426
|
|
|
|
427
|
|
|
$createDefaults = [ |
428
|
|
|
'_controller' => 'sylius.controller.product:createAction', |
429
|
|
|
'_sylius' => [ |
430
|
|
|
'template' => 'SyliusAdminBundle:Product:create.html.twig', |
431
|
|
|
], |
432
|
|
|
]; |
433
|
|
|
$routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
434
|
|
|
$routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
435
|
|
|
|
436
|
|
|
$updateDefaults = [ |
437
|
|
|
'_controller' => 'sylius.controller.product:updateAction', |
438
|
|
|
'_sylius' => [ |
439
|
|
|
'template' => 'SyliusAdminBundle:Product:update.html.twig', |
440
|
|
|
], |
441
|
|
|
]; |
442
|
|
|
$routeFactory->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
443
|
|
|
$routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
444
|
|
|
|
445
|
|
|
$deleteDefaults = [ |
446
|
|
|
'_controller' => 'sylius.controller.product:deleteAction', |
447
|
|
|
]; |
448
|
|
|
$routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
449
|
|
|
$routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled(); |
450
|
|
|
|
451
|
|
|
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
function it_excludes_specific_routes_if_configured( |
455
|
|
|
RegistryInterface $resourceRegistry, |
456
|
|
|
MetadataInterface $metadata, |
457
|
|
|
RouteFactoryInterface $routeFactory, |
458
|
|
|
RouteCollection $routeCollection, |
459
|
|
|
Route $indexRoute, |
460
|
|
|
Route $createRoute, |
461
|
|
|
Route $updateRoute |
462
|
|
|
) { |
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
|
|
|
except: ['show', 'delete'] |
475
|
|
|
EOT; |
476
|
|
|
|
477
|
|
|
$indexDefaults = [ |
478
|
|
|
'_controller' => 'sylius.controller.product:indexAction', |
479
|
|
|
]; |
480
|
|
|
$routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
481
|
|
|
$routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
482
|
|
|
|
483
|
|
|
$createDefaults = [ |
484
|
|
|
'_controller' => 'sylius.controller.product:createAction', |
485
|
|
|
]; |
486
|
|
|
$routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
487
|
|
|
$routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
488
|
|
|
|
489
|
|
|
$updateDefaults = [ |
490
|
|
|
'_controller' => 'sylius.controller.product:updateAction', |
491
|
|
|
]; |
492
|
|
|
$routeFactory->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
493
|
|
|
$routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
494
|
|
|
|
495
|
|
|
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
function it_includes_only_specific_routes_if_configured( |
499
|
|
|
RegistryInterface $resourceRegistry, |
500
|
|
|
MetadataInterface $metadata, |
501
|
|
|
RouteFactoryInterface $routeFactory, |
502
|
|
|
RouteCollection $routeCollection, |
503
|
|
|
Route $indexRoute, |
504
|
|
|
Route $createRoute |
505
|
|
|
) { |
506
|
|
|
$resourceRegistry->get('sylius.product')->willReturn($metadata); |
507
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
508
|
|
|
$metadata->getName()->willReturn('product'); |
509
|
|
|
$metadata->getPluralName()->willReturn('products'); |
510
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
511
|
|
|
|
512
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
513
|
|
|
|
514
|
|
|
$configuration = |
515
|
|
|
<<<EOT |
516
|
|
|
alias: sylius.product |
517
|
|
|
only: ['create', 'index'] |
518
|
|
|
EOT; |
519
|
|
|
|
520
|
|
|
$indexDefaults = [ |
521
|
|
|
'_controller' => 'sylius.controller.product:indexAction', |
522
|
|
|
]; |
523
|
|
|
$routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
524
|
|
|
$routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
525
|
|
|
|
526
|
|
|
$createDefaults = [ |
527
|
|
|
'_controller' => 'sylius.controller.product:createAction', |
528
|
|
|
]; |
529
|
|
|
$routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
530
|
|
|
$routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
531
|
|
|
|
532
|
|
|
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
533
|
|
|
} |
534
|
|
|
|
535
|
|
|
function it_throws_an_exception_if_both_excluded_and_includes_routes_configured() |
536
|
|
|
{ |
537
|
|
|
$configuration = |
538
|
|
|
<<<EOT |
539
|
|
|
alias: sylius.product |
540
|
|
|
except: ['show', 'delete'] |
541
|
|
|
only: ['create'] |
542
|
|
|
EOT; |
543
|
|
|
|
544
|
|
|
$this |
545
|
|
|
->shouldThrow(\InvalidArgumentException::class) |
546
|
|
|
->during('load', [$configuration, 'sylius.resource']) |
547
|
|
|
; |
548
|
|
|
} |
549
|
|
|
|
550
|
|
|
function it_generates_routing_with_custom_redirect_if_specified( |
551
|
|
|
RegistryInterface $resourceRegistry, |
552
|
|
|
MetadataInterface $metadata, |
553
|
|
|
RouteFactoryInterface $routeFactory, |
554
|
|
|
RouteCollection $routeCollection, |
555
|
|
|
Route $showRoute, |
556
|
|
|
Route $indexRoute, |
557
|
|
|
Route $createRoute, |
558
|
|
|
Route $updateRoute, |
559
|
|
|
Route $deleteRoute |
560
|
|
|
) { |
561
|
|
|
$resourceRegistry->get('sylius.product')->willReturn($metadata); |
562
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
563
|
|
|
$metadata->getName()->willReturn('product'); |
564
|
|
|
$metadata->getPluralName()->willReturn('products'); |
565
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
566
|
|
|
|
567
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
568
|
|
|
|
569
|
|
|
$configuration = |
570
|
|
|
<<<EOT |
571
|
|
|
alias: sylius.product |
572
|
|
|
redirect: update |
573
|
|
|
EOT; |
574
|
|
|
|
575
|
|
|
$showDefaults = [ |
576
|
|
|
'_controller' => 'sylius.controller.product:showAction', |
577
|
|
|
]; |
578
|
|
|
$routeFactory->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
579
|
|
|
$routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled(); |
580
|
|
|
|
581
|
|
|
$indexDefaults = [ |
582
|
|
|
'_controller' => 'sylius.controller.product:indexAction', |
583
|
|
|
]; |
584
|
|
|
$routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
585
|
|
|
$routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
586
|
|
|
|
587
|
|
|
$createDefaults = [ |
588
|
|
|
'_controller' => 'sylius.controller.product:createAction', |
589
|
|
|
'_sylius' => [ |
590
|
|
|
'redirect' => 'sylius_product_update', |
591
|
|
|
], |
592
|
|
|
]; |
593
|
|
|
$routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
594
|
|
|
$routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
595
|
|
|
|
596
|
|
|
$updateDefaults = [ |
597
|
|
|
'_controller' => 'sylius.controller.product:updateAction', |
598
|
|
|
'_sylius' => [ |
599
|
|
|
'redirect' => 'sylius_product_update', |
600
|
|
|
], |
601
|
|
|
]; |
602
|
|
|
$routeFactory->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
603
|
|
|
$routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
604
|
|
|
|
605
|
|
|
$deleteDefaults = [ |
606
|
|
|
'_controller' => 'sylius.controller.product:deleteAction', |
607
|
|
|
]; |
608
|
|
|
$routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
609
|
|
|
$routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled(); |
610
|
|
|
|
611
|
|
|
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
612
|
|
|
} |
613
|
|
|
|
614
|
|
|
function it_generates_api_routing_based_on_resource_configuration( |
615
|
|
|
RegistryInterface $resourceRegistry, |
616
|
|
|
MetadataInterface $metadata, |
617
|
|
|
RouteFactoryInterface $routeFactory, |
618
|
|
|
RouteCollection $routeCollection, |
619
|
|
|
Route $showRoute, |
620
|
|
|
Route $indexRoute, |
621
|
|
|
Route $createRoute, |
622
|
|
|
Route $updateRoute, |
623
|
|
|
Route $deleteRoute |
624
|
|
|
) { |
625
|
|
|
$resourceRegistry->get('sylius.product')->willReturn($metadata); |
626
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
627
|
|
|
$metadata->getName()->willReturn('product'); |
628
|
|
|
$metadata->getPluralName()->willReturn('products'); |
629
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
630
|
|
|
|
631
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
632
|
|
|
|
633
|
|
|
$configuration = |
634
|
|
|
<<<EOT |
635
|
|
|
alias: sylius.product |
636
|
|
|
EOT; |
637
|
|
|
|
638
|
|
|
$showDefaults = [ |
639
|
|
|
'_controller' => 'sylius.controller.product:showAction', |
640
|
|
|
]; |
641
|
|
|
$routeFactory->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
642
|
|
|
$routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled(); |
643
|
|
|
|
644
|
|
|
$indexDefaults = [ |
645
|
|
|
'_controller' => 'sylius.controller.product:indexAction', |
646
|
|
|
]; |
647
|
|
|
$routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
648
|
|
|
$routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
649
|
|
|
|
650
|
|
|
$createDefaults = [ |
651
|
|
|
'_controller' => 'sylius.controller.product:createAction', |
652
|
|
|
]; |
653
|
|
|
$routeFactory->createRoute('/products/', $createDefaults, [], [], '', [], ['POST'])->willReturn($createRoute); |
654
|
|
|
$routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
655
|
|
|
|
656
|
|
|
$updateDefaults = [ |
657
|
|
|
'_controller' => 'sylius.controller.product:updateAction', |
658
|
|
|
]; |
659
|
|
|
$routeFactory->createRoute('/products/{id}', $updateDefaults, [], [], '', [], ['PUT', 'PATCH'])->willReturn($updateRoute); |
660
|
|
|
$routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
661
|
|
|
|
662
|
|
|
$deleteDefaults = [ |
663
|
|
|
'_controller' => 'sylius.controller.product:deleteAction', |
664
|
|
|
]; |
665
|
|
|
$routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
666
|
|
|
$routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled(); |
667
|
|
|
|
668
|
|
|
$this->load($configuration, 'sylius.resource_api')->shouldReturn($routeCollection); |
669
|
|
|
} |
670
|
|
|
|
671
|
|
|
function it_generates_routing_with_custom_variables( |
672
|
|
|
RegistryInterface $resourceRegistry, |
673
|
|
|
MetadataInterface $metadata, |
674
|
|
|
RouteFactoryInterface $routeFactory, |
675
|
|
|
RouteCollection $routeCollection, |
676
|
|
|
Route $showRoute, |
677
|
|
|
Route $indexRoute, |
678
|
|
|
Route $createRoute, |
679
|
|
|
Route $updateRoute, |
680
|
|
|
Route $deleteRoute |
681
|
|
|
) { |
682
|
|
|
$resourceRegistry->get('sylius.product')->willReturn($metadata); |
683
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
684
|
|
|
$metadata->getName()->willReturn('product'); |
685
|
|
|
$metadata->getPluralName()->willReturn('products'); |
686
|
|
|
$metadata->getServiceId('controller')->willReturn('sylius.controller.product'); |
687
|
|
|
|
688
|
|
|
$routeFactory->createRouteCollection()->willReturn($routeCollection); |
689
|
|
|
|
690
|
|
|
$configuration = |
691
|
|
|
<<<EOT |
692
|
|
|
alias: sylius.product |
693
|
|
|
vars: |
694
|
|
|
all: |
695
|
|
|
foo: bar |
696
|
|
|
create: |
697
|
|
|
bar: foo |
698
|
|
|
update: |
699
|
|
|
abc: xyz |
700
|
|
|
EOT; |
701
|
|
|
|
702
|
|
|
$showDefaults = [ |
703
|
|
|
'_controller' => 'sylius.controller.product:showAction', |
704
|
|
|
'_sylius' => [ |
705
|
|
|
'vars' => [ |
706
|
|
|
'foo' => 'bar', |
707
|
|
|
] |
708
|
|
|
], |
709
|
|
|
]; |
710
|
|
|
$routeFactory->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])->willReturn($showRoute); |
711
|
|
|
$routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled(); |
712
|
|
|
|
713
|
|
|
$indexDefaults = [ |
714
|
|
|
'_controller' => 'sylius.controller.product:indexAction', |
715
|
|
|
'_sylius' => [ |
716
|
|
|
'vars' => [ |
717
|
|
|
'foo' => 'bar', |
718
|
|
|
] |
719
|
|
|
], |
720
|
|
|
]; |
721
|
|
|
$routeFactory->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])->willReturn($indexRoute); |
722
|
|
|
$routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled(); |
723
|
|
|
|
724
|
|
|
$createDefaults = [ |
725
|
|
|
'_controller' => 'sylius.controller.product:createAction', |
726
|
|
|
'_sylius' => [ |
727
|
|
|
'vars' => [ |
728
|
|
|
'foo' => 'bar', |
729
|
|
|
'bar' => 'foo', |
730
|
|
|
] |
731
|
|
|
], |
732
|
|
|
]; |
733
|
|
|
$routeFactory->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])->willReturn($createRoute); |
734
|
|
|
$routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled(); |
735
|
|
|
|
736
|
|
|
$updateDefaults = [ |
737
|
|
|
'_controller' => 'sylius.controller.product:updateAction', |
738
|
|
|
'_sylius' => [ |
739
|
|
|
'vars' => [ |
740
|
|
|
'foo' => 'bar', |
741
|
|
|
'abc' => 'xyz', |
742
|
|
|
] |
743
|
|
|
], |
744
|
|
|
]; |
745
|
|
|
$routeFactory->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])->willReturn($updateRoute); |
746
|
|
|
$routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled(); |
747
|
|
|
|
748
|
|
|
$deleteDefaults = [ |
749
|
|
|
'_controller' => 'sylius.controller.product:deleteAction', |
750
|
|
|
'_sylius' => [ |
751
|
|
|
'vars' => [ |
752
|
|
|
'foo' => 'bar', |
753
|
|
|
] |
754
|
|
|
], |
755
|
|
|
]; |
756
|
|
|
$routeFactory->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])->willReturn($deleteRoute); |
757
|
|
|
$routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled(); |
758
|
|
|
|
759
|
|
|
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection); |
760
|
|
|
} |
761
|
|
|
|
762
|
|
|
function it_supports_sylius_resource_type() |
763
|
|
|
{ |
764
|
|
|
$this->supports('sylius.product', 'sylius.resource')->shouldReturn(true); |
765
|
|
|
$this->supports('sylius.product', 'sylius.resource_api')->shouldReturn(true); |
766
|
|
|
$this->supports('sylius.product', 'abc')->shouldReturn(false); |
767
|
|
|
} |
768
|
|
|
} |
769
|
|
|
|