public function ContextTypedDataTest::testSerialize in Drupal 9
Same name and namespace in other branches
- 8 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 23
Class
- ContextTypedDataTest
- Tests that contexts work properly with the typed data manager.
Namespace
Drupal\KernelTests\Core\PluginCode
public function testSerialize() {
$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());
}