You are here

function OgUiSubscribeTestCase::testOgUiSubscribe in Organic groups 7.2

Test subscribing to group.

File

og_ui/og_ui.test, line 167

Class

OgUiSubscribeTestCase

Code

function testOgUiSubscribe() {
  $user1 = $this
    ->drupalCreateUser();
  $user2 = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($user1);

  // Create a group.
  $settings = array();
  $settings['type'] = 'article';
  $settings['uid'] = $user1->uid;
  $settings[OG_GROUP_FIELD][LANGUAGE_NONE][0]['value'] = 1;
  $node = $this
    ->drupalCreateNode($settings);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText(t('You are the group manager'), t('Group manager gets correct text.'));
  $this
    ->drupalLogin($user2);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText(t('Request group membership'), t('Non-member without "subscribe without approval" gets correct text.'));
  $this
    ->clickLink(t('Request group membership'));

  // Assert user's request field appears.
  $this
    ->assertText('Request message', t('Request message appears.'));
  $request = $this
    ->randomString();
  $edit = array();
  $edit['og_membership_request[und][0][value]'] = $request;
  $this
    ->drupalPost(NULL, $edit, t('Join'));
  $og_membership = og_get_membership('node', $node->nid, 'user', $user2->uid);
  $wrapper = entity_metadata_wrapper('og_membership', $og_membership);
  $this
    ->assertEqual($request, $wrapper->og_membership_request
    ->value(), t('User request was saved in group membership.'));
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText(t('Unsubscribe from group'), t('Member gets correct unsubscribe text.'));
  $this
    ->clickLink(t('Unsubscribe from group'));
  $this
    ->drupalPost(NULL, array(), t('Unsubscribe'));
  $this
    ->assertFalse(og_is_member('node', $node->nid, 'user', $user2, array(
    OG_STATE_ACTIVE,
    OG_STATE_PENDING,
  )), t('User unsubscribed from group.'));

  // Change global permissions to allow user to subscribe without approval.
  $og_roles = og_roles('node', 'article');
  $rid = array_search(OG_ANONYMOUS_ROLE, $og_roles);
  og_role_change_permissions($rid, array(
    'subscribe without approval' => 1,
  ));
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText(t('Subscribe to group'), t('Non-member with "subscribe without approval" gets correct text.'));
  $this
    ->clickLink(t('Subscribe to group'));
  $this
    ->assertNoText('Request message', t('Request message does not appear.'));
  $this
    ->drupalPost(NULL, array(), t('Join'));
  $this
    ->assertTrue(og_is_member('node', $node->nid, 'user', $user2), t('User subscribed to group'));
}