You are here

public function ContentTypeHeaderMatcherTest::testPostForm in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Routing/ContentTypeHeaderMatcherTest.php \Drupal\Tests\Core\Routing\ContentTypeHeaderMatcherTest::testPostForm()
  2. 9 core/tests/Drupal/Tests/Core/Routing/ContentTypeHeaderMatcherTest.php \Drupal\Tests\Core\Routing\ContentTypeHeaderMatcherTest::testPostForm()

Tests route filtering on POST form submission requests.

File

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

Class

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

Namespace

Drupal\Tests\Core\Routing

Code

public function testPostForm() {
  $collection = $this->fixtures
    ->sampleRouteCollection();
  $collection
    ->addCollection($this->fixtures
    ->contentRouteCollection());

  // Test that all XML and JSON restricted routes get filtered out on a POST
  // form submission.
  $request = Request::create('path/two', 'POST');
  $request->headers
    ->set('Content-type', 'application/www-form-urlencoded');
  $routes = $this->matcher
    ->filter($collection, $request);
  $this
    ->assertCount(5, $routes, 'The correct number of routes was found.');
  $this
    ->assertNull($routes
    ->get('route_f'), 'The json route was found.');
  $this
    ->assertNull($routes
    ->get('route_g'), 'The xml route was not found.');
}