You are here

protected function NodeAccessGrantsCacheContextTest::assertUserCacheContext in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/node/tests/src/Functional/NodeAccessGrantsCacheContextTest.php \Drupal\Tests\node\Functional\NodeAccessGrantsCacheContextTest::assertUserCacheContext()

Asserts that for each given user, the expected cache context is returned.

Parameters

array $expected: Expected values, keyed by user ID, expected cache contexts as values.

1 call to NodeAccessGrantsCacheContextTest::assertUserCacheContext()
NodeAccessGrantsCacheContextTest::testCacheContext in core/modules/node/tests/src/Functional/NodeAccessGrantsCacheContextTest.php
Tests NodeAccessGrantsCacheContext::getContext().

File

core/modules/node/tests/src/Functional/NodeAccessGrantsCacheContextTest.php, line 80

Class

NodeAccessGrantsCacheContextTest
Tests the node access grants cache context service.

Namespace

Drupal\Tests\node\Functional

Code

protected function assertUserCacheContext(array $expected) {
  foreach ($expected as $uid => $context) {
    if ($uid > 0) {
      $this
        ->drupalLogin($this->userMapping[$uid]);
    }
    $this
      ->assertSame($context, $this->container
      ->get('cache_context.user.node_grants')
      ->getContext('view'));
  }
  $this
    ->drupalLogout();
}