Ready for 7.10.29 development.

This commit is contained in:
Colin Kuskie 2013-03-20 21:38:23 -07:00
commit c806f99b7b
4236 changed files with 1217679 additions and 0 deletions

68
t/Group/group_scratch.t Normal file
View file

@ -0,0 +1,68 @@
# vim:syntax=perl
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use Test::More;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use WebGUI::Group;
#----------------------------------------------------------------------------
# Init
my $session1 = WebGUI::Test->session;
my $session2 = WebGUI::Session->open(WebGUI::Test::root, WebGUI::Test::file);
#----------------------------------------------------------------------------
# Tests
### Updates by DRT test that group membership is restricted by user session
### ...specifically for Visitors to have separate scratch group memberships
plan tests => 14; # Increment this number for each test you create
my $group = WebGUI::Group->new($session1, 'new');
WebGUI::Test->addToCleanup($group);
$group->scratchFilter("itchy=test_value");
is( $group->scratchFilter(), "itchy=test_value",'Group->scratchFilter is properly set and retrieved');
$group->groupCacheTimeout(0);
is( $group->groupCacheTimeout(), 0, 'set groupCacheTimeout to 0');
$session1->user({userId => 1});
$session2->user({userId => 1});
### Test group membership before scratch is set
### NOTE: test hasScratchUser first, because isInGroup sets stow & cache
is ($group->hasScratchUser($session1->user->getId,$session1->user->session->getId), 0, 'Group->hasScratchUser correctly returns 0 for Visitor 1 before scratch is set');
is ($group->hasScratchUser($session2->user->getId,$session2->user->session->getId), 0, 'Group->hasScratchUser correctly returns 0 for Visitor 2 before scratch is set');
ok( !$session1->user->isInGroup($group->getId), 'user1->isInGroup correctly returns 0 before scratch is set');
ok( !$session2->user->isInGroup($group->getId), 'user2->isInGroup correctly returns 0 before scratch is set');
### Test group membership after scratch is set
### Clear stow, which is volatile, to simulate new page view
$session1->stow->deleteAll;
$session2->stow->deleteAll;
$session1->scratch->set('itchy', 'test_value');
is ($group->hasScratchUser($session1->user->getId,$session1->user->session->getId), 1, 'Group->hasScratchUser correctly returns 1 for Visitor 1 after scratch for Visitor 1 is set');
is ($group->hasScratchUser($session2->user->getId,$session2->user->session->getId), 0, 'Group->hasScratchUser correctly returns 0 for Visitor 2 after scratch for Visitor 1 is set');
ok( $session1->user->isInGroup($group->getId), 'user1->isInGroup correctly returns 1 after scratch for Visitor 1 is set');
ok( !$session2->user->isInGroup($group->getId), 'user2->isInGroup correctly returns 0 after scratch for Visitor 1 is set');
### Test group membership after scratch is deleted
### Clear stow, which is volatile, to simulate new page view
$session1->stow->deleteAll;
$session2->stow->deleteAll;
$session1->scratch->delete('itchy');
is ($group->hasScratchUser($session1->user->getId,$session1->user->session->getId), 0, 'Group->hasScratchUser for Visitor 1 correctly returns 0 after clearing scratch for Visitor 1');
is ($group->hasScratchUser($session2->user->getId,$session2->user->session->getId), 0, 'Group->hasScratchUser for Visitor 2 correctly returns 0 after clearing scratch for Visitor 1');
ok( !$session1->user->isInGroup($group->getId), 'user1->isInGroup correctly returns 0 after scratch for Visitor 1 is deleted');
ok( !$session2->user->isInGroup($group->getId), 'user2->isInGroup correctly returns 0 after scratch for Visitor 1 is deleted');

101
t/Group/ldap_groups.t Normal file
View file

@ -0,0 +1,101 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Utility;
use WebGUI::User;
use WebGUI::Group;
use WebGUI::Cache;
use Test::More skip_all => 'Disabled until the test LDAP server is rejuvenated';
use Test::Deep;
my @ldapTests = (
{
dn => 'uid=Byron Hadley,o=shawshank',
comment => 'bad dn for group',
expect => 0,
},
{
dn => 'uid=Andy Dufresne,o=shawshank',
comment => 'good dn for group',
expect => 1,
},
{
dn => 'uid=Bogs Diamond,o=shawshank',
comment => 'another good dn for group',
expect => 1,
},
);
################################################################
#
# LDAP specific group properties
# These tests have to be done on an isolated group that will NEVER
# have getGroups called on it
#
################################################################
my $ldapProps = WebGUI::Test->getSmokeLDAPProps();
$session->db->setRow('ldapLink', 'ldapLinkId', $ldapProps, $ldapProps->{ldapLinkId});
my $ldap = WebGUI::LDAPLink->new($session, $ldapProps->{ldapLinkId});
is($ldap->getValue("ldapLinkId"),$ldapProps->{ldapLinkId},'ldap link created properly');
WebGUI::Test->addToCleanup($ldap);
my @shawshank;
foreach my $idx (0..$#ldapTests) {
$shawshank[$idx] = WebGUI::User->new($session, "new");
$shawshank[$idx]->username("shawshank$idx");
$shawshank[$idx]->authMethod("LDAP");
my $auth = $shawshank[$idx]->authInstance;
$auth->saveParams($shawshank[$idx]->getId,$shawshank[$idx]->authMethod,{
connectDN => $ldapTests[$idx]->{dn},
ldapConnection => $ldap->getValue("ldapLinkId"),
ldapUrl => $ldap->getValue("ldapUrl"),
});
}
WebGUI::Test->addToCleanup(@shawshank);
my $lGroup = WebGUI::Group->new($session, 'new');
$lGroup->ldapGroup('cn=Convicts,o=shawshank');
is($lGroup->ldapGroup(), 'cn=Convicts,o=shawshank', 'ldapGroup set and fetched correctly');
$lGroup->ldapGroupProperty('member');
is($lGroup->ldapGroupProperty(), 'member', 'ldapGroup set and fetched correctly');
$lGroup->ldapLinkId($ldapProps->{ldapLinkId});
is($lGroup->ldapLinkId(),$ldapProps->{ldapLinkId}, 'ldapLinkId set and fetched correctly');
is_deeply(
[ (map { $lGroup->hasLDAPUser($_->getId) } @shawshank) ],
[0, 1, 1],
'shawshank user 2, and 3 found in lGroup users from LDAP'
);
$lGroup->ldapRecursiveProperty('LDAP recursive property');
is($lGroup->ldapRecursiveProperty(), 'LDAP recursive property', 'ldapRecursiveProperty set and fetched correctly');
$lGroup->ldapRecursiveFilter('LDAP recursive filter');
is($lGroup->ldapRecursiveFilter(), 'LDAP recursive filter', 'ldapRecursiveFilter set and fetched correctly');
$lGroup->delete;
done_testing;

180
t/Group/resetGroupFields.t Normal file
View file

@ -0,0 +1,180 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Asset;
use WebGUI::Group;
use Test::More;
use Test::Deep;
plan tests => 10;
my $session = WebGUI::Test->session;
my $assetGroup = WebGUI::Group->new($session, 'new');
WebGUI::Test->addToCleanup($assetGroup);
my $settingGroup = WebGUI::Group->new($session, 'new');
WebGUI::Test->addToCleanup($settingGroup);
my $activityGroup = WebGUI::Group->new($session, 'new');
WebGUI::Test->addToCleanup($activityGroup);
my $home = WebGUI::Asset->getDefault($session);
my $snippet1 = $home->addChild({
className => 'WebGUI::Asset::Snippet',
groupIdEdit => $assetGroup->getId,
groupIdView => 7,
snippet => 'one',
});
my $snippet2 = $home->addChild({
className => 'WebGUI::Asset::Snippet',
groupIdEdit => 7,
groupIdView => 7,
snippet => 'two',
});
my $snippet3 = $home->addChild({
className => 'WebGUI::Asset::Snippet',
groupIdEdit => $assetGroup->getId,
groupIdView => $assetGroup->getId,
snippet => 'three',
});
my $gallery1 = $home->addChild({
className => 'WebGUI::Asset::Wobject::Gallery',
groupIdView => 7,
groupIdEdit => $assetGroup->getId,
groupIdAddComment => $assetGroup->getId,
});
cmp_deeply(
$gallery1->get,
superhashof({
groupIdEdit => $assetGroup->getId,
groupIdView => 7,
groupIdAddComment => $assetGroup->getId,
}),
'gallery set up correctly'
);
cmp_deeply(
$snippet1->get,
superhashof({
groupIdEdit => $assetGroup->getId,
groupIdView => 7,
}),
'groupIdEdit updated on test snippet'
);
my $workflow = WebGUI::Workflow->create($session,
{
enabled => 1,
objectType => 'User',
mode => 'realtime',
},
);
WebGUI::Test->addToCleanup($workflow);
WebGUI::Test->originalConfig('workflowActivities');
$session->config->addToArray('workflowActivities/User', 'WebGUI::Workflow::Activity::AddUserToGroup');
my $userActivity = $workflow->addActivity('WebGUI::Workflow::Activity::AddUserToGroup');
$userActivity->set('className', 'WebGUI::Workflow::Activity::AddUserToGroup');
$userActivity->set('groupId', $activityGroup->getId);
is($userActivity->get('groupId'), $activityGroup->getId, 'group in Workflow Activity set to test group');
###################################################################
#
# Asset tests
#
###################################################################
$assetGroup->delete;
my $newSnippet1 = WebGUI::Asset->newByDynamicClass($session, $snippet1->getId);
cmp_deeply(
$newSnippet1->get,
superhashof({
groupIdEdit => 3,
groupIdView => 7,
}),
'groupIdEdit updated on test snippet'
);
my $newSnippet2 = WebGUI::Asset->newByDynamicClass($session, $snippet2->getId);
cmp_deeply(
$newSnippet2->get,
superhashof({
groupIdEdit => 7,
groupIdView => 7,
}),
'other snippet not touched'
);
my $newSnippet3 = WebGUI::Asset->newByDynamicClass($session, $snippet3->getId);
cmp_deeply(
$newSnippet3->get,
superhashof({
groupIdEdit => 3,
groupIdView => 3,
}),
'multiple fields updated'
);
my $newGallery1 = WebGUI::Asset->newByDynamicClass($session, $gallery1->getId);
cmp_deeply(
$newGallery1->get,
superhashof({
groupIdEdit => 3,
groupIdView => 7,
groupIdAddComment => 3,
}),
'multiple fields and tables updated'
);
###################################################################
#
# Setting tests
#
###################################################################
$session->setting->set('groupIdAdminUser', $settingGroup->getId);
is($session->setting->get('groupIdAdminUser'), $settingGroup->getId, 'group in Setting set up');
$settingGroup->delete;
is($session->setting->get('groupIdAdminUser'), 3, 'group in Setting reset to Admin');
###################################################################
#
# Workflow Activity tests
#
###################################################################
$activityGroup->delete;
my $userActivity2 = WebGUI::Workflow::Activity->new($session, $userActivity->getId);
is ($userActivity2->get('groupId'), 3, 'group in Workflow Activity set to Admin');
WebGUI::Test->addToCleanup(WebGUI::VersionTag->getWorking($session));