File: email.t

package info (click to toggle)
libhtml-formhandler-perl 0.40057-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,320 kB
  • ctags: 685
  • sloc: perl: 8,849; makefile: 2
file content (49 lines) | stat: -rw-r--r-- 1,105 bytes parent folder | download | duplicates (4)
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
use strict;
use warnings;
use Test::More;

BEGIN
{
   eval "use Email::Valid";
   plan skip_all => 'Email::Valid required' if $@;
   plan tests => 7;
}

$ENV{LANG} = 'en_us'; # in case user has LANG set

my $class = 'HTML::FormHandler::Field::Email';
use_ok($class);
my $field = $class->new( name => 'test_field', );
$field->build_result;
ok( defined $field, 'new() called' );

$field->_set_input('foo@bar.com');
$field->validate_field;
ok( !$field->has_errors, 'Test for errors 1' );
is( $field->value, 'foo@bar.com', 'value returned' );

$field->_set_input('foo@bar');
$field->validate_field;
ok( $field->has_errors, 'Test for errors 2' );
is(
   $field->errors->[0],
   'Email should be of the format someuser@example.com',
   'Test error message'
);

$field->_set_input('someuser@example.com');
$field->validate_field;
ok( !$field->has_errors, 'Test for errors 3' );

{
    package MyApp::Form::Test;
    use HTML::FormHandler::Moose;
    extends 'HTML::FormHandler';

    has_field 'foo';
    has_field 'email' => (
        type => 'Email',
        email_valid_params => { -mxcheck => 1 },
    );
}