You are here

public function AcceptHeaderMatcherTest::testAcceptFiltering in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/tests/modules/accept_header_routing_test/tests/Unit/AcceptHeaderMatcherTest.php \Drupal\Tests\accept_header_routing_teste\Unit\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/modules/system/tests/modules/accept_header_routing_test/tests/Unit/AcceptHeaderMatcherTest.php, line 76
Contains \Drupal\Tests\accept_header_routing_teste\Unit\Routing\AcceptHeaderMatcherTest.

Class

AcceptHeaderMatcherTest
Confirm that the mime types partial matcher is functioning properly.

Namespace

Drupal\Tests\accept_header_routing_teste\Unit\Routing

Code

public function testAcceptFiltering($accept_header, $format, $included_route, $excluded_route) {
  $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
    ->assertEquals(count($routes), 4, '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;
  }
}