don't strip _ and - from linkAlias in the importer
authorTony Cook <tony@develop-help.com>
Thu, 24 Oct 2013 23:31:27 +0000 (10:31 +1100)
committerTony Cook <tony@develop-help.com>
Thu, 24 Oct 2013 23:31:27 +0000 (10:31 +1100)
site/cgi-bin/modules/BSE/Importer/Target/Article.pm
t/130-importer/020-article.t

index 9eda0de8b1673edb3eb4778423d737f1468b4db4..cf16d2ed18019cac9cde3871108c4d74bbd36d49 100644 (file)
@@ -6,7 +6,7 @@ use Articles;
 use Products;
 use OtherParents;
 
-our $VERSION = "1.007";
+our $VERSION = "1.008";
 
 =head1 NAME
 
@@ -406,7 +406,7 @@ sub xform_entry {
   }
 
   if (defined $entry->{linkAlias}) {
-    $entry->{linkAlias} =~ tr/A-Za-z0-9//cd;
+    $entry->{linkAlias} =~ tr/A-Za-z0-9_-//cd;
   }
 }
 
index 7b39f46d2503095282cfba61b51cee2ee8114d12..470e0b14d2ebeeb0dba2d9cde7abb4341bbaa77f 100644 (file)
@@ -9,7 +9,7 @@ BEGIN {
   eval "require Text::CSV;"
     or plan skip_all => "Text::CSV not available";
 }
-plan tests => 42;
+plan tests => 43;
 
 BEGIN {
   unshift @INC, File::Spec->catdir(BSE::Test::base_dir(), "cgi-bin", "modules");
@@ -90,6 +90,16 @@ skiplines=0
 source=CSV
 target=Article
 
+[import profile alias$when]
+map_id=1
+map_linkAlias=2
+map_title=3
+source=CSV
+target=Article
+code_field=id
+skiplines=0
+update_only=1
+use_codes=1
 CFG
 
 {
@@ -231,6 +241,20 @@ EOS
     is_deeply([ $imp->leaves ], [], "should be no updated articles");
   }
 
+  { # don't strip - and _ from linkAlias
+    my $fh = File::Temp->new;
+    my $filename = $fh->filename;
+    my $id = $testa->id;
+    print $fh <<EOS;
+$id,"alias-${when}_more",test,t101.jpg
+EOS
+    close $fh;
+    my $imp = BSE::Importer->new(cfg => $cfg, profile => "alias$when", callback => sub { note @_ });
+    $imp->process($filename);
+    my $testb = Articles->getByPkey($testa->id);
+    is($testb->linkAlias, "alias-${when}_more", "check alias set correctly");
+  }
+
   END {
     $testa->remove($cfg) if $testa;
   }