function EntityResourceTest::testGetPagedCollection

Same name and namespace in other branches
  1. 9 core/modules/jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php \Drupal\Tests\jsonapi\Kernel\Controller\EntityResourceTest::testGetPagedCollection()
  2. 8.9.x core/modules/jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php \Drupal\Tests\jsonapi\Kernel\Controller\EntityResourceTest::testGetPagedCollection()
  3. 11.x core/modules/jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php \Drupal\Tests\jsonapi\Kernel\Controller\EntityResourceTest::testGetPagedCollection()

@covers ::getCollection

File

core/modules/jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php, line 198

Class

EntityResourceTest
@coversDefaultClass \Drupal\jsonapi\Controller\EntityResource[[api-linebreak]] @group jsonapi

Namespace

Drupal\Tests\jsonapi\Kernel\Controller

Code

public function testGetPagedCollection() : void {
  $request = Request::create('/jsonapi/node/article');
  $request->query = new InputBag([
    'sort' => 'nid',
    'page' => [
      'offset' => 1,
      'limit' => 1,
    ],
  ]);
  $entity_resource = $this->createEntityResource();
  // Get the response.
  $resource_type = $this->container
    ->get('jsonapi.resource_type.repository')
    ->get('node', 'article');
  $response = $entity_resource->getCollection($resource_type, $request);
  // Assertions.
  $this->assertInstanceOf(CacheableResourceResponse::class, $response);
  $this->assertInstanceOf(JsonApiDocumentTopLevel::class, $response->getResponseData());
  $this->assertInstanceOf(Data::class, $response->getResponseData()
    ->getData());
  $data = $response->getResponseData()
    ->getData();
  $this->assertCount(1, $data);
  $this->assertEquals($this->node2
    ->uuid(), $data->toArray()[0]
    ->getId());
  $this->assertEqualsCanonicalizing([
    'node:2',
    'node_list',
  ], $response->getCacheableMetadata()
    ->getCacheTags());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.