Skip to content

Commit

Permalink
fix Macro/FormParam test properly this time
Browse files Browse the repository at this point in the history
  • Loading branch information
haarg committed Jun 15, 2010
1 parent 280d528 commit ad19589
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions t/Macro/FormParam.t
Expand Up @@ -70,35 +70,22 @@ TODO: {

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};
}
}
);
$request->mock('param', sub {shift->body(@_)});

$session->{_request} = $request;
my $param_hash = Hash::MultiValue->from_mixed(
map { $_->{key} => $_->{testValue} } @{ $testBlock }
);
local $session->request->env->{'plack.request.query'} = $param_hash;
local $session->request->env->{'plack.request.body'} = $param_hash;
local $session->request->env->{'plack.request.merged'} = $param_hash;

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;
}

0 comments on commit ad19589

Please sign in to comment.