You are here

public function GetUserGroupsTest::testIsMemberStates in Organic groups 8

Tests member methods for states that other groups users are added to.

@todo Convert Og::isMember() calls to $this->membershipManager->isMember().

File

tests/src/Kernel/Entity/GetUserGroupsTest.php, line 203

Class

GetUserGroupsTest
Tests getting the memberships of an entity.

Namespace

Drupal\Tests\og\Kernel\Entity

Code

public function testIsMemberStates() {

  // Add user to group 1 should now return that group only.
  $membership = $this
    ->createOgMembership($this->group1, $this->user3);

  // Default param is ACTIVE.
  $this
    ->assertTrue(Og::isMember($this->group1, $this->user3));
  $this
    ->assertFalse(Og::isMember($this->group1, $this->user3, [
    OgMembershipInterface::STATE_PENDING,
  ]));
  $this
    ->assertFalse(Og::isMember($this->group1, $this->user3, [
    OgMembershipInterface::STATE_BLOCKED,
  ]));
  $this
    ->assertFalse(Og::isMember($this->group1, $this->user3, [
    OgMembershipInterface::STATE_PENDING,
    OgMembershipInterface::STATE_BLOCKED,
  ]));
  $this
    ->assertFalse(Og::isMemberPending($this->group1, $this->user3));
  $this
    ->assertFalse(Og::isMemberBlocked($this->group1, $this->user3));

  // Change the membership state to PENDING.
  $membership
    ->setState(OgMembershipInterface::STATE_PENDING)
    ->save();
  Og::invalidateCache();
  $this
    ->assertTrue(Og::isMember($this->group1, $this->user3, [
    OgMembershipInterface::STATE_PENDING,
  ]));
  $this
    ->assertTrue(Og::isMemberPending($this->group1, $this->user3));
  $this
    ->assertTrue(Og::isMember($this->group1, $this->user3, [
    OgMembershipInterface::STATE_PENDING,
    OgMembershipInterface::STATE_BLOCKED,
  ]));
  $this
    ->assertFalse(Og::isMember($this->group1, $this->user3));
  $this
    ->assertFalse(Og::isMember($this->group1, $this->user3, [
    OgMembershipInterface::STATE_BLOCKED,
  ]));
  $this
    ->assertFalse(Og::isMemberBlocked($this->group1, $this->user3));

  // Change the membership state to BLOCKED.
  $membership
    ->setState(OgMembershipInterface::STATE_BLOCKED)
    ->save();
  Og::invalidateCache();
  $this
    ->assertTrue(Og::isMember($this->group1, $this->user3, [
    OgMembershipInterface::STATE_BLOCKED,
  ]));
  $this
    ->assertTrue(Og::isMemberBlocked($this->group1, $this->user3));
  $this
    ->assertTrue(Og::isMember($this->group1, $this->user3, [
    OgMembershipInterface::STATE_PENDING,
    OgMembershipInterface::STATE_BLOCKED,
  ]));
  $this
    ->assertFalse(Og::isMember($this->group1, $this->user3));
  $this
    ->assertFalse(Og::isMember($this->group1, $this->user3, [
    OgMembershipInterface::STATE_PENDING,
  ]));
  $this
    ->assertFalse(Og::isMemberPending($this->group1, $this->user3));
}