PageRenderTime 52ms CodeModel.GetById 18ms app.highlight 30ms RepoModel.GetById 1ms app.codeStats 1ms

/t/password.t

http://github.com/gshank/html-formhandler
text | 128 lines | 89 code | 39 blank | 0 comment | 0 complexity | 0869830ce14569b108741c35c877f9dd MD5 | raw file
  1use strict;
  2use warnings;
  3use Test::More;
  4use lib 't/lib';
  5
  6use_ok( 'HTML::FormHandler::Field::Text' );
  7
  8my $field = HTML::FormHandler::Field::Text->new(
  9   name => 'password',
 10   type => 'Text',
 11   required => 1,
 12   password => 1,
 13);
 14
 15is( $field->password, 1, 'password is set');
 16
 17$field->_set_value('abcdef');
 18is( $field->value, 'abcdef', 'set and get value' );
 19
 20is( $field->fif, '', 'no fif for password');
 21
 22$field = HTML::FormHandler::Field::Text->new(
 23   name => 'not_password',
 24   type => 'Text',
 25   required => 1,
 26);
 27
 28is( $field->password, undef, 'password is not set');
 29
 30$field->_set_value('abcdef');
 31is( $field->value, 'abcdef', 'set and get value' );
 32
 33is( $field->fif, 'abcdef', 'get fif');
 34
 35use HTML::FormHandler;
 36use_ok( 'HTML::FormHandler::Field::Password' );
 37
 38{
 39   package My::Form;
 40
 41   use Moose;
 42   extends 'HTML::FormHandler';
 43
 44   sub field_list {
 45       return [
 46               login       => 'Text',
 47               username    => 'Text',
 48               password    => { type => 'Password',
 49                                ne_username => 'username',
 50                                minlength => 6,
 51                              },
 52          ];
 53   }
 54
 55}
 56
 57
 58my $form = My::Form->new;
 59
 60$field = $form->field('password');
 61
 62my $params = {
 63   username => 'my4username',
 64   password => 'something'
 65};
 66
 67$form->process( $params );
 68
 69ok( $field,  'got password field' );
 70
 71$field->_set_input( '2192ab201def' );
 72$field->validate_field;
 73ok( !$field->has_errors, 'Test for errors 1' );
 74
 75$field->_set_input( 'ab1' );
 76$field->validate_field;
 77ok( $field->has_errors, 'too short' );
 78
 79$field->_set_input( 'my4username' );
 80$field->validate_field;
 81ok( $field->has_errors, 'matches username' );
 82
 83$field->_set_input( '' );
 84$field->validate_field;
 85ok( !$field->has_errors, 'empty password accepted' );
 86is($field->noupdate, 1, 'noupdate has been set on password field' );
 87
 88my $pass = 'my4user5name';
 89$field->_set_input( $pass );
 90$field->validate_field;
 91ok( !$field->has_errors, 'just right' );
 92is ( $field->value, $pass, 'Input and value match' );
 93
 94
 95
 96{
 97   package Password::Form;
 98
 99   use HTML::FormHandler::Moose;
100   extends 'HTML::FormHandler';
101
102   has '+field_name_space' => ( default => 'Field' );
103   has_field 'password' => ( type => 'Password', required => 1 );
104   has_field '_password' => ( type => 'PasswordConf', );
105
106}
107
108$form = Password::Form->new;
109ok( $form, 'form created' );
110
111$params = {
112   password => ''
113};
114
115$form->process( params => $params );
116ok( !$form->validated, 'form validated' );
117
118ok( !$form->field('password')->noupdate, q[noupdate is 'false' on password field] );
119
120ok( $form->field('_password')->has_errors, 'Password confirmation has errors' );
121
122$form->process( params => { password => 'aaaaaa', _password => 'bbbb' } );
123ok( $form->field('_password')->has_errors, 'Password confirmation has errors' );
124
125$form->process( params => { password => 'aaaaaa', _password => 'aaaaaa' } );
126ok( $form->validated, 'password confirmation validated' );
127
128done_testing;