X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Ftests%2FDrupal%2FKernelTests%2FCore%2FPlugin%2FContextTypedDataTest.php;fp=web%2Fcore%2Ftests%2FDrupal%2FKernelTests%2FCore%2FPlugin%2FContextTypedDataTest.php;h=2ffec87a13a9cfba2781012a2a8f39f87ac308df;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=0000000000000000000000000000000000000000;hpb=74df008bdbb3a11eeea356744f39b802369bda3c;p=yaffs-website diff --git a/web/core/tests/Drupal/KernelTests/Core/Plugin/ContextTypedDataTest.php b/web/core/tests/Drupal/KernelTests/Core/Plugin/ContextTypedDataTest.php new file mode 100644 index 000000000..2ffec87a1 --- /dev/null +++ b/web/core/tests/Drupal/KernelTests/Core/Plugin/ContextTypedDataTest.php @@ -0,0 +1,63 @@ +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()); + } + + /** + * Tests that getting a context value does not throw fatal errors. + * + * This test ensures that the typed data manager is set correctly on the + * Context class. + * + * @covers ::getContextValue + */ + public function testGetContextValue() { + $data_definition = DataDefinition::create('string'); + $typed_data = new StringData($data_definition); + $typed_data->setValue('example string'); + + // Prepare a container that holds the typed data manager mock. + $typed_data_manager = $this->prophesize(TypedDataManagerInterface::class); + $typed_data_manager->getCanonicalRepresentation($typed_data)->will(function ($arguments) { + return $arguments[0]->getValue(); + }); + $this->container->set('typed_data_manager', $typed_data_manager->reveal()); + + $definition = new ContextDefinition('any'); + $context = new Context($definition, $typed_data); + $value = $context->getContextValue(); + $this->assertSame($value, $typed_data->getValue()); + } + +}