You are here

protected function ResourceTestBase::normalize in JSON:API 8

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::normalize()

Generates a JSON API normalization for the given entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to generate a JSON API normalization for.

\Drupal\Core\Url $url: The URL to use as the "self" link.

Return value

array The JSON API normalization for the given entity.

4 calls to ResourceTestBase::normalize()
ResourceTestBase::testPatchIndividual in tests/src/Functional/ResourceTestBase.php
Tests PATCHing an individual resource, plus edge cases to ensure good DX.
ResourceTestBase::testPostIndividual in tests/src/Functional/ResourceTestBase.php
Tests POSTing an individual resource, plus edge cases to ensure good DX.
UserTest::testPatchDxForSecuritySensitiveBaseFields in tests/src/Functional/UserTest.php
Tests PATCHing security-sensitive base fields of the logged in account.
UserTest::testPatchSecurityOtherUser in tests/src/Functional/UserTest.php
Tests PATCHing security-sensitive base fields to change other users.

File

tests/src/Functional/ResourceTestBase.php, line 323

Class

ResourceTestBase
Subclass this for every JSON API resource type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function normalize(EntityInterface $entity, Url $url) {
  return $this->serializer
    ->normalize(new JsonApiDocumentTopLevel($entity), 'api_json', [
    'resource_type' => $this->container
      ->get('jsonapi.resource_type.repository')
      ->getByTypeName(static::$resourceTypeName),
    // Pass a Request object to the normalizer; this will be considered the
    // "current request" for generating the "self" link.
    'request' => Request::create($url
      ->toString(TRUE)
      ->getGeneratedUrl()),
  ])
    ->rasterizeValue();
}