function ResourceResponseTestTrait::collectionHasResourceIdentifier

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

Determines if a given resource exists in a list of resources.

Parameters

array $needle: The resource or resource identifier.

array $haystack: The list of resources or resource identifiers to search.

Return value

bool TRUE if the needle exists is present in the haystack, FALSE otherwise.

2 calls to ResourceResponseTestTrait::collectionHasResourceIdentifier()
ResourceResponseTestTrait::getExpectedIncludedResourceResponse in core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php
Gets an array of expected ResourceResponses for the given include paths.
ResourceTestBase::decorateExpectedResponseForIncludedFields in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Decorates the expected response with included data and cache metadata.

File

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

Class

ResourceResponseTestTrait
Utility methods for handling resource responses.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected static function collectionHasResourceIdentifier(array $needle, array $haystack) {
    foreach ($haystack as $resource) {
        if ($resource['type'] == $needle['type'] && $resource['id'] == $needle['id']) {
            return TRUE;
        }
    }
    return FALSE;
}

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