public function EntityResourceTest::testPatchIndividualConfig in JSON:API 8
@covers ::patchIndividual @dataProvider patchIndividualConfigProvider
1 call to EntityResourceTest::testPatchIndividualConfig()
- EntityResourceTest::testPatchIndividualFailedConfig in tests/
src/ Kernel/ Controller/ EntityResourceTest.php - @covers ::patchIndividual @dataProvider patchIndividualConfigFailedProvider
File
- tests/
src/ Kernel/ Controller/ EntityResourceTest.php, line 540
Class
- EntityResourceTest
- @coversDefaultClass \Drupal\jsonapi\Controller\EntityResource @group jsonapi @group legacy
Namespace
Drupal\Tests\jsonapi\Kernel\ControllerCode
public function testPatchIndividualConfig($values) {
// List of fields to be ignored.
$ignored_fields = [
'uuid',
'entityTypeId',
'type',
];
$node_type = NodeType::create([
'type' => 'test',
'name' => 'Test Type',
'description' => '',
]);
$node_type
->save();
$parsed_node_type = NodeType::create($values);
Role::load(Role::ANONYMOUS_ID)
->grantPermission('administer content types')
->save();
Role::load(Role::ANONYMOUS_ID)
->grantPermission('edit any article content')
->save();
$payload = Json::encode([
'data' => [
'type' => 'node_type',
'id' => $node_type
->uuid(),
'attributes' => $values,
],
]);
$request = new Request([], [], [], [], [], [], $payload);
$entity_resource = $this
->buildEntityResource('node', 'article');
$response = $entity_resource
->patchIndividual($node_type, $parsed_node_type, $request);
// As a side effect, the node will also be saved.
$this
->assertInstanceOf(JsonApiDocumentTopLevel::class, $response
->getResponseData());
$updated_node_type = $response
->getResponseData()
->getData();
$this
->assertInstanceOf(NodeType::class, $updated_node_type);
// If the field is ignored then we should not see a difference.
foreach ($values as $field_name => $value) {
in_array($field_name, $ignored_fields) ? $this
->assertNotSame($value, $node_type
->get($field_name)) : $this
->assertSame($value, $node_type
->get($field_name));
}
$this
->assertEquals(200, $response
->getStatusCode());
}