Bug 9302: Use patron-title.inc
[koha.git] / t / Creators.t
blob6e825d63bb3ae98d47445efb926f241fd5bdbc96
1 #!/usr/bin/perl
3 # This module will excercise pdf creation routines
5 # When run with KEEP_PDF enviroment variable it will keep
6 # test.pdf for manual inspection. This can be used to verify
7 # that ttf font configuration is complete like:
9 # KEEP_PDF=1 KOHA_CONF=/etc/koha/sites/srvgit/koha-conf.xml prove t/Creators.t
11 # sample of utf-8 text, font name and type will be on bottom of second page
13 use strict;
14 use warnings;
16 use File::Temp qw/ tempfile /;
17 use Test::More tests => 41;
19 BEGIN {
20 use_ok('C4::Creators');
21 use_ok('C4::Creators::PDF');
24 my $pdf_creator = C4::Creators::PDF->new(InitVars => 0);
25 ok($pdf_creator, "testing new() works");
26 if (-e $pdf_creator->{filename}) {
27 pass('testing pdf file created');
29 else {
30 fail('testing pdf file created');
33 ok($pdf_creator->Add(""), "testing Add() works");
34 ok($pdf_creator->Bookmark({}), "testing Bookmark() works");
35 ok($pdf_creator->Compress(1), "testing Compress() works");
37 is($pdf_creator->Font("H"), "Ft1", "testing Font() works");
38 is($pdf_creator->FontSize(), '12', "testing FontSize() is set to 12 by default");
39 my @result = $pdf_creator->FontSize(14);
40 is($result[0], '14', "testing FontSize() can be set to a different value");
41 $pdf_creator->FontSize(); # Reset font size before testing text width etc below
43 ok($pdf_creator->Page(), "testing Page() works");
45 my $expected_width;
46 my $expected_offset;
47 if (C4::Context->config('ttf')) {
48 $expected_width = '23.044921875';
49 $expected_offset = '33.044921875';
50 } else {
51 $expected_width = '19.344';
52 $expected_offset = '29.344';
55 is($pdf_creator->StrWidth("test", "H", 12), $expected_width, "testing StrWidth() returns correct point width");
57 @result = $pdf_creator->Text(10, 10, "test");
58 is($result[0], '10', "testing Text() writes from a given x-value");
59 is($result[1], $expected_offset, "testing Text() writes to the correct x-value");
61 my $font_types = C4::Creators::Lib::get_font_types();
62 isa_ok( $font_types, 'ARRAY', 'get_font_types' );
64 my $y = 50;
65 foreach my $font ( @$font_types ) {
66 ok( $pdf_creator->Font( $font->{type} ), 'Font ' . $font->{type} );
67 ok( $pdf_creator->Text(10, $y, "\x{10C}evap\x{10D}i\x{107} " . $font->{name} . ' - ' . $font->{type} ), 'Text ' . $font->{name});
68 $y += $pdf_creator->FontSize() * 1.2;
71 SKIP: {
72 skip "Skipping because without proper fonts these two tests fail",
73 2 if ! $ENV{KOHA_CONF};
75 my ($fh, $filename) = tempfile();
76 open( $fh, '>', $filename );
77 select $fh;
79 ok($pdf_creator->End(), "testing End() works");
81 close($fh);
82 ok( -s $filename , "test file $filename created OK" );
83 unlink $filename unless $ENV{KEEP_PDF};