You are here

public function ResourceTestBase::testRelated in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::testRelated()

Tests GET of the related resource of an individual resource.

Expected responses are built by making requests to 'relationship' routes. Using the fetched resource identifiers, if any, all targeted resources are fetched individually. These individual responses are then 'merged' into a single expected ResourceResponse. This is repeated for every relationship field of the resource type under test.

2 methods override ResourceTestBase::testRelated()
ItemTest::testRelated in core/modules/jsonapi/tests/src/Functional/ItemTest.php
Tests GET of the related resource of an individual resource.
MessageTest::testRelated in core/modules/jsonapi/tests/src/Functional/MessageTest.php
Tests GET of the related resource of an individual resource.

File

core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php, line 1293

Class

ResourceTestBase
Subclass this for every JSON:API resource type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

public function testRelated() {
  $request_options = [];
  $request_options[RequestOptions::HEADERS]['Accept'] = 'application/vnd.api+json';
  $request_options = NestedArray::mergeDeep($request_options, $this
    ->getAuthenticationRequestOptions());
  $this
    ->doTestRelated($request_options);
  $this
    ->setUpAuthorization('GET');
  $this
    ->doTestRelated($request_options);
}