You are here

public function FeedsMapperTaxonomyTest::testSearchByID in Feeds 8.2

Tests mapping to taxonomy terms by tid.

File

lib/Drupal/feeds/Tests/FeedsMapperTaxonomyTest.php, line 221
Test case for taxonomy mapper mappers/taxonomy.inc.

Class

FeedsMapperTaxonomyTest
Class for testing Feeds <em>content</em> mapper.

Namespace

Drupal\feeds\Tests

Code

public function testSearchByID() {

  // Create 10 terms. The first one was created in setup.
  $tids = array(
    1,
  );
  foreach (range(2, 10) as $i) {
    $term = entity_create('taxonomy_term', array(
      'name' => 'term' . $i,
      'vid' => 'tags',
    ));
    $term
      ->save();
    $tids[] = $term
      ->id();
  }
  FeedsPlugin::loadMappers();
  $target = 'field_tags';
  $mapping = array(
    'term_search' => FEEDS_TAXONOMY_SEARCH_TERM_ID,
  );
  $entityNG = entity_create('node', array(
    'type' => 'article',
  ))
    ->getNGEntity();
  $entity = $entityNG
    ->getBCEntity();
  taxonomy_feeds_set_target(NULL, $entity, $target, $tids, $mapping);
  $this
    ->assertEqual(count($entityNG->field_tags), 10);

  // Test a second mapping with a bogus term id.
  taxonomy_feeds_set_target(NULL, $entity, $target, array(
    1234,
  ), $mapping);
  $this
    ->assertEqual(count($entityNG->field_tags), 10);
}