public function EntityResourceTest::testPatchIndividual in JSON:API 8
Same name and namespace in other branches
- 8.2 tests/src/Kernel/Controller/EntityResourceTest.php \Drupal\Tests\jsonapi\Kernel\Controller\EntityResourceTest::testPatchIndividual()
@covers ::patchIndividual @dataProvider patchIndividualProvider
File
- tests/
src/ Kernel/ Controller/ EntityResourceTest.php, line 488
Class
- EntityResourceTest
- @coversDefaultClass \Drupal\jsonapi\Controller\EntityResource @group jsonapi @group legacy
Namespace
Drupal\Tests\jsonapi\Kernel\ControllerCode
public function testPatchIndividual($values) {
$parsed_node = Node::create($values);
Role::load(Role::ANONYMOUS_ID)
->grantPermission('edit any article content')
->save();
$payload = Json::encode([
'data' => [
'type' => 'article',
'id' => $this->node
->uuid(),
'attributes' => [
'title' => '',
'field_relationships' => '',
],
],
]);
$request = new Request([], [], [], [], [], [], $payload);
// Create a new EntityResource that uses uuid.
$entity_resource = $this
->buildEntityResource('node', 'article');
$response = $entity_resource
->patchIndividual($this->node, $parsed_node, $request);
// As a side effect, the node will also be saved.
$this
->assertInstanceOf(JsonApiDocumentTopLevel::class, $response
->getResponseData());
$updated_node = $response
->getResponseData()
->getData();
$this
->assertInstanceOf(Node::class, $updated_node);
$this
->assertSame($values['title'], $this->node
->getTitle());
$this
->assertSame($values['field_relationships'], $this->node
->get('field_relationships')
->getValue());
$this
->assertEquals(200, $response
->getStatusCode());
}