function ResourceResponseTestTrait::sortOmittedLinks

Same name in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php \Drupal\Tests\jsonapi\Functional\ResourceResponseTestTrait::sortOmittedLinks()
  2. 8.9.x core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php \Drupal\Tests\jsonapi\Functional\ResourceResponseTestTrait::sortOmittedLinks()
  3. 11.x core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php \Drupal\Tests\jsonapi\Functional\ResourceResponseTestTrait::sortOmittedLinks()

Sorts an omitted link object array by href.

Parameters

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

1 call to ResourceResponseTestTrait::sortOmittedLinks()
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 638

Class

ResourceResponseTestTrait
Utility methods for handling resource responses.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected static function sortOmittedLinks(array &$omitted) {
    $help = $omitted['links']['help'];
    $links = array_diff_key($omitted['links'], array_flip([
        'help',
    ]));
    uasort($links, function ($a, $b) {
        return strcmp($a['href'], $b['href']);
    });
    $omitted['links'] = [
        'help' => $help,
    ] + $links;
}

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