You are here

public function FeedsMapperTaxonomyTest::testSearchByName in Feeds 8.2

Tests searching taxonomy terms by name.

File

lib/Drupal/feeds/Tests/FeedsMapperTaxonomyTest.php, line 158
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 testSearchByName() {
  $terms = array(
    'Drupal',
    'localization',
    'localization client',
    'localization server',
    'open atrium',
    'translation',
    'translation server',
    'Drupal planet',
  );
  $this
    ->setSettings('syndication', 'node', array(
    'skip_hash_check' => TRUE,
    'update_existing' => 2,
  ));
  $mappings = array(
    5 => array(
      'source' => 'tags',
      'target' => 'field_tags',
      'term_search' => 0,
    ),
  );
  $this
    ->addMappings('syndication', $mappings);
  $nid = $this
    ->createFeedNode('syndication', NULL, 'Syndication');
  $this
    ->assertText('Created 10 nodes.');

  // Check that terms we not auto-created.
  $this
    ->drupalGet('node/2');
  foreach ($terms as $term) {
    $this
      ->assertNoTaxonomyTerm($term);
  }
  $this
    ->drupalGet('node/3');
  $this
    ->assertNoTaxonomyTerm('Washington DC');

  // Change the mapping configuration.
  $this
    ->removeMappings('syndication', $mappings);

  // Turn on autocreate.
  $mappings[5]['autocreate'] = TRUE;
  $this
    ->addMappings('syndication', $mappings);
  $this
    ->drupalPost('node/' . $nid . '/import', array(), t('Import'));
  $this
    ->assertText('Updated 10 nodes.');
  $this
    ->drupalGet('node/2');
  foreach ($terms as $term) {
    $this
      ->assertTaxonomyTerm($term);
  }
  $this
    ->drupalGet('node/3');
  $this
    ->assertTaxonomyTerm('Washington DC');
  $names = db_query('SELECT name FROM {taxonomy_term_data}')
    ->fetchCol();
  $this
    ->assertEqual(count($names), 31, 'Found correct number of terms in the database.');

  // Run import again. This verifys that the terms we found by name.
  $this
    ->drupalPost('node/' . $nid . '/import', array(), t('Import'));
  $this
    ->assertText('Updated 10 nodes.');
  $names = db_query('SELECT name FROM {taxonomy_term_data}')
    ->fetchCol();
  $this
    ->assertEqual(count($names), 31, 'Found correct number of terms in the database.');
}