function JsonApiFunctionalTest::testMetaRelationEventOnRelationshipEndpoint
Tests adding metadata to the relationship endpoint.
File
-
core/
modules/ jsonapi/ tests/ src/ Functional/ JsonApiFunctionalTest.php, line 693
Class
- JsonApiFunctionalTest
- General functional test class.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
public function testMetaRelationEventOnRelationshipEndpoint() : void {
$this->createDefaultContent(1, 1, FALSE, FALSE, static::IS_NOT_MULTILINGUAL);
$this->container
->get('module_installer')
->install([
'jsonapi_test_meta_events',
]);
$node = $this->nodes[0];
\Drupal::state()->set('jsonapi_test_meta_events.relationship_meta', [
'enabled_type' => 'node--article',
'enabled_relation' => 'field_tags',
'enabled_id' => $node->uuid(),
'fields' => [
'name',
],
]);
// Test if relationship has correct metadata when loading a single resource
$str = $this->drupalGet('jsonapi/node/article/' . $node->uuid() . '/relationships/field_tags');
$resource = Json::decode($str);
$this->assertArrayHasKey('meta', $resource);
$this->assertArrayHasKey('relationship_meta_name', $resource['meta']);
// Test that the tag is added to the meta of the document.
$this->assertEquals([
$node->get('field_tags')->entity
->getName(),
], $resource['meta']['relationship_meta_name']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.