function EntityResourceTestBase::makeNormalizationInvalid

Same name and namespace in other branches
  1. 8.9.x core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::makeNormalizationInvalid()
  2. 10 core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::makeNormalizationInvalid()
  3. 11.x 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 1302

Class

EntityResourceTestBase
Defines a base class for testing all entity resources.

Namespace

Drupal\Tests\rest\Functional\EntityResource

Code

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

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