Subject: | [PATCH] Add tests which actually test PDF::FromHTML can render various HTML files |
This patch (against 0.26) adds several tests against PDF::FromHTML, to
check that it can successfully render a number of simple HTML files.
The maintainers of this module may be interested to note that one
warning and one failure emerge from these simple tests. I will open a
separate bug report for the failure.
Subject: | 0001-Add-a-test-that-attempts-to-render-some-PDFs-from-HT.patch |
diff --git a/t/10_simple_files.t b/t/10_simple_files.t
new file mode 100755
index 0000000..7ab08e3
--- /dev/null
+++ b/t/10_simple_files.t
@@ -0,0 +1,46 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+my @files;
+
+BEGIN {
+ @files = qw(
+ simple_p.html
+ simple_table.html
+ simple_no_head.html
+ simple_entities.html
+ simple_table_br.html
+ );
+}
+
+use Test::More tests => 1 + (scalar(@files) * 5);
+use Test::Exception;
+use File::Spec;
+use FindBin;
+
+use_ok('PDF::FromHTML');
+
+for my $file (@files) {
+ diag("Processing $file");
+ my $pdf;
+ lives_ok {
+ $pdf = PDF::FromHTML->new( encoding => 'utf-8' );
+ } 'Created PDF::FromHTML object';
+
+ lives_ok {
+ $pdf->load_file(
+ File::Spec->catfile($FindBin::Bin, $file)
+ );
+ } "Loaded $file";
+
+ lives_ok {
+ $pdf->convert;
+ } 'Converted to PDF';
+
+ my $output;
+ lives_ok {
+ $pdf->write_file(\$output);
+ } 'Written output to SCALAR';
+
+ ok(length($output), 'Output scalar contains data');
+}
diff --git a/t/simple_entities.html b/t/simple_entities.html
new file mode 100644
index 0000000..d2e300d
--- /dev/null
+++ b/t/simple_entities.html
@@ -0,0 +1,13 @@
+<html>
+ <head></head>
+<body>
+
+ <h2>Some HTML entities</h2>
+
+ <p>Let's try it again, Sam?</p>
+
+ <p>© 2009 Example.Com, no rights reserved.</p>
+
+</body>
+</html>
+
diff --git a/t/simple_no_head.html b/t/simple_no_head.html
new file mode 100644
index 0000000..119c374
--- /dev/null
+++ b/t/simple_no_head.html
@@ -0,0 +1,6 @@
+<html>
+ <!-- an example without any head elements -->
+ <body>
+ <p>Hello headless world!</p>
+ </body>
+</html>
diff --git a/t/simple_p.html b/t/simple_p.html
new file mode 100644
index 0000000..bb0c657
--- /dev/null
+++ b/t/simple_p.html
@@ -0,0 +1,8 @@
+<html>
+ <head>
+ <title>Hello world</title>
+ </head>
+ <body>
+ <p>Hello world!</p>
+ </body>
+</html>
diff --git a/t/simple_table.html b/t/simple_table.html
new file mode 100644
index 0000000..a4a6fca
--- /dev/null
+++ b/t/simple_table.html
@@ -0,0 +1,25 @@
+<html>
+ <head>
+ <title>Simple Table</title>
+ </head>
+<body>
+
+ <h2>Simple Table</h2>
+
+ <table>
+ <tr>
+ <th>Row:</th>
+ <td>Number One</td>
+ </tr>
+ <tr>
+ <th>Row:</th>
+ <td>Number Two</td>
+ </tr>
+ <tr>
+ <th>Thingy:</th>
+ <td>Blah</td>
+ </tr>
+ </table>
+
+</body>
+</html>
diff --git a/t/simple_table_br.html b/t/simple_table_br.html
new file mode 100644
index 0000000..72290ef
--- /dev/null
+++ b/t/simple_table_br.html
@@ -0,0 +1,13 @@
+<html>
+ <head></head>
+<body>
+
+ <table>
+ <tr>
+ <th>One Thing</th>
+ <td>One<br>Two</td>
+ </tr>
+ </table>
+
+</body>
+</html>
--
1.5.6.5