diff --git a/core/lib/Drupal/Core/Entity/EntityResolverManager.php b/core/lib/Drupal/Core/Entity/EntityResolverManager.php index c4e3495..94b9aea 100644 --- a/core/lib/Drupal/Core/Entity/EntityResolverManager.php +++ b/core/lib/Drupal/Core/Entity/EntityResolverManager.php @@ -94,8 +94,8 @@ protected function getController(array $defaults) { /** * Sets the upcasting information using reflection. * - * @param $controller - * A PHP callable representing the Controller + * @param string|array $controller + * A PHP callable representing the controller. * @param \Symfony\Component\Routing\Route $route * The route object to populate without upcasting information. * diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityResolverManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityResolverManagerTest.php index 23bd5c9..a324bf8 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityResolverManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityResolverManagerTest.php @@ -5,7 +5,7 @@ * Contains \Drupal\Tests\Core\Entity\EntityResolverManagerTest. */ -namespace Drupal\Tests\Core\Entity; +namespace Drupal\Tests\Core\Entity { use Drupal\Core\Entity\Entity; use Drupal\Core\Entity\EntityInterface; @@ -78,10 +78,12 @@ protected function setUp() { * * @covers ::setRouteOptions() * @covers ::getController() + * + * @dataProvider providerTestSetRouteOptionsWithStandardRoute */ - public function testSetRouteOptionsWithStandardRoute() { + public function testSetRouteOptionsWithStandardRoute($controller) { $route = new Route('/example', array( - '_controller' => 'Drupal\Tests\Core\Entity\BasicControllerClass::exampleControllerMethod', + '_controller' => $controller, )); $this->setupControllerResolver($route->getDefault('_controller')); @@ -92,14 +94,26 @@ public function testSetRouteOptionsWithStandardRoute() { } /** + * Data provider for testSetRouteOptionsWithStandardRoute. + */ + public function providerTestSetRouteOptionsWithStandardRoute() { + return array( + array('Drupal\Tests\Core\Entity\BasicControllerClass::exampleControllerMethod'), + array('test_function_controller'), + ); + } + + /** * Tests setRouteOptions() with a controller with a non entity argument. * * @covers ::setRouteOptions() * @covers ::getController() + * + * @dataProvider providerTestSetRouteOptionsWithStandardRouteWithArgument */ - public function testSetRouteOptionsWithStandardRouteWithArgument() { + public function testSetRouteOptionsWithStandardRouteWithArgument($controller) { $route = new Route('/example/{argument}', array( - '_controller' => 'Drupal\Tests\Core\Entity\BasicControllerClass::exampleControllerMethodWithArgument', + '_controller' => $controller, 'argument' => 'test', )); $this->setupControllerResolver($route->getDefault('_controller')); @@ -111,14 +125,26 @@ public function testSetRouteOptionsWithStandardRouteWithArgument() { } /** + * Data provider for testSetRouteOptionsWithStandardRouteWithArgument. + */ + public function providerTestSetRouteOptionsWithStandardRouteWithArgument() { + return array( + array('Drupal\Tests\Core\Entity\BasicControllerClass::exampleControllerMethodWithArgument'), + array('test_function_controller_with_argument'), + ); + } + + /** * Tests setRouteOptions() with a _content default. * * @covers ::setRouteOptions() * @covers ::getController() + * + * @dataProvider providerTestSetRouteOptionsWithContentController */ - public function testSetRouteOptionsWithContentController() { + public function testSetRouteOptionsWithContentController($controller) { $route = new Route('/example/{argument}', array( - '_content' => 'Drupal\Tests\Core\Entity\BasicControllerClass::exampleControllerMethodWithArgument', + '_content' => $controller, 'argument' => 'test', )); $this->setupControllerResolver($route->getDefault('_content')); @@ -130,18 +156,30 @@ public function testSetRouteOptionsWithContentController() { } /** + * Data provider for testSetRouteOptionsWithContentController. + */ + public function providerTestSetRouteOptionsWithContentController() { + return array( + array('Drupal\Tests\Core\Entity\BasicControllerClass::exampleControllerMethodWithArgument'), + array('test_function_controller_with_argument'), + ); + } + + /** * Tests setRouteOptions() with an entity type parameter. * * @covers ::setRouteOptions() * @covers ::getController() * @covers ::getEntityTypes() * @covers ::setParametersFromReflection() + * + * @dataProvider providerTestSetRouteOptionsWithEntityTypeNoUpcasting */ - public function testSetRouteOptionsWithEntityTypeNoUpcasting() { + public function testSetRouteOptionsWithEntityTypeNoUpcasting($controller) { $this->setupEntityTypes(); $route = new Route('/example/{entity_test}', array( - '_content' => 'Drupal\Tests\Core\Entity\BasicControllerClass::exampleControllerWithEntityNoUpcasting', + '_content' => $controller, )); $this->setupControllerResolver($route->getDefault('_content')); @@ -152,18 +190,30 @@ public function testSetRouteOptionsWithEntityTypeNoUpcasting() { } /** + * Data provider for testSetRouteOptionsWithEntityTypeNoUpcasting. + */ + public function providerTestSetRouteOptionsWithEntityTypeNoUpcasting() { + return array( + array('Drupal\Tests\Core\Entity\BasicControllerClass::exampleControllerWithEntityNoUpcasting'), + array('test_function_controller_no_upcasting'), + ); + } + + /** * Tests setRouteOptions() with an entity type parameter, upcasting. * * @covers ::setRouteOptions() * @covers ::getController() * @covers ::getEntityTypes() * @covers ::setParametersFromReflection() + * + * @dataProvider providerTestSetRouteOptionsWithEntityTypeUpcasting */ - public function testSetRouteOptionsWithEntityTypeUpcasting() { + public function testSetRouteOptionsWithEntityTypeUpcasting($controller) { $this->setupEntityTypes(); $route = new Route('/example/{entity_test}', array( - '_content' => 'Drupal\Tests\Core\Entity\BasicControllerClass::exampleControllerWithEntityUpcasting', + '_content' => $controller, )); $this->setupControllerResolver($route->getDefault('_content')); @@ -175,6 +225,16 @@ public function testSetRouteOptionsWithEntityTypeUpcasting() { } /** + * Data provider for testSetRouteOptionsWithEntityTypeUpcasting. + */ + public function providerTestSetRouteOptionsWithEntityTypeUpcasting() { + return array( + array('Drupal\Tests\Core\Entity\BasicControllerClass::exampleControllerWithEntityUpcasting'), + array('test_function_controller_entity_upcasting'), + ); + } + + /** * Tests setRouteOptions() with an entity type parameter form. * * @covers ::setRouteOptions() @@ -345,11 +405,19 @@ public function testSetRouteOptionsWithEntityFormRoute() { */ protected function setupControllerResolver($controller_definition) { $controller = $controller_definition; - list($class, $method) = explode('::', $controller); + + if (strpos($controller, '::')) { + list($class, $method) = explode('::', $controller); + $expected = array(new $class(), $method); + } + else { + $expected = $controller; + } + $this->controllerResolver->expects($this->atLeastOnce()) ->method('getControllerFromDefinition') ->with($controller_definition) - ->will($this->returnValue(array(new $class, $method))); + ->will($this->returnValue($expected)); } /** @@ -482,3 +550,22 @@ public function submitForm(array &$form, FormStateInterface $form_state) { } } + +} + +namespace { + + use Drupal\Core\Entity\EntityInterface; + + function test_function_controller() { + } + + function test_function_controller_with_argument($argument) { + } + + function test_function_controller_no_upcasting($entity_test) { + } + + function test_function_controller_entity_upcasting(EntityInterface $entity_test) { + } +}