Bug 5327 added unit tests for C4/Creators/PDF.pm
authorJono Mingard <reason.koan@gmail.com>
Thu, 19 Jan 2012 01:31:57 +0000 (14:31 +1300)
committerPaul Poulain <paul.poulain@biblibre.com>
Tue, 31 Jan 2012 16:21:48 +0000 (17:21 +0100)
Signed-off-by: Chris Hall <chrish@catalyst.net.nz>
t/Creators.t

index 5264d32..720aa2c 100755 (executable)
@@ -6,9 +6,40 @@
 use strict;
 use warnings;
 
-use Test::More tests => 1;
+use Test::More tests => 15;
 
 BEGIN {
         use_ok('C4::Creators');
+        use_ok('C4::Creators::PDF');
 }
 
+my $pdf_creator = C4::Creators::PDF->new('test.pdf' => '', InitVars => 0);
+ok($pdf_creator, "testing new() works");
+if (-e 'test.pdf') {
+  pass('testing pdf file created');
+}
+else {
+  fail('testing pdf file created');
+}
+
+ok($pdf_creator->Add(""), "testing Add() works");
+ok($pdf_creator->Bookmark({}), "testing Bookmark() works");
+ok($pdf_creator->Compress(1), "testing Compress() works");
+
+is($pdf_creator->Font("H"), "Ft1", "testing Font() works");
+is($pdf_creator->FontSize(), '12', "testing FontSize() is set to 12 by default");
+my @result = $pdf_creator->FontSize(14);
+is($result[0], '14', "testing FontSize() can be set to a different value");
+$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");
+
+@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");
+
+ok($pdf_creator->End(), "testing End() works");
+
+unlink 'test.pdf';