You are here

protected function ConditionTestDualUserTest::doTestDifferentUser in Drupal 10

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

Tests with each context mapped to different users.

File

core/tests/Drupal/KernelTests/Core/Plugin/Condition/ConditionTestDualUserTest.php, line 76

Class

ConditionTestDualUserTest
Tests a condition that requires two users.

Namespace

Drupal\KernelTests\Core\Plugin\Condition

Code

protected function doTestDifferentUser() {

  /** @var \Drupal\Core\Condition\ConditionPluginBase $condition */
  $condition = \Drupal::service('plugin.manager.condition')
    ->createInstance('condition_test_dual_user')
    ->setContextMapping([
    'user1' => 'anonymous',
    'user2' => 'authenticated',
  ]);
  $contexts['anonymous'] = EntityContext::fromEntity($this->anonymous);
  $contexts['authenticated'] = EntityContext::fromEntity($this->authenticated);
  \Drupal::service('context.handler')
    ->applyContextMapping($condition, $contexts);
  $this
    ->assertFalse($condition
    ->execute());
}