Bug 20081: Set inline headers for uploaded pdfs

To test:
1 - Edit a framework and add the 'upload/pl' plugin to the 856 field
2 - Attach a pdf to one record
3 - Attach a different type of file to another
(To attach, edit a record in the framework edited above and find the
 helper by the 856 field)
4 - Click the links on the record
5 - Verify the pdf opens inline
6 - Verify the other file does not
7 - prove t/db_dependent/Upload.t

Signed-off-by: Claire Gravely <claire.gravely@bsz-bw.de>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Nick Clemens 2018-01-23 20:21:57 +00:00 committed by Jonathan Druart
parent ef7805aa36
commit 6d150eaeca
2 changed files with 23 additions and 5 deletions

View File

@ -134,10 +134,17 @@ Will be extended by report 14282
sub httpheaders {
my ( $self ) = @_;
return (
'-type' => 'application/octet-stream',
'-attachment' => $self->filename,
);
if( $self->filename =~ /\.pdf$/ ) {
return (
'-type' => 'application/pdf',
'Content-Disposition' => 'inline; filename='.$self->filename,
);
} else {
return (
'-type' => 'application/octet-stream',
'-attachment' => $self->filename,
);
}
}
=head2 CLASS METHODS

View File

@ -2,7 +2,7 @@
use Modern::Perl;
use File::Temp qw/ tempdir /;
use Test::More tests => 12;
use Test::More tests => 13;
use Test::Warn;
use Test::MockModule;
@ -316,6 +316,17 @@ subtest 'Testing delete_temporary' => sub {
'Still 3 permanent uploads' );
};
subtest 'Testing download headers' => sub {
plan tests => 2;
my $test_pdf = Koha::UploadedFile->new({ filename => 'pdf.pdf', uploadcategorycode => 'B', filesize => 1000 });
my $test_not = Koha::UploadedFile->new({ filename => 'pdf.not', uploadcategorycode => 'B', filesize => 1000 });
my @pdf_expect = ( '-type'=>'application/pdf','Content-Disposition'=>'inline; filename=pdf.pdf' );
my @not_expect = ( '-type'=>'application/octet-stream','-attachment'=>'pdf.not' );
my @pdf_head = $test_pdf->httpheaders;
my @not_head = $test_not->httpheaders;
is_deeply(\@pdf_head, \@pdf_expect,"Get inline pdf headers for pdf");
is_deeply(\@not_head, \@not_expect,"Get download headers for non pdf");
};
# The end
$schema->storage->txn_rollback;