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\Controller; |
13
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
15
|
|
|
use Prophecy\Argument; |
16
|
|
|
use Sylius\Bundle\ResourceBundle\Controller\Parameters; |
17
|
|
|
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; |
18
|
|
|
use Sylius\Component\Resource\Metadata\MetadataInterface; |
19
|
|
|
use Symfony\Component\HttpFoundation\ParameterBag; |
20
|
|
|
use Symfony\Component\HttpFoundation\Request; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
24
|
|
|
* @author Arnaud Langade <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
final class RequestConfigurationSpec extends ObjectBehavior |
27
|
|
|
{ |
28
|
|
|
function let(MetadataInterface $metadata, Request $request, Parameters $parameters) |
29
|
|
|
{ |
30
|
|
|
$this->beConstructedWith($metadata, $request, $parameters); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function it_is_initializable() |
34
|
|
|
{ |
35
|
|
|
$this->shouldHaveType(RequestConfiguration::class); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
function it_has_request(Request $request) |
39
|
|
|
{ |
40
|
|
|
$this->getRequest()->shouldReturn($request); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
function it_has_metadata(MetadataInterface $metadata) |
44
|
|
|
{ |
45
|
|
|
$this->getMetadata()->shouldReturn($metadata); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
function it_has_parameters(Parameters $parameters) |
49
|
|
|
{ |
50
|
|
|
$this->getParameters()->shouldReturn($parameters); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
function it_checks_if_its_a_html_request(Request $request) |
54
|
|
|
{ |
55
|
|
|
$request->getRequestFormat()->willReturn('html'); |
56
|
|
|
$this->isHtmlRequest()->shouldReturn(true); |
57
|
|
|
|
58
|
|
|
$request->getRequestFormat()->willReturn('json'); |
59
|
|
|
$this->isHtmlRequest()->shouldReturn(false); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
function it_returns_default_template_names(MetadataInterface $metadata) |
63
|
|
|
{ |
64
|
|
|
$metadata->getTemplatesNamespace()->willReturn('SyliusAdminBundle:Product'); |
65
|
|
|
|
66
|
|
|
$this->getDefaultTemplate('index.html')->shouldReturn('SyliusAdminBundle:Product:index.html.twig'); |
67
|
|
|
$this->getDefaultTemplate('show.html')->shouldReturn('SyliusAdminBundle:Product:show.html.twig'); |
68
|
|
|
$this->getDefaultTemplate('create.html')->shouldReturn('SyliusAdminBundle:Product:create.html.twig'); |
69
|
|
|
$this->getDefaultTemplate('update.html')->shouldReturn('SyliusAdminBundle:Product:update.html.twig'); |
70
|
|
|
$this->getDefaultTemplate('custom.html')->shouldReturn('SyliusAdminBundle:Product:custom.html.twig'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
function it_returns_default_template_names_for_a_directory_based_templates(MetadataInterface $metadata) |
74
|
|
|
{ |
75
|
|
|
$metadata->getTemplatesNamespace()->willReturn('book/Backend'); |
76
|
|
|
|
77
|
|
|
$this->getDefaultTemplate('index.html')->shouldReturn('book/Backend/index.html.twig'); |
78
|
|
|
$this->getDefaultTemplate('show.html')->shouldReturn('book/Backend/show.html.twig'); |
79
|
|
|
$this->getDefaultTemplate('create.html')->shouldReturn('book/Backend/create.html.twig'); |
80
|
|
|
$this->getDefaultTemplate('update.html')->shouldReturn('book/Backend/update.html.twig'); |
81
|
|
|
$this->getDefaultTemplate('custom.html')->shouldReturn('book/Backend/custom.html.twig'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
function it_takes_the_custom_template_if_specified(MetadataInterface $metadata, Parameters $parameters) |
85
|
|
|
{ |
86
|
|
|
$metadata->getTemplatesNamespace()->willReturn('SyliusAdminBundle:Product'); |
87
|
|
|
$parameters->get('template', 'SyliusAdminBundle:Product:foo.html.twig')->willReturn('AppBundle:Product:show.html.twig'); |
88
|
|
|
|
89
|
|
|
$this->getTemplate('foo.html')->shouldReturn('AppBundle:Product:show.html.twig'); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
function it_gets_form_type_and_its_options(MetadataInterface $metadata, Parameters $parameters) |
93
|
|
|
{ |
94
|
|
|
$parameters->get('form')->willReturn(['type' => 'sylius_custom_resource']); |
95
|
|
|
$this->getFormType()->shouldReturn('sylius_custom_resource'); |
96
|
|
|
$this->getFormOptions()->shouldReturn([]); |
97
|
|
|
|
98
|
|
|
$parameters->get('form')->willReturn('sylius_custom_resource'); |
99
|
|
|
$this->getFormType()->shouldReturn('sylius_custom_resource'); |
100
|
|
|
$this->getFormOptions()->shouldReturn([]); |
101
|
|
|
|
102
|
|
|
$parameters->get('form')->willReturn(['type' => 'sylius_custom_resource', 'options' => ['key' => 'value']]); |
103
|
|
|
$this->getFormType()->shouldReturn('sylius_custom_resource'); |
104
|
|
|
$this->getFormOptions()->shouldReturn(['key' => 'value']); |
105
|
|
|
|
106
|
|
|
$metadata->getClass('form')->willReturn('\Fully\Qualified\ClassName'); |
107
|
|
|
$parameters->get('form')->willReturn([]); |
108
|
|
|
$this->getFormType()->shouldReturn('\Fully\Qualified\ClassName'); |
109
|
|
|
$this->getFormOptions()->shouldReturn([]); |
110
|
|
|
|
111
|
|
|
$metadata->getClass('form')->willReturn('\Fully\Qualified\ClassName'); |
112
|
|
|
$parameters->get('form')->willReturn(['options' => ['key' => 'value']]); |
113
|
|
|
$this->getFormType()->shouldReturn('\Fully\Qualified\ClassName'); |
114
|
|
|
$this->getFormOptions()->shouldReturn(['key' => 'value']); |
115
|
|
|
|
116
|
|
|
$metadata->getClass('form')->willReturn(['default' => 'sylius_custom_resource', 'choice' => 'sylius_resource_choice']); |
117
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
118
|
|
|
$metadata->getName()->willReturn('resource'); |
119
|
|
|
$parameters->get('form')->willReturn(['options' => ['key' => 'value']]); |
120
|
|
|
$this->getFormType()->shouldReturn('sylius_resource'); |
121
|
|
|
$this->getFormOptions()->shouldReturn(['key' => 'value']); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
function it_generates_form_type_with_array_configuration(MetadataInterface $metadata, Parameters $parameters) |
125
|
|
|
{ |
126
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
127
|
|
|
$metadata->getName()->willReturn('product'); |
128
|
|
|
|
129
|
|
|
$parameters->get('form')->willReturn(['type'=> 'sylius_product', 'options' => ['validation_groups' => ['sylius']]]); |
130
|
|
|
$this->getFormType()->shouldReturn('sylius_product'); |
131
|
|
|
$this->getFormOptions()->shouldReturn(['validation_groups' => ['sylius']]); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
function it_generates_route_names(MetadataInterface $metadata, Parameters $parameters) |
135
|
|
|
{ |
136
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
137
|
|
|
$metadata->getName()->willReturn('product'); |
138
|
|
|
$parameters->get('section')->willReturn(null); |
139
|
|
|
|
140
|
|
|
$this->getRouteName('index')->shouldReturn('sylius_product_index'); |
141
|
|
|
$this->getRouteName('show')->shouldReturn('sylius_product_show'); |
142
|
|
|
$this->getRouteName('custom')->shouldReturn('sylius_product_custom'); |
143
|
|
|
|
144
|
|
|
$parameters->get('section')->willReturn('admin'); |
145
|
|
|
$this->getRouteName('index')->shouldReturn('sylius_admin_product_index'); |
146
|
|
|
$this->getRouteName('show')->shouldReturn('sylius_admin_product_show'); |
147
|
|
|
$this->getRouteName('custom')->shouldReturn('sylius_admin_product_custom'); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
function it_generates_redirect_referer(Parameters $parameters, Request $request, ParameterBag $bag) |
151
|
|
|
{ |
152
|
|
|
$request->headers = $bag; |
|
|
|
|
153
|
|
|
$bag->get('referer')->willReturn('http://myurl.com'); |
154
|
|
|
|
155
|
|
|
$parameters->get('redirect')->willReturn(['referer' => 'http://myurl.com']); |
156
|
|
|
|
157
|
|
|
$this->getRedirectReferer()->shouldReturn('http://myurl.com'); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
function it_generates_redirect_route(MetadataInterface $metadata, Parameters $parameters) |
161
|
|
|
{ |
162
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
163
|
|
|
$metadata->getName()->willReturn('product'); |
164
|
|
|
$parameters->get('section')->willReturn(null); |
165
|
|
|
|
166
|
|
|
$parameters->get('redirect')->willReturn(null); |
167
|
|
|
$this->getRedirectRoute('index')->shouldReturn('sylius_product_index'); |
168
|
|
|
|
169
|
|
|
$parameters->get('redirect')->willReturn(['route' => 'myRoute']); |
170
|
|
|
$this->getRedirectRoute('show')->shouldReturn('myRoute'); |
171
|
|
|
|
172
|
|
|
$parameters->get('redirect')->willReturn('myRoute'); |
173
|
|
|
$this->getRedirectRoute('custom')->shouldReturn('myRoute'); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
function it_takes_section_into_account_when_generating_redirect_route(MetadataInterface $metadata, Parameters $parameters) |
177
|
|
|
{ |
178
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
179
|
|
|
$metadata->getName()->willReturn('product'); |
180
|
|
|
$parameters->get('section')->willReturn('admin'); |
181
|
|
|
|
182
|
|
|
$parameters->get('redirect')->willReturn(null); |
183
|
|
|
$this->getRedirectRoute('index')->shouldReturn('sylius_admin_product_index'); |
184
|
|
|
|
185
|
|
|
$parameters->get('redirect')->willReturn(['route' => 'myRoute']); |
186
|
|
|
$this->getRedirectRoute('show')->shouldReturn('myRoute'); |
187
|
|
|
|
188
|
|
|
$parameters->get('redirect')->willReturn('myRoute'); |
189
|
|
|
$this->getRedirectRoute('custom')->shouldReturn('myRoute'); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
function it_returns_array_as_redirect_parameters(Parameters $parameters) |
193
|
|
|
{ |
194
|
|
|
$parameters->get('redirect')->willReturn(null); |
195
|
|
|
$this->getRedirectParameters()->shouldReturn([]); |
196
|
|
|
|
197
|
|
|
$parameters->get('redirect')->willReturn('string'); |
198
|
|
|
$this->getRedirectParameters()->shouldReturn([]); |
199
|
|
|
|
200
|
|
|
$parameters->get('redirect')->willReturn(['parameters' => []]); |
201
|
|
|
$this->getRedirectParameters()->shouldReturn([]); |
202
|
|
|
|
203
|
|
|
$parameters->get('redirect')->willReturn(['parameters' => ['myParameter']]); |
204
|
|
|
$this->getRedirectParameters()->shouldReturn(['myParameter']); |
205
|
|
|
|
206
|
|
|
$parameters->get('redirect')->willReturn(['parameters' => ['myParameter']]); |
207
|
|
|
|
208
|
|
|
$this->getRedirectParameters('resource')->shouldReturn(['myParameter']); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
function it_checks_if_limit_is_enabled(Parameters $parameters) |
212
|
|
|
{ |
213
|
|
|
$parameters->get('limit', Argument::any())->willReturn(10); |
214
|
|
|
$this->isLimited()->shouldReturn(true); |
215
|
|
|
|
216
|
|
|
$parameters->get('limit', Argument::any())->willReturn(null); |
217
|
|
|
$this->isLimited()->shouldReturn(false); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
function it_gets_limit(Parameters $parameters) |
221
|
|
|
{ |
222
|
|
|
$parameters->get('limit', false)->willReturn(true); |
223
|
|
|
$parameters->get('limit', 10)->willReturn(10); |
224
|
|
|
$this->getLimit()->shouldReturn(10); |
225
|
|
|
|
226
|
|
|
$parameters->get('limit', false)->willReturn(false); |
227
|
|
|
$parameters->get('limit', 10)->willReturn(null); |
228
|
|
|
$this->getLimit()->shouldReturn(null); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
function it_checks_if_pagination_is_enabled(Parameters $parameters) |
232
|
|
|
{ |
233
|
|
|
$parameters->get('paginate', Argument::any())->willReturn(10); |
234
|
|
|
$this->isPaginated()->shouldReturn(true); |
235
|
|
|
|
236
|
|
|
$parameters->get('paginate', Argument::any())->willReturn(null); |
237
|
|
|
$this->isPaginated()->shouldReturn(false); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
function it_gets_pagination_max_per_page(Parameters $parameters) |
241
|
|
|
{ |
242
|
|
|
$parameters->get('paginate', 10)->willReturn(20); |
243
|
|
|
$this->getPaginationMaxPerPage()->shouldReturn(20); |
244
|
|
|
|
245
|
|
|
$parameters->get('paginate', 10)->willReturn(10); |
246
|
|
|
$this->getPaginationMaxPerPage()->shouldReturn(10); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
function it_checks_if_the_resource_is_filterable(Parameters $parameters) |
250
|
|
|
{ |
251
|
|
|
$parameters->get('filterable', Argument::any())->willReturn(true); |
252
|
|
|
$this->isFilterable()->shouldReturn(true); |
253
|
|
|
|
254
|
|
|
$parameters->get('filterable', Argument::any())->willReturn(null); |
255
|
|
|
$this->isFilterable()->shouldReturn(false); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
function it_has_no_filterable_parameter(Parameters $parameters) |
259
|
|
|
{ |
260
|
|
|
$defaultCriteria = ['property' => 'myValue']; |
261
|
|
|
|
262
|
|
|
$parameters->get('criteria', Argument::any())->willReturn([]); |
263
|
|
|
$parameters->get('filterable', false)->willReturn(false); |
264
|
|
|
|
265
|
|
|
$this->getCriteria($defaultCriteria)->shouldBeArray(); |
266
|
|
|
$this->getCriteria($defaultCriteria)->shouldHaveCount(1); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
function it_has_criteria_parameter(Parameters $parameters, Request $request) |
270
|
|
|
{ |
271
|
|
|
$criteria = ['property' => 'myNewValue']; |
272
|
|
|
|
273
|
|
|
$parameters->get('filterable', false)->willReturn(true); |
274
|
|
|
$parameters->get('criteria', Argument::any())->willReturn([]); |
275
|
|
|
$request->get('criteria', [])->willReturn($criteria); |
276
|
|
|
$this->getCriteria()->shouldReturn($criteria); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
function it_allows_to_override_criteria_parameter_in_route(Parameters $parameters, Request $request) |
280
|
|
|
{ |
281
|
|
|
$criteria = ['property' => 'myValue']; |
282
|
|
|
$overriddenCriteria = ['other_property' => 'myNewValue']; |
283
|
|
|
$combinedCriteria = ['property' => 'myValue', 'other_property' => 'myNewValue']; |
284
|
|
|
|
285
|
|
|
$parameters->get('filterable', false)->willReturn(true); |
286
|
|
|
$parameters->get('criteria', [])->willReturn($criteria); |
287
|
|
|
$request->get('criteria', [])->willReturn($overriddenCriteria); |
288
|
|
|
|
289
|
|
|
$this->getCriteria()->shouldReturn($combinedCriteria); |
290
|
|
|
|
291
|
|
|
$defaultCriteria = ['slug' => 'foo']; |
292
|
|
|
$combinedDefaultCriteria = ['property' => 'myValue', 'slug' => 'foo', 'other_property' => 'myNewValue']; |
|
|
|
|
293
|
|
|
|
294
|
|
|
$parameters->get('filterable', false)->willReturn(true); |
295
|
|
|
$parameters->get('criteria', Argument::any())->willReturn($criteria); |
296
|
|
|
$request->get('criteria', [])->willReturn($overriddenCriteria); |
297
|
|
|
|
298
|
|
|
$this->getCriteria($defaultCriteria)->shouldReturn($combinedDefaultCriteria); |
299
|
|
|
|
300
|
|
|
$parameters->get('filterable', false)->willReturn(true); |
301
|
|
|
$parameters->get('criteria', [])->willReturn(['filter' => 'route']); |
302
|
|
|
$request->get('criteria', [])->willReturn(['filter' => 'request']); |
303
|
|
|
|
304
|
|
|
$this->getCriteria(['filter' => 'default'])->shouldReturn(['filter' => 'request']); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
function it_checks_if_the_resource_is_sortable(Parameters $parameters) |
308
|
|
|
{ |
309
|
|
|
$parameters->get('sortable', Argument::any())->willReturn(true); |
310
|
|
|
$this->isSortable()->shouldReturn(true); |
311
|
|
|
|
312
|
|
|
$parameters->get('sortable', Argument::any())->willReturn(null); |
313
|
|
|
$this->isSortable()->shouldReturn(false); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
function it_has_sorting_parameter(Parameters $parameters, Request $request) |
317
|
|
|
{ |
318
|
|
|
$sorting = ['property' => 'asc']; |
319
|
|
|
|
320
|
|
|
$parameters->get('sortable', false)->willReturn(true); |
321
|
|
|
$parameters->get('sorting', Argument::any())->willReturn($sorting); |
322
|
|
|
$request->get('sorting', [])->willReturn($sorting); |
323
|
|
|
|
324
|
|
|
$this->getSorting()->shouldReturn($sorting); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
function it_has_no_sortable_parameter(Parameters $parameters) |
328
|
|
|
{ |
329
|
|
|
$defaultSorting = ['property' => 'desc']; |
330
|
|
|
|
331
|
|
|
$parameters->get('sorting', Argument::any())->willReturn([]); |
332
|
|
|
$parameters->get('sortable', false)->willReturn(false); |
333
|
|
|
|
334
|
|
|
$this->getSorting($defaultSorting)->shouldBeArray(); |
335
|
|
|
$this->getSorting($defaultSorting)->shouldHaveCount(1); |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
function it_allows_to_override_sorting_parameter_in_route(Parameters $parameters, Request $request) |
339
|
|
|
{ |
340
|
|
|
$sorting = ['property' => 'desc']; |
341
|
|
|
$overriddenSorting = ['other_property' => 'asc']; |
342
|
|
|
$combinedSorting = ['other_property' => 'asc', 'property' => 'desc']; |
343
|
|
|
|
344
|
|
|
$parameters->get('sortable', false)->willReturn(true); |
345
|
|
|
$parameters->get('sorting', [])->willReturn($sorting); |
346
|
|
|
$request->get('sorting', [])->willReturn($overriddenSorting); |
347
|
|
|
|
348
|
|
|
$this->getSorting()->shouldReturn($combinedSorting); |
349
|
|
|
|
350
|
|
|
$defaultSorting = ['foo' => 'bar']; |
351
|
|
|
$combinedDefaultSorting = ['other_property' => 'asc', 'property' => 'desc', 'foo' => 'bar']; |
|
|
|
|
352
|
|
|
|
353
|
|
|
$parameters->get('sortable', false)->willReturn(true); |
354
|
|
|
$parameters->get('sorting', Argument::any())->willReturn($sorting); |
355
|
|
|
$request->get('sorting', [])->willReturn($overriddenSorting); |
356
|
|
|
|
357
|
|
|
$this->getSorting($defaultSorting)->shouldReturn($combinedDefaultSorting); |
358
|
|
|
|
359
|
|
|
$parameters->get('sortable', false)->willReturn(true); |
360
|
|
|
$parameters->get('sorting', [])->willReturn(['sort' => 'route']); |
361
|
|
|
$request->get('sorting', [])->willReturn(['sort' => 'request']); |
362
|
|
|
|
363
|
|
|
$this->getSorting(['sort' => 'default'])->shouldReturn(['sort' => 'request']); |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
function it_has_repository_method_parameter(Parameters $parameters) |
367
|
|
|
{ |
368
|
|
|
$parameters->has('repository')->willReturn(false); |
369
|
|
|
$this->getRepositoryMethod()->shouldReturn(null); |
370
|
|
|
|
371
|
|
|
$parameters->has('repository')->willReturn(true); |
372
|
|
|
$parameters->get('repository')->willReturn(['method' => 'findAllEnabled']); |
373
|
|
|
|
374
|
|
|
$this->getRepositoryMethod()->shouldReturn('findAllEnabled'); |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
function it_has_repository_arguments_parameter(Parameters $parameters) |
378
|
|
|
{ |
379
|
|
|
$parameters->has('repository')->willReturn(false); |
380
|
|
|
$this->getRepositoryArguments()->shouldReturn([]); |
381
|
|
|
|
382
|
|
|
$repositoryConfiguration = ['arguments' => 'value']; |
|
|
|
|
383
|
|
|
$parameters->has('repository')->willReturn(true); |
384
|
|
|
$parameters->get('repository')->willReturn($repositoryConfiguration); |
385
|
|
|
|
386
|
|
|
$this->getRepositoryArguments()->shouldReturn(['value']); |
387
|
|
|
|
388
|
|
|
$repositoryConfiguration = ['arguments' => ['foo, bar']]; |
389
|
|
|
$parameters->has('repository')->willReturn(true); |
390
|
|
|
$parameters->get('repository')->willReturn($repositoryConfiguration); |
391
|
|
|
|
392
|
|
|
$this->getRepositoryArguments()->shouldReturn(['foo, bar']); |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
function it_has_factory_method_parameter(Parameters $parameters) |
396
|
|
|
{ |
397
|
|
|
$parameters->has('factory')->willReturn(false); |
398
|
|
|
$this->getFactoryMethod()->shouldReturn(null); |
399
|
|
|
|
400
|
|
|
$parameters->has('factory')->willReturn(true); |
401
|
|
|
$parameters->get('factory')->willReturn(['method' => 'createForPromotion']); |
402
|
|
|
|
403
|
|
|
$this->getFactoryMethod()->shouldReturn('createForPromotion'); |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
function it_has_factory_arguments_parameter(Parameters $parameters) |
407
|
|
|
{ |
408
|
|
|
$parameters->has('factory')->willReturn(false); |
409
|
|
|
$this->getFactoryArguments()->shouldReturn([]); |
410
|
|
|
|
411
|
|
|
$factoryConfiguration = ['arguments' => 'value']; |
412
|
|
|
$parameters->has('factory')->willReturn(true); |
413
|
|
|
$parameters->get('factory')->willReturn($factoryConfiguration); |
414
|
|
|
|
415
|
|
|
$this->getFactoryArguments()->shouldReturn(['value']); |
416
|
|
|
|
417
|
|
|
$factoryConfiguration = ['arguments' => ['foo, bar']]; |
418
|
|
|
$parameters->has('factory')->willReturn(true); |
419
|
|
|
$parameters->get('factory')->willReturn($factoryConfiguration); |
420
|
|
|
|
421
|
|
|
$this->getFactoryArguments()->shouldReturn(['foo, bar']); |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
function it_has_flash_message_parameter(MetadataInterface $metadata, Parameters $parameters) |
425
|
|
|
{ |
426
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
427
|
|
|
$metadata->getName()->willReturn('product'); |
428
|
|
|
|
429
|
|
|
$parameters->get('flash', 'sylius.product.message')->willReturn('sylius.product.message'); |
430
|
|
|
$this->getFlashMessage('message')->shouldReturn('sylius.product.message'); |
431
|
|
|
|
432
|
|
|
$parameters->get('flash', 'sylius.product.flash')->willReturn('sylius.product.myMessage'); |
433
|
|
|
$this->getFlashMessage('flash')->shouldReturn('sylius.product.myMessage'); |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
function it_has_sortable_position_parameter(Parameters $parameters) |
437
|
|
|
{ |
438
|
|
|
$parameters->get('sortable_position', 'position')->willReturn('position'); |
439
|
|
|
$this->getSortablePosition()->shouldReturn('position'); |
440
|
|
|
|
441
|
|
|
$parameters->get('sortable_position', 'position')->willReturn('myPosition'); |
442
|
|
|
$this->getSortablePosition()->shouldReturn('myPosition'); |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
function it_has_permission_unless_defined_as_false_in_parameters(Parameters $parameters) |
446
|
|
|
{ |
447
|
|
|
$parameters->get('permission', false)->willReturn(false); |
448
|
|
|
$this->shouldNotHavePermission(); |
449
|
|
|
|
450
|
|
|
$parameters->get('permission', false)->willReturn('custom_permission'); |
451
|
|
|
$this->shouldHavePermission(); |
452
|
|
|
|
453
|
|
|
$parameters->get('permission', false)->willReturn(false); |
454
|
|
|
$this->shouldNotHavePermission(); |
455
|
|
|
} |
456
|
|
|
|
457
|
|
|
function it_generates_permission_name(MetadataInterface $metadata, Parameters $parameters) |
458
|
|
|
{ |
459
|
|
|
$metadata->getApplicationName()->willReturn('sylius'); |
460
|
|
|
$metadata->getName()->willReturn('product'); |
461
|
|
|
|
462
|
|
|
$parameters->get('permission')->willReturn(true); |
463
|
|
|
|
464
|
|
|
$this->getPermission('index')->shouldReturn('sylius.product.index'); |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
function it_takes_permission_name_from_parameters_if_provided(Parameters $parameters) |
468
|
|
|
{ |
469
|
|
|
$parameters->get('permission')->willReturn('app.sales_order.view_pricing'); |
470
|
|
|
|
471
|
|
|
$this->getPermission('index')->shouldReturn('app.sales_order.view_pricing'); |
472
|
|
|
} |
473
|
|
|
|
474
|
|
|
function it_throws_an_exception_when_permission_is_set_as_false_in_parameters_but_still_trying_to_get_it(Parameters $parameters) |
475
|
|
|
{ |
476
|
|
|
$parameters->get('permission')->willReturn(null); |
477
|
|
|
|
478
|
|
|
$this |
479
|
|
|
->shouldThrow(\LogicException::class) |
480
|
|
|
->during('getPermission', ['index']) |
481
|
|
|
; |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
function it_has_event_name(Parameters $parameters) |
485
|
|
|
{ |
486
|
|
|
$parameters->get('event')->willReturn('foo'); |
487
|
|
|
$this->getEvent()->shouldReturn('foo'); |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
function it_has_section(Parameters $parameters) |
491
|
|
|
{ |
492
|
|
|
$parameters->get('section')->willReturn(null); |
493
|
|
|
$this->getSection()->shouldReturn(null); |
494
|
|
|
|
495
|
|
|
$parameters->get('section')->willReturn('admin'); |
496
|
|
|
$this->getSection()->shouldReturn('admin'); |
497
|
|
|
} |
498
|
|
|
|
499
|
|
|
function it_has_vars(Parameters $parameters) |
500
|
|
|
{ |
501
|
|
|
$parameters->get('vars', [])->willReturn(['foo' => 'bar']); |
502
|
|
|
$this->getVars()->shouldReturn(['foo' => 'bar']); |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
function it_does_not_have_grid_unless_defined_as_in_parameters(Parameters $parameters) |
506
|
|
|
{ |
507
|
|
|
$parameters->has('grid')->willReturn(false); |
508
|
|
|
$this->shouldNotHaveGrid(); |
509
|
|
|
|
510
|
|
|
$parameters->has('grid')->willReturn(true); |
511
|
|
|
$this->shouldHaveGrid(); |
512
|
|
|
|
513
|
|
|
$parameters->has('grid')->willReturn(true); |
514
|
|
|
$parameters->get('grid')->willReturn('sylius_admin_tax_category'); |
515
|
|
|
|
516
|
|
|
$this->getGrid()->shouldReturn('sylius_admin_tax_category'); |
517
|
|
|
} |
518
|
|
|
|
519
|
|
|
function it_throws_an_exception_when_trying_to_retrieve_undefined_grid(Parameters $parameters) |
520
|
|
|
{ |
521
|
|
|
$parameters->has('grid')->willReturn(false); |
522
|
|
|
|
523
|
|
|
$this |
524
|
|
|
->shouldThrow(\LogicException::class) |
525
|
|
|
->during('getGrid') |
526
|
|
|
; |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
function it_can_have_state_machine_transition(Parameters $parameters) |
530
|
|
|
{ |
531
|
|
|
$parameters->has('state_machine')->willReturn(false); |
532
|
|
|
$this->hasStateMachine()->shouldReturn(false); |
533
|
|
|
|
534
|
|
|
$parameters->has('state_machine')->willReturn(true); |
535
|
|
|
$parameters->get('state_machine')->willReturn([ |
536
|
|
|
'graph' => 'sylius_product_review_state', |
537
|
|
|
'transition' => 'approve', |
538
|
|
|
]); |
539
|
|
|
|
540
|
|
|
$this->hasStateMachine()->shouldReturn(true); |
541
|
|
|
$this->getStateMachineGraph()->shouldReturn('sylius_product_review_state'); |
542
|
|
|
$this->getStateMachineTransition()->shouldReturn('approve'); |
543
|
|
|
} |
544
|
|
|
} |
545
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..