You are here

public function FieldItemSerializationTest::testFieldDenormalizeWithScalarValue in Drupal 10

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

Tests denormalizing using a scalar field value.

File

core/modules/serialization/tests/src/Kernel/FieldItemSerializationTest.php, line 149

Class

FieldItemSerializationTest
Test field level normalization process.

Namespace

Drupal\Tests\serialization\Kernel

Code

public function testFieldDenormalizeWithScalarValue() {
  $this
    ->expectException(UnexpectedValueException::class);
  $this
    ->expectExceptionMessage('Field values for "uuid" must use an array structure');
  $normalized = $this->serializer
    ->normalize($this->entity, 'json');

  // Change the UUID value to use the UUID directly. No array structure.
  $normalized['uuid'] = $normalized['uuid'][0]['value'];
  $this->serializer
    ->denormalize($normalized, $this->entityClass, 'json');
}