public function EntityResourceTest::testPatchRelationship in JSON:API 8
@covers ::patchRelationship @dataProvider patchRelationshipProvider
File
- tests/
src/ Kernel/ Controller/ EntityResourceTest.php, line 704
Class
- EntityResourceTest
- @coversDefaultClass \Drupal\jsonapi\Controller\EntityResource @group jsonapi @group legacy
Namespace
Drupal\Tests\jsonapi\Kernel\ControllerCode
public function testPatchRelationship($relationships) {
$this->node->field_relationships
->appendItem([
'target_id' => $this->node
->id(),
]);
$this->node
->save();
$parsed_field_list = $this->container
->get('plugin.manager.field.field_type')
->createFieldItemList($this->node, 'field_relationships', $relationships);
Role::load(Role::ANONYMOUS_ID)
->grantPermission('edit any article content')
->save();
$entity_resource = $this
->buildEntityResource('node', 'article', [
'field_relationships' => [
new ResourceType('node', 'article', NULL),
],
]);
$response = $entity_resource
->patchRelationship($this->node, 'field_relationships', $parsed_field_list, new Request());
// As a side effect, the node will also be saved.
$this
->assertNotEmpty($this->node
->id());
$this
->assertInstanceOf(JsonApiDocumentTopLevel::class, $response
->getResponseData());
$field_list = $response
->getResponseData()
->getData();
$this
->assertInstanceOf(EntityReferenceFieldItemListInterface::class, $field_list);
$this
->assertSame('field_relationships', $field_list
->getName());
$this
->assertEquals($relationships, $field_list
->getValue());
$this
->assertEquals(204, $response
->getStatusCode());
}