You are here

public function EntitySerializationTest::testDenormalize in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php \Drupal\Tests\serialization\Kernel\EntitySerializationTest::testDenormalize()
  2. 10 core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php \Drupal\Tests\serialization\Kernel\EntitySerializationTest::testDenormalize()

Tests denormalization of an entity.

File

core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php, line 260

Class

EntitySerializationTest
Tests that entities can be serialized to supported core formats.

Namespace

Drupal\Tests\serialization\Kernel

Code

public function testDenormalize() {
  $normalized = $this->serializer
    ->normalize($this->entity);
  foreach ([
    'json',
    'xml',
  ] as $type) {
    $denormalized = $this->serializer
      ->denormalize($normalized, $this->entityClass, $type, [
      'entity_type' => 'entity_test_mulrev',
    ]);
    $this
      ->assertInstanceOf($this->entityClass, $denormalized);
    $this
      ->assertIdentical($denormalized
      ->getEntityTypeId(), $this->entity
      ->getEntityTypeId(), 'Expected entity type found.');
    $this
      ->assertIdentical($denormalized
      ->bundle(), $this->entity
      ->bundle(), 'Expected entity bundle found.');
    $this
      ->assertIdentical($denormalized
      ->uuid(), $this->entity
      ->uuid(), 'Expected entity UUID found.');
  }
}