You are here

protected function ResourceTestBase::getExpectedGetRelationshipResponse in JSON:API 8

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

Gets an expected ResourceResponse for the given relationship.

Parameters

string $relationship_field_name: The relationship for which to get an expected response.

\Drupal\Core\Entity\EntityInterface|null $entity: (optional) The entity for which to get expected relationship response.

Return value

\Drupal\jsonapi\ResourceResponse The expected ResourceResponse.

2 calls to ResourceTestBase::getExpectedGetRelationshipResponse()
ResourceTestBase::doTestRelationshipGet in tests/src/Functional/ResourceTestBase.php
Performs one round of relationship route testing.
ResourceTestBase::getExpectedRelatedResponses in tests/src/Functional/ResourceTestBase.php
Builds an array of expected related ResourceResponses, keyed by field name.

File

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

Class

ResourceTestBase
Subclass this for every JSON API resource type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function getExpectedGetRelationshipResponse($relationship_field_name, EntityInterface $entity = NULL) {
  $entity = $entity ?: $this->entity;
  $access = static::entityFieldAccess($entity, $relationship_field_name, 'view', $this->account);
  if (!$access
    ->isAllowed()) {
    return static::getAccessDeniedResponse($this->entity, $access, $relationship_field_name, 'The current user is not allowed to view this relationship.');
  }
  $expected_document = $this
    ->getExpectedGetRelationshipDocument($relationship_field_name);
  $status_code = isset($expected_document['errors'][0]['status']) ? $expected_document['errors'][0]['status'] : 200;
  $resource_response = new ResourceResponse($expected_document, $status_code);
  return $resource_response;
}