View source
<?php
class UserImportNodeprofile extends UserImportTest {
var $modules = array(
'nodeprofile',
'nodefamily',
'subform_element',
'content',
'number',
'optionwidgets',
'text',
'link',
'date',
'date_api',
'node_import',
);
function get_info() {
return array(
'name' => t('Import Users (Nodeprofile)'),
'desc' => t('Test import of user data into Nodeprofile module.'),
'group' => t('User Import'),
);
}
function testCreateImport() {
$this
->enableModules($this->modules);
$this
->nodeprofileConfiguration();
$this
->get('logout');
$this
->drupalLoginUser($this->user_importer);
$this
->settingsFileSelect();
$this
->importID($this
->getUrl());
$settings = array();
$this
->settingsEmailMatch($settings);
$this
->settingsNodeprofileMatch($settings);
$this
->settingsIgnoreFirstLine($settings);
$this
->drupalPostRequest($this
->getUrl(), $settings, 'Import');
$this
->checkNodeprofileExist();
}
function nodeprofileConfiguration() {
$this->admin_user = $this
->drupalCreateUserRolePerm(array(
'administer users',
'access administration pages',
'administer access control',
'administer site configuration',
'administer content types',
'administer taxonomy',
));
$this
->drupalLoginUser($this->admin_user);
$edit = array(
'name' => 'Identity',
'type' => 'identity',
'title_label' => 'Title',
'body_label' => NULL,
'node_options[promote]' => 0,
'nodefamily_max' => 1,
'nodeprofile' => 1,
);
$this
->drupalPostRequest('admin/content/types/add', $edit, t('Save content type'));
$edit = array(
'label' => 'first_name',
'field_widget_type' => 'text-text',
);
$this
->drupalPostRequest('admin/content/types/identity/add_field', $edit, t('Create field'));
$edit = array(
'label' => 'First Name',
'required' => 1,
);
$this
->drupalPostRequest('admin/content/types/identity/fields/field_first_name', $edit, t('Save field settings'));
$edit = array(
'label' => 'last_name',
'field_widget_type' => 'text-text',
);
$this
->drupalPostRequest('admin/content/types/identity/add_field', $edit, t('Create field'));
$edit = array(
'label' => 'Last Name',
'required' => 1,
);
$this
->drupalPostRequest('admin/content/types/identity/fields/field_last_name', $edit, t('Save field settings'));
$edit = array(
'name' => 'Biography',
'type' => 'biography',
'title_label' => 'Title',
'body_label' => NULL,
'node_options[promote]' => 0,
'nodefamily_max' => 1,
'nodeprofile' => 1,
);
$this
->drupalPostRequest('admin/content/types/add', $edit, t('Save content type'));
$edit = array(
'label' => 'cv',
'field_widget_type' => 'text-text',
);
$this
->drupalPostRequest('admin/content/types/biography/add_field', $edit, t('Create field'));
$edit = array(
'label' => 'CV',
'required' => 1,
'rows' => 5,
);
$this
->drupalPostRequest('admin/content/types/biography/fields/field_cv', $edit, t('Save field settings'));
$edit = array(
'name' => 'Interests',
'nodes[biography]' => 'biography',
'tags' => 1,
);
$this
->drupalPostRequest('admin/content/taxonomy/add/vocabulary', $edit, t('Submit'));
$vocabularies = taxonomy_get_vocabularies('biography');
foreach ($vocabularies as $vocabulary) {
$this->vocabulary_id = $vocabulary->vid;
}
$edit = array(
'label' => 'blog',
'field_widget_type' => 'link-link',
);
$this
->drupalPostRequest('admin/content/types/biography/add_field', $edit, t('Create field'));
$edit = array(
'label' => 'Blog',
);
$this
->drupalPostRequest('admin/content/types/biography/fields/field_blog', $edit, t('Save field settings'));
$edit = array(
'label' => 'birthday',
'field_widget_type' => 'datestamp-date_text',
);
$this
->drupalPostRequest('admin/content/types/biography/add_field', $edit, t('Create field'));
$edit = array(
'label' => 'Birthday',
);
$this
->drupalPostRequest('admin/content/types/biography/fields/field_birthday', $edit, t('Save field settings'));
$edit = array(
'name' => 'Contact Details',
'type' => 'contact_details',
'title_label' => 'Title',
'body_label' => NULL,
'node_options[promote]' => 0,
'nodefamily_max' => 1,
'nodeprofile' => 1,
);
$this
->drupalPostRequest('admin/content/types/add', $edit, t('Save content type'));
$edit = array(
'label' => 'can_be_contacted',
'field_widget_type' => 'number_integer-options_onoff',
);
$this
->drupalPostRequest('admin/content/types/contact-details/add_field', $edit, t('Create field'));
$edit = array(
'label' => 'Can Be Contacted',
'allowed_values' => "0\n 1|Can be contacted",
);
$this
->drupalPostRequest('admin/content/types/contact-details/fields/field_can_be_contacted', $edit, t('Save field settings'));
$edit = array(
'label' => 'contact_preference',
'field_widget_type' => 'text-options_select',
);
$this
->drupalPostRequest('admin/content/types/contact-details/add_field', $edit, t('Create field'));
$edit = array(
'label' => 'Contact Preference',
'allowed_values' => 'email|email
telephone|telephone
post|post',
);
$this
->drupalPostRequest('admin/content/types/contact-details/fields/field_contact_preference', $edit, t('Save field settings'));
$edit = array(
'2[create identity content]' => 'create identity content',
'2[create biography content]' => 'create biography content',
'2[create contact_details content]' => 'create contact_details content',
);
$this
->drupalPostRequest('admin/user/permissions', $edit, t('Save permissions'));
}
function settingsNodeprofileMatch(&$edit) {
$edit['field_match[0][field_match]'] = 'nodeprofile-identity field_first_name_value';
$edit['field_match[1][field_match]'] = 'nodeprofile-identity field_last_name_value';
$edit['field_match[10][field_match]'] = 'nodeprofile-biography field_cv_value';
$edit['field_match[7][field_match]'] = 'nodeprofile-contact_details field_can_be_contacted_value';
$edit['field_match[8][field_match]'] = 'nodeprofile-contact_details field_contact_preference_value';
$edit['field_match[9][field_match]'] = 'taxonomy-' . $this->vocabulary_id;
$edit['field_match[6][field_match]'] = 'nodeprofile-biography field_blog_url';
$edit['field_match[11][field_match]'] = 'nodeprofile-biography field_birthday_value';
}
function checkNodeprofileExist() {
$file_path = drupal_get_path('module', 'user_import') . '/sample.txt';
$handle = @fopen($file_path, "r");
$row = 0;
while ($csv = fgetcsv($handle, 1000, ',')) {
if ($row > 0) {
$user = user_load(array(
'mail' => $csv[5],
));
$identity = node_load(array(
'type' => 'identity',
'uid' => $user->uid,
));
$biography = node_load(array(
'type' => 'biography',
'uid' => $user->uid,
));
$contact_details = node_load(array(
'type' => 'contact_details',
'uid' => $user->uid,
));
$this
->assertEqual($identity->field_first_name[0]['value'], $csv[0], "[Compare CSV and Profile data] Row: {$row} Field: First Name");
$this
->assertEqual($identity->field_last_name[0]['value'], $csv[1], "[Compare CSV and Profile data] Row: {$row} Field: Last Name");
$this
->assertEqual($biography->field_blog[0]['url'], $csv[6], "[Compare CSV and Profile data] Row: {$row} Field: Blog");
$this
->assertEqual($contact_details->field_can_be_contacted[0]['value'], $csv[7], "[Compare CSV and Profile data] Row: {$row} Field: Contact Permission");
$this
->assertEqual($contact_details->field_contact_preference[0]['value'], $csv[8], "[Compare CSV and Profile data] Row: {$row} Field: Contact Preference");
$this
->assertEqual($user->profile_interests, $csv[9], "[Compare CSV and Profile data] Row: {$row} Field: Profile Interests");
$this
->assertEqual($biography->field_cv[0]['value'], $csv[10], "[Compare CSV and Profile data] Row: {$row} Field: CV");
$this
->assertEqual($biography->field_birthday[0]['value'], $csv[11], "[Compare CSV and Profile data] Row: {$row} Field: Birthday");
if (!empty($user->profile_interests)) {
$interests = explode(',', $user->profile_interests);
$this
->drupalGet('profile/profile_interests/' . $interests[0]);
$this
->assertWantedRaw('<a title="View user profile." href="/' . url('user/' . $user->uid) . '">' . $user->name . '</a>', '[Freeform List] User is listed on page about item in list');
}
}
$row++;
}
}
function tearDown() {
$users_email = $this
->usersList();
foreach ($users_email as $mail) {
$account = user_load(array(
'mail' => $mail,
));
if (!empty($account)) {
$identity = node_load(array(
'type' => 'identity',
'uid' => $account->uid,
));
$biography = node_load(array(
'type' => 'biography',
'uid' => $account->uid,
));
$contact_details = node_load(array(
'type' => 'contact_details',
'uid' => $account->uid,
));
node_delete($identity->nid);
node_delete($biography->nid);
node_delete($contact_details->nid);
user_delete(array(), $account->uid);
}
}
$import_id = $this
->importID();
$this
->assertTrue(!empty($import_id), t('Import ID: !id', array(
'!id' => $import_id,
)));
_user_import_settings_deletion($import_id);
taxonomy_del_vocabulary($this->vocabulary_id);
foreach ($this->modules as $module) {
if (function_exists($module . '_uninstall')) {
$result = call_user_func_array($module . '_uninstall', array());
}
}
node_type_delete('dummy');
node_type_delete('identity');
node_type_delete('biography');
node_type_delete('contact_details');
parent::tearDown();
}
}