Provide a way for WebGUI::Test to register groups to clean up at
the end of a test. Convert several tests to use that, including Post.t, which leaked Groups.
This commit is contained in:
parent
0cbe0cc117
commit
ddd06c2ede
4 changed files with 35 additions and 6 deletions
|
|
@ -63,12 +63,14 @@ $testGroups{'canEdit asset'} = WebGUI::Group->new($session, 'new');
|
|||
$testUsers{'canEdit group user'} = WebGUI::User->new($session, 'new');
|
||||
$testUsers{'canEdit group user'}->addToGroups([$testGroups{'canEdit asset'}->getId]);
|
||||
$testUsers{'canEdit group user'}->username('Edit Group User');
|
||||
WebGUI::Test->groupsToDelete($testGroups{'canEdit asset'});
|
||||
|
||||
##A group and user for groupIdEdit
|
||||
$testGroups{'canAdd asset'} = WebGUI::Group->new($session, 'new');
|
||||
$testUsers{'canAdd group user'} = WebGUI::User->new($session, 'new');
|
||||
$testUsers{'canAdd group user'}->addToGroups([$testGroups{'canAdd asset'}->getId]);
|
||||
$testUsers{'canEdit group user'}->username('Can Add Group User');
|
||||
WebGUI::Test->groupsToDelete($testGroups{'canAdd asset'});
|
||||
|
||||
my $canAddMaker = WebGUI::Test::Maker::Permission->new();
|
||||
$canAddMaker->prepare({
|
||||
|
|
@ -819,9 +821,6 @@ END {
|
|||
foreach my $user (values %testUsers) {
|
||||
$user->delete;
|
||||
}
|
||||
foreach my $group (values %testUsers) {
|
||||
$group->delete;
|
||||
}
|
||||
}
|
||||
|
||||
##Return an array of hashrefs. Each hashref describes a test
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ my $otherUser = WebGUI::User->new($session, 'new');
|
|||
my $groupIdEditUser = WebGUI::User->new($session, 'new');
|
||||
my $groupToEditPost = WebGUI::Group->new($session, $collab->get('groupToEditPost'));
|
||||
my $groupIdEditGroup = WebGUI::Group->new($session, $collab->get('groupIdEdit'));
|
||||
WebGUI::Test->groupsToDelete($groupToEditPost, $groupIdEditGroup);
|
||||
$postingUser->username('userForPosting');
|
||||
$otherUser->username('otherUser');
|
||||
|
||||
|
|
|
|||
16
t/Group.t
16
t/Group.t
|
|
@ -233,6 +233,7 @@ my $gB = WebGUI::Group->new($session, "new");
|
|||
$gA->name('Group A');
|
||||
$gB->name('Group B');
|
||||
ok( ($gA->name eq 'Group A' and $gB->name eq 'Group B'), 'object name assignment, multiple objects');
|
||||
WebGUI::Test->groupsToDelete($gA, $gB);
|
||||
|
||||
$gB->addGroups([$gA->getId]);
|
||||
|
||||
|
|
@ -253,6 +254,7 @@ cmp_bag($gA->getGroupsIn(), [3], 'Not allowed to add myself to my group');
|
|||
my $gC = WebGUI::Group->new($session, "new");
|
||||
$gC->name('Group C');
|
||||
$gA->addGroups([$gC->getId]);
|
||||
WebGUI::Test->groupsToDelete($gC);
|
||||
|
||||
cmp_bag($gC->getGroupsFor(), [$gA->getId], 'Group A contains Group C');
|
||||
cmp_bag($gA->getGroupsIn(), [$gC->getId, 3], 'Group C is a member of Group A, cached');
|
||||
|
|
@ -279,6 +281,7 @@ my $gZ = WebGUI::Group->new($session, "new");
|
|||
$gX->name('Group X');
|
||||
$gY->name('Group Y');
|
||||
$gZ->name('Group Z');
|
||||
WebGUI::Test->groupsToDelete($gX, $gY, $gZ);
|
||||
|
||||
$gZ->addGroups([$gX->getId, $gY->getId]);
|
||||
|
||||
|
|
@ -439,6 +442,7 @@ ok( isIn($mob[0]->userId, @{ $gZ->getAllUsers() }), 'mob[0] in list of group Z u
|
|||
my $gK = WebGUI::Group->new($session, "new");
|
||||
$gK->name('Group K');
|
||||
$gC->addGroups([$gK->getId]);
|
||||
WebGUI::Test->groupsToDelete($gK);
|
||||
|
||||
# B
|
||||
# / \
|
||||
|
|
@ -498,6 +502,7 @@ $session->setting->set('useKarma', $defaultKarmaSetting);
|
|||
my $gS = WebGUI::Group->new($session, "new");
|
||||
$gS->name('Group S');
|
||||
$gC->addGroups([$gS->getId]);
|
||||
WebGUI::Test->groupsToDelete($gS);
|
||||
|
||||
# B
|
||||
# / \
|
||||
|
|
@ -579,6 +584,7 @@ foreach my $idx (0..$#ipTests) {
|
|||
}
|
||||
|
||||
my $gI = WebGUI::Group->new($session, "new");
|
||||
WebGUI::Test->groupsToDelete($gI);
|
||||
$gI->name('Group I');
|
||||
$gI->ipFilter('194.168.0.0/24');
|
||||
|
||||
|
|
@ -614,6 +620,7 @@ ok( !$cacheDude->isInGroup($gY->getId), "Cache dude removed from group Y");
|
|||
ok( !$cacheDude->isInGroup($gZ->getId), "Cache dude removed from group Z too");
|
||||
|
||||
my $gCache = WebGUI::Group->new($session, "new");
|
||||
WebGUI::Test->groupsToDelete($gCache);
|
||||
|
||||
$gCache->addUsers([$cacheDude->userId]);
|
||||
|
||||
|
|
@ -642,10 +649,13 @@ SKIP: {
|
|||
ok(undef, "expiration date in groupings for getUser");
|
||||
}
|
||||
|
||||
################################################################
|
||||
#
|
||||
# getUserList
|
||||
#
|
||||
################################################################
|
||||
|
||||
END {
|
||||
foreach my $testGroup ($gX, $gY, $gZ, $gA, $gB, $gI, $gC, $g, $gK, $gS, $gCache) {
|
||||
$testGroup->delete if (defined $testGroup and ref $testGroup eq 'WebGUI::Group');
|
||||
}
|
||||
foreach my $dude ($user, @crowd, @mob, @chameleons, @itchies, @tcps, $cacheDude) {
|
||||
$dude->delete if (defined $dude and ref $dude eq 'WebGUI::User');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ our $logger_error;
|
|||
my %originalConfig;
|
||||
my $originalSetting;
|
||||
|
||||
my @groupsToDelete;
|
||||
|
||||
BEGIN {
|
||||
|
||||
STDERR->autoflush(1);
|
||||
|
|
@ -135,6 +137,9 @@ BEGIN {
|
|||
|
||||
END {
|
||||
my $Test = Test::Builder->new;
|
||||
foreach my $group (@groupsToDelete) {
|
||||
$group->delete;
|
||||
}
|
||||
if ($ENV{WEBGUI_TEST_DEBUG}) {
|
||||
$Test->diag('Sessions: '.$SESSION->db->quickScalar('select count(*) from userSession'));
|
||||
$Test->diag('Scratch : '.$SESSION->db->quickScalar('select count(*) from userSessionScratch'));
|
||||
|
|
@ -369,6 +374,20 @@ sub originalConfig {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 groupsToDelete ( $group, [$group ] )
|
||||
|
||||
Push a list of group objects onto the stack of groups to be automatically deleted
|
||||
at the end of the test.
|
||||
|
||||
=cut
|
||||
|
||||
sub groupsToDelete {
|
||||
my $class = shift;
|
||||
push @groupsToDelete, @_;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
When trying to load the APR module, perl invariably throws an Out Of Memory
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue