class CurrentRouteMatchTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Routing/CurrentRouteMatchTest.php \Drupal\Tests\Core\Routing\CurrentRouteMatchTest
@coversDefaultClass \Drupal\Core\Routing\CurrentRouteMatch @group Routing
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\Routing\RouteMatchTestBase
- class \Drupal\Tests\Core\Routing\CurrentRouteMatchTest
- class \Drupal\Tests\Core\Routing\RouteMatchTestBase
Expanded class hierarchy of CurrentRouteMatchTest
File
- core/
tests/ Drupal/ Tests/ Core/ Routing/ CurrentRouteMatchTest.php, line 21 - Contains \Drupal\Tests\Core\Routing\CurrentRouteMatchTest.
Namespace
Drupal\Tests\Core\RoutingView source
class CurrentRouteMatchTest extends RouteMatchTestBase {
/**
* {@inheritdoc}
*/
protected function getRouteMatch($name, Route $route, array $parameters, array $raw_parameters) {
$request_stack = new RequestStack();
$request = new Request();
$request_stack
->push($request);
$request = $request_stack
->getCurrentRequest();
$request->attributes = new ParameterBag($parameters);
$request->attributes
->set(RouteObjectInterface::ROUTE_NAME, $name);
$request->attributes
->set(RouteObjectInterface::ROUTE_OBJECT, $route);
$request->attributes
->set('_raw_variables', new ParameterBag($raw_parameters));
return new CurrentRouteMatch($request_stack);
}
/**
* @covers ::__construct
* @covers ::getRouteObject
* @covers ::getCurrentRouteMatch
* @covers ::getRouteMatch
*/
public function testGetCurrentRouteObject() {
$request_stack = new RequestStack();
$request = new Request();
$request_stack
->push($request);
$current_route_match = new CurrentRouteMatch($request_stack);
// Before routing.
$this
->assertNull($current_route_match
->getRouteObject());
// After routing.
$route = new Route('/test-route/{foo}');
$request->attributes
->set(RouteObjectInterface::ROUTE_NAME, 'test_route');
$request->attributes
->set(RouteObjectInterface::ROUTE_OBJECT, $route);
$request->attributes
->set('foo', '1');
$this
->assertSame('1', $current_route_match
->getParameter('foo'));
// Immutable for the same request once a route has been matched.
$request->attributes
->set('foo', '2');
$this
->assertSame('1', $current_route_match
->getParameter('foo'));
// Subrequest.
$subrequest = new Request();
$subrequest->attributes
->set(RouteObjectInterface::ROUTE_NAME, 'test_subrequest_route');
$subrequest->attributes
->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/test-subrequest-route/{foo}'));
$subrequest->attributes
->set('foo', '2');
$request_stack
->push($subrequest);
$this
->assertSame('2', $current_route_match
->getParameter('foo'));
// Restored original request.
$request_stack
->pop();
$this
->assertSame('1', $current_route_match
->getParameter('foo'));
}
/**
* @covers ::getRouteMatchFromRequest
*/
public function testGetRouteMatchFromRequestWithRouting() {
$request_stack = new RequestStack();
$request = new Request();
$request_stack
->push($request);
$current_route_match = new CurrentRouteMatch($request_stack);
$route_match = $current_route_match
->getRouteMatchFromRequest($request);
$this
->assertNull($route_match
->getRouteName());
$this
->assertNull($route_match
->getRouteObject());
}
/**
* @covers ::getRouteMatchFromRequest
*/
public function testGetRouteMatchFromRequest() {
$request_stack = new RequestStack();
$request = new Request();
$request_stack
->push($request);
$route = new Route('/test-route/{foo}');
$request->attributes
->set(RouteObjectInterface::ROUTE_NAME, 'test_route');
$request->attributes
->set(RouteObjectInterface::ROUTE_OBJECT, $route);
$request->attributes
->set('foo', '1');
$current_route_match = new CurrentRouteMatch($request_stack);
$route_match = $current_route_match
->getRouteMatchFromRequest($request);
$this
->assertEquals('test_route', $route_match
->getRouteName());
$this
->assertEquals($route, $route_match
->getRouteObject());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CurrentRouteMatchTest:: |
protected | function |
Build a test route match object for the given implementation. Overrides RouteMatchTestBase:: |
|
CurrentRouteMatchTest:: |
public | function | @covers ::__construct @covers ::getRouteObject @covers ::getCurrentRouteMatch @covers ::getRouteMatch | |
CurrentRouteMatchTest:: |
public | function | @covers ::getRouteMatchFromRequest | |
CurrentRouteMatchTest:: |
public | function | @covers ::getRouteMatchFromRequest | |
RouteMatchTestBase:: |
public | function | Provide sets of parameters and expected parameters for parameter tests. | |
RouteMatchTestBase:: |
public | function | @covers ::getParameter @covers \Drupal\Core\Routing\RouteMatch::getParameterNames @dataProvider routeMatchProvider | |
RouteMatchTestBase:: |
public | function | @covers ::getParameters @covers \Drupal\Core\Routing\RouteMatch::getParameterNames @dataProvider routeMatchProvider | |
RouteMatchTestBase:: |
public | function | @covers ::getRawParameter @covers \Drupal\Core\Routing\RouteMatch::getParameterNames @dataProvider routeMatchProvider | |
RouteMatchTestBase:: |
public | function | @covers ::getRawParameters @covers \Drupal\Core\Routing\RouteMatch::getParameterNames @dataProvider routeMatchProvider | |
RouteMatchTestBase:: |
public | function | @covers ::getRouteName @dataProvider routeMatchProvider | |
RouteMatchTestBase:: |
public | function | @covers ::getRouteObject @dataProvider routeMatchProvider | |
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. | |
UnitTestCase:: |
protected | function | 259 |