You are here

public function GroupSubscribeFormTest::testIsStateActive in Organic groups 8

Tests subscribe confirmation related text.

@covers ::isStateActive

File

tests/src/Kernel/Form/GroupSubscribeFormTest.php, line 140

Class

GroupSubscribeFormTest
Tests access to the create entity form through the user interface.

Namespace

Drupal\Tests\og\Kernel\Form

Code

public function testIsStateActive() {
  $user = $this
    ->createUser([
    'access content',
  ]);

  /** @var \Drupal\og\Form\GroupSubscribeForm $form */
  $form = \Drupal::entityTypeManager()
    ->getFormObject('og_membership', 'subscribe');

  // Pending membership.
  $membership_pending = OgMembership::create();
  $membership_pending
    ->setGroup($this->group1)
    ->setOwner($user);
  $form
    ->setEntity($membership_pending);
  $this
    ->assertFalse($form
    ->isStateActive());

  // Active membership.
  $membership_active = OgMembership::create();
  $membership_active
    ->setGroup($this->group2)
    ->setOwner($user);
  $form
    ->setEntity($membership_active);
  $this
    ->assertTrue($form
    ->isStateActive());

  // Confirm user has access to the group node.
  $this
    ->assertTrue($this->group2
    ->access('view', $user));

  // Active membership to a group without access, should result with pending
  // membership by default.
  $membership = OgMembership::create();
  $membership
    ->setGroup($this->group3)
    ->setOwner($user);

  // Confirm user doesn't have access to the unpublished group node.
  $this
    ->assertFalse($this->group3
    ->access('view', $user));

  // Even though the state is active, it should result with pending, as user
  // doesn't have access to the group.
  $form
    ->setEntity($membership);
  $this
    ->assertFalse($form
    ->isStateActive());

  // Change the default settings, and assert state remains active.
  $this
    ->config('og.settings')
    ->set('deny_subscribe_without_approval', FALSE)
    ->save();
  $this
    ->assertTrue($form
    ->isStateActive());
}