Bug 14197: TestBuilder - Remove the error on starting the transaction
[koha.git] / t / Creators.t
1 #!/usr/bin/perl
2 #
3 # This Koha test module is a stub!
4 # Add more tests here!!!
5
6 use strict;
7 use warnings;
8
9 use File::Temp qw/ tempfile  /;
10 use Test::More tests => 16;
11
12 BEGIN {
13         use_ok('C4::Creators');
14         use_ok('C4::Creators::PDF');
15 }
16
17 my $pdf_creator = C4::Creators::PDF->new(InitVars => 0);
18 ok($pdf_creator, "testing new() works");
19 if (-e $pdf_creator->{filename}) {
20   pass('testing pdf file created');
21 }
22 else {
23   fail('testing pdf file created');
24 }
25
26 ok($pdf_creator->Add(""), "testing Add() works");
27 ok($pdf_creator->Bookmark({}), "testing Bookmark() works");
28 ok($pdf_creator->Compress(1), "testing Compress() works");
29
30 is($pdf_creator->Font("H"), "Ft1", "testing Font() works");
31 is($pdf_creator->FontSize(), '12', "testing FontSize() is set to 12 by default");
32 my @result = $pdf_creator->FontSize(14);
33 is($result[0], '14', "testing FontSize() can be set to a different value");
34 $pdf_creator->FontSize(); # Reset font size before testing text width etc below
35
36 ok($pdf_creator->Page(), "testing Page() works");
37
38 my $expected_width;
39 my $expected_offset;
40 if (C4::Context->config('ttf')) {
41     $expected_width  = '23.044921875';
42     $expected_offset = '33.044921875';
43 } else {
44     $expected_width  = '19.344';
45     $expected_offset = '29.344';
46 }
47
48 is($pdf_creator->StrWidth("test", "H", 12), $expected_width, "testing StrWidth() returns correct point width");
49
50 @result = $pdf_creator->Text(10, 10, "test");
51 is($result[0], '10', "testing Text() writes from a given x-value");
52 is($result[1], $expected_offset, "testing Text() writes to the correct x-value");
53
54 my  ($fh, $filename) = tempfile();
55 open(  $fh, '>', $filename );
56 select $fh;
57
58 ok($pdf_creator->End(), "testing End() works");
59
60 close($fh);
61 ok( -s $filename , "test file $filename created OK" );
62 unlink $filename ;