You are here

public function ContextAwarePluginBaseTest::testSetContextValue in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Plugin/Context/ContextAwarePluginBaseTest.php \Drupal\KernelTests\Core\Plugin\Context\ContextAwarePluginBaseTest::testSetContextValue()

@covers ::setContextValue @group legacy

File

core/tests/Drupal/KernelTests/Core/Plugin/Context/ContextAwarePluginBaseTest.php, line 86

Class

ContextAwarePluginBaseTest
@coversDefaultClass \Drupal\Core\Plugin\ContextAwarePluginBase

Namespace

Drupal\KernelTests\Core\Plugin\Context

Code

public function testSetContextValue() {
  $typed_data_manager = $this
    ->prophesize(TypedDataManagerInterface::class);
  $container = new ContainerBuilder();
  $container
    ->set('typed_data_manager', $typed_data_manager
    ->reveal());
  \Drupal::setContainer($container);
  $this->plugin
    ->getPluginDefinition()
    ->addContextDefinition('foo', new ContextDefinition('string'));
  $this
    ->assertFalse($this->plugin->setContextCalled);
  $this->plugin
    ->setContextValue('foo', new StringData(new DataDefinition(), 'bar'));
  $this
    ->assertTrue($this->plugin->setContextCalled);

  // Assert that setContextValue() did NOT update the deprecated $contexts
  // property.
  $this
    ->addExpectedDeprecationMessage('The $contexts property is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Use methods of \\Drupal\\Component\\Plugin\\ContextAwarePluginInterface instead. See https://www.drupal.org/project/drupal/issues/3080631 for more information.');
  $this
    ->assertArrayNotHasKey('foo', $this->plugin->contexts);
}