You are here

public function GroupManagerSubscriptionTest::testGroupManagerSubscription in Organic groups 8

Tests whether a group manager is subscribed when creating a group.

@dataProvider groupManagerSubscriptionProvider

File

tests/src/Kernel/GroupManagerSubscriptionTest.php, line 97

Class

GroupManagerSubscriptionTest
Tests if the group manager is subscribed automatically upon group creation.

Namespace

Drupal\Tests\og\Kernel

Code

public function testGroupManagerSubscription($group_has_owner, $membership_is_overridden) {

  // Create the group, with a specific title that can be detected by the hook
  // implementation that overrides the creation of the membership.
  // @see og_test_entity_insert()
  $group = Node::create([
    'title' => $membership_is_overridden ? 'membership is overridden' : 'membership is not overridden',
    'type' => 'group',
  ]);

  // Set the group owner if the test requires it.
  if ($group_has_owner) {
    $group
      ->setOwner($this->owner);
  }
  $group
    ->save();

  // Check that a membership has only been created if the group had an owner
  // set.
  $membership = $this->membershipManager
    ->getMembership($group, $this->owner
    ->id());
  $this
    ->assertEquals($group_has_owner, !empty($membership));

  // Check if the membership has been overridden.
  $this
    ->assertEquals($membership_is_overridden, $this
    ->isMembershipOverridden($membership));
}