function ResourceResponseTestTrait::resetOmittedLinkKeys

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

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