protected function ResourceTestBase::makeNormalizationInvalid in Drupal 9
Same name and namespace in other branches
- 8 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::makeNormalizationInvalid()
Makes the given JSON:API document invalid.
Parameters
array $document: A JSON:API document.
string $entity_key: The entity key whose normalization to make invalid.
Return value
array The updated JSON:API document, now invalid.
2 calls to ResourceTestBase::makeNormalizationInvalid()
- ResourceTestBase::testPatchIndividual in core/
modules/ jsonapi/ tests/ src/ Functional/ ResourceTestBase.php - Tests PATCHing an individual resource, plus edge cases to ensure good DX.
- ResourceTestBase::testPostIndividual in core/
modules/ jsonapi/ tests/ src/ Functional/ ResourceTestBase.php - Tests POSTing an individual resource, plus edge cases to ensure good DX.
1 method overrides ResourceTestBase::makeNormalizationInvalid()
- UserTest::makeNormalizationInvalid in core/
modules/ jsonapi/ tests/ src/ Functional/ UserTest.php - Makes the given JSON:API document invalid.
File
- core/
modules/ jsonapi/ tests/ src/ Functional/ ResourceTestBase.php, line 878
Class
- ResourceTestBase
- Subclass this for every JSON:API resource type.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
protected function makeNormalizationInvalid(array $document, $entity_key) {
$entity_type = $this->entity
->getEntityType();
switch ($entity_key) {
case 'label':
// Add a second label to this entity to make it invalid.
$label_field = $entity_type
->hasKey('label') ? $entity_type
->getKey('label') : static::$labelFieldName;
$document['data']['attributes'][$label_field] = [
0 => $document['data']['attributes'][$label_field],
1 => 'Second Title',
];
break;
case 'id':
$document['data']['attributes'][$entity_type
->getKey('id')] = $this->anotherEntity
->id();
break;
case 'uuid':
$document['data']['id'] = $this->anotherEntity
->uuid();
break;
}
return $document;
}