From: Tony Cook Date: Mon, 13 Jul 2015 13:14:04 +0000 (+1000) Subject: use the supplied name of the image file for working out the stored name X-Git-Url: http://git.imager.perl.org/bse.git/commitdiff_plain/9ef99d41ed96c72cdc4bfc843081c6492dd9c0e0 use the supplied name of the image file for working out the stored name previously only the full path was supplied, producing long stored filenames with the slashes in the path replaced by dashes --- diff --git a/MANIFEST b/MANIFEST index faf7de5c..9128dbd7 100644 --- a/MANIFEST +++ b/MANIFEST @@ -957,6 +957,7 @@ t/data/importer/product-simple.csv t/data/known_pod_issues.txt t/data/t101.jpg t/data/templates/gentest.tmpl +t/data/testdata.txt t/t000load.t t/t00smoke.t makes a request to most of the scripts t/tags/bse.cfg diff --git a/site/cgi-bin/modules/BSE/Importer/Target/Article.pm b/site/cgi-bin/modules/BSE/Importer/Target/Article.pm index 3f4743f6..f68781f8 100644 --- a/site/cgi-bin/modules/BSE/Importer/Target/Article.pm +++ b/site/cgi-bin/modules/BSE/Importer/Target/Article.pm @@ -6,7 +6,7 @@ use BSE::TB::Articles; use BSE::TB::Products; use BSE::TB::OtherParents; -our $VERSION = "1.011"; +our $VERSION = "1.012"; =head1 NAME @@ -259,7 +259,11 @@ sub row { die "File '$file' not found for image$image_index\n"; } - my %opts = ( file => $full_file ); + my %opts = + ( + file => $full_file, + display_name => $file, + ); for my $key (qw/alt name url storage/) { my $fkey = "image${image_index}_$key"; $entry->{$fkey} diff --git a/t/130-importer/020-article.t b/t/130-importer/020-article.t index 641e20eb..e3f8de90 100644 --- a/t/130-importer/020-article.t +++ b/t/130-importer/020-article.t @@ -9,7 +9,7 @@ BEGIN { eval "require Text::CSV;" or plan skip_all => "Text::CSV not available"; } -plan tests => 43; +plan tests => 44; BEGIN { unshift @INC, File::Spec->catdir(BSE::Test::base_dir(), "cgi-bin", "modules"); @@ -39,7 +39,7 @@ source=CSV target=Article update_only=1 sep_char=\\t -file_path=t +file_path=t/data ignore_missing=0 [import profile completefile$when] @@ -55,7 +55,7 @@ map_file1_requireUser=9 map_file1_notes=10 map_file1_hide_from_list=11 skiplines=0 -file_path=t +file_path=t/data ignore_missing=0 update_only=1 source=CSV @@ -129,7 +129,7 @@ CFG linkAlias\tbody\tfile1_file\timage1_file "alias$when"\t"This is the body text with multiple lines -Yes, multiple lines with CSV!"\tt00smoke.t\tdata/t101.jpg +Yes, multiple lines with CSV!"\ttestdata.txt\tt101.jpg EOS close $fh; my $imp = BSE::Importer->new(cfg => $cfg, profile => "simpleupdate$when", callback => sub { note @_ }); @@ -142,10 +142,12 @@ EOS is(-s $images[0]->full_filename, -s "t/data/t101.jpg", "check size matches source"); + cmp_ok($images[0]->image, '!~', 'data', "check we don't pass full path as basename"); + my @files = $testb->files; is(@files, 1, "should be 1 file"); - is($files[0]->displayName, "t00smoke.t", "check display name"); - is(-s $files[0]->full_filename, -s "t/t00smoke.t", "check size"); + is($files[0]->displayName, "testdata.txt", "check display name"); + is(-s $files[0]->full_filename, -s "t/data/testdata.txt", "check size"); } SKIP: @@ -153,7 +155,7 @@ EOS my $fh = File::Temp->new; my $filename = $fh->filename; print $fh <new(cfg => $cfg, profile => "completefile$when", callback => sub { note @_ }); @@ -163,7 +165,7 @@ EOS my ($file) = grep $_->name eq "test", $testb->files; ok($file, "found the file with name 'test'") or skip "File not found", 9; - is(-s $file->full_filename, -s "t/t00smoke.t", "check size"); + is(-s $file->full_filename, -s "t/data/testdata.txt", "check size"); is($file->displayName, "A Test File.txt", "displayName"); is($file->storage, "local", "storage"); is($file->description, "A test file from BSE", "description"); @@ -191,7 +193,7 @@ EOS or skip "File not found", 9; is($file->description, "New description", "description"); # other fields should be unchanged - is(-s $file->full_filename, -s "t/t00smoke.t", "check size"); + is(-s $file->full_filename, -s "t/data/testdata.txt", "check size"); is($file->displayName, "A Test File.txt", "displayName"); is($file->storage, "local", "storage"); is($file->forSale, 1, "forSale"); diff --git a/t/data/testdata.txt b/t/data/testdata.txt new file mode 100644 index 00000000..dc40faac --- /dev/null +++ b/t/data/testdata.txt @@ -0,0 +1 @@ +Sample file imported by tests in 130-importer/020-article.t