File: 15_literal_param_constraints.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 (42 lines) | stat: -rw-r--r-- 831 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

use strict;
use lib ('.','../t');

$^W = 1;

use Test::More tests => 1;

use Data::FormValidator;

my $input_profile = {
	required => ['my_zipcode_field'],
	constraints => {
		my_zipcode_field => {
			constraint => \&starts_with_402,
			params	   => ['my_zipcode_field', \'cow'],
		}, 
	},
	untaint_all_constraints=>1,

};

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

my $input_hashref = {
	my_zipcode_field => 'big brown', 
};

sub starts_with_402 {
	my ($zip, $cow) = @_;
	return "$zip $$cow";
}

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

# Test to make sure that the constraint receives a literal value of an element passed by reference
is($valids->{my_zipcode_field}, 'big brown cow');