function ContentTypeHeaderMatcherTest::testPostForm

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Routing/ContentTypeHeaderMatcherTest.php \Drupal\Tests\Core\Routing\ContentTypeHeaderMatcherTest::testPostForm()
  2. 10 core/tests/Drupal/Tests/Core/Routing/ContentTypeHeaderMatcherTest.php \Drupal\Tests\Core\Routing\ContentTypeHeaderMatcherTest::testPostForm()
  3. 11.x 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.');
}

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