You are here

public function OptionalContextConditionTest::testContextNoValue in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Plugin/Condition/OptionalContextConditionTest.php \Drupal\KernelTests\Core\Plugin\Condition\OptionalContextConditionTest::testContextNoValue()
  2. 9 core/tests/Drupal/KernelTests/Core/Plugin/Condition/OptionalContextConditionTest.php \Drupal\KernelTests\Core\Plugin\Condition\OptionalContextConditionTest::testContextNoValue()

Tests with both contexts mapped to the same user.

File

core/tests/Drupal/KernelTests/Core/Plugin/Condition/OptionalContextConditionTest.php, line 41

Class

OptionalContextConditionTest
Tests a condition with optional context.

Namespace

Drupal\KernelTests\Core\Plugin\Condition

Code

public function testContextNoValue() {

  /** @var \Drupal\Core\Condition\ConditionPluginBase $condition */
  $condition = \Drupal::service('plugin.manager.condition')
    ->createInstance('condition_test_optional_context')
    ->setContextMapping([
    'node' => 'node',
  ]);
  $definition = EntityContextDefinition::fromEntityTypeId('node');
  $contexts['node'] = new Context($definition);
  \Drupal::service('context.handler')
    ->applyContextMapping($condition, $contexts);
  $this
    ->assertTrue($condition
    ->execute());
}