function ContentTypeHeaderMatcherTest::testJsonRequest
Same name in other branches
- 8.9.x core/tests/Drupal/Tests/Core/Routing/ContentTypeHeaderMatcherTest.php \Drupal\Tests\Core\Routing\ContentTypeHeaderMatcherTest::testJsonRequest()
- 10 core/tests/Drupal/Tests/Core/Routing/ContentTypeHeaderMatcherTest.php \Drupal\Tests\Core\Routing\ContentTypeHeaderMatcherTest::testJsonRequest()
- 11.x core/tests/Drupal/Tests/Core/Routing/ContentTypeHeaderMatcherTest.php \Drupal\Tests\Core\Routing\ContentTypeHeaderMatcherTest::testJsonRequest()
Tests that XML-restricted routes get filtered out on JSON requests.
File
-
core/
tests/ Drupal/ Tests/ Core/ Routing/ ContentTypeHeaderMatcherTest.php, line 71
Class
- ContentTypeHeaderMatcherTest
- Confirm that the content types partial matcher is functioning properly.
Namespace
Drupal\Tests\Core\RoutingCode
public function testJsonRequest() {
$collection = $this->fixtures
->sampleRouteCollection();
$collection->addCollection($this->fixtures
->contentRouteCollection());
$request = Request::create('path/two', 'POST');
$request->headers
->set('Content-type', 'application/json');
$routes = $this->matcher
->filter($collection, $request);
$this->assertCount(6, $routes, 'The correct number of routes was found.');
$this->assertNotNull($routes->get('route_f'), 'The json route was found.');
$this->assertNull($routes->get('route_g'), 'The xml route was not found.');
foreach ($routes as $name => $route) {
$this->assertEquals('route_f', $name, 'The json route is the first one in the collection.');
break;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.