From 5fe509ca71d3fe71078a6576bdb439716d44d73c Mon Sep 17 00:00:00 2001
From: chilic <chilic@651738.no-reply.drupal.org>
Date: Tue, 17 Dec 2013 22:05:52 -0500
Subject: [PATCH] Issue #2149829 by chilic: Import/Update 0 value to text
 field.

---
 mappers/taxonomy.inc                 |  2 +-
 tests/feeds/taxonomy_empty_terms.csv |  6 ++++
 tests/feeds_mapper_taxonomy.test     | 46 ++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+), 1 deletion(-)
 create mode 100644 tests/feeds/taxonomy_empty_terms.csv

diff --git a/mappers/taxonomy.inc b/mappers/taxonomy.inc
index 02ac54e7..8e9abff4 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 00000000..5a62ebaf
--- /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 2c6dfb65..2951b583 100644
--- a/tests/feeds_mapper_taxonomy.test
+++ b/tests/feeds_mapper_taxonomy.test
@@ -298,6 +298,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.
    */
-- 
GitLab