Lines 4-9
use Modern::Perl;
Link Here
|
4 |
use File::Temp qw/ tempdir /; |
4 |
use File::Temp qw/ tempdir /; |
5 |
use Test::More tests => 13; |
5 |
use Test::More tests => 13; |
6 |
use Test::Warn; |
6 |
use Test::Warn; |
|
|
7 |
use Try::Tiny; |
7 |
|
8 |
|
8 |
use Test::MockModule; |
9 |
use Test::MockModule; |
9 |
use t::lib::Mocks; |
10 |
use t::lib::Mocks; |
Lines 171-177
subtest 'Test delete via UploadedFile as well as UploadedFiles' => sub {
Link Here
|
171 |
my $kohaobj = Koha::UploadedFiles->find( $upl->result ); |
172 |
my $kohaobj = Koha::UploadedFiles->find( $upl->result ); |
172 |
$path = $kohaobj->full_path; |
173 |
$path = $kohaobj->full_path; |
173 |
$delete = $kohaobj->delete; |
174 |
$delete = $kohaobj->delete; |
174 |
ok( $delete=~/^-?1$/, 'Delete successful' ); |
175 |
ok( $delete, 'Delete successful' ); |
175 |
isnt( -e $path, 1, 'File no longer found after delete' ); |
176 |
isnt( -e $path, 1, 'File no longer found after delete' ); |
176 |
|
177 |
|
177 |
# add another record with TestBuilder, so file does not exist |
178 |
# add another record with TestBuilder, so file does not exist |
Lines 180-195
subtest 'Test delete via UploadedFile as well as UploadedFiles' => sub {
Link Here
|
180 |
warning_like { $delete = Koha::UploadedFiles->find( $upload01->{id} )->delete; } |
181 |
warning_like { $delete = Koha::UploadedFiles->find( $upload01->{id} )->delete; } |
181 |
qr/file was missing/, |
182 |
qr/file was missing/, |
182 |
'delete warns when file is missing'; |
183 |
'delete warns when file is missing'; |
183 |
ok( $delete=~/^-?1$/, 'Deleting record was successful' ); |
184 |
ok( $delete, 'Deleting record was successful' ); |
184 |
is( Koha::UploadedFiles->count, 4, 'Back to four uploads now' ); |
185 |
is( Koha::UploadedFiles->count, 4, 'Back to four uploads now' ); |
185 |
|
186 |
|
186 |
# add another one with TestBuilder and delete twice (file does not exist) |
187 |
# add another one with TestBuilder and delete twice (file does not exist) |
187 |
$upload01 = $builder->build({ source => 'UploadedFile' }); |
188 |
$upload01 = $builder->build({ source => 'UploadedFile' }); |
188 |
$kohaobj = Koha::UploadedFiles->find( $upload01->{id} ); |
189 |
$kohaobj = Koha::UploadedFiles->find( $upload01->{id} ); |
189 |
$delete = $kohaobj->delete({ keep_file => 1 }); |
190 |
$delete = $kohaobj->delete({ keep_file => 1 }); |
190 |
$delete = $kohaobj->delete({ keep_file => 1 }); |
191 |
try { |
191 |
ok( $delete =~ /^(0E0|-1)$/, 'Repeated delete unsuccessful' ); |
192 |
$delete = $kohaobj->delete({ keep_file => 1 }); |
192 |
# NOTE: Koha::Object->delete does not return 0E0 (yet?) |
193 |
} catch { |
|
|
194 |
ok( $_->isa("DBIx::Class::Exception"), 'Repeated delete unsuccessful' ); |
195 |
} |
193 |
}; |
196 |
}; |
194 |
|
197 |
|
195 |
subtest 'Test delete_missing' => sub { |
198 |
subtest 'Test delete_missing' => sub { |
196 |
- |
|
|