function EntitySerializationTest::testDenormalize

Same name in other branches
  1. 9 core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php \Drupal\Tests\serialization\Kernel\EntitySerializationTest::testDenormalize()
  2. 8.9.x core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php \Drupal\Tests\serialization\Kernel\EntitySerializationTest::testDenormalize()
  3. 11.x 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 269

Class

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

Namespace

Drupal\Tests\serialization\Kernel

Code

public function testDenormalize() : void {
    $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.