add Password test, fix bug in Password with maxlength
This commit is contained in:
parent
16a6c2cc00
commit
c8c7b78ee1
2 changed files with 32 additions and 25 deletions
|
|
@ -93,7 +93,7 @@ Renders an input tag of type password.
|
||||||
sub toHtml {
|
sub toHtml {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $html = '<input type="password" name="'.$self->get("name").'" value="'.$self->fixQuotes($self->get("value")).'" size="'.$self->get("size").'" id="'.$self->get('id').'" ';
|
my $html = '<input type="password" name="'.$self->get("name").'" value="'.$self->fixQuotes($self->get("value")).'" size="'.$self->get("size").'" id="'.$self->get('id').'" ';
|
||||||
$html .= 'maxlength="'.$self->get("maxLength").'" ' if ($self->get("maxLength"));
|
$html .= 'maxlength="'.$self->get("maxlength").'" ' if ($self->get("maxlength"));
|
||||||
$html .= $self->get("extras").' />';
|
$html .= $self->get("extras").' />';
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,8 @@ use WebGUI::Form;
|
||||||
use WebGUI::Form::Password;
|
use WebGUI::Form::Password;
|
||||||
use WebGUI::Session;
|
use WebGUI::Session;
|
||||||
use HTML::Form;
|
use HTML::Form;
|
||||||
use Test::MockObject;
|
use Tie::IxHash;
|
||||||
|
use WebGUI::Form_Checking;
|
||||||
|
|
||||||
#The goal of this test is to verify that Password form elements work
|
#The goal of this test is to verify that Password form elements work
|
||||||
|
|
||||||
|
|
@ -27,7 +28,19 @@ my $session = WebGUI::Test->session;
|
||||||
|
|
||||||
# put your tests here
|
# put your tests here
|
||||||
|
|
||||||
my $numTests = 10;
|
my %testBlock;
|
||||||
|
|
||||||
|
tie %testBlock, 'Tie::IxHash';
|
||||||
|
|
||||||
|
%testBlock = (
|
||||||
|
PASS1 => [ 'some user value', 'EQUAL', 'Regular text'],
|
||||||
|
PASS2 => [ "some user value\nwith\r\nwhitespace", "EQUAL", 'Embedded whitespace is passed'],
|
||||||
|
);
|
||||||
|
|
||||||
|
my $formType = 'password';
|
||||||
|
my $formClass = 'WebGUI::Form::Password';
|
||||||
|
|
||||||
|
my $numTests = 12 + scalar keys %testBlock;
|
||||||
|
|
||||||
diag("Planning on running $numTests tests\n");
|
diag("Planning on running $numTests tests\n");
|
||||||
|
|
||||||
|
|
@ -37,7 +50,7 @@ my ($header, $footer) = (WebGUI::Form::formHeader($session), WebGUI::Form::formF
|
||||||
|
|
||||||
my $html = join "\n",
|
my $html = join "\n",
|
||||||
$header,
|
$header,
|
||||||
WebGUI::Form::Password->new($session, {
|
$formClass->new($session, {
|
||||||
name => 'TestText',
|
name => 'TestText',
|
||||||
value => 'Some text in here',
|
value => 'Some text in here',
|
||||||
})->toHtml,
|
})->toHtml,
|
||||||
|
|
@ -55,38 +68,26 @@ is(scalar @inputs, 1, 'The form has 1 input');
|
||||||
#Basic tests
|
#Basic tests
|
||||||
|
|
||||||
my $input = $inputs[0];
|
my $input = $inputs[0];
|
||||||
|
use Data::Dumper;
|
||||||
|
diag(Dumper $input);
|
||||||
|
diag($html);
|
||||||
is($input->name, 'TestText', 'Checking input name');
|
is($input->name, 'TestText', 'Checking input name');
|
||||||
is($input->type, 'password', 'Checking input type');
|
is($input->type, $formType, 'Checking input type');
|
||||||
is($input->value, 'Some text in here', 'Checking default value');
|
is($input->value, 'Some text in here', 'Checking default value');
|
||||||
is($input->disabled, undef, 'Disabled param not sent to form');
|
is($input->disabled, undef, 'Disabled param not sent to form');
|
||||||
|
is($input->{size}, 30, 'Default size');
|
||||||
##Test Form Output parsing
|
is($input->{maxlength}, 35, 'Default maxlength');
|
||||||
|
|
||||||
my $request = Test::MockObject->new;
|
|
||||||
$request->mock('body',
|
|
||||||
sub {
|
|
||||||
my ($self, $value) = @_;
|
|
||||||
my @return = ();
|
|
||||||
return 'some user value' if ($value eq 'TestText');
|
|
||||||
return "some user value\nwith\r\nwhitespace" if ($value eq 'TestText2');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
$session->{_request} = $request;
|
|
||||||
|
|
||||||
my $value = $session->form->get('TestText', 'Password');
|
|
||||||
is($value, 'some user value', 'checking existent form value');
|
|
||||||
$value = $session->form->get('TestText2', 'Password');
|
|
||||||
is($value, "some user value\nwith\r\nwhitespace", 'checking form postprocessing for whitespace');
|
|
||||||
|
|
||||||
##Form value preprocessing
|
##Form value preprocessing
|
||||||
##Note that HTML::Form will unencode the text for you.
|
##Note that HTML::Form will unencode the text for you.
|
||||||
|
|
||||||
$html = join "\n",
|
$html = join "\n",
|
||||||
$header,
|
$header,
|
||||||
WebGUI::Form::Password->new($session, {
|
$formClass->new($session, {
|
||||||
name => 'preTestText',
|
name => 'preTestText',
|
||||||
value => q!Some & text in " here!,
|
value => q!Some & text in " here!,
|
||||||
|
size => 25,
|
||||||
|
maxlength => 200,
|
||||||
})->toHtml,
|
})->toHtml,
|
||||||
$footer;
|
$footer;
|
||||||
|
|
||||||
|
|
@ -95,3 +96,9 @@ $html = join "\n",
|
||||||
$input = $inputs[0];
|
$input = $inputs[0];
|
||||||
is($input->name, 'preTestText', 'Checking input name');
|
is($input->name, 'preTestText', 'Checking input name');
|
||||||
is($input->value, 'Some & text in " here', 'Checking default value');
|
is($input->value, 'Some & text in " here', 'Checking default value');
|
||||||
|
is($input->{size}, 25, 'Checking size param, set');
|
||||||
|
is($input->{maxlength}, 200, 'Checking maxlength param, set');
|
||||||
|
|
||||||
|
##Test Form Output parsing
|
||||||
|
|
||||||
|
WebGUI::Form_Checking::auto_check($session, $formType, %testBlock);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue