From 09b998f131f89e697e745ad191c8caac23f1310a Mon Sep 17 00:00:00 2001 From: webchick Date: Wed, 12 Sep 2012 23:16:39 -0700 Subject: [PATCH] Issue #1777430 by Crell, sun, tim.plunkett: Fixed Allow for ContainerAware controllers. --- core/lib/Drupal/Core/ControllerResolver.php | 2 + .../Tests/Routing/ControllerResolverTest.php | 43 +++++++++++++++++++ .../system/Tests/Routing/MockController.php | 19 ++++++++ 3 files changed, 64 insertions(+) create mode 100644 core/modules/system/lib/Drupal/system/Tests/Routing/ControllerResolverTest.php create mode 100644 core/modules/system/lib/Drupal/system/Tests/Routing/MockController.php diff --git a/core/lib/Drupal/Core/ControllerResolver.php b/core/lib/Drupal/Core/ControllerResolver.php index 0019f165ad2..abb988964c5 100644 --- a/core/lib/Drupal/Core/ControllerResolver.php +++ b/core/lib/Drupal/Core/ControllerResolver.php @@ -60,5 +60,7 @@ class ControllerResolver extends BaseControllerResolver { if ($controller[0] instanceof ContainerAwareInterface) { $controller[0]->setContainer($this->container); } + + return $controller; } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Routing/ControllerResolverTest.php b/core/modules/system/lib/Drupal/system/Tests/Routing/ControllerResolverTest.php new file mode 100644 index 00000000000..46ed2a3919c --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Routing/ControllerResolverTest.php @@ -0,0 +1,43 @@ + 'Controller Resolver tests', + 'description' => 'Tests that the Drupal-extended ControllerResolver is functioning properly.', + 'group' => 'Routing', + ); + } + + /** + * Confirms that a container aware controller gets returned. + */ + function testContainerAware() { + $container = new Container(); + $resolver = new ControllerResolver($container); + + $request = Request::create('/some/path'); + $request->attributes->set('_controller', '\Drupal\system\Tests\Routing\MockController::run'); + + $controller = $resolver->getController($request); + + $this->assertTrue($controller[0] instanceof MockController, 'The correct controller object was returned.'); + } +} diff --git a/core/modules/system/lib/Drupal/system/Tests/Routing/MockController.php b/core/modules/system/lib/Drupal/system/Tests/Routing/MockController.php new file mode 100644 index 00000000000..fe09a7b8524 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Routing/MockController.php @@ -0,0 +1,19 @@ +