Provide a way for config file settings to be restored at the end of a test,

via the END block in WebGUI::Test.
This commit is contained in:
Colin Kuskie 2009-03-28 03:53:26 +00:00
parent 6f368127be
commit b61ef2c91f

View file

@ -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