You are here

public function EntitySerializationTest::testDenormalizeValidCustomSerializedField in Drupal 10

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

Tests normalizing/denormalizing valid custom serialized fields.

File

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

Class

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

Namespace

Drupal\Tests\serialization\Kernel

Code

public function testDenormalizeValidCustomSerializedField() {
  $entity = EntitySerializedField::create([
    'serialized_long' => serialize([
      'key' => 'value',
    ]),
  ]);
  $normalized = $this->serializer
    ->normalize($entity);
  $this
    ->assertEquals([
    'key' => 'value',
  ], $normalized['serialized_long'][0]['value']);
  $entity = $this->serializer
    ->denormalize($normalized, EntitySerializedField::class);
  $this
    ->assertEquals(serialize([
    'key' => 'value',
  ]), $entity
    ->get('serialized_long')->value);
}