add a test for the FormParam macro, and clarify in the docs that FormParam returns only the first value from a list
This commit is contained in:
parent
00de81868b
commit
84117932af
2 changed files with 96 additions and 1 deletions
|
|
@ -18,8 +18,9 @@ our $I18N = {
|
|||
<p><b>^FormParam();</b><br />
|
||||
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");
|
||||
</p>
|
||||
<p>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.</p>
|
||||
|,
|
||||
lastUpdated => 1146679330,
|
||||
lastUpdated => 1154143837,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
94
t/Macro/FormParam.t
Normal file
94
t/Macro/FormParam.t
Normal file
|
|
@ -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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue