Lines 149-155
subtest 'Add same file in same category' => sub {
Link Here
|
149 |
}; |
149 |
}; |
150 |
|
150 |
|
151 |
subtest 'Test delete via UploadedFile as well as UploadedFiles' => sub { |
151 |
subtest 'Test delete via UploadedFile as well as UploadedFiles' => sub { |
152 |
plan tests => 8; |
152 |
plan tests => 10; |
153 |
|
153 |
|
154 |
# add temporary file with same name and contents (file4) |
154 |
# add temporary file with same name and contents (file4) |
155 |
my $upl = Koha::Uploader->new({ tmp => 1 }); |
155 |
my $upl = Koha::Uploader->new({ tmp => 1 }); |
Lines 160-166
subtest 'Test delete via UploadedFile as well as UploadedFiles' => sub {
Link Here
|
160 |
|
160 |
|
161 |
# testing delete via UploadedFiles (plural) |
161 |
# testing delete via UploadedFiles (plural) |
162 |
my $delete = Koha::UploadedFiles->search({ id => $id })->delete; |
162 |
my $delete = Koha::UploadedFiles->search({ id => $id })->delete; |
163 |
is( $delete, 1, 'Delete successful' ); |
163 |
isnt( $delete, "0E0", 'Delete successful' ); |
164 |
isnt( -e $path, 1, 'File no longer found after delete' ); |
164 |
isnt( -e $path, 1, 'File no longer found after delete' ); |
165 |
is( Koha::UploadedFiles->find( $id ), undef, 'Record also gone' ); |
165 |
is( Koha::UploadedFiles->find( $id ), undef, 'Record also gone' ); |
166 |
|
166 |
|
Lines 171-186
subtest 'Test delete via UploadedFile as well as UploadedFiles' => sub {
Link Here
|
171 |
my $kohaobj = Koha::UploadedFiles->find( $upl->result ); |
171 |
my $kohaobj = Koha::UploadedFiles->find( $upl->result ); |
172 |
$path = $kohaobj->full_path; |
172 |
$path = $kohaobj->full_path; |
173 |
$delete = $kohaobj->delete; |
173 |
$delete = $kohaobj->delete; |
174 |
is( $delete, 1, 'Delete successful' ); |
174 |
ok( $delete=~/^-?1$/, 'Delete successful' ); |
175 |
isnt( -e $path, 1, 'File no longer found after delete' ); |
175 |
isnt( -e $path, 1, 'File no longer found after delete' ); |
176 |
|
176 |
|
177 |
# add another record with TestBuilder, so file does not exist |
177 |
# add another record with TestBuilder, so file does not exist |
178 |
# catch warning |
178 |
# catch warning |
179 |
my $upload01 = $builder->build({ source => 'UploadedFile' }); |
179 |
my $upload01 = $builder->build({ source => 'UploadedFile' }); |
180 |
warning_like { Koha::UploadedFiles->find( $upload01->{id} )->delete; } |
180 |
warning_like { $delete = Koha::UploadedFiles->find( $upload01->{id} )->delete; } |
181 |
qr/file was missing/, |
181 |
qr/file was missing/, |
182 |
'delete warns when file is missing'; |
182 |
'delete warns when file is missing'; |
|
|
183 |
ok( $delete=~/^-?1$/, 'Deleting record was successful' ); |
183 |
is( Koha::UploadedFiles->count, 4, 'Back to four uploads now' ); |
184 |
is( Koha::UploadedFiles->count, 4, 'Back to four uploads now' ); |
|
|
185 |
|
186 |
# add another one with TestBuilder and delete twice (file does not exist) |
187 |
$upload01 = $builder->build({ source => 'UploadedFile' }); |
188 |
my $kohaobj = Koha::UploadedFiles->find( $upload01->{id} ); |
189 |
$delete = $kohaobj->delete({ keep_file => 1 }); |
190 |
$delete = $kohaobj->delete({ keep_file => 1 }); |
191 |
ok( $delete =~ /^(0E0|-1)$/, 'Repeated delete unsuccessful' ); |
192 |
# NOTE: Koha::Object->delete does not return 0E0 (yet?) |
184 |
}; |
193 |
}; |
185 |
|
194 |
|
186 |
subtest 'Call search_term with[out] private flag' => sub { |
195 |
subtest 'Call search_term with[out] private flag' => sub { |
Lines 245-251
subtest 'Testing allows_add_by' => sub {
Link Here
|
245 |
}; |
254 |
}; |
246 |
|
255 |
|
247 |
subtest 'Testing delete_temporary' => sub { |
256 |
subtest 'Testing delete_temporary' => sub { |
248 |
plan tests => 6; |
257 |
plan tests => 9; |
249 |
|
258 |
|
250 |
# Add two temporary files: result should be 3 + 3 |
259 |
# Add two temporary files: result should be 3 + 3 |
251 |
Koha::Uploader->new({ tmp => 1 })->cgi; # add file6 and file7 |
260 |
Koha::Uploader->new({ tmp => 1 })->cgi; # add file6 and file7 |
Lines 270-284
subtest 'Testing delete_temporary' => sub {
Link Here
|
270 |
|
279 |
|
271 |
# Now call delete_temporary with 6, 5 and 0 |
280 |
# Now call delete_temporary with 6, 5 and 0 |
272 |
t::lib::Mocks::mock_preference('UploadPurgeTemporaryFilesDays', 6 ); |
281 |
t::lib::Mocks::mock_preference('UploadPurgeTemporaryFilesDays', 6 ); |
273 |
Koha::UploadedFiles->delete_temporary; |
282 |
my $delete = Koha::UploadedFiles->delete_temporary; |
|
|
283 |
ok( $delete =~ /^(-1|0E0)$/, 'Check return value with 6' ); |
274 |
is( Koha::UploadedFiles->search->count, 6, 'Delete with pref==6' ); |
284 |
is( Koha::UploadedFiles->search->count, 6, 'Delete with pref==6' ); |
275 |
|
285 |
|
276 |
# use override parameter |
286 |
# use override parameter |
277 |
Koha::UploadedFiles->delete_temporary({ override_pref => 5 }); |
287 |
$delete = Koha::UploadedFiles->delete_temporary({ override_pref => 5 }); |
|
|
288 |
ok( $delete =~ /^(2|-1)$/, 'Check return value with 5' ); |
278 |
is( Koha::UploadedFiles->search->count, 4, 'Delete with override==5' ); |
289 |
is( Koha::UploadedFiles->search->count, 4, 'Delete with override==5' ); |
279 |
|
290 |
|
280 |
t::lib::Mocks::mock_preference('UploadPurgeTemporaryFilesDays', 0 ); |
291 |
t::lib::Mocks::mock_preference('UploadPurgeTemporaryFilesDays', 0 ); |
281 |
Koha::UploadedFiles->delete_temporary; |
292 |
$delete = Koha::UploadedFiles->delete_temporary; |
|
|
293 |
ok( $delete =~ /^(-1|1)$/, 'Check return value with 0' ); |
282 |
is( Koha::UploadedFiles->search->count, 3, 'Delete with pref==0 makes 3' ); |
294 |
is( Koha::UploadedFiles->search->count, 3, 'Delete with pref==0 makes 3' ); |
283 |
is( Koha::UploadedFiles->search({ permanent => 1 })->count, 3, |
295 |
is( Koha::UploadedFiles->search({ permanent => 1 })->count, 3, |
284 |
'Still 3 permanent uploads' ); |
296 |
'Still 3 permanent uploads' ); |
285 |
- |
|
|