diff --git a/mappers/taxonomy.inc b/mappers/taxonomy.inc index 02ac54e..8e9abff 100644 --- a/mappers/taxonomy.inc +++ b/mappers/taxonomy.inc @@ -143,7 +143,7 @@ function taxonomy_feeds_set_target($source, $entity, $target, $terms, $mapping = if ($tids = $name_query->propertyCondition('name', $term)->execute()) { $tid = key($tids['taxonomy_term']); } - elseif ($mapping['autocreate']) { + elseif ($mapping['autocreate'] && strlen(trim($term))) { $term = (object) array( 'name' => $term, 'vid' => key($cache['allowed_vocabularies'][$target]), diff --git a/tests/feeds/taxonomy_empty_terms.csv b/tests/feeds/taxonomy_empty_terms.csv new file mode 100644 index 0000000..5a62eba --- /dev/null +++ b/tests/feeds/taxonomy_empty_terms.csv @@ -0,0 +1,6 @@ +"guid","title","tags" +"1","Lorem Ipsum 1","term1" +"2","Lorem Ipsum 2","" +"3","Lorem Ipsum 3", +"4","Lorem Ipsum 4"," " +"5","Lorem Ipsum 5","0" diff --git a/tests/feeds_mapper_taxonomy.test b/tests/feeds_mapper_taxonomy.test index 2c6dfb6..2951b58 100644 --- a/tests/feeds_mapper_taxonomy.test +++ b/tests/feeds_mapper_taxonomy.test @@ -299,6 +299,52 @@ class FeedsMapperTaxonomyTestCase extends FeedsMapperTestCase { } /** + * Tests importing empty values + */ + public function testBlankSourceValues() { + // Create a CSV importer configuration. + $this->createImporterConfiguration('Node import from CSV', 'node'); + $this->setPlugin('node', 'FeedsFileFetcher'); + $this->setPlugin('node', 'FeedsCSVParser'); + $this->setSettings('node', 'FeedsNodeProcessor', array('bundle' => 'article')); + $this->setSettings('node', NULL, array('content_type' => '')); + $this->addMappings('node', array( + 0 => array( + 'source' => 'title', + 'target' => 'title', + ), + 1 => array( + 'source' => 'tags', + 'target' => 'field_tags', + 'term_search' => 0, + 'autocreate' => 1, + ), + 2 => array( + 'source' => 'guid', + 'target' => 'guid', + 'unique' => TRUE, + ), + )); + + // Verify that there are 5 nodes total. + $this->importFile('node', $this->absolutePath() . '/tests/feeds/taxonomy_empty_terms.csv'); + $this->assertText('Created 5 nodes'); + + // Make sure only two terms were added + $names = db_query('SELECT name FROM {taxonomy_term_data}')->fetchCol(); + $this->assertEqual(count($names), 2, 'Found correct number of terms in the database.'); + + // Make sure the correct terms were created + $terms = array( + 'term1', + '0', + ); + foreach ($terms as $term_name) { + $this->assertTrue(in_array($term_name, $names), 'Correct term created'); + } + } + + /** * Finds node style taxonomy term markup in DOM. */ public function assertTaxonomyTerm($term) {