From c90fa56507eb2b744dbce84aa4d9ab34b28cef93 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 18 Feb 2009 02:46:59 +0000 Subject: [PATCH] Make WebGUI::PseudoRequest work with fatals. Cookies are now mocked and tied off inside that package. ErrorHandler uses the session request object, instead of RequestUtil. --- lib/WebGUI/Session/ErrorHandler.pm | 5 +++-- t/Session/ErrorHandler.t | 21 ++++++++++++++++++++- t/lib/WebGUI/PseudoRequest.pm | 11 +++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/lib/WebGUI/Session/ErrorHandler.pm b/lib/WebGUI/Session/ErrorHandler.pm index d1610376b..31304500d 100644 --- a/lib/WebGUI/Session/ErrorHandler.pm +++ b/lib/WebGUI/Session/ErrorHandler.pm @@ -17,7 +17,7 @@ package WebGUI::Session::ErrorHandler; use strict; use Log::Log4perl; -use Apache2::RequestUtil; +#use Apache2::RequestUtil; use JSON; use HTML::Entities qw(encode_entities); @@ -220,7 +220,8 @@ sub fatal { local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1; $self->session->http->setStatus("500","Server Error"); - Apache2::RequestUtil->request->content_type('text/html') if ($self->session->request); + #Apache2::RequestUtil->request->content_type('text/html') if ($self->session->request); + $self->session->request->content_type('text/html') if ($self->session->request); $self->getLogger->fatal($message); $self->getLogger->debug("Stack trace for FATAL ".$message."\n".$self->getStackTrace()); $self->session->http->sendHeader if ($self->session->request); diff --git a/t/Session/ErrorHandler.t b/t/Session/ErrorHandler.t index c714458cd..12d0b8ff3 100644 --- a/t/Session/ErrorHandler.t +++ b/t/Session/ErrorHandler.t @@ -18,7 +18,7 @@ use WebGUI::Session; use Test::More; use Test::MockObject::Extends; -my $numTests = 37; +my $numTests = 39; plan tests => $numTests; @@ -223,6 +223,25 @@ foreach my $entry (qw/_debug_error _debug_warn _debug_info _debug_debug/) { my $showDebug = $eh->showDebug; +#################################################### +# +# fatal, stub +# +#################################################### + +my $newSession = WebGUI::Session->open(WebGUI::Test::root, WebGUI::Test::file); +my $outputBuffer; +open my $outputHandle, '>', \$outputBuffer or die "Unable to create scalar filehandle: $!\n"; +$newSession->output->setHandle($outputHandle); +WEBGUI_FATAL: { + $newSession->log->fatal(); +} +ok(1, 'fatal: recovered from fatal okay'); +TODO: { + local $TODO = 'Validate the fatal output'; + ok(0, 'output from fatal when there is a db handler and request present'); +} + END { $session->setting->set('debugIp', $origDebugIp); $session->setting->set('showDebug', $origShowDebug); diff --git a/t/lib/WebGUI/PseudoRequest.pm b/t/lib/WebGUI/PseudoRequest.pm index c9ef80ad1..ed3621b34 100644 --- a/t/lib/WebGUI/PseudoRequest.pm +++ b/t/lib/WebGUI/PseudoRequest.pm @@ -2,6 +2,17 @@ package WebGUI::PseudoRequest; use strict; +use Test::MockObject; + +my $mocker = Test::MockObject->new(); +$mocker->fake_module( + 'Apache2::Cookie', + new => sub { return bless {}, 'Apache2::Cookie'; }, + expires => sub { 1; }, + domain => sub { 1; }, + bake => sub { 1; }, +); + =head1 LEGAL -------------------------------------------------------------------