first batch of test automation for getValueFromPost checking

This commit is contained in:
Colin Kuskie 2006-03-27 19:41:18 +00:00
parent 9938a23665
commit 29ee2c313d
4 changed files with 123 additions and 111 deletions

View file

@ -17,7 +17,8 @@ use WebGUI::Form;
use WebGUI::Form::Text;
use WebGUI::Session;
use HTML::Form;
use Test::MockObject;
use Tie::IxHash;
use WebGUI::Form_Checking;
#The goal of this test is to verify that Text form elements work
@ -27,7 +28,18 @@ my $session = WebGUI::Test->session;
# put your tests here
my $numTests = 10;
my %testBlock;
tie %testBlock, 'Tie::IxHash';
%testBlock = (
TestText => [ 'some user value', 'EQUAL', 'Regular text'],
TestText2 => [ "some user value\nwith\r\nwhitespace", "some user valuewithwhitespace", 'Embedded whitespace is stripped'],
);
my $formType = 'text';
my $numTests = 12 + scalar keys %testBlock;
diag("Planning on running $numTests tests\n");
@ -56,28 +68,11 @@ is(scalar @inputs, 1, 'The form has 1 input');
my $input = $inputs[0];
is($input->name, 'TestText', 'Checking input name');
is($input->type, 'text', 'Checking input type');
is($input->type, $formType, 'Checking input type');
is($input->value, 'Some text in here', 'Checking default value');
is($input->disabled, undef, 'Disabled param not sent to form');
##Test Form Output parsing
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', 'Text');
is($value, 'some user value', 'checking existent form value');
$value = $session->form->get('TestText2', 'Text');
is($value, 'some user valuewithwhitespace', 'checking form postprocessing for whitespace');
is($input->{size}, 30, 'Checking size param, default');
is($input->{maxlength}, 255, 'Checking maxlength param, default');
##Form value preprocessing
##Note that HTML::Form will unencode the text for you.
@ -87,6 +82,8 @@ $html = join "\n",
WebGUI::Form::Text->new($session, {
name => 'preTestText',
value => q!Some & text in " here!,
size => 25,
maxlength => 200,
})->toHtml,
$footer;
@ -95,3 +92,9 @@ $html = join "\n",
$input = $inputs[0];
is($input->name, 'preTestText', 'Checking input name');
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);

View file

@ -17,7 +17,8 @@ use WebGUI::Form;
use WebGUI::Form::Textarea;
use WebGUI::Session;
use HTML::Form;
use Test::MockObject;
use Tie::IxHash;
use WebGUI::Form_Checking;
#The goal of this test is to verify that Textarea form elements work
@ -27,7 +28,18 @@ my $session = WebGUI::Test->session;
# put your tests here
my $numTests = 10;
my %testBlock;
tie %testBlock, 'Tie::IxHash';
%testBlock = (
TestText => [ 'some user value', 'EQUAL', 'Regular text'],
TestText2 => [ "some user value\nwith\r\nwhitespace", 'EQUAL', 'Embedded whitespace is left'],
);
my $formType = 'textarea';
my $numTests = 14 + scalar keys %testBlock;
diag("Planning on running $numTests tests\n");
@ -56,37 +68,21 @@ is(scalar @inputs, 1, 'The form has 1 input');
my $input = $inputs[0];
is($input->name, 'TestText', 'Checking input name');
is($input->type, 'textarea', 'Checking input type');
is($input->type, $formType, 'Checking input type');
is($input->value, 'Some text in here', 'Checking default value');
is($input->disabled, undef, 'Disabled param not sent to form');
##Test Form Output parsing
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', 'Textarea');
is($value, 'some user value', 'checking existent form value');
$value = $session->form->get('TestText2', 'Textarea');
is($value, "some user value\nwith\r\nwhitespace", 'checking form postprocessing for whitespace');
##Form value preprocessing
##Note that HTML::Form will unencode the text for you.
is($input->{rows}, 5, 'Default number of rows');
is($input->{cols}, 50, 'Default number of columns');
is($input->{wrap}, 'virtual', 'Default wrap');
$html = join "\n",
$header,
WebGUI::Form::Textarea->new($session, {
name => 'preTestText',
value => q!Some & text in " here!,
rows => 10,
columns => 80,
wrap => 'off'
})->toHtml,
$footer;
@ -95,3 +91,10 @@ $html = join "\n",
$input = $inputs[0];
is($input->name, 'preTestText', 'Checking input name');
is($input->value, 'Some & text in " here', 'Checking default value');
is($input->{rows}, 10, 'set number of rows');
is($input->{cols}, 80, 'set number of columns');
is($input->{wrap}, 'off', 'set wrap to off');
##Test Form Output parsing
WebGUI::Form_Checking::auto_check($session, $formType, %testBlock);

View file

@ -17,7 +17,8 @@ use WebGUI::Form;
use WebGUI::Form::Url;
use WebGUI::Session;
use HTML::Form;
use Test::MockObject;
use Tie::IxHash;
use WebGUI::Form_Checking;
#The goal of this test is to verify that Url form elements work
@ -27,7 +28,23 @@ my $session = WebGUI::Test->session;
# put your tests here
my $numTests = 14;
my %testBlock;
tie %testBlock, 'Tie::IxHash';
%testBlock = (
Email1 => [ 'mailto:whatever', 'EQUAL', 'mailto processing'],
Email2 => [ 'me@nowhere.com', 'mailto:me@nowhere.com', 'email address processing'],
Email3 => [ '/', 'EQUAL', 'Url'],
Email4 => [ '://', 'EQUAL', 'colon'],
Email5 => [ '^', 'EQUAL', 'caret'],
Email6 => [ 'mySite', 'http://mySite', 'bare hostname'],
Email7 => [ '??**()!!', 'http://??**()!!', 'WRONG: random crap is passed through'],
);
my $formClass = 'WebGUI::Form::Url';
my $numTests = 12 + scalar keys %testBlock;
diag("Planning on running $numTests tests\n");
@ -37,7 +54,7 @@ my ($header, $footer) = (WebGUI::Form::formHeader($session), WebGUI::Form::formF
my $html = join "\n",
$header,
WebGUI::Form::Text->new($session, {
$formClass->new($session, {
name => 'TestUrl',
value => 'http://www.webgui.org',
})->toHtml,
@ -59,46 +76,19 @@ is($input->name, 'TestUrl', 'Checking input name');
is($input->type, 'text', 'Checking input type');
is($input->value, 'http://www.webgui.org', 'Checking default value');
is($input->disabled, undef, 'Disabled param not sent to form');
##Test Form Output parsing
my $request = Test::MockObject->new;
$request->mock('body',
sub {
my ($self, $value) = @_;
my @return = ();
return 'mailto:whatever' if ($value eq 'mailto_test');
return 'me@nowhere.com' if ($value eq 'address_test');
return "/" if ($value eq 'leading_slash');
return "://" if ($value eq 'colon');
return "^" if ($value eq 'caret');
return "mySite" if ($value eq 'host');
return;
}
);
$session->{_request} = $request;
my $value = $session->form->get('mailto_test', 'Url');
is($value, 'mailto:whatever', 'checking mailto processing');
$value = $session->form->get('address_test', 'Url');
is($value, 'mailto:me@nowhere.com', 'checking email address processing');
$value = $session->form->get('leading_slash', 'Url');
is($value, '/', 'checking leading slash');
$value = $session->form->get('colon', 'Url');
is($value, '://', 'checking colon slash slash');
$value = $session->form->get('caret', 'Url');
is($value, '^', 'checking leading caret');
$value = $session->form->get('host', 'Url');
is($value, 'http://mySite', 'checking host');
is($input->{size}, 30, 'Checking size param, default');
is($input->{maxlength}, 2048, 'Checking maxlength param, default');
##Form value preprocessing
##Note that HTML::Form will unencode the text for you.
$html = join "\n",
$header,
WebGUI::Form::Text->new($session, {
$formClass->new($session, {
name => 'preTestUrl',
value => q!http://www.webgui.org?foo=bar&baz=buz!,
size => 25,
maxlength => 1024,
})->toHtml,
$footer;
@ -107,3 +97,9 @@ $html = join "\n",
$input = $inputs[0];
is($input->name, 'preTestUrl', 'Checking input name');
is($input->value, 'http://www.webgui.org?foo=bar&baz=buz', 'Checking default value');
is($input->{size}, 25, 'set size');
is($input->{maxlength}, 1024, 'set maxlength');
##Test Form Output parsing
WebGUI::Form_Checking::auto_check($session, 'Url', %testBlock);

View file

@ -17,7 +17,8 @@ use WebGUI::Form;
use WebGUI::Form::Zipcode;
use WebGUI::Session;
use HTML::Form;
use Test::MockObject;
use Tie::IxHash;
use WebGUI::Form_Checking;
#The goal of this test is to verify that Zipcode form elements work
@ -27,7 +28,21 @@ my $session = WebGUI::Test->session;
# put your tests here
my $numTests = 11;
my %testBlock;
tie %testBlock, 'Tie::IxHash';
%testBlock = (
Zip1 => [ 'ABCDE', 'EQUAL', 'alpha'],
Zip2 => [ '02468', 'EQUAL', 'numeric'],
Zip3 => [ 'NO WHERE', 'EQUAL', 'alpha space'],
Zip4 => [ '-', 'EQUAL', 'base dash'],
Zip5 => [ 'abcde', undef, 'lower case'],
);
my $formClass = 'WebGUI::Form::Zipcode';
my $numTests = 14 + scalar keys %testBlock;
diag("Planning on running $numTests tests\n");
@ -37,7 +52,7 @@ my ($header, $footer) = (WebGUI::Form::formHeader($session), WebGUI::Form::formF
my $html = join "\n",
$header,
WebGUI::Form::Zipcode->new($session, {
$formClass->new($session, {
name => 'TestZip',
value => '97123-ORST',
})->toHtml,
@ -59,34 +74,29 @@ is($input->name, 'TestZip', 'Checking input name');
is($input->type, 'text', 'Checking input type');
is($input->value, '97123-ORST', 'Checking default value');
is($input->disabled, undef, 'Disabled param not sent to form');
is($input->{size}, 30, 'Checking size param, default');
is($input->{maxlength}, 10, 'Checking maxlength param, default');
##Test Form Output parsing
my $request = Test::MockObject->new;
$request->mock('body',
sub {
my ($self, $value) = @_;
my @return = ();
return 'ABCDE' if ($value eq 'alpha');
return '02468' if ($value eq 'numeric');
return "NO WHERE" if ($value eq 'alpha space');
return "-" if ($value eq 'dash');
return "abcde" if ($value eq 'failure');
return;
}
);
$session->{_request} = $request;
WebGUI::Form_Checking::auto_check($session, 'Zipcode', %testBlock);
my $value = $session->form->get('alpha', 'Zipcode');
is($value, 'ABCDE', 'checking alpha processing');
$value = $session->form->get('numeric', 'Zipcode');
is($value, '02468', 'checking numeric processing');
$value = $session->form->get('alpha space', 'Zipcode');
is($value, 'NO WHERE', 'checking alpha space');
$value = $session->form->get('dash', 'Zipcode');
is($value, '-', 'checking dash');
$value = $session->form->get('failure', 'Zipcode');
is($value, undef, 'checking failure');
##Form value preprocessing. Zipcode does no preprocessing
$html = join "\n",
$header,
$formClass->new($session, {
name => 'TestZip2',
value => '97229-MXIM',
size => 12,
maxlength => 13,
})->toHtml,
$footer;
my @forms = HTML::Form->parse($html, 'http://www.webgui.org');
@inputs = $forms[0]->inputs;
$input = $inputs[0];
is($input->name, 'TestZip2', 'Checking input name');
is($input->type, 'text', 'Checking input type');
is($input->value, '97229-MXIM', 'Checking default value');
is($input->disabled, undef, 'Disabled param not sent to form');
is($input->{size}, 12, 'Checking size param, default');
is($input->{maxlength}, 13, 'Checking maxlength param, default');