Up coverage of addGroups to 100%.

Change tabs to spaces in group diagrams.
Optimize the addGroups membership check so the expensive getGroupsIn
doesn't have to take place.
Add a label to the foreach.
This commit is contained in:
Colin Kuskie 2007-11-26 05:13:32 +00:00
parent 1b3d7f0c2b
commit 8b84ae3e76
2 changed files with 32 additions and 29 deletions

View file

@ -124,15 +124,15 @@ sub addGroups {
my $self = shift;
my $groups = shift;
WebGUI::Cache->new($self->session, $self->getId)->delete;
foreach my $gid (@{$groups}) {
GROUP: foreach my $gid (@{$groups}) {
next if ($gid eq '1');
next if ($gid eq $self->getId);
my ($isIn) = $self->session->db->quickArray("select count(*) from groupGroupings where groupId=? and inGroup=?", [$gid, $self->getId]);
next GROUP if $isIn;
my $group = WebGUI::Group->new($self->session, $gid);
my $recursive = isIn($self->getId, @{$group->getGroupsIn(1)});
unless ($isIn || $recursive) {
$self->session->db->write("insert into groupGroupings (groupId,inGroup) values (?,?)",[$gid, $self->getId]);
}
next GROUP if $recursive;
$self->session->db->write("insert into groupGroupings (groupId,inGroup) values (?,?)",[$gid, $self->getId]);
}
$self->clearCaches();
return 1;

View file

@ -75,7 +75,7 @@ my @ipTests = (
);
plan tests => (138 + scalar(@scratchTests) + scalar(@ipTests)); # increment this value for each test you create
plan tests => (139 + scalar(@scratchTests) + scalar(@ipTests)); # increment this value for each test you create
my $session = WebGUI::Test->session;
my $testCache = WebGUI::Cache->new($session, 'myTestKey');
@ -243,9 +243,9 @@ cmp_bag($gA->getGroupsIn(), [3], 'Group C is not a member of Group A');
cmp_bag($gB->getGroupsIn(1), [$gA->getId, 3], 'Group C is not in Group B, recursively');
cmp_bag($gC->getGroupsFor(), [], 'No groups contain Group C');
# B Z
# / \ / \
# A C Y X
# B Z
# / \ / \
# A C Y X
$gB->addGroups([$gC->getId]);
@ -258,13 +258,13 @@ $gZ->name('Group Z');
$gZ->addGroups([$gX->getId, $gY->getId]);
# B
# / \
# A C
# |
# Z
# / \
# X Y
# B
# / \
# A C
# |
# Z
# / \
# X Y
$gA->addGroups([$gZ->getId]);
cmp_bag($gB->getGroupsIn(1), [$gA->getId, $gC->getId, $gZ->getId, $gY->getId, $gX->getId, 3], 'Add Z tree to A under B');
@ -272,6 +272,9 @@ cmp_bag($gB->getGroupsIn(1), [$gA->getId, $gC->getId, $gZ->getId, $gY->getId, $g
$gX->addGroups([$gA->getId]);
cmp_bag($gX->getGroupsIn(), [3], 'Not able to add B tree under Z tree under X');
$gZ->addGroups([$gX->getId]);
cmp_bag($gZ->getGroupsIn(), [$gX->getId, $gY->getId, 3], 'Not able to add a group when it is already a member of a group');
cmp_bag($gX->getAllGroupsFor(), [ map {$_->getId} ($gZ, $gA, $gB) ], 'getAllGroupsFor X');
cmp_bag($gY->getAllGroupsFor(), [ map {$_->getId} ($gZ, $gA, $gB) ], 'getAllGroupsFor Y');
cmp_bag($gZ->getAllGroupsFor(), [ map {$_->getId} ($gA, $gB) ], 'getAllGroupsFor Z');
@ -406,13 +409,13 @@ my $gK = WebGUI::Group->new($session, "new");
$gK->name('Group K');
$gC->addGroups([$gK->getId]);
# B
# / \
# A C
# | |
# Z K
# / \
# X Y
# B
# / \
# A C
# | |
# Z K
# / \
# X Y
$gK->karmaThreshold(5);
@ -465,13 +468,13 @@ my $gS = WebGUI::Group->new($session, "new");
$gS->name('Group S');
$gC->addGroups([$gS->getId]);
# B
# / \
# A C
# | | \
# Z K S
# / \
# X Y
# B
# / \
# A C
# | | \
# Z K S
# / \
# X Y
$gS->scratchFilter('name=Tom;airport=PDX');