|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Koha is free software; you can redistribute it and/or modify it |
| 6 |
# under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# Koha is distributed in the hope that it will be useful, but |
| 11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with Koha; if not, see <https://www.gnu.org/licenses>. |
| 17 |
|
| 18 |
use Modern::Perl; |
| 19 |
use File::Temp; |
| 20 |
|
| 21 |
use Test::NoWarnings; |
| 22 |
use Test::More tests => 4; |
| 23 |
|
| 24 |
use Test::MockModule; |
| 25 |
use Test::Exception; |
| 26 |
|
| 27 |
use t::lib::Mocks; |
| 28 |
|
| 29 |
use_ok('Koha::PDF::Loader'); |
| 30 |
|
| 31 |
subtest 'PDF loader tests' => sub { |
| 32 |
plan tests => 4; |
| 33 |
|
| 34 |
#Create a self-destructing temporary file |
| 35 |
my $tmpdir = File::Temp::tempdir( CLEANUP => 1 ); |
| 36 |
my ( $fh, $filename ) = File::Temp::tempfile( DIR => $tmpdir, SUFFIX => '.pdf' ); |
| 37 |
|
| 38 |
#Create a blank PDF template for testing purposes using temporary file |
| 39 |
my $template = PDF::API2->new(); |
| 40 |
$template->save($filename); |
| 41 |
|
| 42 |
my $to_string = Koha::PDF::Loader->get_method_name( { method => 'to_string' } ); |
| 43 |
my $from_string = Koha::PDF::Loader->get_method_name( { method => 'from_string' } ); |
| 44 |
is( $to_string, 'to_string', 'to_string method name correct' ); |
| 45 |
is( $from_string, 'from_string', 'from_string method name correct' ); |
| 46 |
|
| 47 |
#Load PDF object from PDF template |
| 48 |
my $pdf = Koha::PDF::Loader->load_pdf_from_template( { pdf_template => $filename } ); |
| 49 |
ok( $pdf, 'Koha::PDF::Loader loaded something' ); |
| 50 |
ok( $pdf->isa('PDF::API2'), 'PDF object is a PDF::API2 object' ); |
| 51 |
}; |
| 52 |
|
| 53 |
subtest 'PDF loader tests (legacy)' => sub { |
| 54 |
plan tests => 4; |
| 55 |
|
| 56 |
#Create a self-destructing temporary file |
| 57 |
my $tmpdir = File::Temp::tempdir( CLEANUP => 1 ); |
| 58 |
my ( $fh, $filename ) = File::Temp::tempfile( DIR => $tmpdir, SUFFIX => '.pdf' ); |
| 59 |
|
| 60 |
#Create a blank PDF template for testing purposes using temporary file |
| 61 |
my $template = PDF::API2->new(); |
| 62 |
$template->save($filename); |
| 63 |
|
| 64 |
#Test the use of deprecated function names, which will be automatically used for older versions of PDF::API2 |
| 65 |
Koha::PDF::Loader->set_method_name( { method => 'to_string', name_to_use => 'stringify' } ); |
| 66 |
Koha::PDF::Loader->set_method_name( { method => 'from_string', name_to_use => 'open_scalar' } ); |
| 67 |
|
| 68 |
my $to_string = Koha::PDF::Loader->get_method_name( { method => 'to_string' } ); |
| 69 |
my $from_string = Koha::PDF::Loader->get_method_name( { method => 'from_string' } ); |
| 70 |
is( $to_string, 'stringify', 'to_string method name correct' ); |
| 71 |
is( $from_string, 'open_scalar', 'from_string method name correct' ); |
| 72 |
|
| 73 |
#Load PDF object from PDF template |
| 74 |
my $pdf = Koha::PDF::Loader->load_pdf_from_template( { pdf_template => $filename } ); |
| 75 |
ok( $pdf, 'Koha::PDF::Loader loaded something using legacy method names' ); |
| 76 |
ok( $pdf->isa('PDF::API2'), 'PDF object is a PDF::API2 object' ); |
| 77 |
}; |