You are here

public function AcceptHeaderMatcherTest::testNoRouteFound in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Routing/AcceptHeaderMatcherTest.php \Drupal\Tests\Core\Routing\AcceptHeaderMatcherTest::testNoRouteFound()
  2. 10 core/tests/Drupal/Tests/Core/Routing/AcceptHeaderMatcherTest.php \Drupal\Tests\Core\Routing\AcceptHeaderMatcherTest::testNoRouteFound()

Confirms that the AcceptHeaderMatcher throws an exception for no-route.

File

core/tests/Drupal/Tests/Core/Routing/AcceptHeaderMatcherTest.php, line 90

Class

AcceptHeaderMatcherTest
Confirm that the mime types partial matcher is functioning properly.

Namespace

Drupal\Tests\Core\Routing

Code

public function testNoRouteFound() {

  // Remove the sample routes that would match any method.
  $routes = $this->fixtures
    ->sampleRouteCollection();
  $routes
    ->remove('route_a');
  $routes
    ->remove('route_b');
  $routes
    ->remove('route_c');
  $routes
    ->remove('route_d');
  $request = Request::create('path/two', 'GET');
  $request->headers
    ->set('Accept', 'application/json, text/xml;q=0.9');
  $request
    ->setRequestFormat('json');
  $this
    ->expectException(NotAcceptableHttpException::class);
  $this
    ->expectExceptionMessage('No route found for the specified formats application/json text/xml');
  $this->matcher
    ->filter($routes, $request);
}