EMS import/export, Form::*::getValueFromPost(alt_values), and tests
This commit is contained in:
parent
0a7e06edca
commit
c09b2cae1b
46 changed files with 1728 additions and 299 deletions
|
|
@ -45,7 +45,7 @@ my $testBlock = [
|
|||
my $formClass = 'WebGUI::Form::Checkbox';
|
||||
my $formType = 'Checkbox';
|
||||
|
||||
my $numTests = 7 + scalar @{ $testBlock } + 1;
|
||||
my $numTests = 7 + scalar @{ $testBlock } + 3;
|
||||
|
||||
|
||||
plan tests => $numTests;
|
||||
|
|
@ -105,3 +105,8 @@ is( $forms[0]->param('cbox3'), ' ', 'WRONG: whitespace value');
|
|||
|
||||
WebGUI::Form_Checking::auto_check($session, $formType, $testBlock);
|
||||
|
||||
#
|
||||
# test WebGUI::FormValidator::Checkbox(undef,@values)
|
||||
#
|
||||
is(WebGUI::Form::Checkbox->new($session)->getValueFromPost('test'), 'test', '$cbox->getValueFromPost(arg)');
|
||||
is($session->form->checkbox(undef,'test'), 'test', 'WebGUI::FormValidator::checkbox');
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ my $testBlock = [
|
|||
my $formClass = 'WebGUI::Form::ClassName';
|
||||
my $formType = 'ClassName';
|
||||
|
||||
my $numTests = 11 + scalar @{ $testBlock } + 1;
|
||||
my $numTests = 11 + scalar @{ $testBlock } + 3;
|
||||
|
||||
|
||||
plan tests => $numTests;
|
||||
|
|
@ -127,3 +127,8 @@ is($input->{maxlength}, 20, 'set maxlength');
|
|||
#diag $formType;
|
||||
WebGUI::Form_Checking::auto_check($session, $formType, $testBlock);
|
||||
|
||||
#
|
||||
# test WebGUI::FormValidator::ClassName(undef,@values)
|
||||
#
|
||||
is(WebGUI::Form::ClassName->new($session)->getValueFromPost('t*est'), 'test', '$cname->getValueFromPost(arg)');
|
||||
is($session->form->className(undef,'t*est'), 'test', 'WebGUI::FormValidator::className');
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ my $testBlock = [
|
|||
my $formType = 'text';
|
||||
my $formClass = 'WebGUI::Form::Email';
|
||||
|
||||
my $numTests = 11 + scalar @{ $testBlock } + 1;
|
||||
my $numTests = 11 + scalar @{ $testBlock } + 5;
|
||||
|
||||
|
||||
plan tests => $numTests;
|
||||
|
|
@ -106,3 +106,14 @@ is($input->{maxlength}, 200, 'Checking maxlength param, set');
|
|||
##Test Form Output parsing
|
||||
|
||||
WebGUI::Form_Checking::auto_check($session, 'email', $testBlock);
|
||||
|
||||
# just testing that getValueFromPost works with an argument
|
||||
|
||||
my $email = WebGUI::Form::Email->new($session);
|
||||
is($email->getValueFromPost('james@plainblack.com'), 'james@plainblack.com', 'getValueFromPost(valid) returned a valid email');
|
||||
is($email->getValueFromPost('this*isn"t and@emailaddres,s'), undef, 'getValueFromPost(invalid) returned undef instead of an invalid email');
|
||||
is($session->form->email(undef,'james@plainblack.com'), 'james@plainblack.com', '$form->email(valid) returned a valid email');
|
||||
is($session->form->email(undef,'this*isn"t and@emailaddres,s'), undef, '$form->email(invalid) returned undef instead of an invalid email');
|
||||
|
||||
__END__
|
||||
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ my $testBlock = [
|
|||
my $formClass = 'WebGUI::Form::Float';
|
||||
my $formType = 'Float';
|
||||
|
||||
my $numTests = 11 + scalar @{ $testBlock } + 1;
|
||||
my $numTests = 11 + scalar @{ $testBlock } + 3;
|
||||
|
||||
|
||||
plan tests => $numTests;
|
||||
|
|
@ -143,3 +143,11 @@ is($input->{maxlength}, 20, 'set maxlength');
|
|||
|
||||
WebGUI::Form_Checking::auto_check($session, $formType, $testBlock);
|
||||
|
||||
# just testing that getValueFromPost works with an argument
|
||||
|
||||
my $float = WebGUI::Form::Float->new($session);
|
||||
is($float->getValueFromPost('112.233'), 112.233, 'Got a valid float');
|
||||
is($float->getValueFromPost('fred'), 0, 'Returned 0 instead of an invalid float');
|
||||
|
||||
__END__
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ my $testBlock = [
|
|||
my $formClass = 'WebGUI::Form::Integer';
|
||||
my $formType = 'Integer';
|
||||
|
||||
my $numTests = 11 + scalar @{ $testBlock } + 1;
|
||||
my $numTests = 11 + scalar @{ $testBlock } + 11;
|
||||
|
||||
|
||||
plan tests => $numTests;
|
||||
|
|
@ -120,3 +120,21 @@ is($input->{maxlength}, 20, 'set maxlength');
|
|||
|
||||
WebGUI::Form_Checking::auto_check($session, $formType, $testBlock);
|
||||
|
||||
# just testing that getValueFromPost works with an argument
|
||||
|
||||
my $int = WebGUI::Form::Integer->new($session);
|
||||
is($int->getValueFromPost(-123456), -123456, 'getValueFromPost(-123456)');
|
||||
is($int->getValueFromPost('002300'), '002300', 'getValueFromPost(002300)');
|
||||
is($int->getValueFromPost('+123456'), 0, 'getValueFromPost(+123456)');
|
||||
is($int->getValueFromPost('123-456.'), 0, 'getValueFromPost(123-456.)');
|
||||
is($int->getValueFromPost(123.456), 0, 'getValueFromPost(123.456)');
|
||||
|
||||
is($session->form->integer(undef,-123456), -123456, 'session->form->integer(undef,-123456)');
|
||||
is($session->form->integer(undef,'002300'), '002300', 'session->form->integer(undef,002300)');
|
||||
is($session->form->integer(undef,'+123456'), 0, 'session->form->integer(undef,+123456)');
|
||||
is($session->form->integer(undef,'123-456.'), 0, 'session->form->integer(undef,123-456.)');
|
||||
is($session->form->integer(undef,123.456), 0, 'session->form->integer(undef,123.456)');
|
||||
|
||||
|
||||
__END__
|
||||
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ my $testBlock = [
|
|||
my $formClass = 'WebGUI::Form::Phone';
|
||||
my $formType = 'Phone';
|
||||
|
||||
my $numTests = 11 + scalar @{ $testBlock } + 1;
|
||||
my $numTests = 11 + scalar @{ $testBlock } + 10;
|
||||
|
||||
|
||||
plan tests => $numTests;
|
||||
|
|
@ -144,3 +144,17 @@ is($input->{maxlength}, 20, 'set maxlength');
|
|||
|
||||
WebGUI::Form_Checking::auto_check($session, $formType, $testBlock);
|
||||
|
||||
# test that we can process non-POST values correctly
|
||||
my $cntl = WebGUI::Form::Phone->new($session,{ defaultValue => 4242 });
|
||||
is($cntl->getValueFromPost('123-123-1234'), '123-123-1234', 'getValueFromPost(valid)');
|
||||
is($cntl->getValueFromPost('123/123-1234'), undef, 'getValueFromPost(invalid)');
|
||||
is($cntl->getValueFromPost(0), 0, 'zero');
|
||||
is($cntl->getValueFromPost(''), undef, '""');
|
||||
is($session->form->phone(undef,'123-123-1234'), '123-123-1234', 'valid');
|
||||
is($session->form->phone(undef,'123/123-1234'), undef, 'invalid');
|
||||
is($session->form->phone(undef,0), 0, 'zero');
|
||||
is($session->form->phone(undef,undef), undef, 'undef returns undef');
|
||||
is($session->form->phone(undef,''), undef, '""');
|
||||
|
||||
__END__
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ my $testBlock = [
|
|||
my $formClass = 'WebGUI::Form::SelectBox';
|
||||
my $formType = 'SelectBox';
|
||||
|
||||
my $numTests = 8 + scalar @{ $testBlock } + 1;
|
||||
my $numTests = 8 + scalar @{ $testBlock } + 12;
|
||||
|
||||
|
||||
plan tests => $numTests;
|
||||
|
|
@ -107,3 +107,20 @@ is($input->{size}, 5, 'set size');
|
|||
##Test Form Output parsing
|
||||
|
||||
WebGUI::Form_Checking::auto_check($session, $formType, $testBlock);
|
||||
|
||||
# test that we can process non-POST values correctly
|
||||
my $cntl = WebGUI::Form::SelectBox->new($session,{ defaultValue => 4242 });
|
||||
is($cntl->getValueFromPost('text'), 'text', 'getValueFromPost(text)');
|
||||
is($cntl->getValueFromPost(42), 42, 'getValueFromPost(int)');
|
||||
is($cntl->getValueFromPost(0), 0, 'zero');
|
||||
is($cntl->getValueFromPost(''), '', '""');
|
||||
is($cntl->getValueFromPost(1,2,3), 1, 'list returns first item');
|
||||
is($session->form->selectBox(undef,'text'), 'text', 'text');
|
||||
is($session->form->selectBox(undef,42), 42, 'int');
|
||||
is($session->form->selectBox(undef,0), 0, 'zero');
|
||||
is($session->form->selectBox(undef,undef), '', 'undef returns ""');
|
||||
is($session->form->selectBox(undef,''), '', '""');
|
||||
is($session->form->selectBox(undef,1,2,3), 1, 'list returns first item');
|
||||
|
||||
__END__
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ my $testBlock = [
|
|||
|
||||
my $formType = 'text';
|
||||
|
||||
my $numTests = 11 + scalar @{ $testBlock } + 1;
|
||||
my $numTests = 11 + scalar @{ $testBlock } + 9;
|
||||
|
||||
|
||||
plan tests => $numTests;
|
||||
|
|
@ -113,3 +113,17 @@ is($input->{maxlength}, 200, 'Checking maxlength param, set');
|
|||
##Test Form Output parsing
|
||||
|
||||
WebGUI::Form_Checking::auto_check($session, $formType, $testBlock);
|
||||
|
||||
# test that we can process non-POST values correctly
|
||||
my $cntl = WebGUI::Form::Text->new($session,{ defaultValue => 4242 });
|
||||
is($cntl->getValueFromPost('123-123-1234'), '123-123-1234', 'getValueFromPost(valid)');
|
||||
is($cntl->getValueFromPost(0), 0, 'zero');
|
||||
is($cntl->getValueFromPost(''), '', '""');
|
||||
is($cntl->getValueFromPost(undef), undef, 'undef returns undef');
|
||||
is($session->form->text(undef,'123-123-1234'), '123-123-1234', 'valid');
|
||||
is($session->form->text(undef,0), 0, 'zero');
|
||||
is($session->form->text(undef,undef), undef, 'undef returns undef');
|
||||
is($session->form->text(undef,''), '', '""');
|
||||
|
||||
__END__
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ my $testBlock = [
|
|||
|
||||
my $formType = 'textarea';
|
||||
|
||||
my $numTests = 12 + scalar @{ $testBlock } + 1;
|
||||
my $numTests = 12 + scalar @{ $testBlock } + 5;
|
||||
|
||||
|
||||
plan tests => $numTests;
|
||||
|
|
@ -99,3 +99,16 @@ like($input->{style}, qr/width: 500/, 'Custom width');
|
|||
##Test Form Output parsing
|
||||
|
||||
WebGUI::Form_Checking::auto_check($session, $formType, $testBlock);
|
||||
|
||||
# just testing that getValueFromPost works with an argument
|
||||
|
||||
my $txt = WebGUI::Form::Textarea->new($session);
|
||||
is($txt->getValueFromPost("some test here"), "some test here", 'getValueFromPost(text)');
|
||||
is($txt->getValueFromPost("some \ntest \r\nhere"), "some \ntest \r\nhere", 'getValueFromPost(newlines)');
|
||||
|
||||
is($session->form->textarea(undef,"some test here"), "some test here", 'session->form->textarea(undef,text)');
|
||||
is($session->form->textarea(undef,"some \ntest \r\nhere"), "some \ntest \r\nhere", 'session->form->textarea(undef,newlines)');
|
||||
|
||||
|
||||
__END__
|
||||
|
||||
|
|
|
|||
23
t/Form/Url.t
23
t/Form/Url.t
|
|
@ -74,7 +74,7 @@ my $testBlock = [
|
|||
|
||||
my $formClass = 'WebGUI::Form::Url';
|
||||
|
||||
my $numTests = 11 + scalar @{ $testBlock } + 1;
|
||||
my $numTests = 11 + scalar @{ $testBlock } + 15;
|
||||
|
||||
|
||||
plan tests => $numTests;
|
||||
|
|
@ -131,3 +131,24 @@ is($input->{maxlength}, 1024, 'set maxlength');
|
|||
##Test Form Output parsing
|
||||
|
||||
WebGUI::Form_Checking::auto_check($session, 'Url', $testBlock);
|
||||
|
||||
# test that we can process non-POST values correctly
|
||||
my $cntl = WebGUI::Form::Url->new($session,{ defaultValue => 4242 });
|
||||
is($cntl->getValueFromPost('mailto:whatever'), 'mailto:whatever', 'mailto processing');
|
||||
is($cntl->getValueFromPost('me@nowhere.com'), 'mailto:me@nowhere.com', 'email address processing');
|
||||
is($cntl->getValueFromPost('/'), '/', '/');
|
||||
is($cntl->getValueFromPost('://'), '://', '://');
|
||||
is($cntl->getValueFromPost('^'), '^', '^');
|
||||
is($cntl->getValueFromPost('mySite'), 'http://mySite', 'http://mySite');
|
||||
is($cntl->getValueFromPost('??**()!!'), 'http://??**()!!', 'random crap is passed through');
|
||||
|
||||
is($session->form->url(undef,'mailto:whatever'), 'mailto:whatever', 'mailto processing');
|
||||
is($session->form->url(undef,'me@nowhere.com'), 'mailto:me@nowhere.com', 'email address processing');
|
||||
is($session->form->url(undef,'/'), '/', '/');
|
||||
is($session->form->url(undef,'://'), '://', '://');
|
||||
is($session->form->url(undef,'^'), '^', '^');
|
||||
is($session->form->url(undef,'mySite'), 'http://mySite', 'http://mySite');
|
||||
is($session->form->url(undef,'??**()!!'), 'http://??**()!!', 'random crap is passed through');
|
||||
|
||||
__END__
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ my $testBlock = [
|
|||
|
||||
my $formClass = 'WebGUI::Form::Zipcode';
|
||||
|
||||
my $numTests = 12 + scalar @{ $testBlock } + 1;
|
||||
my $numTests = 12 + scalar @{ $testBlock } + 11;
|
||||
|
||||
|
||||
plan tests => $numTests;
|
||||
|
|
@ -117,3 +117,21 @@ is($input->{maxlength}, 13, 'Checking maxlength param, default');
|
|||
##Test Form Output parsing
|
||||
|
||||
WebGUI::Form_Checking::auto_check($session, 'Zipcode', $testBlock);
|
||||
|
||||
# test that we can process non-POST values correctly
|
||||
my $cntl = WebGUI::Form::Zipcode->new($session,{ defaultValue => 4242 });
|
||||
is($cntl->getValueFromPost('ABCDE'), 'ABCDE', 'alpha');
|
||||
is($cntl->getValueFromPost('02468'), '02468', 'numeric');
|
||||
is($cntl->getValueFromPost('NO WHERE'), 'NO WHERE', 'alpha space');
|
||||
is($cntl->getValueFromPost('-'), '-', 'bare dash');
|
||||
is($cntl->getValueFromPost('abcde'), undef, 'lower case');
|
||||
|
||||
is($session->form->zipcode(undef,'ABCDE'), 'ABCDE', 'alpha');
|
||||
is($session->form->zipcode(undef,'02468'), '02468', 'numeric');
|
||||
is($session->form->zipcode(undef,'NO WHERE'), 'NO WHERE', 'alpha space');
|
||||
is($session->form->zipcode(undef,'-'), '-', 'bare dash');
|
||||
is($session->form->zipcode(undef,'abcde'), undef, 'lower case');
|
||||
|
||||
|
||||
__END__
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue