You are here

protected function ResourceTestBase::makeNormalizationInvalid in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::makeNormalizationInvalid()
  2. 9 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.

File

core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php, line 888

Class

ResourceTestBase
Subclass this for every JSON:API resource type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

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;
}