public function ResourceTestBase::testRelationships in JSON:API 8
Same name and namespace in other branches
- 8.2 tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::testRelationships()
Tests CRUD of individual resource relationship data.
Unlike the "related" routes, relationship routes only return information about the "relationship" itself, not the targeted resources. For JSON API with Drupal, relationship routes are like looking at an entity reference field without loading the entities. It only reveals the type of the targeted resource and the target resource IDs. These type+ID combos are referred to as "resource identifiers."
3 methods override ResourceTestBase::testRelationships()
- ItemTest::testRelationships in tests/
src/ Functional/ ItemTest.php - Tests CRUD of individual resource relationship data.
- MessageTest::testRelationships in tests/
src/ Functional/ MessageTest.php - Tests CRUD of individual resource relationship data.
- ShortcutTest::testRelationships in tests/
src/ Functional/ ShortcutTest.php - Tests CRUD of individual resource relationship data.
File
- tests/
src/ Functional/ ResourceTestBase.php, line 1269
Class
- ResourceTestBase
- Subclass this for every JSON API resource type.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
public function testRelationships() {
if ($this->entity instanceof ConfigEntityInterface) {
$this
->markTestSkipped('Configuration entities cannot have relationships.');
}
$request_options = [];
$request_options[RequestOptions::HEADERS]['Accept'] = 'application/vnd.api+json';
$request_options = NestedArray::mergeDeep($request_options, $this
->getAuthenticationRequestOptions());
// Test GET.
$this
->doTestRelationshipGet($request_options);
$this
->setUpAuthorization('GET');
$this
->doTestRelationshipGet($request_options);
// Test POST.
$this
->doTestRelationshipPost($request_options);
// Grant entity-level edit access.
$this
->setUpAuthorization('PATCH');
$this
->doTestRelationshipPost($request_options);
// Field edit access is still forbidden, grant it.
$this
->grantPermissionsToTestedRole([
'field_jsonapi_test_entity_ref view access',
'field_jsonapi_test_entity_ref edit access',
'field_jsonapi_test_entity_ref update access',
]);
$this
->doTestRelationshipPost($request_options);
}