| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Test::More; |
| 4 |
use HTML::FormHandler::Test; |
| 5 |
|
| 6 |
{ |
| 7 |
package MyApp::Form::BlockComment; |
| 8 |
use HTML::FormHandler::Moose; |
| 9 |
extends 'HTML::FormHandler'; |
| 10 |
|
| 11 |
has '+name' => ( default => 'test_form' ); |
| 12 |
has_block 'comment' => ( tag => 'a', content => 'This is a comment from a block', |
| 13 |
class => ['comment' ] ); |
| 14 |
has_field 'foo' => ( tags => { before_element => '%comment' } ); |
| 15 |
has_field 'bar' => ( tags => { before_element => \&bar_element } ); |
| 16 |
|
| 17 |
sub bar_element { |
| 18 |
my $self = shift; |
| 19 |
return '<div>In a Sub</div>'; |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
my $form = MyApp::Form::BlockComment->new; |
| 24 |
ok( $form, 'form built' ); |
| 25 |
$form->process; |
| 26 |
my $rendered = $form->render; |
| 27 |
my $expected = |
| 28 |
'<form id="test_form" method="post"> |
| 29 |
<div class="form_messages"></div> |
| 30 |
<div> |
| 31 |
<label for="foo">Foo</label> |
| 32 |
<a class="comment">This is a comment from a block</a> |
| 33 |
<input id="foo" name="foo" type="text" value="" /> |
| 34 |
</div> |
| 35 |
<div> |
| 36 |
<label for="bar">Bar</label> |
| 37 |
<div>In a Sub</div> |
| 38 |
<input id="bar" name="bar" type="text" value="" /> |
| 39 |
</div> |
| 40 |
</form>'; |
| 41 |
|
| 42 |
is_html( $rendered, $expected, 'rendered as expected' ); |
| 43 |
|
| 44 |
done_testing; |