Issue #2321393 by damiankloip, undertext: Fixed Unable to pass function name to '_content' property of the route.
parent
61150517df
commit
6d8b0b81d3
|
@ -94,21 +94,28 @@ class EntityResolverManager {
|
|||
/**
|
||||
* Sets the upcasting information using reflection.
|
||||
*
|
||||
* @param array $controller
|
||||
* An array of class instance and method name.
|
||||
* @param string|array $controller
|
||||
* A PHP callable representing the controller.
|
||||
* @param \Symfony\Component\Routing\Route $route
|
||||
* The route object to populate without upcasting information.
|
||||
*
|
||||
* @return bool
|
||||
* Returns TRUE if the upcasting parameters could be set, FALSE otherwise.
|
||||
*/
|
||||
protected function setParametersFromReflection(array $controller, Route $route) {
|
||||
protected function setParametersFromReflection($controller, Route $route) {
|
||||
$entity_types = $this->getEntityTypes();
|
||||
$parameter_definitions = $route->getOption('parameters') ?: array();
|
||||
|
||||
$result = FALSE;
|
||||
list($instance, $method) = $controller;
|
||||
$reflection = new \ReflectionMethod($instance, $method);
|
||||
|
||||
if (is_array($controller)) {
|
||||
list($instance, $method) = $controller;
|
||||
$reflection = new \ReflectionMethod($instance, $method);
|
||||
}
|
||||
else {
|
||||
$reflection = new \ReflectionFunction($controller);
|
||||
}
|
||||
|
||||
$parameters = $reflection->getParameters();
|
||||
foreach ($parameters as $parameter) {
|
||||
$parameter_name = $parameter->getName();
|
||||
|
|
|
@ -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 @@ class EntityResolverManagerTest extends UnitTestCase {
|
|||
*
|
||||
* @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'));
|
||||
|
||||
|
@ -91,15 +93,27 @@ class EntityResolverManagerTest extends UnitTestCase {
|
|||
$this->assertEmpty($route->getOption('parameters'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'));
|
||||
|
@ -110,15 +124,27 @@ class EntityResolverManagerTest extends UnitTestCase {
|
|||
$this->assertEmpty($route->getOption('parameters'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'));
|
||||
|
@ -129,6 +155,16 @@ class EntityResolverManagerTest extends UnitTestCase {
|
|||
$this->assertEmpty($route->getOption('parameters'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
@ -136,12 +172,14 @@ class EntityResolverManagerTest extends UnitTestCase {
|
|||
* @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'));
|
||||
|
||||
|
@ -151,6 +189,16 @@ class EntityResolverManagerTest extends UnitTestCase {
|
|||
$this->assertEmpty($route->getOption('parameters'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
@ -158,12 +206,14 @@ class EntityResolverManagerTest extends UnitTestCase {
|
|||
* @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'));
|
||||
|
||||
|
@ -174,6 +224,16 @@ class EntityResolverManagerTest extends UnitTestCase {
|
|||
$this->assertEquals(array('entity_test' => array('type' => 'entity:entity_test')), $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
@ -345,11 +405,19 @@ class EntityResolverManagerTest extends UnitTestCase {
|
|||
*/
|
||||
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 @@ class BasicFormNoContainerInjectionInterface implements FormInterface {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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) {
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue