You are here

protected function ResourceTestBase::getModifiedEntityForPostTesting 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::getModifiedEntityForPostTesting()
  2. 9 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getModifiedEntityForPostTesting()

Gets the normalized POST entity with random values for its unique fields.

Return value

array An array structure as returned by ::getNormalizedPostEntity().

See also

::testPostIndividual

::getPostDocument

File

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

Class

ResourceTestBase
Subclass this for every JSON:API resource type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function getModifiedEntityForPostTesting() {
  $document = $this
    ->getPostDocument();

  // Ensure that all the unique fields of the entity type get a new random
  // value.
  foreach (static::$uniqueFieldNames as $field_name) {
    $field_definition = $this->entity
      ->getFieldDefinition($field_name);
    $field_type_class = $field_definition
      ->getItemDefinition()
      ->getClass();
    $document['data']['attributes'][$field_name] = $field_type_class::generateSampleValue($field_definition);
  }
  return $document;
}