You are here

public function GetMembershipsTest::testOrphanedMembershipsDeletion in Organic groups 8

Tests that memberships are deleted when a user is deleted.

File

tests/src/Kernel/Entity/GetMembershipsTest.php, line 269

Class

GetMembershipsTest
Tests retrieving OgMembership entities associated with a given user.

Namespace

Drupal\Tests\og\Kernel\Entity

Code

public function testOrphanedMembershipsDeletion() {
  foreach ($this->users as $user) {

    // Keep track of the user ID before deleting the user.
    $user_id = $user
      ->id();
    $user
      ->delete();

    // Check that the memberships for the user are deleted from the database.
    $memberships = $this->entityTypeManager
      ->getStorage('og_membership')
      ->getQuery()
      ->condition('uid', $user_id)
      ->execute();
    $this
      ->assertEmpty($memberships);
  }
}