@@ -478,4 +478,85 @@ public function testMultipleAdminRoutesOnSameCrudAction(): void
478478 $ this ->assertNotNull ($ router ->getRouteCollection ()->get ('second_admin_multiple_route_action2_path2 ' ));
479479 $ this ->assertNotNull ($ router ->getRouteCollection ()->get ('second_admin_multiple_route_action2_path3 ' ));
480480 }
481+
482+ public function testBuiltInActionsWithCustomRouteNames (): void
483+ {
484+ $ client = static ::createClient ();
485+ $ router = $ client ->getContainer ()->get ('router ' );
486+
487+ // Test that when built-in actions have custom route names, only the custom routes are generated
488+ // and the default routes are NOT generated (avoiding duplicates)
489+
490+ // 'index' action was customized with route name 'list' (path not customized, so it uses the default '/')
491+ $ indexCustomRoute = $ router ->getRouteCollection ()->get ('admin_built_in_action_list ' );
492+ $ this ->assertNotNull ($ indexCustomRoute , 'Custom route for index action should exist ' );
493+ $ this ->assertSame ('/admin/built-in-action/index ' , $ indexCustomRoute ->getPath ());
494+ $ this ->assertSame (
495+ 'EasyCorp\Bundle\EasyAdminBundle\Tests\AdminRouteTestApplication\Controller\BuiltInActionCrudController::index ' ,
496+ $ indexCustomRoute ->getDefault ('_controller ' )
497+ );
498+
499+ // The default 'index' route should NOT exist
500+ $ indexDefaultRoute = $ router ->getRouteCollection ()->get ('admin_built_in_action_index ' );
501+ $ this ->assertNull ($ indexDefaultRoute , 'Default route for index action should NOT exist when overridden ' );
502+
503+ // 'new' action was customized with route name 'create' and path '/create'
504+ $ newCustomRoute = $ router ->getRouteCollection ()->get ('admin_built_in_action_create ' );
505+ $ this ->assertNotNull ($ newCustomRoute , 'Custom route for new action should exist ' );
506+ $ this ->assertSame ('/admin/built-in-action/create ' , $ newCustomRoute ->getPath ());
507+ $ this ->assertSame (
508+ 'EasyCorp\Bundle\EasyAdminBundle\Tests\AdminRouteTestApplication\Controller\BuiltInActionCrudController::new ' ,
509+ $ newCustomRoute ->getDefault ('_controller ' )
510+ );
511+
512+ // The default 'new' route should NOT exist
513+ $ newDefaultRoute = $ router ->getRouteCollection ()->get ('admin_built_in_action_new ' );
514+ $ this ->assertNull ($ newDefaultRoute , 'Default route for new action should NOT exist when overridden ' );
515+
516+ // 'edit' action was customized with route name 'update' (path not customized, so it auto-generates based on action name)
517+ $ editCustomRoute = $ router ->getRouteCollection ()->get ('admin_built_in_action_update ' );
518+ $ this ->assertNotNull ($ editCustomRoute , 'Custom route for edit action should exist ' );
519+ $ this ->assertSame ('/admin/built-in-action/edit ' , $ editCustomRoute ->getPath ());
520+ $ this ->assertSame (
521+ 'EasyCorp\Bundle\EasyAdminBundle\Tests\AdminRouteTestApplication\Controller\BuiltInActionCrudController::edit ' ,
522+ $ editCustomRoute ->getDefault ('_controller ' )
523+ );
524+
525+ // The default 'edit' route should NOT exist
526+ $ editDefaultRoute = $ router ->getRouteCollection ()->get ('admin_built_in_action_edit ' );
527+ $ this ->assertNull ($ editDefaultRoute , 'Default route for edit action should NOT exist when overridden ' );
528+
529+ // 'detail' action was customized with route name 'show' (path not customized, so it auto-generates based on action name)
530+ $ detailCustomRoute = $ router ->getRouteCollection ()->get ('admin_built_in_action_show ' );
531+ $ this ->assertNotNull ($ detailCustomRoute , 'Custom route for detail action should exist ' );
532+ $ this ->assertSame ('/admin/built-in-action/detail ' , $ detailCustomRoute ->getPath ());
533+ $ this ->assertSame (
534+ 'EasyCorp\Bundle\EasyAdminBundle\Tests\AdminRouteTestApplication\Controller\BuiltInActionCrudController::detail ' ,
535+ $ detailCustomRoute ->getDefault ('_controller ' )
536+ );
537+
538+ // The default 'detail' route should NOT exist
539+ $ detailDefaultRoute = $ router ->getRouteCollection ()->get ('admin_built_in_action_detail ' );
540+ $ this ->assertNull ($ detailDefaultRoute , 'Default route for detail action should NOT exist when overridden ' );
541+
542+ // 'delete' action was NOT customized, so it should use the default route
543+ $ deleteDefaultRoute = $ router ->getRouteCollection ()->get ('admin_built_in_action_delete ' );
544+ $ this ->assertNotNull ($ deleteDefaultRoute , 'Default route for delete action should exist when NOT overridden ' );
545+ $ this ->assertSame ('/admin/built-in-action/{entityId}/delete ' , $ deleteDefaultRoute ->getPath ());
546+ $ this ->assertSame (
547+ 'EasyCorp\Bundle\EasyAdminBundle\Tests\AdminRouteTestApplication\Controller\BuiltInActionCrudController::delete ' ,
548+ $ deleteDefaultRoute ->getDefault ('_controller ' )
549+ );
550+
551+ // Test that routes work for second dashboard too
552+ $ this ->assertNotNull ($ router ->getRouteCollection ()->get ('second_admin_built_in_action_list ' ));
553+ $ this ->assertNull ($ router ->getRouteCollection ()->get ('second_admin_built_in_action_index ' ));
554+ $ this ->assertNotNull ($ router ->getRouteCollection ()->get ('second_admin_built_in_action_create ' ));
555+ $ this ->assertNull ($ router ->getRouteCollection ()->get ('second_admin_built_in_action_new ' ));
556+ $ this ->assertNotNull ($ router ->getRouteCollection ()->get ('second_admin_built_in_action_update ' ));
557+ $ this ->assertNull ($ router ->getRouteCollection ()->get ('second_admin_built_in_action_edit ' ));
558+ $ this ->assertNotNull ($ router ->getRouteCollection ()->get ('second_admin_built_in_action_show ' ));
559+ $ this ->assertNull ($ router ->getRouteCollection ()->get ('second_admin_built_in_action_detail ' ));
560+ $ this ->assertNotNull ($ router ->getRouteCollection ()->get ('second_admin_built_in_action_delete ' ));
561+ }
481562}
0 commit comments