From b61ef2c91f03ac6b997c997e0c700be84d387616 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sat, 28 Mar 2009 03:53:26 +0000 Subject: [PATCH] Provide a way for config file settings to be restored at the end of a test, via the END block in WebGUI::Test. --- t/lib/WebGUI/Test.pm | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/t/lib/WebGUI/Test.pm b/t/lib/WebGUI/Test.pm index 6f18bacd6..75ee57659 100644 --- a/t/lib/WebGUI/Test.pm +++ b/t/lib/WebGUI/Test.pm @@ -2,6 +2,7 @@ package WebGUI::Test; use strict; use warnings; +use Storable qw/dclone/; =head1 LEGAL @@ -47,6 +48,8 @@ our $logger_debug; our $logger_info; our $logger_error; +my %originalConfig = (); + BEGIN { STDERR->autoflush(1); @@ -135,6 +138,14 @@ END { $Test->diag('Users : '.$SESSION->db->quickScalar('select count(*) from users')); $Test->diag('Groups : '.$SESSION->db->quickScalar('select count(*) from groups')); } + while (my ($key, $value) = each %originalConfig) { + if (defined $value) { + $SESSION->config->set($key, $value); + } + else { + $SESSION->config->delete($key); + } + } $SESSION->var->end; $SESSION->close if defined $SESSION; } @@ -332,6 +343,24 @@ sub session { } +#---------------------------------------------------------------------------- + +=head2 originalConfig ( $param ) + +Stores the original data from the config file, to be restored +automatically at the end of the test. This is a class method. + +=cut + +sub originalConfig { + my ($class, $param) = @_; + my $safeValue = my $value = $SESSION->config->get($param); + if (ref $value) { + $safeValue = dclone $value; + } + $originalConfig{$param} = $safeValue; +} + #---------------------------------------------------------------------------- =head1 BUGS