You are here

public function ResourceTestBase::testRelated in JSON:API 8

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

Tests GETing 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.

4 methods override ResourceTestBase::testRelated()
BlockContentTest::testRelated in tests/src/Functional/BlockContentTest.php
Tests GETing related resource of an individual resource.
CommentTest::testRelated in tests/src/Functional/CommentTest.php
Tests GETing related resource of an individual resource.
ItemTest::testRelated in tests/src/Functional/ItemTest.php
Tests GETing related resource of an individual resource.
MessageTest::testRelated in tests/src/Functional/MessageTest.php
Tests GETing related resource of an individual resource.

File

tests/src/Functional/ResourceTestBase.php, line 1250

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);
}