You are here

function OgUiSubscribeTestCase::testOgUiAddPeople in Organic groups 7

Testing adding people via group/[entity_type]/[etid]/admin/people/add-user.

File

og_ui/og_ui.test, line 86

Class

OgUiSubscribeTestCase

Code

function testOgUiAddPeople() {
  $admin_user = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($admin_user);

  // Create an entity.
  $node = entity_create('node', array(
    'type' => 'article',
    'uid' => $admin_user->uid,
  ));
  $node->{OG_GROUP_FIELD}[LANGUAGE_NONE][0]['value'] = 1;
  entity_save('node', $node);
  $group = og_get_group('node', $node->nid);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText(t('You are the group manager'), t('Group manager gets correct text.'));
  $web_user = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($web_user);
  $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 does not appear.'));
  $request = $this
    ->randomString();
  $edit = array();
  $edit['membership_fields[og_membership_request][und][0][value]'] = $request;
  $this
    ->drupalPost(NULL, $edit, t('Join'));
  $og_membership = og_get_group_membership($group->gid, 'user', $web_user->uid);
  $this
    ->assertEqual($request, $og_membership->og_membership_request[LANGUAGE_NONE][0]['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('Remove'));
  $this
    ->assertFalse(og_is_member($group->gid, 'user', $web_user, array(
    OG_STATE_ACTIVE,
    OG_STATE_PENDING,
  )), t('User unsubscribed from group.'));

  // Change global permissions to allow user to subscribe without approval.
  $roles = array_flip(og_get_global_roles());
  $rid = $roles[OG_ANONYMOUS_ROLE];
  $permissions = array(
    'subscribe without approval' => 1,
  );
  og_role_change_permissions($rid, $permissions);
  $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($group->gid, 'user', $web_user), t('User subscribed to group'));
}