| Total Complexity | 52 | 
| Total Lines | 2549 | 
| 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  | 
            ||
| 88 | class AdminTest extends TestCase  | 
            ||
| 89 | { | 
            ||
| 90 | protected $cacheTempFolder;  | 
            ||
| 91 | |||
| 92 | protected function setUp(): void  | 
            ||
| 93 |     { | 
            ||
| 94 | $this->cacheTempFolder = sys_get_temp_dir().'/sonata_test_route';  | 
            ||
| 95 | $filesystem = new Filesystem();  | 
            ||
| 96 | $filesystem->remove($this->cacheTempFolder);  | 
            ||
| 97 | }  | 
            ||
| 98 | |||
| 99 | /**  | 
            ||
| 100 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::__construct  | 
            ||
| 101 | */  | 
            ||
| 102 | public function testConstructor(): void  | 
            ||
| 103 |     { | 
            ||
| 104 | $class = 'Application\Sonata\NewsBundle\Entity\Post';  | 
            ||
| 105 | $baseControllerName = 'Sonata\NewsBundle\Controller\PostAdminController';  | 
            ||
| 106 | |||
| 107 |         $admin = new PostAdmin('sonata.post.admin.post', $class, $baseControllerName); | 
            ||
| 108 | $this->assertInstanceOf(AbstractAdmin::class, $admin);  | 
            ||
| 109 | $this->assertSame($class, $admin->getClass());  | 
            ||
| 110 | $this->assertSame($baseControllerName, $admin->getBaseControllerName());  | 
            ||
| 111 | }  | 
            ||
| 112 | |||
| 113 | public function testGetClass(): void  | 
            ||
| 114 |     { | 
            ||
| 115 | $class = Post::class;  | 
            ||
| 116 | $baseControllerName = 'Sonata\NewsBundle\Controller\PostAdminController';  | 
            ||
| 117 | |||
| 118 |         $admin = new PostAdmin('sonata.post.admin.post', $class, $baseControllerName); | 
            ||
| 119 | |||
| 120 | $admin->setModelManager($this->getMockForAbstractClass(ModelManagerInterface::class));  | 
            ||
| 121 | |||
| 122 | $admin->setSubject(new BlogPost());  | 
            ||
| 123 | $this->assertSame(BlogPost::class, $admin->getClass());  | 
            ||
| 124 | |||
| 125 | $admin->setSubClasses(['foo']);  | 
            ||
| 126 | $this->assertSame(BlogPost::class, $admin->getClass());  | 
            ||
| 127 | |||
| 128 | $admin->setSubject(null);  | 
            ||
| 129 | $admin->setSubClasses([]);  | 
            ||
| 130 | $this->assertSame($class, $admin->getClass());  | 
            ||
| 131 | |||
| 132 | $admin->setSubClasses(['foo' => 'bar']);  | 
            ||
| 133 | $admin->setRequest(new Request(['subclass' => 'foo']));  | 
            ||
| 134 |         $this->assertSame('bar', $admin->getClass()); | 
            ||
| 135 | }  | 
            ||
| 136 | |||
| 137 | public function testGetClassException(): void  | 
            ||
| 138 |     { | 
            ||
| 139 | $this->expectException(\RuntimeException::class);  | 
            ||
| 140 |         $this->expectExceptionMessage('Feature not implemented: an embedded admin cannot have subclass'); | 
            ||
| 141 | |||
| 142 | $class = 'Application\Sonata\NewsBundle\Entity\Post';  | 
            ||
| 143 | $baseControllerName = 'Sonata\NewsBundle\Controller\PostAdminController';  | 
            ||
| 144 | |||
| 145 |         $admin = new PostAdmin('sonata.post.admin.post', $class, $baseControllerName); | 
            ||
| 146 | $admin->setParentFieldDescription(new FieldDescription());  | 
            ||
| 147 | $admin->setSubClasses(['foo' => 'bar']);  | 
            ||
| 148 | $admin->setRequest(new Request(['subclass' => 'foo']));  | 
            ||
| 149 | $admin->getClass();  | 
            ||
| 150 | }  | 
            ||
| 151 | |||
| 152 | public function testCheckAccessThrowsExceptionOnMadeUpAction(): void  | 
            ||
| 153 |     { | 
            ||
| 154 | $admin = new PostAdmin(  | 
            ||
| 155 | 'sonata.post.admin.post',  | 
            ||
| 156 | 'Application\Sonata\NewsBundle\Entity\Post',  | 
            ||
| 157 | 'Sonata\NewsBundle\Controller\PostAdminController'  | 
            ||
| 158 | );  | 
            ||
| 159 | $this->expectException(  | 
            ||
| 160 | \InvalidArgumentException::class  | 
            ||
| 161 | );  | 
            ||
| 162 | $this->expectExceptionMessage(  | 
            ||
| 163 | 'Action "made-up" could not be found'  | 
            ||
| 164 | );  | 
            ||
| 165 |         $admin->checkAccess('made-up'); | 
            ||
| 166 | }  | 
            ||
| 167 | |||
| 168 | public function testCheckAccessThrowsAccessDeniedException(): void  | 
            ||
| 169 |     { | 
            ||
| 170 | $admin = new PostAdmin(  | 
            ||
| 171 | 'sonata.post.admin.post',  | 
            ||
| 172 | 'Application\Sonata\NewsBundle\Entity\Post',  | 
            ||
| 173 | 'Sonata\NewsBundle\Controller\PostAdminController'  | 
            ||
| 174 | );  | 
            ||
| 175 | $securityHandler = $this->prophesize(SecurityHandlerInterface::class);  | 
            ||
| 176 | $securityHandler->isGranted($admin, 'CUSTOM_ROLE', $admin)->willReturn(true);  | 
            ||
| 177 | $securityHandler->isGranted($admin, 'EXTRA_CUSTOM_ROLE', $admin)->willReturn(false);  | 
            ||
| 178 | $customExtension = $this->prophesize(AbstractAdminExtension::class);  | 
            ||
| 179 | $customExtension->getAccessMapping($admin)->willReturn(  | 
            ||
| 180 | ['custom_action' => ['CUSTOM_ROLE', 'EXTRA_CUSTOM_ROLE']]  | 
            ||
| 181 | );  | 
            ||
| 182 | $admin->addExtension($customExtension->reveal());  | 
            ||
| 183 | $admin->setSecurityHandler($securityHandler->reveal());  | 
            ||
| 184 | $this->expectException(  | 
            ||
| 185 | AccessDeniedException::class  | 
            ||
| 186 | );  | 
            ||
| 187 | $this->expectExceptionMessage(  | 
            ||
| 188 | 'Access Denied to the action custom_action and role EXTRA_CUSTOM_ROLE'  | 
            ||
| 189 | );  | 
            ||
| 190 |         $admin->checkAccess('custom_action'); | 
            ||
| 191 | }  | 
            ||
| 192 | |||
| 193 | public function testHasAccessOnMadeUpAction(): void  | 
            ||
| 194 |     { | 
            ||
| 195 | $admin = new PostAdmin(  | 
            ||
| 196 | 'sonata.post.admin.post',  | 
            ||
| 197 | 'Application\Sonata\NewsBundle\Entity\Post',  | 
            ||
| 198 | 'Sonata\NewsBundle\Controller\PostAdminController'  | 
            ||
| 199 | );  | 
            ||
| 200 | |||
| 201 |         $this->assertFalse($admin->hasAccess('made-up')); | 
            ||
| 202 | }  | 
            ||
| 203 | |||
| 204 | public function testHasAccess(): void  | 
            ||
| 205 |     { | 
            ||
| 206 | $admin = new PostAdmin(  | 
            ||
| 207 | 'sonata.post.admin.post',  | 
            ||
| 208 | 'Application\Sonata\NewsBundle\Entity\Post',  | 
            ||
| 209 | 'Sonata\NewsBundle\Controller\PostAdminController'  | 
            ||
| 210 | );  | 
            ||
| 211 | $securityHandler = $this->prophesize(SecurityHandlerInterface::class);  | 
            ||
| 212 | $securityHandler->isGranted($admin, 'CUSTOM_ROLE', $admin)->willReturn(true);  | 
            ||
| 213 | $securityHandler->isGranted($admin, 'EXTRA_CUSTOM_ROLE', $admin)->willReturn(false);  | 
            ||
| 214 | $customExtension = $this->prophesize(AbstractAdminExtension::class);  | 
            ||
| 215 | $customExtension->getAccessMapping($admin)->willReturn(  | 
            ||
| 216 | ['custom_action' => ['CUSTOM_ROLE', 'EXTRA_CUSTOM_ROLE']]  | 
            ||
| 217 | );  | 
            ||
| 218 | $admin->addExtension($customExtension->reveal());  | 
            ||
| 219 | $admin->setSecurityHandler($securityHandler->reveal());  | 
            ||
| 220 | |||
| 221 |         $this->assertFalse($admin->hasAccess('custom_action')); | 
            ||
| 222 | }  | 
            ||
| 223 | |||
| 224 | public function testHasAccessAllowsAccess(): void  | 
            ||
| 225 |     { | 
            ||
| 226 | $admin = new PostAdmin(  | 
            ||
| 227 | 'sonata.post.admin.post',  | 
            ||
| 228 | 'Application\Sonata\NewsBundle\Entity\Post',  | 
            ||
| 229 | 'Sonata\NewsBundle\Controller\PostAdminController'  | 
            ||
| 230 | );  | 
            ||
| 231 | $securityHandler = $this->prophesize(SecurityHandlerInterface::class);  | 
            ||
| 232 | $securityHandler->isGranted($admin, 'CUSTOM_ROLE', $admin)->willReturn(true);  | 
            ||
| 233 | $securityHandler->isGranted($admin, 'EXTRA_CUSTOM_ROLE', $admin)->willReturn(true);  | 
            ||
| 234 | $customExtension = $this->prophesize(AbstractAdminExtension::class);  | 
            ||
| 235 | $customExtension->getAccessMapping($admin)->willReturn(  | 
            ||
| 236 | ['custom_action' => ['CUSTOM_ROLE', 'EXTRA_CUSTOM_ROLE']]  | 
            ||
| 237 | );  | 
            ||
| 238 | $admin->addExtension($customExtension->reveal());  | 
            ||
| 239 | $admin->setSecurityHandler($securityHandler->reveal());  | 
            ||
| 240 | |||
| 241 |         $this->assertTrue($admin->hasAccess('custom_action')); | 
            ||
| 242 | }  | 
            ||
| 243 | |||
| 244 | public function testHasAccessAllowsAccessEditAction(): void  | 
            ||
| 245 |     { | 
            ||
| 246 | $admin = new PostAdmin(  | 
            ||
| 247 | 'sonata.post.admin.post',  | 
            ||
| 248 | 'Application\Sonata\NewsBundle\Entity\Post',  | 
            ||
| 249 | 'Sonata\NewsBundle\Controller\PostAdminController'  | 
            ||
| 250 | );  | 
            ||
| 251 | $securityHandler = $this->prophesize(SecurityHandlerInterface::class);  | 
            ||
| 252 | $securityHandler->isGranted($admin, 'EDIT_ROLE', $admin)->willReturn(true);  | 
            ||
| 253 | $customExtension = $this->prophesize(AbstractAdminExtension::class);  | 
            ||
| 254 | $customExtension->getAccessMapping($admin)->willReturn(  | 
            ||
| 255 | ['edit_action' => ['EDIT_ROLE']]  | 
            ||
| 256 | );  | 
            ||
| 257 | $admin->addExtension($customExtension->reveal());  | 
            ||
| 258 | $admin->setSecurityHandler($securityHandler->reveal());  | 
            ||
| 259 | |||
| 260 |         $this->assertTrue($admin->hasAccess('edit_action')); | 
            ||
| 261 | }  | 
            ||
| 262 | |||
| 263 | /**  | 
            ||
| 264 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::hasChild  | 
            ||
| 265 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::addChild  | 
            ||
| 266 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getChild  | 
            ||
| 267 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::isChild  | 
            ||
| 268 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::hasChildren  | 
            ||
| 269 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getChildren  | 
            ||
| 270 | */  | 
            ||
| 271 | public function testChildren(): void  | 
            ||
| 272 |     { | 
            ||
| 273 |         $postAdmin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 274 | $this->assertFalse($postAdmin->hasChildren());  | 
            ||
| 275 |         $this->assertFalse($postAdmin->hasChild('comment')); | 
            ||
| 276 | |||
| 277 |         $commentAdmin = new CommentAdmin('sonata.post.admin.comment', 'Application\Sonata\NewsBundle\Entity\Comment', 'Sonata\NewsBundle\Controller\CommentAdminController'); | 
            ||
| 278 | $postAdmin->addChild($commentAdmin, 'post');  | 
            ||
| 279 | |||
| 280 | $this->assertTrue($postAdmin->hasChildren());  | 
            ||
| 281 |         $this->assertTrue($postAdmin->hasChild('sonata.post.admin.comment')); | 
            ||
| 282 | |||
| 283 |         $this->assertSame('sonata.post.admin.comment', $postAdmin->getChild('sonata.post.admin.comment')->getCode()); | 
            ||
| 284 |         $this->assertSame('sonata.post.admin.post|sonata.post.admin.comment', $postAdmin->getChild('sonata.post.admin.comment')->getBaseCodeRoute()); | 
            ||
| 285 |         $this->assertSame($postAdmin, $postAdmin->getChild('sonata.post.admin.comment')->getParent()); | 
            ||
| 286 |         $this->assertSame('post', $commentAdmin->getParentAssociationMapping()); | 
            ||
| 287 | |||
| 288 | $this->assertFalse($postAdmin->isChild());  | 
            ||
| 289 | $this->assertTrue($commentAdmin->isChild());  | 
            ||
| 290 | |||
| 291 | $this->assertSame(['sonata.post.admin.comment' => $commentAdmin], $postAdmin->getChildren());  | 
            ||
| 292 | }  | 
            ||
| 293 | |||
| 294 | /**  | 
            ||
| 295 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::configure  | 
            ||
| 296 | */  | 
            ||
| 297 | public function testConfigure(): void  | 
            ||
| 298 |     { | 
            ||
| 299 |         $admin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 300 | $this->assertNotNull($admin->getUniqid());  | 
            ||
| 301 | |||
| 302 | $admin->initialize();  | 
            ||
| 303 | $this->assertNotNull($admin->getUniqid());  | 
            ||
| 304 |         $this->assertSame('Post', $admin->getClassnameLabel()); | 
            ||
| 305 | |||
| 306 |         $admin = new CommentAdmin('sonata.post.admin.comment', 'Application\Sonata\NewsBundle\Entity\Comment', 'Sonata\NewsBundle\Controller\CommentAdminController'); | 
            ||
| 307 |         $admin->setClassnameLabel('postcomment'); | 
            ||
| 308 | |||
| 309 | $admin->initialize();  | 
            ||
| 310 |         $this->assertSame('postcomment', $admin->getClassnameLabel()); | 
            ||
| 311 | }  | 
            ||
| 312 | |||
| 313 | public function testConfigureWithValidParentAssociationMapping(): void  | 
            ||
| 314 |     { | 
            ||
| 315 |         $admin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 316 |         $admin->setParentAssociationMapping('Category'); | 
            ||
| 317 | |||
| 318 | $admin->initialize();  | 
            ||
| 319 |         $this->assertSame('Category', $admin->getParentAssociationMapping()); | 
            ||
| 320 | }  | 
            ||
| 321 | |||
| 322 | public function provideGetBaseRoutePattern()  | 
            ||
| 323 |     { | 
            ||
| 324 | return [  | 
            ||
| 325 | [  | 
            ||
| 326 | 'Application\Sonata\NewsBundle\Entity\Post',  | 
            ||
| 327 | '/sonata/news/post',  | 
            ||
| 328 | ],  | 
            ||
| 329 | [  | 
            ||
| 330 | 'Application\Sonata\NewsBundle\Document\Post',  | 
            ||
| 331 | '/sonata/news/post',  | 
            ||
| 332 | ],  | 
            ||
| 333 | [  | 
            ||
| 334 | 'MyApplication\MyBundle\Entity\Post',  | 
            ||
| 335 | '/myapplication/my/post',  | 
            ||
| 336 | ],  | 
            ||
| 337 | [  | 
            ||
| 338 | 'MyApplication\MyBundle\Entity\Post\Category',  | 
            ||
| 339 | '/myapplication/my/post-category',  | 
            ||
| 340 | ],  | 
            ||
| 341 | [  | 
            ||
| 342 | 'MyApplication\MyBundle\Entity\Product\Category',  | 
            ||
| 343 | '/myapplication/my/product-category',  | 
            ||
| 344 | ],  | 
            ||
| 345 | [  | 
            ||
| 346 | 'MyApplication\MyBundle\Entity\Other\Product\Category',  | 
            ||
| 347 | '/myapplication/my/other-product-category',  | 
            ||
| 348 | ],  | 
            ||
| 349 | [  | 
            ||
| 350 | 'Symfony\Cmf\Bundle\FooBundle\Document\Menu',  | 
            ||
| 351 | '/cmf/foo/menu',  | 
            ||
| 352 | ],  | 
            ||
| 353 | [  | 
            ||
| 354 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\Phpcr\Menu',  | 
            ||
| 355 | '/cmf/foo/menu',  | 
            ||
| 356 | ],  | 
            ||
| 357 | [  | 
            ||
| 358 | 'Symfony\Bundle\BarBarBundle\Doctrine\Phpcr\Menu',  | 
            ||
| 359 | '/symfony/barbar/menu',  | 
            ||
| 360 | ],  | 
            ||
| 361 | [  | 
            ||
| 362 | 'Symfony\Bundle\BarBarBundle\Doctrine\Phpcr\Menu\Item',  | 
            ||
| 363 | '/symfony/barbar/menu-item',  | 
            ||
| 364 | ],  | 
            ||
| 365 | [  | 
            ||
| 366 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\Orm\Menu',  | 
            ||
| 367 | '/cmf/foo/menu',  | 
            ||
| 368 | ],  | 
            ||
| 369 | [  | 
            ||
| 370 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\MongoDB\Menu',  | 
            ||
| 371 | '/cmf/foo/menu',  | 
            ||
| 372 | ],  | 
            ||
| 373 | [  | 
            ||
| 374 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\CouchDB\Menu',  | 
            ||
| 375 | '/cmf/foo/menu',  | 
            ||
| 376 | ],  | 
            ||
| 377 | [  | 
            ||
| 378 | 'AppBundle\Entity\User',  | 
            ||
| 379 | '/app/user',  | 
            ||
| 380 | ],  | 
            ||
| 381 | [  | 
            ||
| 382 | 'App\Entity\User',  | 
            ||
| 383 | '/app/user',  | 
            ||
| 384 | ],  | 
            ||
| 385 | ];  | 
            ||
| 386 | }  | 
            ||
| 387 | |||
| 388 | /**  | 
            ||
| 389 | * @dataProvider provideGetBaseRoutePattern  | 
            ||
| 390 | */  | 
            ||
| 391 | public function testGetBaseRoutePattern(string $objFqn, string $expected): void  | 
            ||
| 392 |     { | 
            ||
| 393 |         $admin = new PostAdmin('sonata.post.admin.post', $objFqn, 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 394 | $this->assertSame($expected, $admin->getBaseRoutePattern());  | 
            ||
| 395 | }  | 
            ||
| 396 | |||
| 397 | /**  | 
            ||
| 398 | * @dataProvider provideGetBaseRoutePattern  | 
            ||
| 399 | */  | 
            ||
| 400 | public function testGetBaseRoutePatternWithChildAdmin(string $objFqn, string $expected): void  | 
            ||
| 401 |     { | 
            ||
| 402 |         $postAdmin = new PostAdmin('sonata.post.admin.post', $objFqn, 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 403 |         $commentAdmin = new CommentAdmin('sonata.post.admin.comment', 'Application\Sonata\NewsBundle\Entity\Comment', 'Sonata\NewsBundle\Controller\CommentAdminController'); | 
            ||
| 404 | $commentAdmin->setParent($postAdmin);  | 
            ||
| 405 | |||
| 406 |         $this->assertSame($expected.'/{id}/comment', $commentAdmin->getBaseRoutePattern()); | 
            ||
| 407 | }  | 
            ||
| 408 | |||
| 409 | /**  | 
            ||
| 410 | * @dataProvider provideGetBaseRoutePattern  | 
            ||
| 411 | */  | 
            ||
| 412 | public function testGetBaseRoutePatternWithTwoNestedChildAdmin(string $objFqn, string $expected): void  | 
            ||
| 413 |     { | 
            ||
| 414 |         $postAdmin = new PostAdmin('sonata.post.admin.post', $objFqn, 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 415 | $commentAdmin = new CommentAdmin(  | 
            ||
| 416 | 'sonata.post.admin.comment',  | 
            ||
| 417 | 'Application\Sonata\NewsBundle\Entity\Comment',  | 
            ||
| 418 | 'Sonata\NewsBundle\Controller\CommentAdminController'  | 
            ||
| 419 | );  | 
            ||
| 420 | $commentVoteAdmin = new CommentVoteAdmin(  | 
            ||
| 421 | 'sonata.post.admin.comment_vote',  | 
            ||
| 422 | 'Application\Sonata\NewsBundle\Entity\CommentVote',  | 
            ||
| 423 | 'Sonata\NewsBundle\Controller\CommentVoteAdminController'  | 
            ||
| 424 | );  | 
            ||
| 425 | $commentAdmin->setParent($postAdmin);  | 
            ||
| 426 | $commentVoteAdmin->setParent($commentAdmin);  | 
            ||
| 427 | |||
| 428 |         $this->assertSame($expected.'/{id}/comment/{childId}/commentvote', $commentVoteAdmin->getBaseRoutePattern()); | 
            ||
| 429 | }  | 
            ||
| 430 | |||
| 431 | public function testGetBaseRoutePatternWithSpecifedPattern(): void  | 
            ||
| 432 |     { | 
            ||
| 433 |         $postAdmin = new PostWithCustomRouteAdmin('sonata.post.admin.post_with_custom_route', 'Application\Sonata\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostWithCustomRouteAdminController'); | 
            ||
| 434 | |||
| 435 |         $this->assertSame('/post-custom', $postAdmin->getBaseRoutePattern()); | 
            ||
| 436 | }  | 
            ||
| 437 | |||
| 438 | public function testGetBaseRoutePatternWithChildAdminAndWithSpecifedPattern(): void  | 
            ||
| 439 |     { | 
            ||
| 440 |         $postAdmin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 441 |         $commentAdmin = new CommentWithCustomRouteAdmin('sonata.post.admin.comment_with_custom_route', 'Application\Sonata\NewsBundle\Entity\Comment', 'Sonata\NewsBundle\Controller\CommentWithCustomRouteAdminController'); | 
            ||
| 442 | $commentAdmin->setParent($postAdmin);  | 
            ||
| 443 | |||
| 444 |         $this->assertSame('/sonata/news/post/{id}/comment-custom', $commentAdmin->getBaseRoutePattern()); | 
            ||
| 445 | }  | 
            ||
| 446 | |||
| 447 | public function testGetBaseRoutePatternWithUnreconizedClassname(): void  | 
            ||
| 448 |     { | 
            ||
| 449 | $this->expectException(\RuntimeException::class);  | 
            ||
| 450 | |||
| 451 |         $admin = new PostAdmin('sonata.post.admin.post', 'News\Thing\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 452 | $admin->getBaseRoutePattern();  | 
            ||
| 453 | }  | 
            ||
| 454 | |||
| 455 | public function provideGetBaseRouteName()  | 
            ||
| 456 |     { | 
            ||
| 457 | return [  | 
            ||
| 458 | [  | 
            ||
| 459 | 'Application\Sonata\NewsBundle\Entity\Post',  | 
            ||
| 460 | 'admin_sonata_news_post',  | 
            ||
| 461 | ],  | 
            ||
| 462 | [  | 
            ||
| 463 | 'Application\Sonata\NewsBundle\Document\Post',  | 
            ||
| 464 | 'admin_sonata_news_post',  | 
            ||
| 465 | ],  | 
            ||
| 466 | [  | 
            ||
| 467 | 'MyApplication\MyBundle\Entity\Post',  | 
            ||
| 468 | 'admin_myapplication_my_post',  | 
            ||
| 469 | ],  | 
            ||
| 470 | [  | 
            ||
| 471 | 'MyApplication\MyBundle\Entity\Post\Category',  | 
            ||
| 472 | 'admin_myapplication_my_post_category',  | 
            ||
| 473 | ],  | 
            ||
| 474 | [  | 
            ||
| 475 | 'MyApplication\MyBundle\Entity\Product\Category',  | 
            ||
| 476 | 'admin_myapplication_my_product_category',  | 
            ||
| 477 | ],  | 
            ||
| 478 | [  | 
            ||
| 479 | 'MyApplication\MyBundle\Entity\Other\Product\Category',  | 
            ||
| 480 | 'admin_myapplication_my_other_product_category',  | 
            ||
| 481 | ],  | 
            ||
| 482 | [  | 
            ||
| 483 | 'Symfony\Cmf\Bundle\FooBundle\Document\Menu',  | 
            ||
| 484 | 'admin_cmf_foo_menu',  | 
            ||
| 485 | ],  | 
            ||
| 486 | [  | 
            ||
| 487 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\Phpcr\Menu',  | 
            ||
| 488 | 'admin_cmf_foo_menu',  | 
            ||
| 489 | ],  | 
            ||
| 490 | [  | 
            ||
| 491 | 'Symfony\Bundle\BarBarBundle\Doctrine\Phpcr\Menu',  | 
            ||
| 492 | 'admin_symfony_barbar_menu',  | 
            ||
| 493 | ],  | 
            ||
| 494 | [  | 
            ||
| 495 | 'Symfony\Bundle\BarBarBundle\Doctrine\Phpcr\Menu\Item',  | 
            ||
| 496 | 'admin_symfony_barbar_menu_item',  | 
            ||
| 497 | ],  | 
            ||
| 498 | [  | 
            ||
| 499 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\Orm\Menu',  | 
            ||
| 500 | 'admin_cmf_foo_menu',  | 
            ||
| 501 | ],  | 
            ||
| 502 | [  | 
            ||
| 503 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\MongoDB\Menu',  | 
            ||
| 504 | 'admin_cmf_foo_menu',  | 
            ||
| 505 | ],  | 
            ||
| 506 | [  | 
            ||
| 507 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\CouchDB\Menu',  | 
            ||
| 508 | 'admin_cmf_foo_menu',  | 
            ||
| 509 | ],  | 
            ||
| 510 | [  | 
            ||
| 511 | 'AppBundle\Entity\User',  | 
            ||
| 512 | 'admin_app_user',  | 
            ||
| 513 | ],  | 
            ||
| 514 | [  | 
            ||
| 515 | 'App\Entity\User',  | 
            ||
| 516 | 'admin_app_user',  | 
            ||
| 517 | ],  | 
            ||
| 518 | ];  | 
            ||
| 519 | }  | 
            ||
| 520 | |||
| 521 | /**  | 
            ||
| 522 | * @dataProvider provideGetBaseRouteName  | 
            ||
| 523 | */  | 
            ||
| 524 | public function testGetBaseRouteName(string $objFqn, string $expected): void  | 
            ||
| 525 |     { | 
            ||
| 526 |         $admin = new PostAdmin('sonata.post.admin.post', $objFqn, 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 527 | |||
| 528 | $this->assertSame($expected, $admin->getBaseRouteName());  | 
            ||
| 529 | }  | 
            ||
| 530 | |||
| 531 | /**  | 
            ||
| 532 | * @group legacy  | 
            ||
| 533 | * @expectedDeprecation Calling "addChild" without second argument is deprecated since sonata-project/admin-bundle 3.35 and will not be allowed in 4.0.  | 
            ||
| 534 | * @dataProvider provideGetBaseRouteName  | 
            ||
| 535 | */  | 
            ||
| 536 | public function testGetBaseRouteNameWithChildAdmin(string $objFqn, string $expected): void  | 
            ||
| 537 |     { | 
            ||
| 538 | $routeGenerator = new DefaultRouteGenerator(  | 
            ||
| 539 | $this->createMock(RouterInterface::class),  | 
            ||
| 540 | new RoutesCache($this->cacheTempFolder, true)  | 
            ||
| 541 | );  | 
            ||
| 542 | |||
| 543 | $container = new Container();  | 
            ||
| 544 | $pool = new Pool($container, 'Sonata Admin', '/path/to/pic.png');  | 
            ||
| 545 | |||
| 546 | $pathInfo = new PathInfoBuilder($this->createMock(AuditManagerInterface::class));  | 
            ||
| 547 |         $postAdmin = new PostAdmin('sonata.post.admin.post', $objFqn, 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 548 |         $container->set('sonata.post.admin.post', $postAdmin); | 
            ||
| 549 | $postAdmin->setConfigurationPool($pool);  | 
            ||
| 550 | $postAdmin->setRouteBuilder($pathInfo);  | 
            ||
| 551 | $postAdmin->setRouteGenerator($routeGenerator);  | 
            ||
| 552 | $postAdmin->initialize();  | 
            ||
| 553 | |||
| 554 | $commentAdmin = new CommentAdmin(  | 
            ||
| 555 | 'sonata.post.admin.comment',  | 
            ||
| 556 | 'Application\Sonata\NewsBundle\Entity\Comment',  | 
            ||
| 557 | 'Sonata\NewsBundle\Controller\CommentAdminController'  | 
            ||
| 558 | );  | 
            ||
| 559 |         $container->set('sonata.post.admin.comment', $commentAdmin); | 
            ||
| 560 | $commentAdmin->setConfigurationPool($pool);  | 
            ||
| 561 | $commentAdmin->setRouteBuilder($pathInfo);  | 
            ||
| 562 | $commentAdmin->setRouteGenerator($routeGenerator);  | 
            ||
| 563 | $commentAdmin->initialize();  | 
            ||
| 564 | |||
| 565 | $postAdmin->addChild($commentAdmin, 'post');  | 
            ||
| 566 | |||
| 567 | $commentVoteAdmin = new CommentVoteAdmin(  | 
            ||
| 568 | 'sonata.post.admin.comment_vote',  | 
            ||
| 569 | 'Application\Sonata\NewsBundle\Entity\CommentVote',  | 
            ||
| 570 | 'Sonata\NewsBundle\Controller\CommentVoteAdminController'  | 
            ||
| 571 | );  | 
            ||
| 572 | |||
| 573 |         $container->set('sonata.post.admin.comment_vote', $commentVoteAdmin); | 
            ||
| 574 | $commentVoteAdmin->setConfigurationPool($pool);  | 
            ||
| 575 | $commentVoteAdmin->setRouteBuilder($pathInfo);  | 
            ||
| 576 | $commentVoteAdmin->setRouteGenerator($routeGenerator);  | 
            ||
| 577 | $commentVoteAdmin->initialize();  | 
            ||
| 578 | |||
| 579 | $commentAdmin->addChild($commentVoteAdmin);  | 
            ||
| 580 | $pool->setAdminServiceIds([  | 
            ||
| 581 | 'sonata.post.admin.post',  | 
            ||
| 582 | 'sonata.post.admin.comment',  | 
            ||
| 583 | 'sonata.post.admin.comment_vote',  | 
            ||
| 584 | ]);  | 
            ||
| 585 | |||
| 586 | $this->assertSame($expected.'_comment', $commentAdmin->getBaseRouteName());  | 
            ||
| 587 | |||
| 588 |         $this->assertTrue($postAdmin->hasRoute('show')); | 
            ||
| 589 |         $this->assertTrue($postAdmin->hasRoute('sonata.post.admin.post.show')); | 
            ||
| 590 |         $this->assertTrue($postAdmin->hasRoute('sonata.post.admin.post|sonata.post.admin.comment.show')); | 
            ||
| 591 |         $this->assertTrue($postAdmin->hasRoute('sonata.post.admin.post|sonata.post.admin.comment|sonata.post.admin.comment_vote.show')); | 
            ||
| 592 |         $this->assertTrue($postAdmin->hasRoute('sonata.post.admin.comment.list')); | 
            ||
| 593 |         $this->assertTrue($postAdmin->hasRoute('sonata.post.admin.comment|sonata.post.admin.comment_vote.list')); | 
            ||
| 594 |         $this->assertFalse($postAdmin->hasRoute('sonata.post.admin.post|sonata.post.admin.comment.edit')); | 
            ||
| 595 |         $this->assertFalse($commentAdmin->hasRoute('edit')); | 
            ||
| 596 |         $this->assertSame('post', $commentAdmin->getParentAssociationMapping()); | 
            ||
| 597 | |||
| 598 | /*  | 
            ||
| 599 | * Test the route name from request  | 
            ||
| 600 | */  | 
            ||
| 601 | $postListRequest = new Request(  | 
            ||
| 602 | [],  | 
            ||
| 603 | [],  | 
            ||
| 604 | [  | 
            ||
| 605 | '_route' => $postAdmin->getBaseRouteName().'_list',  | 
            ||
| 606 | ]  | 
            ||
| 607 | );  | 
            ||
| 608 | |||
| 609 | $postAdmin->setRequest($postListRequest);  | 
            ||
| 610 | $commentAdmin->setRequest($postListRequest);  | 
            ||
| 611 | |||
| 612 |         $this->assertTrue($postAdmin->isCurrentRoute('list')); | 
            ||
| 613 |         $this->assertFalse($postAdmin->isCurrentRoute('create')); | 
            ||
| 614 |         $this->assertFalse($commentAdmin->isCurrentRoute('list')); | 
            ||
| 615 |         $this->assertFalse($commentVoteAdmin->isCurrentRoute('list')); | 
            ||
| 616 |         $this->assertTrue($commentAdmin->isCurrentRoute('list', 'sonata.post.admin.post')); | 
            ||
| 617 |         $this->assertFalse($commentAdmin->isCurrentRoute('edit', 'sonata.post.admin.post')); | 
            ||
| 618 |         $this->assertTrue($commentVoteAdmin->isCurrentRoute('list', 'sonata.post.admin.post')); | 
            ||
| 619 |         $this->assertFalse($commentVoteAdmin->isCurrentRoute('edit', 'sonata.post.admin.post')); | 
            ||
| 620 | }  | 
            ||
| 621 | |||
| 622 | public function testGetBaseRouteNameWithUnreconizedClassname(): void  | 
            ||
| 623 |     { | 
            ||
| 624 | $this->expectException(\RuntimeException::class);  | 
            ||
| 625 | |||
| 626 |         $admin = new PostAdmin('sonata.post.admin.post', 'News\Thing\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 627 | $admin->getBaseRouteName();  | 
            ||
| 628 | }  | 
            ||
| 629 | |||
| 630 | public function testGetBaseRouteNameWithSpecifiedName(): void  | 
            ||
| 631 |     { | 
            ||
| 632 |         $postAdmin = new PostWithCustomRouteAdmin('sonata.post.admin.post_with_custom_route', 'Application\Sonata\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 633 | |||
| 634 |         $this->assertSame('post_custom', $postAdmin->getBaseRouteName()); | 
            ||
| 635 | }  | 
            ||
| 636 | |||
| 637 | public function testGetBaseRouteNameWithChildAdminAndWithSpecifiedName(): void  | 
            ||
| 638 |     { | 
            ||
| 639 |         $postAdmin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 640 |         $commentAdmin = new CommentWithCustomRouteAdmin('sonata.post.admin.comment_with_custom_route', 'Application\Sonata\NewsBundle\Entity\Comment', 'Sonata\NewsBundle\Controller\CommentWithCustomRouteAdminController'); | 
            ||
| 641 | $commentAdmin->setParent($postAdmin);  | 
            ||
| 642 | |||
| 643 |         $this->assertSame('admin_sonata_news_post_comment_custom', $commentAdmin->getBaseRouteName()); | 
            ||
| 644 | }  | 
            ||
| 645 | |||
| 646 | public function testGetBaseRouteNameWithTwoNestedChildAdminAndWithSpecifiedName(): void  | 
            ||
| 647 |     { | 
            ||
| 648 | $postAdmin = new PostAdmin(  | 
            ||
| 649 | 'sonata.post.admin.post',  | 
            ||
| 650 | 'Application\Sonata\NewsBundle\Entity\Post',  | 
            ||
| 651 | 'Sonata\NewsBundle\Controller\PostAdminController'  | 
            ||
| 652 | );  | 
            ||
| 653 | $commentAdmin = new CommentWithCustomRouteAdmin(  | 
            ||
| 654 | 'sonata.post.admin.comment_with_custom_route',  | 
            ||
| 655 | 'Application\Sonata\NewsBundle\Entity\Comment',  | 
            ||
| 656 | 'Sonata\NewsBundle\Controller\CommentWithCustomRouteAdminController'  | 
            ||
| 657 | );  | 
            ||
| 658 | $commentVoteAdmin = new CommentVoteAdmin(  | 
            ||
| 659 | 'sonata.post.admin.comment_vote',  | 
            ||
| 660 | 'Application\Sonata\NewsBundle\Entity\CommentVote',  | 
            ||
| 661 | 'Sonata\NewsBundle\Controller\CommentVoteAdminController'  | 
            ||
| 662 | );  | 
            ||
| 663 | $commentAdmin->setParent($postAdmin);  | 
            ||
| 664 | $commentVoteAdmin->setParent($commentAdmin);  | 
            ||
| 665 | |||
| 666 |         $this->assertSame('admin_sonata_news_post_comment_custom_commentvote', $commentVoteAdmin->getBaseRouteName()); | 
            ||
| 667 | }  | 
            ||
| 668 | |||
| 669 | /**  | 
            ||
| 670 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::setUniqid  | 
            ||
| 671 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getUniqid  | 
            ||
| 672 | */  | 
            ||
| 673 | public function testSetUniqid(): void  | 
            ||
| 674 |     { | 
            ||
| 675 |         $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 676 | |||
| 677 | $uniqid = uniqid();  | 
            ||
| 678 | $admin->setUniqid($uniqid);  | 
            ||
| 679 | |||
| 680 | $this->assertSame($uniqid, $admin->getUniqid());  | 
            ||
| 681 | }  | 
            ||
| 682 | |||
| 683 | public function testToString(): void  | 
            ||
| 684 |     { | 
            ||
| 685 |         $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 686 | |||
| 687 | $s = new \stdClass();  | 
            ||
| 688 | |||
| 689 | $this->assertNotEmpty($admin->toString($s));  | 
            ||
| 690 | |||
| 691 | $s = new FooToString();  | 
            ||
| 692 |         $this->assertSame('salut', $admin->toString($s)); | 
            ||
| 693 | |||
| 694 | // To string method is implemented, but returns null  | 
            ||
| 695 | $s = new FooToStringNull();  | 
            ||
| 696 | $this->assertNotEmpty($admin->toString($s));  | 
            ||
| 697 | |||
| 698 |         $this->assertSame('', $admin->toString(false)); | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 699 | }  | 
            ||
| 700 | |||
| 701 | public function testIsAclEnabled(): void  | 
            ||
| 702 |     { | 
            ||
| 703 |         $postAdmin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 704 | |||
| 705 | $this->assertFalse($postAdmin->isAclEnabled());  | 
            ||
| 706 | |||
| 707 |         $commentAdmin = new CommentAdmin('sonata.post.admin.comment', 'Application\Sonata\NewsBundle\Entity\Comment', 'Sonata\NewsBundle\Controller\CommentAdminController'); | 
            ||
| 708 | $commentAdmin->setSecurityHandler($this->createMock(AclSecurityHandlerInterface::class));  | 
            ||
| 709 | $this->assertTrue($commentAdmin->isAclEnabled());  | 
            ||
| 710 | }  | 
            ||
| 711 | |||
| 712 | /**  | 
            ||
| 713 | * @group legacy  | 
            ||
| 714 | *  | 
            ||
| 715 | * @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.  | 
            ||
| 716 | *  | 
            ||
| 717 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getSubClasses  | 
            ||
| 718 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getSubClass  | 
            ||
| 719 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::setSubClasses  | 
            ||
| 720 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::hasSubClass  | 
            ||
| 721 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::hasActiveSubClass  | 
            ||
| 722 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getActiveSubClass  | 
            ||
| 723 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getActiveSubclassCode  | 
            ||
| 724 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getClass  | 
            ||
| 725 | */  | 
            ||
| 726 | public function testSubClass(): void  | 
            ||
| 727 |     { | 
            ||
| 728 | // NEXT_MAJOR: Remove the "@group" and "@expectedDeprecation" annotations  | 
            ||
| 729 | $admin = new PostAdmin(  | 
            ||
| 730 | 'sonata.post.admin.post',  | 
            ||
| 731 | Post::class,  | 
            ||
| 732 | 'Sonata\NewsBundle\Controller\PostAdminController'  | 
            ||
| 733 | );  | 
            ||
| 734 |         $this->assertFalse($admin->hasSubClass('test')); | 
            ||
| 735 | $this->assertFalse($admin->hasActiveSubClass());  | 
            ||
| 736 | $this->assertCount(0, $admin->getSubClasses());  | 
            ||
| 737 | $this->assertNull($admin->getActiveSubClass());  | 
            ||
| 738 | $this->assertNull($admin->getActiveSubclassCode());  | 
            ||
| 739 | $this->assertSame(Post::class, $admin->getClass());  | 
            ||
| 740 | |||
| 741 | // Just for the record, if there is no inheritance set, the getSubject is not used  | 
            ||
| 742 | // the getSubject can also lead to some issue  | 
            ||
| 743 | $admin->setSubject(new BlogPost());  | 
            ||
| 744 | $this->assertSame(BlogPost::class, $admin->getClass());  | 
            ||
| 745 | |||
| 746 | $admin->setSubClasses([  | 
            ||
| 747 | 'extended1' => 'NewsBundle\Entity\PostExtended1',  | 
            ||
| 748 | 'extended2' => 'NewsBundle\Entity\PostExtended2',  | 
            ||
| 749 | ]);  | 
            ||
| 750 |         $this->assertFalse($admin->hasSubClass('test')); | 
            ||
| 751 |         $this->assertTrue($admin->hasSubClass('extended1')); | 
            ||
| 752 | $this->assertFalse($admin->hasActiveSubClass());  | 
            ||
| 753 | $this->assertCount(2, $admin->getSubClasses());  | 
            ||
| 754 | // NEXT_MAJOR: remove the following 2 `assertNull()` assertions  | 
            ||
| 755 | $this->assertNull($admin->getActiveSubClass());  | 
            ||
| 756 | $this->assertNull($admin->getActiveSubclassCode());  | 
            ||
| 757 | $this->assertSame(  | 
            ||
| 758 | BlogPost::class,  | 
            ||
| 759 | $admin->getClass(),  | 
            ||
| 760 | 'When there is no subclass in the query the class parameter should be returned'  | 
            ||
| 761 | );  | 
            ||
| 762 | |||
| 763 | $request = new Request(['subclass' => 'extended1']);  | 
            ||
| 764 | $admin->setRequest($request);  | 
            ||
| 765 |         $this->assertFalse($admin->hasSubClass('test')); | 
            ||
| 766 |         $this->assertTrue($admin->hasSubClass('extended1')); | 
            ||
| 767 | $this->assertTrue($admin->hasActiveSubClass());  | 
            ||
| 768 | $this->assertCount(2, $admin->getSubClasses());  | 
            ||
| 769 | $this->assertSame(  | 
            ||
| 770 | 'NewsBundle\Entity\PostExtended1',  | 
            ||
| 771 | $admin->getActiveSubClass(),  | 
            ||
| 772 | 'It should return the curently active sub class.'  | 
            ||
| 773 | );  | 
            ||
| 774 |         $this->assertSame('extended1', $admin->getActiveSubclassCode()); | 
            ||
| 775 | $this->assertSame(  | 
            ||
| 776 | 'NewsBundle\Entity\PostExtended1',  | 
            ||
| 777 | $admin->getClass(),  | 
            ||
| 778 | 'getClass() should return the name of the sub class when passed through a request query parameter.'  | 
            ||
| 779 | );  | 
            ||
| 780 | |||
| 781 |         $request->query->set('subclass', 'inject'); | 
            ||
| 782 | |||
| 783 | $this->assertNull($admin->getActiveSubclassCode());  | 
            ||
| 784 | // NEXT_MAJOR: remove the previous `assertNull()` assertion and uncomment the following lines  | 
            ||
| 785 | // $this->expectException(\LogicException::class);  | 
            ||
| 786 |         // $this->expectExceptionMessage(sprintf('Admin "%s" has no active subclass.', PostAdmin::class)); | 
            ||
| 787 | }  | 
            ||
| 788 | |||
| 789 | /**  | 
            ||
| 790 | * @group legacy  | 
            ||
| 791 | *  | 
            ||
| 792 | * @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.  | 
            ||
| 793 | */  | 
            ||
| 794 | public function testNonExistantSubclass(): void  | 
            ||
| 795 |     { | 
            ||
| 796 | // NEXT_MAJOR: Remove the "@group" and "@expectedDeprecation" annotations  | 
            ||
| 797 |         $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 798 | $admin->setModelManager($this->getMockForAbstractClass(ModelManagerInterface::class));  | 
            ||
| 799 | |||
| 800 | $admin->setRequest(new Request(['subclass' => 'inject']));  | 
            ||
| 801 | |||
| 802 | $admin->setSubClasses(['extended1' => 'NewsBundle\Entity\PostExtended1', 'extended2' => 'NewsBundle\Entity\PostExtended2']);  | 
            ||
| 803 | |||
| 804 | $this->assertTrue($admin->hasActiveSubClass());  | 
            ||
| 805 | |||
| 806 | $this->expectException(\RuntimeException::class);  | 
            ||
| 807 | |||
| 808 | $admin->getActiveSubClass();  | 
            ||
| 809 | }  | 
            ||
| 810 | |||
| 811 | /**  | 
            ||
| 812 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::hasActiveSubClass  | 
            ||
| 813 | */  | 
            ||
| 814 | public function testOnlyOneSubclassNeededToBeActive(): void  | 
            ||
| 815 |     { | 
            ||
| 816 |         $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 817 | $admin->setSubClasses(['extended1' => 'NewsBundle\Entity\PostExtended1']);  | 
            ||
| 818 | $request = new Request(['subclass' => 'extended1']);  | 
            ||
| 819 | $admin->setRequest($request);  | 
            ||
| 820 | $this->assertTrue($admin->hasActiveSubClass());  | 
            ||
| 821 | }  | 
            ||
| 822 | |||
| 823 | /**  | 
            ||
| 824 | * @group legacy  | 
            ||
| 825 | * @expectedDeprecation Method "Sonata\AdminBundle\Admin\AbstractAdmin::addSubClass" is deprecated since sonata-project/admin-bundle 3.30 and will be removed in 4.0.  | 
            ||
| 826 | */  | 
            ||
| 827 | public function testAddSubClassIsDeprecated(): void  | 
            ||
| 828 |     { | 
            ||
| 829 | $admin = new PostAdmin(  | 
            ||
| 830 | 'sonata.post.admin.post',  | 
            ||
| 831 | Post::class,  | 
            ||
| 832 | 'Sonata\NewsBundle\Controller\PostAdminController'  | 
            ||
| 833 | );  | 
            ||
| 834 |         $admin->addSubClass('whatever'); | 
            ||
| 835 | }  | 
            ||
| 836 | |||
| 837 | /**  | 
            ||
| 838 | * @group legacy  | 
            ||
| 839 | */  | 
            ||
| 840 | public function testGetPerPageOptions(): void  | 
            ||
| 841 |     { | 
            ||
| 842 |         $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 843 | |||
| 844 | $perPageOptions = $admin->getPerPageOptions();  | 
            ||
| 845 | |||
| 846 |         foreach ($perPageOptions as $perPage) { | 
            ||
| 847 | $this->assertSame(0, $perPage % 4);  | 
            ||
| 848 | }  | 
            ||
| 849 | |||
| 850 | $admin->setPerPageOptions([500, 1000]);  | 
            ||
| 851 | $this->assertSame([500, 1000], $admin->getPerPageOptions());  | 
            ||
| 852 | }  | 
            ||
| 853 | |||
| 854 | public function testGetLabelTranslatorStrategy(): void  | 
            ||
| 855 |     { | 
            ||
| 856 |         $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 857 | |||
| 858 | $this->assertNull($admin->getLabelTranslatorStrategy());  | 
            ||
| 859 | |||
| 860 | $labelTranslatorStrategy = $this->createMock(LabelTranslatorStrategyInterface::class);  | 
            ||
| 861 | $admin->setLabelTranslatorStrategy($labelTranslatorStrategy);  | 
            ||
| 862 | $this->assertSame($labelTranslatorStrategy, $admin->getLabelTranslatorStrategy());  | 
            ||
| 863 | }  | 
            ||
| 864 | |||
| 865 | public function testGetRouteBuilder(): void  | 
            ||
| 866 |     { | 
            ||
| 867 |         $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 868 | |||
| 869 | $this->assertNull($admin->getRouteBuilder());  | 
            ||
| 870 | |||
| 871 | $routeBuilder = $this->createMock(RouteBuilderInterface::class);  | 
            ||
| 872 | $admin->setRouteBuilder($routeBuilder);  | 
            ||
| 873 | $this->assertSame($routeBuilder, $admin->getRouteBuilder());  | 
            ||
| 874 | }  | 
            ||
| 875 | |||
| 876 | public function testGetMenuFactory(): void  | 
            ||
| 877 |     { | 
            ||
| 878 |         $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 879 | |||
| 880 | $this->assertNull($admin->getMenuFactory());  | 
            ||
| 881 | |||
| 882 | $menuFactory = $this->createMock(FactoryInterface::class);  | 
            ||
| 883 | $admin->setMenuFactory($menuFactory);  | 
            ||
| 884 | $this->assertSame($menuFactory, $admin->getMenuFactory());  | 
            ||
| 885 | }  | 
            ||
| 886 | |||
| 887 | public function testGetExtensions(): void  | 
            ||
| 900 | |||
| 901 | public function testGetFilterTheme(): void  | 
            ||
| 910 | |||
| 911 | public function testGetFormTheme(): void  | 
            ||
| 921 | |||
| 922 | public function testGetValidator(): void  | 
            ||
| 933 | |||
| 934 | public function testGetSecurityHandler(): void  | 
            ||
| 944 | |||
| 945 | public function testGetSecurityInformation(): void  | 
            ||
| 959 | |||
| 960 | public function testGetManagerType(): void  | 
            ||
| 969 | |||
| 970 | public function testGetModelManager(): void  | 
            ||
| 981 | |||
| 982 | /**  | 
            ||
| 983 | * NEXT_MAJOR: remove this method.  | 
            ||
| 984 | *  | 
            ||
| 985 | * @group legacy  | 
            ||
| 986 | */  | 
            ||
| 987 | public function testGetBaseCodeRoute(): void  | 
            ||
| 996 | |||
| 997 | // NEXT_MAJOR: uncomment this method.  | 
            ||
| 998 | // public function testGetBaseCodeRoute()  | 
            ||
| 999 |     // { | 
            ||
| 1000 | // $postAdmin = new PostAdmin(  | 
            ||
| 1001 | // 'sonata.post.admin.post',  | 
            ||
| 1002 | // 'NewsBundle\Entity\Post',  | 
            ||
| 1003 | // 'Sonata\NewsBundle\Controller\PostAdminController'  | 
            ||
| 1004 | // );  | 
            ||
| 1005 | // $commentAdmin = new CommentAdmin(  | 
            ||
| 1006 | // 'sonata.post.admin.comment',  | 
            ||
| 1007 | // 'Application\Sonata\NewsBundle\Entity\Comment',  | 
            ||
| 1008 | // 'Sonata\NewsBundle\Controller\CommentAdminController'  | 
            ||
| 1009 | // );  | 
            ||
| 1010 | //  | 
            ||
| 1011 | // $this->assertSame($postAdmin->getCode(), $postAdmin->getBaseCodeRoute());  | 
            ||
| 1012 | //  | 
            ||
| 1013 | // $postAdmin->addChild($commentAdmin);  | 
            ||
| 1014 | //  | 
            ||
| 1015 | // $this->assertSame(  | 
            ||
| 1016 | // 'sonata.post.admin.post|sonata.post.admin.comment',  | 
            ||
| 1017 | // $commentAdmin->getBaseCodeRoute()  | 
            ||
| 1018 | // );  | 
            ||
| 1019 | // }  | 
            ||
| 1020 | |||
| 1021 | public function testGetRouteGenerator(): void  | 
            ||
| 1032 | |||
| 1033 | public function testGetConfigurationPool(): void  | 
            ||
| 1046 | |||
| 1047 | public function testGetShowBuilder(): void  | 
            ||
| 1058 | |||
| 1059 | public function testGetListBuilder(): void  | 
            ||
| 1070 | |||
| 1071 | public function testGetDatagridBuilder(): void  | 
            ||
| 1082 | |||
| 1083 | public function testGetFormContractor(): void  | 
            ||
| 1094 | |||
| 1095 | public function testGetRequest(): void  | 
            ||
| 1107 | |||
| 1108 | public function testGetRequestWithException(): void  | 
            ||
| 1116 | |||
| 1117 | public function testGetTranslationDomain(): void  | 
            ||
| 1126 | |||
| 1127 | /**  | 
            ||
| 1128 | * @group legacy  | 
            ||
| 1129 | */  | 
            ||
| 1130 | public function testGetTranslator(): void  | 
            ||
| 1141 | |||
| 1142 | public function testGetShowGroups(): void  | 
            ||
| 1143 |     { | 
            ||
| 1144 |         $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 1145 | |||
| 1146 | // NEXT_MAJOR: Remove the argument "sonata_deprecation_mute" in the following call.  | 
            ||
| 1147 |         $this->assertFalse($admin->getShowGroups('sonata_deprecation_mute')); | 
            ||
| 1148 | |||
| 1149 | $groups = ['foo', 'bar', 'baz'];  | 
            ||
| 1150 | |||
| 1151 | $admin->setShowGroups($groups);  | 
            ||
| 1152 | $this->assertSame($groups, $admin->getShowGroups());  | 
            ||
| 1153 | }  | 
            ||
| 1154 | |||
| 1155 | public function testGetFormGroups(): void  | 
            ||
| 1156 |     { | 
            ||
| 1157 |         $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 1158 | |||
| 1159 | // NEXT_MAJOR: Remove the argument "sonata_deprecation_mute" in the following call.  | 
            ||
| 1160 |         $this->assertFalse($admin->getFormGroups('sonata_deprecation_mute')); | 
            ||
| 1161 | |||
| 1162 | $groups = ['foo', 'bar', 'baz'];  | 
            ||
| 1163 | |||
| 1164 | $admin->setFormGroups($groups);  | 
            ||
| 1165 | $this->assertSame($groups, $admin->getFormGroups());  | 
            ||
| 1166 | }  | 
            ||
| 1167 | |||
| 1168 | public function testGetMaxPageLinks(): void  | 
            ||
| 1177 | |||
| 1178 | /**  | 
            ||
| 1179 | * @group legacy  | 
            ||
| 1180 | */  | 
            ||
| 1181 | public function testGetMaxPerPage(): void  | 
            ||
| 1190 | |||
| 1191 | public function testGetLabel(): void  | 
            ||
| 1200 | |||
| 1201 | public function testGetBaseController(): void  | 
            ||
| 1210 | |||
| 1211 | public function testGetTemplates(): void  | 
            ||
| 1228 | |||
| 1229 | public function testGetTemplate1(): void  | 
            ||
| 1242 | |||
| 1243 | public function testGetIdParameter(): void  | 
            ||
| 1274 | |||
| 1275 | public function testGetExportFormats(): void  | 
            ||
| 1281 | |||
| 1282 | public function testGetUrlsafeIdentifier(): void  | 
            ||
| 1297 | |||
| 1298 | public function testDeterminedPerPageValue(): void  | 
            ||
| 1299 |     { | 
            ||
| 1300 |         $admin = new PostAdmin('sonata.post.admin.post', 'Acme\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 1301 | |||
| 1302 |         $this->assertFalse($admin->determinedPerPageValue('foo')); | 
            ||
| 1303 | $this->assertFalse($admin->determinedPerPageValue(123));  | 
            ||
| 1304 | $this->assertTrue($admin->determinedPerPageValue(16));  | 
            ||
| 1305 | }  | 
            ||
| 1306 | |||
| 1307 | public function testIsGranted(): void  | 
            ||
| 1308 |     { | 
            ||
| 1309 |         $admin = new PostAdmin('sonata.post.admin.post', 'Acme\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 1310 | $modelManager = $this->createStub(ModelManagerInterface::class);  | 
            ||
| 1311 | $modelManager  | 
            ||
| 1312 |             ->method('getNormalizedIdentifier') | 
            ||
| 1313 |             ->willReturnCallback(static function (?object $model = null): ?string { | 
            ||
| 1314 | return $model ? $model->id : null;  | 
            ||
| 1315 | });  | 
            ||
| 1316 | |||
| 1317 | $admin->setModelManager($modelManager);  | 
            ||
| 1318 | |||
| 1319 | $entity1 = new \stdClass();  | 
            ||
| 1320 | $entity1->id = '1';  | 
            ||
| 1321 | |||
| 1322 | $securityHandler = $this->createMock(AclSecurityHandlerInterface::class);  | 
            ||
| 1323 | $securityHandler  | 
            ||
| 1324 | ->expects($this->exactly(6))  | 
            ||
| 1325 |             ->method('isGranted') | 
            ||
| 1326 | ->willReturnCallback(static function (  | 
            ||
| 1327 | AdminInterface $adminIn,  | 
            ||
| 1328 | string $attributes,  | 
            ||
| 1329 | ?object $object = null  | 
            ||
| 1330 | ) use (  | 
            ||
| 1331 | $admin,  | 
            ||
| 1332 | $entity1  | 
            ||
| 1333 |             ): bool { | 
            ||
| 1334 | return $admin === $adminIn && 'FOO' === $attributes &&  | 
            ||
| 1335 | ($object === $admin || $object === $entity1);  | 
            ||
| 1336 | });  | 
            ||
| 1337 | |||
| 1338 | $admin->setSecurityHandler($securityHandler);  | 
            ||
| 1339 | |||
| 1340 |         $this->assertTrue($admin->isGranted('FOO')); | 
            ||
| 1341 |         $this->assertTrue($admin->isGranted('FOO')); | 
            ||
| 1342 |         $this->assertTrue($admin->isGranted('FOO', $entity1)); | 
            ||
| 1343 |         $this->assertTrue($admin->isGranted('FOO', $entity1)); | 
            ||
| 1344 |         $this->assertFalse($admin->isGranted('BAR')); | 
            ||
| 1345 |         $this->assertFalse($admin->isGranted('BAR')); | 
            ||
| 1346 |         $this->assertFalse($admin->isGranted('BAR', $entity1)); | 
            ||
| 1347 |         $this->assertFalse($admin->isGranted('BAR', $entity1)); | 
            ||
| 1348 | |||
| 1349 | $entity2 = new \stdClass();  | 
            ||
| 1350 | $entity2->id = '2';  | 
            ||
| 1351 | |||
| 1352 |         $this->assertFalse($admin->isGranted('BAR', $entity2)); | 
            ||
| 1353 |         $this->assertFalse($admin->isGranted('BAR', $entity2)); | 
            ||
| 1354 | |||
| 1355 | $entity3 = new \stdClass();  | 
            ||
| 1356 | $entity3->id = '3';  | 
            ||
| 1357 | |||
| 1358 |         $this->assertFalse($admin->isGranted('BAR', $entity3)); | 
            ||
| 1359 |         $this->assertFalse($admin->isGranted('BAR', $entity3)); | 
            ||
| 1360 | }  | 
            ||
| 1361 | |||
| 1362 | public function testSupportsPreviewMode(): void  | 
            ||
| 1363 |     { | 
            ||
| 1364 |         $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 1365 | |||
| 1366 | $this->assertFalse($admin->supportsPreviewMode());  | 
            ||
| 1367 | }  | 
            ||
| 1368 | |||
| 1369 | public function testGetPermissionsShow(): void  | 
            ||
| 1370 |     { | 
            ||
| 1371 |         $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 1372 | |||
| 1373 | $this->assertSame(['LIST'], $admin->getPermissionsShow(AbstractAdmin::CONTEXT_DASHBOARD));  | 
            ||
| 1374 | $this->assertSame(['LIST'], $admin->getPermissionsShow(AbstractAdmin::CONTEXT_MENU));  | 
            ||
| 1375 |         $this->assertSame(['LIST'], $admin->getPermissionsShow('foo')); | 
            ||
| 1376 | }  | 
            ||
| 1377 | |||
| 1378 | public function testShowIn(): void  | 
            ||
| 1379 |     { | 
            ||
| 1380 |         $admin = new PostAdmin('sonata.post.admin.post', 'Acme\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 1381 | |||
| 1382 | $securityHandler = $this->createMock(AclSecurityHandlerInterface::class);  | 
            ||
| 1383 | $securityHandler  | 
            ||
| 1384 |             ->method('isGranted') | 
            ||
| 1385 |             ->willReturnCallback(static function (AdminInterface $adminIn, array $attributes, $object = null) use ($admin): bool { | 
            ||
| 1386 | return $admin === $adminIn && $attributes === ['LIST'];  | 
            ||
| 1387 | });  | 
            ||
| 1388 | |||
| 1389 | $admin->setSecurityHandler($securityHandler);  | 
            ||
| 1390 | |||
| 1391 | $this->assertTrue($admin->showIn(AbstractAdmin::CONTEXT_DASHBOARD));  | 
            ||
| 1392 | $this->assertTrue($admin->showIn(AbstractAdmin::CONTEXT_MENU));  | 
            ||
| 1393 |         $this->assertTrue($admin->showIn('foo')); | 
            ||
| 1394 | }  | 
            ||
| 1395 | |||
| 1396 | public function testGetObjectIdentifier(): void  | 
            ||
| 1397 |     { | 
            ||
| 1398 |         $admin = new PostAdmin('sonata.post.admin.post', 'Acme\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 1399 | |||
| 1400 |         $this->assertSame('sonata.post.admin.post', $admin->getObjectIdentifier()); | 
            ||
| 1401 | }  | 
            ||
| 1402 | |||
| 1403 | /**  | 
            ||
| 1404 | * @group legacy  | 
            ||
| 1405 | */  | 
            ||
| 1406 | public function testTrans(): void  | 
            ||
| 1407 |     { | 
            ||
| 1408 |         $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 1409 |         $admin->setTranslationDomain('fooMessageDomain'); | 
            ||
| 1410 | |||
| 1411 | $translator = $this->createMock(TranslatorInterface::class);  | 
            ||
| 1412 | $admin->setTranslator($translator);  | 
            ||
| 1413 | |||
| 1414 | $translator->expects($this->once())  | 
            ||
| 1415 |             ->method('trans') | 
            ||
| 1416 |             ->with($this->equalTo('foo'), $this->equalTo([]), $this->equalTo('fooMessageDomain')) | 
            ||
| 1417 |             ->willReturn('fooTranslated'); | 
            ||
| 1418 | |||
| 1419 |         $this->assertSame('fooTranslated', $admin->trans('foo')); | 
            ||
| 1420 | }  | 
            ||
| 1421 | |||
| 1422 | /**  | 
            ||
| 1423 | * @group legacy  | 
            ||
| 1424 | */  | 
            ||
| 1425 | public function testTransWithMessageDomain(): void  | 
            ||
| 1426 |     { | 
            ||
| 1427 |         $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 1428 | |||
| 1429 | $translator = $this->createMock(TranslatorInterface::class);  | 
            ||
| 1430 | $admin->setTranslator($translator);  | 
            ||
| 1431 | |||
| 1432 | $translator->expects($this->once())  | 
            ||
| 1433 |             ->method('trans') | 
            ||
| 1434 |             ->with($this->equalTo('foo'), $this->equalTo(['name' => 'Andrej']), $this->equalTo('fooMessageDomain')) | 
            ||
| 1435 |             ->willReturn('fooTranslated'); | 
            ||
| 1436 | |||
| 1437 |         $this->assertSame('fooTranslated', $admin->trans('foo', ['name' => 'Andrej'], 'fooMessageDomain')); | 
            ||
| 1438 | }  | 
            ||
| 1439 | |||
| 1440 | /**  | 
            ||
| 1441 | * @group legacy  | 
            ||
| 1442 | */  | 
            ||
| 1443 | public function testTransChoice(): void  | 
            ||
| 1444 |     { | 
            ||
| 1445 |         $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 1446 |         $admin->setTranslationDomain('fooMessageDomain'); | 
            ||
| 1447 | |||
| 1448 | $translator = $this->createMock(TranslatorInterface::class);  | 
            ||
| 1449 | $admin->setTranslator($translator);  | 
            ||
| 1450 | |||
| 1451 | $translator->expects($this->once())  | 
            ||
| 1452 |             ->method('transChoice') | 
            ||
| 1453 |             ->with($this->equalTo('foo'), $this->equalTo(2), $this->equalTo([]), $this->equalTo('fooMessageDomain')) | 
            ||
| 1454 |             ->willReturn('fooTranslated'); | 
            ||
| 1455 | |||
| 1456 |         $this->assertSame('fooTranslated', $admin->transChoice('foo', 2)); | 
            ||
| 1457 | }  | 
            ||
| 1458 | |||
| 1459 | /**  | 
            ||
| 1460 | * @group legacy  | 
            ||
| 1461 | */  | 
            ||
| 1462 | public function testTransChoiceWithMessageDomain(): void  | 
            ||
| 1463 |     { | 
            ||
| 1464 |         $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 1465 | |||
| 1466 | $translator = $this->createMock(TranslatorInterface::class);  | 
            ||
| 1467 | $admin->setTranslator($translator);  | 
            ||
| 1468 | |||
| 1469 | $translator->expects($this->once())  | 
            ||
| 1470 |             ->method('transChoice') | 
            ||
| 1471 |             ->with($this->equalTo('foo'), $this->equalTo(2), $this->equalTo(['name' => 'Andrej']), $this->equalTo('fooMessageDomain')) | 
            ||
| 1472 |             ->willReturn('fooTranslated'); | 
            ||
| 1473 | |||
| 1474 |         $this->assertSame('fooTranslated', $admin->transChoice('foo', 2, ['name' => 'Andrej'], 'fooMessageDomain')); | 
            ||
| 1475 | }  | 
            ||
| 1476 | |||
| 1477 | public function testSetFilterPersister(): void  | 
            ||
| 1478 |     { | 
            ||
| 1479 |         $admin = new class('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle\Controller\PostAdminController') extends PostAdmin { | 
            ||
| 1480 | public function persistFilters(): bool  | 
            ||
| 1484 | };  | 
            ||
| 1485 | |||
| 1486 | $filterPersister = $this->createMock(FilterPersisterInterface::class);  | 
            ||
| 1487 | |||
| 1488 | $admin->setFilterPersister($filterPersister);  | 
            ||
| 1489 | $this->assertTrue($admin->persistFilters());  | 
            ||
| 1490 | }  | 
            ||
| 1491 | |||
| 1492 | public function testGetRootCode(): void  | 
            ||
| 1493 |     { | 
            ||
| 1494 |         $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 1495 | |||
| 1496 |         $this->assertSame('sonata.post.admin.post', $admin->getRootCode()); | 
            ||
| 1497 | |||
| 1498 |         $parentAdmin = new PostAdmin('sonata.post.admin.post.parent', 'NewsBundle\Entity\PostParent', 'Sonata\NewsBundle\Controller\PostParentAdminController'); | 
            ||
| 1499 | $parentFieldDescription = $this->createMock(FieldDescriptionInterface::class);  | 
            ||
| 1500 | $parentFieldDescription->expects($this->once())  | 
            ||
| 1501 |             ->method('getAdmin') | 
            ||
| 1502 | ->willReturn($parentAdmin);  | 
            ||
| 1503 | |||
| 1504 | $this->assertFalse($admin->hasParentFieldDescription());  | 
            ||
| 1505 | $admin->setParentFieldDescription($parentFieldDescription);  | 
            ||
| 1506 | $this->assertSame($parentFieldDescription, $admin->getParentFieldDescription());  | 
            ||
| 1507 |         $this->assertSame('sonata.post.admin.post.parent', $admin->getRootCode()); | 
            ||
| 1508 | }  | 
            ||
| 1509 | |||
| 1510 | public function testGetRoot(): void  | 
            ||
| 1511 |     { | 
            ||
| 1512 |         $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 1513 | |||
| 1514 | $this->assertSame($admin, $admin->getRoot());  | 
            ||
| 1515 | |||
| 1516 |         $parentAdmin = new PostAdmin('sonata.post.admin.post.parent', 'NewsBundle\Entity\PostParent', 'Sonata\NewsBundle\Controller\PostParentAdminController'); | 
            ||
| 1517 | $parentFieldDescription = $this->createMock(FieldDescriptionInterface::class);  | 
            ||
| 1518 | $parentFieldDescription->expects($this->once())  | 
            ||
| 1519 |             ->method('getAdmin') | 
            ||
| 1520 | ->willReturn($parentAdmin);  | 
            ||
| 1521 | |||
| 1522 | $this->assertFalse($admin->hasParentFieldDescription());  | 
            ||
| 1523 | $admin->setParentFieldDescription($parentFieldDescription);  | 
            ||
| 1524 | $this->assertSame($parentFieldDescription, $admin->getParentFieldDescription());  | 
            ||
| 1525 | $this->assertSame($parentAdmin, $admin->getRoot());  | 
            ||
| 1526 | }  | 
            ||
| 1527 | |||
| 1528 | public function testGetExportFields(): void  | 
            ||
| 1529 |     { | 
            ||
| 1530 |         $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); | 
            ||
| 1531 | |||
| 1532 | $modelManager = $this->createMock(ModelManagerInterface::class);  | 
            ||
| 1533 | $modelManager->expects($this->once())  | 
            ||
| 1534 |             ->method('getExportFields') | 
            ||
| 1535 |             ->with($this->equalTo('NewsBundle\Entity\Post')) | 
            ||
| 1536 | ->willReturn(['foo', 'bar']);  | 
            ||
| 1537 | |||
| 1541 | |||
| 1542 | public function testGetPersistentParametersWithNoExtension(): void  | 
            ||
| 1548 | |||
| 1549 | public function testGetPersistentParametersWithInvalidExtension(): void  | 
            ||
| 1562 | |||
| 1563 | public function testGetPersistentParametersWithValidExtension(): void  | 
            ||
| 1578 | |||
| 1579 | public function testGetNewInstanceForChildAdminWithParentValue(): void  | 
            ||
| 1615 | |||
| 1616 | public function testGetNewInstanceForChildAdminWithCollectionParentValue(): void  | 
            ||
| 1652 | |||
| 1653 | public function testGetNewInstanceForEmbededAdminWithCollectionParentValue(): void  | 
            ||
| 1694 | |||
| 1695 | public function testFormAddPostSubmitEventForPreValidation(): void  | 
            ||
| 1757 | |||
| 1758 | public function testRemoveFieldFromFormGroup(): void  | 
            ||
| 1784 | |||
| 1785 | public function testGetFilterParameters(): void  | 
            ||
| 1825 | |||
| 1826 | public function testGetFilterFieldDescription(): void  | 
            ||
| 1897 | |||
| 1898 | public function testGetSubjectNoRequest(): void  | 
            ||
| 1910 | |||
| 1911 | public function testGetSideMenu(): void  | 
            ||
| 1935 | |||
| 1936 | /**  | 
            ||
| 1937 | * @return array  | 
            ||
| 1938 | */  | 
            ||
| 1939 | public function provideGetSubject()  | 
            ||
| 1949 | |||
| 1950 | /**  | 
            ||
| 1951 | * @dataProvider provideGetSubject  | 
            ||
| 1952 | */  | 
            ||
| 1953 | public function testGetSubjectFailed($id): void  | 
            ||
| 1968 | |||
| 1969 | /**  | 
            ||
| 1970 | * @dataProvider provideGetSubject  | 
            ||
| 1971 | */  | 
            ||
| 1972 | public function testGetSubject($id): void  | 
            ||
| 1991 | |||
| 1992 | public function testGetSubjectWithParentDescription(): void  | 
            ||
| 2021 | |||
| 2022 | /**  | 
            ||
| 2023 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::configureActionButtons  | 
            ||
| 2024 | */  | 
            ||
| 2025 | public function testGetActionButtonsList(): void  | 
            ||
| 2058 | |||
| 2059 | /**  | 
            ||
| 2060 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::configureActionButtons  | 
            ||
| 2061 | */  | 
            ||
| 2062 | public function testGetActionButtonsListCreateDisabled(): void  | 
            ||
| 2076 | |||
| 2077 | /**  | 
            ||
| 2078 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::configureBatchActions  | 
            ||
| 2079 | */  | 
            ||
| 2080 | public function testGetBatchActions(): void  | 
            ||
| 2134 | |||
| 2135 | /**  | 
            ||
| 2136 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::showMosaicButton  | 
            ||
| 2137 | */  | 
            ||
| 2138 | public function testShowMosaicButton(): void  | 
            ||
| 2147 | |||
| 2148 | /**  | 
            ||
| 2149 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::showMosaicButton  | 
            ||
| 2150 | */  | 
            ||
| 2151 | public function testShowMosaicButtonHideMosaic(): void  | 
            ||
| 2161 | |||
| 2162 | /**  | 
            ||
| 2163 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getDashboardActions  | 
            ||
| 2164 | * @dataProvider provideGetBaseRouteName  | 
            ||
| 2165 | */  | 
            ||
| 2166 | public function testDefaultDashboardActionsArePresent(string $objFqn, string $expected): void  | 
            ||
| 2197 | |||
| 2198 | public function testDefaultFilters(): void  | 
            ||
| 2257 | |||
| 2258 | /**  | 
            ||
| 2259 | * @group legacy  | 
            ||
| 2260 | */  | 
            ||
| 2261 | public function testDefaultBreadcrumbsBuilder(): void  | 
            ||
| 2285 | |||
| 2286 | /**  | 
            ||
| 2287 | * @group legacy  | 
            ||
| 2288 | */  | 
            ||
| 2289 | public function testBreadcrumbsBuilderSetter(): void  | 
            ||
| 2299 | |||
| 2300 | /**  | 
            ||
| 2301 | * @group legacy  | 
            ||
| 2302 | */  | 
            ||
| 2303 | public function testGetBreadcrumbs(): void  | 
            ||
| 2313 | |||
| 2314 | /**  | 
            ||
| 2315 | * @group legacy  | 
            ||
| 2316 | */  | 
            ||
| 2317 | public function testBuildBreadcrumbs(): void  | 
            ||
| 2334 | |||
| 2335 | /**  | 
            ||
| 2336 | * NEXT_MAJOR: remove this method.  | 
            ||
| 2337 | *  | 
            ||
| 2338 | * @group legacy  | 
            ||
| 2339 | */  | 
            ||
| 2340 | public function testCreateQueryLegacyCallWorks(): void  | 
            ||
| 2355 | |||
| 2356 | public function testGetDataSourceIterator(): void  | 
            ||
| 2398 | |||
| 2399 | public function testCircularChildAdmin(): void  | 
            ||
| 2419 | |||
| 2420 | public function testCircularChildAdminTripleLevel(): void  | 
            ||
| 2446 | |||
| 2447 | public function testCircularChildAdminWithItself(): void  | 
            ||
| 2461 | |||
| 2462 | public function testGetRootAncestor(): void  | 
            ||
| 2496 | |||
| 2497 | public function testGetChildDepth(): void  | 
            ||
| 2531 | |||
| 2532 | public function testGetCurrentLeafChildAdmin(): void  | 
            ||
| 2569 | |||
| 2570 | public function testAdminWithoutControllerName(): void  | 
            ||
| 2576 | |||
| 2577 | public function testAdminAvoidInifiniteLoop(): void  | 
            ||
| 2607 | |||
| 2608 | /**  | 
            ||
| 2609 | * NEXT_MAJOR: Remove this test and its data provider.  | 
            ||
| 2610 | *  | 
            ||
| 2611 | * @group legacy  | 
            ||
| 2612 | *  | 
            ||
| 2613 | * @dataProvider getDeprecatedAbstractAdminConstructorArgs  | 
            ||
| 2614 | *  | 
            ||
| 2615 | * @expectedDeprecation Passing other type than string%S as argument %d for method Sonata\AdminBundle\Admin\AbstractAdmin::__construct() is deprecated since sonata-project/admin-bundle 3.65. It will accept only string%S in version 4.0.  | 
            ||
| 2616 | */  | 
            ||
| 2617 | public function testDeprecatedAbstractAdminConstructorArgs($code, $class, $baseControllerName): void  | 
            ||
| 2621 | |||
| 2622 | public function getDeprecatedAbstractAdminConstructorArgs(): iterable  | 
            ||
| 2636 | }  | 
            ||
| 2637 | 
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: