You are here

public function UserFeedsMapperLocationTestCase::test in Location Feeds 7

Same name and namespace in other branches
  1. 6 tests/location_feeds.user.test \UserFeedsMapperLocationTestCase::test()

Basic test loading an RSS feed for users with locations.

File

tests/location_feeds.user.test, line 38

Class

UserFeedsMapperLocationTestCase

Code

public function test() {

  // expected import values:
  $loc = array(
    0 => array(
      'street' => "405 Hilgard Ave.",
      'city' => "Los Angeles",
      'province' => "CA",
      'postal_code' => 90095,
      'country' => "us",
    ),
    1 => array(
      'street' => "2400 Inner Campus Drive",
      'city' => "Austin",
      'province' => "TX",
      'postal_code' => 78712,
      'country' => "us",
    ),
    2 => array(
      'street' => "405 Hilgard Ave.",
      'city' => "Los Angeles",
      'province' => "CA",
      'postal_code' => 90095,
      'country' => "us",
    ),
  );
  $settings = array();
  $this
    ->saveUserLocationSettings($settings);

  // Create a feed.
  $this
    ->createImporterConfiguration('User location import', 'user_location_import');

  // Set and configure plugins.
  $this
    ->setSettings('user_location_import', NULL, array(
    'content_type' => '',
    'import_period' => FEEDS_SCHEDULE_NEVER,
  ));
  $this
    ->setPlugin('user_location_import', 'FeedsFileFetcher');
  $this
    ->setPlugin('user_location_import', 'FeedsCSVParser');
  $this
    ->setPlugin('user_location_import', 'FeedsUserProcessor');

  // Go to mapping page and create a couple of mappings.
  $mappings = array(
    '0' => array(
      'source' => 'name',
      'target' => 'name',
      'unique' => 0,
    ),
    '1' => array(
      'source' => 'mail',
      'target' => 'mail',
      'unique' => 1,
    ),
    '2' => array(
      'source' => 'street',
      'target' => 'locations:street',
      'unique' => FALSE,
    ),
    '3' => array(
      'source' => 'city',
      'target' => 'locations:city',
      'unique' => FALSE,
    ),
    '4' => array(
      'source' => 'state',
      'target' => 'locations:province',
      'unique' => FALSE,
    ),
    '5' => array(
      'source' => 'country',
      'target' => 'locations:country',
      'unique' => FALSE,
    ),
    '6' => array(
      'source' => 'zip',
      'target' => 'locations:postal_code',
      'unique' => FALSE,
    ),
  );
  $this
    ->addMappings('user_location_import', $mappings);

  // Import CSV file.
  $this
    ->importFile('user_location_import', drupal_get_path('module', 'location_feeds') . '/tests/feeds/location_users.csv');

  // Assert result.
  $this
    ->assertText('Created 3 users');
  $this
    ->drupalGet('admin/people');
  $this
    ->assertText('blue');
  $this
    ->assertText('drop');
  $this
    ->assertText('red');
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'user');
  $query
    ->propertyCondition('name', 'blue');
  $res = $query
    ->execute();
  foreach ($res['user'] as $uid => $account) {
    $blue = user_load($uid);
    if ($blue->name == 'blue') {
      break;
    }
  }
  $this
    ->assertEqual($loc[0]['street'], $blue->locations[0]['street'], t('Testing street import, expected: @e, found: @f', array(
    '@e' => $loc[0]['street'],
    '@f' => $blue->locations[0]['street'],
  )));
  $this
    ->assertEqual($loc[0]['city'], $blue->locations[0]['city'], t('Testing city import, expected: @e, found: @f', array(
    '@e' => $loc[0]['city'],
    '@f' => $blue->locations[0]['city'],
  )));
  $this
    ->assertEqual($loc[0]['province'], $blue->locations[0]['province'], t('Testing province import, expected: @e, found: @f', array(
    '@e' => $loc[0]['province'],
    '@f' => $blue->locations[0]['province'],
  )));
  $this
    ->assertEqual($loc[0]['country'], $blue->locations[0]['country'], t('Testing country import, expected: @e, found: @f', array(
    '@e' => $loc[0]['country'],
    '@f' => $blue->locations[0]['country'],
  )));
  $this
    ->assertEqual($loc[0]['postal_code'], $blue->locations[0]['postal_code'], t('Testing country import, expected: @e, found: @f', array(
    '@e' => $loc[0]['postal_code'],
    '@f' => $blue->locations[0]['postal_code'],
  )));
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'user');
  $query
    ->propertyCondition('name', 'drop');
  $res = $query
    ->execute();
  foreach ($res['user'] as $uid => $account) {
    $drop = user_load($uid);
    if ($drop->name == 'drop') {
      break;
    }
  }
  $this
    ->assertEqual($loc[1]['street'], $drop->locations[0]['street'], t('Testing street import, expected: @e, found: @f', array(
    '@e' => $loc[1]['street'],
    '@f' => $drop->locations[0]['street'],
  )));
  $this
    ->assertEqual($loc[1]['city'], $drop->locations[0]['city'], t('Testing city import, expected: @e, found: @f', array(
    '@e' => $loc[1]['city'],
    '@f' => $drop->locations[0]['city'],
  )));
  $this
    ->assertEqual($loc[1]['province'], $drop->locations[0]['province'], t('Testing province import, expected: @e, found: @f', array(
    '@e' => $loc[1]['province'],
    '@f' => $drop->locations[0]['province'],
  )));
  $this
    ->assertEqual($loc[1]['country'], $drop->locations[0]['country'], t('Testing country import, expected: @e, found: @f', array(
    '@e' => $loc[1]['country'],
    '@f' => $drop->locations[0]['country'],
  )));
  $this
    ->assertEqual($loc[1]['postal_code'], $drop->locations[0]['postal_code'], t('Testing country import, expected: @e, found: @f', array(
    '@e' => $loc[1]['postal_code'],
    '@f' => $drop->locations[0]['postal_code'],
  )));
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'user');
  $query
    ->propertyCondition('name', 'red');
  $res = $query
    ->execute();
  foreach ($res['user'] as $uid => $account) {
    $red = user_load($uid);
    if ($red->name == 'red') {
      break;
    }
  }
  $this
    ->assertEqual($loc[2]['street'], $red->locations[0]['street'], t('Testing street import, expected: @e, found: @f', array(
    '@e' => $loc[2]['street'],
    '@f' => $red->locations[0]['street'],
  )));
  $this
    ->assertEqual($loc[2]['city'], $red->locations[0]['city'], t('Testing city import, expected: @e, found: @f', array(
    '@e' => $loc[2]['city'],
    '@f' => $red->locations[0]['city'],
  )));
  $this
    ->assertEqual($loc[2]['province'], $red->locations[0]['province'], t('Testing province import, expected: @e, found: @f', array(
    '@e' => $loc[2]['province'],
    '@f' => $red->locations[0]['province'],
  )));
  $this
    ->assertEqual($loc[2]['country'], $red->locations[0]['country'], t('Testing country import, expected: @e, found: @f', array(
    '@e' => $loc[2]['country'],
    '@f' => $red->locations[0]['country'],
  )));
  $this
    ->assertEqual($loc[2]['postal_code'], $red->locations[0]['postal_code'], t('Testing country import, expected: @e, found: @f', array(
    '@e' => $loc[2]['postal_code'],
    '@f' => $red->locations[0]['postal_code'],
  )));
}