Debian Codegraph @

t/compound/select.t

raw
1 use strict;
2 use warnings;
3 use Test::More;
4
5 {
6 package Test::Field::MyComp;
7 use HTML::FormHandler::Moose;
8 extends 'HTML::FormHandler::Field::Compound';
9
10 has_field 'flim' => ( type => 'Select', options_method => \&options_flim );
11 has_field 'flam' => ( type => 'Multiple', options_method => \&options_flam );
12 has_field 'flot';
13
14 sub options_flim {
15 my $self = shift;
16 return [ { value => 1, label => 'one' }, { value => 2, label => 'two' } ];
17 }
18
19 sub options_flam {
20 my $self = shift;
21 return [ { value => 1, label => 'red' }, { value => 2, label => 'blue' } ];
22 }
23
24 }
25
26 {
27 package Test::Form;
28 use HTML::FormHandler::Moose;
29 extends 'HTML::FormHandler';
30
31 has '+field_name_space' => ( default => sub { [ 'Test::Field' ] } );
32 has_field 'floo' => ( type => 'MyComp' );
33 has_field 'ploot';
34
35 }
36
37 my $form = Test::Form->new;
38 ok( $form, 'form built' );
39 my $flim_options = $form->field('floo.flim')->options;
40 is( scalar @$flim_options, 2, 'right number of flim options' );
41 my $flam_options = $form->field('floo.flam')->options;
42 is( scalar @$flam_options, 2, 'right number of flam options' );
43
44 done_testing;