You are here

public function EntityResourceTest::testGetEmptyCollection 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::testGetEmptyCollection()

@covers ::getCollection

File

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

Class

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

Namespace

Drupal\Tests\jsonapi\Kernel\Controller

Code

public function testGetEmptyCollection() {
  $filter = new Filter(new EntityConditionGroup('AND', [
    new EntityCondition('uuid', 'invalid'),
  ]));
  $request = new Request([], [], [
    '_route_params' => [
      '_json_api_params' => [
        'filter' => $filter,
      ],
    ],
    '_json_api_params' => [
      'filter' => $filter,
    ],
  ]);

  // 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(0, $response
    ->getResponseData()
    ->getData()
    ->count());
  $this
    ->assertEquals([
    'node_list',
  ], $response
    ->getCacheableMetadata()
    ->getCacheTags());
}