View source
<?php
namespace Drupal\Tests\Core\Routing;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\Routing\Route;
abstract class RouteMatchTestBase extends UnitTestCase {
protected abstract function getRouteMatch($name, Route $route, array $parameters, array $raw_parameters);
public function routeMatchProvider() {
$base_data = array(
array(
new Route('/test-route/{param_without_leading_underscore}/{_param_with_leading_underscore}', array(
'default_without_leading_underscore' => NULL,
'_default_with_leading_underscore' => NULL,
)),
array(
'param_without_leading_underscore' => 'value',
'_param_with_leading_underscore' => 'value',
'default_without_leading_underscore' => 'value',
'_default_with_leading_underscore' => 'value',
'foo' => 'value',
),
array(
'param_without_leading_underscore' => 'value',
'_param_with_leading_underscore' => 'value',
'default_without_leading_underscore' => 'value',
),
),
);
$data = array();
foreach ($base_data as $entry) {
$route = $entry[0];
$params = $entry[1];
$expected_params = $entry[2];
$data[] = array(
$this
->getRouteMatch('test_route', $route, $params, $params),
$route,
$params,
$expected_params,
);
}
return $data;
}
public function testGetRouteName(RouteMatchInterface $route_match) {
$this
->assertSame('test_route', $route_match
->getRouteName());
}
public function testGetRouteObject(RouteMatchInterface $route_match, Route $route) {
$this
->assertSame($route, $route_match
->getRouteObject());
}
public function testGetParameter(RouteMatchInterface $route_match, Route $route, $parameters, $expected_filtered_parameters) {
foreach ($expected_filtered_parameters as $name => $expected_value) {
$this
->assertSame($expected_value, $route_match
->getParameter($name));
}
foreach (array_diff_key($parameters, $expected_filtered_parameters) as $name) {
$this
->assertNull($route_match
->getParameter($name));
}
}
public function testGetParameters(RouteMatchInterface $route_match, Route $route, $parameters, $expected_filtered_parameters) {
$this
->assertSame($expected_filtered_parameters, $route_match
->getParameters()
->all());
}
public function testGetRawParameter(RouteMatchInterface $route_match, Route $route, $parameters, $expected_filtered_parameters) {
foreach ($expected_filtered_parameters as $name => $expected_value) {
$this
->assertSame($expected_value, $route_match
->getRawParameter($name));
}
foreach (array_diff_key($parameters, $expected_filtered_parameters) as $name) {
$this
->assertNull($route_match
->getRawParameter($name));
}
}
public function testGetRawParameters(RouteMatchInterface $route_match, Route $route, $parameters, $expected_filtered_parameters) {
$this
->assertSame($expected_filtered_parameters, $route_match
->getRawParameters()
->all());
}
}