File: profile_checking.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 (47 lines) | stat: -rw-r--r-- 1,299 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
47

use strict;

$^W = 1;

use Test::More tests => 1;

use Data::FormValidator;

my $input_profile = {
               required => [ qw( email_1  email_ok) ],
               optional => ['filled','not_filled'],
               constraint_regexp_map => {
                      '/^email/'  => "email",
               },
               constraints => {
                 not_filled   => 'phone',
               },
               missing_optional_valid => 1,       
               bad_key_which_should_trigger_error=>1,
               another_bad_key_which_should_trigger_error=>1,
            };

my $validator = new Data::FormValidator({default => $input_profile});

my $input_hashref = {
   email_1  => 'invalidemail',
   email_ok => 'mark@stosberg.com', 
   filled  => 'dog',
   not_filled => '',
   should_be_unknown => 1, 
};

my ($valids, $missings, $invalids, $unknowns);

eval{
  ($valids, $missings, $invalids, $unknowns) = $validator->validate($input_hashref, 'default');
};

ok(not $@ 
   or 
   $@ =~ qr/\QInvalid input profile: keys not recognised [bad_key_which_should_trigger_error, another_bad_key_which_should_trigger_error]/ 
   or
   $@ =~ qr/\QInvalid input profile: keys not recognised [another_bad_key_which_should_trigger_error, bad_key_which_should_trigger_error]/
  ) || warn $@;