fix Form_Checking
This commit is contained in:
parent
26efb0e6b0
commit
0dbabaf733
1 changed files with 7 additions and 20 deletions
|
|
@ -1,34 +1,23 @@
|
|||
package WebGUI::Form_Checking;
|
||||
|
||||
use Test::MockObject;
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
use Hash::MultiValue;
|
||||
|
||||
sub auto_check {
|
||||
my ($session, $formType, $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->{dataType} ||= 'SCALAR';
|
||||
|
|
@ -42,8 +31,6 @@ sub auto_check {
|
|||
cmp_bag(\@value, $test->{expected}, $test->{comment});
|
||||
}
|
||||
}
|
||||
|
||||
$session->{_request} = $origSessionRequest;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue