From 84117932afe59a68c2eee60c7605eecd513b34de Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sat, 29 Jul 2006 03:31:59 +0000 Subject: [PATCH] add a test for the FormParam macro, and clarify in the docs that FormParam returns only the first value from a list --- lib/WebGUI/i18n/English/Macro_FormParam.pm | 3 +- t/Macro/FormParam.t | 94 ++++++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 t/Macro/FormParam.t diff --git a/lib/WebGUI/i18n/English/Macro_FormParam.pm b/lib/WebGUI/i18n/English/Macro_FormParam.pm index 49495b574..6164ea899 100644 --- a/lib/WebGUI/i18n/English/Macro_FormParam.pm +++ b/lib/WebGUI/i18n/English/Macro_FormParam.pm @@ -18,8 +18,9 @@ our $I18N = {

^FormParam();
This macro is mainly used in generating dynamic queries in SQL Reports. Using this macro you can pull the value of any form field simply by specifying the name of the form field, like this: ^FormParam("phoneNumber");

+

If the macro is used to pull data from a form field that returns multiple values, like a dropdown list, then only the first value will be returned.

|, - lastUpdated => 1146679330, + lastUpdated => 1154143837, }, }; diff --git a/t/Macro/FormParam.t b/t/Macro/FormParam.t new file mode 100644 index 000000000..c099ab995 --- /dev/null +++ b/t/Macro/FormParam.t @@ -0,0 +1,94 @@ +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2006 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------- +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------- + +use FindBin; +use strict; +use lib "$FindBin::Bin/../lib"; + +use WebGUI::Test; +use WebGUI::Session; + +use Test::More; # increment this value for each test you create +use Test::MockObject; + +my $session = WebGUI::Test->session; + +my @testSets = ( + { + key => 'FormParam1', + testValue => 'a', + expected => 'EQUAL', + comment => 'scalar data, alpha', + dataType => 'SCALAR' + }, + { + key => 'FormParam2', + testValue => 100, + expected => 'EQUAL', + comment => 'scalar data, numeric', + dataType => 'SCALAR' + }, + { + key => 'FormParam3', + testValue => [qw/a b c/], + expected => "a", + comment => 'array data, alpha', + dataType => 'SCALAR' + }, + { + key => 'FormParam4', + testValue => [qw/b c a/], + expected => "b", + comment => 'array data, alpha, non-alpha order', + dataType => 'SCALAR' + }, +); + +my $numTests = scalar @testSets; + +plan tests => $numTests + 2; + +use_ok('WebGUI::Macro::FormParam'); + +auto_check($session, \@testSets); + +sub auto_check { + my ($session, $testBlock) = @_; + my $origSessionRequest = $session->{_request}; + + ##Create a by-name interface to the test to simplify the + ##mocked request. + my %tests = map { $_->{key} => $_ } @{ $testBlock }; + is(scalar keys %tests, scalar @{ $testBlock }, 'no collisions in testBlock'); + + my $request = Test::MockObject->new; + $request->mock('body', + sub { + my ($self, $value) = @_; + return unless exists $tests{$value}; + if (ref $tests{$value}->{testValue} eq "ARRAY") { + return @{ $tests{$value}->{testValue} } ; + } + else { + return $tests{$value}->{testValue}; + } + } + ); + + $session->{_request} = $request; + + foreach my $test ( @{ $testBlock } ) { + $test->{expected} = $test->{testValue} if $test->{expected} eq 'EQUAL'; + my $value = WebGUI::Macro::FormParam::process($session, $test->{key}); + is($value, $test->{expected}, $test->{comment}); + } + + $session->{_request} = $origSessionRequest; +}