/t/render_html_attributes.t
text | 76 lines | 60 code | 16 blank | 0 comment | 0 complexity | 27389736c096b6bc98c92c3fd25939d3 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'); 13use_ok('HTML::FormHandler::Render::Table'); 14 15my $dir = File::ShareDir::dist_dir('HTML-FormHandler') . '/templates/'; 16ok( $dir, 'found template dir' ); 17 18{ 19 20 package Test::Form; 21 use HTML::FormHandler::Moose; 22 extends 'HTML::FormHandler'; 23 24 sub build_tt_template {'form.tt'} 25 sub build_tt_include_path { ['share/templates'] } 26 27 has_field 'foo' => ( css_class => 'schoen', style => 'bunt', title => 'MyTitle' ); 28 has_field 'bar' => ( html_attr => { arbitrary => 'something', title => 'AltTitle' } ); 29 30} 31 32my %results; 33{ 34 my $form 35 = Test::Form->new( css_class => 'beautifully', style => 'colorful' ); 36 $results{Widgets} = $form->render; 37} 38{ 39 my $form 40 = Test::Form->new( css_class => 'beautifully', style => 'colorful' ); 41 HTML::FormHandler::Render::WithTT->meta->apply($form); 42 $results{TT} = $form->render; 43} 44{ 45 my $form 46 = Test::Form->new( css_class => 'beautifully', style => 'colorful' ); 47 HTML::FormHandler::Render::Simple->meta->apply($form); 48 $results{Simple} = $form->render; 49} 50{ 51 my $form 52 = Test::Form->new( css_class => 'beautifully', style => 'colorful' ); 53 HTML::FormHandler::Render::Table->meta->apply($form); 54 $results{Table} = $form->render; 55} 56is( scalar( grep {$_} values %results ), 57 scalar keys %results, 58 'Both methods rendered' 59); 60 61while ( my ( $key, $res ) = each %results ) { 62 like( $res, qr/class="schoen"/, "$key Field got the class" ); 63 like( $res, qr/style="bunt"/, "$key Field got the style" ); 64 65 like( $res, qr/class="beautifully"/, "$key Form got the class" ); 66 like( $res, qr/style="colorful"/, "$key Form got the style" ); 67 68 like( $res, qr/arbitrary="something"/, "$key Field got the arbitrary attribute" ); 69 70 like( $res, qr/title="MyTitle"/, "$key Field got the title" ); 71 like( $res, qr/title="AltTitle"/, "$key Field got the title from html_attr" ); 72 73} 74 75done_testing(); 76