You are here

public function OgMembershipTest::testMembershipStaticCache in Organic groups 8

Tests getting an ogMembership from the static cache.

File

tests/src/Kernel/Entity/OgMembershipTest.php, line 205

Class

OgMembershipTest
Tests the OgMembership entity.

Namespace

Drupal\Tests\og\Kernel\Entity

Code

public function testMembershipStaticCache() {

  // Create a second bundle and add as a group.
  $another_group = EntityTest::create([
    'type' => mb_strtolower($this
      ->randomMachineName()),
    'name' => $this
      ->randomString(),
  ]);
  $another_group
    ->save();
  $this->groupTypeManager
    ->addGroup('entity_test', $another_group
    ->bundle());
  $membership = Og::createMembership($this->group, $this->user);
  $membership
    ->save();

  // Load the membership to instantiate the membership static cache.
  $membership = Og::getMembership($this->group, $this->user);
  $this
    ->assertInstanceOf(OgMembership::class, $membership);

  // Create another membership for the given user on the same request.
  $membership = Og::createMembership($another_group, $this->user);
  $membership
    ->save();
  $membership = Og::getMembership($another_group, $this->user);
  $this
    ->assertInstanceOf(OgMembership::class, $membership);
}