You are here

protected function OgMembershipTest::setUp in Organic groups 8

Overrides KernelTestBase::setUp

File

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

Class

OgMembershipTest
Tests the OgMembership entity.

Namespace

Drupal\Tests\og\Kernel\Entity

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->installConfig([
    'og',
  ]);
  $this
    ->installEntitySchema('og_membership');
  $this
    ->installEntitySchema('entity_test');
  $this
    ->installEntitySchema('entity_test_mul');
  $this
    ->installEntitySchema('node');
  $this
    ->installEntitySchema('user');
  $this
    ->installSchema('system', 'sequences');
  $this->entityTypeManager = $this->container
    ->get('entity_type.manager');
  $this->groupTypeManager = $this->container
    ->get('og.group_type_manager');
  $storage = $this->entityTypeManager
    ->getStorage('user');

  // Insert a row for the anonymous user.
  // @see user_install().
  $storage
    ->create([
    'uid' => 0,
    'status' => 0,
    'name' => '',
  ])
    ->save();

  // Create the group owner.
  $owner = User::create([
    'name' => $this
      ->randomString(),
  ]);
  $owner
    ->save();
  $this->owner = $owner;

  // Create a bundle and add as a group.
  $group = EntityTest::create([
    'type' => 'test_bundle',
    'name' => $this
      ->randomString(),
    'user_id' => $owner
      ->id(),
  ]);
  $group
    ->save();
  $this->group = $group;

  // Add that as a group.
  $this->groupTypeManager
    ->addGroup('entity_test', $group
    ->bundle());

  // Create test user.
  $user = User::create([
    'name' => $this
      ->randomString(),
  ]);
  $user
    ->save();
  $this->user = $user;
}