File: empty.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 (74 lines) | stat: -rw-r--r-- 1,879 bytes parent folder | download | duplicates (4)
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
63
64
65
66
67
68
69
70
71
72
73
74
use strict;
use warnings;
use Test::More;

# tests behavior for an empty compound field, where the compund field value
# is undef
{
    {
        package MyApp::Test::Compound;
        use HTML::FormHandler::Moose;
        extends 'HTML::FormHandler';

        has_field 'comp_foo' => ( type => 'Compound', default => { one => 1, two => 2, three => 3 } );
        has_field 'comp_foo.one';
        has_field 'comp_foo.two';
        has_field 'comp_foo.three';
        has_field 'bar';
    }

    my $form = MyApp::Test::Compound->new;
    ok( $form );
    my $params = {
        'comp_foo.one' => '',
        'comp_foo.two' => '',
        'comp_foo.three' => '',
        'bar' => 'my_bar',
    };
    $form->process( params => $params );
    my $value = $form->value;
    my $exp_value = {
        comp_foo => undef,
        bar => 'my_bar',
    };
    is_deeply( $value, $exp_value, 'got expected value' );
}

# tests behavior for an empty compound field with 'not_nullable', where the
# compund field contains empty values
{
    {
        package MyApp::Test::Compound;
        use HTML::FormHandler::Moose;
        extends 'HTML::FormHandler';

        has_field 'comp_foo' => ( type => 'Compound', not_nullable => 1 );
        has_field 'comp_foo.one';
        has_field 'comp_foo.two';
        has_field 'comp_foo.three';
        has_field 'bar';
    }

    my $form = MyApp::Test::Compound->new;
    ok( $form );
    my $params = {
        'comp_foo.one' => '',
        'comp_foo.two' => '',
        'comp_foo.three' => '',
        'bar' => 'my_bar',
    };
    $form->process( params => $params );
    my $value = $form->value;
    my $exp_value = {
        comp_foo => {
            one => undef,
            two => undef,
            three => undef,
        },
        bar => 'my_bar',
    };
    is_deeply( $value, $exp_value, 'got expected value' );
}


done_testing;