You are here

public function UIFPlusOgFieldsTestCase::testUIFPlusOgFieldImport in User Import Framework Plus 7

Test import of og group memberships

File

./uif_plus.test, line 79
Test cases for User Import Framework Plus module

Class

UIFPlusOgFieldsTestCase

Code

public function testUIFPlusOgFieldImport() {
  $this
    ->drupalLogin($this->import_user);

  // Create a group.
  og_create_field(OG_GROUP_FIELD, 'node', 'page');
  $settings = array();
  $settings['title'] = t('Group 1');
  $settings['type'] = 'page';
  $settings['uid'] = $this->import_user->uid;
  $settings[OG_GROUP_FIELD][LANGUAGE_NONE][0]['value'] = 1;
  $node = $this
    ->drupalCreateNode($settings);
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertText(t('Group 1'), t('Group 1 is.'));
  $this
    ->assertText(t('You are the group manager'), t('Group manager gets correct text.'));

  // check total members
  $memberships = og_membership_load_multiple(FALSE, array(
    'gid' => $node->nid,
    'entity_type' => 'user',
  ));
  $this
    ->assertEqual(count($memberships), 1, t('Found 1 OG membership.'));

  // import user into the group
  variable_set('uif_value_delimiter', '_:_');
  $edit = array();
  $edit['files[user_upload]'] = DRUPAL_ROOT . '/' . drupal_get_path('module', 'uif_plus') . '/data/test_og_1.csv';
  $this
    ->drupalPost('admin/people/uif', $edit, t('Next'));
  $this
    ->drupalPost(NULL, array(), t('Import users'));
  $this
    ->assertText(t('User import complete', array()));
  $this
    ->assertText(t('One user was created', array()));
  $memberships2 = og_membership_load_multiple(FALSE, array(
    'gid' => $node->nid,
    'entity_type' => 'user',
  ));
  $this
    ->assertEqual(count($memberships2), 2, t('Found 2 OG memberships.'));

  // check og_membership of new user
  $accounts = user_load_multiple(array(), array(
    'name' => 'flintstone',
    'mail' => 'flintstone@bedrock.com',
  ));
  $new_user = reset($accounts);
  $this
    ->assertEqual($new_user->name, 'flintstone', 'User flinstone found');

  // Assert the user is a group member.
  // Note: Method signature of og_is_member() is different in og-1.x and og-2.x
  if (uif_plus_check_og_version_1()) {
    $this
      ->assertTrue(og_is_member($node->nid, 'user', $new_user), t('User flinstone is a group member of Group 1'));
  }
  else {
    $this
      ->assertTrue(og_is_member('node', $node->nid, 'user', $new_user), t('User flinstone is a group member of Group 1'));
  }
}