You are here

public function EntityToJsonApiTest::testSerialize 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::testSerialize()

@covers ::serialize @covers ::normalize

File

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

Class

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

Namespace

Drupal\Tests\jsonapi_extras\Kernel

Code

public function testSerialize() {
  $entities = [
    [
      $this->node,
      [
        'field_tags',
      ],
      [
        [
          'type' => 'taxonomy_term--tags',
          'id' => $this->term1
            ->uuid(),
          'attributes' => [
            'drupal_internal__tid' => (int) $this->term1
              ->id(),
            'name' => $this->term1
              ->label(),
          ],
        ],
        [
          'type' => 'taxonomy_term--tags',
          'id' => $this->term2
            ->uuid(),
          'attributes' => [
            'drupal_internal__tid' => (int) $this->term2
              ->id(),
            'name' => $this->term2
              ->label(),
          ],
        ],
      ],
    ],
    [
      $this->user,
      [],
      [],
    ],
    [
      $this->file,
      [],
      [],
    ],
    [
      $this->term1,
      [],
      [],
    ],
    // Make sure we also support configuration entities.
    [
      $this->nodeType,
      [],
      [],
    ],
  ];
  array_walk($entities, function ($data) {
    list($entity, $include_fields, $expected_includes) = $data;
    $this
      ->assertEntity($entity, $include_fields, $expected_includes);
  });
}