From 653c2cf3c79053554e19f2fa1fc0216b55fd51ca Mon Sep 17 00:00:00 2001
From: Alex Barth <alex_b@53995.no-reply.drupal.org>
Date: Wed, 28 Apr 2010 15:37:32 +0000
Subject: [PATCH] #624464 bangpound: Support tabs as delimiters.

---
 CHANGELOG.txt                            |  3 ++-
 feeds_defaults/tests/feeds_defaults.test | 17 ++++++++++++++---
 plugins/FeedsCSVParser.inc               | 12 ++++++++++--
 tests/feeds/nodes.tsv                    | 10 ++++++++++
 4 files changed, 36 insertions(+), 6 deletions(-)
 create mode 100644 tests/feeds/nodes.tsv

diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 1d04978d..899caa2c 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -4,6 +4,7 @@
 Feeds 6.x 1.0 Alpha 14, 2010-04-11
 ----------------------------------
 
+- #624464 bangpound: Support tabs as delimiters.
 - #758664: Fix regression introduced with #740962.
 
 Feeds 6.x 1.0 Alpha 13, 2010-03-30
@@ -12,7 +13,7 @@ Feeds 6.x 1.0 Alpha 13, 2010-03-30
 - #622932 pounard: Fix SQL capitalization.
 - #622932 pounard: Fix non-standard SQL (PostgreSQL compatibility)
 - #705872 Scott Reynolds: Added HTTPFetcher autodiscovery
-- #740962 alex_b: Fix FileFetcher Attached to Feed Node, Upload Field Not Saving 
+- #740962 alex_b: Fix FileFetcher Attached to Feed Node, Upload Field Not Saving
   File Path.
 - #754938 Monkey Master: FeedsCSVParser.inc uses strtolower() while parsing
   UTF-8 files.
diff --git a/feeds_defaults/tests/feeds_defaults.test b/feeds_defaults/tests/feeds_defaults.test
index 3a0029c0..17e0e4d5 100644
--- a/feeds_defaults/tests/feeds_defaults.test
+++ b/feeds_defaults/tests/feeds_defaults.test
@@ -332,10 +332,8 @@ class FeedsDefaultsNodeTestCase extends FeedsDefaultsTestCase {
     $this->drupalPost('import/node/import', array(), 'Import');
     $this->assertText('Created 79 Story nodes.');
 
-    // Disable.
+    // Disable, nodes should be still present.
     $this->disable('node');
-
-    // Nodes should be still present.
     $count = db_result(db_query("SELECT COUNT(*) FROM {feeds_node_item}"));
     $this->assertEqual($count, 79, 'Found correct number of items.');
     $count = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE type = 'story' AND status = 1 AND uid = 0"));
@@ -343,6 +341,19 @@ class FeedsDefaultsNodeTestCase extends FeedsDefaultsTestCase {
     // Do not filter on type intentionally. There shouldn't be more than 8 nodes total.
     $count = db_result(db_query("SELECT COUNT(*) FROM {node_revisions}"));
     $this->assertEqual($count, 79, 'Found correct number of items.');
+
+    // Import a tab separated file.
+    $this->enable('node');
+    $this->drupalPost('import/node/delete-items', array(), 'Delete');
+    $edit = array(
+      'files[feeds]' => $this->absolutePath() .'/tests/feeds/nodes.tsv',
+      'feeds[FeedsCSVParser][delimiter]' => "\t",
+    );
+    $this->drupalPost('import/node', $edit, 'Import');
+    $this->assertText('Created 8 Story nodes.');
+
+    // Disable before exiting test.
+    $this->disable('node');
   }
 }
 
diff --git a/plugins/FeedsCSVParser.inc b/plugins/FeedsCSVParser.inc
index 1e481e20..730726e8 100644
--- a/plugins/FeedsCSVParser.inc
+++ b/plugins/FeedsCSVParser.inc
@@ -86,7 +86,11 @@ class FeedsCSVParser extends FeedsParser {
       '#type' => 'select',
       '#title' => t('Delimiter'),
       '#description' => t('The character that delimits fields in the CSV file.'),
-      '#options' => drupal_map_assoc(array(',', ';')),
+      '#options'  => array(
+        ',' => ',',
+        ';' => ';',
+        "\t" => 'TAB',
+      ),
       '#default_value' => isset($source_config['delimiter']) ? $source_config['delimiter'] : ',',
     );
     return $form;
@@ -108,7 +112,11 @@ class FeedsCSVParser extends FeedsParser {
       '#type' => 'select',
       '#title' => t('Default delimiter'),
       '#description' => t('Default field delimiter.'),
-      '#options' => drupal_map_assoc(array(',', ';')),
+      '#options' => array(
+        ',' => ',',
+        ';' => ';',
+        "\t" => 'TAB',
+      ),
       '#default_value' => $this->config['delimiter'],
     );
     return $form;
diff --git a/tests/feeds/nodes.tsv b/tests/feeds/nodes.tsv
new file mode 100644
index 00000000..a3bf82fe
--- /dev/null
+++ b/tests/feeds/nodes.tsv
@@ -0,0 +1,10 @@
+Title	Body	published	GUID
+"Ut wisi enim ad minim veniam"	"Ut wisi enim ad minim veniam	quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat."	205200720	2
+"Duis autem vel eum iriure dolor"	"Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat	vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi."	428112720	3
+"Nam liber tempor"	"Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum."	1151766000	1
+Typi non habent""	"Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem."	1256326995	4
+"Lorem ipsum"	"Lorem ipsum dolor sit amet	consectetuer adipiscing elit	sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat."	1251936720	1
+"Investigationes demonstraverunt"	"Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius."	946702800	5
+"Claritas est etiam"	"Claritas est etiam processus dynamicus	qui sequitur mutationem consuetudium lectorum."	438112720	6
+"Mirum est notare"	"Mirum est notare quam littera gothica	quam nunc putamus parum claram	anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima."	1151066000	7
+"Eodem modo typi"	"Eodem modo typi	qui nunc nobis videntur parum clari	fiant sollemnes in futurum."	1201936720	8
\ No newline at end of file
-- 
GitLab