You are here

protected function EntityToJsonApiTest::assertJsonApiIncludes in JSON:API Extras 8.3

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/EntityToJsonApiTest.php \Drupal\Tests\jsonapi_extras\Kernel\EntityToJsonApiTest::assertJsonApiIncludes()

Shallowly checks the list of includes.

Parameters

array $structured: The JSON:API data to check.

array[] $includes: The list of partial structures of the "included" key.

1 call to EntityToJsonApiTest::assertJsonApiIncludes()
EntityToJsonApiTest::assertEntity in tests/src/Kernel/EntityToJsonApiTest.php
Checks entity's serialization/normalization.

File

tests/src/Kernel/EntityToJsonApiTest.php, line 279

Class

EntityToJsonApiTest
@coversDefaultClass \Drupal\jsonapi_extras\EntityToJsonApi @group jsonapi @group jsonapi_serializer @group legacy

Namespace

Drupal\Tests\jsonapi_extras\Kernel

Code

protected function assertJsonApiIncludes(array $structured, array $includes) {
  static::assertFalse(empty($structured['included']), 'The list of includes should is empty.');
  foreach ($includes as $i => $include) {
    static::assertFalse(empty($structured['included'][$i]), sprintf('The include #%d does not exist.', $i));
    static::assertSame($include['type'], $structured['included'][$i]['type'], sprintf('The type of include #%d does not match expected value.', $i));
    foreach ($include['attributes'] as $attribute => $expected_value) {
      static::assertSame($expected_value, $structured['included'][$i]['attributes'][$attribute], sprintf('The "%s" of include #%d doest match the expected value.', $attribute, $i));
    }
  }
}