protected function ResourceTestBase::getExpectedGetRelationshipDocument in JSON:API 8
Same name and namespace in other branches
- 8.2 tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getExpectedGetRelationshipDocument()
Gets an expected document 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 document.
Return value
array The expected document array.
2 calls to ResourceTestBase::getExpectedGetRelationshipDocument()
- ResourceTestBase::doTestRelationshipPost in tests/
src/ Functional/ ResourceTestBase.php - Performs one round of relationship POST, PATCH and DELETE route testing.
- ResourceTestBase::getExpectedGetRelationshipResponse in tests/
src/ Functional/ ResourceTestBase.php - Gets an expected ResourceResponse for the given relationship.
File
- tests/
src/ Functional/ ResourceTestBase.php, line 1596
Class
- ResourceTestBase
- Subclass this for every JSON API resource type.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
protected function getExpectedGetRelationshipDocument($relationship_field_name, EntityInterface $entity = NULL) {
$entity = $entity ?: $this->entity;
$entity_type_id = $entity
->getEntityTypeId();
$bundle = $entity
->bundle();
$id = $entity
->uuid();
$self_link = Url::fromUri("base:/jsonapi/{$entity_type_id}/{$bundle}/{$id}/relationships/{$relationship_field_name}")
->setAbsolute()
->toString(TRUE)
->getGeneratedUrl();
$related_link = Url::fromUri("base:/jsonapi/{$entity_type_id}/{$bundle}/{$id}/{$relationship_field_name}")
->setAbsolute()
->toString(TRUE)
->getGeneratedUrl();
$data = $this
->getExpectedGetRelationshipDocumentData($relationship_field_name, $entity);
return [
'data' => $data,
'jsonapi' => [
'meta' => [
'links' => [
'self' => 'http://jsonapi.org/format/1.0/',
],
],
'version' => '1.0',
],
'links' => [
'self' => $self_link,
'related' => $related_link,
],
];
}