You are here

public function EntitySerializationTest::testDenormalize in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/serialization/src/Tests/EntitySerializationTest.php \Drupal\serialization\Tests\EntitySerializationTest::testDenormalize()

Tests denormalization of an entity.

File

core/modules/serialization/src/Tests/EntitySerializationTest.php, line 214
Contains \Drupal\serialization\Tests\EntitySerializationTest.

Class

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

Namespace

Drupal\serialization\Tests

Code

public function testDenormalize() {
  $normalized = $this->serializer
    ->normalize($this->entity);
  foreach (array(
    'json',
    'xml',
  ) as $type) {
    $denormalized = $this->serializer
      ->denormalize($normalized, $this->entityClass, $type, array(
      'entity_type' => 'entity_test_mulrev',
    ));
    $this
      ->assertTrue($denormalized instanceof $this->entityClass, SafeMarkup::format('Denormalized entity is an instance of @class', array(
      '@class' => $this->entityClass,
    )));
    $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.');
  }
}