This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * This file is part of the Sonata Project package. |
||
7 | * |
||
8 | * (c) Thomas Rabaix <[email protected]> |
||
9 | * |
||
10 | * For the full copyright and license information, please view the LICENSE |
||
11 | * file that was distributed with this source code. |
||
12 | */ |
||
13 | |||
14 | namespace Sonata\AdminBundle\Tests\Datagrid; |
||
15 | |||
16 | use PHPUnit\Framework\TestCase; |
||
17 | use Sonata\AdminBundle\Admin\FieldDescriptionCollection; |
||
18 | use Sonata\AdminBundle\Admin\FieldDescriptionInterface; |
||
19 | use Sonata\AdminBundle\Datagrid\Datagrid; |
||
20 | use Sonata\AdminBundle\Datagrid\PagerInterface; |
||
21 | use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; |
||
22 | use Sonata\AdminBundle\Filter\FilterInterface; |
||
23 | use Sonata\AdminBundle\Tests\Fixtures\Entity\Form\TestEntity; |
||
24 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
||
25 | use Symfony\Component\Form\Form; |
||
26 | use Symfony\Component\Form\FormBuilder; |
||
27 | use Symfony\Component\Form\FormFactoryInterface; |
||
28 | |||
29 | /** |
||
30 | * @author Andrej Hudec <[email protected]> |
||
31 | */ |
||
32 | class DatagridTest extends TestCase |
||
33 | { |
||
34 | /** |
||
35 | * @var Datagrid |
||
36 | */ |
||
37 | private $datagrid; |
||
38 | |||
39 | /** |
||
40 | * @var PagerInterface |
||
41 | */ |
||
42 | private $pager; |
||
43 | |||
44 | /** |
||
45 | * @var ProxyQueryInterface |
||
46 | */ |
||
47 | private $query; |
||
48 | |||
49 | /** |
||
50 | * @var FieldDescriptionCollection |
||
51 | */ |
||
52 | private $columns; |
||
53 | |||
54 | /** |
||
55 | * @var FormBuilder |
||
56 | */ |
||
57 | private $formBuilder; |
||
58 | |||
59 | /** |
||
60 | * @var array |
||
61 | */ |
||
62 | private $formTypes; |
||
63 | |||
64 | protected function setUp(): void |
||
65 | { |
||
66 | $this->query = $this->createMock(ProxyQueryInterface::class); |
||
67 | $this->columns = new FieldDescriptionCollection(); |
||
68 | $this->pager = $this->createMock(PagerInterface::class); |
||
69 | |||
70 | $this->formTypes = []; |
||
71 | |||
72 | $this->formBuilder = $this->getMockBuilder(FormBuilder::class) |
||
73 | ->disableOriginalConstructor() |
||
74 | ->getMock(); |
||
75 | |||
76 | $this->formBuilder |
||
77 | ->method('get') |
||
78 | ->willReturnCallback(function (string $name): FormBuilder { |
||
79 | if (isset($this->formTypes[$name])) { |
||
80 | return $this->formTypes[$name]; |
||
81 | } |
||
82 | }); |
||
83 | |||
84 | $this->formBuilder |
||
85 | ->method('add') |
||
86 | ->willReturnCallback(function (?string $name, string $type, array $options): void { |
||
87 | $this->formTypes[$name] = new FormBuilder( |
||
88 | $name, |
||
89 | TestEntity::class, |
||
90 | $this->createMock(EventDispatcherInterface::class), |
||
91 | $this->createMock(FormFactoryInterface::class), |
||
92 | $options |
||
93 | ); |
||
94 | }); |
||
95 | |||
96 | $this->formBuilder |
||
97 | ->method('getForm') |
||
98 | ->willReturnCallback(function () { |
||
99 | return $this->getMockBuilder(Form::class) |
||
100 | ->disableOriginalConstructor() |
||
101 | ->getMock(); |
||
102 | }); |
||
103 | |||
104 | $values = []; |
||
105 | |||
106 | $this->datagrid = new Datagrid($this->query, $this->columns, $this->pager, $this->formBuilder, $values); |
||
107 | } |
||
108 | |||
109 | public function testGetPager(): void |
||
110 | { |
||
111 | $this->assertSame($this->pager, $this->datagrid->getPager()); |
||
112 | } |
||
113 | |||
114 | public function testFilter(): void |
||
115 | { |
||
116 | $this->assertFalse($this->datagrid->hasFilter('foo')); |
||
117 | |||
118 | $filter = $this->createMock(FilterInterface::class); |
||
119 | $filter->expects($this->once()) |
||
120 | ->method('getName') |
||
121 | ->willReturn('foo'); |
||
122 | |||
123 | $this->datagrid->addFilter($filter); |
||
124 | |||
125 | $this->assertTrue($this->datagrid->hasFilter('foo')); |
||
126 | $this->assertFalse($this->datagrid->hasFilter('nonexistent')); |
||
127 | $this->assertSame($filter, $this->datagrid->getFilter('foo')); |
||
128 | |||
129 | $this->datagrid->removeFilter('foo'); |
||
130 | |||
131 | $this->assertFalse($this->datagrid->hasFilter('foo')); |
||
132 | |||
133 | $this->expectException(\InvalidArgumentException::class); |
||
134 | $this->expectExceptionMessage('Filter named "foo" doesn\'t exist.'); |
||
135 | |||
136 | $this->datagrid->getFilter('foo'); |
||
137 | } |
||
138 | |||
139 | public function testGetFilters(): void |
||
140 | { |
||
141 | $this->assertSame([], $this->datagrid->getFilters()); |
||
142 | |||
143 | $filter1 = $this->createMock(FilterInterface::class); |
||
144 | $filter1->expects($this->once()) |
||
145 | ->method('getName') |
||
146 | ->willReturn('foo'); |
||
147 | |||
148 | $filter2 = $this->createMock(FilterInterface::class); |
||
149 | $filter2->expects($this->once()) |
||
150 | ->method('getName') |
||
151 | ->willReturn('bar'); |
||
152 | |||
153 | $filter3 = $this->createMock(FilterInterface::class); |
||
154 | $filter3->expects($this->once()) |
||
155 | ->method('getName') |
||
156 | ->willReturn('baz'); |
||
157 | |||
158 | $this->datagrid->addFilter($filter1); |
||
159 | $this->datagrid->addFilter($filter2); |
||
160 | $this->datagrid->addFilter($filter3); |
||
161 | |||
162 | $this->assertSame(['foo' => $filter1, 'bar' => $filter2, 'baz' => $filter3], $this->datagrid->getFilters()); |
||
163 | |||
164 | $this->datagrid->removeFilter('bar'); |
||
165 | |||
166 | $this->assertSame(['foo' => $filter1, 'baz' => $filter3], $this->datagrid->getFilters()); |
||
167 | } |
||
168 | |||
169 | public function testReorderFilters(): void |
||
170 | { |
||
171 | $this->assertSame([], $this->datagrid->getFilters()); |
||
172 | |||
173 | $filter1 = $this->createMock(FilterInterface::class); |
||
174 | $filter1->expects($this->once()) |
||
175 | ->method('getName') |
||
176 | ->willReturn('foo'); |
||
177 | |||
178 | $filter2 = $this->createMock(FilterInterface::class); |
||
179 | $filter2->expects($this->once()) |
||
180 | ->method('getName') |
||
181 | ->willReturn('bar'); |
||
182 | |||
183 | $filter3 = $this->createMock(FilterInterface::class); |
||
184 | $filter3->expects($this->once()) |
||
185 | ->method('getName') |
||
186 | ->willReturn('baz'); |
||
187 | |||
188 | $this->datagrid->addFilter($filter1); |
||
189 | $this->datagrid->addFilter($filter2); |
||
190 | $this->datagrid->addFilter($filter3); |
||
191 | |||
192 | $this->assertSame(['foo' => $filter1, 'bar' => $filter2, 'baz' => $filter3], $this->datagrid->getFilters()); |
||
193 | $this->assertSame(['foo', 'bar', 'baz'], array_keys($this->datagrid->getFilters())); |
||
194 | |||
195 | $this->datagrid->reorderFilters(['bar', 'baz', 'foo']); |
||
196 | |||
197 | $this->assertSame(['bar' => $filter2, 'baz' => $filter3, 'foo' => $filter1], $this->datagrid->getFilters()); |
||
198 | $this->assertSame(['bar', 'baz', 'foo'], array_keys($this->datagrid->getFilters())); |
||
199 | } |
||
200 | |||
201 | public function testGetValues(): void |
||
202 | { |
||
203 | $this->assertSame([], $this->datagrid->getValues()); |
||
204 | |||
205 | $this->datagrid->setValue('foo', 'bar', 'baz'); |
||
206 | |||
207 | $this->assertSame(['foo' => ['type' => 'bar', 'value' => 'baz']], $this->datagrid->getValues()); |
||
208 | } |
||
209 | |||
210 | public function testGetColumns(): void |
||
211 | { |
||
212 | $this->assertSame($this->columns, $this->datagrid->getColumns()); |
||
213 | } |
||
214 | |||
215 | public function testGetQuery(): void |
||
216 | { |
||
217 | $this->assertSame($this->query, $this->datagrid->getQuery()); |
||
218 | } |
||
219 | |||
220 | public function testHasActiveFilters(): void |
||
221 | { |
||
222 | $this->assertFalse($this->datagrid->hasActiveFilters()); |
||
223 | |||
224 | $filter1 = $this->createMock(FilterInterface::class); |
||
225 | $filter1->expects($this->once()) |
||
226 | ->method('getName') |
||
227 | ->willReturn('foo'); |
||
228 | $filter1 |
||
229 | ->method('isActive') |
||
230 | ->willReturn(false); |
||
231 | |||
232 | $this->datagrid->addFilter($filter1); |
||
233 | |||
234 | $this->assertFalse($this->datagrid->hasActiveFilters()); |
||
235 | |||
236 | $filter2 = $this->createMock(FilterInterface::class); |
||
237 | $filter2->expects($this->once()) |
||
238 | ->method('getName') |
||
239 | ->willReturn('bar'); |
||
240 | $filter2 |
||
241 | ->method('isActive') |
||
242 | ->willReturn(true); |
||
243 | |||
244 | $this->datagrid->addFilter($filter2); |
||
245 | |||
246 | $this->assertTrue($this->datagrid->hasActiveFilters()); |
||
247 | } |
||
248 | |||
249 | public function testHasDisplayableFilters(): void |
||
250 | { |
||
251 | $this->assertFalse($this->datagrid->hasDisplayableFilters()); |
||
252 | } |
||
253 | |||
254 | public function testHasDisplayableFiltersNotActive(): void |
||
255 | { |
||
256 | $filter = $this->createMock(FilterInterface::class); |
||
257 | $filter->expects($this->once()) |
||
258 | ->method('getName') |
||
259 | ->willReturn('foo'); |
||
260 | $filter |
||
261 | ->method('getOption') |
||
262 | ->willReturn(false); |
||
263 | $filter |
||
264 | ->method('isActive') |
||
265 | ->willReturn(false); |
||
266 | |||
267 | $this->datagrid->addFilter($filter); |
||
268 | |||
269 | $this->assertFalse($this->datagrid->hasDisplayableFilters()); |
||
270 | } |
||
271 | |||
272 | public function testHasDisplayableFiltersActive(): void |
||
273 | { |
||
274 | $filter = $this->createMock(FilterInterface::class); |
||
275 | $filter->expects($this->once()) |
||
276 | ->method('getName') |
||
277 | ->willReturn('bar'); |
||
278 | $filter |
||
279 | ->method('getOption') |
||
280 | ->willReturn(true); |
||
281 | $filter |
||
282 | ->method('isActive') |
||
283 | ->willReturn(true); |
||
284 | |||
285 | $this->datagrid->addFilter($filter); |
||
286 | |||
287 | $this->assertTrue($this->datagrid->hasDisplayableFilters()); |
||
288 | } |
||
289 | |||
290 | public function testHasDisplayableFiltersAlwaysShow(): void |
||
291 | { |
||
292 | $filter = $this->createMock(FilterInterface::class); |
||
293 | $filter->expects($this->once()) |
||
294 | ->method('getName') |
||
295 | ->willReturn('bar'); |
||
296 | $filter |
||
297 | ->method('getOption') |
||
298 | ->with($this->equalTo('show_filter')) |
||
299 | ->willReturn(true); |
||
300 | $filter |
||
301 | ->method('isActive') |
||
302 | ->willReturn(false); |
||
303 | |||
304 | $this->datagrid->addFilter($filter); |
||
305 | |||
306 | $this->assertTrue($this->datagrid->hasDisplayableFilters()); |
||
307 | } |
||
308 | |||
309 | public function testGetForm(): void |
||
310 | { |
||
311 | $this->assertInstanceOf(Form::class, $this->datagrid->getForm()); |
||
312 | } |
||
313 | |||
314 | public function testGetResults(): void |
||
315 | { |
||
316 | $this->pager->expects($this->once()) |
||
317 | ->method('getResults') |
||
318 | ->willReturn(['foo', 'bar']); |
||
319 | |||
320 | $this->assertSame(['foo', 'bar'], $this->datagrid->getResults()); |
||
321 | } |
||
322 | |||
323 | public function testEmptyResults(): void |
||
324 | { |
||
325 | $this->pager->expects($this->once()) |
||
0 ignored issues
–
show
|
|||
326 | ->method('getResults') |
||
327 | ->willReturn([]); |
||
328 | |||
329 | $this->assertSame([], $this->datagrid->getResults()); |
||
330 | $this->assertSame([], $this->datagrid->getResults()); |
||
331 | } |
||
332 | |||
333 | public function testBuildPager(): void |
||
334 | { |
||
335 | $filter1 = $this->createMock(FilterInterface::class); |
||
336 | $filter1->expects($this->once()) |
||
337 | ->method('getName') |
||
338 | ->willReturn('foo'); |
||
339 | $filter1 |
||
340 | ->method('getFormName') |
||
341 | ->willReturn('fooFormName'); |
||
342 | $filter1 |
||
343 | ->method('isActive') |
||
344 | ->willReturn(false); |
||
345 | $filter1 |
||
346 | ->method('getRenderSettings') |
||
347 | ->willReturn(['foo1', ['bar1' => 'baz1']]); |
||
348 | |||
349 | $this->datagrid->addFilter($filter1); |
||
350 | |||
351 | $filter2 = $this->createMock(FilterInterface::class); |
||
352 | $filter2->expects($this->once()) |
||
353 | ->method('getName') |
||
354 | ->willReturn('bar'); |
||
355 | $filter2 |
||
356 | ->method('getFormName') |
||
357 | ->willReturn('barFormName'); |
||
358 | $filter2 |
||
359 | ->method('isActive') |
||
360 | ->willReturn(true); |
||
361 | $filter2 |
||
362 | ->method('getRenderSettings') |
||
363 | ->willReturn(['foo2', ['bar2' => 'baz2']]); |
||
364 | |||
365 | $this->datagrid->addFilter($filter2); |
||
366 | |||
367 | $this->datagrid->buildPager(); |
||
368 | |||
369 | $this->assertSame(['foo' => null, 'bar' => null], $this->datagrid->getValues()); |
||
370 | $this->assertInstanceOf(FormBuilder::class, $this->formBuilder->get('fooFormName')); |
||
371 | $this->assertSame(['bar1' => 'baz1'], $this->formBuilder->get('fooFormName')->getOptions()); |
||
372 | $this->assertInstanceOf(FormBuilder::class, $this->formBuilder->get('barFormName')); |
||
373 | $this->assertSame(['bar2' => 'baz2'], $this->formBuilder->get('barFormName')->getOptions()); |
||
374 | $this->assertInstanceOf(FormBuilder::class, $this->formBuilder->get('_sort_by')); |
||
375 | $this->assertInstanceOf(FormBuilder::class, $this->formBuilder->get('_sort_order')); |
||
376 | $this->assertInstanceOf(FormBuilder::class, $this->formBuilder->get('_page')); |
||
377 | $this->assertInstanceOf(FormBuilder::class, $this->formBuilder->get('_per_page')); |
||
378 | } |
||
379 | |||
380 | public function testBuildPagerWithException(): void |
||
381 | { |
||
382 | $this->expectException(\Symfony\Component\Form\Exception\UnexpectedTypeException::class); |
||
383 | $this->expectExceptionMessage('Expected argument of type "Sonata\\AdminBundle\\Admin\\FieldDescriptionInterface", "array" given'); |
||
384 | |||
385 | $filter = $this->createMock(FilterInterface::class); |
||
386 | $filter->expects($this->once()) |
||
387 | ->method('getName') |
||
388 | ->willReturn('foo'); |
||
389 | $filter |
||
390 | ->method('isActive') |
||
391 | ->willReturn(false); |
||
392 | $filter |
||
393 | ->method('getRenderSettings') |
||
394 | ->willReturn(['foo', ['bar' => 'baz']]); |
||
395 | |||
396 | $this->datagrid->addFilter($filter); |
||
397 | |||
398 | $this->datagrid->setValue('_sort_by', 'foo', 'baz'); |
||
399 | |||
400 | $this->datagrid->buildPager(); |
||
401 | } |
||
402 | |||
403 | public function testBuildPagerWithSortBy(): void |
||
404 | { |
||
405 | $sortBy = $this->createMock(FieldDescriptionInterface::class); |
||
406 | $sortBy->expects($this->once()) |
||
407 | ->method('isSortable') |
||
408 | ->willReturn(true); |
||
409 | |||
410 | $this->pager->expects($this->once()) |
||
0 ignored issues
–
show
The method
expects() does not seem to exist on object<Sonata\AdminBundl...atagrid\PagerInterface> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
411 | ->method('setMaxPerPage') |
||
412 | ->with($this->equalTo('25')); |
||
413 | |||
414 | $this->pager->expects($this->once()) |
||
0 ignored issues
–
show
The method
expects() does not seem to exist on object<Sonata\AdminBundl...atagrid\PagerInterface> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
415 | ->method('setPage') |
||
416 | ->with($this->equalTo('1')); |
||
417 | |||
418 | $this->datagrid = new Datagrid($this->query, $this->columns, $this->pager, $this->formBuilder, ['_sort_by' => $sortBy]); |
||
419 | |||
420 | $filter = $this->createMock(FilterInterface::class); |
||
421 | $filter->expects($this->once()) |
||
422 | ->method('getName') |
||
423 | ->willReturn('foo'); |
||
424 | $filter |
||
425 | ->method('getFormName') |
||
426 | ->willReturn('fooFormName'); |
||
427 | $filter |
||
428 | ->method('isActive') |
||
429 | ->willReturn(false); |
||
430 | $filter |
||
431 | ->method('getRenderSettings') |
||
432 | ->willReturn(['foo', ['bar' => 'baz']]); |
||
433 | |||
434 | $this->datagrid->addFilter($filter); |
||
435 | |||
436 | $this->datagrid->buildPager(); |
||
437 | |||
438 | $this->assertSame(['_sort_by' => $sortBy, 'foo' => null, '_sort_order' => 'ASC'], $this->datagrid->getValues()); |
||
439 | $this->assertInstanceOf(FormBuilder::class, $this->formBuilder->get('fooFormName')); |
||
440 | $this->assertSame(['bar' => 'baz'], $this->formBuilder->get('fooFormName')->getOptions()); |
||
441 | $this->assertInstanceOf(FormBuilder::class, $this->formBuilder->get('_sort_by')); |
||
442 | $this->assertInstanceOf(FormBuilder::class, $this->formBuilder->get('_sort_order')); |
||
443 | $this->assertInstanceOf(FormBuilder::class, $this->formBuilder->get('_page')); |
||
444 | $this->assertInstanceOf(FormBuilder::class, $this->formBuilder->get('_per_page')); |
||
445 | } |
||
446 | |||
447 | /** |
||
448 | * @dataProvider getBuildPagerWithPageTests |
||
449 | */ |
||
450 | public function testBuildPagerWithPage($page, $perPage): void |
||
451 | { |
||
452 | $sortBy = $this->createMock(FieldDescriptionInterface::class); |
||
453 | $sortBy->expects($this->once()) |
||
454 | ->method('isSortable') |
||
455 | ->willReturn(true); |
||
456 | |||
457 | $this->pager->expects($this->once()) |
||
0 ignored issues
–
show
The method
expects() does not seem to exist on object<Sonata\AdminBundl...atagrid\PagerInterface> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
458 | ->method('setMaxPerPage') |
||
459 | ->with($this->equalTo('50')); |
||
460 | |||
461 | $this->pager->expects($this->once()) |
||
0 ignored issues
–
show
The method
expects() does not seem to exist on object<Sonata\AdminBundl...atagrid\PagerInterface> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
462 | ->method('setPage') |
||
463 | ->with($this->equalTo('3')); |
||
464 | |||
465 | $this->datagrid = new Datagrid($this->query, $this->columns, $this->pager, $this->formBuilder, ['_sort_by' => $sortBy, '_page' => $page, '_per_page' => $perPage]); |
||
466 | |||
467 | $filter = $this->createMock(FilterInterface::class); |
||
468 | $filter->expects($this->once()) |
||
469 | ->method('getName') |
||
470 | ->willReturn('foo'); |
||
471 | $filter |
||
472 | ->method('getFormName') |
||
473 | ->willReturn('fooFormName'); |
||
474 | $filter |
||
475 | ->method('isActive') |
||
476 | ->willReturn(false); |
||
477 | $filter |
||
478 | ->method('getRenderSettings') |
||
479 | ->willReturn(['foo', ['bar' => 'baz']]); |
||
480 | |||
481 | $this->datagrid->addFilter($filter); |
||
482 | |||
483 | $this->datagrid->buildPager(); |
||
484 | |||
485 | $this->assertSame([ |
||
486 | '_sort_by' => $sortBy, |
||
487 | '_page' => $page, |
||
488 | '_per_page' => $perPage, |
||
489 | 'foo' => null, |
||
490 | '_sort_order' => 'ASC', |
||
491 | ], $this->datagrid->getValues()); |
||
492 | $this->assertInstanceOf(FormBuilder::class, $this->formBuilder->get('fooFormName')); |
||
493 | $this->assertSame(['bar' => 'baz'], $this->formBuilder->get('fooFormName')->getOptions()); |
||
494 | $this->assertInstanceOf(FormBuilder::class, $this->formBuilder->get('_sort_by')); |
||
495 | $this->assertInstanceOf(FormBuilder::class, $this->formBuilder->get('_sort_order')); |
||
496 | $this->assertInstanceOf(FormBuilder::class, $this->formBuilder->get('_page')); |
||
497 | $this->assertInstanceOf(FormBuilder::class, $this->formBuilder->get('_per_page')); |
||
498 | } |
||
499 | |||
500 | public function getBuildPagerWithPageTests(): array |
||
501 | { |
||
502 | // tests for php 5.3, because isset functionality was changed since php 5.4 |
||
503 | return [ |
||
504 | [3, 50], |
||
505 | ['3', '50'], |
||
506 | [3, '50'], |
||
507 | ['3', 50], |
||
508 | [3, ['type' => null, 'value' => 50]], |
||
509 | [3, ['type' => null, 'value' => '50']], |
||
510 | ]; |
||
511 | } |
||
512 | |||
513 | /** |
||
514 | * @dataProvider getBuildPagerWithPage2Tests |
||
515 | */ |
||
516 | public function testBuildPagerWithPage2($page, $perPage): void |
||
517 | { |
||
518 | $this->pager->expects($this->once()) |
||
0 ignored issues
–
show
The method
expects() does not seem to exist on object<Sonata\AdminBundl...atagrid\PagerInterface> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
519 | ->method('setMaxPerPage') |
||
520 | ->with($this->equalTo('50')); |
||
521 | |||
522 | $this->pager->expects($this->once()) |
||
0 ignored issues
–
show
The method
expects() does not seem to exist on object<Sonata\AdminBundl...atagrid\PagerInterface> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
523 | ->method('setPage') |
||
524 | ->with($this->equalTo('3')); |
||
525 | |||
526 | $this->datagrid = new Datagrid($this->query, $this->columns, $this->pager, $this->formBuilder, []); |
||
527 | $this->datagrid->setValue('_per_page', null, $perPage); |
||
528 | $this->datagrid->setValue('_page', null, $page); |
||
529 | |||
530 | $this->datagrid->buildPager(); |
||
531 | |||
532 | $this->assertSame([ |
||
533 | '_per_page' => ['type' => null, 'value' => $perPage], |
||
534 | '_page' => ['type' => null, 'value' => $page], |
||
535 | ], $this->datagrid->getValues()); |
||
536 | $this->assertInstanceOf(FormBuilder::class, $this->formBuilder->get('_sort_by')); |
||
537 | $this->assertInstanceOf(FormBuilder::class, $this->formBuilder->get('_sort_order')); |
||
538 | $this->assertInstanceOf(FormBuilder::class, $this->formBuilder->get('_page')); |
||
539 | $this->assertInstanceOf(FormBuilder::class, $this->formBuilder->get('_per_page')); |
||
540 | } |
||
541 | |||
542 | public function getBuildPagerWithPage2Tests(): array |
||
543 | { |
||
544 | // tests for php 5.3, because isset functionality was changed since php 5.4 |
||
545 | return [ |
||
546 | [3, 50], |
||
547 | ['3', '50'], |
||
548 | [3, '50'], |
||
549 | ['3', 50], |
||
550 | ]; |
||
551 | } |
||
552 | |||
553 | public function testSortParameters(): void |
||
554 | { |
||
555 | $field1 = $this->createMock(FieldDescriptionInterface::class); |
||
556 | $field1->method('getName')->willReturn('field1'); |
||
557 | |||
558 | $field2 = $this->createMock(FieldDescriptionInterface::class); |
||
559 | $field2->method('getName')->willReturn('field2'); |
||
560 | |||
561 | $field3 = $this->createMock(FieldDescriptionInterface::class); |
||
562 | $field3->method('getName')->willReturn('field3'); |
||
563 | $field3->method('getOption')->with('sortable')->willReturn('field3sortBy'); |
||
564 | |||
565 | $this->datagrid = new Datagrid( |
||
566 | $this->query, |
||
567 | $this->columns, |
||
568 | $this->pager, |
||
569 | $this->formBuilder, |
||
570 | ['_sort_by' => $field1, '_sort_order' => 'ASC'] |
||
571 | ); |
||
572 | |||
573 | $parameters = $this->datagrid->getSortParameters($field1); |
||
574 | |||
575 | $this->assertSame('DESC', $parameters['filter']['_sort_order']); |
||
576 | $this->assertSame('field1', $parameters['filter']['_sort_by']); |
||
577 | |||
578 | $parameters = $this->datagrid->getSortParameters($field2); |
||
579 | |||
580 | $this->assertSame('ASC', $parameters['filter']['_sort_order']); |
||
581 | $this->assertSame('field2', $parameters['filter']['_sort_by']); |
||
582 | |||
583 | $parameters = $this->datagrid->getSortParameters($field3); |
||
584 | |||
585 | $this->assertSame('ASC', $parameters['filter']['_sort_order']); |
||
586 | $this->assertSame('field3sortBy', $parameters['filter']['_sort_by']); |
||
587 | |||
588 | $this->datagrid = new Datagrid( |
||
589 | $this->query, |
||
590 | $this->columns, |
||
591 | $this->pager, |
||
592 | $this->formBuilder, |
||
593 | ['_sort_by' => $field3, '_sort_order' => 'ASC'] |
||
594 | ); |
||
595 | |||
596 | $parameters = $this->datagrid->getSortParameters($field3); |
||
597 | |||
598 | $this->assertSame('DESC', $parameters['filter']['_sort_order']); |
||
599 | $this->assertSame('field3sortBy', $parameters['filter']['_sort_by']); |
||
600 | } |
||
601 | |||
602 | public function testGetPaginationParameters(): void |
||
603 | { |
||
604 | $field = $this->createMock(FieldDescriptionInterface::class); |
||
605 | |||
606 | $this->datagrid = new Datagrid( |
||
607 | $this->query, |
||
608 | $this->columns, |
||
609 | $this->pager, |
||
610 | $this->formBuilder, |
||
611 | ['_sort_by' => $field, '_sort_order' => 'ASC'] |
||
612 | ); |
||
613 | |||
614 | $field->expects($this->once())->method('getName')->willReturn($name = 'test'); |
||
615 | |||
616 | $result = $this->datagrid->getPaginationParameters($page = 5); |
||
617 | |||
618 | $this->assertSame($page, $result['filter']['_page']); |
||
619 | $this->assertSame($name, $result['filter']['_sort_by']); |
||
620 | } |
||
621 | } |
||
622 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.