PageRenderTime 24ms CodeModel.GetById 1ms app.highlight 18ms RepoModel.GetById 2ms app.codeStats 0ms

/xt/email.t

http://github.com/gshank/html-formhandler
Unknown | 49 lines | 40 code | 9 blank | 0 comment | 0 complexity | 01c888254762c89513dab94c7e325e37 MD5 | raw file
 1use strict;
 2use warnings;
 3use Test::More;
 4
 5BEGIN
 6{
 7   eval "use Email::Valid";
 8   plan skip_all => 'Email::Valid required' if $@;
 9   plan tests => 7;
10}
11
12$ENV{LANG} = 'en_us'; # in case user has LANG set
13
14my $class = 'HTML::FormHandler::Field::Email';
15use_ok($class);
16my $field = $class->new( name => 'test_field', );
17$field->build_result;
18ok( defined $field, 'new() called' );
19
20$field->_set_input('foo@bar.com');
21$field->validate_field;
22ok( !$field->has_errors, 'Test for errors 1' );
23is( $field->value, 'foo@bar.com', 'value returned' );
24
25$field->_set_input('foo@bar');
26$field->validate_field;
27ok( $field->has_errors, 'Test for errors 2' );
28is(
29   $field->errors->[0],
30   'Email should be of the format someuser@example.com',
31   'Test error message'
32);
33
34$field->_set_input('someuser@example.com');
35$field->validate_field;
36ok( !$field->has_errors, 'Test for errors 3' );
37
38{
39    package MyApp::Form::Test;
40    use HTML::FormHandler::Moose;
41    extends 'HTML::FormHandler';
42
43    has_field 'foo';
44    has_field 'email' => (
45        type => 'Email',
46        email_valid_params => { -mxcheck => 1 },
47    );
48}
49