function RequestFormatRouteFilterTest::testNoRouteFound
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php \Drupal\Tests\Core\Routing\RequestFormatRouteFilterTest::testNoRouteFound()
- 8.9.x core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php \Drupal\Tests\Core\Routing\RequestFormatRouteFilterTest::testNoRouteFound()
- 11.x core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php \Drupal\Tests\Core\Routing\RequestFormatRouteFilterTest::testNoRouteFound()
@covers ::filter
File
-
core/
tests/ Drupal/ Tests/ Core/ Routing/ RequestFormatRouteFilterTest.php, line 66
Class
- RequestFormatRouteFilterTest
- @coversDefaultClass \Drupal\Core\Routing\RequestFormatRouteFilter @group Routing
Namespace
Drupal\Tests\Core\RoutingCode
public function testNoRouteFound() : void {
$url = $this->prophesize(GeneratedUrl::class);
$url_assembler = $this->prophesize(UnroutedUrlAssemblerInterface::class);
$url_assembler->assemble('http://localhost/test?_format=xml', [
'query' => [
'_format' => 'json',
],
'external' => TRUE,
], TRUE)
->willReturn($url);
$container = new ContainerBuilder();
$container->set('unrouted_url_assembler', $url_assembler->reveal());
\Drupal::setContainer($container);
$collection = new RouteCollection();
$route_with_format = new Route('/test');
$route_with_format->setRequirement('_format', 'json');
$collection->add('test_0', $route_with_format);
$collection->add('test_1', clone $route_with_format);
$request = Request::create('test?_format=xml', 'GET');
$request->setRequestFormat('xml');
$route_filter = new RequestFormatRouteFilter();
$this->expectException(NotAcceptableHttpException::class);
$this->expectExceptionMessage('No route found for the specified format xml.');
$route_filter->filter($collection, $request);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.