Issue #1777430 by Crell, sun, tim.plunkett: Fixed Allow for ContainerAware controllers.
parent
3d2aad9e0a
commit
09b998f131
|
@ -60,5 +60,7 @@ class ControllerResolver extends BaseControllerResolver {
|
|||
if ($controller[0] instanceof ContainerAwareInterface) {
|
||||
$controller[0]->setContainer($this->container);
|
||||
}
|
||||
|
||||
return $controller;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of Drupal\system\Tests\Routing\ControllerResolverTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\system\Tests\Routing;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
use Drupal\Core\ControllerResolver;
|
||||
use Drupal\simpletest\UnitTestBase;
|
||||
|
||||
/**
|
||||
* Tests that the Drupal-extended ControllerResolver is functioning properly.
|
||||
*/
|
||||
class ControllerResolverTest extends UnitTestBase {
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => '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.');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of Drupal\system\Tests\Routing\MockController.
|
||||
*/
|
||||
|
||||
namespace Drupal\system\Tests\Routing;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
|
||||
/**
|
||||
* Dummy class, just for testing.
|
||||
*/
|
||||
class MockController extends ContainerAware {
|
||||
|
||||
public function run() {}
|
||||
|
||||
}
|
Loading…
Reference in New Issue