You are here

protected function OptionalContextConditionTest::testContextAvailable in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/tests/modules/condition_test/src/Tests/OptionalContextConditionTest.php \Drupal\condition_test\Tests\OptionalContextConditionTest::testContextAvailable()

Tests with both contexts mapped to the same user.

File

core/modules/system/tests/modules/condition_test/src/Tests/OptionalContextConditionTest.php, line 61
Contains \Drupal\condition_test\Tests\OptionalContextConditionTest.

Class

OptionalContextConditionTest
Tests a condition with optional context.

Namespace

Drupal\condition_test\Tests

Code

protected function testContextAvailable() {
  NodeType::create([
    'type' => 'example',
    'name' => 'Example',
  ])
    ->save();

  /** @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, $node);
  \Drupal::service('context.handler')
    ->applyContextMapping($condition, $contexts);
  $this
    ->assertFalse($condition
    ->execute());
}