class AccessAwareRouterTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php \Drupal\Tests\Core\Routing\AccessAwareRouterTest
@coversDefaultClass \Drupal\Core\Routing\AccessAwareRouter @group Routing
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\Routing\AccessAwareRouterTest
Expanded class hierarchy of AccessAwareRouterTest
File
- core/
tests/ Drupal/ Tests/ Core/ Routing/ AccessAwareRouterTest.php, line 22 - Contains \Drupal\Tests\Core\Routing\AccessAwareRouterTest.
Namespace
Drupal\Tests\Core\RoutingView source
class AccessAwareRouterTest extends UnitTestCase {
/**
* @var \Symfony\Component\Routing\Route
*/
protected $route;
/**
* @var \Symfony\Cmf\Component\Routing\ChainRouter|\PHPUnit_Framework_MockObject_MockObject
*/
protected $chainRouter;
/**
* @var \Drupal\Core\Access\AccessManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $accessManager;
/**
* @var \Drupal\Core\Session\AccountInterface||\PHPUnit_Framework_MockObject_MockObject
*/
protected $currentUser;
/**
* @var \Drupal\Core\Routing\AccessAwareRouter
*/
protected $router;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->route = new Route('test');
$this->accessManager = $this
->getMock('Drupal\\Core\\Access\\AccessManagerInterface');
$this->currentUser = $this
->getMock('Drupal\\Core\\Session\\AccountInterface');
}
/**
* Sets up a chain router with matchRequest.
*/
protected function setupRouter() {
$this->chainRouter = $this
->getMockBuilder('Symfony\\Cmf\\Component\\Routing\\ChainRouter')
->disableOriginalConstructor()
->getMock();
$this->chainRouter
->expects($this
->once())
->method('matchRequest')
->will($this
->returnValue(array(
RouteObjectInterface::ROUTE_OBJECT => $this->route,
)));
$this->router = new AccessAwareRouter($this->chainRouter, $this->accessManager, $this->currentUser);
}
/**
* Tests the matchRequest() function for access allowed.
*/
public function testMatchRequestAllowed() {
$this
->setupRouter();
$request = new Request();
$access_result = AccessResult::allowed();
$this->accessManager
->expects($this
->once())
->method('checkRequest')
->with($request)
->willReturn($access_result);
$parameters = $this->router
->matchRequest($request);
$expected = [
RouteObjectInterface::ROUTE_OBJECT => $this->route,
AccessAwareRouterInterface::ACCESS_RESULT => $access_result,
];
$this
->assertSame($expected, $request->attributes
->all());
$this
->assertSame($expected, $parameters);
}
/**
* Tests the matchRequest() function for access denied.
*
* @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
*/
public function testMatchRequestDenied() {
$this
->setupRouter();
$request = new Request();
$access_result = AccessResult::forbidden();
$this->accessManager
->expects($this
->once())
->method('checkRequest')
->with($request)
->willReturn($access_result);
$parameters = $this->router
->matchRequest($request);
$expected = [
AccessAwareRouterInterface::ACCESS_RESULT => $access_result,
];
$this
->assertSame($expected, $request->attributes
->all());
$this
->assertSame($expected, $parameters);
}
/**
* Ensure that methods are passed to the wrapped router.
*
* @covers ::__call
*/
public function testCall() {
$mock_router = $this
->getMock('Symfony\\Component\\Routing\\RouterInterface');
$this->chainRouter = $this
->getMockBuilder('Symfony\\Cmf\\Component\\Routing\\ChainRouter')
->disableOriginalConstructor()
->setMethods([
'add',
])
->getMock();
$this->chainRouter
->expects($this
->once())
->method('add')
->with($mock_router)
->willReturnSelf();
$this->router = new AccessAwareRouter($this->chainRouter, $this->accessManager, $this->currentUser);
$this->router
->add($mock_router);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AccessAwareRouterTest:: |
protected | property | ||
AccessAwareRouterTest:: |
protected | property | ||
AccessAwareRouterTest:: |
protected | property | ||
AccessAwareRouterTest:: |
protected | property | ||
AccessAwareRouterTest:: |
protected | property | ||
AccessAwareRouterTest:: |
public | function |
Overrides UnitTestCase:: |
|
AccessAwareRouterTest:: |
protected | function | Sets up a chain router with matchRequest. | |
AccessAwareRouterTest:: |
public | function | Ensure that methods are passed to the wrapped router. | |
AccessAwareRouterTest:: |
public | function | Tests the matchRequest() function for access allowed. | |
AccessAwareRouterTest:: |
public | function | Tests the matchRequest() function for access denied. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |