function DenormalizeTest::testDenormalizeValidCustomSerializedField

Same name and namespace in other branches
  1. 8.9.x core/modules/hal/tests/src/Kernel/DenormalizeTest.php \Drupal\Tests\hal\Kernel\DenormalizeTest::testDenormalizeValidCustomSerializedField()

Tests normalizing/denormalizing valid custom serialized fields.

File

core/modules/hal/tests/src/Kernel/DenormalizeTest.php, line 184

Class

DenormalizeTest
Tests HAL denormalization edge cases for EntityResource.

Namespace

Drupal\Tests\hal\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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.