You are here

public function UIFTestCaseFieldFields::testUIFImportWithFieldAllFields in User Import Framework 7

Test addition of all Field module fields.

File

./uif.test, line 158
UIF test code.

Class

UIFTestCaseFieldFields
Test import with Field module fields.

Code

public function testUIFImportWithFieldAllFields() {
  $fields = array(
    array(
      'label' => 'Boolean Test',
      'field_name' => 'boolean_test',
      'type' => 'list_boolean',
      'widget_type' => 'options_buttons',
      'check_raw' => 'Boolean Test:&nbsp;</div><div class="field-items"><div class="field-item even">1</div>',
    ),
    array(
      'label' => 'Decimal Test',
      'field_name' => 'decimal_test',
      'type' => 'number_decimal',
      'widget_type' => 'number',
      'check_text' => '3.14',
    ),
    array(
      'label' => 'Float Test',
      'field_name' => 'float_test',
      'type' => 'number_float',
      'widget_type' => 'number',
      'check_text' => '1.23',
    ),
    array(
      'label' => 'Integer Test',
      'field_name' => 'integer_test',
      'type' => 'number_integer',
      'widget_type' => 'number',
      'check_text' => '4 844 632',
    ),
    array(
      'label' => 'Float List Test',
      'field_name' => 'float_list_test',
      'type' => 'list_float',
      'widget_type' => 'options_select',
      'check_text' => '4.56',
    ),
    array(
      'label' => 'Integer List Test',
      'field_name' => 'integer_list_test',
      'type' => 'list_integer',
      'widget_type' => 'options_select',
      'check_text' => '5678',
    ),
    array(
      'label' => 'Test List Test',
      'field_name' => 'text_list_test',
      'type' => 'list_text',
      'widget_type' => 'options_select',
      'check_text' => 'repeat',
    ),
    array(
      'label' => 'Long Text Test',
      'field_name' => 'long_text_test',
      'type' => 'text_long',
      'widget_type' => 'text_textarea',
      'check_text' => 'now is the time for',
    ),
    array(
      'label' => 'Long Text and Summary Test',
      'field_name' => 'long_text_summary_test',
      'type' => 'text_with_summary',
      'widget_type' => 'text_textarea_with_summary',
      'check_text' => 'all good people to',
    ),
    array(
      'label' => 'Text Test',
      'field_name' => 'text_test',
      'type' => 'text',
      'widget_type' => 'text_textfield',
      'check_text' => 'come to the aid',
    ),
    array(
      'label' => 'Term Reference Test',
      'field_name' => 'term_ref_test',
      'type' => 'taxonomy_term_reference',
      'widget_type' => 'options_select',
      'check_text' => 'granite',
    ),
  );
  $this
    ->drupalLogin($this->admin_user);
  foreach ($fields as $field) {
    $edit['fields[_add_new_field][label]'] = $field['label'];
    $edit['fields[_add_new_field][field_name]'] = $field['field_name'];
    $edit['fields[_add_new_field][type]'] = $field['type'];
    $edit['fields[_add_new_field][widget_type]'] = $field['widget_type'];
    $this
      ->drupalPost('admin/config/people/accounts/fields', $edit, t('Save'));
    $this
      ->assertText(t('These settings apply to the @label field everywhere it is used.', array(
      '@label' => $field['label'],
    )));
    if ($field['type'] == 'taxonomy_term_reference') {

      // otherwise no vocab assigned
      $this
        ->drupalPost(NULL, array(), t('Save field settings'));
    }
  }
  $this
    ->drupalLogin($this->import_user);
  $edit = array();
  $edit['files[user_upload]'] = DRUPAL_ROOT . '/' . drupal_get_path('module', 'uif') . '/test_data/test_field_fields_1.csv';
  $this
    ->drupalPost('admin/people/uif', $edit, t('Next'));
  $this
    ->assertText(t('Preview these records and when ready to import click Import users', array()));
  $this
    ->assertText('wilma@example.com');
  $this
    ->assertText(t('(create)', array()));
  $this
    ->drupalPost(NULL, array(), t('Import users'));
  $this
    ->assertText(t('User import complete', array()));

  // Retrieve imported user
  field_cache_clear();
  $name = 'wilma';
  $account = user_load_by_name($name);
  $this
    ->assertTrue($account != NULL, t('User @name was loaded', array(
    '@name' => $name,
  )));
  $account->pass_raw = 'rubble';
  $this
    ->drupalLogin($account);
  foreach ($fields as $field) {
    $this
      ->assertText($field['label']);
    if (isset($field['check_text'])) {
      $this
        ->assertText($field['check_text']);
    }
    elseif (isset($field['check_raw'])) {
      $this
        ->assertRaw($field['check_raw']);
    }
  }
}