You are here

public function FeedsMapperTaxonomyTestCase::testSearchByGUID in Feeds 7.2

Tests mapping to a taxonomy term's guid.

File

tests/feeds_mapper_taxonomy.test, line 262
Contains FeedsMapperTaxonomyTestCase.

Class

FeedsMapperTaxonomyTestCase
Test case for taxonomy mapper mappers/taxonomy.inc.

Code

public function testSearchByGUID() {

  // Create 10 terms. The first one was created in setup.
  $tids = array(
    1,
  );
  foreach (range(2, 10) as $i) {
    $term = (object) array(
      'name' => 'term' . $i,
      'vid' => 1,
    );
    taxonomy_term_save($term);
    $tids[] = $term->tid;
  }

  // Create a bunch of bogus imported terms.
  $guids = array();
  foreach ($tids as $tid) {
    $guid = 100 * $tid;
    $guids[] = $guid;
    $record = array(
      'entity_type' => 'taxonomy_term',
      'entity_id' => $tid,
      'id' => 'does_not_exist',
      'feed_nid' => 0,
      'imported' => REQUEST_TIME,
      'url' => '',
      'guid' => $guid,
    );
    drupal_write_record('feeds_item', $record);
  }
  FeedsPlugin::loadMappers();
  $entity = new stdClass();
  $target = 'field_tags';
  $mapping = array(
    'term_search' => FEEDS_TAXONOMY_SEARCH_TERM_GUID,
    'language' => LANGUAGE_NONE,
  );
  $source = FeedsSource::instance('tmp', 0);
  taxonomy_feeds_set_target($source, $entity, $target, $guids, $mapping);
  $this
    ->assertEqual(count($entity->field_tags[LANGUAGE_NONE]), 10);
  foreach ($entity->field_tags[LANGUAGE_NONE] as $delta => $values) {
    $this
      ->assertEqual($tids[$delta], $values['tid'], 'Correct term id foud.');
  }

  // Test a second mapping with a bogus term id.
  taxonomy_feeds_set_target($source, $entity, $target, array(
    1234,
  ), $mapping);
  $this
    ->assertEqual(count($entity->field_tags[LANGUAGE_NONE]), 10);
  foreach ($entity->field_tags[LANGUAGE_NONE] as $delta => $values) {
    $this
      ->assertEqual($tids[$delta], $values['tid'], 'Correct term id foud.');
  }
}