Issue #1777430 by Crell, sun, tim.plunkett: Fixed Allow for ContainerAware controllers.

8.0.x
webchick 2012-09-12 23:16:39 -07:00
parent 3d2aad9e0a
commit 09b998f131
3 changed files with 64 additions and 0 deletions

View File

@ -60,5 +60,7 @@ class ControllerResolver extends BaseControllerResolver {
if ($controller[0] instanceof ContainerAwareInterface) {
$controller[0]->setContainer($this->container);
}
return $controller;
}
}

View File

@ -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.');
}
}

View File

@ -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() {}
}