public function EntitySerializationTest::testDenormalizeCustomSerializedItem in Drupal 10
Same name and namespace in other branches
- 8 core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php \Drupal\Tests\serialization\Kernel\EntitySerializationTest::testDenormalizeCustomSerializedItem()
- 9 core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php \Drupal\Tests\serialization\Kernel\EntitySerializationTest::testDenormalizeCustomSerializedItem()
Tests normalizing/denormalizing custom serialized columns.
File
- core/
modules/ serialization/ tests/ src/ Kernel/ EntitySerializationTest.php, line 299
Class
- EntitySerializationTest
- Tests that entities can be serialized to supported core formats.
Namespace
Drupal\Tests\serialization\KernelCode
public function testDenormalizeCustomSerializedItem() {
$entity = EntitySerializedField::create([
'serialized_text' => serialize([
'Hello world!',
]),
]);
$normalized = $this->serializer
->normalize($entity);
$this
->assertEquals([
'Hello world!',
], $normalized['serialized_text'][0]['value']);
$this
->expectException(\LogicException::class);
$this
->expectExceptionMessage('The generic FieldItemNormalizer cannot denormalize string values for "value" properties of the "serialized_text" field (field item class: Drupal\\entity_test\\Plugin\\Field\\FieldType\\SerializedPropertyItem).');
$this->serializer
->denormalize([
'serialized_text' => [
[
'value' => 'boo',
],
],
'type' => 'entity_test_serialized_field',
], EntitySerializedField::class);
}