File: constraint_method_string.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 (65 lines) | stat: -rw-r--r-- 1,564 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/perl
# 
# in response to bug report 2006/10/25 by Brian E. Lozier <brian@massassi.net>
# test script by Evan A. Zacks <zackse@cpan.org>
#
# The problem was that when specifying constraint_methods in a profile and
# using the name of a built-in (e.g., "zip") as the constraint, the built-in
# (match_zip or valid_zip) ended up being called as a method rather than a
# function.  
#
# So now we throw an error if a non-code-ref is used with a constraint method.

use strict;

use Test::More tests => 4;

use_ok('Data::FormValidator');

my $err_re = qr/not a code ref/;

{
  my %profile = (
      required => ['zip'],
      constraint_methods => {
          zip => 'zip',
      }
  );

  my %data = (
      zip => 56567
  );

eval {  my $r = Data::FormValidator->check(\%data, \%profile) };
like($@, $err_re,
    "error thrown when given a string to constraint_method");
}

{
  my %profile = (
      required => ['zip'],
      constraint_methods => {
          zip => ['zip'],
      }
  );

  my %data = ( zip => 56567 );

    eval {  my $r = Data::FormValidator->check(\%data, \%profile) };
    like($@, $err_re,
        "error thrown when given a string to constraint_method...even as part of a list.");
}

{
  my %profile = (
      required => ['zip'],
      untaint_all_constraints => 1,
      constraint_methods => { zip => {} }
  );

  my %data = ( zip => 56567 );

  eval {  my $r = Data::FormValidator->check(\%data, \%profile) };
  like($@, $err_re,
         "error thrown when given a string to constraint_method...even as hash declaration.");
}