RouteMatchTest.php in Zircon Profile 8.0
File
core/tests/Drupal/Tests/Core/Routing/RouteMatchTest.php
View source
<?php
namespace Drupal\Tests\Core\Routing;
use Drupal\Core\Routing\RouteMatch;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
class RouteMatchTest extends RouteMatchTestBase {
protected function getRouteMatch($name, Route $route, array $parameters, array $raw_parameters) {
return new RouteMatch($name, $route, $parameters, $raw_parameters);
}
public function testRouteMatchFromRequest() {
$request = new Request();
$route_match = RouteMatch::createFromRequest($request);
$this
->assertNull($route_match
->getRouteName());
$this
->assertNull($route_match
->getRouteObject());
$this
->assertSame(array(), $route_match
->getParameters()
->all());
$this
->assertNull($route_match
->getParameter('foo'));
$this
->assertSame(array(), $route_match
->getRawParameters()
->all());
$this
->assertNull($route_match
->getRawParameter('foo'));
$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');
$route_match = RouteMatch::createFromRequest($request);
$this
->assertSame('test_route', $route_match
->getRouteName());
$this
->assertSame($route, $route_match
->getRouteObject());
$this
->assertSame(array(
'foo' => '1',
), $route_match
->getParameters()
->all());
$this
->assertSame(array(), $route_match
->getRawParameters()
->all());
$foo = new \stdClass();
$foo->value = 1;
$request->attributes
->set('foo', $foo);
$request->attributes
->set('_raw_variables', new ParameterBag(array(
'foo' => '1',
)));
$route_match = RouteMatch::createFromRequest($request);
$this
->assertSame(array(
'foo' => $foo,
), $route_match
->getParameters()
->all());
$this
->assertSame(array(
'foo' => '1',
), $route_match
->getRawParameters()
->all());
}
}