function ResourceTestBase::makeNormalizationInvalid
Same name in other branches
- 9 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::makeNormalizationInvalid()
- 10 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::makeNormalizationInvalid()
- 11.x 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.
3 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.
- UserTest::makeNormalizationInvalid in core/
modules/ jsonapi/ tests/ src/ Functional/ UserTest.php - Makes the given JSON:API document invalid.
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 876
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.