public function EntityResourceTest::testGetPagedCollection in JSON:API 8.2
Same name and namespace in other branches
- 8 tests/src/Kernel/Controller/EntityResourceTest.php \Drupal\Tests\jsonapi\Kernel\Controller\EntityResourceTest::testGetPagedCollection()
@covers ::getCollection
File
- tests/
src/ Kernel/ Controller/ EntityResourceTest.php, line 304
Class
- EntityResourceTest
- @coversDefaultClass \Drupal\jsonapi\Controller\EntityResource @group jsonapi @group legacy
Namespace
Drupal\Tests\jsonapi\Kernel\ControllerCode
public function testGetPagedCollection() {
$request = Request::create('/jsonapi/node/article');
$request->query = new ParameterBag([
'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(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
->assertEquals([
'node:2',
'node_list',
], $response
->getCacheableMetadata()
->getCacheTags());
}