You are here

protected static function ResourceResponseTestTrait::collectionHasResourceIdentifier in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php \Drupal\Tests\jsonapi\Functional\ResourceResponseTestTrait::collectionHasResourceIdentifier()
  2. 10 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 307

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;
}