File: api.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 (62 lines) | stat: -rw-r--r-- 1,341 bytes parent folder | download
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use strict;
use warnings;
use Test::More;

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

    has '+use_fields_for_input_without_param' => ( default => 1 );
    has_field 'foo';
    has_field 'bar' => ( default => 2 );
    has_field 'moxy';
    has_field 'naffy' => ( type => 'Compound' );
    has_field 'naffy.one';
    has_field 'naffy.two' => ( default => 'two');

}

my $form = MyApp::Form::Test->new;
ok( $form );

# process with no params
$form->process( {} );
my $fif = $form->fif;
my $exp_fif = {
    foo => '',
    bar => 2,
    moxy => '',
    'naffy.one' => '',
    'naffy.two' => 'two',
};
is_deeply( $fif, $exp_fif, 'expected fif for non-validated' );

# process with only one param, others from fields
my $params = { foo => 1 };
$form->process( $params );
$fif = $form->fif;
$exp_fif = {
    foo => 1,
    bar => 2,
    moxy => '',
    'naffy.one' => '',
    'naffy.two' => 'two',
};
is_deeply( $fif, $exp_fif, 'got expected fill-in-form including defaults' );

# moxy && # naffy->{one} are missing because not validated, so not
# moved to value.
my $value = $form->value;
my $val_exp = {
    foo => 1,
    bar => 2,
    moxy => undef,
    naffy => {
        one => undef,
        two => 'two',
    },
};
is_deeply( $value, $val_exp, 'got expected value' );

done_testing;