function ResourceTestBase::doTestRelationshipGet

Same name in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::doTestRelationshipGet()
  2. 8.9.x core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::doTestRelationshipGet()
  3. 10 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::doTestRelationshipGet()

Performs one round of relationship route testing.

Parameters

array $request_options: Request options to apply.

See also

\GuzzleHttp\ClientInterface::request()

::testRelationships

1 call to ResourceTestBase::doTestRelationshipGet()
ResourceTestBase::testRelationships in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Tests CRUD of individual resource relationship data.

File

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

Class

ResourceTestBase
Subclass this for every JSON:API resource type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function doTestRelationshipGet(array $request_options) {
    $relationship_field_names = $this->getRelationshipFieldNames($this->entity);
    // If there are no relationship fields, we can't test relationship routes.
    if (empty($relationship_field_names)) {
        return;
    }
    // Test GET.
    $related_responses = $this->getRelationshipResponses($relationship_field_names, $request_options);
    foreach ($relationship_field_names as $relationship_field_name) {
        $expected_resource_response = $this->getExpectedGetRelationshipResponse($relationship_field_name);
        $expected_document = $expected_resource_response->getResponseData();
        $expected_cacheability = $expected_resource_response->getCacheableMetadata();
        $actual_response = $related_responses[$relationship_field_name];
        $this->assertResourceResponse($expected_resource_response->getStatusCode(), $expected_document, $actual_response, $expected_cacheability->getCacheTags(), $expected_cacheability->getCacheContexts(), 'UNCACHEABLE (request policy)', empty(array_intersect([
            'user',
            'session',
        ], $expected_cacheability->getCacheContexts())) ? $expected_resource_response->isSuccessful() ? 'MISS' : FALSE : 'UNCACHEABLE (poor cacheability)');
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.