You are here

function UserImportNodeprofile::checkNodeprofileExist in User Import 5

Same name and namespace in other branches
  1. 8 tests/user_import_nodeprofile.test \UserImportNodeprofile::checkNodeprofileExist()

* Check data in CSV file matches data in profiles

1 call to UserImportNodeprofile::checkNodeprofileExist()
UserImportNodeprofile::testCreateImport in tests/user_import_nodeprofile.test
* User with right permissions creates import (with new settings) * - test import of user data into Nodeprofile module

File

tests/user_import_nodeprofile.test, line 158

Class

UserImportNodeprofile
Test import of user data into Profile module

Code

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],
      ));

      // test each data cell against nodeprofile field content
      $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,
      ));

      //if ($row == 1) var_dump($user);
      $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");

      //test interests link on profile page
      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++;
  }
}