| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Test::More; |
| 4 |
use File::ShareDir; |
| 5 |
use HTML::TreeBuilder; |
| 6 |
use HTML::FormHandler::Test; |
| 7 |
|
| 8 |
BEGIN { |
| 9 |
plan skip_all => 'Install Template Toolkit to test Render::WithTT' |
| 10 |
unless eval { require Template }; |
| 11 |
} |
| 12 |
|
| 13 |
|
| 14 |
{ |
| 15 |
package Test::Form; |
| 16 |
use HTML::FormHandler::Moose; |
| 17 |
extends 'HTML::FormHandler'; |
| 18 |
with 'HTML::FormHandler::Render::WithTT' => |
| 19 |
{ -excludes => [ 'build_tt_template', 'build_tt_include_path' ] }; |
| 20 |
sub build_tt_template {'form/form22.tt'} |
| 21 |
sub build_tt_include_path { ['share/templates'] } |
| 22 |
|
| 23 |
has_field 'foo'; |
| 24 |
has_field 'opt_in' => ( type => 'Checkbox' ); |
| 25 |
has_field 'choose' => ( type => 'Select', default => 2 ); |
| 26 |
sub options_choose { |
| 27 |
return ( |
| 28 |
1 => 'apples', |
| 29 |
2 => 'oranges', |
| 30 |
3 => 'kiwi', |
| 31 |
); |
| 32 |
} |
| 33 |
has_field 'my_hidden' => ( type => 'Hidden' ); |
| 34 |
has_field 'submit' => ( type => 'Submit' ); |
| 35 |
} |
| 36 |
|
| 37 |
my $form = Test::Form->new; |
| 38 |
ok( $form, 'form builds' ); |
| 39 |
my $rendered = $form->tt_render; |
| 40 |
ok($rendered, 'form tt renders' ); |
| 41 |
my $expected = ' |
| 42 |
<form class="xxx www"> |
| 43 |
<div class="c23 a44"> |
| 44 |
<label>Foo</label><input class="c123 ty63" id="foo" name="foo" type="text" value="" /> |
| 45 |
</div><div class="x33 y55"> |
| 46 |
<label class="muha" for="opt_in">Opt in?</label><input class="v22 dg34" id="opt_in" name="opt_in" type="checkbox" value="1" /> |
| 47 |
</div> |
| 48 |
<div class="select p55"> |
| 49 |
<select class="sw11" id="choose" name="choose"> |
| 50 |
<option id="choose.0" value="1">apples</option> |
| 51 |
<option id="choose.1" selected="selected" value="2">oranges</option> |
| 52 |
<option id="choose.2" value="3">kiwi</option> |
| 53 |
</select> |
| 54 |
</div> |
| 55 |
<div classs="c23 a44"> |
| 56 |
<input class="ghty" id="submit" name="submit" type="submit" value="Save" /> |
| 57 |
</div> |
| 58 |
<input id="hid12" name="my_hidden" type="hidden" value="" /> |
| 59 |
</form> |
| 60 |
'; |
| 61 |
is_html( $rendered, $expected); |
| 62 |
|
| 63 |
done_testing; |