You are here

public function FeedsMapperTaxonomyTestCase::testInheritTaxonomy in Feeds 7.2

Same name and namespace in other branches
  1. 6 tests/feeds_mapper_taxonomy.test \FeedsMapperTaxonomyTestCase::testInheritTaxonomy()
  2. 7 tests/feeds_mapper_taxonomy.test \FeedsMapperTaxonomyTestCase::testInheritTaxonomy()

Tests inheriting taxonomy from the feed node.

File

tests/feeds_mapper_taxonomy.test, line 127
Contains FeedsMapperTaxonomyTestCase.

Class

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

Code

public function testInheritTaxonomy() {

  // Adjust importer settings.
  $this
    ->setSettings('syndication', NULL, array(
    'import_period' => FEEDS_SCHEDULE_NEVER,
  ));
  $this
    ->setSettings('syndication', NULL, array(
    'import_on_create' => FALSE,
  ));
  $this
    ->assertText('Do not import on submission');

  // Map feed node's taxonomy to feed item node's taxonomy.
  $mappings = array(
    5 => array(
      'source' => 'parent:taxonomy:tags',
      'target' => 'field_tags',
    ),
  );
  $this
    ->addMappings('syndication', $mappings);

  // Create feed node and add term term1.
  $langcode = LANGUAGE_NONE;
  $nid = $this
    ->createFeedNode('syndication', NULL, 'Syndication');
  $term = taxonomy_get_term_by_name('term1');
  $term = reset($term);
  $edit = array(
    'field_tags' . '[' . $langcode . '][]' => $term->tid,
  );
  $this
    ->drupalPost("node/{$nid}/edit", $edit, t('Save'));
  $this
    ->assertTaxonomyTerm($term->name);

  // Import nodes.
  $this
    ->drupalPost("node/{$nid}/import", array(), 'Import');
  $this
    ->assertText('Created 10 nodes.');
  $count = db_query("SELECT COUNT(*) FROM {taxonomy_index}")
    ->fetchField();

  // There should be one term for each node imported plus the term on the feed node.
  $this
    ->assertEqual(11, $count, 'Found correct number of tags for all feed nodes and feed items.');
}