function ResourceTestBase::getModifiedEntityForPostTesting

Same name in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getModifiedEntityForPostTesting()
  2. 8.9.x core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getModifiedEntityForPostTesting()
  3. 11.x 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

1 call to ResourceTestBase::getModifiedEntityForPostTesting()
ResourceTestBase::doTestPostIndividual in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Tests POSTing an individual resource, plus edge cases to ensure good DX.
2 methods override ResourceTestBase::getModifiedEntityForPostTesting()
UserTest::getModifiedEntityForPostTesting in core/modules/jsonapi/tests/src/Functional/UserTest.php
Gets the normalized POST entity with random values for its unique fields.
WorkspaceTest::getModifiedEntityForPostTesting in core/modules/jsonapi/tests/src/Functional/WorkspaceTest.php
Gets the normalized POST entity with random values for its unique fields.

File

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

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.