You are here

public function UIFPlusProfileFieldsTestCase::testUIFPlusMultiCardinalityFieldImport in User Import Framework Plus 7

Test import of multiple values separated by a value delimiter

File

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

Class

UIFPlusProfileFieldsTestCase

Code

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

  // The main profile2 type is created during module installation. Add a field to it
  $field = array(
    'field_name' => 'field_interests',
    'type' => 'text',
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  );
  field_create_field($field);
  $instance = array(
    'entity_type' => 'user',
    'field_name' => 'field_interests',
    'bundle' => 'user',
    'label' => 'Interests',
    'description' => 'Enter your interests',
  );
  field_create_instance($instance);
  variable_set('uif_value_delimiter', '_:_');

  // import user
  $edit = array();
  $edit['files[user_upload]'] = DRUPAL_ROOT . '/' . drupal_get_path('module', 'uif_plus') . '/data/test_profile2_2.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()));

  // load imported user
  $accounts = user_load_multiple(array(), array(
    'name' => 'barney',
    'mail' => 'barney@bedrock.com',
  ));
  $new_user = reset($accounts);
  $this
    ->assertEqual($new_user->field_interests[LANGUAGE_NONE][0]['value'], 'bowling', t('Interest 1: bowling, for User: @user imported successfully', array(
    '@user' => $new_user->name,
  )));
  $this
    ->assertEqual($new_user->field_interests[LANGUAGE_NONE][1]['value'], 'poker', t('Interest 2: poker, for User: @user imported successfully', array(
    '@user' => $new_user->name,
  )));
  $this
    ->assertEqual($new_user->field_interests[LANGUAGE_NONE][2]['value'], 'playing golf', t('Interest 3: playing golf, for User: @user imported successfully', array(
    '@user' => $new_user->name,
  )));
}