function ContextTypedDataTest::testSerialize
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Plugin/ContextTypedDataTest.php \Drupal\KernelTests\Core\Plugin\ContextTypedDataTest::testSerialize()
- 8.9.x core/tests/Drupal/KernelTests/Core/Plugin/ContextTypedDataTest.php \Drupal\KernelTests\Core\Plugin\ContextTypedDataTest::testSerialize()
- 10 core/tests/Drupal/KernelTests/Core/Plugin/ContextTypedDataTest.php \Drupal\KernelTests\Core\Plugin\ContextTypedDataTest::testSerialize()
Tests that contexts can be serialized.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Plugin/ ContextTypedDataTest.php, line 25
Class
- ContextTypedDataTest
- Tests that contexts work properly with the typed data manager.
Namespace
Drupal\KernelTests\Core\PluginCode
public function testSerialize() : void {
$definition = new ContextDefinition('any');
$data_definition = DataDefinition::create('string');
$typed_data = new StringData($data_definition);
$typed_data->setValue('example string');
$context = new Context($definition, $typed_data);
// getContextValue() will cause the context to reference the typed data
// manager service.
$value = $context->getContextValue();
$context = serialize($context);
$context = unserialize($context);
$this->assertSame($value, $context->getContextValue());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.