View | Details | Raw Unified | Return to bug 6874
Collapse All | Expand All

(-)a/cataloguing/value_builder/upload.pl (-3 / +3 lines)
Lines 26-33 use C4::Context; Link Here
26
use C4::Output;
26
use C4::Output;
27
use C4::UploadedFiles;
27
use C4::UploadedFiles;
28
28
29
my $upload_path = C4::Context->preference('uploadPath');
30
31
sub plugin_parameters {
29
sub plugin_parameters {
32
    my ( $dbh, $record, $tagslib, $i, $tabloop ) = @_;
30
    my ( $dbh, $record, $tagslib, $i, $tabloop ) = @_;
33
    return "";
31
    return "";
Lines 115-120 sub plugin { Link Here
115
            -size => 50,
113
            -size => 50,
116
        );
114
        );
117
115
116
        my $upload_path = C4::Context->preference('uploadPath');
118
        my $dirs_tree = [ {
117
        my $dirs_tree = [ {
119
            name => '/',
118
            name => '/',
120
            value => '/',
119
            value => '/',
Lines 137-143 sub plugin { Link Here
137
136
138
# Build a hierarchy of directories
137
# Build a hierarchy of directories
139
sub finddirs {
138
sub finddirs {
140
    my $base = shift || $upload_path;
139
    my $base = shift;
140
    my $upload_path = C4::Context->preference('uploadPath');
141
    my $found = 0;
141
    my $found = 0;
142
    my @dirs;
142
    my @dirs;
143
    my @files = glob("$base/*");
143
    my @files = glob("$base/*");
(-)a/t/db_dependent/UploadedFiles.t (-1 / +44 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use File::Temp qw/ tempdir /;
5
use Test::CGI::Multipart;
6
use Test::More tests => 11;
7
8
use C4::Context;
9
use C4::UploadedFiles;
10
11
# This simulates a multipart POST request with a file upload.
12
my $tcm = new Test::CGI::Multipart;
13
$tcm->upload_file(
14
    name => 'testfile',
15
    file => 'testfilename.txt',
16
    value => "This is the content of testfilename.txt",
17
);
18
my $cgi = $tcm->create_cgi;
19
20
# Save the value of uploadPath and set it to a temporary directory
21
my $uploadPath = C4::Context->preference('uploadPath');
22
my $tempdir = tempdir(CLEANUP => 1);
23
C4::Context->set_preference('uploadPath', $tempdir);
24
25
my $testfilename = $cgi->param('testfile');
26
my $testfile_fh = $cgi->upload('testfile');
27
my $id = C4::UploadedFiles::UploadFile($testfilename, '', $testfile_fh->handle);
28
ok($id, "File uploaded, id is $id");
29
30
my $file = C4::UploadedFiles::GetUploadedFile($id);
31
isa_ok($file, 'HASH', "GetUploadedFiles($id)");
32
foreach my $key (qw(id filename filepath dir)) {
33
    ok(exists $file->{$key}, "GetUploadedFile($id)->{$key} exists");
34
}
35
36
ok(-e $file->{filepath}, "File $file->{filepath} exists");
37
38
ok(C4::UploadedFiles::DelUploadedFile($id), "DelUploadedFile($id) returned true");
39
ok(! -e $file->{filepath}, "File $file->{filepath} does not exist anymore");
40
41
C4::Context->set_preference('uploadPath', $uploadPath);
42
43
is(C4::UploadedFiles::UploadFile($testfilename, '../', $testfile_fh->handle), undef, 'UploadFile with $dir containing ".." return undef');
44
is(C4::UploadedFiles::GetUploadedFile(), undef, 'GetUploadedFile without parameters returns undef');

Return to bug 6874