You are here

public function EntityResourceTest::testGetEmptyCollection in Drupal 9

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

@covers ::getCollection

File

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

Class

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

Namespace

Drupal\Tests\jsonapi\Kernel\Controller

Code

public function testGetEmptyCollection() {
  $request = Request::create('/jsonapi/node/article');
  $request->query = new ParameterBag([
    'filter' => [
      'id' => 'invalid',
    ],
  ]);

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

  // Assertions.
  $this
    ->assertInstanceOf(CacheableResourceResponse::class, $response);
  $this
    ->assertInstanceOf(JsonApiDocumentTopLevel::class, $response
    ->getResponseData());
  $this
    ->assertInstanceOf(Data::class, $response
    ->getResponseData()
    ->getData());
  $this
    ->assertEquals(0, $response
    ->getResponseData()
    ->getData()
    ->count());
  $this
    ->assertEquals([
    'node_list',
  ], $response
    ->getCacheableMetadata()
    ->getCacheTags());
}