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;
|
package WebGUI::Form_Checking;
|
||||||
|
|
||||||
use Test::MockObject;
|
|
||||||
use Test::More;
|
use Test::More;
|
||||||
use Test::Deep;
|
use Test::Deep;
|
||||||
|
use Hash::MultiValue;
|
||||||
|
|
||||||
sub auto_check {
|
sub auto_check {
|
||||||
my ($session, $formType, $testBlock) = @_;
|
my ($session, $formType, $testBlock) = @_;
|
||||||
my $origSessionRequest = $session->{_request};
|
|
||||||
|
|
||||||
##Create a by-name interface to the test to simplify the
|
##Create a by-name interface to the test to simplify the
|
||||||
##mocked request.
|
##mocked request.
|
||||||
my %tests = map { $_->{key} => $_ } @{ $testBlock };
|
my %tests = map { $_->{key} => $_ } @{ $testBlock };
|
||||||
is(scalar keys %tests, scalar @{ $testBlock }, 'no collisions in testBlock');
|
is(scalar keys %tests, scalar @{ $testBlock }, 'no collisions in testBlock');
|
||||||
|
|
||||||
my $request = Test::MockObject->new;
|
my $param_hash = Hash::MultiValue->from_mixed(
|
||||||
$request->mock('body',
|
map { $_->{key} => $_->{testValue} } @{ $testBlock }
|
||||||
sub {
|
);
|
||||||
my ($self, $value) = @_;
|
local $session->request->env->{'plack.request.query'} = $param_hash;
|
||||||
return unless exists $tests{$value};
|
local $session->request->env->{'plack.request.body'} = $param_hash;
|
||||||
if (ref $tests{$value}->{testValue} eq "ARRAY") {
|
local $session->request->env->{'plack.request.merged'} = $param_hash;
|
||||||
return @{ $tests{$value}->{testValue} } ;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return $tests{$value}->{testValue};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
$request->mock('param', sub {shift->body(@_)});
|
|
||||||
|
|
||||||
$session->{_request} = $request;
|
|
||||||
|
|
||||||
foreach my $test ( @{ $testBlock } ) {
|
foreach my $test ( @{ $testBlock } ) {
|
||||||
$test->{dataType} ||= 'SCALAR';
|
$test->{dataType} ||= 'SCALAR';
|
||||||
|
|
@ -42,8 +31,6 @@ sub auto_check {
|
||||||
cmp_bag(\@value, $test->{expected}, $test->{comment});
|
cmp_bag(\@value, $test->{expected}, $test->{comment});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$session->{_request} = $origSessionRequest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue