public function FeedsMapperTaxonomyTestCase::testSearchByName in Feeds 7.2
Tests searching taxonomy terms by name.
File
- tests/
feeds_mapper_taxonomy.test, line 166 - Contains FeedsMapperTaxonomyTestCase.
Class
- FeedsMapperTaxonomyTestCase
- Test case for taxonomy mapper mappers/taxonomy.inc.
Code
public function testSearchByName() {
$terms = array(
'Drupal',
'localization',
'localization client',
'localization server',
'open atrium',
'translation',
'translation server',
'Drupal planet',
);
$this
->setSettings('syndication', 'FeedsNodeProcessor', 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.');
}