You are here

public function RoutesTest::testRoutesCollection in JSON:API 8

Same name and namespace in other branches
  1. 8.2 tests/src/Unit/Routing/RoutesTest.php \Drupal\Tests\jsonapi\Unit\Routing\RoutesTest::testRoutesCollection()

@covers ::routes

File

tests/src/Unit/Routing/RoutesTest.php, line 63

Class

RoutesTest
@coversDefaultClass \Drupal\jsonapi\Routing\Routes @group jsonapi

Namespace

Drupal\Tests\jsonapi\Unit\Routing

Code

public function testRoutesCollection() {

  // Get the route collection and start making assertions.
  $routes = $this->routes['ok']
    ->routes();

  // Make sure that there are 4 routes for the non-internal resource and 1 for
  // the entry point.
  $this
    ->assertEquals(5, $routes
    ->count());
  $iterator = $routes
    ->getIterator();

  // Check the collection route.

  /** @var \Symfony\Component\Routing\Route $route */
  $route = $iterator
    ->offsetGet('jsonapi.entity_type_1--bundle_1_1.collection');
  $this
    ->assertSame('/jsonapi/entity_type_1/bundle_1_1', $route
    ->getPath());
  $this
    ->assertSame([
    'lorem',
    'ipsum',
  ], $route
    ->getOption('_auth'));
  $this
    ->assertSame('entity_type_1--bundle_1_1', $route
    ->getDefault(Routes::RESOURCE_TYPE_KEY));
  $this
    ->assertEquals([
    'GET',
    'POST',
  ], $route
    ->getMethods());
  $this
    ->assertSame(Routes::FRONT_CONTROLLER, $route
    ->getDefault(RouteObjectInterface::CONTROLLER_NAME));
  $this
    ->assertSame('Drupal\\jsonapi\\Resource\\JsonApiDocumentTopLevel', $route
    ->getDefault('serialization_class'));
}