Provide a way for tests to purge assets with all their (hidden and unreachable)

version tags.  Fix Survey.t that was leaking versionTags.
This commit is contained in:
Colin Kuskie 2009-09-01 22:30:07 +00:00
parent c671e94056
commit 838ae00af5
2 changed files with 35 additions and 20 deletions

View file

@ -36,6 +36,8 @@ my $import_node = WebGUI::Asset->getImportNode($session);
# Create a Survey # Create a Survey
$survey = $import_node->addChild( { className => 'WebGUI::Asset::Wobject::Survey', } ); $survey = $import_node->addChild( { className => 'WebGUI::Asset::Wobject::Survey', } );
my $tag = WebGUI::VersionTag->getWorking($session);
WebGUI::Test->assetsToPurge($survey);
isa_ok($survey, 'WebGUI::Asset::Wobject::Survey'); isa_ok($survey, 'WebGUI::Asset::Wobject::Survey');
my $sJSON = $survey->surveyJSON; my $sJSON = $survey->surveyJSON;
@ -270,11 +272,3 @@ like($storage->getFileContentsAsScalar($filename), qr{
} }
#----------------------------------------------------------------------------
# Cleanup
END {
$survey->purge() if $survey;
my $versionTag = WebGUI::VersionTag->getWorking( $session, 1 );
$versionTag->rollback() if $versionTag;
}

View file

@ -57,6 +57,7 @@ our $logger_error;
my %originalConfig; my %originalConfig;
my $originalSetting; my $originalSetting;
my @assetsToPurge;
my @groupsToDelete; my @groupsToDelete;
my @usersToDelete; my @usersToDelete;
my @sessionsToDelete; my @sessionsToDelete;
@ -172,7 +173,7 @@ END {
my $newUser = WebGUI::User->new($SESSION, $userId); my $newUser = WebGUI::User->new($SESSION, $userId);
$newUser->delete if $newUser; $newUser->delete if $newUser;
} }
foreach my $stor (@storagesToDelete) { STORAGE: foreach my $stor (@storagesToDelete) {
if ($SESSION->id->valid($stor)) { if ($SESSION->id->valid($stor)) {
my $storage = WebGUI::Storage->get($SESSION, $stor); my $storage = WebGUI::Storage->get($SESSION, $stor);
$storage->delete if $storage; $storage->delete if $storage;
@ -207,6 +208,9 @@ END {
$workflow->delete; $workflow->delete;
} }
ASSET: foreach my $asset (@assetsToPurge) {
$asset->purge;
}
if ($ENV{WEBGUI_TEST_DEBUG}) { if ($ENV{WEBGUI_TEST_DEBUG}) {
$Test->diag('Sessions : '.$SESSION->db->quickScalar('select count(*) from userSession')); $Test->diag('Sessions : '.$SESSION->db->quickScalar('select count(*) from userSession'));
$Test->diag('Scratch : '.$SESSION->db->quickScalar('select count(*) from userSessionScratch')); $Test->diag('Scratch : '.$SESSION->db->quickScalar('select count(*) from userSessionScratch'));
@ -502,6 +506,23 @@ sub originalConfig {
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
=head2 assetsToPurge ( $asset, [$asset ] )
Push a list of Asset objects onto the stack of assets to be automatically purged
at the end of the test. This will also clean-up all version tags associated
with the Asset.
This is a class method.
=cut
sub assetsToPurge {
my $class = shift;
push @assetsToPurge, @_;
}
#----------------------------------------------------------------------------
=head2 groupsToDelete ( $group, [$group ] ) =head2 groupsToDelete ( $group, [$group ] )
Push a list of group objects onto the stack of groups to be automatically deleted Push a list of group objects onto the stack of groups to be automatically deleted