function AcceptHeaderMatcherTest::testAcceptFiltering
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Routing/AcceptHeaderMatcherTest.php \Drupal\Tests\Core\Routing\AcceptHeaderMatcherTest::testAcceptFiltering()
- 8.9.x core/tests/Drupal/Tests/Core/Routing/AcceptHeaderMatcherTest.php \Drupal\Tests\Core\Routing\AcceptHeaderMatcherTest::testAcceptFiltering()
- 10 core/tests/Drupal/Tests/Core/Routing/AcceptHeaderMatcherTest.php \Drupal\Tests\Core\Routing\AcceptHeaderMatcherTest::testAcceptFiltering()
Tests that requests using Accept headers get filtered correctly.
@dataProvider acceptFilterProvider
Parameters
string $accept_header: The HTTP Accept header value of the request.
string $format: The request format.
string $included_route: The route name that should survive the filter and be ranked first.
string $excluded_route: The route name that should be filtered out during matching.
File
-
core/
tests/ Drupal/ Tests/ Core/ Routing/ AcceptHeaderMatcherTest.php, line 73
Class
- AcceptHeaderMatcherTest
- Confirm that the mime types partial matcher is functioning properly.
Namespace
Drupal\Tests\Core\RoutingCode
public function testAcceptFiltering($accept_header, $format, $included_route, $excluded_route) : void {
$collection = $this->fixtures
->sampleRouteCollection();
$request = Request::create('path/two', 'GET');
$request->headers
->set('Accept', $accept_header);
$request->setRequestFormat($format);
$routes = $this->matcher
->filter($collection, $request);
$this->assertCount(4, $routes, 'The correct number of routes was found.');
$this->assertNotNull($routes->get($included_route), "Route {$included_route} was found when matching {$accept_header}.");
$this->assertNull($routes->get($excluded_route), "Route {$excluded_route} was not found when matching {$accept_header}.");
foreach ($routes as $name => $route) {
$this->assertEquals($name, $included_route, "Route {$included_route} is the first one in the collection when matching {$accept_header}.");
break;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.