From 06f52bae9ae6c222f75182d4b47519b7913fee01 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 29 Feb 2008 22:09:32 +0000 Subject: [PATCH] Fix how logging gets intercepted. It used to be on by default, now it must be turned on. --- t/Asset/AssetLineage.t | 2 ++ t/Session/DateTime.t | 2 ++ t/Session/ErrorHandler.t | 2 ++ t/Session/Stow.t | 2 ++ t/Storage/Image.t | 3 +++ t/lib/WebGUI/Test.pm | 25 ++++++++++++++++++------- 6 files changed, 29 insertions(+), 7 deletions(-) diff --git a/t/Asset/AssetLineage.t b/t/Asset/AssetLineage.t index 984fc265e..f8d15d3da 100644 --- a/t/Asset/AssetLineage.t +++ b/t/Asset/AssetLineage.t @@ -451,6 +451,8 @@ cmp_bag( my $vTag2 = WebGUI::VersionTag->getWorking($session); $vTag2->set({name=>"deep addChild test"}); +WebGUI::Test->interceptLogging(); + my @deepAsset = ($root); for (1..42) { diff --git a/t/Session/DateTime.t b/t/Session/DateTime.t index fca1337f8..0ad6a6748 100644 --- a/t/Session/DateTime.t +++ b/t/Session/DateTime.t @@ -116,6 +116,8 @@ $session->user({userId => 1}); ##back to Visitor my $wgBdayMail = 'Thu, 16 Aug 2001 08:00:00 -0500'; is ($dt->mailToEpoch($wgBdayMail), $wgbday, 'mailToEpoch'); +WebGUI::Test->interceptLogging(); + is ($dt->mailToEpoch(750), undef, 'mailToEpoch returns undef on failure to parse'); like($WebGUI::Test::logger_warns, qr{750 is not a valid date for email}, "DateTime logs a warning on failure to parse"); diff --git a/t/Session/ErrorHandler.t b/t/Session/ErrorHandler.t index aaf3adfa2..6f5763684 100644 --- a/t/Session/ErrorHandler.t +++ b/t/Session/ErrorHandler.t @@ -36,6 +36,8 @@ my ($eh) = $session->quick('errorHandler'); # #################################################### +WebGUI::Test->interceptLogging(); + my $accumulated_warn = ""; $eh->warn("This is a warning"); is($WebGUI::Test::logger_warns, "This is a warning", "warn: Log4perl called"); diff --git a/t/Session/Stow.t b/t/Session/Stow.t index a89af7477..0475f0691 100644 --- a/t/Session/Stow.t +++ b/t/Session/Stow.t @@ -50,6 +50,8 @@ is($stow->get("Test2"), undef, "deleteAll()"); $session->config->set('disableCache', 1); is($stow->get('Test2'), undef, 'get: when config->disableCache is set get returns undef'); +WebGUI::Test->interceptLogging(); + $stow->set('unavailableVariable', 'too bad'); is($WebGUI::Test::logger_debug, 'Stow->set() is being called but cache has been disabled', 'debug emitted by set when disableCache is true'); diff --git a/t/Storage/Image.t b/t/Storage/Image.t index 8352f3257..8f4768df4 100644 --- a/t/Storage/Image.t +++ b/t/Storage/Image.t @@ -116,6 +116,9 @@ foreach my $extTest ( @{ $extensionTests } ) { # generateThumbnail # #################################################### + +WebGUI::Test->interceptLogging(); + my $thumbStore = WebGUI::Storage::Image->create($session); my $square = WebGUI::Image->new($session, 500, 500); $square->setBackgroundColor('#FF0000'); diff --git a/t/lib/WebGUI/Test.pm b/t/lib/WebGUI/Test.pm index 33c98284b..5f774e875 100644 --- a/t/lib/WebGUI/Test.pm +++ b/t/lib/WebGUI/Test.pm @@ -123,13 +123,6 @@ BEGIN { $SESSION = WebGUI::Session->open( $WEBGUI_ROOT, $CONFIG_FILE ); $SESSION->{_request} = $pseudoRequest; - my $logger = $SESSION->errorHandler->getLogger; - $logger = Test::MockObject::Extends->new( $logger ); - - $logger->mock( 'warn', sub { $WebGUI::Test::logger_warns = $_[1]} ); - $logger->mock( 'debug', sub { $WebGUI::Test::logger_debug = $_[1]} ); - $logger->mock( 'info', sub { $WebGUI::Test::logger_info = $_[1]} ); - $logger->mock( 'error', sub { $WebGUI::Test::logger_error = $_[1]} ); } END { @@ -146,6 +139,24 @@ END { #---------------------------------------------------------------------------- +=head2 interceptLogging + +Intercept logging request and capture them in buffer variables for testing + +=cut + +sub interceptLogging { + my $logger = $SESSION->errorHandler->getLogger; + $logger = Test::MockObject::Extends->new( $logger ); + + $logger->mock( 'warn', sub { $WebGUI::Test::logger_warns = $_[1]} ); + $logger->mock( 'debug', sub { $WebGUI::Test::logger_debug = $_[1]} ); + $logger->mock( 'info', sub { $WebGUI::Test::logger_info = $_[1]} ); + $logger->mock( 'error', sub { $WebGUI::Test::logger_error = $_[1]} ); +} + +#---------------------------------------------------------------------------- + =head2 config Returns the config object from the session.