You are here

public function OgMembershipTest::testSaveSameMembershipTwice in Organic groups 8

Tests re-saving a membership.

@covers ::preSave

File

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

Class

OgMembershipTest
Tests the OgMembership entity.

Namespace

Drupal\Tests\og\Kernel\Entity

Code

public function testSaveSameMembershipTwice() {
  $group = EntityTest::create([
    'type' => mb_strtolower($this
      ->randomMachineName()),
    'name' => $this
      ->randomString(),
  ]);
  $group
    ->save();
  $this->groupTypeManager
    ->addGroup('entity_test', $group
    ->bundle());

  /** @var \Drupal\og\OgMembershipInterface $membership */
  $membership = Og::createMembership($group, $this->user);
  $membership
    ->save();

  // Block membership and save.
  $membership
    ->setState(OgMembershipInterface::STATE_BLOCKED);
  $membership
    ->save();
}