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
|
#!/usr/bin/perl
use Test::More qw/no_plan/;
use strict;
use lib 'perllib';
use Data::FormValidator;
my $input_profile = {
required => [ 'email_field' ],
constraints => {
email_field => [ 'email' ],
}
};
my $input_hashref = {
email_field => 'test@bad_email',
};
my $results;
eval{
$results = Data::FormValidator->check($input_hashref, $input_profile);
};
is($@, '', "Survived validate");
my @invalids = $results->invalid;
is(scalar @invalids, 1, "Correctly catches the bad field");
is($invalids[0], 'email_field', "The invalid field is listed correctly as 'email_field'");
# Now add constraint_regexp_map to the profile, and we'll get a weird interaction...
my $regex = qr/^test/;
$input_profile->{constraint_regexp_map} = { qr/email_/ => $regex };
eval{
$results = Data::FormValidator->check($input_hashref, $input_profile);
};
is($@, '', "Survived validate");
@invalids = $results->invalid;
is(scalar @invalids, 1, "Still correctly catches the bad field");
is($invalids[0], 'email_field', "The invalid field is still listed correctly as 'email_field'");
ok($input_hashref->{email_field} =~ $regex, "But perl agrees that the email address does match the regex");
|