Debian Codegraph @

t/render/html5_attributes.t

raw
1 use strict;
2 use warnings;
3 use Test::More;
4 use File::ShareDir;
5
6 BEGIN {
7 plan skip_all => 'Install Template Toolkit to test Render::WithTT'
8 unless eval { require Template };
9 }
10
11 use_ok('HTML::FormHandler::Render::WithTT');
12 use_ok('HTML::FormHandler::Render::Simple');
13 use_ok('HTML::FormHandler::Render::Table');
14
15 {
16
17 package Test::Form;
18 use HTML::FormHandler::Moose;
19 extends 'HTML::FormHandler';
20
21 has '+is_html5' => (default => 1);
22
23 has_field 'foo' => ( element_class => 'schoen', style => 'bunt', title => 'MyTitle', required => 1, maxlength=> 10 );
24 has_field 'bar' => ( element_attr => { arbitrary => 'something', title => 'AltTitle' } );
25 has_field 'range' => ( type => "Integer", range_start => 5, range_end => 10, html5_type_attr => 'tel' );
26 has_field 'email' => ( type => "Email");
27 has_field 'date' => ( type => "Date");
28 has_field 'money' => ( type => "Money");
29 }
30
31 {
32 package Test::Form::WithTT::Role;
33 use Moose::Role;
34 with 'HTML::FormHandler::Render::WithTT' =>
35 { -excludes => [ 'build_tt_template', 'build_tt_include_path' ] };
36 sub build_tt_template {'form/form.tt'}
37 sub build_tt_include_path { ['share/templates'] }
38 }
39
40 my %results;
41 {
42 my $form
43 = Test::Form->new( form_element_attr => { class => 'beautifully' }, style => 'colorful' );
44 $results{Widgets} = $form->render;
45 }
46 {
47 my $form
48 = Test::Form->new_with_traits( traits => ['Test::Form::WithTT::Role'],
49 form_element_attr => { class => 'beautifully' }, style => 'colorful' );
50 $results{TT} = $form->tt_render;
51 }
52 {
53 my $form
54 = Test::Form->new_with_traits( traits => ['HTML::FormHandler::Render::Simple'],
55 form_element_attr => { class => 'beautifully' }, style => 'colorful' );
56 $results{Simple} = $form->render;
57 }
58 {
59 my $form
60 = Test::Form->new_with_traits( traits => ['HTML::FormHandler::Render::Table'],
61 form_element_attr => { class => 'beautifully' }, style => 'colorful' );
62 $results{Table} = $form->render;
63 }
64 is( scalar( grep {$_} values %results ),
65 scalar keys %results,
66 'Both methods rendered'
67 );
68
69 while ( my ( $key, $res ) = each %results ) {
70 like( $res, qr/class="schoen"/, "$key Field got the class" );
71 like( $res, qr/style="bunt"/, "$key Field got the style" );
72
73 like( $res, qr/class="beautifully"/, "$key Form got the class" );
74 like( $res, qr/style="colorful"/, "$key Form got the style" );
75
76 like( $res, qr/arbitrary="something"/, "$key Field got the arbitrary attribute" );
77
78 like( $res, qr/title="MyTitle"/, "$key Field got the title" );
79 like( $res, qr/title="AltTitle"/, "$key Field got the title from element_attr" );
80
81 like( $res, qr/required="required"/, "$key Form got the html5 required" );
82 like( $res, qr/input type="number" name="money"/, "$key Form got the html5 type" );
83 like( $res, qr/input type="date" name="date"/, "$key Form got the html5 type" );
84 like( $res, qr/input type="email" name="email"/, "$key Form got the html5 type" );
85 like( $res, qr/input type="tel" name="range"/, "$key Form got the html5 type" );
86 like( $res, qr/max="10"/, "$key Form got the html5 max attribute" );
87 like( $res, qr/min="5"/, "$key Form got the html5 min attribute" );
88
89 }
90
91 done_testing();