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
|
#!/usr/bin/perl
# this test checks that a failing constraint is only marked as invalid once
use Test::More tests => 1;
use Data::FormValidator;
use strict;
sub check_passwords {
my ( $dfv, $val ) = @_;
my $passwords = $dfv->{__INPUT_DATA}->{password};
if( ref( $passwords ) eq 'ARRAY' ) {
if( $$passwords[0] eq $$passwords[1] ) {
return 1;
}
return 0;
}
return 1;
}
my %data = (
'password' => ['123456','123457'],
);
my %profile = (
optional => [qw/password/],
constraint_methods => {
password => \&check_passwords,
},
);
my $results = Data::FormValidator->check(\%data, \%profile);
my $invalid = $results->{invalid};
my $duplicated = {};
my $has_duplicates;
foreach ( @{$invalid->{password}} ) {
if( exists $duplicated->{$_} ) {
$has_duplicates = 1;
last;
}
$duplicated->{$_} = 1;
}
ok(!$has_duplicates, 'constraint marked as invalid only once');
|