You are here

public function EntityResourceTest::testGetCollection in JSON:API 8.2

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

@covers ::getCollection

File

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

Class

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

Namespace

Drupal\Tests\jsonapi\Kernel\Controller

Code

public function testGetCollection() {
  $request = Request::create('/jsonapi/node/article');
  $request->query = new ParameterBag([
    'sort' => 'nid',
  ]);

  // Get the response.
  $resource_type = new ResourceType('node', 'article', NULL);
  $response = $this->entityResource
    ->getCollection($resource_type, $request);

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