function NodeAccessGrantsCacheContextTest::assertUserCacheContext

Same name in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeAccessGrantsCacheContextTest.php \Drupal\Tests\node\Functional\NodeAccessGrantsCacheContextTest::assertUserCacheContext()
  2. 8.9.x core/modules/node/tests/src/Functional/NodeAccessGrantsCacheContextTest.php \Drupal\Tests\node\Functional\NodeAccessGrantsCacheContextTest::assertUserCacheContext()
  3. 10 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.

@internal

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 111

Class

NodeAccessGrantsCacheContextTest
Tests the node access grants cache context service.

Namespace

Drupal\Tests\node\Functional

Code

protected function assertUserCacheContext(array $expected) : void {
    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();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.