You are here

protected function GetUserGroupsTest::setUp in Organic groups 8

Overrides KernelTestBase::setUp

File

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

Class

GetUserGroupsTest
Tests getting the memberships of an entity.

Namespace

Drupal\Tests\og\Kernel\Entity

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->installConfig([
    'og',
  ]);
  $this
    ->installEntitySchema('og_membership');
  $this
    ->installEntitySchema('user');
  $this
    ->installEntitySchema('entity_test');
  $this
    ->installSchema('system', 'sequences');
  $this->membershipManager = $this->container
    ->get('og.membership_manager');
  $this->groupBundle = mb_strtolower($this
    ->randomMachineName());

  // Create users.
  $this->user1 = User::create([
    'name' => $this
      ->randomString(),
  ]);
  $this->user1
    ->save();
  $this->user2 = User::create([
    'name' => $this
      ->randomString(),
  ]);
  $this->user2
    ->save();
  $this->user3 = User::create([
    'name' => $this
      ->randomString(),
  ]);
  $this->user3
    ->save();

  // Define the group content as group.
  Og::groupTypeManager()
    ->addGroup('entity_test', $this->groupBundle);

  // Create a group and associate with user 1.
  $this->group1 = EntityTest::create([
    'type' => $this->groupBundle,
    'name' => $this
      ->randomString(),
    'user_id' => $this->user1
      ->id(),
  ]);
  $this->group1
    ->save();

  // Create a group and associate with user 2.
  $this->group2 = EntityTest::create([
    'type' => $this->groupBundle,
    'name' => $this
      ->randomString(),
    'user_id' => $this->user2
      ->id(),
  ]);
  $this->group2
    ->save();
}