You are here

public function IsGroupMemberCacheContextTest::testGetCacheableMetadata in Group 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Unit/IsGroupMemberCacheContextTest.php \Drupal\Tests\group\Unit\IsGroupMemberCacheContextTest::testGetCacheableMetadata()

Tests getting the cacheable metadata for a valid cache context.

@covers ::getCacheableMetadata

File

tests/src/Unit/IsGroupMemberCacheContextTest.php, line 132

Class

IsGroupMemberCacheContextTest
Tests the user.is_group_member:%group_id cache context.

Namespace

Drupal\Tests\group\Unit

Code

public function testGetCacheableMetadata() {
  $user = $this
    ->prophesize(UserInterface::class);
  $user
    ->getCacheContexts()
    ->willReturn([]);
  $user
    ->getCacheTags()
    ->willReturn([
    'user:1',
  ]);
  $user
    ->getCacheMaxAge()
    ->willReturn(-1);
  $user = $user
    ->reveal();
  $current_user = $this
    ->prophesize(AccountProxyInterface::class);
  $current_user
    ->getAccount()
    ->willReturn($user);
  $cache_context = new IsGroupMemberCacheContext($current_user
    ->reveal(), $this
    ->createEntityTypeManager(1)
    ->reveal(), $this
    ->createGroupMembershipLoader(TRUE)
    ->reveal());
  $this
    ->assertEquals(CacheableMetadata::createFromObject($user), $cache_context
    ->getCacheableMetadata(1));
}