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