From 280d5282d9331e7d135f55808ca409156fed1866 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Tue, 15 Jun 2010 07:53:55 -0500 Subject: [PATCH] Revert "fix test" This reverts commit fab0e078f5eaa91326e4034b955c3140a28501dc. --- t/Macro/FormParam.t | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/t/Macro/FormParam.t b/t/Macro/FormParam.t index 4b2f80f7e..c608eaf2f 100644 --- a/t/Macro/FormParam.t +++ b/t/Macro/FormParam.t @@ -18,7 +18,6 @@ use WebGUI::Macro::FormParam; use Test::More; # increment this value for each test you create use Test::MockObject; -use WebGUI::Form_Checking; my $session = WebGUI::Test->session; @@ -60,7 +59,7 @@ $numTests += 3; ##TODO block plan tests => $numTests; -WebGUI::Form_Checking::auto_check($session, \@testSets); +auto_check($session, \@testSets); TODO: { local $TODO = "Tests to write later"; @@ -69,3 +68,37 @@ TODO: { ok(0, "Also try undef"); } +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; + + 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; +}