You are here

public function OgRoleCacheContextTest::testNoMemberships in Organic groups 8

Same name in this branch
  1. 8 tests/src/Unit/Cache/Context/OgRoleCacheContextTest.php \Drupal\Tests\og\Unit\Cache\Context\OgRoleCacheContextTest::testNoMemberships()
  2. 8 tests/src/Kernel/Cache/Context/OgRoleCacheContextTest.php \Drupal\Tests\og\Kernel\Cache\Context\OgRoleCacheContextTest::testNoMemberships()

Tests generating of a cache context key for a user with no memberships.

This is a common case, e.g. for anonymous users.

@covers ::getContext

File

tests/src/Unit/Cache/Context/OgRoleCacheContextTest.php, line 75

Class

OgRoleCacheContextTest
Tests the OG role cache context.

Namespace

Drupal\Tests\og\Unit\Cache\Context

Code

public function testNoMemberships() : void {

  // No memberships (an empty array) will be returned by the membership
  // manager.

  /** @var \Drupal\Core\Session\AccountInterface|\Prophecy\Prophecy\ObjectProphecy $user */
  $user = $this
    ->prophesize(AccountInterface::class)
    ->reveal();
  $this->membershipManager
    ->getMemberships($user
    ->id())
    ->willReturn([]);

  // The result should be the predefined 'NO_CONTEXT' value.
  $result = $this
    ->getContextResult($user);
  $this
    ->assertEquals(OgRoleCacheContext::NO_CONTEXT, $result);
}