|
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 => 13; |
5 |
use Test::More tests => 18; |
| 6 |
use Test::Warn; |
6 |
use Test::Warn; |
| 7 |
|
7 |
|
| 8 |
use Test::MockModule; |
8 |
use Test::MockModule; |
|
Lines 46-51
our $uploads = [
Link Here
|
| 46 |
{ name => 'file6', cat => undef, size => 6500 }, |
46 |
{ name => 'file6', cat => undef, size => 6500 }, |
| 47 |
{ name => 'file7', cat => undef, size => 6501 }, |
47 |
{ name => 'file7', cat => undef, size => 6501 }, |
| 48 |
], |
48 |
], |
|
|
49 |
#cheksum tests |
| 50 |
[ |
| 51 |
{ name => 'file8', cat => 'A', checksum => 0, size => 2000 }, |
| 52 |
], |
| 53 |
[ |
| 54 |
{ name => 'file9', cat => undef, checksum => 0, size => 5000 }, # temp without checksum |
| 55 |
], |
| 56 |
[ |
| 57 |
{ name => 'file3', cat => 'B', checksum => 0, size => 1000 }, #duplicate file without checksum |
| 58 |
], |
| 59 |
#path tests |
| 60 |
[ |
| 61 |
{ name => 'file10', dir => 'A/B', cat => 'A', size => 2000 }, |
| 62 |
], |
| 63 |
[ |
| 64 |
{ name => 'file11', dir => 'A/B', cat => undef, size => 3000 }, |
| 65 |
], |
| 49 |
]; |
66 |
]; |
| 50 |
|
67 |
|
| 51 |
# Redirect upload dir structure and mock C4::Context and CGI |
68 |
# Redirect upload dir structure and mock C4::Context and CGI |
|
Lines 327-332
subtest 'Testing download headers' => sub {
Link Here
|
| 327 |
is_deeply(\@pdf_head, \@pdf_expect,"Get inline pdf headers for pdf"); |
344 |
is_deeply(\@pdf_head, \@pdf_expect,"Get inline pdf headers for pdf"); |
| 328 |
is_deeply(\@not_head, \@not_expect,"Get download headers for non pdf"); |
345 |
is_deeply(\@not_head, \@not_expect,"Get download headers for non pdf"); |
| 329 |
}; |
346 |
}; |
|
|
347 |
|
| 348 |
subtest 'Not add file checksum to the uploaded filename' => sub { |
| 349 |
plan tests => 7; |
| 350 |
|
| 351 |
my $upl = Koha::Uploader->new({ |
| 352 |
category => $uploads->[$current_upload]->[0]->{cat}, |
| 353 |
checksum => 0, |
| 354 |
}); #add file8 |
| 355 |
my $cgi = $upl->cgi; |
| 356 |
my $res = $upl->result; |
| 357 |
is( $upl->err, undef, 'No errors reported' ); |
| 358 |
|
| 359 |
my $rec = Koha::UploadedFiles->find( $res ); |
| 360 |
is( $rec->filename, 'file8', 'Check file name' ); |
| 361 |
is( $rec->checksum, 0, 'Checksum false' ); |
| 362 |
my $path = $rec->full_path; |
| 363 |
is( -e $path, 1, 'File is found' ); |
| 364 |
my $fh = $rec->file_handle; |
| 365 |
is( ref($fh) eq 'IO::File' && $fh->opened, 1, 'Get returns a file handle' ); |
| 366 |
my $delete = $rec->delete; |
| 367 |
ok( $delete=~/^-?1$/, 'Delete successful' ); |
| 368 |
isnt( -e $path, 1, 'File no longer found after delete' ); |
| 369 |
}; |
| 370 |
|
| 371 |
subtest 'Temporary upload without checksum' => sub { |
| 372 |
plan tests => 5; |
| 373 |
|
| 374 |
my $upl = Koha::Uploader->new({ |
| 375 |
tmp => 1, |
| 376 |
checksum => 0, |
| 377 |
}); #add file9 |
| 378 |
my $cgi = $upl->cgi; |
| 379 |
is( $upl->count, 1, 'Upload 9 includes one temporary file' ); |
| 380 |
is( $upl->err, undef, 'No errors reported' ); |
| 381 |
|
| 382 |
my $rec = Koha::UploadedFiles->find( $upl->result ); |
| 383 |
is( $rec->checksum, 0, 'Checksum false' ); |
| 384 |
is( $rec->uploadcategorycode =~ /_upload$/, 1, 'Check category temp file' ); |
| 385 |
my $path = $rec->full_path; |
| 386 |
is( -e $path, 1, 'File is found' ); |
| 387 |
}; |
| 388 |
|
| 389 |
subtest 'Duplicate file without checksum' => sub { |
| 390 |
plan tests => 5; |
| 391 |
|
| 392 |
my $upl = Koha::Uploader->new({ |
| 393 |
category => $uploads->[$current_upload]->[0]->{cat}, |
| 394 |
checksum => 0, |
| 395 |
}); |
| 396 |
my $cgi = $upl->cgi; |
| 397 |
is( $upl->count, 1, 'Upload 10 successful' ); |
| 398 |
is( $upl->err, undef, 'No errors reported' ); |
| 399 |
|
| 400 |
my $rec = Koha::UploadedFiles->find( $upl->result ); |
| 401 |
is( $rec->filename, 'file3', 'Check file name' ); |
| 402 |
is( $rec->checksum, 0, 'Checksum false' ); |
| 403 |
my $e = $upl->err; |
| 404 |
isnt( $e->{file2}->{code}, Koha::Uploader::ERR_EXISTS, "Already exists error reported" ); |
| 405 |
}; |
| 406 |
|
| 407 |
subtest 'Add upload in dir' => sub { |
| 408 |
plan tests => 8; |
| 409 |
|
| 410 |
my $upl = Koha::Uploader->new({ |
| 411 |
category => $uploads->[$current_upload]->[0]->{cat}, |
| 412 |
dir => $uploads->[$current_upload]->[0]->{dir}, |
| 413 |
}); |
| 414 |
my $cgi = $upl->cgi; |
| 415 |
is( $upl->count, 1, 'Upload 10 successful' ); |
| 416 |
isnt( $upl->result, undef, 'Result is undefined' ); |
| 417 |
is( $upl->err, undef, 'No errors reported' ); |
| 418 |
|
| 419 |
my $rec = Koha::UploadedFiles->find( $upl->result ); |
| 420 |
is( $rec->dir, 'A/B', 'Check dir A/B' ); |
| 421 |
my $path = $rec->full_path; |
| 422 |
is( -e $path, 1, 'File is found' ); |
| 423 |
my $fh = $rec->file_handle; |
| 424 |
is( ref($fh) eq 'IO::File' && $fh->opened, 1, 'Get returns a file handle' ); |
| 425 |
my $delete = $rec->delete; |
| 426 |
ok( $delete=~/^-?1$/, 'Delete successful' ); |
| 427 |
isnt( -e $path, 1, 'File no longer found after delete' ); |
| 428 |
|
| 429 |
}; |
| 430 |
|
| 431 |
|
| 432 |
subtest 'Temporary upload in dir' => sub { |
| 433 |
plan tests => 4; |
| 434 |
|
| 435 |
my $upl = Koha::Uploader->new({ |
| 436 |
tmp => 1, |
| 437 |
dir => $uploads->[$current_upload]->[0]->{dir}, |
| 438 |
}); #add file9 |
| 439 |
my $cgi = $upl->cgi; |
| 440 |
is( $upl->err, undef, 'No errors reported' ); |
| 441 |
|
| 442 |
my $rec = Koha::UploadedFiles->find( $upl->result ); |
| 443 |
is( $rec->dir, 'A/B', 'Check dir' ); |
| 444 |
is( $rec->uploadcategorycode =~ /_upload$/, 1, 'Check category temp file' ); |
| 445 |
my $path = $rec->full_path; |
| 446 |
is( -e $path, 1, 'File is found' ); |
| 447 |
}; |
| 330 |
# The end |
448 |
# The end |
| 331 |
$schema->storage->txn_rollback; |
449 |
$schema->storage->txn_rollback; |
| 332 |
|
450 |
|
| 333 |
- |
|
|