File: params_not_mentioned.t

package info (click to toggle)
libdata-formvalidator-perl 4.66-1%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 588 kB
  • ctags: 127
  • sloc: perl: 2,756; makefile: 2
file content (46 lines) | stat: -rw-r--r-- 1,095 bytes parent folder | download | duplicates (6)
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
use strict;
use Test::More;
use Data::FormValidator;
plan(tests => 5);

# Test that constrants can refer to fields that are not mentioned
# in 'required' or 'optional'

my $profile = {
    required    => [qw(foo)],
    optional    => [qw(bar)],
    constraints => {
        foo => {
            constraint  => sub {
                if( defined $_[0] && defined $_[1] ) {
                    return $_[0] eq $_[1];
                } else {
                    return;
                }
             },
            params      => [qw(foo baz)],
        },
    },
};
my $input = {
    foo => 'stuff',
    bar => 'other stuff',
    baz => 'stuff',
};

my $results = Data::FormValidator->check($input, $profile);
ok(! $results->has_invalid(), 'no_invalids' );
ok( $results->valid('foo'), 'foo valid');

{
    # with CGI object as input. 
    use CGI;
    my $q = CGI->new($input);
    my $results;
    eval { $results = Data::FormValidator->check($q, $profile); };
    is ($@, '', 'survived eval');
    ok(! $results->has_invalid(), 'no_invalids' );
    ok( $results->valid('foo'), 'foo valid');

}