You are here

public function FeedsMapperTaxonomyTestCase::testSearchByID in Feeds 7.2

Tests mapping to taxonomy terms by tid.

File

tests/feeds_mapper_taxonomy.test, line 228
Contains FeedsMapperTaxonomyTestCase.

Class

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

Code

public function testSearchByID() {

  // Create 10 terms. The first one was created in setup.
  $terms = array(
    1,
  );
  foreach (range(2, 10) as $i) {
    $term = (object) array(
      'name' => 'term' . $i,
      'vid' => 1,
    );
    taxonomy_term_save($term);
    $terms[] = $term->tid;
  }
  FeedsPlugin::loadMappers();
  $entity = new stdClass();
  $target = 'field_tags';
  $mapping = array(
    'term_search' => FEEDS_TAXONOMY_SEARCH_TERM_ID,
    'language' => LANGUAGE_NONE,
  );
  $source = FeedsSource::instance('tmp', 0);
  taxonomy_feeds_set_target($source, $entity, $target, $terms, $mapping);
  $this
    ->assertEqual(count($entity->field_tags[LANGUAGE_NONE]), 10);

  // 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);
}