X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=t%2FCreators.t;h=b1206af16a450c0bcd633bc2aeedb76baaa41422;hb=0fd2a8d19024ff4b8903db16a7befd4a62a2f57c;hp=720aa2cf723c5bcef48932022e1e02b046ef8b39;hpb=e81cbd7fe0064519fa86f96b2dc4a7800b5e3c67;p=koha-ffzg.git diff --git a/t/Creators.t b/t/Creators.t index 720aa2cf72..b1206af16a 100755 --- a/t/Creators.t +++ b/t/Creators.t @@ -1,21 +1,29 @@ #!/usr/bin/perl # -# This Koha test module is a stub! -# Add more tests here!!! +# This module will excercise pdf creation routines +# +# When run with KEEP_PDF enviroment variable it will keep +# test.pdf for manual inspection. This can be used to verify +# that ttf font configuration is complete like: +# +# KEEP_PDF=1 KOHA_CONF=/etc/koha/sites/srvgit/koha-conf.xml prove t/Creators.t +# +# sample of utf-8 text, font name and type will be on bottom of second page use strict; use warnings; -use Test::More tests => 15; +use File::Temp qw/ tempfile /; +use Test::More tests => 41; BEGIN { use_ok('C4::Creators'); - use_ok('C4::Creators::PDF'); + use_ok('C4::Creators::PDF', qw( Init Add Bookmark Compress Font FontSize Page StrWidth Text End )); } -my $pdf_creator = C4::Creators::PDF->new('test.pdf' => '', InitVars => 0); +my $pdf_creator = C4::Creators::PDF->new(InitVars => 0); ok($pdf_creator, "testing new() works"); -if (-e 'test.pdf') { +if (-e $pdf_creator->{filename}) { pass('testing pdf file created'); } else { @@ -34,12 +42,43 @@ $pdf_creator->FontSize(); # Reset font size before testing text width etc below ok($pdf_creator->Page(), "testing Page() works"); -is($pdf_creator->StrWidth("test", "H", 12), '19.344', "testing StrWidth() returns correct point width"); +my $expected_width; +my $expected_offset; +if (C4::Context->config('ttf')) { + $expected_width = '23.044921875'; + $expected_offset = '33.044921875'; +} else { + $expected_width = '19.344'; + $expected_offset = '29.344'; +} + +is($pdf_creator->StrWidth("test", "H", 12), $expected_width, "testing StrWidth() returns correct point width"); @result = $pdf_creator->Text(10, 10, "test"); is($result[0], '10', "testing Text() writes from a given x-value"); -is($result[1], '29.344', "testing Text() writes to the correct x-value"); +is($result[1], $expected_offset, "testing Text() writes to the correct x-value"); -ok($pdf_creator->End(), "testing End() works"); +my $font_types = C4::Creators::Lib::get_font_types(); +isa_ok( $font_types, 'ARRAY', 'get_font_types' ); -unlink 'test.pdf'; +my $y = 50; +foreach my $font ( @$font_types ) { + ok( $pdf_creator->Font( $font->{type} ), 'Font ' . $font->{type} ); + ok( $pdf_creator->Text(10, $y, "\x{10C}evap\x{10D}i\x{107} " . $font->{name} . ' - ' . $font->{type} ), 'Text ' . $font->{name}); + $y += $pdf_creator->FontSize() * 1.2; +} + +SKIP: { + skip "Skipping because without proper fonts these two tests fail", + 2 if ! $ENV{KOHA_CONF}; + + my ($fh, $filename) = tempfile(); + open( $fh, '>', $filename ); + select $fh; + + ok($pdf_creator->End(), "testing End() works"); + + close($fh); + ok( -s $filename , "test file $filename created OK" ); + unlink $filename unless $ENV{KEEP_PDF}; +}