function ContextTypedDataTest::testGetContextValue

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Plugin/ContextTypedDataTest.php \Drupal\KernelTests\Core\Plugin\ContextTypedDataTest::testGetContextValue()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Plugin/ContextTypedDataTest.php \Drupal\KernelTests\Core\Plugin\ContextTypedDataTest::testGetContextValue()
  3. 11.x core/tests/Drupal/KernelTests/Core/Plugin/ContextTypedDataTest.php \Drupal\KernelTests\Core\Plugin\ContextTypedDataTest::testGetContextValue()

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

File

core/tests/Drupal/KernelTests/Core/Plugin/ContextTypedDataTest.php, line 47

Class

ContextTypedDataTest
Tests that contexts work properly with the typed data manager.

Namespace

Drupal\KernelTests\Core\Plugin

Code

public function testGetContextValue() : void {
    $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());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.