You are here

protected static function ResourceResponseTestTrait::resetOmittedLinkKeys in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php \Drupal\Tests\jsonapi\Functional\ResourceResponseTestTrait::resetOmittedLinkKeys()

Resets omitted link keys.

Omitted link keys are a link relation type + a random string. This string is meaningless and only serves to differentiate link objects. Given that these are random, we can't assert their value.

Parameters

array $omitted: An array of JSON:API omitted link objects.

2 calls to ResourceResponseTestTrait::resetOmittedLinkKeys()
ResourceResponseTestTrait::mergeOmittedObjects in core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php
Merges the links of two omitted objects and returns a new omitted object.
ResourceTestBase::assertSameDocument in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Asserts that an expected document matches the response body.

File

core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php, line 656

Class

ResourceResponseTestTrait
Utility methods for handling resource responses.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected static function resetOmittedLinkKeys(array &$omitted) {
  $help = $omitted['links']['help'];
  $reindexed = [];
  $links = array_diff_key($omitted['links'], array_flip([
    'help',
  ]));
  foreach (array_values($links) as $index => $link) {
    $reindexed['item--' . $index] = $link;
  }
  $omitted['links'] = [
    'help' => $help,
  ] + $reindexed;
}