File: 21_multiple_fields.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 (60 lines) | stat: -rw-r--r-- 1,186 bytes parent folder | download | duplicates (7)
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
use strict;
use Test::More tests => 3;
use lib ('.','../t');

# Verify that multiple params passed to a constraint are being handled correctly

$^W = 1;


use Data::FormValidator;

my $validator = new Data::FormValidator({
   default =>
   {
    required => [ qw/my_zipcode_field my_other_field/],
	 constraints => { 
		 my_zipcode_field => { 
			 constraint =>  \&zipcode_check,
			 name       =>  'zipcode',
			 params     =>  [ 'my_zipcode_field', 'my_other_field' ],
		 },
	 },
 },
  });

my @args_for_check;		# to control which args were given

sub zipcode_check {
  @args_for_check = @_;
  if ($_[0] == 402015 and $_[1] eq 'mapserver_rulez') {
    return 1;
  }
  return 0;
}

my $input_hashref =
  {
   my_zipcode_field => '402015',
   my_other_field   => 'mapserver_rulez',
  };

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

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

ok(not $@) or
  diag "eval error: $@";

ok(not grep { (ref $_) eq 'ARRAY' } @$invalids) or
  diag $#{$invalids};


is_deeply(\@args_for_check, [402015,'mapserver_rulez']); 

# Local variables:
# compile-command: "cd .. && make test"
# End: