File Coverage

blib/lib/HTML/FormHandler/Test.pm
Criterion Covered Total %
statement 33 33 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 40 41 97.5


line stmt bran cond sub pod time code
1             package HTML::FormHandler::Test;
2             # ABSTRACT: provides is_html method used in tests
3             $HTML::FormHandler::Test::VERSION = '0.40068';
4 57     57   3373013 use strict;
  57         159  
  57         1541  
5 57     57   298 use warnings;
  57         129  
  57         1508  
6 57     57   290 use base 'Test::Builder::Module';
  57         119  
  57         5165  
7 57     57   34689 use HTML::TreeBuilder;
  57         1416124  
  57         632  
8 57     57   2490 use Test::Builder::Module;
  57         147  
  57         662  
9             our @EXPORT = ('is_html');
10 57     57   36405 use Encode ('decode');
  57         480543  
  57         9884  
11              
12              
13             sub is_html {
14 191     191 0 6005 my ( $got, $expected, $message ) = @_;
15 191         1413 my $t1 = HTML::TreeBuilder->new;
16 191         59209 my $t2 = HTML::TreeBuilder->new;
17              
18 191         42343 $got = decode('utf8', $got);
19 191         11678 $expected = decode('utf8', $expected);
20 191         9579 $t1->parse($got);
21 191         496455 $t1->eof;
22 191         50947 $t2->parse($expected);
23 191         478064 $t2->eof;
24 191         45244 my $out1 = $t1->as_XML;
25 191         390931 my $out2 = $t2->as_XML;
26 191         364798 $t1->delete;
27 191         31577 $t2->delete;
28 191         28053 my $tb = HTML::FormHandler::Test->builder;
29 191         3516 return $tb->is_eq($out1, $out2, $message);
30             }
31              
32             1;
33              
34             __END__
35              
36             =pod
37              
38             =encoding UTF-8
39              
40             =head1 NAME
41              
42             HTML::FormHandler::Test - provides is_html method used in tests
43              
44             =head1 VERSION
45              
46             version 0.40068
47              
48             =head1 SYNOPSIS
49              
50             Simple 'is_html' method for testing form rendering against
51             an expected value without having to fuss with exactly matching
52             newlines and spaces. Uses L<HTML::TreeBuilder>, which uses
53             L<HTML::Parser>.
54              
55             See numerous examples in the 't/render' directory.
56              
57             use Test::More;
58             use HTML::FormHandler::Test;
59             use_ok('MyApp::Form::Basic');
60             my $form = MyApp::Form::Basic->new;
61             $form->process;
62             my $expected = '<form html>';
63             is_html( $form->render, $expected, 'form renders ok' );
64              
65             =head1 AUTHOR
66              
67             FormHandler Contributors - see HTML::FormHandler
68              
69             =head1 COPYRIGHT AND LICENSE
70              
71             This software is copyright (c) 2017 by Gerda Shank.
72              
73             This is free software; you can redistribute it and/or modify it under
74             the same terms as the Perl 5 programming language system itself.
75              
76             =cut