protected function EntityResourceTestBase::makeNormalizationInvalid in Drupal 10
Same name and namespace in other branches
- 8 core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::makeNormalizationInvalid()
- 9 core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::makeNormalizationInvalid()
Makes the given entity normalization invalid.
Parameters
array $normalization: An entity normalization.
string $entity_key: The entity key whose normalization to make invalid.
Return value
array The updated entity normalization, now invalid.
2 calls to EntityResourceTestBase::makeNormalizationInvalid()
- EntityResourceTestBase::testPatch in core/
modules/ rest/ tests/ src/ Functional/ EntityResource/ EntityResourceTestBase.php - Tests a PATCH request for an entity, plus edge cases to ensure good DX.
- EntityResourceTestBase::testPost in core/
modules/ rest/ tests/ src/ Functional/ EntityResource/ EntityResourceTestBase.php - Tests a POST request for an entity, plus edge cases to ensure good DX.
File
- core/
modules/ rest/ tests/ src/ Functional/ EntityResource/ EntityResourceTestBase.php, line 1303
Class
- EntityResourceTestBase
- Even though there is the generic EntityResource, it's necessary for every entity type to have its own test, because they each have different fields, validation constraints, et cetera. It's not because the generic case works, that every case…
Namespace
Drupal\Tests\rest\Functional\EntityResourceCode
protected function makeNormalizationInvalid(array $normalization, $entity_key) {
$entity_type = $this->entity
->getEntityType();
switch ($entity_key) {
case 'label':
// Add a second label to this entity to make it invalid.
if ($label_field = $entity_type
->hasKey('label') ? $entity_type
->getKey('label') : static::$labelFieldName) {
$normalization[$label_field][1]['value'] = 'Second Title';
}
break;
case 'id':
$normalization[$entity_type
->getKey('id')][0]['value'] = $this->anotherEntity
->id();
break;
case 'uuid':
$normalization[$entity_type
->getKey('uuid')][0]['value'] = $this->anotherEntity
->uuid();
break;
}
return $normalization;
}