function FieldItemSerializationTest::testFieldDenormalizeWithScalarValue

Same name in other branches
  1. 9 core/modules/serialization/tests/src/Kernel/FieldItemSerializationTest.php \Drupal\Tests\serialization\Kernel\FieldItemSerializationTest::testFieldDenormalizeWithScalarValue()
  2. 10 core/modules/serialization/tests/src/Kernel/FieldItemSerializationTest.php \Drupal\Tests\serialization\Kernel\FieldItemSerializationTest::testFieldDenormalizeWithScalarValue()
  3. 11.x 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');
}

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