You are here

public function EntityResourceTest::testGetCollection in JSON:API 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/Controller/EntityResourceTest.php \Drupal\Tests\jsonapi\Kernel\Controller\EntityResourceTest::testGetCollection()

@covers ::getCollection

File

tests/src/Kernel/Controller/EntityResourceTest.php, line 186

Class

EntityResourceTest
@coversDefaultClass \Drupal\jsonapi\Controller\EntityResource @group jsonapi @group legacy

Namespace

Drupal\Tests\jsonapi\Kernel\Controller

Code

public function testGetCollection() {
  $request = new Request([], [], [
    '_route_params' => [
      '_json_api_params' => [],
    ],
    '_json_api_params' => [],
  ]);

  // Get the response.
  $entity_resource = $this
    ->buildEntityResource('node', 'article');
  $response = $entity_resource
    ->getCollection($request);

  // Assertions.
  $this
    ->assertInstanceOf(JsonApiDocumentTopLevel::class, $response
    ->getResponseData());
  $this
    ->assertInstanceOf(EntityCollection::class, $response
    ->getResponseData()
    ->getData());
  $this
    ->assertEquals(1, $response
    ->getResponseData()
    ->getData()
    ->getIterator()
    ->current()
    ->id());
  $this
    ->assertEquals([
    'node:1',
    'node:2',
    'node:3',
    'node:4',
    'node_list',
  ], $response
    ->getCacheableMetadata()
    ->getCacheTags());
}