|
Lines 36-41
our $uploads = [
Link Here
|
| 36 |
[ |
36 |
[ |
| 37 |
{ name => 'file4', cat => undef, size => 5000 }, # temp duplicate |
37 |
{ name => 'file4', cat => undef, size => 5000 }, # temp duplicate |
| 38 |
], |
38 |
], |
|
|
39 |
[ |
| 40 |
{ name => 'file5', cat => undef, size => 7000 }, # temp duplicate |
| 41 |
], |
| 39 |
]; |
42 |
]; |
| 40 |
|
43 |
|
| 41 |
# Redirect upload dir structure and mock File::Spec and CGI |
44 |
# Redirect upload dir structure and mock File::Spec and CGI |
|
Lines 48-54
$cgimod->mock( 'new' => \&newCGI );
Link Here
|
| 48 |
|
51 |
|
| 49 |
# Start testing |
52 |
# Start testing |
| 50 |
subtest 'Test01' => sub { |
53 |
subtest 'Test01' => sub { |
| 51 |
plan tests => 7; |
54 |
plan tests => 9; |
| 52 |
test01(); |
55 |
test01(); |
| 53 |
}; |
56 |
}; |
| 54 |
subtest 'Test02' => sub { |
57 |
subtest 'Test02' => sub { |
|
Lines 64-70
subtest 'Test04' => sub {
Link Here
|
| 64 |
test04(); |
67 |
test04(); |
| 65 |
}; |
68 |
}; |
| 66 |
subtest 'Test05' => sub { |
69 |
subtest 'Test05' => sub { |
| 67 |
plan tests => 5; |
70 |
plan tests => 6; |
| 68 |
test05(); |
71 |
test05(); |
| 69 |
}; |
72 |
}; |
| 70 |
subtest 'Test06' => sub { |
73 |
subtest 'Test06' => sub { |
|
Lines 85-90
sub test01 {
Link Here
|
| 85 |
# Delete existing records (for later tests) |
88 |
# Delete existing records (for later tests) |
| 86 |
$dbh->do( "DELETE FROM uploaded_files" ); |
89 |
$dbh->do( "DELETE FROM uploaded_files" ); |
| 87 |
|
90 |
|
|
|
91 |
# Check mocked directories |
| 92 |
is( Koha::UploadedFile->permanent_directory, $tempdir, |
| 93 |
'Check permanent directory' ); |
| 94 |
is( Koha::UploadedFile->temporary_directory, $tempdir, |
| 95 |
'Check temporary directory' ); |
| 96 |
|
| 88 |
my $upl = Koha::Upload->new({ |
97 |
my $upl = Koha::Upload->new({ |
| 89 |
category => $uploads->[$current_upload]->[0]->{cat}, |
98 |
category => $uploads->[$current_upload]->[0]->{cat}, |
| 90 |
}); |
99 |
}); |
|
Lines 143-153
sub test05 { # add temporary file with same name and contents, delete it
Link Here
|
| 143 |
is( $upl->count, 1, 'Upload 5 adds duplicate temporary file' ); |
152 |
is( $upl->count, 1, 'Upload 5 adds duplicate temporary file' ); |
| 144 |
my $id = $upl->result; |
153 |
my $id = $upl->result; |
| 145 |
my $r = $upl->get({ id => $id }); |
154 |
my $r = $upl->get({ id => $id }); |
| 146 |
my @d = $upl->delete({ id => $id }); |
155 |
|
| 147 |
is( $d[0], $r->{name}, 'Delete successful' ); |
156 |
# testing delete via UploadedFiles (plural) |
| 148 |
is( -e $r->{path}? 1: 0, 0, 'File no longer found after delete' ); |
157 |
my $delete = Koha::UploadedFiles->search({ id => $id })->delete; |
|
|
158 |
is( $delete, 1, 'Delete successful' ); |
| 159 |
isnt( -e $r->{path}, 1, 'File no longer found after delete' ); |
| 149 |
is( scalar $upl->get({ id => $id }), undef, 'Record also gone' ); |
160 |
is( scalar $upl->get({ id => $id }), undef, 'Record also gone' ); |
| 150 |
is( $upl->delete({ id => $id }), undef, 'Repeated delete failed' ); |
161 |
|
|
|
162 |
# testing delete via UploadedFile (singular) |
| 163 |
# Note that find returns a Koha::Object |
| 164 |
$upl = Koha::Upload->new({ tmp => 1 }); |
| 165 |
$upl->cgi; |
| 166 |
$id = $upl->result; |
| 167 |
my $kohaobj = Koha::UploadedFiles->find( $id ); |
| 168 |
my $name = $kohaobj->filename; |
| 169 |
my $path = $kohaobj->full_path; |
| 170 |
$delete = $kohaobj->delete; |
| 171 |
is( $delete, $name, 'Delete successful' ); |
| 172 |
isnt( -e $path, 1, 'File no longer found after delete' ); |
| 151 |
} |
173 |
} |
| 152 |
|
174 |
|
| 153 |
sub test06 { #some extra tests for get |
175 |
sub test06 { #some extra tests for get |