File Coverage

blib/lib/HTML/FormHandler/Test.pm
Criterion Covered Total %
statement 18 33 54.5
branch n/a
condition n/a
subroutine 6 7 85.7
pod 0 1 0.0
total 24 41 58.5


line stmt bran cond sub pod time code
1             package HTML::FormHandler::Test;
2             # ABSTRACT: provides is_html method used in tests
3 52     52   1724229 use strict;
  52         126  
  52         2486  
4 52     52   293 use warnings;
  52         105  
  52         2095  
5 52     52   294 use base 'Test::Builder::Module';
  52         100  
  52         10257  
6 52     52   82775 use HTML::TreeBuilder;
  52         2892677  
  52         865  
7 52     52   2614 use Test::Builder::Module;
  52         116  
  52         677  
8             our @EXPORT = ('is_html');
9 52     52   87571 use Encode ('decode');
  52         949955  
  52         15365  
10              
11              
12             sub is_html {
13 0     0 0   my ( $got, $expected, $message ) = @_;
14 0           my $t1 = HTML::TreeBuilder->new;
15 0           my $t2 = HTML::TreeBuilder->new;
16              
17 0           $got = decode('utf8', $got);
18 0           $expected = decode('utf8', $expected);
19 0           $t1->parse($got);
20 0           $t1->eof;
21 0           $t2->parse($expected);
22 0           $t2->eof;
23 0           my $out1 = $t1->as_XML;
24 0           my $out2 = $t2->as_XML;
25 0           $t1->delete;
26 0           $t2->delete;
27 0           my $tb = HTML::FormHandler::Test->builder;
28 0           return $tb->is_eq($out1, $out2, $message);
29             }
30              
31             1;
32              
33             __END__
34              
35             =pod
36              
37             =encoding UTF-8
38              
39             =head1 NAME
40              
41             HTML::FormHandler::Test - provides is_html method used in tests
42              
43             =head1 VERSION
44              
45             version 0.40057
46              
47             =head1 SYNOPSIS
48              
49             Simple 'is_html' method for testing form rendering against
50             an expected value without having to fuss with exactly matching
51             newlines and spaces. Uses L<HTML::TreeBuilder>, which uses
52             L<HTML::Parser>.
53              
54             See numerous examples in the 't/render' directory.
55              
56             use Test::More;
57             use HTML::FormHandler::Test;
58             use_ok('MyApp::Form::Basic');
59             my $form = MyApp::Form::Basic->new;
60             $form->process;
61             my $expected = '<form html>';
62             is_html( $form->render, $expected, 'form renders ok' );
63              
64             =head1 AUTHOR
65              
66             FormHandler Contributors - see HTML::FormHandler
67              
68             =head1 COPYRIGHT AND LICENSE
69              
70             This software is copyright (c) 2014 by Gerda Shank.
71              
72             This is free software; you can redistribute it and/or modify it under
73             the same terms as the Perl 5 programming language system itself.
74              
75             =cut