Total Complexity | 48 |
Total Lines | 2445 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like AdminTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AdminTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
79 | class AdminTest extends TestCase |
||
80 | { |
||
81 | protected $cacheTempFolder; |
||
82 | |||
83 | public function setUp(): void |
||
89 | |||
90 | /** |
||
91 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::__construct |
||
92 | */ |
||
93 | public function testConstructor(): void |
||
103 | |||
104 | public function testGetClass(): void |
||
127 | |||
128 | public function testGetClassException(): void |
||
142 | |||
143 | public function testCheckAccessThrowsExceptionOnMadeUpAction(): void |
||
144 | { |
||
145 | $admin = new PostAdmin( |
||
146 | 'sonata.post.admin.post', |
||
147 | 'Application\Sonata\NewsBundle\Entity\Post', |
||
148 | 'Sonata\NewsBundle\Controller\PostAdminController' |
||
149 | ); |
||
150 | $this->expectException( |
||
151 | \InvalidArgumentException::class |
||
152 | ); |
||
153 | $this->expectExceptionMessage( |
||
154 | 'Action "made-up" could not be found' |
||
155 | ); |
||
156 | $admin->checkAccess('made-up'); |
||
157 | } |
||
158 | |||
159 | public function testCheckAccessThrowsAccessDeniedException(): void |
||
160 | { |
||
161 | $admin = new PostAdmin( |
||
162 | 'sonata.post.admin.post', |
||
163 | 'Application\Sonata\NewsBundle\Entity\Post', |
||
164 | 'Sonata\NewsBundle\Controller\PostAdminController' |
||
165 | ); |
||
166 | $securityHandler = $this->prophesize(SecurityHandlerInterface::class); |
||
167 | $securityHandler->isGranted($admin, 'CUSTOM_ROLE', $admin)->willReturn(true); |
||
168 | $securityHandler->isGranted($admin, 'EXTRA_CUSTOM_ROLE', $admin)->willReturn(false); |
||
169 | $customExtension = $this->prophesize(AbstractAdminExtension::class); |
||
170 | $customExtension->getAccessMapping($admin)->willReturn( |
||
171 | ['custom_action' => ['CUSTOM_ROLE', 'EXTRA_CUSTOM_ROLE']] |
||
172 | ); |
||
173 | $admin->addExtension($customExtension->reveal()); |
||
174 | $admin->setSecurityHandler($securityHandler->reveal()); |
||
175 | $this->expectException( |
||
176 | AccessDeniedException::class |
||
177 | ); |
||
178 | $this->expectExceptionMessage( |
||
179 | 'Access Denied to the action custom_action and role EXTRA_CUSTOM_ROLE' |
||
180 | ); |
||
181 | $admin->checkAccess('custom_action'); |
||
182 | } |
||
183 | |||
184 | public function testHasAccessOnMadeUpAction(): void |
||
185 | { |
||
186 | $admin = new PostAdmin( |
||
187 | 'sonata.post.admin.post', |
||
188 | 'Application\Sonata\NewsBundle\Entity\Post', |
||
189 | 'Sonata\NewsBundle\Controller\PostAdminController' |
||
190 | ); |
||
191 | |||
192 | $this->assertFalse($admin->hasAccess('made-up')); |
||
193 | } |
||
194 | |||
195 | public function testHasAccess(): void |
||
196 | { |
||
197 | $admin = new PostAdmin( |
||
198 | 'sonata.post.admin.post', |
||
199 | 'Application\Sonata\NewsBundle\Entity\Post', |
||
200 | 'Sonata\NewsBundle\Controller\PostAdminController' |
||
201 | ); |
||
202 | $securityHandler = $this->prophesize(SecurityHandlerInterface::class); |
||
203 | $securityHandler->isGranted($admin, 'CUSTOM_ROLE', $admin)->willReturn(true); |
||
204 | $securityHandler->isGranted($admin, 'EXTRA_CUSTOM_ROLE', $admin)->willReturn(false); |
||
205 | $customExtension = $this->prophesize(AbstractAdminExtension::class); |
||
206 | $customExtension->getAccessMapping($admin)->willReturn( |
||
207 | ['custom_action' => ['CUSTOM_ROLE', 'EXTRA_CUSTOM_ROLE']] |
||
208 | ); |
||
209 | $admin->addExtension($customExtension->reveal()); |
||
210 | $admin->setSecurityHandler($securityHandler->reveal()); |
||
211 | |||
212 | $this->assertFalse($admin->hasAccess('custom_action')); |
||
213 | } |
||
214 | |||
215 | public function testHasAccessAllowsAccess(): void |
||
216 | { |
||
217 | $admin = new PostAdmin( |
||
218 | 'sonata.post.admin.post', |
||
219 | 'Application\Sonata\NewsBundle\Entity\Post', |
||
220 | 'Sonata\NewsBundle\Controller\PostAdminController' |
||
221 | ); |
||
222 | $securityHandler = $this->prophesize(SecurityHandlerInterface::class); |
||
223 | $securityHandler->isGranted($admin, 'CUSTOM_ROLE', $admin)->willReturn(true); |
||
224 | $securityHandler->isGranted($admin, 'EXTRA_CUSTOM_ROLE', $admin)->willReturn(true); |
||
225 | $customExtension = $this->prophesize(AbstractAdminExtension::class); |
||
226 | $customExtension->getAccessMapping($admin)->willReturn( |
||
227 | ['custom_action' => ['CUSTOM_ROLE', 'EXTRA_CUSTOM_ROLE']] |
||
228 | ); |
||
229 | $admin->addExtension($customExtension->reveal()); |
||
230 | $admin->setSecurityHandler($securityHandler->reveal()); |
||
231 | |||
232 | $this->assertTrue($admin->hasAccess('custom_action')); |
||
233 | } |
||
234 | |||
235 | public function testHasAccessAllowsAccessEditAction(): void |
||
236 | { |
||
237 | $admin = new PostAdmin( |
||
238 | 'sonata.post.admin.post', |
||
239 | 'Application\Sonata\NewsBundle\Entity\Post', |
||
240 | 'Sonata\NewsBundle\Controller\PostAdminController' |
||
241 | ); |
||
242 | $securityHandler = $this->prophesize(SecurityHandlerInterface::class); |
||
243 | $securityHandler->isGranted($admin, 'EDIT_ROLE', $admin)->willReturn(true); |
||
244 | $customExtension = $this->prophesize(AbstractAdminExtension::class); |
||
245 | $customExtension->getAccessMapping($admin)->willReturn( |
||
246 | ['edit_action' => ['EDIT_ROLE']] |
||
247 | ); |
||
248 | $admin->addExtension($customExtension->reveal()); |
||
249 | $admin->setSecurityHandler($securityHandler->reveal()); |
||
250 | |||
251 | $this->assertTrue($admin->hasAccess('edit_action')); |
||
252 | } |
||
253 | |||
254 | /** |
||
255 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::hasChild |
||
256 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::addChild |
||
257 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getChild |
||
258 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::isChild |
||
259 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::hasChildren |
||
260 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getChildren |
||
261 | */ |
||
262 | public function testChildren(): void |
||
263 | { |
||
264 | $postAdmin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
265 | $this->assertFalse($postAdmin->hasChildren()); |
||
266 | $this->assertFalse($postAdmin->hasChild('comment')); |
||
267 | |||
268 | $commentAdmin = new CommentAdmin('sonata.post.admin.comment', 'Application\Sonata\NewsBundle\Entity\Comment', 'Sonata\NewsBundle\Controller\CommentAdminController'); |
||
269 | $postAdmin->addChild($commentAdmin, 'post'); |
||
270 | |||
271 | $this->assertTrue($postAdmin->hasChildren()); |
||
272 | $this->assertTrue($postAdmin->hasChild('sonata.post.admin.comment')); |
||
273 | |||
274 | $this->assertSame('sonata.post.admin.comment', $postAdmin->getChild('sonata.post.admin.comment')->getCode()); |
||
275 | $this->assertSame('sonata.post.admin.post|sonata.post.admin.comment', $postAdmin->getChild('sonata.post.admin.comment')->getBaseCodeRoute()); |
||
276 | $this->assertSame($postAdmin, $postAdmin->getChild('sonata.post.admin.comment')->getParent()); |
||
277 | $this->assertSame('post', $commentAdmin->getParentAssociationMapping()); |
||
278 | |||
279 | $this->assertFalse($postAdmin->isChild()); |
||
280 | $this->assertTrue($commentAdmin->isChild()); |
||
281 | |||
282 | $this->assertSame(['sonata.post.admin.comment' => $commentAdmin], $postAdmin->getChildren()); |
||
283 | } |
||
284 | |||
285 | /** |
||
286 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::configure |
||
287 | */ |
||
288 | public function testConfigure(): void |
||
289 | { |
||
290 | $admin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
291 | $this->assertNotNull($admin->getUniqid()); |
||
292 | |||
293 | $admin->initialize(); |
||
294 | $this->assertNotNull($admin->getUniqid()); |
||
295 | $this->assertSame('Post', $admin->getClassnameLabel()); |
||
296 | |||
297 | $admin = new CommentAdmin('sonata.post.admin.comment', 'Application\Sonata\NewsBundle\Entity\Comment', 'Sonata\NewsBundle\Controller\CommentAdminController'); |
||
298 | $admin->setClassnameLabel('postcomment'); |
||
299 | |||
300 | $admin->initialize(); |
||
301 | $this->assertSame('postcomment', $admin->getClassnameLabel()); |
||
302 | } |
||
303 | |||
304 | public function testConfigureWithValidParentAssociationMapping(): void |
||
305 | { |
||
306 | $admin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
307 | $admin->setParentAssociationMapping('Category'); |
||
308 | |||
309 | $admin->initialize(); |
||
310 | $this->assertSame('Category', $admin->getParentAssociationMapping()); |
||
311 | } |
||
312 | |||
313 | public function provideGetBaseRoutePattern() |
||
314 | { |
||
315 | return [ |
||
316 | [ |
||
317 | 'Application\Sonata\NewsBundle\Entity\Post', |
||
318 | '/sonata/news/post', |
||
319 | ], |
||
320 | [ |
||
321 | 'Application\Sonata\NewsBundle\Document\Post', |
||
322 | '/sonata/news/post', |
||
323 | ], |
||
324 | [ |
||
325 | 'MyApplication\MyBundle\Entity\Post', |
||
326 | '/myapplication/my/post', |
||
327 | ], |
||
328 | [ |
||
329 | 'MyApplication\MyBundle\Entity\Post\Category', |
||
330 | '/myapplication/my/post-category', |
||
331 | ], |
||
332 | [ |
||
333 | 'MyApplication\MyBundle\Entity\Product\Category', |
||
334 | '/myapplication/my/product-category', |
||
335 | ], |
||
336 | [ |
||
337 | 'MyApplication\MyBundle\Entity\Other\Product\Category', |
||
338 | '/myapplication/my/other-product-category', |
||
339 | ], |
||
340 | [ |
||
341 | 'Symfony\Cmf\Bundle\FooBundle\Document\Menu', |
||
342 | '/cmf/foo/menu', |
||
343 | ], |
||
344 | [ |
||
345 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\Phpcr\Menu', |
||
346 | '/cmf/foo/menu', |
||
347 | ], |
||
348 | [ |
||
349 | 'Symfony\Bundle\BarBarBundle\Doctrine\Phpcr\Menu', |
||
350 | '/symfony/barbar/menu', |
||
351 | ], |
||
352 | [ |
||
353 | 'Symfony\Bundle\BarBarBundle\Doctrine\Phpcr\Menu\Item', |
||
354 | '/symfony/barbar/menu-item', |
||
355 | ], |
||
356 | [ |
||
357 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\Orm\Menu', |
||
358 | '/cmf/foo/menu', |
||
359 | ], |
||
360 | [ |
||
361 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\MongoDB\Menu', |
||
362 | '/cmf/foo/menu', |
||
363 | ], |
||
364 | [ |
||
365 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\CouchDB\Menu', |
||
366 | '/cmf/foo/menu', |
||
367 | ], |
||
368 | [ |
||
369 | 'AppBundle\Entity\User', |
||
370 | '/app/user', |
||
371 | ], |
||
372 | [ |
||
373 | 'App\Entity\User', |
||
374 | '/app/user', |
||
375 | ], |
||
376 | ]; |
||
377 | } |
||
378 | |||
379 | /** |
||
380 | * @dataProvider provideGetBaseRoutePattern |
||
381 | */ |
||
382 | public function testGetBaseRoutePattern(string $objFqn, string $expected): void |
||
383 | { |
||
384 | $admin = new PostAdmin('sonata.post.admin.post', $objFqn, 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
385 | $this->assertSame($expected, $admin->getBaseRoutePattern()); |
||
386 | } |
||
387 | |||
388 | /** |
||
389 | * @dataProvider provideGetBaseRoutePattern |
||
390 | */ |
||
391 | public function testGetBaseRoutePatternWithChildAdmin(string $objFqn, string $expected): void |
||
392 | { |
||
393 | $postAdmin = new PostAdmin('sonata.post.admin.post', $objFqn, 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
394 | $commentAdmin = new CommentAdmin('sonata.post.admin.comment', 'Application\Sonata\NewsBundle\Entity\Comment', 'Sonata\NewsBundle\Controller\CommentAdminController'); |
||
395 | $commentAdmin->setParent($postAdmin); |
||
396 | |||
397 | $this->assertSame($expected.'/{id}/comment', $commentAdmin->getBaseRoutePattern()); |
||
398 | } |
||
399 | |||
400 | /** |
||
401 | * @dataProvider provideGetBaseRoutePattern |
||
402 | */ |
||
403 | public function testGetBaseRoutePatternWithTwoNestedChildAdmin(string $objFqn, string $expected): void |
||
404 | { |
||
405 | $postAdmin = new PostAdmin('sonata.post.admin.post', $objFqn, 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
406 | $commentAdmin = new CommentAdmin( |
||
407 | 'sonata.post.admin.comment', |
||
408 | 'Application\Sonata\NewsBundle\Entity\Comment', |
||
409 | 'Sonata\NewsBundle\Controller\CommentAdminController' |
||
410 | ); |
||
411 | $commentVoteAdmin = new CommentVoteAdmin( |
||
412 | 'sonata.post.admin.comment_vote', |
||
413 | 'Application\Sonata\NewsBundle\Entity\CommentVote', |
||
414 | 'Sonata\NewsBundle\Controller\CommentVoteAdminController' |
||
415 | ); |
||
416 | $commentAdmin->setParent($postAdmin); |
||
417 | $commentVoteAdmin->setParent($commentAdmin); |
||
418 | |||
419 | $this->assertSame($expected.'/{id}/comment/{childId}/commentvote', $commentVoteAdmin->getBaseRoutePattern()); |
||
420 | } |
||
421 | |||
422 | public function testGetBaseRoutePatternWithSpecifedPattern(): void |
||
423 | { |
||
424 | $postAdmin = new PostWithCustomRouteAdmin('sonata.post.admin.post_with_custom_route', 'Application\Sonata\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostWithCustomRouteAdminController'); |
||
425 | |||
426 | $this->assertSame('/post-custom', $postAdmin->getBaseRoutePattern()); |
||
427 | } |
||
428 | |||
429 | public function testGetBaseRoutePatternWithChildAdminAndWithSpecifedPattern(): void |
||
430 | { |
||
431 | $postAdmin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
432 | $commentAdmin = new CommentWithCustomRouteAdmin('sonata.post.admin.comment_with_custom_route', 'Application\Sonata\NewsBundle\Entity\Comment', 'Sonata\NewsBundle\Controller\CommentWithCustomRouteAdminController'); |
||
433 | $commentAdmin->setParent($postAdmin); |
||
434 | |||
435 | $this->assertSame('/sonata/news/post/{id}/comment-custom', $commentAdmin->getBaseRoutePattern()); |
||
436 | } |
||
437 | |||
438 | public function testGetBaseRoutePatternWithUnreconizedClassname(): void |
||
439 | { |
||
440 | $this->expectException(\RuntimeException::class); |
||
441 | |||
442 | $admin = new PostAdmin('sonata.post.admin.post', 'News\Thing\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
443 | $admin->getBaseRoutePattern(); |
||
444 | } |
||
445 | |||
446 | public function provideGetBaseRouteName() |
||
447 | { |
||
448 | return [ |
||
449 | [ |
||
450 | 'Application\Sonata\NewsBundle\Entity\Post', |
||
451 | 'admin_sonata_news_post', |
||
452 | ], |
||
453 | [ |
||
454 | 'Application\Sonata\NewsBundle\Document\Post', |
||
455 | 'admin_sonata_news_post', |
||
456 | ], |
||
457 | [ |
||
458 | 'MyApplication\MyBundle\Entity\Post', |
||
459 | 'admin_myapplication_my_post', |
||
460 | ], |
||
461 | [ |
||
462 | 'MyApplication\MyBundle\Entity\Post\Category', |
||
463 | 'admin_myapplication_my_post_category', |
||
464 | ], |
||
465 | [ |
||
466 | 'MyApplication\MyBundle\Entity\Product\Category', |
||
467 | 'admin_myapplication_my_product_category', |
||
468 | ], |
||
469 | [ |
||
470 | 'MyApplication\MyBundle\Entity\Other\Product\Category', |
||
471 | 'admin_myapplication_my_other_product_category', |
||
472 | ], |
||
473 | [ |
||
474 | 'Symfony\Cmf\Bundle\FooBundle\Document\Menu', |
||
475 | 'admin_cmf_foo_menu', |
||
476 | ], |
||
477 | [ |
||
478 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\Phpcr\Menu', |
||
479 | 'admin_cmf_foo_menu', |
||
480 | ], |
||
481 | [ |
||
482 | 'Symfony\Bundle\BarBarBundle\Doctrine\Phpcr\Menu', |
||
483 | 'admin_symfony_barbar_menu', |
||
484 | ], |
||
485 | [ |
||
486 | 'Symfony\Bundle\BarBarBundle\Doctrine\Phpcr\Menu\Item', |
||
487 | 'admin_symfony_barbar_menu_item', |
||
488 | ], |
||
489 | [ |
||
490 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\Orm\Menu', |
||
491 | 'admin_cmf_foo_menu', |
||
492 | ], |
||
493 | [ |
||
494 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\MongoDB\Menu', |
||
495 | 'admin_cmf_foo_menu', |
||
496 | ], |
||
497 | [ |
||
498 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\CouchDB\Menu', |
||
499 | 'admin_cmf_foo_menu', |
||
500 | ], |
||
501 | [ |
||
502 | 'AppBundle\Entity\User', |
||
503 | 'admin_app_user', |
||
504 | ], |
||
505 | [ |
||
506 | 'App\Entity\User', |
||
507 | 'admin_app_user', |
||
508 | ], |
||
509 | ]; |
||
510 | } |
||
511 | |||
512 | /** |
||
513 | * @dataProvider provideGetBaseRouteName |
||
514 | */ |
||
515 | public function testGetBaseRouteName(string $objFqn, string $expected): void |
||
516 | { |
||
517 | $admin = new PostAdmin('sonata.post.admin.post', $objFqn, 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
518 | |||
519 | $this->assertSame($expected, $admin->getBaseRouteName()); |
||
520 | } |
||
521 | |||
522 | /** |
||
523 | * @group legacy |
||
524 | * @expectedDeprecation Calling "addChild" without second argument is deprecated since sonata-project/admin-bundle 3.35 and will not be allowed in 4.0. |
||
525 | * @dataProvider provideGetBaseRouteName |
||
526 | */ |
||
527 | public function testGetBaseRouteNameWithChildAdmin(string $objFqn, string $expected): void |
||
528 | { |
||
529 | $routeGenerator = new DefaultRouteGenerator( |
||
530 | $this->createMock(RouterInterface::class), |
||
531 | new RoutesCache($this->cacheTempFolder, true) |
||
532 | ); |
||
533 | |||
534 | $container = new Container(); |
||
535 | $pool = new Pool($container, 'Sonata Admin', '/path/to/pic.png'); |
||
536 | |||
537 | $pathInfo = new PathInfoBuilder($this->createMock(AuditManagerInterface::class)); |
||
538 | $postAdmin = new PostAdmin('sonata.post.admin.post', $objFqn, 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
539 | $container->set('sonata.post.admin.post', $postAdmin); |
||
540 | $postAdmin->setConfigurationPool($pool); |
||
541 | $postAdmin->setRouteBuilder($pathInfo); |
||
542 | $postAdmin->setRouteGenerator($routeGenerator); |
||
543 | $postAdmin->initialize(); |
||
544 | |||
545 | $commentAdmin = new CommentAdmin( |
||
546 | 'sonata.post.admin.comment', |
||
547 | 'Application\Sonata\NewsBundle\Entity\Comment', |
||
548 | 'Sonata\NewsBundle\Controller\CommentAdminController' |
||
549 | ); |
||
550 | $container->set('sonata.post.admin.comment', $commentAdmin); |
||
551 | $commentAdmin->setConfigurationPool($pool); |
||
552 | $commentAdmin->setRouteBuilder($pathInfo); |
||
553 | $commentAdmin->setRouteGenerator($routeGenerator); |
||
554 | $commentAdmin->initialize(); |
||
555 | |||
556 | $postAdmin->addChild($commentAdmin, 'post'); |
||
557 | |||
558 | $commentVoteAdmin = new CommentVoteAdmin( |
||
559 | 'sonata.post.admin.comment_vote', |
||
560 | 'Application\Sonata\NewsBundle\Entity\CommentVote', |
||
561 | 'Sonata\NewsBundle\Controller\CommentVoteAdminController' |
||
562 | ); |
||
563 | |||
564 | $container->set('sonata.post.admin.comment_vote', $commentVoteAdmin); |
||
565 | $commentVoteAdmin->setConfigurationPool($pool); |
||
566 | $commentVoteAdmin->setRouteBuilder($pathInfo); |
||
567 | $commentVoteAdmin->setRouteGenerator($routeGenerator); |
||
568 | $commentVoteAdmin->initialize(); |
||
569 | |||
570 | $commentAdmin->addChild($commentVoteAdmin); |
||
571 | $pool->setAdminServiceIds([ |
||
572 | 'sonata.post.admin.post', |
||
573 | 'sonata.post.admin.comment', |
||
574 | 'sonata.post.admin.comment_vote', |
||
575 | ]); |
||
576 | |||
577 | $this->assertSame($expected.'_comment', $commentAdmin->getBaseRouteName()); |
||
578 | |||
579 | $this->assertTrue($postAdmin->hasRoute('show')); |
||
580 | $this->assertTrue($postAdmin->hasRoute('sonata.post.admin.post.show')); |
||
581 | $this->assertTrue($postAdmin->hasRoute('sonata.post.admin.post|sonata.post.admin.comment.show')); |
||
582 | $this->assertTrue($postAdmin->hasRoute('sonata.post.admin.post|sonata.post.admin.comment|sonata.post.admin.comment_vote.show')); |
||
583 | $this->assertTrue($postAdmin->hasRoute('sonata.post.admin.comment.list')); |
||
584 | $this->assertTrue($postAdmin->hasRoute('sonata.post.admin.comment|sonata.post.admin.comment_vote.list')); |
||
585 | $this->assertFalse($postAdmin->hasRoute('sonata.post.admin.post|sonata.post.admin.comment.edit')); |
||
586 | $this->assertFalse($commentAdmin->hasRoute('edit')); |
||
587 | $this->assertSame('post', $commentAdmin->getParentAssociationMapping()); |
||
588 | |||
589 | /* |
||
590 | * Test the route name from request |
||
591 | */ |
||
592 | $postListRequest = new Request( |
||
593 | [], |
||
594 | [], |
||
595 | [ |
||
596 | '_route' => $postAdmin->getBaseRouteName().'_list', |
||
597 | ] |
||
598 | ); |
||
599 | |||
600 | $postAdmin->setRequest($postListRequest); |
||
601 | $commentAdmin->setRequest($postListRequest); |
||
602 | |||
603 | $this->assertTrue($postAdmin->isCurrentRoute('list')); |
||
604 | $this->assertFalse($postAdmin->isCurrentRoute('create')); |
||
605 | $this->assertFalse($commentAdmin->isCurrentRoute('list')); |
||
606 | $this->assertFalse($commentVoteAdmin->isCurrentRoute('list')); |
||
607 | $this->assertTrue($commentAdmin->isCurrentRoute('list', 'sonata.post.admin.post')); |
||
608 | $this->assertFalse($commentAdmin->isCurrentRoute('edit', 'sonata.post.admin.post')); |
||
609 | $this->assertTrue($commentVoteAdmin->isCurrentRoute('list', 'sonata.post.admin.post')); |
||
610 | $this->assertFalse($commentVoteAdmin->isCurrentRoute('edit', 'sonata.post.admin.post')); |
||
611 | } |
||
612 | |||
613 | public function testGetBaseRouteNameWithUnreconizedClassname(): void |
||
614 | { |
||
615 | $this->expectException(\RuntimeException::class); |
||
616 | |||
617 | $admin = new PostAdmin('sonata.post.admin.post', 'News\Thing\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
618 | $admin->getBaseRouteName(); |
||
619 | } |
||
620 | |||
621 | public function testGetBaseRouteNameWithSpecifiedName(): void |
||
622 | { |
||
623 | $postAdmin = new PostWithCustomRouteAdmin('sonata.post.admin.post_with_custom_route', 'Application\Sonata\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
624 | |||
625 | $this->assertSame('post_custom', $postAdmin->getBaseRouteName()); |
||
626 | } |
||
627 | |||
628 | public function testGetBaseRouteNameWithChildAdminAndWithSpecifiedName(): void |
||
629 | { |
||
630 | $postAdmin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
631 | $commentAdmin = new CommentWithCustomRouteAdmin('sonata.post.admin.comment_with_custom_route', 'Application\Sonata\NewsBundle\Entity\Comment', 'Sonata\NewsBundle\Controller\CommentWithCustomRouteAdminController'); |
||
632 | $commentAdmin->setParent($postAdmin); |
||
633 | |||
634 | $this->assertSame('admin_sonata_news_post_comment_custom', $commentAdmin->getBaseRouteName()); |
||
635 | } |
||
636 | |||
637 | public function testGetBaseRouteNameWithTwoNestedChildAdminAndWithSpecifiedName(): void |
||
638 | { |
||
639 | $postAdmin = new PostAdmin( |
||
640 | 'sonata.post.admin.post', |
||
641 | 'Application\Sonata\NewsBundle\Entity\Post', |
||
642 | 'Sonata\NewsBundle\Controller\PostAdminController' |
||
643 | ); |
||
644 | $commentAdmin = new CommentWithCustomRouteAdmin( |
||
645 | 'sonata.post.admin.comment_with_custom_route', |
||
646 | 'Application\Sonata\NewsBundle\Entity\Comment', |
||
647 | 'Sonata\NewsBundle\Controller\CommentWithCustomRouteAdminController' |
||
648 | ); |
||
649 | $commentVoteAdmin = new CommentVoteAdmin( |
||
650 | 'sonata.post.admin.comment_vote', |
||
651 | 'Application\Sonata\NewsBundle\Entity\CommentVote', |
||
652 | 'Sonata\NewsBundle\Controller\CommentVoteAdminController' |
||
653 | ); |
||
654 | $commentAdmin->setParent($postAdmin); |
||
655 | $commentVoteAdmin->setParent($commentAdmin); |
||
656 | |||
657 | $this->assertSame('admin_sonata_news_post_comment_custom_commentvote', $commentVoteAdmin->getBaseRouteName()); |
||
658 | } |
||
659 | |||
660 | /** |
||
661 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::setUniqid |
||
662 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getUniqid |
||
663 | */ |
||
664 | public function testSetUniqid(): void |
||
665 | { |
||
666 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
667 | |||
668 | $uniqid = uniqid(); |
||
669 | $admin->setUniqid($uniqid); |
||
670 | |||
671 | $this->assertSame($uniqid, $admin->getUniqid()); |
||
672 | } |
||
673 | |||
674 | public function testToString(): void |
||
675 | { |
||
676 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
677 | |||
678 | $s = new \stdClass(); |
||
679 | |||
680 | $this->assertNotEmpty($admin->toString($s)); |
||
681 | |||
682 | $s = new FooToString(); |
||
683 | $this->assertSame('salut', $admin->toString($s)); |
||
684 | |||
685 | // To string method is implemented, but returns null |
||
686 | $s = new FooToStringNull(); |
||
687 | $this->assertNotEmpty($admin->toString($s)); |
||
688 | |||
689 | $this->assertSame('', $admin->toString(false)); |
||
|
|||
690 | } |
||
691 | |||
692 | public function testIsAclEnabled(): void |
||
693 | { |
||
694 | $postAdmin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
695 | |||
696 | $this->assertFalse($postAdmin->isAclEnabled()); |
||
697 | |||
698 | $commentAdmin = new CommentAdmin('sonata.post.admin.comment', 'Application\Sonata\NewsBundle\Entity\Comment', 'Sonata\NewsBundle\Controller\CommentAdminController'); |
||
699 | $commentAdmin->setSecurityHandler($this->createMock(AclSecurityHandlerInterface::class)); |
||
700 | $this->assertTrue($commentAdmin->isAclEnabled()); |
||
701 | } |
||
702 | |||
703 | /** |
||
704 | * @group legacy |
||
705 | * |
||
706 | * @expectedDeprecation Calling Sonata\AdminBundle\Admin\AbstractAdmin::getActiveSubclassCode() when there is no active subclass is deprecated since sonata-project/admin-bundle 3.52 and will throw an exception in 4.0. Use Sonata\AdminBundle\Admin\AbstractAdmin::hasActiveSubClass() to know if there is an active subclass. |
||
707 | * |
||
708 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getSubClasses |
||
709 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getSubClass |
||
710 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::setSubClasses |
||
711 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::hasSubClass |
||
712 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::hasActiveSubClass |
||
713 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getActiveSubClass |
||
714 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getActiveSubclassCode |
||
715 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getClass |
||
716 | */ |
||
717 | public function testSubClass(): void |
||
718 | { |
||
719 | // NEXT_MAJOR: Remove the "@group" and "@expectedDeprecation" annotations |
||
720 | $admin = new PostAdmin( |
||
721 | 'sonata.post.admin.post', |
||
722 | Post::class, |
||
723 | 'Sonata\NewsBundle\Controller\PostAdminController' |
||
724 | ); |
||
725 | $this->assertFalse($admin->hasSubClass('test')); |
||
726 | $this->assertFalse($admin->hasActiveSubClass()); |
||
727 | $this->assertCount(0, $admin->getSubClasses()); |
||
728 | $this->assertNull($admin->getActiveSubClass()); |
||
729 | $this->assertNull($admin->getActiveSubclassCode()); |
||
730 | $this->assertSame(Post::class, $admin->getClass()); |
||
731 | |||
732 | // Just for the record, if there is no inheritance set, the getSubject is not used |
||
733 | // the getSubject can also lead to some issue |
||
734 | $admin->setSubject(new BlogPost()); |
||
735 | $this->assertSame(BlogPost::class, $admin->getClass()); |
||
736 | |||
737 | $admin->setSubClasses([ |
||
738 | 'extended1' => 'NewsBundle\Entity\PostExtended1', |
||
739 | 'extended2' => 'NewsBundle\Entity\PostExtended2', |
||
740 | ]); |
||
741 | $this->assertFalse($admin->hasSubClass('test')); |
||
742 | $this->assertTrue($admin->hasSubClass('extended1')); |
||
743 | $this->assertFalse($admin->hasActiveSubClass()); |
||
744 | $this->assertCount(2, $admin->getSubClasses()); |
||
745 | // NEXT_MAJOR: remove the following 2 `assertNull()` assertions |
||
746 | $this->assertNull($admin->getActiveSubClass()); |
||
747 | $this->assertNull($admin->getActiveSubclassCode()); |
||
748 | $this->assertSame( |
||
749 | BlogPost::class, |
||
750 | $admin->getClass(), |
||
751 | 'When there is no subclass in the query the class parameter should be returned' |
||
752 | ); |
||
753 | |||
754 | $request = new Request(['subclass' => 'extended1']); |
||
755 | $admin->setRequest($request); |
||
756 | $this->assertFalse($admin->hasSubClass('test')); |
||
757 | $this->assertTrue($admin->hasSubClass('extended1')); |
||
758 | $this->assertTrue($admin->hasActiveSubClass()); |
||
759 | $this->assertCount(2, $admin->getSubClasses()); |
||
760 | $this->assertSame( |
||
761 | 'NewsBundle\Entity\PostExtended1', |
||
762 | $admin->getActiveSubClass(), |
||
763 | 'It should return the curently active sub class.' |
||
764 | ); |
||
765 | $this->assertSame('extended1', $admin->getActiveSubclassCode()); |
||
766 | $this->assertSame( |
||
767 | 'NewsBundle\Entity\PostExtended1', |
||
768 | $admin->getClass(), |
||
769 | 'getClass() should return the name of the sub class when passed through a request query parameter.' |
||
770 | ); |
||
771 | |||
772 | $request->query->set('subclass', 'inject'); |
||
773 | |||
774 | $this->assertNull($admin->getActiveSubclassCode()); |
||
775 | // NEXT_MAJOR: remove the previous `assertNull()` assertion and uncomment the following lines |
||
776 | // $this->expectException(\LogicException::class); |
||
777 | // $this->expectExceptionMessage(sprintf('Admin "%s" has no active subclass.', PostAdmin::class)); |
||
778 | } |
||
779 | |||
780 | /** |
||
781 | * @group legacy |
||
782 | * |
||
783 | * @expectedDeprecation Calling Sonata\AdminBundle\Admin\AbstractAdmin::getActiveSubclassCode() when there is no active subclass is deprecated since sonata-project/admin-bundle 3.52 and will throw an exception in 4.0. Use Sonata\AdminBundle\Admin\AbstractAdmin::hasActiveSubClass() to know if there is an active subclass. |
||
784 | */ |
||
785 | public function testNonExistantSubclass(): void |
||
786 | { |
||
787 | // NEXT_MAJOR: Remove the "@group" and "@expectedDeprecation" annotations |
||
788 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
789 | $admin->setModelManager($this->getMockForAbstractClass(ModelManagerInterface::class)); |
||
790 | |||
791 | $admin->setRequest(new Request(['subclass' => 'inject'])); |
||
792 | |||
793 | $admin->setSubClasses(['extended1' => 'NewsBundle\Entity\PostExtended1', 'extended2' => 'NewsBundle\Entity\PostExtended2']); |
||
794 | |||
795 | $this->assertTrue($admin->hasActiveSubClass()); |
||
796 | |||
797 | $this->expectException(\RuntimeException::class); |
||
798 | |||
799 | $admin->getActiveSubClass(); |
||
800 | } |
||
801 | |||
802 | /** |
||
803 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::hasActiveSubClass |
||
804 | */ |
||
805 | public function testOnlyOneSubclassNeededToBeActive(): void |
||
806 | { |
||
807 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
808 | $admin->setSubClasses(['extended1' => 'NewsBundle\Entity\PostExtended1']); |
||
809 | $request = new Request(['subclass' => 'extended1']); |
||
810 | $admin->setRequest($request); |
||
811 | $this->assertTrue($admin->hasActiveSubClass()); |
||
812 | } |
||
813 | |||
814 | /** |
||
815 | * @group legacy |
||
816 | * @expectedDeprecation Method "Sonata\AdminBundle\Admin\AbstractAdmin::addSubClass" is deprecated since sonata-project/admin-bundle 3.30 and will be removed in 4.0. |
||
817 | */ |
||
818 | public function testAddSubClassIsDeprecated(): void |
||
819 | { |
||
820 | $admin = new PostAdmin( |
||
821 | 'sonata.post.admin.post', |
||
822 | Post::class, |
||
823 | 'Sonata\NewsBundle\Controller\PostAdminController' |
||
824 | ); |
||
825 | $admin->addSubClass('whatever'); |
||
826 | } |
||
827 | |||
828 | public function testGetPerPageOptions(): void |
||
829 | { |
||
830 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
831 | |||
832 | $perPageOptions = $admin->getPerPageOptions(); |
||
833 | |||
834 | foreach ($perPageOptions as $perPage) { |
||
835 | $this->assertSame(0, $perPage % 4); |
||
836 | } |
||
837 | |||
838 | $admin->setPerPageOptions([500, 1000]); |
||
839 | $this->assertSame([500, 1000], $admin->getPerPageOptions()); |
||
840 | } |
||
841 | |||
842 | public function testGetLabelTranslatorStrategy(): void |
||
843 | { |
||
844 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
845 | |||
846 | $this->assertNull($admin->getLabelTranslatorStrategy()); |
||
847 | |||
848 | $labelTranslatorStrategy = $this->createMock(LabelTranslatorStrategyInterface::class); |
||
849 | $admin->setLabelTranslatorStrategy($labelTranslatorStrategy); |
||
850 | $this->assertSame($labelTranslatorStrategy, $admin->getLabelTranslatorStrategy()); |
||
851 | } |
||
852 | |||
853 | public function testGetRouteBuilder(): void |
||
854 | { |
||
855 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
856 | |||
857 | $this->assertNull($admin->getRouteBuilder()); |
||
858 | |||
859 | $routeBuilder = $this->createMock(RouteBuilderInterface::class); |
||
860 | $admin->setRouteBuilder($routeBuilder); |
||
861 | $this->assertSame($routeBuilder, $admin->getRouteBuilder()); |
||
862 | } |
||
863 | |||
864 | public function testGetMenuFactory(): void |
||
865 | { |
||
866 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
867 | |||
868 | $this->assertNull($admin->getMenuFactory()); |
||
869 | |||
870 | $menuFactory = $this->createMock(FactoryInterface::class); |
||
871 | $admin->setMenuFactory($menuFactory); |
||
872 | $this->assertSame($menuFactory, $admin->getMenuFactory()); |
||
873 | } |
||
874 | |||
875 | public function testGetExtensions(): void |
||
876 | { |
||
877 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
878 | |||
879 | $this->assertSame([], $admin->getExtensions()); |
||
880 | |||
881 | $adminExtension1 = $this->createMock(AdminExtensionInterface::class); |
||
882 | $adminExtension2 = $this->createMock(AdminExtensionInterface::class); |
||
883 | |||
884 | $admin->addExtension($adminExtension1); |
||
885 | $admin->addExtension($adminExtension2); |
||
886 | $this->assertSame([$adminExtension1, $adminExtension2], $admin->getExtensions()); |
||
887 | } |
||
888 | |||
889 | public function testGetFilterTheme(): void |
||
890 | { |
||
891 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
892 | |||
893 | $this->assertSame([], $admin->getFilterTheme()); |
||
894 | |||
895 | $admin->setFilterTheme(['FooTheme']); |
||
896 | $this->assertSame(['FooTheme'], $admin->getFilterTheme()); |
||
897 | } |
||
898 | |||
899 | public function testGetFormTheme(): void |
||
900 | { |
||
901 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
902 | |||
903 | $this->assertSame([], $admin->getFormTheme()); |
||
904 | |||
905 | $admin->setFormTheme(['FooTheme']); |
||
906 | |||
907 | $this->assertSame(['FooTheme'], $admin->getFormTheme()); |
||
908 | } |
||
909 | |||
910 | public function testGetValidator(): void |
||
911 | { |
||
912 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
913 | |||
914 | $this->assertNull($admin->getValidator()); |
||
915 | |||
916 | $validator = $this->getMockForAbstractClass(ValidatorInterface::class); |
||
917 | |||
918 | $admin->setValidator($validator); |
||
919 | $this->assertSame($validator, $admin->getValidator()); |
||
920 | } |
||
921 | |||
922 | public function testGetSecurityHandler(): void |
||
923 | { |
||
924 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
925 | |||
926 | $this->assertNull($admin->getSecurityHandler()); |
||
927 | |||
928 | $securityHandler = $this->createMock(SecurityHandlerInterface::class); |
||
929 | $admin->setSecurityHandler($securityHandler); |
||
930 | $this->assertSame($securityHandler, $admin->getSecurityHandler()); |
||
931 | } |
||
932 | |||
933 | public function testGetSecurityInformation(): void |
||
934 | { |
||
935 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
936 | |||
937 | $this->assertSame([], $admin->getSecurityInformation()); |
||
938 | |||
939 | $securityInformation = [ |
||
940 | 'GUEST' => ['VIEW', 'LIST'], |
||
941 | 'STAFF' => ['EDIT', 'LIST', 'CREATE'], |
||
942 | ]; |
||
943 | |||
944 | $admin->setSecurityInformation($securityInformation); |
||
945 | $this->assertSame($securityInformation, $admin->getSecurityInformation()); |
||
946 | } |
||
947 | |||
948 | public function testGetManagerType(): void |
||
949 | { |
||
950 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
951 | |||
952 | $this->assertNull($admin->getManagerType()); |
||
953 | |||
954 | $admin->setManagerType('foo_orm'); |
||
955 | $this->assertSame('foo_orm', $admin->getManagerType()); |
||
956 | } |
||
957 | |||
958 | public function testGetModelManager(): void |
||
959 | { |
||
960 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
961 | |||
962 | $this->assertNull($admin->getModelManager()); |
||
963 | |||
964 | $modelManager = $this->createMock(ModelManagerInterface::class); |
||
965 | |||
966 | $admin->setModelManager($modelManager); |
||
967 | $this->assertSame($modelManager, $admin->getModelManager()); |
||
968 | } |
||
969 | |||
970 | /** |
||
971 | * NEXT_MAJOR: remove this method. |
||
972 | * |
||
973 | * @group legacy |
||
974 | */ |
||
975 | public function testGetBaseCodeRoute(): void |
||
976 | { |
||
977 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
978 | |||
979 | $this->assertSame('', $admin->getBaseCodeRoute()); |
||
980 | |||
981 | $admin->setBaseCodeRoute('foo'); |
||
982 | $this->assertSame('foo', $admin->getBaseCodeRoute()); |
||
983 | } |
||
984 | |||
985 | // NEXT_MAJOR: uncomment this method. |
||
986 | // public function testGetBaseCodeRoute() |
||
987 | // { |
||
988 | // $postAdmin = new PostAdmin( |
||
989 | // 'sonata.post.admin.post', |
||
990 | // 'NewsBundle\Entity\Post', |
||
991 | // 'Sonata\NewsBundle\Controller\PostAdminController' |
||
992 | // ); |
||
993 | // $commentAdmin = new CommentAdmin( |
||
994 | // 'sonata.post.admin.comment', |
||
995 | // 'Application\Sonata\NewsBundle\Entity\Comment', |
||
996 | // 'Sonata\NewsBundle\Controller\CommentAdminController' |
||
997 | // ); |
||
998 | // |
||
999 | // $this->assertSame($postAdmin->getCode(), $postAdmin->getBaseCodeRoute()); |
||
1000 | // |
||
1001 | // $postAdmin->addChild($commentAdmin); |
||
1002 | // |
||
1003 | // $this->assertSame( |
||
1004 | // 'sonata.post.admin.post|sonata.post.admin.comment', |
||
1005 | // $commentAdmin->getBaseCodeRoute() |
||
1006 | // ); |
||
1007 | // } |
||
1008 | |||
1009 | public function testGetRouteGenerator(): void |
||
1010 | { |
||
1011 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1012 | |||
1013 | $this->assertNull($admin->getRouteGenerator()); |
||
1014 | |||
1015 | $routeGenerator = $this->createMock(RouteGeneratorInterface::class); |
||
1016 | |||
1017 | $admin->setRouteGenerator($routeGenerator); |
||
1018 | $this->assertSame($routeGenerator, $admin->getRouteGenerator()); |
||
1019 | } |
||
1020 | |||
1021 | public function testGetConfigurationPool(): void |
||
1022 | { |
||
1023 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1024 | |||
1025 | $this->assertNull($admin->getConfigurationPool()); |
||
1026 | |||
1027 | $pool = $this->getMockBuilder(Pool::class) |
||
1028 | ->disableOriginalConstructor() |
||
1029 | ->getMock(); |
||
1030 | |||
1031 | $admin->setConfigurationPool($pool); |
||
1032 | $this->assertSame($pool, $admin->getConfigurationPool()); |
||
1033 | } |
||
1034 | |||
1035 | public function testGetShowBuilder(): void |
||
1036 | { |
||
1037 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1038 | |||
1039 | $this->assertNull($admin->getShowBuilder()); |
||
1040 | |||
1041 | $showBuilder = $this->createMock(ShowBuilderInterface::class); |
||
1042 | |||
1043 | $admin->setShowBuilder($showBuilder); |
||
1044 | $this->assertSame($showBuilder, $admin->getShowBuilder()); |
||
1045 | } |
||
1046 | |||
1047 | public function testGetListBuilder(): void |
||
1048 | { |
||
1049 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1050 | |||
1051 | $this->assertNull($admin->getListBuilder()); |
||
1052 | |||
1053 | $listBuilder = $this->createMock(ListBuilderInterface::class); |
||
1054 | |||
1055 | $admin->setListBuilder($listBuilder); |
||
1056 | $this->assertSame($listBuilder, $admin->getListBuilder()); |
||
1057 | } |
||
1058 | |||
1059 | public function testGetDatagridBuilder(): void |
||
1060 | { |
||
1061 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1062 | |||
1063 | $this->assertNull($admin->getDatagridBuilder()); |
||
1064 | |||
1065 | $datagridBuilder = $this->createMock(DatagridBuilderInterface::class); |
||
1066 | |||
1067 | $admin->setDatagridBuilder($datagridBuilder); |
||
1068 | $this->assertSame($datagridBuilder, $admin->getDatagridBuilder()); |
||
1069 | } |
||
1070 | |||
1071 | public function testGetFormContractor(): void |
||
1072 | { |
||
1073 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1074 | |||
1075 | $this->assertNull($admin->getFormContractor()); |
||
1076 | |||
1077 | $formContractor = $this->createMock(FormContractorInterface::class); |
||
1078 | |||
1079 | $admin->setFormContractor($formContractor); |
||
1080 | $this->assertSame($formContractor, $admin->getFormContractor()); |
||
1081 | } |
||
1082 | |||
1083 | public function testGetRequest(): void |
||
1084 | { |
||
1085 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1086 | |||
1087 | $this->assertFalse($admin->hasRequest()); |
||
1088 | |||
1089 | $request = new Request(); |
||
1090 | |||
1091 | $admin->setRequest($request); |
||
1092 | $this->assertSame($request, $admin->getRequest()); |
||
1093 | $this->assertTrue($admin->hasRequest()); |
||
1094 | } |
||
1095 | |||
1096 | public function testGetRequestWithException(): void |
||
1097 | { |
||
1098 | $this->expectException(\RuntimeException::class); |
||
1099 | $this->expectExceptionMessage('The Request object has not been set'); |
||
1100 | |||
1101 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1102 | $admin->getRequest(); |
||
1103 | } |
||
1104 | |||
1105 | public function testGetTranslationDomain(): void |
||
1106 | { |
||
1107 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1108 | |||
1109 | $this->assertSame('messages', $admin->getTranslationDomain()); |
||
1110 | |||
1111 | $admin->setTranslationDomain('foo'); |
||
1112 | $this->assertSame('foo', $admin->getTranslationDomain()); |
||
1113 | } |
||
1114 | |||
1115 | /** |
||
1116 | * @group legacy |
||
1117 | */ |
||
1118 | public function testGetTranslator(): void |
||
1119 | { |
||
1120 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1121 | |||
1122 | $this->assertNull($admin->getTranslator()); |
||
1123 | |||
1124 | $translator = $this->createMock(TranslatorInterface::class); |
||
1125 | |||
1126 | $admin->setTranslator($translator); |
||
1127 | $this->assertSame($translator, $admin->getTranslator()); |
||
1128 | } |
||
1129 | |||
1130 | public function testGetShowGroups(): void |
||
1131 | { |
||
1132 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1133 | |||
1134 | $this->assertFalse($admin->getShowGroups()); |
||
1135 | |||
1136 | $groups = ['foo', 'bar', 'baz']; |
||
1137 | |||
1138 | $admin->setShowGroups($groups); |
||
1139 | $this->assertSame($groups, $admin->getShowGroups()); |
||
1140 | } |
||
1141 | |||
1142 | public function testGetFormGroups(): void |
||
1143 | { |
||
1144 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1145 | |||
1146 | $this->assertFalse($admin->getFormGroups()); |
||
1147 | |||
1148 | $groups = ['foo', 'bar', 'baz']; |
||
1149 | |||
1150 | $admin->setFormGroups($groups); |
||
1151 | $this->assertSame($groups, $admin->getFormGroups()); |
||
1152 | } |
||
1153 | |||
1154 | public function testGetMaxPageLinks(): void |
||
1155 | { |
||
1156 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1157 | |||
1158 | $this->assertSame(25, $admin->getMaxPageLinks()); |
||
1159 | |||
1160 | $admin->setMaxPageLinks(14); |
||
1161 | $this->assertSame(14, $admin->getMaxPageLinks()); |
||
1162 | } |
||
1163 | |||
1164 | public function testGetMaxPerPage(): void |
||
1165 | { |
||
1166 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1167 | |||
1168 | $this->assertSame(32, $admin->getMaxPerPage()); |
||
1169 | |||
1170 | $admin->setMaxPerPage(94); |
||
1171 | $this->assertSame(94, $admin->getMaxPerPage()); |
||
1172 | } |
||
1173 | |||
1174 | public function testGetLabel(): void |
||
1175 | { |
||
1176 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1177 | |||
1178 | $this->assertNull($admin->getLabel()); |
||
1179 | |||
1180 | $admin->setLabel('FooLabel'); |
||
1181 | $this->assertSame('FooLabel', $admin->getLabel()); |
||
1182 | } |
||
1183 | |||
1184 | public function testGetBaseController(): void |
||
1185 | { |
||
1186 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1187 | |||
1188 | $this->assertSame('Sonata\NewsBundle\Controller\PostAdminController', $admin->getBaseControllerName()); |
||
1189 | |||
1190 | $admin->setBaseControllerName('Sonata\NewsBundle\Controller\FooAdminController'); |
||
1191 | $this->assertSame('Sonata\NewsBundle\Controller\FooAdminController', $admin->getBaseControllerName()); |
||
1192 | } |
||
1193 | |||
1194 | public function testGetTemplates(): void |
||
1195 | { |
||
1196 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1197 | |||
1198 | $templates = [ |
||
1199 | 'list' => '@FooAdmin/CRUD/list.html.twig', |
||
1200 | 'show' => '@FooAdmin/CRUD/show.html.twig', |
||
1201 | 'edit' => '@FooAdmin/CRUD/edit.html.twig', |
||
1202 | ]; |
||
1203 | |||
1204 | $templateRegistry = $this->prophesize(MutableTemplateRegistryInterface::class); |
||
1205 | $templateRegistry->getTemplates()->shouldBeCalled()->willReturn($templates); |
||
1206 | |||
1207 | $admin->setTemplateRegistry($templateRegistry->reveal()); |
||
1208 | |||
1209 | $this->assertSame($templates, $admin->getTemplates()); |
||
1210 | } |
||
1211 | |||
1212 | public function testGetTemplate1(): void |
||
1213 | { |
||
1214 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1215 | |||
1216 | $templateRegistry = $this->prophesize(MutableTemplateRegistryInterface::class); |
||
1217 | $templateRegistry->getTemplate('edit')->shouldBeCalled()->willReturn('@FooAdmin/CRUD/edit.html.twig'); |
||
1218 | $templateRegistry->getTemplate('show')->shouldBeCalled()->willReturn('@FooAdmin/CRUD/show.html.twig'); |
||
1219 | |||
1220 | $admin->setTemplateRegistry($templateRegistry->reveal()); |
||
1221 | |||
1222 | $this->assertSame('@FooAdmin/CRUD/edit.html.twig', $admin->getTemplate('edit')); |
||
1223 | $this->assertSame('@FooAdmin/CRUD/show.html.twig', $admin->getTemplate('show')); |
||
1224 | } |
||
1225 | |||
1226 | public function testGetIdParameter(): void |
||
1227 | { |
||
1228 | $postAdmin = new PostAdmin( |
||
1229 | 'sonata.post.admin.post', |
||
1230 | 'NewsBundle\Entity\Post', |
||
1231 | 'Sonata\NewsBundle\Controller\PostAdminController' |
||
1232 | ); |
||
1233 | |||
1234 | $this->assertSame('id', $postAdmin->getIdParameter()); |
||
1235 | $this->assertFalse($postAdmin->isChild()); |
||
1236 | |||
1237 | $commentAdmin = new CommentAdmin( |
||
1238 | 'sonata.post.admin.comment', |
||
1239 | 'Application\Sonata\NewsBundle\Entity\Comment', |
||
1240 | 'Sonata\NewsBundle\Controller\CommentAdminController' |
||
1241 | ); |
||
1242 | $commentAdmin->setParent($postAdmin); |
||
1243 | |||
1244 | $this->assertTrue($commentAdmin->isChild()); |
||
1245 | $this->assertSame('childId', $commentAdmin->getIdParameter()); |
||
1246 | |||
1247 | $commentVoteAdmin = new CommentVoteAdmin( |
||
1248 | 'sonata.post.admin.comment_vote', |
||
1249 | 'Application\Sonata\NewsBundle\Entity\CommentVote', |
||
1250 | 'Sonata\NewsBundle\Controller\CommentVoteAdminController' |
||
1251 | ); |
||
1252 | $commentVoteAdmin->setParent($commentAdmin); |
||
1253 | |||
1254 | $this->assertTrue($commentVoteAdmin->isChild()); |
||
1255 | $this->assertSame('childChildId', $commentVoteAdmin->getIdParameter()); |
||
1256 | } |
||
1257 | |||
1258 | public function testGetExportFormats(): void |
||
1259 | { |
||
1260 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1261 | |||
1262 | $this->assertSame(['json', 'xml', 'csv', 'xls'], $admin->getExportFormats()); |
||
1263 | } |
||
1264 | |||
1265 | public function testGetUrlsafeIdentifier(): void |
||
1266 | { |
||
1267 | $admin = new PostAdmin('sonata.post.admin.post', 'Acme\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1268 | |||
1269 | $entity = new \stdClass(); |
||
1270 | |||
1271 | $modelManager = $this->createMock(ModelManagerInterface::class); |
||
1272 | $modelManager->expects($this->once()) |
||
1273 | ->method('getUrlsafeIdentifier') |
||
1274 | ->with($this->equalTo($entity)) |
||
1275 | ->willReturn('foo'); |
||
1276 | $admin->setModelManager($modelManager); |
||
1277 | |||
1278 | $this->assertSame('foo', $admin->getUrlsafeIdentifier($entity)); |
||
1279 | } |
||
1280 | |||
1281 | public function testDeterminedPerPageValue(): void |
||
1282 | { |
||
1283 | $admin = new PostAdmin('sonata.post.admin.post', 'Acme\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1284 | |||
1285 | $this->assertFalse($admin->determinedPerPageValue('foo')); |
||
1286 | $this->assertFalse($admin->determinedPerPageValue(123)); |
||
1287 | $this->assertTrue($admin->determinedPerPageValue(16)); |
||
1288 | |||
1289 | $admin->setPerPageOptions([101, 102, 103]); |
||
1290 | $this->assertFalse($admin->determinedPerPageValue(16)); |
||
1291 | $this->assertTrue($admin->determinedPerPageValue(101)); |
||
1292 | } |
||
1293 | |||
1294 | public function testIsGranted(): void |
||
1295 | { |
||
1296 | $admin = new PostAdmin('sonata.post.admin.post', 'Acme\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1297 | $modelManager = $this->createStub(ModelManagerInterface::class); |
||
1298 | $modelManager |
||
1299 | ->method('getNormalizedIdentifier') |
||
1300 | ->willReturnCallback(static function (?object $entity = null): ?string { |
||
1301 | return $entity ? $entity->id : null; |
||
1302 | }); |
||
1303 | |||
1304 | $admin->setModelManager($modelManager); |
||
1305 | |||
1306 | $entity1 = new \stdClass(); |
||
1307 | $entity1->id = '1'; |
||
1308 | |||
1309 | $securityHandler = $this->createMock(AclSecurityHandlerInterface::class); |
||
1310 | $securityHandler |
||
1311 | ->expects($this->exactly(6)) |
||
1312 | ->method('isGranted') |
||
1313 | ->willReturnCallback(static function ( |
||
1314 | AdminInterface $adminIn, |
||
1315 | string $attributes, |
||
1316 | ?object $object = null |
||
1317 | ) use ( |
||
1318 | $admin, |
||
1319 | $entity1 |
||
1320 | ): bool { |
||
1321 | return $admin === $adminIn && 'FOO' === $attributes && |
||
1322 | ($object === $admin || $object === $entity1); |
||
1323 | }); |
||
1324 | |||
1325 | $admin->setSecurityHandler($securityHandler); |
||
1326 | |||
1327 | $this->assertTrue($admin->isGranted('FOO')); |
||
1328 | $this->assertTrue($admin->isGranted('FOO')); |
||
1329 | $this->assertTrue($admin->isGranted('FOO', $entity1)); |
||
1330 | $this->assertTrue($admin->isGranted('FOO', $entity1)); |
||
1331 | $this->assertFalse($admin->isGranted('BAR')); |
||
1332 | $this->assertFalse($admin->isGranted('BAR')); |
||
1333 | $this->assertFalse($admin->isGranted('BAR', $entity1)); |
||
1334 | $this->assertFalse($admin->isGranted('BAR', $entity1)); |
||
1335 | |||
1336 | $entity2 = new \stdClass(); |
||
1337 | $entity2->id = '2'; |
||
1338 | |||
1339 | $this->assertFalse($admin->isGranted('BAR', $entity2)); |
||
1340 | $this->assertFalse($admin->isGranted('BAR', $entity2)); |
||
1341 | |||
1342 | $entity3 = new \stdClass(); |
||
1343 | $entity3->id = '3'; |
||
1344 | |||
1345 | $this->assertFalse($admin->isGranted('BAR', $entity3)); |
||
1346 | $this->assertFalse($admin->isGranted('BAR', $entity3)); |
||
1347 | } |
||
1348 | |||
1349 | public function testSupportsPreviewMode(): void |
||
1350 | { |
||
1351 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1352 | |||
1353 | $this->assertFalse($admin->supportsPreviewMode()); |
||
1354 | } |
||
1355 | |||
1356 | public function testGetPermissionsShow(): void |
||
1357 | { |
||
1358 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1359 | |||
1360 | $this->assertSame(['LIST'], $admin->getPermissionsShow(AbstractAdmin::CONTEXT_DASHBOARD)); |
||
1361 | $this->assertSame(['LIST'], $admin->getPermissionsShow(AbstractAdmin::CONTEXT_MENU)); |
||
1362 | $this->assertSame(['LIST'], $admin->getPermissionsShow('foo')); |
||
1363 | } |
||
1364 | |||
1365 | public function testShowIn(): void |
||
1366 | { |
||
1367 | $admin = new PostAdmin('sonata.post.admin.post', 'Acme\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1368 | |||
1369 | $securityHandler = $this->createMock(AclSecurityHandlerInterface::class); |
||
1370 | $securityHandler |
||
1371 | ->method('isGranted') |
||
1372 | ->willReturnCallback(static function (AdminInterface $adminIn, array $attributes, $object = null) use ($admin): bool { |
||
1373 | return $admin === $adminIn && $attributes === ['LIST']; |
||
1374 | }); |
||
1375 | |||
1376 | $admin->setSecurityHandler($securityHandler); |
||
1377 | |||
1378 | $this->assertTrue($admin->showIn(AbstractAdmin::CONTEXT_DASHBOARD)); |
||
1379 | $this->assertTrue($admin->showIn(AbstractAdmin::CONTEXT_MENU)); |
||
1380 | $this->assertTrue($admin->showIn('foo')); |
||
1381 | } |
||
1382 | |||
1383 | public function testGetObjectIdentifier(): void |
||
1389 | |||
1390 | /** |
||
1391 | * @group legacy |
||
1392 | */ |
||
1393 | public function testTrans(): void |
||
1408 | |||
1409 | /** |
||
1410 | * @group legacy |
||
1411 | */ |
||
1412 | public function testTransWithMessageDomain(): void |
||
1426 | |||
1427 | /** |
||
1428 | * @group legacy |
||
1429 | */ |
||
1430 | public function testTransChoice(): void |
||
1445 | |||
1446 | /** |
||
1447 | * @group legacy |
||
1448 | */ |
||
1449 | public function testTransChoiceWithMessageDomain(): void |
||
1463 | |||
1464 | public function testSetFilterPersister(): void |
||
1465 | { |
||
1466 | $admin = new class('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle\Controller\PostAdminController') extends PostAdmin { |
||
1467 | public function persistFilters(): bool |
||
1468 | { |
||
1469 | return $this->persistFilters; |
||
1470 | } |
||
1471 | }; |
||
1472 | |||
1473 | $filterPersister = $this->createMock(FilterPersisterInterface::class); |
||
1474 | |||
1475 | $admin->setFilterPersister($filterPersister); |
||
1476 | $this->assertTrue($admin->persistFilters()); |
||
1477 | } |
||
1478 | |||
1479 | public function testGetRootCode(): void |
||
1480 | { |
||
1481 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1482 | |||
1483 | $this->assertSame('sonata.post.admin.post', $admin->getRootCode()); |
||
1484 | |||
1485 | $parentAdmin = new PostAdmin('sonata.post.admin.post.parent', 'NewsBundle\Entity\PostParent', 'Sonata\NewsBundle\Controller\PostParentAdminController'); |
||
1486 | $parentFieldDescription = $this->createMock(FieldDescriptionInterface::class); |
||
1487 | $parentFieldDescription->expects($this->once()) |
||
1488 | ->method('getAdmin') |
||
1489 | ->willReturn($parentAdmin); |
||
1490 | |||
1491 | $this->assertNull($admin->getParentFieldDescription()); |
||
1492 | $admin->setParentFieldDescription($parentFieldDescription); |
||
1493 | $this->assertSame($parentFieldDescription, $admin->getParentFieldDescription()); |
||
1494 | $this->assertSame('sonata.post.admin.post.parent', $admin->getRootCode()); |
||
1495 | } |
||
1496 | |||
1497 | public function testGetRoot(): void |
||
1498 | { |
||
1499 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1500 | |||
1501 | $this->assertSame($admin, $admin->getRoot()); |
||
1502 | |||
1503 | $parentAdmin = new PostAdmin('sonata.post.admin.post.parent', 'NewsBundle\Entity\PostParent', 'Sonata\NewsBundle\Controller\PostParentAdminController'); |
||
1504 | $parentFieldDescription = $this->createMock(FieldDescriptionInterface::class); |
||
1505 | $parentFieldDescription->expects($this->once()) |
||
1506 | ->method('getAdmin') |
||
1507 | ->willReturn($parentAdmin); |
||
1508 | |||
1509 | $this->assertNull($admin->getParentFieldDescription()); |
||
1510 | $admin->setParentFieldDescription($parentFieldDescription); |
||
1511 | $this->assertSame($parentFieldDescription, $admin->getParentFieldDescription()); |
||
1512 | $this->assertSame($parentAdmin, $admin->getRoot()); |
||
1513 | } |
||
1514 | |||
1515 | public function testGetExportFields(): void |
||
1516 | { |
||
1517 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1518 | |||
1519 | $modelManager = $this->createMock(ModelManagerInterface::class); |
||
1520 | $modelManager->expects($this->once()) |
||
1521 | ->method('getExportFields') |
||
1522 | ->with($this->equalTo('NewsBundle\Entity\Post')) |
||
1523 | ->willReturn(['foo', 'bar']); |
||
1524 | |||
1525 | $admin->setModelManager($modelManager); |
||
1526 | $this->assertSame(['foo', 'bar'], $admin->getExportFields()); |
||
1527 | } |
||
1528 | |||
1529 | public function testGetPersistentParametersWithNoExtension(): void |
||
1530 | { |
||
1531 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1532 | |||
1533 | $this->assertEmpty($admin->getPersistentParameters()); |
||
1534 | } |
||
1535 | |||
1536 | public function testGetPersistentParametersWithInvalidExtension(): void |
||
1537 | { |
||
1538 | $this->expectException(\RuntimeException::class); |
||
1539 | |||
1540 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1541 | |||
1542 | $extension = $this->createMock(AdminExtensionInterface::class); |
||
1543 | $extension->expects($this->once())->method('getPersistentParameters')->willReturn(null); |
||
1544 | |||
1545 | $admin->addExtension($extension); |
||
1546 | |||
1547 | $admin->getPersistentParameters(); |
||
1548 | } |
||
1549 | |||
1550 | public function testGetPersistentParametersWithValidExtension(): void |
||
1551 | { |
||
1552 | $expected = [ |
||
1553 | 'context' => 'foobar', |
||
1554 | ]; |
||
1555 | |||
1556 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1557 | |||
1558 | $extension = $this->createMock(AdminExtensionInterface::class); |
||
1559 | $extension->expects($this->once())->method('getPersistentParameters')->willReturn($expected); |
||
1560 | |||
1561 | $admin->addExtension($extension); |
||
1562 | |||
1563 | $this->assertSame($expected, $admin->getPersistentParameters()); |
||
1564 | } |
||
1565 | |||
1566 | public function testGetFormWithNonCollectionParentValue(): void |
||
1567 | { |
||
1568 | $post = new Post(); |
||
1569 | $tagAdmin = $this->createTagAdmin($post); |
||
1570 | $tag = $tagAdmin->getSubject(); |
||
1571 | |||
1572 | $tag->setPosts(null); |
||
1573 | $tagAdmin->getForm(); |
||
1574 | $this->assertSame($post, $tag->getPosts()); |
||
1575 | } |
||
1576 | |||
1577 | public function testGetFormWithCollectionParentValue(): void |
||
1578 | { |
||
1579 | $post = new Post(); |
||
1580 | $tagAdmin = $this->createTagAdmin($post); |
||
1581 | $tag = $tagAdmin->getSubject(); |
||
1582 | |||
1583 | // Case of a doctrine collection |
||
1584 | $this->assertInstanceOf(Collection::class, $tag->getPosts()); |
||
1585 | $this->assertCount(0, $tag->getPosts()); |
||
1586 | |||
1587 | $tag->addPost(new Post()); |
||
1588 | |||
1589 | $this->assertCount(1, $tag->getPosts()); |
||
1590 | |||
1591 | $tagAdmin->getForm(); |
||
1592 | |||
1593 | $this->assertInstanceOf(Collection::class, $tag->getPosts()); |
||
1594 | $this->assertCount(2, $tag->getPosts()); |
||
1595 | $this->assertContains($post, $tag->getPosts()); |
||
1596 | |||
1597 | // Case of an array |
||
1598 | $tag->setPosts([]); |
||
1599 | $this->assertCount(0, $tag->getPosts()); |
||
1600 | |||
1601 | $tag->addPost(new Post()); |
||
1602 | |||
1603 | $this->assertCount(1, $tag->getPosts()); |
||
1604 | |||
1605 | $tagAdmin->getForm(); |
||
1606 | |||
1607 | $this->assertIsArray($tag->getPosts()); |
||
1608 | $this->assertCount(2, $tag->getPosts()); |
||
1609 | $this->assertContains($post, $tag->getPosts()); |
||
1610 | } |
||
1611 | |||
1612 | public function testFormAddPostSubmitEventForPreValidation(): void |
||
1613 | { |
||
1614 | $modelAdmin = new ModelAdmin('sonata.post.admin.model', 'Application\Sonata\FooBundle\Entity\Model', 'Sonata\FooBundle\Controller\ModelAdminController'); |
||
1615 | $object = new \stdClass(); |
||
1616 | |||
1617 | $labelTranslatorStrategy = $this->createMock(LabelTranslatorStrategyInterface::class); |
||
1618 | $modelAdmin->setLabelTranslatorStrategy($labelTranslatorStrategy); |
||
1619 | |||
1620 | $validator = $this->createMock(ValidatorInterface::class); |
||
1621 | $validator |
||
1622 | ->method('getMetadataFor') |
||
1623 | ->willReturn($this->createMock(MemberMetadata::class)); |
||
1624 | $modelAdmin->setValidator($validator); |
||
1625 | |||
1626 | $modelManager = $this->createMock(ModelManagerInterface::class); |
||
1627 | $modelManager |
||
1628 | ->method('getNewFieldDescriptionInstance') |
||
1629 | ->willReturn(new FieldDescription()); |
||
1630 | $modelAdmin->setModelManager($modelManager); |
||
1631 | |||
1632 | // a Admin class to test that preValidate is called |
||
1633 | $testAdminPreValidate = $this->createMock(AbstractAdmin::class); |
||
1634 | $testAdminPreValidate->expects($this->once()) |
||
1635 | ->method('preValidate') |
||
1636 | ->with($this->identicalTo($object)); |
||
1637 | |||
1638 | $event = $this->createMock(FormEvent::class); |
||
1639 | $event |
||
1640 | ->method('getData') |
||
1641 | ->willReturn($object); |
||
1642 | |||
1643 | $formBuild = $this->createMock(FormBuilder::class); |
||
1644 | $formBuild->expects($this->once()) |
||
1645 | ->method('addEventListener') |
||
1646 | ->with( |
||
1647 | $this->identicalTo(FormEvents::POST_SUBMIT), |
||
1648 | $this->callback(static function ($callback) use ($testAdminPreValidate, $event): bool { |
||
1649 | if (\is_callable($callback)) { |
||
1650 | $closure = $callback->bindTo($testAdminPreValidate); |
||
1651 | $closure($event); |
||
1652 | |||
1653 | return true; |
||
1654 | } |
||
1655 | |||
1656 | return false; |
||
1657 | }), |
||
1658 | $this->greaterThan(0) |
||
1659 | ); |
||
1660 | |||
1661 | $formContractor = $this->createMock(FormContractorInterface::class); |
||
1662 | $formContractor |
||
1663 | ->method('getDefaultOptions') |
||
1664 | ->willReturn([]); |
||
1665 | $formContractor |
||
1666 | ->method('getFormBuilder') |
||
1667 | ->willReturn($formBuild); |
||
1668 | |||
1669 | $modelAdmin->setFormContractor($formContractor); |
||
1670 | $modelAdmin->defineFormBuilder($formBuild); |
||
1671 | $modelAdmin->getForm(); |
||
1672 | } |
||
1673 | |||
1674 | public function testRemoveFieldFromFormGroup(): void |
||
1675 | { |
||
1676 | $formGroups = [ |
||
1677 | 'foobar' => [ |
||
1678 | 'fields' => [ |
||
1679 | 'foo' => 'foo', |
||
1680 | 'bar' => 'bar', |
||
1681 | ], |
||
1682 | ], |
||
1683 | ]; |
||
1684 | |||
1685 | $admin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1686 | $admin->setFormGroups($formGroups); |
||
1687 | |||
1688 | $admin->removeFieldFromFormGroup('foo'); |
||
1689 | $this->assertSame($admin->getFormGroups(), [ |
||
1690 | 'foobar' => [ |
||
1691 | 'fields' => [ |
||
1692 | 'bar' => 'bar', |
||
1693 | ], |
||
1694 | ], |
||
1695 | ]); |
||
1696 | |||
1697 | $admin->removeFieldFromFormGroup('bar'); |
||
1698 | $this->assertSame($admin->getFormGroups(), []); |
||
1699 | } |
||
1700 | |||
1701 | public function testGetFilterParameters(): void |
||
1702 | { |
||
1703 | $authorId = uniqid(); |
||
1704 | |||
1705 | $postAdmin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1706 | |||
1707 | $commentAdmin = new CommentAdmin('sonata.post.admin.comment', 'Application\Sonata\NewsBundle\Entity\Comment', 'Sonata\NewsBundle\Controller\CommentAdminController'); |
||
1708 | $commentAdmin->setParentAssociationMapping('post.author'); |
||
1709 | $commentAdmin->setParent($postAdmin); |
||
1710 | |||
1711 | $request = $this->createMock(Request::class); |
||
1712 | $query = $this->createMock(ParameterBag::class); |
||
1713 | $query |
||
1714 | ->method('get') |
||
1715 | ->willReturn([ |
||
1716 | 'filter' => [ |
||
1717 | '_page' => '1', |
||
1718 | '_per_page' => '32', |
||
1719 | ], |
||
1720 | ]); |
||
1721 | |||
1722 | $request->query = $query; |
||
1723 | $request |
||
1724 | ->method('get') |
||
1725 | ->willReturn($authorId); |
||
1726 | |||
1727 | $commentAdmin->setRequest($request); |
||
1728 | |||
1729 | $modelManager = $this->createMock(ModelManagerInterface::class); |
||
1730 | $modelManager |
||
1731 | ->method('getDefaultSortValues') |
||
1732 | ->willReturn([]); |
||
1733 | |||
1734 | $commentAdmin->setModelManager($modelManager); |
||
1735 | |||
1736 | $parameters = $commentAdmin->getFilterParameters(); |
||
1737 | |||
1738 | $this->assertTrue(isset($parameters['post__author'])); |
||
1739 | $this->assertSame(['value' => $authorId], $parameters['post__author']); |
||
1740 | } |
||
1741 | |||
1742 | public function testGetFilterFieldDescription(): void |
||
1743 | { |
||
1744 | $modelAdmin = new ModelAdmin('sonata.post.admin.model', 'Application\Sonata\FooBundle\Entity\Model', 'Sonata\FooBundle\Controller\ModelAdminController'); |
||
1745 | |||
1746 | $fooFieldDescription = new FieldDescription(); |
||
1747 | $barFieldDescription = new FieldDescription(); |
||
1748 | $bazFieldDescription = new FieldDescription(); |
||
1749 | |||
1750 | $modelManager = $this->createMock(ModelManagerInterface::class); |
||
1751 | $modelManager->expects($this->exactly(3)) |
||
1752 | ->method('getNewFieldDescriptionInstance') |
||
1753 | ->willReturnCallback(static function ($adminClass, string $name, $filterOptions) use ($fooFieldDescription, $barFieldDescription, $bazFieldDescription) { |
||
1754 | switch ($name) { |
||
1755 | case 'foo': |
||
1756 | $fieldDescription = $fooFieldDescription; |
||
1757 | |||
1758 | break; |
||
1759 | |||
1760 | case 'bar': |
||
1761 | $fieldDescription = $barFieldDescription; |
||
1762 | |||
1763 | break; |
||
1764 | |||
1765 | case 'baz': |
||
1766 | $fieldDescription = $bazFieldDescription; |
||
1767 | |||
1768 | break; |
||
1769 | |||
1770 | default: |
||
1771 | throw new \RuntimeException(sprintf('Unknown filter name "%s"', $name)); |
||
1772 | break; |
||
1773 | } |
||
1774 | |||
1775 | $fieldDescription->setName($name); |
||
1776 | |||
1777 | return $fieldDescription; |
||
1778 | }); |
||
1779 | |||
1780 | $modelAdmin->setModelManager($modelManager); |
||
1781 | |||
1782 | $pager = $this->createMock(PagerInterface::class); |
||
1783 | |||
1784 | $datagrid = $this->createMock(DatagridInterface::class); |
||
1785 | $datagrid->expects($this->once()) |
||
1786 | ->method('getPager') |
||
1787 | ->willReturn($pager); |
||
1788 | |||
1789 | $datagridBuilder = $this->createMock(DatagridBuilderInterface::class); |
||
1790 | $datagridBuilder->expects($this->once()) |
||
1791 | ->method('getBaseDatagrid') |
||
1792 | ->with($this->identicalTo($modelAdmin), []) |
||
1793 | ->willReturn($datagrid); |
||
1794 | |||
1795 | $datagridBuilder->expects($this->exactly(3)) |
||
1796 | ->method('addFilter') |
||
1797 | ->willReturnCallback(static function ($datagrid, $type, $fieldDescription, AdminInterface $admin): void { |
||
1798 | $admin->addFilterFieldDescription($fieldDescription->getName(), $fieldDescription); |
||
1799 | $fieldDescription->mergeOption('field_options', ['required' => false]); |
||
1800 | }); |
||
1801 | |||
1802 | $modelAdmin->setDatagridBuilder($datagridBuilder); |
||
1803 | |||
1804 | $this->assertSame(['foo' => $fooFieldDescription, 'bar' => $barFieldDescription, 'baz' => $bazFieldDescription], $modelAdmin->getFilterFieldDescriptions()); |
||
1805 | $this->assertFalse($modelAdmin->hasFilterFieldDescription('fooBar')); |
||
1806 | $this->assertTrue($modelAdmin->hasFilterFieldDescription('foo')); |
||
1807 | $this->assertTrue($modelAdmin->hasFilterFieldDescription('bar')); |
||
1808 | $this->assertTrue($modelAdmin->hasFilterFieldDescription('baz')); |
||
1809 | $this->assertSame($fooFieldDescription, $modelAdmin->getFilterFieldDescription('foo')); |
||
1810 | $this->assertSame($barFieldDescription, $modelAdmin->getFilterFieldDescription('bar')); |
||
1811 | $this->assertSame($bazFieldDescription, $modelAdmin->getFilterFieldDescription('baz')); |
||
1812 | } |
||
1813 | |||
1814 | public function testGetSubjectNoRequest(): void |
||
1815 | { |
||
1816 | $modelManager = $this->createMock(ModelManagerInterface::class); |
||
1817 | $modelManager |
||
1818 | ->expects($this->never()) |
||
1819 | ->method('find'); |
||
1820 | |||
1821 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1822 | $admin->setModelManager($modelManager); |
||
1823 | |||
1824 | $this->assertNull($admin->getSubject()); |
||
1825 | } |
||
1826 | |||
1827 | public function testGetSideMenu(): void |
||
1828 | { |
||
1829 | $item = $this->createMock(ItemInterface::class); |
||
1830 | $item |
||
1831 | ->expects($this->once()) |
||
1832 | ->method('setChildrenAttribute') |
||
1833 | ->with('class', 'nav navbar-nav'); |
||
1834 | $item |
||
1835 | ->expects($this->once()) |
||
1836 | ->method('setExtra') |
||
1837 | ->with('translation_domain', 'foo_bar_baz'); |
||
1838 | |||
1839 | $menuFactory = $this->createMock(FactoryInterface::class); |
||
1840 | $menuFactory |
||
1841 | ->expects($this->once()) |
||
1842 | ->method('createItem') |
||
1843 | ->willReturn($item); |
||
1844 | |||
1845 | $modelAdmin = new ModelAdmin('sonata.post.admin.model', 'Application\Sonata\FooBundle\Entity\Model', 'Sonata\FooBundle\Controller\ModelAdminController'); |
||
1846 | $modelAdmin->setMenuFactory($menuFactory); |
||
1847 | $modelAdmin->setTranslationDomain('foo_bar_baz'); |
||
1848 | |||
1849 | $modelAdmin->getSideMenu('foo'); |
||
1850 | } |
||
1851 | |||
1852 | /** |
||
1853 | * @return array |
||
1854 | */ |
||
1855 | public function provideGetSubject() |
||
1856 | { |
||
1857 | return [ |
||
1858 | [23], |
||
1859 | ['azerty'], |
||
1860 | ['4f69bbb5f14a13347f000092'], |
||
1861 | ['0779ca8d-e2be-11e4-ac58-0242ac11000b'], |
||
1862 | ['123'.AdapterInterface::ID_SEPARATOR.'my_type'], // composite keys are supported |
||
1863 | ]; |
||
1864 | } |
||
1865 | |||
1866 | /** |
||
1867 | * @dataProvider provideGetSubject |
||
1868 | */ |
||
1869 | public function testGetSubjectFailed($id): void |
||
1870 | { |
||
1871 | $modelManager = $this->createMock(ModelManagerInterface::class); |
||
1872 | $modelManager |
||
1873 | ->expects($this->once()) |
||
1874 | ->method('find') |
||
1875 | ->with('NewsBundle\Entity\Post', $id) |
||
1876 | ->willReturn(null); // entity not found |
||
1877 | |||
1878 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1879 | $admin->setModelManager($modelManager); |
||
1880 | |||
1881 | $admin->setRequest(new Request(['id' => $id])); |
||
1882 | $this->assertNull($admin->getSubject()); |
||
1883 | } |
||
1884 | |||
1885 | /** |
||
1886 | * @dataProvider provideGetSubject |
||
1887 | */ |
||
1888 | public function testGetSubject($id): void |
||
1889 | { |
||
1890 | $entity = new Post(); |
||
1891 | |||
1892 | $modelManager = $this->createMock(ModelManagerInterface::class); |
||
1893 | $modelManager |
||
1894 | ->expects($this->once()) |
||
1895 | ->method('find') |
||
1896 | ->with('NewsBundle\Entity\Post', $id) |
||
1897 | ->willReturn($entity); |
||
1898 | |||
1899 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1900 | $admin->setModelManager($modelManager); |
||
1901 | |||
1902 | $admin->setRequest(new Request(['id' => $id])); |
||
1903 | $this->assertSame($entity, $admin->getSubject()); |
||
1904 | $this->assertSame($entity, $admin->getSubject()); // model manager must be used only once |
||
1905 | } |
||
1906 | |||
1907 | public function testGetSubjectWithParentDescription(): void |
||
1908 | { |
||
1909 | $adminId = 1; |
||
1910 | |||
1911 | $comment = new Comment(); |
||
1912 | |||
1913 | $modelManager = $this->createMock(ModelManagerInterface::class); |
||
1914 | $modelManager |
||
1915 | ->method('find') |
||
1916 | ->with('NewsBundle\Entity\Comment', $adminId) |
||
1917 | ->willReturn($comment); |
||
1918 | |||
1919 | $request = new Request(['id' => $adminId]); |
||
1920 | |||
1921 | $postAdmin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
1922 | $postAdmin->setRequest($request); |
||
1923 | |||
1924 | $commentAdmin = new CommentAdmin('sonata.post.admin.comment', 'NewsBundle\Entity\Comment', 'Sonata\NewsBundle\Controller\CommentAdminController'); |
||
1925 | $commentAdmin->setRequest($request); |
||
1926 | $commentAdmin->setModelManager($modelManager); |
||
1927 | |||
1928 | $this->assertSame($comment, $commentAdmin->getSubject()); |
||
1929 | |||
1930 | $commentAdmin->setSubject(null); |
||
1931 | $commentAdmin->setParentFieldDescription(new FieldDescription()); |
||
1932 | |||
1933 | $this->assertNull($commentAdmin->getSubject()); |
||
1934 | } |
||
1935 | |||
1936 | /** |
||
1937 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::configureActionButtons |
||
1938 | */ |
||
1939 | public function testGetActionButtonsList(): void |
||
1972 | |||
1973 | /** |
||
1974 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::configureActionButtons |
||
1975 | */ |
||
1976 | public function testGetActionButtonsListCreateDisabled(): void |
||
1990 | |||
1991 | /** |
||
1992 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::configureBatchActions |
||
1993 | */ |
||
1994 | public function testGetBatchActions(): void |
||
1995 | { |
||
1996 | $expected = [ |
||
1997 | 'delete' => [ |
||
1998 | 'label' => 'action_delete', |
||
1999 | 'translation_domain' => 'SonataAdminBundle', |
||
2000 | 'ask_confirmation' => true, // by default always true |
||
2001 | ], |
||
2002 | 'foo' => [ |
||
2003 | 'label' => 'action_foo', |
||
2004 | 'translation_domain' => 'SonataAdminBundle', |
||
2005 | ], |
||
2006 | 'bar' => [ |
||
2007 | 'label' => 'batch.label_bar', |
||
2008 | 'translation_domain' => 'SonataAdminBundle', |
||
2009 | ], |
||
2010 | 'baz' => [ |
||
2011 | 'label' => 'action_baz', |
||
2012 | 'translation_domain' => 'AcmeAdminBundle', |
||
2013 | ], |
||
2014 | ]; |
||
2015 | |||
2016 | $pathInfo = new PathInfoBuilder($this->createMock(AuditManagerInterface::class)); |
||
2017 | |||
2018 | $labelTranslatorStrategy = $this->createMock(LabelTranslatorStrategyInterface::class); |
||
2019 | $labelTranslatorStrategy |
||
2020 | ->method('getLabel') |
||
2021 | ->willReturnCallback(static function (string $label, string $context = '', string $type = ''): string { |
||
2022 | return $context.'.'.$type.'_'.$label; |
||
2023 | }); |
||
2024 | |||
2025 | $admin = new PostAdmin('sonata.post.admin.model', 'Application\Sonata\FooBundle\Entity\Model', 'Sonata\FooBundle\Controller\ModelAdminController'); |
||
2026 | $admin->setRouteBuilder($pathInfo); |
||
2027 | $admin->setTranslationDomain('SonataAdminBundle'); |
||
2028 | $admin->setLabelTranslatorStrategy($labelTranslatorStrategy); |
||
2029 | |||
2030 | $routeGenerator = $this->createMock(RouteGeneratorInterface::class); |
||
2031 | $routeGenerator |
||
2032 | ->expects($this->once()) |
||
2033 | ->method('hasAdminRoute') |
||
2034 | ->with($admin, 'delete') |
||
2035 | ->willReturn(true); |
||
2036 | $admin->setRouteGenerator($routeGenerator); |
||
2037 | |||
2038 | $securityHandler = $this->createMock(SecurityHandlerInterface::class); |
||
2039 | $securityHandler |
||
2040 | ->method('isGranted') |
||
2041 | ->willReturnCallback(static function (AdminInterface $adminIn, string $attributes, $object = null) use ($admin): bool { |
||
2042 | return $admin === $adminIn && 'DELETE' === $attributes; |
||
2043 | }); |
||
2044 | $admin->setSecurityHandler($securityHandler); |
||
2045 | |||
2046 | $this->assertSame($expected, $admin->getBatchActions()); |
||
2047 | } |
||
2048 | |||
2049 | /** |
||
2050 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::showMosaicButton |
||
2051 | */ |
||
2052 | public function testShowMosaicButton(): void |
||
2053 | { |
||
2054 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
2055 | $listModes = $admin->getListModes(); |
||
2056 | |||
2057 | $admin->showMosaicButton(true); |
||
2058 | |||
2059 | $this->assertSame($listModes, $admin->getListModes()); |
||
2060 | } |
||
2061 | |||
2062 | /** |
||
2063 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::showMosaicButton |
||
2064 | */ |
||
2065 | public function testShowMosaicButtonHideMosaic(): void |
||
2066 | { |
||
2067 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
2068 | $listModes = $admin->getListModes(); |
||
2069 | $expected['list'] = $listModes['list']; |
||
2070 | |||
2071 | $admin->showMosaicButton(false); |
||
2072 | |||
2073 | $this->assertSame($expected, $admin->getListModes()); |
||
2074 | } |
||
2075 | |||
2076 | /** |
||
2077 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getDashboardActions |
||
2078 | * @dataProvider provideGetBaseRouteName |
||
2079 | */ |
||
2080 | public function testDefaultDashboardActionsArePresent(string $objFqn, string $expected): void |
||
2111 | |||
2112 | public function testDefaultFilters(): void |
||
2171 | |||
2172 | /** |
||
2173 | * @group legacy |
||
2174 | */ |
||
2175 | public function testDefaultBreadcrumbsBuilder(): void |
||
2199 | |||
2200 | /** |
||
2201 | * @group legacy |
||
2202 | */ |
||
2203 | public function testBreadcrumbsBuilderSetter(): void |
||
2213 | |||
2214 | /** |
||
2215 | * @group legacy |
||
2216 | */ |
||
2217 | public function testGetBreadcrumbs(): void |
||
2227 | |||
2228 | /** |
||
2229 | * @group legacy |
||
2230 | */ |
||
2231 | public function testBuildBreadcrumbs(): void |
||
2248 | |||
2249 | /** |
||
2250 | * NEXT_MAJOR: remove this method. |
||
2251 | * |
||
2252 | * @group legacy |
||
2253 | */ |
||
2254 | public function testCreateQueryLegacyCallWorks(): void |
||
2269 | |||
2270 | public function testGetDataSourceIterator(): void |
||
2312 | |||
2313 | public function testCircularChildAdmin(): void |
||
2333 | |||
2334 | public function testCircularChildAdminTripleLevel(): void |
||
2360 | |||
2361 | public function testCircularChildAdminWithItself(): void |
||
2375 | |||
2376 | public function testGetRootAncestor(): void |
||
2410 | |||
2411 | public function testGetChildDepth(): void |
||
2445 | |||
2446 | public function testGetCurrentLeafChildAdmin(): void |
||
2483 | |||
2484 | private function createTagAdmin(Post $post): TagAdmin |
||
2523 | } |
||
2524 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: