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:
parent
c671e94056
commit
838ae00af5
2 changed files with 35 additions and 20 deletions
|
|
@ -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;
|
||||||
|
|
@ -177,7 +179,7 @@ cmp_deeply(from_json($surveyEnd), { type => 'forward', url => '/getting_started'
|
||||||
WebGUI::Test->getPage( $survey, 'www_jumpTo', { formParams => {id => '0'} } );
|
WebGUI::Test->getPage( $survey, 'www_jumpTo', { formParams => {id => '0'} } );
|
||||||
is( $session->http->getStatus, '201', 'Page request ok' ); # why is "201 - created" status used??
|
is( $session->http->getStatus, '201', 'Page request ok' ); # why is "201 - created" status used??
|
||||||
is($survey->responseJSON->nextResponse, 0, 'S0 is the first response');
|
is($survey->responseJSON->nextResponse, 0, 'S0 is the first response');
|
||||||
|
|
||||||
tie my %expectedSurveyOrder, 'Tie::IxHash';
|
tie my %expectedSurveyOrder, 'Tie::IxHash';
|
||||||
%expectedSurveyOrder = (
|
%expectedSurveyOrder = (
|
||||||
'undefined' => 0,
|
'undefined' => 0,
|
||||||
|
|
@ -200,16 +202,16 @@ cmp_deeply(from_json($surveyEnd), { type => 'forward', url => '/getting_started'
|
||||||
$session->db->write('delete from Survey_response where assetId = ?', [$survey->getId]);
|
$session->db->write('delete from Survey_response where assetId = ?', [$survey->getId]);
|
||||||
delete $survey->{responseId};
|
delete $survey->{responseId};
|
||||||
delete $survey->{surveyJSON};
|
delete $survey->{surveyJSON};
|
||||||
|
|
||||||
my $surveyId = $survey->getId;
|
my $surveyId = $survey->getId;
|
||||||
my $revisionDate = WebGUI::Asset->getCurrentRevisionDate($session, $surveyId);
|
my $revisionDate = WebGUI::Asset->getCurrentRevisionDate($session, $surveyId);
|
||||||
ok($revisionDate, 'Revision Date initially defined');
|
ok($revisionDate, 'Revision Date initially defined');
|
||||||
|
|
||||||
# Modify Survey structure, new revision not created
|
# Modify Survey structure, new revision not created
|
||||||
$survey->submitObjectEdit({ id => "0", text => "new text"});
|
$survey->submitObjectEdit({ id => "0", text => "new text"});
|
||||||
is($survey->surveyJSON->section([0])->{text}, 'new text', 'Survey updated');
|
is($survey->surveyJSON->section([0])->{text}, 'new text', 'Survey updated');
|
||||||
is($session->db->quickScalar('select revisionDate from Survey where assetId = ?', [$surveyId]), $revisionDate, 'Revision unchanged');
|
is($session->db->quickScalar('select revisionDate from Survey where assetId = ?', [$surveyId]), $revisionDate, 'Revision unchanged');
|
||||||
|
|
||||||
# Push revisionDate into the past because we can't have 2 revision dates with the same epoch (this is very hacky)
|
# Push revisionDate into the past because we can't have 2 revision dates with the same epoch (this is very hacky)
|
||||||
$revisionDate--;
|
$revisionDate--;
|
||||||
$session->stow->deleteAll();
|
$session->stow->deleteAll();
|
||||||
|
|
@ -217,11 +219,11 @@ cmp_deeply(from_json($surveyEnd), { type => 'forward', url => '/getting_started'
|
||||||
$session->db->write('update Survey set revisionDate = ? where assetId = ?', [$revisionDate, $surveyId]);
|
$session->db->write('update Survey set revisionDate = ? where assetId = ?', [$revisionDate, $surveyId]);
|
||||||
$session->db->write('update assetData set revisionDate = ? where assetId = ?', [$revisionDate, $surveyId]);
|
$session->db->write('update assetData set revisionDate = ? where assetId = ?', [$revisionDate, $surveyId]);
|
||||||
$session->db->write('update wobject set revisionDate = ? where assetId = ?', [$revisionDate, $surveyId]);
|
$session->db->write('update wobject set revisionDate = ? where assetId = ?', [$revisionDate, $surveyId]);
|
||||||
|
|
||||||
$survey = WebGUI::Asset->new($session, $surveyId);
|
$survey = WebGUI::Asset->new($session, $surveyId);
|
||||||
isa_ok($survey, 'WebGUI::Asset::Wobject::Survey', 'Got back survey after monkeying with revisionDate');
|
isa_ok($survey, 'WebGUI::Asset::Wobject::Survey', 'Got back survey after monkeying with revisionDate');
|
||||||
is($session->db->quickScalar('select revisionDate from Survey where assetId = ?', [$surveyId]), $revisionDate, 'Revision date pushed back');
|
is($session->db->quickScalar('select revisionDate from Survey where assetId = ?', [$surveyId]), $revisionDate, 'Revision date pushed back');
|
||||||
|
|
||||||
# Create new response
|
# Create new response
|
||||||
my $responseId = $survey->responseId;
|
my $responseId = $survey->responseId;
|
||||||
is(
|
is(
|
||||||
|
|
@ -229,26 +231,26 @@ cmp_deeply(from_json($surveyEnd), { type => 'forward', url => '/getting_started'
|
||||||
$revisionDate,
|
$revisionDate,
|
||||||
'Pushed back revisionDate used for new response'
|
'Pushed back revisionDate used for new response'
|
||||||
);
|
);
|
||||||
|
|
||||||
# Make another change, causing new revision to be automatically created
|
# Make another change, causing new revision to be automatically created
|
||||||
$survey->submitObjectEdit({ id => "0", text => "newer text"});
|
$survey->submitObjectEdit({ id => "0", text => "newer text"});
|
||||||
|
|
||||||
my $newerSurvey = WebGUI::Asset->new($session, $surveyId); # retrieve newer revision
|
my $newerSurvey = WebGUI::Asset->new($session, $surveyId); # retrieve newer revision
|
||||||
isa_ok($newerSurvey, 'WebGUI::Asset::Wobject::Survey', 'After change, re-retrieved Survey instance');
|
isa_ok($newerSurvey, 'WebGUI::Asset::Wobject::Survey', 'After change, re-retrieved Survey instance');
|
||||||
is($newerSurvey->getId, $surveyId, '..which is the same survey');
|
is($newerSurvey->getId, $surveyId, '..which is the same survey');
|
||||||
is($newerSurvey->surveyJSON->section([0])->{text}, 'newer text', '..with updated text');
|
is($newerSurvey->surveyJSON->section([0])->{text}, 'newer text', '..with updated text');
|
||||||
ok($newerSurvey->get('revisionDate') > $revisionDate, '..and newer revisionDate');
|
ok($newerSurvey->get('revisionDate') > $revisionDate, '..and newer revisionDate');
|
||||||
|
|
||||||
# Create another response (this one will use the new revision)
|
# Create another response (this one will use the new revision)
|
||||||
my $newUser = WebGUI::User->new( $session, 'new' );
|
my $newUser = WebGUI::User->new( $session, 'new' );
|
||||||
WebGUI::Test->usersToDelete($newUser);
|
WebGUI::Test->usersToDelete($newUser);
|
||||||
$session->user({ user => $newUser });
|
$session->user({ user => $newUser });
|
||||||
my $newResponseId = $survey->responseId;
|
my $newResponseId = $survey->responseId;
|
||||||
is($newerSurvey->responseJSON->nextResponseSection()->{text}, 'newer text', 'New response uses the new text');
|
is($newerSurvey->responseJSON->nextResponseSection()->{text}, 'newer text', 'New response uses the new text');
|
||||||
|
|
||||||
# And the punch line..
|
# And the punch line..
|
||||||
is($survey->responseJSON->nextResponseSection()->{text}, 'new text', '..wheras the original response uses the original text');
|
is($survey->responseJSON->nextResponseSection()->{text}, 'new text', '..wheras the original response uses the original text');
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue