protected function ResourceTestBase::doTestRelationshipGet in JSON:API 8
Same name and namespace in other branches
- 8.2 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 tests/
src/ Functional/ ResourceTestBase.php - Tests CRUD of individual resource relationship data.
File
- tests/
src/ Functional/ ResourceTestBase.php, line 1355
Class
- ResourceTestBase
- Subclass this for every JSON API resource type.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
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();
$actual_response = $related_responses[$relationship_field_name];
/* @var \Psr\Http\Message\ResponseInterface $actual_response */
$actual_document = Json::decode((string) $actual_response
->getBody());
$this
->assertSameDocument($expected_document, $actual_document);
$this
->assertSame($expected_resource_response
->getStatusCode(), $actual_response
->getStatusCode());
}
}