File Coverage

blib/lib/Test/Excel/Template/Plus.pm
Criterion Covered Total %
statement 15 35 42.8
branch 0 4 0.0
condition n/a
subroutine 5 6 83.3
pod 1 1 100.0
total 21 46 45.6


line stmt bran cond sub pod time code
1              
2             package Test::Excel::Template::Plus;
3              
4 1     1   34413 use strict;
  1         2  
  1         47  
5 1     1   6 use warnings;
  1         2  
  1         31  
6              
7 1     1   806 use Test::Deep ();
  1         14178  
  1         44  
8 1     1   11 use Test::Builder ();
  1         3  
  1         28  
9              
10 1     1   1174 use Spreadsheet::ParseExcel;
  1         61860  
  1         258  
11              
12             our $VERSION = '0.06';
13             our $AUTHORITY = 'cpan:STEVAN';
14              
15             require Exporter;
16             our @ISA = qw(Exporter);
17             our @EXPORT = qw(cmp_excel_files);
18              
19             # get the testing singleton ...
20             my $Test = Test::Builder->new;
21              
22             sub cmp_excel_files ($$;$) {
23 0     0 1   my ($file1, $file2, $msg) = @_;
24              
25 0           my $excel1 = Spreadsheet::ParseExcel::Workbook->Parse($file1);
26 0           my $excel2 = Spreadsheet::ParseExcel::Workbook->Parse($file2);
27              
28             ## NOTE:
29             ## Clean out some data bits that
30             ## dont seem to actually matter.
31             ## This is not perfect, so there
32             ## might be others when comparing
33             ## other xls files. This works for
34             ## me now though.
35              
36 0           foreach (qw/File Font Format _Pos/) {
37 0           $excel1->{$_} = undef;
38 0           $excel2->{$_} = undef;
39             }
40              
41 0           my $worksheet_count_1 = scalar @{$excel1->{Worksheet}};
  0            
42 0           my $worksheet_count_2 = scalar @{$excel2->{Worksheet}};
  0            
43              
44 0 0         if ($worksheet_count_1 != $worksheet_count_2) {
45 0           $Test->ok(0, $msg);
46 0           return;
47             }
48              
49 0           foreach my $i (0 .. $worksheet_count_1) {
50 0           foreach (qw/DefRowHeight _Pos/) {
51 0           $excel1->{Worksheet}->[$i]->{$_} = undef;
52 0           $excel2->{Worksheet}->[$i]->{$_} = undef;
53             }
54             }
55              
56 0 0         if (Test::Deep::eq_deeply($excel1, $excel2)) {
57 0           $Test->ok(1, $msg);
58             }
59             else {
60 0           $Test->ok(0, $msg);
61             }
62             }
63              
64              
65             1;
66              
67             __END__
68              
69             =pod
70              
71             =head1 NAME
72              
73             Test::Excel::Template::Plus - Testing module for use with Excel::Template::Plus
74              
75             =head1 SYNOPSIS
76              
77             use Test::More tests => 1;
78             use Test::Excel::Template::Plus;
79              
80             my $template = Excel::Template::Plus->new(
81             engine => 'TT',
82             template => 'test.tmpl',
83             config => { INCLUDE => [ '/templates' ] },
84             params => { ... }
85             );
86             $template->write_file('test.xls');
87              
88             # compare the file we just made with
89             # an existing example file ...
90             cmp_excel_files("test.xls", "t/xls/test.xls", '... the excel files matched');
91              
92             =head1 DISCLAIMER
93              
94             This module is woefully incomplete. It works for my B<very> basic purposes right
95             now, but it is surely going to need B<lots> or work in the future to make it
96             really usable.
97              
98             =head1 DESCRIPTION
99              
100             This module attempts to provide a means of testing and comparing dynamically
101             generated excel files. Currently it only supports comparing two excel files
102             for some approximation of strutural (values within cells) and visual (formatting
103             of said cells) equivalence.
104              
105             As a by product of the implementation, elements may get compared which don't
106             really need comparing, and things which do need comparing may be skipped. This
107             will get refined as time goes by and the module is used in more heavyweight
108             situations.
109              
110             =head1 FUNCTIONS
111              
112             =over 4
113              
114             =item B<cmp_excel_files($file1, $file2, $msg)>
115              
116             =back
117              
118             =head1 BUGS
119              
120             All complex software has bugs lurking in it, and this module is no
121             exception. If you find a bug please either email me, or add the bug
122             to cpan-RT.
123              
124             =head1 AUTHOR
125              
126             Stevan Little E<lt>stevan@cpan.orgE<gt>
127              
128             =head1 COPYRIGHT AND LICENSE
129              
130             Copyright 2007-2014 by Infinity Interactive, Inc.
131              
132             L<http://www.iinteractive.com>
133              
134             This library is free software; you can redistribute it and/or modify
135             it under the same terms as Perl itself.
136              
137             =cut