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