PageRenderTime 15ms CodeModel.GetById 10ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 0ms

/t/render_withtt.t

http://github.com/gshank/html-formhandler
text | 62 lines | 50 code | 12 blank | 0 comment | 0 complexity | 55aefee737abc8f176ff4f48a5ad59f7 MD5 | raw file
 1use strict;
 2use warnings;
 3use Test::More;
 4use File::ShareDir;
 5
 6BEGIN {
 7    plan skip_all => 'Install Template Toolkit to test Render::WithTT'
 8       unless eval { require Template };
 9}
10
11use_ok('HTML::FormHandler::Render::WithTT');
12use_ok('HTML::FormHandler::Render::Simple');
13
14my $dir = File::ShareDir::dist_dir('HTML-FormHandler') . '/templates/';
15ok( $dir, 'found template dir' );
16
17{
18    package Test::Form;
19    use HTML::FormHandler::Moose;
20    extends 'HTML::FormHandler';
21    #with 'HTML::FormHandler::Render::WithTT';
22
23    sub build_tt_template { 'form.tt' }
24    sub build_tt_include_path { ['share/templates'] }
25
26    has_field 'foo';
27    has_field 'bar';
28    has_field 'submit' => ( type => 'Submit' );
29
30}
31
32my $rendered_via_tt;
33{
34    my $form = Test::Form->new(name => 'test_tt');
35    HTML::FormHandler::Render::WithTT->meta->apply($form);
36    ok( $form, 'form builds' );
37    ok( $form->tt_include_path, 'tt include path' );
38    $rendered_via_tt = $form->tt_render;
39    ok($rendered_via_tt, 'form tt renders' );
40}
41
42SKIP: {
43    skip 'Install HTML::TreeBuilder to test TT Result', 3
44        unless eval { require HTML::TreeBuilder && $HTML::TreeBuilder::VERSION >= 3.23 };
45        # really old TreeBuilder versions might not work
46
47    my $rendered_via_widget;
48    {
49        my $form = Test::Form->new(name => 'test_tt');
50        HTML::FormHandler::Render::Simple->meta->apply($form);
51        ok( $form, 'form builds' );
52        $rendered_via_widget = $form->render;
53        ok($rendered_via_widget, 'form simple renders' );
54    }
55
56    my $widget = HTML::TreeBuilder->new_from_content($rendered_via_widget);
57    my $tt = HTML::TreeBuilder->new_from_content($rendered_via_tt);
58    is($widget->as_HTML, $tt->as_HTML,
59        "TT Rendering and Widget Rendering matches");
60};
61
62done_testing;