View source
<?php
class JanrainCaptureMappingTestCase extends DrupalWebTestCase {
function getInfo() {
return array(
'name' => t('Janrain Capture Mapping tests'),
'description' => t('Test the field mapping for Janrain Capture.'),
'group' => t('Janrain Capture'),
);
}
function setUp() {
parent::setUp('entity', 'janrain_capture', 'janrain_capture_mapping');
$admin_user = $this
->drupalCreateUser(array(
'access administration pages',
'administer site configuration',
));
$this
->drupalLogin($admin_user);
}
function testPropertyMapping() {
$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'));
$drupal_user = $this
->drupalCreateUser();
$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);
$this
->assertTrue($drupal_user->mail == $capture_profile['email'], t('User email was updated from capture'));
$this
->assertTrue($drupal_user->name == $capture_profile['displayName'], t('User name was updated from capture'));
}
function testFieldApiMapping() {
$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();
$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'));
$drupal_user = $this
->drupalCreateUser();
$drupal_user = user_load($drupal_user->uid);
$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);
$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'));
}
}