Debian Codegraph @

t/compound/empty.t

raw
1 use strict;
2 use warnings;
3 use Test::More;
4
5 # tests behavior for an empty compound field, where the compund field value
6 # is undef
7 {
8 {
9 package MyApp::Test::Compound;
10 use HTML::FormHandler::Moose;
11 extends 'HTML::FormHandler';
12
13 has_field 'comp_foo' => ( type => 'Compound', default => { one => 1, two => 2, three => 3 } );
14 has_field 'comp_foo.one';
15 has_field 'comp_foo.two';
16 has_field 'comp_foo.three';
17 has_field 'bar';
18 }
19
20 my $form = MyApp::Test::Compound->new;
21 ok( $form );
22 my $params = {
23 'comp_foo.one' => '',
24 'comp_foo.two' => '',
25 'comp_foo.three' => '',
26 'bar' => 'my_bar',
27 };
28 $form->process( params => $params );
29 my $value = $form->value;
30 my $exp_value = {
31 comp_foo => undef,
32 bar => 'my_bar',
33 };
34 is_deeply( $value, $exp_value, 'got expected value' );
35 }
36
37 # tests behavior for an empty compound field with 'not_nullable', where the
38 # compund field contains empty values
39 {
40 {
41 package MyApp::Test::Compound;
42 use HTML::FormHandler::Moose;
43 extends 'HTML::FormHandler';
44
45 has_field 'comp_foo' => ( type => 'Compound', not_nullable => 1 );
46 has_field 'comp_foo.one';
47 has_field 'comp_foo.two';
48 has_field 'comp_foo.three';
49 has_field 'bar';
50 }
51
52 my $form = MyApp::Test::Compound->new;
53 ok( $form );
54 my $params = {
55 'comp_foo.one' => '',
56 'comp_foo.two' => '',
57 'comp_foo.three' => '',
58 'bar' => 'my_bar',
59 };
60 $form->process( params => $params );
61 my $value = $form->value;
62 my $exp_value = {
63 comp_foo => {
64 one => undef,
65 two => undef,
66 three => undef,
67 },
68 bar => 'my_bar',
69 };
70 is_deeply( $value, $exp_value, 'got expected value' );
71 }
72
73
74 done_testing;