/** * @covers ::applyContextMapping */ public function testApplyContextMappingConfigurableAssigned() { $context_data = StringData::createInstance(DataDefinition::create('string')); $context_data->setValue('foo'); $context = $this->getMock('Drupal\\Core\\Plugin\\Context\\ContextInterface'); $context->expects($this->atLeastOnce())->method('getContextData')->will($this->returnValue($context_data)); $context->expects($this->atLeastOnce())->method('hasContextValue')->willReturn(TRUE); $contexts = array('name' => $context); $context_definition = $this->getMock('Drupal\\Core\\Plugin\\Context\\ContextDefinitionInterface'); $plugin = $this->getMock('Drupal\\Tests\\Core\\Plugin\\TestConfigurableContextAwarePluginInterface'); $plugin->expects($this->once())->method('getContextMapping')->willReturn([]); $plugin->expects($this->once())->method('getContextDefinitions')->will($this->returnValue(array('hit' => $context_definition))); $plugin->expects($this->once())->method('setContextValue')->with('hit', $context_data); // Make sure that the cacheability metadata is passed to the plugin context. $plugin_context = $this->getMock('Drupal\\Core\\Plugin\\Context\\ContextInterface'); $plugin_context->expects($this->once())->method('addCacheableDependency')->with($context); $plugin->expects($this->once())->method('getContext')->with('hit')->willReturn($plugin_context); $this->contextHandler->applyContextMapping($plugin, $contexts, ['hit' => 'name']); }
/** * Helper mock callback to return the typed data value. */ public function getCanonicalRepresentation() { return $this->typedData->getValue(); }
/** * Constructs a new instance. * * @param \Drupal\Core\TypedData\DataDefinitionInterface $definition * The data definition. * @param string $name * The name of the created property. * @param \Drupal\plugin\Plugin\Field\FieldType\PluginCollectionItemInterface $parent * The parent object of the data property. */ public function __construct(DataDefinitionInterface $definition, $name, PluginCollectionItemInterface $parent) { parent::__construct($definition, $name, $parent); }