You are here

public function FeedsMapperTaxonomyTestCase::testAllowedVocabularies in Feeds 7.2

Tests that only term references are added from allowed vocabularies.

File

tests/feeds_mapper_taxonomy.test, line 319
Contains FeedsMapperTaxonomyTestCase.

Class

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

Code

public function testAllowedVocabularies() {

  // Create a second vocabulary.
  $vocabulary = new stdClass();
  $vocabulary->name = 'Foo';
  $vocabulary->machine_name = 'foo';
  taxonomy_vocabulary_save($vocabulary);

  // Add a term to this vocabulary.
  $term1 = new stdClass();
  $term1->name = 'Foo1';
  $term1->vid = $vocabulary->vid;
  taxonomy_term_save($term1);

  // Add a term to the tags vocabulary.
  $term2 = new stdClass();
  $term2->name = 'Bar1';
  $term2->vid = 1;
  taxonomy_term_save($term2);
  FeedsPlugin::loadMappers();
  $entity = new stdClass();
  $target = 'field_tags';
  $terms = array(
    'Foo1',
    'Bar1',
  );
  $mapping = array(
    'term_search' => FEEDS_TAXONOMY_SEARCH_TERM_NAME,
    'language' => LANGUAGE_NONE,
  );
  $source = FeedsSource::instance('tmp', 0);
  taxonomy_feeds_set_target($source, $entity, $target, $terms, $mapping);

  // Assert that only the term 'Bar1' was set.
  $this
    ->assertEqual(count($entity->field_tags[LANGUAGE_NONE]), 1);
  $this
    ->assertEqual($term2->tid, $entity->field_tags[LANGUAGE_NONE][0]['tid']);
}