1 | <?php |
||
29 | class ResourceLoaderSpec extends ObjectBehavior |
||
30 | { |
||
31 | function let(RegistryInterface $resourceRegistry, RouteFactoryInterface $routeFactory) |
||
35 | |||
36 | function it_is_initializable() |
||
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() |
||
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() |
||
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 |
||
613 | |||
614 | function it_generates_api_routing_based_on_resource_configuration( |
||
670 | |||
671 | function it_generates_routing_with_custom_variables( |
||
761 | |||
762 | function it_supports_sylius_resource_type() |
||
768 | } |
||
769 |