| Total Complexity | 53 |
| Total Lines | 2618 |
| 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 |
||
| 90 | class AdminTest extends TestCase |
||
| 91 | { |
||
| 92 | protected $cacheTempFolder; |
||
| 93 | |||
| 94 | protected function setUp(): void |
||
| 95 | { |
||
| 96 | $this->cacheTempFolder = sprintf('%s/sonata_test_route', sys_get_temp_dir()); |
||
| 97 | $filesystem = new Filesystem(); |
||
| 98 | $filesystem->remove($this->cacheTempFolder); |
||
| 99 | } |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::__construct |
||
| 103 | */ |
||
| 104 | public function testConstructor(): void |
||
| 105 | { |
||
| 106 | $class = 'Application\Sonata\NewsBundle\Entity\Post'; |
||
| 107 | $baseControllerName = 'Sonata\NewsBundle\Controller\PostAdminController'; |
||
| 108 | |||
| 109 | $admin = new PostAdmin('sonata.post.admin.post', $class, $baseControllerName); |
||
| 110 | $this->assertInstanceOf(AbstractAdmin::class, $admin); |
||
| 111 | $this->assertSame($class, $admin->getClass()); |
||
| 112 | $this->assertSame($baseControllerName, $admin->getBaseControllerName()); |
||
| 113 | } |
||
| 114 | |||
| 115 | public function testGetClass(): void |
||
| 116 | { |
||
| 117 | $class = Post::class; |
||
| 118 | $baseControllerName = 'Sonata\NewsBundle\Controller\PostAdminController'; |
||
| 119 | |||
| 120 | $admin = new PostAdmin('sonata.post.admin.post', $class, $baseControllerName); |
||
| 121 | |||
| 122 | $admin->setModelManager($this->getMockForAbstractClass(ModelManagerInterface::class)); |
||
| 123 | |||
| 124 | $admin->setSubject(new BlogPost()); |
||
| 125 | $this->assertSame(BlogPost::class, $admin->getClass()); |
||
| 126 | |||
| 127 | $admin->setSubClasses(['foo']); |
||
| 128 | $this->assertSame(BlogPost::class, $admin->getClass()); |
||
| 129 | |||
| 130 | $admin->setSubject(null); |
||
| 131 | $admin->setSubClasses([]); |
||
| 132 | $this->assertSame($class, $admin->getClass()); |
||
| 133 | |||
| 134 | $admin->setSubClasses(['foo' => 'bar']); |
||
| 135 | $admin->setRequest(new Request(['subclass' => 'foo'])); |
||
| 136 | $this->assertSame('bar', $admin->getClass()); |
||
| 137 | } |
||
| 138 | |||
| 139 | public function testGetClassException(): void |
||
| 140 | { |
||
| 141 | $this->expectException(\RuntimeException::class); |
||
| 142 | $this->expectExceptionMessage('Feature not implemented: an embedded admin cannot have subclass'); |
||
| 143 | |||
| 144 | $class = 'Application\Sonata\NewsBundle\Entity\Post'; |
||
| 145 | $baseControllerName = 'Sonata\NewsBundle\Controller\PostAdminController'; |
||
| 146 | |||
| 147 | $admin = new PostAdmin('sonata.post.admin.post', $class, $baseControllerName); |
||
| 148 | $admin->setParentFieldDescription(new FieldDescription()); |
||
| 149 | $admin->setSubClasses(['foo' => 'bar']); |
||
| 150 | $admin->setRequest(new Request(['subclass' => 'foo'])); |
||
| 151 | $admin->getClass(); |
||
| 152 | } |
||
| 153 | |||
| 154 | public function testCheckAccessThrowsExceptionOnMadeUpAction(): void |
||
| 155 | { |
||
| 156 | $admin = new PostAdmin( |
||
| 157 | 'sonata.post.admin.post', |
||
| 158 | 'Application\Sonata\NewsBundle\Entity\Post', |
||
| 159 | 'Sonata\NewsBundle\Controller\PostAdminController' |
||
| 160 | ); |
||
| 161 | $this->expectException( |
||
| 162 | \InvalidArgumentException::class |
||
| 163 | ); |
||
| 164 | $this->expectExceptionMessage( |
||
| 165 | 'Action "made-up" could not be found' |
||
| 166 | ); |
||
| 167 | $admin->checkAccess('made-up'); |
||
| 168 | } |
||
| 169 | |||
| 170 | public function testCheckAccessThrowsAccessDeniedException(): void |
||
| 171 | { |
||
| 172 | $admin = new PostAdmin( |
||
| 173 | 'sonata.post.admin.post', |
||
| 174 | 'Application\Sonata\NewsBundle\Entity\Post', |
||
| 175 | 'Sonata\NewsBundle\Controller\PostAdminController' |
||
| 176 | ); |
||
| 177 | $securityHandler = $this->prophesize(SecurityHandlerInterface::class); |
||
| 178 | $securityHandler->isGranted($admin, 'CUSTOM_ROLE', $admin)->willReturn(true); |
||
| 179 | $securityHandler->isGranted($admin, 'EXTRA_CUSTOM_ROLE', $admin)->willReturn(false); |
||
| 180 | $customExtension = $this->prophesize(AbstractAdminExtension::class); |
||
| 181 | $customExtension->getAccessMapping($admin)->willReturn( |
||
| 182 | ['custom_action' => ['CUSTOM_ROLE', 'EXTRA_CUSTOM_ROLE']] |
||
| 183 | ); |
||
| 184 | $admin->addExtension($customExtension->reveal()); |
||
| 185 | $admin->setSecurityHandler($securityHandler->reveal()); |
||
| 186 | $this->expectException( |
||
| 187 | AccessDeniedException::class |
||
| 188 | ); |
||
| 189 | $this->expectExceptionMessage( |
||
| 190 | 'Access Denied to the action custom_action and role EXTRA_CUSTOM_ROLE' |
||
| 191 | ); |
||
| 192 | $admin->checkAccess('custom_action'); |
||
| 193 | } |
||
| 194 | |||
| 195 | public function testHasAccessOnMadeUpAction(): void |
||
| 196 | { |
||
| 197 | $admin = new PostAdmin( |
||
| 198 | 'sonata.post.admin.post', |
||
| 199 | 'Application\Sonata\NewsBundle\Entity\Post', |
||
| 200 | 'Sonata\NewsBundle\Controller\PostAdminController' |
||
| 201 | ); |
||
| 202 | |||
| 203 | $this->assertFalse($admin->hasAccess('made-up')); |
||
| 204 | } |
||
| 205 | |||
| 206 | public function testHasAccess(): void |
||
| 207 | { |
||
| 208 | $admin = new PostAdmin( |
||
| 209 | 'sonata.post.admin.post', |
||
| 210 | 'Application\Sonata\NewsBundle\Entity\Post', |
||
| 211 | 'Sonata\NewsBundle\Controller\PostAdminController' |
||
| 212 | ); |
||
| 213 | $securityHandler = $this->prophesize(SecurityHandlerInterface::class); |
||
| 214 | $securityHandler->isGranted($admin, 'CUSTOM_ROLE', $admin)->willReturn(true); |
||
| 215 | $securityHandler->isGranted($admin, 'EXTRA_CUSTOM_ROLE', $admin)->willReturn(false); |
||
| 216 | $customExtension = $this->prophesize(AbstractAdminExtension::class); |
||
| 217 | $customExtension->getAccessMapping($admin)->willReturn( |
||
| 218 | ['custom_action' => ['CUSTOM_ROLE', 'EXTRA_CUSTOM_ROLE']] |
||
| 219 | ); |
||
| 220 | $admin->addExtension($customExtension->reveal()); |
||
| 221 | $admin->setSecurityHandler($securityHandler->reveal()); |
||
| 222 | |||
| 223 | $this->assertFalse($admin->hasAccess('custom_action')); |
||
| 224 | } |
||
| 225 | |||
| 226 | public function testHasAccessAllowsAccess(): void |
||
| 227 | { |
||
| 228 | $admin = new PostAdmin( |
||
| 229 | 'sonata.post.admin.post', |
||
| 230 | 'Application\Sonata\NewsBundle\Entity\Post', |
||
| 231 | 'Sonata\NewsBundle\Controller\PostAdminController' |
||
| 232 | ); |
||
| 233 | $securityHandler = $this->prophesize(SecurityHandlerInterface::class); |
||
| 234 | $securityHandler->isGranted($admin, 'CUSTOM_ROLE', $admin)->willReturn(true); |
||
| 235 | $securityHandler->isGranted($admin, 'EXTRA_CUSTOM_ROLE', $admin)->willReturn(true); |
||
| 236 | $customExtension = $this->prophesize(AbstractAdminExtension::class); |
||
| 237 | $customExtension->getAccessMapping($admin)->willReturn( |
||
| 238 | ['custom_action' => ['CUSTOM_ROLE', 'EXTRA_CUSTOM_ROLE']] |
||
| 239 | ); |
||
| 240 | $admin->addExtension($customExtension->reveal()); |
||
| 241 | $admin->setSecurityHandler($securityHandler->reveal()); |
||
| 242 | |||
| 243 | $this->assertTrue($admin->hasAccess('custom_action')); |
||
| 244 | } |
||
| 245 | |||
| 246 | public function testHasAccessAllowsAccessEditAction(): void |
||
| 247 | { |
||
| 248 | $admin = new PostAdmin( |
||
| 249 | 'sonata.post.admin.post', |
||
| 250 | 'Application\Sonata\NewsBundle\Entity\Post', |
||
| 251 | 'Sonata\NewsBundle\Controller\PostAdminController' |
||
| 252 | ); |
||
| 253 | $securityHandler = $this->prophesize(SecurityHandlerInterface::class); |
||
| 254 | $securityHandler->isGranted($admin, 'EDIT_ROLE', $admin)->willReturn(true); |
||
| 255 | $customExtension = $this->prophesize(AbstractAdminExtension::class); |
||
| 256 | $customExtension->getAccessMapping($admin)->willReturn( |
||
| 257 | ['edit_action' => ['EDIT_ROLE']] |
||
| 258 | ); |
||
| 259 | $admin->addExtension($customExtension->reveal()); |
||
| 260 | $admin->setSecurityHandler($securityHandler->reveal()); |
||
| 261 | |||
| 262 | $this->assertTrue($admin->hasAccess('edit_action')); |
||
| 263 | } |
||
| 264 | |||
| 265 | /** |
||
| 266 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::hasChild |
||
| 267 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::addChild |
||
| 268 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getChild |
||
| 269 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::isChild |
||
| 270 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::hasChildren |
||
| 271 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getChildren |
||
| 272 | */ |
||
| 273 | public function testChildren(): void |
||
| 274 | { |
||
| 275 | $postAdmin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 276 | $this->assertFalse($postAdmin->hasChildren()); |
||
| 277 | $this->assertFalse($postAdmin->hasChild('comment')); |
||
| 278 | |||
| 279 | $commentAdmin = new CommentAdmin('sonata.post.admin.comment', 'Application\Sonata\NewsBundle\Entity\Comment', 'Sonata\NewsBundle\Controller\CommentAdminController'); |
||
| 280 | $postAdmin->addChild($commentAdmin, 'post'); |
||
| 281 | |||
| 282 | $this->assertTrue($postAdmin->hasChildren()); |
||
| 283 | $this->assertTrue($postAdmin->hasChild('sonata.post.admin.comment')); |
||
| 284 | |||
| 285 | $this->assertSame('sonata.post.admin.comment', $postAdmin->getChild('sonata.post.admin.comment')->getCode()); |
||
| 286 | $this->assertSame('sonata.post.admin.post|sonata.post.admin.comment', $postAdmin->getChild('sonata.post.admin.comment')->getBaseCodeRoute()); |
||
| 287 | $this->assertSame($postAdmin, $postAdmin->getChild('sonata.post.admin.comment')->getParent()); |
||
| 288 | $this->assertSame('post', $commentAdmin->getParentAssociationMapping()); |
||
| 289 | |||
| 290 | $this->assertFalse($postAdmin->isChild()); |
||
| 291 | $this->assertTrue($commentAdmin->isChild()); |
||
| 292 | |||
| 293 | $this->assertSame(['sonata.post.admin.comment' => $commentAdmin], $postAdmin->getChildren()); |
||
| 294 | } |
||
| 295 | |||
| 296 | /** |
||
| 297 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getParent |
||
| 298 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::setParent |
||
| 299 | */ |
||
| 300 | public function testParent(): void |
||
| 301 | { |
||
| 302 | $postAdmin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 303 | $commentAdmin = new CommentAdmin('sonata.post.admin.comment', 'Application\Sonata\NewsBundle\Entity\Comment', 'Sonata\NewsBundle\Controller\CommentAdminController'); |
||
| 304 | $this->assertFalse($commentAdmin->isChild()); |
||
| 305 | $this->assertFalse($commentAdmin->hasParentFieldDescription()); |
||
| 306 | |||
| 307 | $commentAdmin->setParent($postAdmin, 'post'); |
||
| 308 | |||
| 309 | $this->assertSame($postAdmin, $commentAdmin->getParent()); |
||
| 310 | $this->assertSame('post', $commentAdmin->getParentAssociationMapping()); |
||
| 311 | } |
||
| 312 | |||
| 313 | /** |
||
| 314 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::configure |
||
| 315 | */ |
||
| 316 | public function testConfigure(): void |
||
| 317 | { |
||
| 318 | $admin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 319 | $this->assertNotNull($admin->getUniqid()); |
||
| 320 | |||
| 321 | $admin->initialize(); |
||
| 322 | $this->assertNotNull($admin->getUniqid()); |
||
| 323 | $this->assertSame('Post', $admin->getClassnameLabel()); |
||
| 324 | |||
| 325 | $admin = new CommentAdmin('sonata.post.admin.comment', 'Application\Sonata\NewsBundle\Entity\Comment', 'Sonata\NewsBundle\Controller\CommentAdminController'); |
||
| 326 | $admin->setClassnameLabel('postcomment'); |
||
| 327 | |||
| 328 | $admin->initialize(); |
||
| 329 | $this->assertSame('postcomment', $admin->getClassnameLabel()); |
||
| 330 | } |
||
| 331 | |||
| 332 | public function testConfigureWithValidParentAssociationMapping(): void |
||
| 333 | { |
||
| 334 | $admin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 335 | $admin->setParentAssociationMapping('Category'); |
||
| 336 | |||
| 337 | $admin->initialize(); |
||
| 338 | $this->assertSame('Category', $admin->getParentAssociationMapping()); |
||
| 339 | } |
||
| 340 | |||
| 341 | public function provideGetBaseRoutePattern() |
||
| 342 | { |
||
| 343 | return [ |
||
| 344 | [ |
||
| 345 | 'Application\Sonata\NewsBundle\Entity\Post', |
||
| 346 | '/sonata/news/post', |
||
| 347 | ], |
||
| 348 | [ |
||
| 349 | 'Application\Sonata\NewsBundle\Document\Post', |
||
| 350 | '/sonata/news/post', |
||
| 351 | ], |
||
| 352 | [ |
||
| 353 | 'MyApplication\MyBundle\Entity\Post', |
||
| 354 | '/myapplication/my/post', |
||
| 355 | ], |
||
| 356 | [ |
||
| 357 | 'MyApplication\MyBundle\Entity\Post\Category', |
||
| 358 | '/myapplication/my/post-category', |
||
| 359 | ], |
||
| 360 | [ |
||
| 361 | 'MyApplication\MyBundle\Entity\Product\Category', |
||
| 362 | '/myapplication/my/product-category', |
||
| 363 | ], |
||
| 364 | [ |
||
| 365 | 'MyApplication\MyBundle\Entity\Other\Product\Category', |
||
| 366 | '/myapplication/my/other-product-category', |
||
| 367 | ], |
||
| 368 | [ |
||
| 369 | 'Symfony\Cmf\Bundle\FooBundle\Document\Menu', |
||
| 370 | '/cmf/foo/menu', |
||
| 371 | ], |
||
| 372 | [ |
||
| 373 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\Phpcr\Menu', |
||
| 374 | '/cmf/foo/menu', |
||
| 375 | ], |
||
| 376 | [ |
||
| 377 | 'Symfony\Bundle\BarBarBundle\Doctrine\Phpcr\Menu', |
||
| 378 | '/symfony/barbar/menu', |
||
| 379 | ], |
||
| 380 | [ |
||
| 381 | 'Symfony\Bundle\BarBarBundle\Doctrine\Phpcr\Menu\Item', |
||
| 382 | '/symfony/barbar/menu-item', |
||
| 383 | ], |
||
| 384 | [ |
||
| 385 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\Orm\Menu', |
||
| 386 | '/cmf/foo/menu', |
||
| 387 | ], |
||
| 388 | [ |
||
| 389 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\MongoDB\Menu', |
||
| 390 | '/cmf/foo/menu', |
||
| 391 | ], |
||
| 392 | [ |
||
| 393 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\CouchDB\Menu', |
||
| 394 | '/cmf/foo/menu', |
||
| 395 | ], |
||
| 396 | [ |
||
| 397 | 'AppBundle\Entity\User', |
||
| 398 | '/app/user', |
||
| 399 | ], |
||
| 400 | [ |
||
| 401 | 'App\Entity\User', |
||
| 402 | '/app/user', |
||
| 403 | ], |
||
| 404 | ]; |
||
| 405 | } |
||
| 406 | |||
| 407 | /** |
||
| 408 | * @dataProvider provideGetBaseRoutePattern |
||
| 409 | */ |
||
| 410 | public function testGetBaseRoutePattern(string $objFqn, string $expected): void |
||
| 411 | { |
||
| 412 | $admin = new PostAdmin('sonata.post.admin.post', $objFqn, 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 413 | $this->assertSame($expected, $admin->getBaseRoutePattern()); |
||
| 414 | } |
||
| 415 | |||
| 416 | /** |
||
| 417 | * @dataProvider provideGetBaseRoutePattern |
||
| 418 | */ |
||
| 419 | public function testGetBaseRoutePatternWithChildAdmin(string $objFqn, string $expected): void |
||
| 420 | { |
||
| 421 | $postAdmin = new PostAdmin('sonata.post.admin.post', $objFqn, 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 422 | $commentAdmin = new CommentAdmin('sonata.post.admin.comment', 'Application\Sonata\NewsBundle\Entity\Comment', 'Sonata\NewsBundle\Controller\CommentAdminController'); |
||
| 423 | $commentAdmin->setParent($postAdmin, 'post'); |
||
| 424 | |||
| 425 | $this->assertSame(sprintf('%s/{id}/comment', $expected), $commentAdmin->getBaseRoutePattern()); |
||
| 426 | } |
||
| 427 | |||
| 428 | /** |
||
| 429 | * @dataProvider provideGetBaseRoutePattern |
||
| 430 | */ |
||
| 431 | public function testGetBaseRoutePatternWithTwoNestedChildAdmin(string $objFqn, string $expected): void |
||
| 432 | { |
||
| 433 | $postAdmin = new PostAdmin('sonata.post.admin.post', $objFqn, 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 434 | $commentAdmin = new CommentAdmin( |
||
| 435 | 'sonata.post.admin.comment', |
||
| 436 | 'Application\Sonata\NewsBundle\Entity\Comment', |
||
| 437 | 'Sonata\NewsBundle\Controller\CommentAdminController' |
||
| 438 | ); |
||
| 439 | $commentVoteAdmin = new CommentVoteAdmin( |
||
| 440 | 'sonata.post.admin.comment_vote', |
||
| 441 | 'Application\Sonata\NewsBundle\Entity\CommentVote', |
||
| 442 | 'Sonata\NewsBundle\Controller\CommentVoteAdminController' |
||
| 443 | ); |
||
| 444 | $commentAdmin->setParent($postAdmin, 'post'); |
||
| 445 | $commentVoteAdmin->setParent($commentAdmin, 'comment'); |
||
| 446 | |||
| 447 | $this->assertSame(sprintf('%s/{id}/comment/{childId}/commentvote', $expected), $commentVoteAdmin->getBaseRoutePattern()); |
||
| 448 | } |
||
| 449 | |||
| 450 | public function testGetBaseRoutePatternWithSpecifedPattern(): void |
||
| 451 | { |
||
| 452 | $postAdmin = new PostWithCustomRouteAdmin('sonata.post.admin.post_with_custom_route', 'Application\Sonata\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostWithCustomRouteAdminController'); |
||
| 453 | |||
| 454 | $this->assertSame('/post-custom', $postAdmin->getBaseRoutePattern()); |
||
| 455 | } |
||
| 456 | |||
| 457 | public function testGetBaseRoutePatternWithChildAdminAndWithSpecifedPattern(): void |
||
| 458 | { |
||
| 459 | $postAdmin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 460 | $commentAdmin = new CommentWithCustomRouteAdmin('sonata.post.admin.comment_with_custom_route', 'Application\Sonata\NewsBundle\Entity\Comment', 'Sonata\NewsBundle\Controller\CommentWithCustomRouteAdminController'); |
||
| 461 | $commentAdmin->setParent($postAdmin, 'post'); |
||
| 462 | |||
| 463 | $this->assertSame('/sonata/news/post/{id}/comment-custom', $commentAdmin->getBaseRoutePattern()); |
||
| 464 | } |
||
| 465 | |||
| 466 | public function testGetBaseRoutePatternWithUnreconizedClassname(): void |
||
| 467 | { |
||
| 468 | $this->expectException(\RuntimeException::class); |
||
| 469 | |||
| 470 | $admin = new PostAdmin('sonata.post.admin.post', 'News\Thing\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 471 | $admin->getBaseRoutePattern(); |
||
| 472 | } |
||
| 473 | |||
| 474 | public function provideGetBaseRouteName() |
||
| 475 | { |
||
| 476 | return [ |
||
| 477 | [ |
||
| 478 | 'Application\Sonata\NewsBundle\Entity\Post', |
||
| 479 | 'admin_sonata_news_post', |
||
| 480 | ], |
||
| 481 | [ |
||
| 482 | 'Application\Sonata\NewsBundle\Document\Post', |
||
| 483 | 'admin_sonata_news_post', |
||
| 484 | ], |
||
| 485 | [ |
||
| 486 | 'MyApplication\MyBundle\Entity\Post', |
||
| 487 | 'admin_myapplication_my_post', |
||
| 488 | ], |
||
| 489 | [ |
||
| 490 | 'MyApplication\MyBundle\Entity\Post\Category', |
||
| 491 | 'admin_myapplication_my_post_category', |
||
| 492 | ], |
||
| 493 | [ |
||
| 494 | 'MyApplication\MyBundle\Entity\Product\Category', |
||
| 495 | 'admin_myapplication_my_product_category', |
||
| 496 | ], |
||
| 497 | [ |
||
| 498 | 'MyApplication\MyBundle\Entity\Other\Product\Category', |
||
| 499 | 'admin_myapplication_my_other_product_category', |
||
| 500 | ], |
||
| 501 | [ |
||
| 502 | 'Symfony\Cmf\Bundle\FooBundle\Document\Menu', |
||
| 503 | 'admin_cmf_foo_menu', |
||
| 504 | ], |
||
| 505 | [ |
||
| 506 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\Phpcr\Menu', |
||
| 507 | 'admin_cmf_foo_menu', |
||
| 508 | ], |
||
| 509 | [ |
||
| 510 | 'Symfony\Bundle\BarBarBundle\Doctrine\Phpcr\Menu', |
||
| 511 | 'admin_symfony_barbar_menu', |
||
| 512 | ], |
||
| 513 | [ |
||
| 514 | 'Symfony\Bundle\BarBarBundle\Doctrine\Phpcr\Menu\Item', |
||
| 515 | 'admin_symfony_barbar_menu_item', |
||
| 516 | ], |
||
| 517 | [ |
||
| 518 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\Orm\Menu', |
||
| 519 | 'admin_cmf_foo_menu', |
||
| 520 | ], |
||
| 521 | [ |
||
| 522 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\MongoDB\Menu', |
||
| 523 | 'admin_cmf_foo_menu', |
||
| 524 | ], |
||
| 525 | [ |
||
| 526 | 'Symfony\Cmf\Bundle\FooBundle\Doctrine\CouchDB\Menu', |
||
| 527 | 'admin_cmf_foo_menu', |
||
| 528 | ], |
||
| 529 | [ |
||
| 530 | 'AppBundle\Entity\User', |
||
| 531 | 'admin_app_user', |
||
| 532 | ], |
||
| 533 | [ |
||
| 534 | 'App\Entity\User', |
||
| 535 | 'admin_app_user', |
||
| 536 | ], |
||
| 537 | ]; |
||
| 538 | } |
||
| 539 | |||
| 540 | /** |
||
| 541 | * @dataProvider provideGetBaseRouteName |
||
| 542 | */ |
||
| 543 | public function testGetBaseRouteName(string $objFqn, string $expected): void |
||
| 544 | { |
||
| 545 | $admin = new PostAdmin('sonata.post.admin.post', $objFqn, 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 546 | |||
| 547 | $this->assertSame($expected, $admin->getBaseRouteName()); |
||
| 548 | } |
||
| 549 | |||
| 550 | /** |
||
| 551 | * @group legacy |
||
| 552 | * @expectedDeprecation Calling "addChild" without second argument is deprecated since sonata-project/admin-bundle 3.35 and will not be allowed in 4.0. |
||
| 553 | * @dataProvider provideGetBaseRouteName |
||
| 554 | */ |
||
| 555 | public function testGetBaseRouteNameWithChildAdmin(string $objFqn, string $expected): void |
||
| 556 | { |
||
| 557 | $routeGenerator = new DefaultRouteGenerator( |
||
| 558 | $this->createMock(RouterInterface::class), |
||
| 559 | new RoutesCache($this->cacheTempFolder, true) |
||
| 560 | ); |
||
| 561 | |||
| 562 | $container = new Container(); |
||
| 563 | $pool = new Pool($container, 'Sonata Admin', '/path/to/pic.png'); |
||
| 564 | |||
| 565 | $pathInfo = new PathInfoBuilder($this->createMock(AuditManagerInterface::class)); |
||
| 566 | $postAdmin = new PostAdmin('sonata.post.admin.post', $objFqn, 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 567 | $container->set('sonata.post.admin.post', $postAdmin); |
||
| 568 | $postAdmin->setConfigurationPool($pool); |
||
| 569 | $postAdmin->setRouteBuilder($pathInfo); |
||
| 570 | $postAdmin->setRouteGenerator($routeGenerator); |
||
| 571 | $postAdmin->initialize(); |
||
| 572 | |||
| 573 | $commentAdmin = new CommentAdmin( |
||
| 574 | 'sonata.post.admin.comment', |
||
| 575 | 'Application\Sonata\NewsBundle\Entity\Comment', |
||
| 576 | 'Sonata\NewsBundle\Controller\CommentAdminController' |
||
| 577 | ); |
||
| 578 | $container->set('sonata.post.admin.comment', $commentAdmin); |
||
| 579 | $commentAdmin->setConfigurationPool($pool); |
||
| 580 | $commentAdmin->setRouteBuilder($pathInfo); |
||
| 581 | $commentAdmin->setRouteGenerator($routeGenerator); |
||
| 582 | $commentAdmin->initialize(); |
||
| 583 | |||
| 584 | $postAdmin->addChild($commentAdmin, 'post'); |
||
| 585 | |||
| 586 | $commentVoteAdmin = new CommentVoteAdmin( |
||
| 587 | 'sonata.post.admin.comment_vote', |
||
| 588 | 'Application\Sonata\NewsBundle\Entity\CommentVote', |
||
| 589 | 'Sonata\NewsBundle\Controller\CommentVoteAdminController' |
||
| 590 | ); |
||
| 591 | |||
| 592 | $container->set('sonata.post.admin.comment_vote', $commentVoteAdmin); |
||
| 593 | $commentVoteAdmin->setConfigurationPool($pool); |
||
| 594 | $commentVoteAdmin->setRouteBuilder($pathInfo); |
||
| 595 | $commentVoteAdmin->setRouteGenerator($routeGenerator); |
||
| 596 | $commentVoteAdmin->initialize(); |
||
| 597 | |||
| 598 | $commentAdmin->addChild($commentVoteAdmin); |
||
| 599 | $pool->setAdminServiceIds([ |
||
| 600 | 'sonata.post.admin.post', |
||
| 601 | 'sonata.post.admin.comment', |
||
| 602 | 'sonata.post.admin.comment_vote', |
||
| 603 | ]); |
||
| 604 | |||
| 605 | $this->assertSame(sprintf('%s_comment', $expected), $commentAdmin->getBaseRouteName()); |
||
| 606 | |||
| 607 | $this->assertTrue($postAdmin->hasRoute('show')); |
||
| 608 | $this->assertTrue($postAdmin->hasRoute('sonata.post.admin.post.show')); |
||
| 609 | $this->assertTrue($postAdmin->hasRoute('sonata.post.admin.post|sonata.post.admin.comment.show')); |
||
| 610 | $this->assertTrue($postAdmin->hasRoute('sonata.post.admin.post|sonata.post.admin.comment|sonata.post.admin.comment_vote.show')); |
||
| 611 | $this->assertTrue($postAdmin->hasRoute('sonata.post.admin.comment.list')); |
||
| 612 | $this->assertTrue($postAdmin->hasRoute('sonata.post.admin.comment|sonata.post.admin.comment_vote.list')); |
||
| 613 | $this->assertFalse($postAdmin->hasRoute('sonata.post.admin.post|sonata.post.admin.comment.edit')); |
||
| 614 | $this->assertFalse($commentAdmin->hasRoute('edit')); |
||
| 615 | $this->assertSame('post', $commentAdmin->getParentAssociationMapping()); |
||
| 616 | |||
| 617 | /* |
||
| 618 | * Test the route name from request |
||
| 619 | */ |
||
| 620 | $postListRequest = new Request( |
||
| 621 | [], |
||
| 622 | [], |
||
| 623 | [ |
||
| 624 | '_route' => sprintf('%s_list', $postAdmin->getBaseRouteName()), |
||
| 625 | ] |
||
| 626 | ); |
||
| 627 | |||
| 628 | $postAdmin->setRequest($postListRequest); |
||
| 629 | $commentAdmin->setRequest($postListRequest); |
||
| 630 | |||
| 631 | $this->assertTrue($postAdmin->isCurrentRoute('list')); |
||
| 632 | $this->assertFalse($postAdmin->isCurrentRoute('create')); |
||
| 633 | $this->assertFalse($commentAdmin->isCurrentRoute('list')); |
||
| 634 | $this->assertFalse($commentVoteAdmin->isCurrentRoute('list')); |
||
| 635 | $this->assertTrue($commentAdmin->isCurrentRoute('list', 'sonata.post.admin.post')); |
||
| 636 | $this->assertFalse($commentAdmin->isCurrentRoute('edit', 'sonata.post.admin.post')); |
||
| 637 | $this->assertTrue($commentVoteAdmin->isCurrentRoute('list', 'sonata.post.admin.post')); |
||
| 638 | $this->assertFalse($commentVoteAdmin->isCurrentRoute('edit', 'sonata.post.admin.post')); |
||
| 639 | } |
||
| 640 | |||
| 641 | public function testGetBaseRouteNameWithUnreconizedClassname(): void |
||
| 648 | |||
| 649 | public function testGetBaseRouteNameWithSpecifiedName(): void |
||
| 655 | |||
| 656 | public function testGetBaseRouteNameWithChildAdminAndWithSpecifiedName(): void |
||
| 664 | |||
| 665 | public function testGetBaseRouteNameWithTwoNestedChildAdminAndWithSpecifiedName(): void |
||
| 687 | |||
| 688 | /** |
||
| 689 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::setUniqid |
||
| 690 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getUniqid |
||
| 691 | */ |
||
| 692 | public function testSetUniqid(): void |
||
| 701 | |||
| 702 | public function testToString(): void |
||
| 719 | |||
| 720 | public function testIsAclEnabled(): void |
||
| 730 | |||
| 731 | /** |
||
| 732 | * @group legacy |
||
| 733 | * |
||
| 734 | * @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. |
||
| 735 | * |
||
| 736 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getSubClasses |
||
| 737 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getSubClass |
||
| 738 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::setSubClasses |
||
| 739 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::hasSubClass |
||
| 740 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::hasActiveSubClass |
||
| 741 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getActiveSubClass |
||
| 742 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getActiveSubclassCode |
||
| 743 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getClass |
||
| 744 | */ |
||
| 745 | public function testSubClass(): void |
||
| 807 | |||
| 808 | /** |
||
| 809 | * @group legacy |
||
| 810 | * |
||
| 811 | * @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. |
||
| 812 | */ |
||
| 813 | public function testNonExistantSubclass(): void |
||
| 829 | |||
| 830 | /** |
||
| 831 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::hasActiveSubClass |
||
| 832 | */ |
||
| 833 | public function testOnlyOneSubclassNeededToBeActive(): void |
||
| 841 | |||
| 842 | /** |
||
| 843 | * @group legacy |
||
| 844 | * @expectedDeprecation Method "Sonata\AdminBundle\Admin\AbstractAdmin::addSubClass" is deprecated since sonata-project/admin-bundle 3.30 and will be removed in 4.0. |
||
| 845 | */ |
||
| 846 | public function testAddSubClassIsDeprecated(): void |
||
| 855 | |||
| 856 | /** |
||
| 857 | * @group legacy |
||
| 858 | */ |
||
| 859 | public function testGetPerPageOptions(): void |
||
| 860 | { |
||
| 861 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 862 | |||
| 863 | $perPageOptions = $admin->getPerPageOptions(); |
||
| 864 | |||
| 865 | foreach ($perPageOptions as $perPage) { |
||
| 866 | $this->assertSame(0, $perPage % 4); |
||
| 867 | } |
||
| 868 | |||
| 869 | $admin->setPerPageOptions([500, 1000]); |
||
| 870 | $this->assertSame([500, 1000], $admin->getPerPageOptions()); |
||
| 871 | } |
||
| 872 | |||
| 873 | public function testGetLabelTranslatorStrategy(): void |
||
| 874 | { |
||
| 875 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 876 | |||
| 877 | $this->assertNull($admin->getLabelTranslatorStrategy()); |
||
| 878 | |||
| 879 | $labelTranslatorStrategy = $this->createMock(LabelTranslatorStrategyInterface::class); |
||
| 880 | $admin->setLabelTranslatorStrategy($labelTranslatorStrategy); |
||
| 881 | $this->assertSame($labelTranslatorStrategy, $admin->getLabelTranslatorStrategy()); |
||
| 882 | } |
||
| 883 | |||
| 884 | public function testGetRouteBuilder(): void |
||
| 885 | { |
||
| 886 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 887 | |||
| 888 | $this->assertNull($admin->getRouteBuilder()); |
||
| 889 | |||
| 890 | $routeBuilder = $this->createMock(RouteBuilderInterface::class); |
||
| 891 | $admin->setRouteBuilder($routeBuilder); |
||
| 892 | $this->assertSame($routeBuilder, $admin->getRouteBuilder()); |
||
| 893 | } |
||
| 894 | |||
| 895 | public function testGetMenuFactory(): void |
||
| 896 | { |
||
| 897 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 898 | |||
| 899 | $this->assertNull($admin->getMenuFactory()); |
||
| 900 | |||
| 901 | $menuFactory = $this->createMock(FactoryInterface::class); |
||
| 902 | $admin->setMenuFactory($menuFactory); |
||
| 903 | $this->assertSame($menuFactory, $admin->getMenuFactory()); |
||
| 904 | } |
||
| 905 | |||
| 906 | public function testGetExtensions(): void |
||
| 907 | { |
||
| 908 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 909 | |||
| 910 | $this->assertSame([], $admin->getExtensions()); |
||
| 911 | |||
| 912 | $adminExtension1 = $this->createMock(AdminExtensionInterface::class); |
||
| 913 | $adminExtension2 = $this->createMock(AdminExtensionInterface::class); |
||
| 914 | |||
| 915 | $admin->addExtension($adminExtension1); |
||
| 916 | $admin->addExtension($adminExtension2); |
||
| 917 | $this->assertSame([$adminExtension1, $adminExtension2], $admin->getExtensions()); |
||
| 918 | } |
||
| 919 | |||
| 920 | public function testGetFilterTheme(): void |
||
| 921 | { |
||
| 922 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 923 | |||
| 924 | $this->assertSame([], $admin->getFilterTheme()); |
||
| 925 | |||
| 926 | $admin->setFilterTheme(['FooTheme']); |
||
| 927 | $this->assertSame(['FooTheme'], $admin->getFilterTheme()); |
||
| 928 | } |
||
| 929 | |||
| 930 | public function testGetFormTheme(): void |
||
| 931 | { |
||
| 932 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 933 | |||
| 934 | $this->assertSame([], $admin->getFormTheme()); |
||
| 935 | |||
| 936 | $admin->setFormTheme(['FooTheme']); |
||
| 937 | |||
| 938 | $this->assertSame(['FooTheme'], $admin->getFormTheme()); |
||
| 939 | } |
||
| 940 | |||
| 941 | public function testGetValidator(): void |
||
| 942 | { |
||
| 943 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 944 | |||
| 945 | $this->assertNull($admin->getValidator()); |
||
| 946 | |||
| 947 | $validator = $this->getMockForAbstractClass(ValidatorInterface::class); |
||
| 948 | |||
| 949 | $admin->setValidator($validator); |
||
| 950 | $this->assertSame($validator, $admin->getValidator()); |
||
| 951 | } |
||
| 952 | |||
| 953 | public function testGetSecurityHandler(): void |
||
| 954 | { |
||
| 955 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 956 | |||
| 957 | $this->assertNull($admin->getSecurityHandler()); |
||
| 958 | |||
| 959 | $securityHandler = $this->createMock(SecurityHandlerInterface::class); |
||
| 960 | $admin->setSecurityHandler($securityHandler); |
||
| 961 | $this->assertSame($securityHandler, $admin->getSecurityHandler()); |
||
| 962 | } |
||
| 963 | |||
| 964 | public function testGetSecurityInformation(): void |
||
| 965 | { |
||
| 966 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 967 | |||
| 968 | $this->assertSame([], $admin->getSecurityInformation()); |
||
| 969 | |||
| 970 | $securityInformation = [ |
||
| 971 | 'GUEST' => ['VIEW', 'LIST'], |
||
| 972 | 'STAFF' => ['EDIT', 'LIST', 'CREATE'], |
||
| 973 | ]; |
||
| 974 | |||
| 975 | $admin->setSecurityInformation($securityInformation); |
||
| 976 | $this->assertSame($securityInformation, $admin->getSecurityInformation()); |
||
| 977 | } |
||
| 978 | |||
| 979 | public function testGetManagerType(): void |
||
| 980 | { |
||
| 981 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 982 | |||
| 983 | $this->assertNull($admin->getManagerType()); |
||
| 984 | |||
| 985 | $admin->setManagerType('foo_orm'); |
||
| 986 | $this->assertSame('foo_orm', $admin->getManagerType()); |
||
| 987 | } |
||
| 988 | |||
| 989 | public function testGetModelManager(): void |
||
| 990 | { |
||
| 991 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 992 | |||
| 993 | $this->assertNull($admin->getModelManager()); |
||
| 994 | |||
| 995 | $modelManager = $this->createMock(ModelManagerInterface::class); |
||
| 996 | |||
| 997 | $admin->setModelManager($modelManager); |
||
| 998 | $this->assertSame($modelManager, $admin->getModelManager()); |
||
| 999 | } |
||
| 1000 | |||
| 1001 | /** |
||
| 1002 | * NEXT_MAJOR: remove this method. |
||
| 1003 | * |
||
| 1004 | * @group legacy |
||
| 1005 | */ |
||
| 1006 | public function testGetBaseCodeRoute(): void |
||
| 1007 | { |
||
| 1008 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1009 | |||
| 1010 | $this->assertSame('', $admin->getBaseCodeRoute()); |
||
| 1011 | |||
| 1012 | $admin->setBaseCodeRoute('foo'); |
||
| 1013 | $this->assertSame('foo', $admin->getBaseCodeRoute()); |
||
| 1014 | } |
||
| 1015 | |||
| 1016 | // NEXT_MAJOR: uncomment this method. |
||
| 1017 | // public function testGetBaseCodeRoute() |
||
| 1018 | // { |
||
| 1019 | // $postAdmin = new PostAdmin( |
||
| 1020 | // 'sonata.post.admin.post', |
||
| 1021 | // 'NewsBundle\Entity\Post', |
||
| 1022 | // 'Sonata\NewsBundle\Controller\PostAdminController' |
||
| 1023 | // ); |
||
| 1024 | // $commentAdmin = new CommentAdmin( |
||
| 1025 | // 'sonata.post.admin.comment', |
||
| 1026 | // 'Application\Sonata\NewsBundle\Entity\Comment', |
||
| 1027 | // 'Sonata\NewsBundle\Controller\CommentAdminController' |
||
| 1028 | // ); |
||
| 1029 | // |
||
| 1030 | // $this->assertSame($postAdmin->getCode(), $postAdmin->getBaseCodeRoute()); |
||
| 1031 | // |
||
| 1032 | // $postAdmin->addChild($commentAdmin); |
||
| 1033 | // |
||
| 1034 | // $this->assertSame( |
||
| 1035 | // 'sonata.post.admin.post|sonata.post.admin.comment', |
||
| 1036 | // $commentAdmin->getBaseCodeRoute() |
||
| 1037 | // ); |
||
| 1038 | // } |
||
| 1039 | |||
| 1040 | public function testGetRouteGenerator(): void |
||
| 1041 | { |
||
| 1042 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1043 | |||
| 1044 | $this->assertNull($admin->getRouteGenerator()); |
||
| 1045 | |||
| 1046 | $routeGenerator = $this->createMock(RouteGeneratorInterface::class); |
||
| 1047 | |||
| 1048 | $admin->setRouteGenerator($routeGenerator); |
||
| 1049 | $this->assertSame($routeGenerator, $admin->getRouteGenerator()); |
||
| 1050 | } |
||
| 1051 | |||
| 1052 | public function testGetConfigurationPool(): void |
||
| 1053 | { |
||
| 1054 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1055 | |||
| 1056 | $this->assertNull($admin->getConfigurationPool()); |
||
| 1057 | |||
| 1058 | $pool = $this->getMockBuilder(Pool::class) |
||
| 1059 | ->disableOriginalConstructor() |
||
| 1060 | ->getMock(); |
||
| 1061 | |||
| 1062 | $admin->setConfigurationPool($pool); |
||
| 1063 | $this->assertSame($pool, $admin->getConfigurationPool()); |
||
| 1064 | } |
||
| 1065 | |||
| 1066 | public function testGetShowBuilder(): void |
||
| 1067 | { |
||
| 1068 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1069 | |||
| 1070 | $this->assertNull($admin->getShowBuilder()); |
||
| 1071 | |||
| 1072 | $showBuilder = $this->createMock(ShowBuilderInterface::class); |
||
| 1073 | |||
| 1074 | $admin->setShowBuilder($showBuilder); |
||
| 1075 | $this->assertSame($showBuilder, $admin->getShowBuilder()); |
||
| 1076 | } |
||
| 1077 | |||
| 1078 | public function testGetListBuilder(): void |
||
| 1079 | { |
||
| 1080 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1081 | |||
| 1082 | $this->assertNull($admin->getListBuilder()); |
||
| 1083 | |||
| 1084 | $listBuilder = $this->createMock(ListBuilderInterface::class); |
||
| 1085 | |||
| 1086 | $admin->setListBuilder($listBuilder); |
||
| 1087 | $this->assertSame($listBuilder, $admin->getListBuilder()); |
||
| 1088 | } |
||
| 1089 | |||
| 1090 | public function testGetDatagridBuilder(): void |
||
| 1091 | { |
||
| 1092 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1093 | |||
| 1094 | $this->assertNull($admin->getDatagridBuilder()); |
||
| 1095 | |||
| 1096 | $datagridBuilder = $this->createMock(DatagridBuilderInterface::class); |
||
| 1097 | |||
| 1098 | $admin->setDatagridBuilder($datagridBuilder); |
||
| 1099 | $this->assertSame($datagridBuilder, $admin->getDatagridBuilder()); |
||
| 1100 | } |
||
| 1101 | |||
| 1102 | public function testGetFormContractor(): void |
||
| 1103 | { |
||
| 1104 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1105 | |||
| 1106 | $this->assertNull($admin->getFormContractor()); |
||
| 1107 | |||
| 1108 | $formContractor = $this->createMock(FormContractorInterface::class); |
||
| 1109 | |||
| 1110 | $admin->setFormContractor($formContractor); |
||
| 1111 | $this->assertSame($formContractor, $admin->getFormContractor()); |
||
| 1112 | } |
||
| 1113 | |||
| 1114 | public function testGetRequest(): void |
||
| 1115 | { |
||
| 1116 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1117 | |||
| 1118 | $this->assertFalse($admin->hasRequest()); |
||
| 1119 | |||
| 1120 | $request = new Request(); |
||
| 1121 | |||
| 1122 | $admin->setRequest($request); |
||
| 1123 | $this->assertSame($request, $admin->getRequest()); |
||
| 1124 | $this->assertTrue($admin->hasRequest()); |
||
| 1125 | } |
||
| 1126 | |||
| 1127 | public function testGetRequestWithException(): void |
||
| 1128 | { |
||
| 1129 | $this->expectException(\RuntimeException::class); |
||
| 1130 | $this->expectExceptionMessage('The Request object has not been set'); |
||
| 1131 | |||
| 1132 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1133 | $admin->getRequest(); |
||
| 1134 | } |
||
| 1135 | |||
| 1136 | public function testGetTranslationDomain(): void |
||
| 1137 | { |
||
| 1138 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1139 | |||
| 1140 | $this->assertSame('messages', $admin->getTranslationDomain()); |
||
| 1141 | |||
| 1142 | $admin->setTranslationDomain('foo'); |
||
| 1143 | $this->assertSame('foo', $admin->getTranslationDomain()); |
||
| 1144 | } |
||
| 1145 | |||
| 1146 | /** |
||
| 1147 | * @group legacy |
||
| 1148 | */ |
||
| 1149 | public function testGetTranslator(): void |
||
| 1150 | { |
||
| 1151 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1152 | |||
| 1153 | $this->assertNull($admin->getTranslator()); |
||
| 1154 | |||
| 1155 | $translator = $this->createMock(TranslatorInterface::class); |
||
| 1156 | |||
| 1157 | $admin->setTranslator($translator); |
||
| 1158 | $this->assertSame($translator, $admin->getTranslator()); |
||
| 1159 | } |
||
| 1160 | |||
| 1161 | public function testGetShowGroups(): void |
||
| 1162 | { |
||
| 1163 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1164 | |||
| 1165 | // NEXT_MAJOR: Remove the argument "sonata_deprecation_mute" in the following call. |
||
| 1166 | $this->assertFalse($admin->getShowGroups('sonata_deprecation_mute')); |
||
| 1167 | |||
| 1168 | $groups = ['foo', 'bar', 'baz']; |
||
| 1169 | |||
| 1170 | $admin->setShowGroups($groups); |
||
| 1171 | $this->assertSame($groups, $admin->getShowGroups()); |
||
| 1172 | } |
||
| 1173 | |||
| 1174 | public function testGetFormGroups(): void |
||
| 1175 | { |
||
| 1176 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1177 | |||
| 1178 | // NEXT_MAJOR: Remove the argument "sonata_deprecation_mute" in the following call. |
||
| 1179 | $this->assertFalse($admin->getFormGroups('sonata_deprecation_mute')); |
||
| 1180 | |||
| 1181 | $groups = ['foo', 'bar', 'baz']; |
||
| 1182 | |||
| 1183 | $admin->setFormGroups($groups); |
||
| 1184 | $this->assertSame($groups, $admin->getFormGroups()); |
||
| 1185 | } |
||
| 1186 | |||
| 1187 | public function testGetMaxPageLinks(): void |
||
| 1188 | { |
||
| 1189 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1190 | |||
| 1191 | $this->assertSame(25, $admin->getMaxPageLinks()); |
||
| 1192 | |||
| 1193 | $admin->setMaxPageLinks(14); |
||
| 1194 | $this->assertSame(14, $admin->getMaxPageLinks()); |
||
| 1195 | } |
||
| 1196 | |||
| 1197 | /** |
||
| 1198 | * @group legacy |
||
| 1199 | */ |
||
| 1200 | public function testGetMaxPerPage(): void |
||
| 1201 | { |
||
| 1202 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1203 | |||
| 1204 | $this->assertSame(32, $admin->getMaxPerPage()); |
||
| 1205 | |||
| 1206 | $admin->setMaxPerPage(94); |
||
| 1207 | $this->assertSame(94, $admin->getMaxPerPage()); |
||
| 1208 | } |
||
| 1209 | |||
| 1210 | public function testGetLabel(): void |
||
| 1211 | { |
||
| 1212 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1213 | |||
| 1214 | $this->assertNull($admin->getLabel()); |
||
| 1215 | |||
| 1216 | $admin->setLabel('FooLabel'); |
||
| 1217 | $this->assertSame('FooLabel', $admin->getLabel()); |
||
| 1218 | } |
||
| 1219 | |||
| 1220 | public function testGetBaseController(): void |
||
| 1221 | { |
||
| 1222 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1223 | |||
| 1224 | $this->assertSame('Sonata\NewsBundle\Controller\PostAdminController', $admin->getBaseControllerName()); |
||
| 1225 | |||
| 1226 | $admin->setBaseControllerName('Sonata\NewsBundle\Controller\FooAdminController'); |
||
| 1227 | $this->assertSame('Sonata\NewsBundle\Controller\FooAdminController', $admin->getBaseControllerName()); |
||
| 1228 | } |
||
| 1229 | |||
| 1230 | public function testGetTemplates(): void |
||
| 1231 | { |
||
| 1232 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1233 | |||
| 1234 | $templates = [ |
||
| 1235 | 'list' => '@FooAdmin/CRUD/list.html.twig', |
||
| 1236 | 'show' => '@FooAdmin/CRUD/show.html.twig', |
||
| 1237 | 'edit' => '@FooAdmin/CRUD/edit.html.twig', |
||
| 1238 | ]; |
||
| 1239 | |||
| 1240 | $templateRegistry = $this->prophesize(MutableTemplateRegistryInterface::class); |
||
| 1241 | $templateRegistry->getTemplates()->shouldBeCalled()->willReturn($templates); |
||
| 1242 | |||
| 1243 | $admin->setTemplateRegistry($templateRegistry->reveal()); |
||
| 1244 | |||
| 1245 | $this->assertSame($templates, $admin->getTemplates()); |
||
| 1246 | } |
||
| 1247 | |||
| 1248 | public function testGetTemplate1(): void |
||
| 1249 | { |
||
| 1250 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1251 | |||
| 1252 | $templateRegistry = $this->prophesize(MutableTemplateRegistryInterface::class); |
||
| 1253 | $templateRegistry->getTemplate('edit')->shouldBeCalled()->willReturn('@FooAdmin/CRUD/edit.html.twig'); |
||
| 1254 | $templateRegistry->getTemplate('show')->shouldBeCalled()->willReturn('@FooAdmin/CRUD/show.html.twig'); |
||
| 1255 | |||
| 1256 | $admin->setTemplateRegistry($templateRegistry->reveal()); |
||
| 1257 | |||
| 1258 | $this->assertSame('@FooAdmin/CRUD/edit.html.twig', $admin->getTemplate('edit')); |
||
| 1259 | $this->assertSame('@FooAdmin/CRUD/show.html.twig', $admin->getTemplate('show')); |
||
| 1260 | } |
||
| 1261 | |||
| 1262 | public function testGetIdParameter(): void |
||
| 1263 | { |
||
| 1264 | $postAdmin = new PostAdmin( |
||
| 1265 | 'sonata.post.admin.post', |
||
| 1266 | 'NewsBundle\Entity\Post', |
||
| 1267 | 'Sonata\NewsBundle\Controller\PostAdminController' |
||
| 1268 | ); |
||
| 1269 | |||
| 1270 | $this->assertSame('id', $postAdmin->getIdParameter()); |
||
| 1271 | $this->assertFalse($postAdmin->isChild()); |
||
| 1272 | |||
| 1273 | $commentAdmin = new CommentAdmin( |
||
| 1274 | 'sonata.post.admin.comment', |
||
| 1275 | 'Application\Sonata\NewsBundle\Entity\Comment', |
||
| 1276 | 'Sonata\NewsBundle\Controller\CommentAdminController' |
||
| 1277 | ); |
||
| 1278 | $commentAdmin->setParent($postAdmin, 'post'); |
||
| 1279 | |||
| 1280 | $this->assertTrue($commentAdmin->isChild()); |
||
| 1281 | $this->assertSame('childId', $commentAdmin->getIdParameter()); |
||
| 1282 | |||
| 1283 | $commentVoteAdmin = new CommentVoteAdmin( |
||
| 1284 | 'sonata.post.admin.comment_vote', |
||
| 1285 | 'Application\Sonata\NewsBundle\Entity\CommentVote', |
||
| 1286 | 'Sonata\NewsBundle\Controller\CommentVoteAdminController' |
||
| 1287 | ); |
||
| 1288 | $commentVoteAdmin->setParent($commentAdmin, 'comment'); |
||
| 1289 | |||
| 1290 | $this->assertTrue($commentVoteAdmin->isChild()); |
||
| 1291 | $this->assertSame('childChildId', $commentVoteAdmin->getIdParameter()); |
||
| 1292 | } |
||
| 1293 | |||
| 1294 | public function testGetExportFormats(): void |
||
| 1295 | { |
||
| 1296 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1297 | |||
| 1298 | $this->assertSame(['json', 'xml', 'csv', 'xls'], $admin->getExportFormats()); |
||
| 1299 | } |
||
| 1300 | |||
| 1301 | public function testGetUrlsafeIdentifier(): void |
||
| 1302 | { |
||
| 1303 | $admin = new PostAdmin('sonata.post.admin.post', 'Acme\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1304 | |||
| 1305 | $model = new \stdClass(); |
||
| 1306 | |||
| 1307 | $modelManager = $this->createMock(ModelManagerInterface::class); |
||
| 1308 | $modelManager->expects($this->once()) |
||
| 1309 | ->method('getUrlSafeIdentifier') |
||
| 1310 | ->with($this->equalTo($model)) |
||
| 1311 | ->willReturn('foo'); |
||
| 1312 | $admin->setModelManager($modelManager); |
||
| 1313 | |||
| 1314 | $this->assertSame('foo', $admin->getUrlSafeIdentifier($model)); |
||
| 1315 | } |
||
| 1316 | |||
| 1317 | public function testDeterminedPerPageValue(): void |
||
| 1318 | { |
||
| 1319 | $admin = new PostAdmin('sonata.post.admin.post', 'Acme\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1320 | |||
| 1321 | $this->assertFalse($admin->determinedPerPageValue('foo')); |
||
| 1322 | $this->assertFalse($admin->determinedPerPageValue(123)); |
||
| 1323 | $this->assertTrue($admin->determinedPerPageValue(16)); |
||
| 1324 | } |
||
| 1325 | |||
| 1326 | public function testIsGranted(): void |
||
| 1327 | { |
||
| 1328 | $admin = new PostAdmin('sonata.post.admin.post', 'Acme\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1329 | $modelManager = $this->createStub(ModelManagerInterface::class); |
||
| 1330 | $modelManager |
||
| 1331 | ->method('getNormalizedIdentifier') |
||
| 1332 | ->willReturnCallback(static function (?object $model = null): ?string { |
||
| 1333 | return $model ? $model->id : null; |
||
| 1334 | }); |
||
| 1335 | |||
| 1336 | $admin->setModelManager($modelManager); |
||
| 1337 | |||
| 1338 | $entity1 = new \stdClass(); |
||
| 1339 | $entity1->id = '1'; |
||
| 1340 | |||
| 1341 | $securityHandler = $this->createMock(AclSecurityHandlerInterface::class); |
||
| 1342 | $securityHandler |
||
| 1343 | ->expects($this->exactly(6)) |
||
| 1344 | ->method('isGranted') |
||
| 1345 | ->willReturnCallback(static function ( |
||
| 1346 | AdminInterface $adminIn, |
||
| 1347 | string $attributes, |
||
| 1348 | ?object $object = null |
||
| 1349 | ) use ( |
||
| 1350 | $admin, |
||
| 1351 | $entity1 |
||
| 1352 | ): bool { |
||
| 1353 | return $admin === $adminIn && 'FOO' === $attributes && |
||
| 1354 | ($object === $admin || $object === $entity1); |
||
| 1355 | }); |
||
| 1356 | |||
| 1357 | $admin->setSecurityHandler($securityHandler); |
||
| 1358 | |||
| 1359 | $this->assertTrue($admin->isGranted('FOO')); |
||
| 1360 | $this->assertTrue($admin->isGranted('FOO')); |
||
| 1361 | $this->assertTrue($admin->isGranted('FOO', $entity1)); |
||
| 1362 | $this->assertTrue($admin->isGranted('FOO', $entity1)); |
||
| 1363 | $this->assertFalse($admin->isGranted('BAR')); |
||
| 1364 | $this->assertFalse($admin->isGranted('BAR')); |
||
| 1365 | $this->assertFalse($admin->isGranted('BAR', $entity1)); |
||
| 1366 | $this->assertFalse($admin->isGranted('BAR', $entity1)); |
||
| 1367 | |||
| 1368 | $entity2 = new \stdClass(); |
||
| 1369 | $entity2->id = '2'; |
||
| 1370 | |||
| 1371 | $this->assertFalse($admin->isGranted('BAR', $entity2)); |
||
| 1372 | $this->assertFalse($admin->isGranted('BAR', $entity2)); |
||
| 1373 | |||
| 1374 | $entity3 = new \stdClass(); |
||
| 1375 | $entity3->id = '3'; |
||
| 1376 | |||
| 1377 | $this->assertFalse($admin->isGranted('BAR', $entity3)); |
||
| 1378 | $this->assertFalse($admin->isGranted('BAR', $entity3)); |
||
| 1379 | } |
||
| 1380 | |||
| 1381 | public function testSupportsPreviewMode(): void |
||
| 1382 | { |
||
| 1383 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1384 | |||
| 1385 | $this->assertFalse($admin->supportsPreviewMode()); |
||
| 1386 | } |
||
| 1387 | |||
| 1388 | public function testGetPermissionsShow(): void |
||
| 1389 | { |
||
| 1390 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1391 | |||
| 1392 | $this->assertSame(['LIST'], $admin->getPermissionsShow(AbstractAdmin::CONTEXT_DASHBOARD)); |
||
| 1393 | $this->assertSame(['LIST'], $admin->getPermissionsShow(AbstractAdmin::CONTEXT_MENU)); |
||
| 1394 | $this->assertSame(['LIST'], $admin->getPermissionsShow('foo')); |
||
| 1395 | } |
||
| 1396 | |||
| 1397 | public function testShowIn(): void |
||
| 1398 | { |
||
| 1399 | $admin = new PostAdmin('sonata.post.admin.post', 'Acme\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1400 | |||
| 1401 | $securityHandler = $this->createMock(AclSecurityHandlerInterface::class); |
||
| 1402 | $securityHandler |
||
| 1403 | ->method('isGranted') |
||
| 1404 | ->willReturnCallback(static function (AdminInterface $adminIn, array $attributes, $object = null) use ($admin): bool { |
||
| 1405 | return $admin === $adminIn && $attributes === ['LIST']; |
||
| 1406 | }); |
||
| 1407 | |||
| 1408 | $admin->setSecurityHandler($securityHandler); |
||
| 1409 | |||
| 1410 | $this->assertTrue($admin->showIn(AbstractAdmin::CONTEXT_DASHBOARD)); |
||
| 1411 | $this->assertTrue($admin->showIn(AbstractAdmin::CONTEXT_MENU)); |
||
| 1412 | $this->assertTrue($admin->showIn('foo')); |
||
| 1413 | } |
||
| 1414 | |||
| 1415 | public function testGetObjectIdentifier(): void |
||
| 1416 | { |
||
| 1417 | $admin = new PostAdmin('sonata.post.admin.post', 'Acme\NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1418 | |||
| 1419 | $this->assertSame('sonata.post.admin.post', $admin->getObjectIdentifier()); |
||
| 1420 | } |
||
| 1421 | |||
| 1422 | /** |
||
| 1423 | * @group legacy |
||
| 1424 | */ |
||
| 1425 | public function testTrans(): void |
||
| 1426 | { |
||
| 1427 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1428 | $admin->setTranslationDomain('fooMessageDomain'); |
||
| 1429 | |||
| 1430 | $translator = $this->createMock(TranslatorInterface::class); |
||
| 1431 | $admin->setTranslator($translator); |
||
| 1432 | |||
| 1433 | $translator->expects($this->once()) |
||
| 1434 | ->method('trans') |
||
| 1435 | ->with($this->equalTo('foo'), $this->equalTo([]), $this->equalTo('fooMessageDomain')) |
||
| 1436 | ->willReturn('fooTranslated'); |
||
| 1437 | |||
| 1438 | $this->assertSame('fooTranslated', $admin->trans('foo')); |
||
| 1439 | } |
||
| 1440 | |||
| 1441 | /** |
||
| 1442 | * @group legacy |
||
| 1443 | */ |
||
| 1444 | public function testTransWithMessageDomain(): void |
||
| 1445 | { |
||
| 1446 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1447 | |||
| 1448 | $translator = $this->createMock(TranslatorInterface::class); |
||
| 1449 | $admin->setTranslator($translator); |
||
| 1450 | |||
| 1451 | $translator->expects($this->once()) |
||
| 1452 | ->method('trans') |
||
| 1453 | ->with($this->equalTo('foo'), $this->equalTo(['name' => 'Andrej']), $this->equalTo('fooMessageDomain')) |
||
| 1454 | ->willReturn('fooTranslated'); |
||
| 1455 | |||
| 1456 | $this->assertSame('fooTranslated', $admin->trans('foo', ['name' => 'Andrej'], 'fooMessageDomain')); |
||
| 1457 | } |
||
| 1458 | |||
| 1459 | /** |
||
| 1460 | * @group legacy |
||
| 1461 | */ |
||
| 1462 | public function testTransChoice(): void |
||
| 1463 | { |
||
| 1464 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1465 | $admin->setTranslationDomain('fooMessageDomain'); |
||
| 1466 | |||
| 1467 | $translator = $this->createMock(TranslatorInterface::class); |
||
| 1468 | $admin->setTranslator($translator); |
||
| 1469 | |||
| 1470 | $translator->expects($this->once()) |
||
| 1471 | ->method('transChoice') |
||
| 1472 | ->with($this->equalTo('foo'), $this->equalTo(2), $this->equalTo([]), $this->equalTo('fooMessageDomain')) |
||
| 1473 | ->willReturn('fooTranslated'); |
||
| 1474 | |||
| 1475 | $this->assertSame('fooTranslated', $admin->transChoice('foo', 2)); |
||
| 1476 | } |
||
| 1477 | |||
| 1478 | /** |
||
| 1479 | * @group legacy |
||
| 1480 | */ |
||
| 1481 | public function testTransChoiceWithMessageDomain(): void |
||
| 1482 | { |
||
| 1483 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1484 | |||
| 1485 | $translator = $this->createMock(TranslatorInterface::class); |
||
| 1486 | $admin->setTranslator($translator); |
||
| 1487 | |||
| 1488 | $translator->expects($this->once()) |
||
| 1489 | ->method('transChoice') |
||
| 1490 | ->with($this->equalTo('foo'), $this->equalTo(2), $this->equalTo(['name' => 'Andrej']), $this->equalTo('fooMessageDomain')) |
||
| 1491 | ->willReturn('fooTranslated'); |
||
| 1492 | |||
| 1493 | $this->assertSame('fooTranslated', $admin->transChoice('foo', 2, ['name' => 'Andrej'], 'fooMessageDomain')); |
||
| 1494 | } |
||
| 1495 | |||
| 1496 | public function testSetFilterPersister(): void |
||
| 1497 | { |
||
| 1498 | $admin = new class('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle\Controller\PostAdminController') extends PostAdmin { |
||
| 1499 | public function persistFilters(): bool |
||
| 1503 | }; |
||
| 1504 | |||
| 1505 | $filterPersister = $this->createMock(FilterPersisterInterface::class); |
||
| 1506 | |||
| 1507 | $admin->setFilterPersister($filterPersister); |
||
| 1508 | $this->assertTrue($admin->persistFilters()); |
||
| 1509 | } |
||
| 1510 | |||
| 1511 | public function testGetRootCode(): void |
||
| 1512 | { |
||
| 1513 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1514 | |||
| 1515 | $this->assertSame('sonata.post.admin.post', $admin->getRootCode()); |
||
| 1516 | |||
| 1517 | $parentAdmin = new PostAdmin('sonata.post.admin.post.parent', 'NewsBundle\Entity\PostParent', 'Sonata\NewsBundle\Controller\PostParentAdminController'); |
||
| 1518 | $parentFieldDescription = $this->createMock(FieldDescriptionInterface::class); |
||
| 1519 | $parentFieldDescription->expects($this->once()) |
||
| 1520 | ->method('getAdmin') |
||
| 1521 | ->willReturn($parentAdmin); |
||
| 1522 | |||
| 1523 | $this->assertFalse($admin->hasParentFieldDescription()); |
||
| 1524 | $admin->setParentFieldDescription($parentFieldDescription); |
||
| 1525 | $this->assertSame($parentFieldDescription, $admin->getParentFieldDescription()); |
||
| 1526 | $this->assertSame('sonata.post.admin.post.parent', $admin->getRootCode()); |
||
| 1527 | } |
||
| 1528 | |||
| 1529 | public function testGetRoot(): void |
||
| 1530 | { |
||
| 1531 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1532 | |||
| 1533 | $this->assertSame($admin, $admin->getRoot()); |
||
| 1534 | |||
| 1535 | $parentAdmin = new PostAdmin('sonata.post.admin.post.parent', 'NewsBundle\Entity\PostParent', 'Sonata\NewsBundle\Controller\PostParentAdminController'); |
||
| 1536 | $parentFieldDescription = $this->createMock(FieldDescriptionInterface::class); |
||
| 1537 | $parentFieldDescription->expects($this->once()) |
||
| 1538 | ->method('getAdmin') |
||
| 1539 | ->willReturn($parentAdmin); |
||
| 1540 | |||
| 1541 | $this->assertFalse($admin->hasParentFieldDescription()); |
||
| 1542 | $admin->setParentFieldDescription($parentFieldDescription); |
||
| 1543 | $this->assertSame($parentFieldDescription, $admin->getParentFieldDescription()); |
||
| 1544 | $this->assertSame($parentAdmin, $admin->getRoot()); |
||
| 1545 | } |
||
| 1546 | |||
| 1547 | public function testGetExportFields(): void |
||
| 1548 | { |
||
| 1549 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1550 | |||
| 1551 | $modelManager = $this->createMock(ModelManagerInterface::class); |
||
| 1552 | $modelManager->expects($this->once()) |
||
| 1553 | ->method('getExportFields') |
||
| 1554 | ->with($this->equalTo('NewsBundle\Entity\Post')) |
||
| 1555 | ->willReturn(['foo', 'bar']); |
||
| 1556 | |||
| 1557 | $admin->setModelManager($modelManager); |
||
| 1558 | $this->assertSame(['foo', 'bar'], $admin->getExportFields()); |
||
| 1559 | } |
||
| 1560 | |||
| 1561 | public function testGetPersistentParametersWithNoExtension(): void |
||
| 1562 | { |
||
| 1563 | $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); |
||
| 1564 | |||
| 1567 | |||
| 1568 | public function testGetPersistentParametersWithInvalidExtension(): void |
||
| 1581 | |||
| 1582 | public function testGetPersistentParametersWithValidExtension(): void |
||
| 1597 | |||
| 1598 | public function testGetNewInstanceForChildAdminWithParentValue(): void |
||
| 1632 | |||
| 1633 | public function testGetNewInstanceForChildAdminWithCollectionParentValue(): void |
||
| 1669 | |||
| 1670 | public function testGetNewInstanceForEmbededAdminWithParentValue(): void |
||
| 1709 | |||
| 1710 | public function testFormAddPostSubmitEventForPreValidation(): void |
||
| 1772 | |||
| 1773 | public function testCanAddInlineValidationOnlyForGenericMetadata(): void |
||
| 1822 | |||
| 1823 | public function testRemoveFieldFromFormGroup(): void |
||
| 1849 | |||
| 1850 | public function testGetFilterParameters(): void |
||
| 1889 | |||
| 1890 | public function testGetFilterFieldDescription(): void |
||
| 1961 | |||
| 1962 | public function testGetSubjectNoRequest(): void |
||
| 1974 | |||
| 1975 | public function testGetSideMenu(): void |
||
| 1999 | |||
| 2000 | /** |
||
| 2001 | * @return array |
||
| 2002 | */ |
||
| 2003 | public function provideGetSubject() |
||
| 2013 | |||
| 2014 | /** |
||
| 2015 | * @dataProvider provideGetSubject |
||
| 2016 | */ |
||
| 2017 | public function testGetSubjectFailed($id): void |
||
| 2032 | |||
| 2033 | /** |
||
| 2034 | * @dataProvider provideGetSubject |
||
| 2035 | */ |
||
| 2036 | public function testGetSubject($id): void |
||
| 2055 | |||
| 2056 | public function testGetSubjectWithParentDescription(): void |
||
| 2085 | |||
| 2086 | /** |
||
| 2087 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::configureActionButtons |
||
| 2088 | */ |
||
| 2089 | public function testGetActionButtonsList(): void |
||
| 2122 | |||
| 2123 | /** |
||
| 2124 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::configureActionButtons |
||
| 2125 | */ |
||
| 2126 | public function testGetActionButtonsListCreateDisabled(): void |
||
| 2140 | |||
| 2141 | /** |
||
| 2142 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::configureBatchActions |
||
| 2143 | */ |
||
| 2144 | public function testGetBatchActions(): void |
||
| 2198 | |||
| 2199 | /** |
||
| 2200 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::showMosaicButton |
||
| 2201 | */ |
||
| 2202 | public function testShowMosaicButton(): void |
||
| 2211 | |||
| 2212 | /** |
||
| 2213 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::showMosaicButton |
||
| 2214 | */ |
||
| 2215 | public function testShowMosaicButtonHideMosaic(): void |
||
| 2225 | |||
| 2226 | /** |
||
| 2227 | * @covers \Sonata\AdminBundle\Admin\AbstractAdmin::getDashboardActions |
||
| 2228 | * @dataProvider provideGetBaseRouteName |
||
| 2229 | */ |
||
| 2230 | public function testDefaultDashboardActionsArePresent(string $objFqn, string $expected): void |
||
| 2261 | |||
| 2262 | /** |
||
| 2263 | * NEXT_MAJOR: Remove the assertion about isDefaultFilter method and the legacy group. |
||
| 2264 | * |
||
| 2265 | * @group legacy |
||
| 2266 | * |
||
| 2267 | * @expectedDeprecation Method "Sonata\AdminBundle\Admin\AbstractAdmin::isDefaultFilter" is deprecated since sonata-project/admin-bundle 3.x. |
||
| 2268 | */ |
||
| 2269 | public function testDefaultFilters(): void |
||
| 2328 | |||
| 2329 | /** |
||
| 2330 | * @group legacy |
||
| 2331 | */ |
||
| 2332 | public function testDefaultBreadcrumbsBuilder(): void |
||
| 2356 | |||
| 2357 | /** |
||
| 2358 | * @group legacy |
||
| 2359 | */ |
||
| 2360 | public function testBreadcrumbsBuilderSetter(): void |
||
| 2370 | |||
| 2371 | /** |
||
| 2372 | * @group legacy |
||
| 2373 | */ |
||
| 2374 | public function testGetBreadcrumbs(): void |
||
| 2384 | |||
| 2385 | /** |
||
| 2386 | * @group legacy |
||
| 2387 | */ |
||
| 2388 | public function testBuildBreadcrumbs(): void |
||
| 2405 | |||
| 2406 | /** |
||
| 2407 | * NEXT_MAJOR: remove this method. |
||
| 2408 | * |
||
| 2409 | * @group legacy |
||
| 2410 | */ |
||
| 2411 | public function testCreateQueryLegacyCallWorks(): void |
||
| 2426 | |||
| 2427 | public function testGetDataSourceIterator(): void |
||
| 2469 | |||
| 2470 | public function testCircularChildAdmin(): void |
||
| 2490 | |||
| 2491 | public function testCircularChildAdminTripleLevel(): void |
||
| 2517 | |||
| 2518 | public function testCircularChildAdminWithItself(): void |
||
| 2532 | |||
| 2533 | public function testGetRootAncestor(): void |
||
| 2567 | |||
| 2568 | public function testGetChildDepth(): void |
||
| 2602 | |||
| 2603 | public function testGetCurrentLeafChildAdmin(): void |
||
| 2640 | |||
| 2641 | public function testAdminWithoutControllerName(): void |
||
| 2647 | |||
| 2648 | public function testAdminAvoidInifiniteLoop(): void |
||
| 2678 | |||
| 2679 | /** |
||
| 2680 | * NEXT_MAJOR: Remove this test and its data provider. |
||
| 2681 | * |
||
| 2682 | * @group legacy |
||
| 2683 | * |
||
| 2684 | * @dataProvider getDeprecatedAbstractAdminConstructorArgs |
||
| 2685 | * |
||
| 2686 | * @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. |
||
| 2687 | */ |
||
| 2688 | public function testDeprecatedAbstractAdminConstructorArgs($code, $class, $baseControllerName): void |
||
| 2692 | |||
| 2693 | public function getDeprecatedAbstractAdminConstructorArgs(): iterable |
||
| 2707 | } |
||
| 2708 |
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: