You are here

function JanrainCaptureMappingTestCase::testPropertyMapping in Janrain Registration 7.2

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

Create some field mappings through the UI and ensure that they work.

File

janrain_capture_mapping/tests/janrain_capture_mapping.test, line 30

Class

JanrainCaptureMappingTestCase

Code

function testPropertyMapping() {

  // Test that we can map a capture field to the username property
  $display_name_fid = db_query("SELECT fid FROM {janrain_capture_mapping_field} where path = 'displayName'")
    ->fetchField();
  $edit = array(
    '0[fid]' => $display_name_fid,
    '0[field]' => 'name',
  );
  $this
    ->drupalPost('admin/config/people/janrain_capture/mapping', $edit, t('Save configuration'));
  $mapping = variable_get('janrain_capture_mapping_map', array());
  $this
    ->assertEqual($display_name_fid, $mapping[0]['fid'], t('Property mapping was saved'));

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

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

  // Test that the email gets mapped even though we have not set up a mapping for it.
  $this
    ->assertTrue($drupal_user->mail == $capture_profile['email'], t('User email was updated from capture'));

  // Test that our username mapping trumps the default mapping of email address to
  // username that is done by the core janrain_capture module.
  $this
    ->assertTrue($drupal_user->name == $capture_profile['displayName'], t('User name was updated from capture'));
}