You are here

public function EntitySerializationTest::testDenormalizeInvalidCustomSerializedField 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::testDenormalizeInvalidCustomSerializedField()
  2. 9 core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php \Drupal\Tests\serialization\Kernel\EntitySerializationTest::testDenormalizeInvalidCustomSerializedField()

Tests normalizing/denormalizing invalid custom serialized fields.

File

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

Class

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

Namespace

Drupal\Tests\serialization\Kernel

Code

public function testDenormalizeInvalidCustomSerializedField() {
  $entity = EntitySerializedField::create([
    'serialized_long' => serialize([
      'Hello world!',
    ]),
  ]);
  $normalized = $this->serializer
    ->normalize($entity);
  $this
    ->assertEquals([
    'Hello world!',
  ], $normalized['serialized_long'][0]['value']);
  $this
    ->expectException(\LogicException::class);
  $this
    ->expectExceptionMessage('The generic FieldItemNormalizer cannot denormalize string values for "value" properties of the "serialized_long" field (field item class: Drupal\\Core\\Field\\Plugin\\Field\\FieldType\\StringLongItem).');
  $this->serializer
    ->denormalize([
    'serialized_long' => [
      [
        'value' => 'boo',
      ],
    ],
    'type' => 'entity_test_serialized_field',
  ], EntitySerializedField::class);
}