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:
parent
6f368127be
commit
b61ef2c91f
1 changed files with 29 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ package WebGUI::Test;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
use Storable qw/dclone/;
|
||||||
|
|
||||||
=head1 LEGAL
|
=head1 LEGAL
|
||||||
|
|
||||||
|
|
@ -47,6 +48,8 @@ our $logger_debug;
|
||||||
our $logger_info;
|
our $logger_info;
|
||||||
our $logger_error;
|
our $logger_error;
|
||||||
|
|
||||||
|
my %originalConfig = ();
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
|
|
||||||
STDERR->autoflush(1);
|
STDERR->autoflush(1);
|
||||||
|
|
@ -135,6 +138,14 @@ END {
|
||||||
$Test->diag('Users : '.$SESSION->db->quickScalar('select count(*) from users'));
|
$Test->diag('Users : '.$SESSION->db->quickScalar('select count(*) from users'));
|
||||||
$Test->diag('Groups : '.$SESSION->db->quickScalar('select count(*) from groups'));
|
$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->var->end;
|
||||||
$SESSION->close if defined $SESSION;
|
$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
|
=head1 BUGS
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue