diff --git a/core/modules/system/tests/modules/condition_test/src/Plugin/Condition/OptionalContextCondition.php b/core/modules/system/tests/modules/condition_test/src/Plugin/Condition/OptionalContextCondition.php
new file mode 100644
index 0000000..986a66c
--- /dev/null
+++ b/core/modules/system/tests/modules/condition_test/src/Plugin/Condition/OptionalContextCondition.php
@@ -0,0 +1,40 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\condition_test\Plugin\Condition\OptionalContextCondition.
+ */
+
+namespace Drupal\condition_test\Plugin\Condition;
+
+use Drupal\Core\Condition\ConditionPluginBase;
+
+/**
+ * Provides a condition with optional context.
+ *
+ * @Condition(
+ *   id = "condition_test_optional_context",
+ *   label = @Translation("Optional context"),
+ *   context = {
+ *     "node" = @ContextDefinition("entity:node", label = @Translation("Node"), required = FALSE),
+ *   }
+ * )
+ */
+class OptionalContextCondition extends ConditionPluginBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function evaluate() {
+    // Grant access if no context value is given.
+    return !$this->getContextValue('node');
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function summary() {
+    return $this->t('Context with optional context.');
+  }
+
+}
diff --git a/core/modules/system/tests/modules/condition_test/src/Tests/OptionalContextConditionTest.php b/core/modules/system/tests/modules/condition_test/src/Tests/OptionalContextConditionTest.php
new file mode 100644
index 0000000..f455905
--- /dev/null
+++ b/core/modules/system/tests/modules/condition_test/src/Tests/OptionalContextConditionTest.php
@@ -0,0 +1,74 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\condition_test\Tests\OptionalContextConditionTest.
+ */
+
+namespace Drupal\condition_test\Tests;
+
+use Drupal\Core\Plugin\Context\Context;
+use Drupal\Core\Plugin\Context\ContextDefinition;
+use Drupal\node\Entity\Node;
+use Drupal\simpletest\KernelTestBase;
+
+/**
+ * Tests a condition with optional context.
+ *
+ * @group condition_test
+ */
+class OptionalContextConditionTest extends KernelTestBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public static $modules = ['system', 'user', 'condition_test', 'node'];
+
+  /**
+   * Tests with both contexts mapped to the same user.
+   */
+  protected function testContextMissing() {
+    /** @var \Drupal\Core\Condition\ConditionPluginBase $condition */
+    $condition = \Drupal::service('plugin.manager.condition')
+      ->createInstance('condition_test_optional_context')
+      ->setContextMapping([
+        'node' => 'node',
+      ]);
+    \Drupal::service('context.handler')->applyContextMapping($condition, []);
+    $this->assertTrue($condition->execute());
+  }
+
+  /**
+   * Tests with both contexts mapped to the same user.
+   */
+  protected function testContextNoValue() {
+    /** @var \Drupal\Core\Condition\ConditionPluginBase $condition */
+    $condition = \Drupal::service('plugin.manager.condition')
+      ->createInstance('condition_test_optional_context')
+      ->setContextMapping([
+        'node' => 'node',
+      ]);
+    $definition = new ContextDefinition('entity:node');
+    $contexts['node'] = (new Context($definition));
+    \Drupal::service('context.handler')->applyContextMapping($condition, $contexts);
+    $this->assertTrue($condition->execute());
+  }
+
+  /**
+   * Tests with both contexts mapped to the same user.
+   */
+  protected function testContextAvailable() {
+    /** @var \Drupal\Core\Condition\ConditionPluginBase $condition */
+    $condition = \Drupal::service('plugin.manager.condition')
+      ->createInstance('condition_test_optional_context')
+      ->setContextMapping([
+        'node' => 'node',
+      ]);
+    $definition = new ContextDefinition('entity:node');
+    $node = Node::create(['type' => 'example']);
+    $contexts['node'] = (new Context($definition))->setContextValue($node);
+    \Drupal::service('context.handler')->applyContextMapping($condition, $contexts);
+    $this->assertFalse($condition->execute());
+  }
+
+}
