Debian Codegraph @

t/09poc02.t

raw
1 #! perl
2
3 use strict;
4 use warnings;
5 use Test::More tests => 4;
6
7 package POC::Report;
8
9 use base qw(Data::Report);
10
11 package POC::Report::Html;
12
13 use base qw(Data::Report::Plugin::Html);
14
15 sub start {
16 my $self = shift;
17 $self->_argcheck(3);
18 $self->{_title1} = shift;
19 $self->{_title2} = shift;
20 $self->{_title3} = shift;
21 $self->SUPER::start;
22 }
23
24 sub _top_heading {
25 my $self = shift;
26 $self->_print("<html>\n",
27 "<head>\n",
28 "<title>", $self->_html($self->{_title1}), "</title>\n",
29 '<link rel="stylesheet" href="css/', $self->get_style, '.css">', "\n",
30 "</head>\n",
31 "<body>\n",
32 "<p class=\"title\">", $self->_html($self->{_title1}), "</p>\n",
33 "<p class=\"subtitle\">", $self->_html($self->{_title2}), "<br>\n",
34 $self->_html($self->{_title3}), "</p>\n");
35 }
36
37 sub _std_stylist {
38 my ($rep, $row, $col) = @_;
39
40 return { line_after => 1 }
41 if $row eq "total" && !$col;
42 return;
43 }
44
45 sub finish {
46 my $self = shift;
47 $self->_argcheck(0);
48 $self->SUPER::finish;
49 $self->_print("</body>\n</html>\n");
50 }
51
52 package main;
53
54 my $rep = POC::Report::->create(type => "html");
55 isa_ok($rep, 'POC::Report::Html');
56
57 $rep->set_layout
58 ([ { name => "acct", title => "Acct", width => 6 },
59 { name => "desc", title => "Report", width => 40, align => "|" },
60 { name => "deb", title => "Debet", width => 10, align => "<" },
61 { name => "crd", title => "Credit", width => 10, align => ">" },
62 ]);
63
64 my $out = "";
65 $rep->set_output(\$out);
66 $rep->start(qw(Title_One Title_Two Title_Three_Left&Right));
67
68 is($rep->get_stylist, \&POC::Report::Html::_std_stylist, "CB: stylist");
69 is($rep->get_topheading, \&POC::Report::Html::_top_heading, "CB: heading");
70
71 $rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "normal" });
72 $rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "normal" });
73 $rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "normal" });
74 $rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "total" });
75 $rep->finish;
76 $rep->close;
77
78 my $ref; { undef $/; $ref = <DATA>; }
79 $ref =~ s/[\r\n]/\n/g;
80
81 is($out, $ref, "contents");
82
83 __DATA__
84 <html>
85 <head>
86 <title>Title_One</title>
87 <link rel="stylesheet" href="css/default.css">
88 </head>
89 <body>
90 <p class="title">Title_One</p>
91 <p class="subtitle">Title_Two<br>
92 Title_Three_Left&amp;Right</p>
93 <table class="main">
94 <tr class="head">
95 <th align="left" class="h_acct">Acct</th>
96 <th align="center" class="h_desc">Report</th>
97 <th align="left" class="h_deb">Debet</th>
98 <th align="right" class="h_crd">Credit</th>
99 </tr>
100 <tr class="r_normal">
101 <td align="left" class="c_acct">one</td>
102 <td align="center" class="c_desc">two</td>
103 <td align="left" class="c_deb">three</td>
104 <td align="right" class="c_crd">four</td>
105 </tr>
106 <tr class="r_normal">
107 <td align="left" class="c_acct">one</td>
108 <td align="center" class="c_desc">two</td>
109 <td align="left" class="c_deb">three</td>
110 <td align="right" class="c_crd">four</td>
111 </tr>
112 <tr class="r_normal">
113 <td align="left" class="c_acct">one</td>
114 <td align="center" class="c_desc">two</td>
115 <td align="left" class="c_deb">three</td>
116 <td align="right" class="c_crd">four</td>
117 </tr>
118 <tr class="r_total">
119 <td align="left" class="c_acct">one</td>
120 <td align="center" class="c_desc">two</td>
121 <td align="left" class="c_deb">three</td>
122 <td align="right" class="c_crd">four</td>
123 </tr>
124 </table>
125 </body>
126 </html>