You are here

function JanrainCaptureMappingTestCase::testFieldApiMapping in Janrain Registration 7

Same name and namespace in other branches
  1. 7.4 janrain_capture_mapping/tests/janrain_capture_mapping.test \JanrainCaptureMappingTestCase::testFieldApiMapping()
  2. 7.2 janrain_capture_mapping/tests/janrain_capture_mapping.test \JanrainCaptureMappingTestCase::testFieldApiMapping()
  3. 7.3 janrain_capture_mapping/tests/janrain_capture_mapping.test \JanrainCaptureMappingTestCase::testFieldApiMapping()

File

janrain_capture_mapping/tests/janrain_capture_mapping.test, line 66

Class

JanrainCaptureMappingTestCase

Code

function testFieldApiMapping() {

  // Set up a Field API field on the user so that we can test mapping a Capture
  // property to that field.
  $field = array(
    'type' => 'text',
    'field_name' => 'field_test_field',
    'cardinality' => 1,
  );
  field_create_field($field);
  $instance = array(
    'field_name' => 'field_test_field',
    'entity_type' => 'user',
    'label' => 'User text field',
    'bundle' => 'user',
    'required' => FALSE,
    'settings' => array(
      'user_register_form' => FALSE,
    ),
    'widget' => array(
      'type' => 'text_textfield',
      'weight' => -1,
    ),
  );
  field_create_instance($instance);
  $given_name_fid = db_query("SELECT fid FROM {janrain_capture_mapping_field} where path = 'givenName'")
    ->fetchField();

  // Our mappings start at index 2 because 0 and 1 have been taken by the two default fields that
  // get mapped on install.
  $edit = array(
    '0[fid]' => $given_name_fid,
    '0[field]' => 'field_test_field',
    '0[column]' => 'value',
  );
  $this
    ->drupalPost('admin/config/people/janrain_capture/mapping', $edit, t('Save configuration'));
  $mapping = variable_get('janrain_capture_mapping_map', array());
  $this
    ->assertEqual($given_name_fid, $mapping[0]['fid'], t('Field mapping was saved'));

  // Create a user whose profile we will manipulate
  $drupal_user = $this
    ->drupalCreateUser();

  // Load up our user fully.
  $drupal_user = user_load($drupal_user->uid);

  // Mock a capture profile that will get mapped.
  $capture_profile = array(
    'uuid' => $this
      ->randomString(),
    'email' => 'user2@someaddress.com',
    'givenName' => $this
      ->randomName(),
    'familyName' => $this
      ->randomName(),
    'displayName' => $this
      ->randomName(),
    'gender' => 'female',
  );
  janrain_capture_sync_account($drupal_user, $capture_profile);
  user_save($drupal_user);

  // Test that our field_test_field value was mapped correctly.
  $this
    ->assertTrue($drupal_user->field_test_field[LANGUAGE_NONE][0]['value'] == $capture_profile['givenName'], t('Given name field from capture was mapped to the test field'));
}