File: select.t

package info (click to toggle)
libhtml-formhandler-perl 0.40057-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,320 kB
  • ctags: 685
  • sloc: perl: 8,849; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 1,178 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use strict;
use warnings;
use Test::More;

{
    package Test::Field::MyComp;
    use HTML::FormHandler::Moose;
    extends 'HTML::FormHandler::Field::Compound';

    has_field 'flim' => ( type => 'Select', options_method => \&options_flim );
    has_field 'flam' => ( type => 'Multiple', options_method => \&options_flam );
    has_field 'flot';

    sub options_flim {
        my $self = shift;
        return [ { value => 1, label => 'one' }, { value => 2, label => 'two' } ];
    }

    sub options_flam {
        my $self = shift;
        return [ { value => 1, label => 'red' }, { value => 2, label => 'blue' } ];
    }

}

{
    package Test::Form;
    use HTML::FormHandler::Moose;
    extends 'HTML::FormHandler';

    has '+field_name_space' => ( default => sub { [ 'Test::Field' ] } );
    has_field 'floo' => ( type => 'MyComp' );
    has_field 'ploot';

}

my $form = Test::Form->new;
ok( $form, 'form built' );
my $flim_options = $form->field('floo.flim')->options;
is( scalar @$flim_options, 2, 'right number of flim options' );
my $flam_options = $form->field('floo.flam')->options;
is( scalar @$flam_options, 2, 'right number of flam options' );

done_testing;