Lines 2-8
Link Here
|
2 |
|
2 |
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
4 |
use File::Temp qw/ tempdir /; |
4 |
use File::Temp qw/ tempdir /; |
5 |
use Test::More tests => 10; |
5 |
use Test::More tests => 11; |
6 |
use Test::Warn; |
6 |
use Test::Warn; |
7 |
|
7 |
|
8 |
use Test::MockModule; |
8 |
use Test::MockModule; |
Lines 11-16
use t::lib::TestBuilder;
Link Here
|
11 |
|
11 |
|
12 |
use C4::Context; |
12 |
use C4::Context; |
13 |
use Koha::Database; |
13 |
use Koha::Database; |
|
|
14 |
use Koha::DateUtils; |
14 |
use Koha::UploadedFile; |
15 |
use Koha::UploadedFile; |
15 |
use Koha::UploadedFiles; |
16 |
use Koha::UploadedFiles; |
16 |
use Koha::Uploader; |
17 |
use Koha::Uploader; |
Lines 41-46
our $uploads = [
Link Here
|
41 |
[ |
42 |
[ |
42 |
{ name => 'file5', cat => undef, size => 7000 }, |
43 |
{ name => 'file5', cat => undef, size => 7000 }, |
43 |
], |
44 |
], |
|
|
45 |
[ |
46 |
{ name => 'file6', cat => undef, size => 6500 }, |
47 |
{ name => 'file7', cat => undef, size => 6501 }, |
48 |
], |
44 |
]; |
49 |
]; |
45 |
|
50 |
|
46 |
# Redirect upload dir structure and mock File::Spec and CGI |
51 |
# Redirect upload dir structure and mock File::Spec and CGI |
Lines 239-244
subtest 'Testing allows_add_by' => sub {
Link Here
|
239 |
1, 'Patron is still allowed to add uploaded files' ); |
244 |
1, 'Patron is still allowed to add uploaded files' ); |
240 |
}; |
245 |
}; |
241 |
|
246 |
|
|
|
247 |
subtest 'Testing delete_temporary' => sub { |
248 |
plan tests => 7; |
249 |
|
250 |
# Add two temporary files: result should be 3 + 3 |
251 |
Koha::Uploader->new({ tmp => 1 })->cgi; # add file6 and file7 |
252 |
is( Koha::UploadedFiles->search->count, 6, 'Test starting count' ); |
253 |
is( Koha::UploadedFiles->search({ permanent => 1 })->count, 3, |
254 |
'Includes 3 permanent' ); |
255 |
|
256 |
# Move all permanents to today - 1 |
257 |
# Move temp 1 to today - 3, and temp 2,3 to today - 5 |
258 |
my $today = dt_from_string; |
259 |
$today->subtract( minutes => 2 ); # should be enough :) |
260 |
my $dt = $today->clone->subtract( days => 1 ); |
261 |
foreach my $rec ( Koha::UploadedFiles->search({ permanent => 1 }) ) { |
262 |
$rec->dtcreated($dt)->store; |
263 |
} |
264 |
my @recs = Koha::UploadedFiles->search({ permanent => 0 }); |
265 |
$dt = $today->clone->subtract( days => 3 ); |
266 |
$recs[0]->dtcreated($dt)->store; |
267 |
$dt = $today->clone->subtract( days => 5 ); |
268 |
$recs[1]->dtcreated($dt)->store; |
269 |
$recs[2]->dtcreated($dt)->store; |
270 |
|
271 |
# Now call delete_temporary with 0, 6, 5 and 1 (via override) |
272 |
t::lib::Mocks::mock_preference('Upload_PurgeTemporaryFiles_Days', 0 ); |
273 |
Koha::UploadedFiles->delete_temporary; |
274 |
is( Koha::UploadedFiles->search->count, 6, 'Delete with pref==0' ); |
275 |
|
276 |
t::lib::Mocks::mock_preference('Upload_PurgeTemporaryFiles_Days', 6 ); |
277 |
Koha::UploadedFiles->delete_temporary; |
278 |
is( Koha::UploadedFiles->search->count, 6, 'Delete with pref==6' ); |
279 |
|
280 |
t::lib::Mocks::mock_preference('Upload_PurgeTemporaryFiles_Days', 5 ); |
281 |
Koha::UploadedFiles->delete_temporary; |
282 |
is( Koha::UploadedFiles->search->count, 4, 'Delete with pref==5 makes 4' ); |
283 |
|
284 |
Koha::UploadedFiles->delete_temporary({ override_pref => 1 }); |
285 |
is( Koha::UploadedFiles->search->count, 3, 'Delete override==1 makes 3' ); |
286 |
is( Koha::UploadedFiles->search({ permanent => 1 })->count, 3, |
287 |
'Still 3 permanent uploads' ); |
288 |
}; |
289 |
|
242 |
# The end |
290 |
# The end |
243 |
$schema->storage->txn_rollback; |
291 |
$schema->storage->txn_rollback; |
244 |
|
292 |
|
245 |
- |
|
|