function EntitySerializationTest::testDenormalize
Tests denormalization of an entity.
File
- 
              core/modules/ serialization/ tests/ src/ Kernel/ EntitySerializationTest.php, line 272 
Class
- EntitySerializationTest
- Tests that entities can be serialized to supported core formats.
Namespace
Drupal\Tests\serialization\KernelCode
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->assertSame($this->entity
      ->getEntityTypeId(), $denormalized->getEntityTypeId(), 'Expected entity type found.');
    $this->assertSame($this->entity
      ->bundle(), $denormalized->bundle(), 'Expected entity bundle found.');
    $this->assertSame($this->entity
      ->uuid(), $denormalized->uuid(), 'Expected entity UUID found.');
  }
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
