public function EntitySerializationTest::testDenormalizeCustomSerializedItem in Drupal 8
Same name and namespace in other branches
- 9 core/modules/serialization/tests/src/Kernel/EntitySerializationTest.php \Drupal\Tests\serialization\Kernel\EntitySerializationTest::testDenormalizeCustomSerializedItem()
- 10 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 291
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($normalized['serialized_text'][0]['value'], [
'Hello world!',
]);
$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);
}