Debian Codegraph @

lib/HTML/FormHandler/Test.pm

raw
1 package HTML::FormHandler::Test;
2 # ABSTRACT: provides is_html method used in tests
3 $HTML::FormHandler::Test::VERSION = '0.410002';
4 use strict;
5 use warnings;
6 use base 'Test::Builder::Module';
7 use HTML::TreeBuilder;
8 use Test::Builder::Module;
9 our @EXPORT = ('is_html');
10 use Encode ('decode');
11
12
13 sub is_html {
14 my ( $got, $expected, $message ) = @_;
15 my $t1 = HTML::TreeBuilder->new;
16 my $t2 = HTML::TreeBuilder->new;
17
18 $got = decode('utf8', $got);
19 $expected = decode('utf8', $expected);
20 $t1->parse($got);
21 $t1->eof;
22 $t2->parse($expected);
23 $t2->eof;
24 my $out1 = $t1->as_XML;
25 my $out2 = $t2->as_XML;
26 $t1->delete;
27 $t2->delete;
28 my $tb = HTML::FormHandler::Test->builder;
29 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.410002
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