function UserImportProfileTestCase::checkProfileExist in User Import 6.4
Same name and namespace in other branches
- 6.2 user_import.test \UserImportProfileTestCase::checkProfileExist()
Check data in CSV file matches data in profiles
1 call to UserImportProfileTestCase::checkProfileExist()
- UserImportProfileTestCase::testCreateImport in ./
user_import.test - User with right permissions creates import (with new settings)
File
- ./
user_import.test, line 528
Class
- UserImportProfileTestCase
- Test import of user data into Profile module
Code
function checkProfileExist() {
$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],
));
// test each data cell against Profile field content
$profile_first_name = isset($user->profile_first_name) ? $user->profile_first_name : '';
$this
->assertEqual($profile_first_name, $csv[0], "[Compare CSV data to Profile data] Row: {$row} Field: First Name");
$profile_last_name = isset($user->profile_last_name) ? $user->profile_last_name : '';
$this
->assertEqual($profile_last_name, $csv[1], "[Compare CSV data to Profile data] Row: {$row} Field: Last Name");
$profile_blog = isset($user->profile_blog) ? $user->profile_blog : '';
$this
->assertEqual($profile_blog, $csv[6], "[Compare CSV data to Profile data] Row: {$row} Field: Blog");
$profile_contact_permission = isset($user->profile_contact_permission) ? $user->profile_contact_permission : '';
$file_field_value = !isset($csv[7]) || empty($csv[7]) ? 0 : 1;
$this
->assertEqual($profile_contact_permission, $file_field_value, "[Compare CSV data to Profile data] Row: {$row} Field: Contact Permission");
$profile_contact_preference = isset($user->profile_contact_preference) ? $user->profile_contact_preference : '';
$this
->assertEqual($profile_contact_preference, $csv[8], "[Compare CSV data to Profile data] Row: {$row} Field: Contact Preference");
$profile_interests = isset($user->profile_interests) ? $user->profile_interests : '';
$this
->assertEqual($profile_interests, $csv[9], "[Compare CSV data to Profile data] Row: {$row} Field: Profile Interests");
$profile_cv = isset($user->profile_cv) ? $user->profile_cv : '';
$this
->assertEqual($profile_cv, $csv[10], "[Compare CSV data to Profile data] Row: {$row} Field: CV");
$profile_birthday = isset($user->profile_birthday) ? implode('/', $user->profile_birthday) : '';
if (isset($user->profile_birthday)) {
$profile_birthday = $user->profile_birthday['month'] . '/' . $user->profile_birthday['day'] . '/' . $user->profile_birthday['year'];
}
else {
$profile_birthday = '';
}
$this
->assertEqual($profile_birthday, $csv[11], "[Compare CSV data to Profile data] Row: {$row} Field: Birthday");
/**
* @todo test below fails because it gets an access denied message.
*/
//test interests link on profile page
// if (!empty($user->profile_interests)) {
// $interests = explode(',', $user->profile_interests);
// $this->drupalGet('profile/profile_interests/' . $interests[0]);
// $this->assertRaw('<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++;
}
}