5 1_validate_11_no_extra.t - Test CGI::Ex::Validate's ability to not allow extra form fields
10 use Test::More tests => 21;
12 use_ok('CGI::Ex::Validate');
16 sub validate { CGI::Ex::Validate::validate(@_) }
18 ###----------------------------------------------------------------###
20 ### test single group for extra fields
23 'general no_extra_fields' => 'all',
24 foo => {max_len => 10},
28 $e = validate({}, $v);
31 $e = validate({foo => "foo"}, $v);
34 $e = validate({foo => "foo", bar => "bar"}, $v);
37 $e = validate({bar => "bar"}, $v);
41 ### test on failed validate if
44 'general no_extra_fields' => 'all',
45 'group validate_if' => 'baz',
46 foo => {max_len => 10},
50 $e = validate({}, $v);
53 $e = validate({foo => "foo"}, $v);
56 $e = validate({foo => "foo", bar => "bar"}, $v);
59 $e = validate({bar => "bar"}, $v);
62 ### test on successful validate if
65 'general no_extra_fields' => 'all',
66 'group validate_if' => 'baz',
67 foo => {max_len => 10},
68 baz => {max_len => 10},
72 $e = validate({baz => 1}, $v);
75 $e = validate({baz => 1, foo => "foo"}, $v);
78 $e = validate({baz => 1, foo => "foo", bar => "bar"}, $v);
81 $e = validate({baz => 1, bar => "bar"}, $v);
84 ### test on multiple groups, some with validate if
87 'general no_extra_fields' => 'all',
88 'group validate_if' => 'baz',
89 foo => {max_len => 10},
90 baz => {max_len => 10},
93 'group validate_if' => 'hem',
94 haw => {max_len => 10},
98 $e = validate({haw => 1, baz => 1}, $v);
101 $e = validate({haw => 1, baz => 1, foo => "foo"}, $v);
104 $e = validate({haw => 1, baz => 1, foo => "foo", bar => "bar"}, $v);
107 $e = validate({haw => 1, baz => 1, bar => "bar"}, $v);
111 ### test on multiple groups, some with validate if
114 'general no_extra_fields' => 'used',
115 'group validate_if' => 'baz',
116 foo => {max_len => 10},
117 baz => {max_len => 10},
120 'group validate_if' => 'hem',
121 haw => {max_len => 10},
125 $e = validate({haw => 1, baz => 1}, $v);
128 $e = validate({haw => 1, baz => 1, foo => "foo"}, $v);
131 $e = validate({haw => 1, baz => 1, foo => "foo", bar => "bar"}, $v);
134 $e = validate({haw => 1, baz => 1, bar => "bar"}, $v);