webgui/t/Session/ErrorHandler.t
Doug Bell babfa74209 Merge branch 'master' into 8-merge
Conflicts:
	docs/gotcha.txt
	lib/WebGUI.pm
	lib/WebGUI/Asset.pm
	lib/WebGUI/Asset/File/GalleryFile/Photo.pm
	lib/WebGUI/Asset/Post.pm
	lib/WebGUI/Asset/Story.pm
	lib/WebGUI/Asset/Template.pm
	lib/WebGUI/Asset/Wobject/Calendar.pm
	lib/WebGUI/Asset/Wobject/GalleryAlbum.pm
	lib/WebGUI/Asset/Wobject/Navigation.pm
	lib/WebGUI/AssetLineage.pm
	lib/WebGUI/AssetTrash.pm
	lib/WebGUI/Config.pm
	lib/WebGUI/Form/Template.pm
	lib/WebGUI/Group.pm
	lib/WebGUI/Inbox.pm
	lib/WebGUI/Workflow/Activity/DeleteExpiredSessions.pm
	lib/WebGUI/Workflow/Activity/TrashExpiredEvents.pm
	sbin/testEnvironment.pl
	t/AdSpace.t
	t/AdSpace/Ad.t
	t/Asset/Asset.t
	t/Asset/AssetExportHtml.t
	t/Asset/AssetLineage.t
	t/Asset/EMSSubmissionForm.t
	t/Asset/Event.t
	t/Asset/File/GalleryFile/Photo/00base.t
	t/Asset/File/GalleryFile/Photo/comment.t
	t/Asset/File/GalleryFile/Photo/download.t
	t/Asset/File/GalleryFile/Photo/edit.t
	t/Asset/File/GalleryFile/Photo/exif.t
	t/Asset/File/GalleryFile/Photo/makeResolutions.t
	t/Asset/File/GalleryFile/Photo/makeShortcut.t
	t/Asset/File/Image/setfile.t
	t/Asset/File/setfile.t
	t/Asset/Post.t
	t/Asset/Post/Thread/getAdjacentThread.t
	t/Asset/Sku.t
	t/Asset/Sku/ProductCollateral.t
	t/Asset/Story.t
	t/Asset/Template.t
	t/Asset/Template/HTMLTemplateExpr.t
	t/Asset/Wobject/Gallery/00base.t
	t/Asset/Wobject/GalleryAlbum/00base.t
	t/Asset/Wobject/GalleryAlbum/ajax.t
	t/Asset/Wobject/GalleryAlbum/delete.t
	t/Asset/Wobject/Matrix.t
	t/Asset/Wobject/StoryArchive.t
	t/Asset/Wobject/Survey/ExpressionEngine.t
	t/Asset/Wobject/Survey/Reports.t
	t/AssetAspect/RssFeed.t
	t/Auth/mech.t
	t/Config.t
	t/Group.t
	t/Help/isa.t
	t/International.t
	t/Mail/Send.t
	t/Operation/AdSpace.t
	t/Operation/Auth.t
	t/Pluggable.t
	t/Session.t
	t/Session/DateTime.t
	t/Session/ErrorHandler.t
	t/Session/Scratch.t
	t/Session/Stow.t
	t/Shop/Cart.t
	t/Shop/Pay.t
	t/Shop/PayDriver/ITransact.t
	t/Shop/PayDriver/PayPalStd.t
	t/Shop/Ship.t
	t/Shop/ShipDriver.t
	t/Shop/TaxDriver/EU.t
	t/Shop/TaxDriver/Generic.t
	t/Shop/Transaction.t
	t/Shop/Vendor.t
	t/VersionTag.t
	t/Workflow/Activity/ArchiveOldStories.t
	t/Workflow/Activity/ExpireIncompleteSurveyResponses.t
	t/lib/WebGUI/Test.pm
2010-07-09 11:48:30 -05:00

117 lines
3.6 KiB
Perl

#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use Test::More;
use Test::MockObject::Extends;
use Try::Tiny;
my $numTests = 13;
plan tests => $numTests;
my $session = WebGUI::Test->session;
##Setup for security method test
my $env = $session->request->env;
$env->{REMOTE_ADDR} = '192.168.0.6';
my $eh = $session->errorHandler;
####################################################
#
# warn, security
#
####################################################
WebGUI::Test->interceptLogging( sub {
my $log_data = shift;
my $accumulated_warn = "";
$eh->warn("This is a warning");
is($log_data->{warn}, "This is a warning", "warn: Log4perl called");
$eh->warn("Second warning");
is($log_data->{warn}, "Second warning", "warn: Log4perl called again");
$eh->security('Shields up, red alert');
my $security = sprintf '%s (%d) connecting from %s attempted to %s',
$session->user->username, $session->user->userId, $session->env->getIp, 'Shields up, red alert';
is($log_data->{warn}, $security, 'security: calls warn with username, userId and IP address');
});
####################################################
#
# info, audit
#
####################################################
WebGUI::Test->interceptLogging( sub {
my $log_data = shift;
$eh->info("This is informative");
is($log_data->{info}, "This is informative", "info: Log4perl called");
$eh->info("More info");
is($log_data->{info}, "More info", "info: Log4perl called again");
$eh->audit('Check this out');
my $audit = sprintf '%s (%d) %s', $session->user->username, $session->user->userId, 'Check this out';
is($log_data->{info}, $audit, 'audit: calls info with username and userId');
});
####################################################
#
# debug
#
####################################################
WebGUI::Test->interceptLogging( sub {
my $log_data = shift;
$eh->debug("This is a bug");
is($log_data->{debug}, "This is a bug", "debug: Log4perl called");
$eh->debug("More bugs");
is($log_data->{debug}, "More bugs", "debug: Log4perl called again");
});
####################################################
#
# error
#
####################################################
WebGUI::Test->interceptLogging( sub {
my $log_data = shift;
$eh->error("ERROR");
is($log_data->{error}, "ERROR", "error: Log4perl called error");
$eh->error("More errors");
is($log_data->{error}, "More errors", "error: Log4perl called error again");
});
####################################################
#
# fatal, stub
#
####################################################
WebGUI::Test->interceptLogging( sub {
my $log_data = shift;
my $thrown = try {
$eh->fatal('Bad things are happenning');
fail 'fatal throws exception';
fail ' ... exception isa WebGUI::Exception::Fatal';
}
catch {
pass 'fatal throws exception';
isa_ok $_, 'WebGUI::Error::Fatal';
};
is $log_data->{fatal}, 'Bad things are happenning', 'fatal: logger called correctly';
});