This repository has been archived on 2023-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
Foodloop-Server/t/plugins/validators.t
2017-04-25 20:50:34 +01:00

36 lines
979 B
Perl

use strict;
use warnings;
use Mojolicious::Lite;
use Test::More;
plugin 'Pear::LocalLoop::Plugin::Validators';
my $validator = app->validator;
my $validation = $validator->validation;
my $valid_email = 'test@example.com';
my $invalid_email = 'test.example.com';
my $valid_postcode = 'WC1H 9EB';
my $invalid_postcode = 'AB1 2CD';
my $not_a_postcode = 'a';
$validation->input({
valid_email => $valid_email,
invalid_email => $invalid_email,
valid_postcode => $valid_postcode,
invalid_postcode => $invalid_postcode,
not_a_postcode => $not_a_postcode,
});
$validation->required('valid_email')->email;
$validation->required('invalid_email')->email;
$validation->required('valid_postcode')->postcode;
$validation->required('invalid_postcode')->postcode;
$validation->required('not_a_postcode')->postcode;
ok $validation->has_error, 'Have Errors';
is_deeply $validation->failed, [ qw/ invalid_email invalid_postcode not_a_postcode / ], 'Correct Errors';
done_testing;