function LinkItemSerializationTest::testLinkDeserialization
Same name in other branches
- 9 core/modules/link/tests/src/Kernel/LinkItemSerializationTest.php \Drupal\Tests\link\Kernel\LinkItemSerializationTest::testLinkDeserialization()
- 10 core/modules/link/tests/src/Kernel/LinkItemSerializationTest.php \Drupal\Tests\link\Kernel\LinkItemSerializationTest::testLinkDeserialization()
- 11.x core/modules/link/tests/src/Kernel/LinkItemSerializationTest.php \Drupal\Tests\link\Kernel\LinkItemSerializationTest::testLinkDeserialization()
Tests the deserialization.
File
-
core/
modules/ link/ tests/ src/ Kernel/ LinkItemSerializationTest.php, line 86
Class
- LinkItemSerializationTest
- Tests link field serialization.
Namespace
Drupal\Tests\link\KernelCode
public function testLinkDeserialization() {
// Create entity.
$entity = EntityTest::create();
$url = 'https://www.drupal.org?test_param=test_value';
$parsed_url = UrlHelper::parse($url);
$title = $this->randomMachineName();
$entity->field_test->uri = $parsed_url['path'];
$entity->field_test->title = $title;
$entity->field_test
->first()
->get('options')
->set('query', $parsed_url['query']);
$json = json_decode($this->serializer
->serialize($entity, 'json'), TRUE);
$json['field_test'][0]['options'] = 'string data';
$serialized = json_encode($json, TRUE);
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('The generic FieldItemNormalizer cannot denormalize string values for "options" properties of the "field_test" field (field item class: Drupal\\link\\Plugin\\Field\\FieldType\\LinkItem).');
$this->serializer
->deserialize($serialized, EntityTest::class, 'json');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.