public function ContextTypedDataTest::testGetContextValue in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Plugin/Context/ContextTypedDataTest.php \Drupal\Tests\Core\Plugin\Context\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/ Tests/ Core/ Plugin/ Context/ ContextTypedDataTest.php, line 40 - Contains \Drupal\Tests\Core\Plugin\Context\ContextTypedDataTest.
Class
- ContextTypedDataTest
- Tests that contexts work properly with the typed data manager.
Namespace
Drupal\Tests\Core\Plugin\ContextCode
public function testGetContextValue() {
// Prepare a container that holds the typed data manager mock.
$typed_data_manager = $this
->getMockBuilder('Drupal\\Core\\TypedData\\TypedDataManager')
->disableOriginalConstructor()
->getMock();
$typed_data_manager
->expects($this
->once())
->method('getCanonicalRepresentation')
->will($this
->returnCallback(array(
$this,
'getCanonicalRepresentation',
)));
$container = new ContainerBuilder();
$container
->set('typed_data_manager', $typed_data_manager);
\Drupal::setContainer($container);
$definition = new ContextDefinition('any');
$data_definition = DataDefinition::create('string');
$this->typedData = new StringData($data_definition);
$this->typedData
->setValue('example string');
$context = new Context($definition, $this->typedData);
$value = $context
->getContextValue();
$this
->assertSame($value, $this->typedData
->getValue());
}