PageRenderTime 39ms CodeModel.GetById 10ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 0ms

/t/reprender.t

http://github.com/gshank/html-formhandler
text | 38 lines | 32 code | 6 blank | 0 comment | 0 complexity | aaf3983218b5cee2b9614ecebfc88cd7 MD5 | raw file
 1use strict;
 2use warnings;
 3use Test::More;
 4
 5{
 6    package Test::Repeatable::Array;
 7    use HTML::FormHandler::Moose;
 8    extends 'HTML::FormHandler';
 9
10    has_field 'foo';
11    has_field 'my_array' => ( type => 'Repeatable', num_when_empty => 2 );
12    has_field 'my_array.contains' => ( type => 'Text' );
13    has_field 'my_rep' => ( type => 'Repeatable', 'num_when_empty' => 2 );
14    has_field 'my_rep.foo';
15    has_field 'bar';
16
17}
18
19my $form = Test::Repeatable::Array->new;
20my $rendered_array = $form->field('my_array')->render;
21like( $rendered_array, qr/my_array\.0/, 'renders my_array field' );
22my $rendered_rep = $form->field('my_rep')->render;
23like( $rendered_rep, qr/my_rep\.0/, 'renders my_rep field' );
24$form->process( params => {} );
25$rendered_array = $form->field('my_array')->render;
26like( $rendered_array, qr/my_array\.0/, 'renders my_array field' );
27$rendered_rep = $form->field('my_rep')->render;
28like( $rendered_rep, qr/my_rep\.0/, 'renders my_rep field' );
29
30$form->process( params => { foo => 'xxx', bar => 'yyy',
31   'my_array.0' => '', 'my_array.1' => '',
32   'my_rep.0.foo' => '', 'my_rep.1.foo' => '' } );
33$rendered_array = $form->field('my_array')->render;
34like( $rendered_array, qr/my_array\.0/, 'renders my_array field' );
35$rendered_rep = $form->field('my_rep')->render;
36like( $rendered_rep, qr/my_rep\.0/, 'renders my_rep field' );
37
38done_testing;