function ContentTypeHeaderMatcherTest::testContentTypeRequestHeaderMissing

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Routing/ContentTypeHeaderMatcherTest.php \Drupal\Tests\Core\Routing\ContentTypeHeaderMatcherTest::testContentTypeRequestHeaderMissing()
  2. 10 core/tests/Drupal/Tests/Core/Routing/ContentTypeHeaderMatcherTest.php \Drupal\Tests\Core\Routing\ContentTypeHeaderMatcherTest::testContentTypeRequestHeaderMissing()
  3. 11.x core/tests/Drupal/Tests/Core/Routing/ContentTypeHeaderMatcherTest.php \Drupal\Tests\Core\Routing\ContentTypeHeaderMatcherTest::testContentTypeRequestHeaderMissing()

Confirms that the matcher throws an exception for missing request header.

@covers ::filter

File

core/tests/Drupal/Tests/Core/Routing/ContentTypeHeaderMatcherTest.php, line 125

Class

ContentTypeHeaderMatcherTest
Confirm that the content types partial matcher is functioning properly.

Namespace

Drupal\Tests\Core\Routing

Code

public function testContentTypeRequestHeaderMissing() {
    $matcher = new ContentTypeHeaderMatcher();
    $routes = $this->fixtures
        ->contentRouteCollection();
    $request = Request::create('path/two', 'POST');
    // Delete all request headers that Request::create() sets by default.
    $request->headers = new ParameterBag();
    $this->expectException(UnsupportedMediaTypeHttpException::class);
    $this->expectExceptionMessage('No "Content-Type" request header specified');
    $matcher->filter($routes, $request);
}

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