You are here

public function FeedsCSVtoRelationsTest::testUniqueEndpoints in Relation 7

Test unique endpoints setting

File

relation_feeds/tests/relation.feeds_processor.test, line 114

Class

FeedsCSVtoRelationsTest
Test aggregating a feed as data records.

Code

public function testUniqueEndpoints() {

  // relation_ctools_test relation types are all non-directional so create a
  // directional relation type too.
  $this->relation_types['directional'] = array(
    'relation_type' => 'directional',
    'label' => 'directional',
    'directional' => TRUE,
    'source_bundles' => array(
      'user:*',
    ),
    'target_bundles' => array(
      'user:*',
    ),
  );
  relation_type_save($this->relation_types['directional']);

  // Go to mapping page and create a couple of mappings.
  $mappings = array(
    0 => array(
      'source' => 'target',
      'target' => 'target_bundles:user:*:guid',
    ),
    1 => array(
      'source' => 'source',
      'target' => 'source_bundles:user:*:guid',
    ),
  );
  $this
    ->setSettings('relation_import', 'RelationFeedsProcessor', array(
    'bundle' => 'directional',
    // unfortunate typo, can't fix as it would break existing and exported
    // feeds importer configurations.
    'unique_enpoints' => TRUE,
  ));
  $this
    ->addMappings('relation_import', $mappings);

  // Import CSV file creating 'directional' relations between users.
  $this
    ->importFile('relation_import', $this
    ->absolutePath() . '/tests/feeds/directional_relations.csv');

  // Assert results.
  $this
    ->assertText('Created 4 relations');

  // Directional relations should be the following:
  // Morticia → Gomez
  // Gomez → Morticia
  // Fester → Gomez
  // Fester → Fester
  foreach (array(
    'Morticia',
    'Gomez',
    'Fester',
  ) as $user_name) {
    $users[$user_name] = user_load_by_name($user_name);
  }
  $endpoint_sets[] = array(
    array(
      'entity_type' => 'user',
      'entity_id' => $users['Morticia']->uid,
    ),
    array(
      'entity_type' => 'user',
      'entity_id' => $users['Gomez']->uid,
    ),
  );
  $endpoint_sets[] = array(
    array(
      'entity_type' => 'user',
      'entity_id' => $users['Gomez']->uid,
    ),
    array(
      'entity_type' => 'user',
      'entity_id' => $users['Morticia']->uid,
    ),
  );
  $endpoint_sets[] = array(
    array(
      'entity_type' => 'user',
      'entity_id' => $users['Fester']->uid,
    ),
    array(
      'entity_type' => 'user',
      'entity_id' => $users['Gomez']->uid,
    ),
  );
  $endpoint_sets[] = array(
    array(
      'entity_type' => 'user',
      'entity_id' => $users['Fester']->uid,
    ),
    array(
      'entity_type' => 'user',
      'entity_id' => $users['Fester']->uid,
    ),
  );
  foreach ($endpoint_sets as $endpoints) {
    $this
      ->assertTrue(relation_relation_exists($endpoints, 'directional', TRUE));
  }
}