You are here

function OgGroupMembership::testUserEdit in Organic groups 7

Test re-saving user with pending membership.

File

./og.test, line 612

Class

OgGroupMembership
Test group membership handeling.

Code

function testUserEdit() {
  $user1 = $this
    ->drupalCreateUser();
  $user2 = $this
    ->drupalCreateUser();
  $type = $this
    ->drupalCreateContentType()->type;
  og_create_field(OG_GROUP_FIELD, 'node', $type);
  $settings = array(
    'type' => $type,
    OG_GROUP_FIELD . '[und][0][value]' => 1,
  );
  $settings['uid'] = $user1->uid;
  $node = $this
    ->drupalCreateNode($settings);
  $group = og_get_group('node', $node->nid);
  $this
    ->assertFalse(og_get_entity_groups('user', $user2, array(
    OG_STATE_PENDING,
  )), 'User has no pending membership, as expected.');
  og_group($group->gid, array(
    'entity' => $user2,
    'state' => OG_STATE_PENDING,
  ));

  // Save via UI.
  $this
    ->drupalLogin($user2);
  $this
    ->drupalPost("user/{$user2->uid}/edit", array(), 'Save');
  $gids = og_get_entity_groups('user', $user2, array(
    OG_STATE_PENDING,
  ));
  $this
    ->assertEqual(array_values($gids), array(
    1,
  ), 'User membership was retained after user save.');

  // Programatic save.
  $user2 = user_load($user2->uid, TRUE);
  user_save($user2);
  $gids = og_get_entity_groups('user', $user2, array(
    OG_STATE_PENDING,
  ));
  $this
    ->assertEqual(array_values($gids), array(
    1,
  ), 'User membership was retained after programatic save.');
}