function RequestFormatRouteFilterTest::testNoRouteFoundWhenNoRequestFormatAndSingleRouteWithMultipleFormats

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php \Drupal\Tests\Core\Routing\RequestFormatRouteFilterTest::testNoRouteFoundWhenNoRequestFormatAndSingleRouteWithMultipleFormats()
  2. 8.9.x core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php \Drupal\Tests\Core\Routing\RequestFormatRouteFilterTest::testNoRouteFoundWhenNoRequestFormatAndSingleRouteWithMultipleFormats()
  3. 10 core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php \Drupal\Tests\Core\Routing\RequestFormatRouteFilterTest::testNoRouteFoundWhenNoRequestFormatAndSingleRouteWithMultipleFormats()

@covers ::filter

File

core/tests/Drupal/Tests/Core/Routing/RequestFormatRouteFilterTest.php, line 92

Class

RequestFormatRouteFilterTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Routing%21RequestFormatRouteFilter.php/class/RequestFormatRouteFilter/11.x" title="Provides a route filter, which filters by the request format." class="local">\Drupal\Core\Routing\RequestFormatRouteFilter</a> @group Routing

Namespace

Drupal\Tests\Core\Routing

Code

public function testNoRouteFoundWhenNoRequestFormatAndSingleRouteWithMultipleFormats() : void {
    $this->expectException(NotAcceptableHttpException::class);
    $this->expectExceptionMessage('No route found for the specified format html.');
    $url = $this->prophesize(GeneratedUrl::class);
    $url_assembler = $this->prophesize(UnroutedUrlAssemblerInterface::class);
    $url_assembler->assemble('http://localhost/test', [
        'query' => [
            '_format' => 'json',
        ],
        'external' => TRUE,
    ], TRUE)
        ->willReturn($url);
    $url_assembler->assemble('http://localhost/test', [
        'query' => [
            '_format' => 'xml',
        ],
        '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|xml');
    $collection->add('sole_route_multiple_formats', $route_with_format);
    $request = Request::create('test', 'GET');
    $route_filter = new RequestFormatRouteFilter();
    $route_filter->filter($collection, $request);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.