You are here

public function ContentTypeHeaderMatcherTest::testJsonRequest in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 60
Contains \Drupal\Tests\Core\Routing\ContentTypeHeaderMatcherTest.

Class

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

Namespace

Drupal\Tests\Core\Routing

Code

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
    ->assertEquals(count($routes), 6, '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($name, 'route_f', 'The json route is the first one in the collection.');
    break;
  }
}