Add Asset Dashlets to Dashboard. Add required and static properties to Dashboard Assets. Add caching to StockData and WeatherData assets. Add LastModifiedBy macro. Add GroupManager to the Group form control.
This commit is contained in:
parent
79aa44cf7e
commit
88797c1d6c
42 changed files with 3506 additions and 448 deletions
|
|
@ -172,7 +172,7 @@ sub definition {
|
|||
|
||||
package main;
|
||||
|
||||
plan tests => 134
|
||||
plan tests => 137
|
||||
+ scalar(@fixIdTests)
|
||||
+ scalar(@fixTitleTests)
|
||||
+ 2*scalar(@getTitleTests) #same tests used for getTitle and getMenuTitle
|
||||
|
|
@ -1011,8 +1011,12 @@ $session->http->setRedirectLocation('');
|
|||
is $clippedAsset->checkView(), 'chunked', 'checkView: returns "chunked" when admin is on for cut asset';
|
||||
is $session->http->getRedirectLocation, $clippedAsset->getUrl('func=manageClipboard'), '... cut asset sets redirect to manageClipboard';
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# packed head tags
|
||||
################################################################
|
||||
#
|
||||
# Packed head tags
|
||||
#
|
||||
################################################################
|
||||
|
||||
use HTML::Packer;
|
||||
my $asset = WebGUI::Asset->getImportNode( $session )->addChild({
|
||||
className => 'WebGUI::Asset::Snippet',
|
||||
|
|
@ -1035,6 +1039,30 @@ is $asset->get('extraHeadTagsPacked'), $packed, 'extraHeadTagsPacked';
|
|||
$asset->update({ extraHeadTags => '' });
|
||||
ok !$asset->get('extraHeadTagsPacked'), 'extraHeadTagsPacked cleared';
|
||||
|
||||
################################################################
|
||||
#
|
||||
# getContentLastModifiedBy
|
||||
#
|
||||
################################################################
|
||||
|
||||
{
|
||||
my $revised_user1 = WebGUI::User->new($session, 'new');
|
||||
my $revised_user2 = WebGUI::User->new($session, 'new');
|
||||
WebGUI::Test->addToCleanup($revised_user1, $revised_user2 );
|
||||
$session->user({user => $revised_user1});
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||
my $asset = WebGUI::Asset->getImportNode( $session )->addChild({
|
||||
className => 'WebGUI::Asset::Snippet',
|
||||
}, undef, 12);
|
||||
$versionTag->commit;
|
||||
$asset = $asset->cloneFromDb;
|
||||
WebGUI::Test->addToCleanup($asset, $versionTag);
|
||||
is $asset->getContentLastModifiedBy, $asset->get('revisedBy'), 'getContentLastModifiedBy returns revisedBy for most assets';
|
||||
is $asset->getContentLastModifiedBy, $revised_user1->userId, '... real userId check';
|
||||
$session->user({user => $revised_user2});
|
||||
$asset = $asset->addRevision({ title => 'titular', }, 14);
|
||||
is $asset->getContentLastModifiedBy, $revised_user2->userId, '... check that a new revision tracks';
|
||||
}
|
||||
|
||||
##Return an array of hashrefs. Each hashref describes a test
|
||||
##for the fixId method.
|
||||
|
|
|
|||
67
t/Asset/Wobject/Folder.t
Normal file
67
t/Asset/Wobject/Folder.t
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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 File::Spec;
|
||||
use lib "$FindBin::Bin/../../lib";
|
||||
|
||||
use Test::MockTime qw/:all/; ##Must be loaded before all other code
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use Test::More tests => 3; # increment this value for each test you create
|
||||
use WebGUI::Asset::Wobject::Folder;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
# Do our work in the import node
|
||||
my $node = WebGUI::Asset->getImportNode($session);
|
||||
|
||||
################################################################
|
||||
#
|
||||
# getContentLastModifiedBy
|
||||
#
|
||||
################################################################
|
||||
|
||||
my $revised_user1 = WebGUI::User->new($session, 'new');
|
||||
my $revised_user2 = WebGUI::User->new($session, 'new');
|
||||
WebGUI::Test->addToCleanup($revised_user1, $revised_user2 );
|
||||
$session->user({userId => 3});
|
||||
set_relative_time(-600);
|
||||
WebGUI::Test->addToCleanup(sub { restore_time(); });
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||
my $folder = $node->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Folder',
|
||||
}, undef, 12);
|
||||
$session->user({user => $revised_user1});
|
||||
my $snip1 = $folder->addChild({
|
||||
className => 'WebGUI::Asset::Snippet',
|
||||
}, undef, 14);
|
||||
|
||||
set_relative_time(-500);
|
||||
$session->user({user => $revised_user2});
|
||||
my $snip2 = $folder->addChild({
|
||||
className => 'WebGUI::Asset::Snippet',
|
||||
}, undef, 16);
|
||||
|
||||
$folder = $folder->cloneFromDb;
|
||||
$snip1 = $snip1->cloneFromDb;
|
||||
$snip2 = $snip2->cloneFromDb;
|
||||
WebGUI::Test->addToCleanup($folder);
|
||||
is $folder->getContentLastModifiedBy, $snip2->get('revisedBy'), 'getContentLastModifiedBy returns revisedBy for most recent child asset';
|
||||
is $folder->getContentLastModifiedBy, $revised_user2->userId, '... real userId check';
|
||||
$session->user({user => $revised_user1});
|
||||
|
||||
set_relative_time(-100);
|
||||
|
||||
$snip1 = $snip1->addRevision({ title => 'titular', }, 18);
|
||||
is $folder->getContentLastModifiedBy, $revised_user1->userId, '... check that a new revision tracks';
|
||||
|
||||
|
||||
67
t/Asset/Wobject/Layout.t
Normal file
67
t/Asset/Wobject/Layout.t
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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 File::Spec;
|
||||
use lib "$FindBin::Bin/../../lib";
|
||||
|
||||
use Test::MockTime qw/:all/; ##Must be loaded before all other code
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use Test::More tests => 3; # increment this value for each test you create
|
||||
use WebGUI::Asset::Wobject::Layout;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
# Do our work in the import node
|
||||
my $node = WebGUI::Asset->getImportNode($session);
|
||||
|
||||
################################################################
|
||||
#
|
||||
# getContentLastModifiedBy
|
||||
#
|
||||
################################################################
|
||||
|
||||
my $revised_user1 = WebGUI::User->new($session, 'new');
|
||||
my $revised_user2 = WebGUI::User->new($session, 'new');
|
||||
WebGUI::Test->addToCleanup($revised_user1, $revised_user2 );
|
||||
$session->user({userId => 3});
|
||||
set_relative_time(-600);
|
||||
WebGUI::Test->addToCleanup(sub { restore_time(); });
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||
my $page = $node->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Layout',
|
||||
}, undef, 12);
|
||||
$session->user({user => $revised_user1});
|
||||
my $snip1 = $page->addChild({
|
||||
className => 'WebGUI::Asset::Snippet',
|
||||
}, undef, 14);
|
||||
|
||||
set_relative_time(-500);
|
||||
$session->user({user => $revised_user2});
|
||||
my $snip2 = $page->addChild({
|
||||
className => 'WebGUI::Asset::Snippet',
|
||||
}, undef, 16);
|
||||
|
||||
$page = $page->cloneFromDb;
|
||||
$snip1 = $snip1->cloneFromDb;
|
||||
$snip2 = $snip2->cloneFromDb;
|
||||
WebGUI::Test->addToCleanup($page);
|
||||
is $page->getContentLastModifiedBy, $snip2->get('revisedBy'), 'getContentLastModifiedBy returns revisedBy for most recent child asset';
|
||||
is $page->getContentLastModifiedBy, $revised_user2->userId, '... real userId check';
|
||||
$session->user({user => $revised_user1});
|
||||
|
||||
set_relative_time(-100);
|
||||
|
||||
$snip1 = $snip1->addRevision({ title => 'titular', }, 18);
|
||||
is $page->getContentLastModifiedBy, $revised_user1->userId, '... check that a new revision tracks';
|
||||
|
||||
|
||||
65
t/Asset/Wobject/StockData.t
Normal file
65
t/Asset/Wobject/StockData.t
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
# 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
|
||||
#------------------------------------------------------------------
|
||||
|
||||
# This tests the AssetReport asset
|
||||
#
|
||||
#
|
||||
|
||||
use Test::MockTime qw/:all/;
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../../lib";
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
use JSON;
|
||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Cache;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
my $node = WebGUI::Asset->getImportNode( $session );
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 6; # Increment this number for each test you create
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Asset Report creation
|
||||
my $asset = $node->addChild( {
|
||||
className => 'WebGUI::Asset::Wobject::StockData',
|
||||
source => 'usa',
|
||||
defaultStocks => "GWR",
|
||||
cacheTimeout => 2000,
|
||||
} );
|
||||
WebGUI::Test->addToCleanup($asset);
|
||||
|
||||
my $now = time();
|
||||
set_relative_time(-1000);
|
||||
|
||||
my $stocks = $asset->_getStocks(["GWR"]);
|
||||
is $stocks->{qw/GWR symbol/}, 'GWR', 'stock fetch successful';
|
||||
cmp_ok $stocks->{qw/GWR last_fetch/}, '<', $now-500, 'last_fetch set in the past';
|
||||
my $last_fetch = $stocks->{qw/GWR last_fetch/};
|
||||
|
||||
my $cache = WebGUI::Cache->new($session, [$asset->getId, 'usa', 'GWR']);
|
||||
is $cache->get()->{qw/GWR symbol/}, 'GWR', 'cache loaded with valid data';
|
||||
|
||||
restore_time();
|
||||
|
||||
my $stocks2 = $asset->_getStocks([qw/GWR UNP/]);
|
||||
is $stocks2->{qw/UNP symbol/}, 'UNP', 'stock fetch successful, new stock';
|
||||
is $stocks2->{qw/GWR symbol/}, 'GWR', '... cached stock';
|
||||
is $stocks2->{qw/GWR last_fetch/}, $last_fetch, 'GWR stock lookup was cached';
|
||||
|
||||
#vim:ft=perl
|
||||
111
t/Asset/Wobject/WeatherData.t
Normal file
111
t/Asset/Wobject/WeatherData.t
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
# 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
|
||||
#------------------------------------------------------------------
|
||||
|
||||
# This tests the AssetReport asset
|
||||
#
|
||||
#
|
||||
|
||||
use Test::MockTime qw/:all/;
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../../lib";
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
use Clone qw/clone/;
|
||||
|
||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Cache;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
my $node = WebGUI::Asset->getImportNode( $session );
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
my $can_test = 1;
|
||||
|
||||
my $partnerId = $session->config->get('testing/WeatherData_partnerId');
|
||||
if (!$partnerId) {
|
||||
$partnerId = 'partnerId';
|
||||
$can_test = 0;
|
||||
}
|
||||
|
||||
my $licenseKey = $session->config->get('testing/WeatherData_licenseKey');
|
||||
if (!$licenseKey) {
|
||||
$partnerId = 'licenseKey';
|
||||
$can_test = 0;
|
||||
}
|
||||
|
||||
if ($can_test) {
|
||||
plan tests => 7; # Increment this number for each test you create
|
||||
}
|
||||
else {
|
||||
plan skip_all => 'Missing credentials for Weather.com';
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Asset Report creation
|
||||
|
||||
#1234567890123456789012#
|
||||
my $templateId = 'FAKE_WEATHER_TEMPLATEq';
|
||||
|
||||
my $templateMock = Test::MockObject->new({});
|
||||
$templateMock->set_isa('WebGUI::Asset::Template');
|
||||
$templateMock->set_always('getId', $templateId);
|
||||
my $templateVars;
|
||||
$templateMock->mock('process', sub { $templateVars = clone $_[1]; } );
|
||||
|
||||
my $asset = $node->addChild( {
|
||||
className => 'WebGUI::Asset::Wobject::WeatherData',
|
||||
cacheTimeout => 2000,
|
||||
partnerId => $partnerId,
|
||||
licenseKey => $licenseKey,
|
||||
locations => "53715",
|
||||
templateId => $templateId,
|
||||
} );
|
||||
WebGUI::Test->addToCleanup($asset);
|
||||
|
||||
my $now = time();
|
||||
diag $now;
|
||||
set_relative_time(-1000);
|
||||
diag time();
|
||||
|
||||
WebGUI::Test->mockAssetId($templateId, $templateMock);
|
||||
$asset->prepareView();
|
||||
$asset->view();
|
||||
|
||||
my $weather_data = $templateVars->{'ourLocations.loop'}->[0];
|
||||
|
||||
is $weather_data->{cityState}, 'Madison, WI (53715)', 'data from weather.com returned';
|
||||
my $last_fetch = $weather_data->{last_fetch};
|
||||
diag $last_fetch;
|
||||
cmp_ok $last_fetch, '<', $now-500, 'last_fetch set in the past';
|
||||
|
||||
my $cache = WebGUI::Cache->new($session, [$asset->getId, '53715']);
|
||||
is $cache->get()->{'locations'}->[0]->{cityState}, 'Madison, WI (53715)', 'cache loaded with valid data';
|
||||
|
||||
restore_time();
|
||||
|
||||
$cache = WebGUI::Cache->new($session, [$asset->getId, '53715']);
|
||||
is $cache->get()->{'locations'}->[0]->{cityState}, 'Madison, WI (53715)', 'cache loaded with valid data';
|
||||
|
||||
$asset->update({locations => "53715\n97123"});
|
||||
|
||||
$asset->view();
|
||||
$weather_data = $templateVars->{'ourLocations.loop'};
|
||||
is $weather_data->[1]->{cityState}, 'Hillsboro, OR (97123)', 'weather data fetch successful, new location';
|
||||
is $weather_data->[0]->{cityState}, 'Madison, WI (53715)', '...cached weather data';
|
||||
is $weather_data->[0]->{last_fetch}, $last_fetch, '53715 lookup was cached';
|
||||
|
||||
#vim:ft=perl
|
||||
178
t/Form/Group.t
Normal file
178
t/Form/Group.t
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
|
||||
# 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::Form;
|
||||
use WebGUI::Form::Group;
|
||||
use WebGUI::Group;
|
||||
use WebGUI::Session;
|
||||
|
||||
#The goal of this test is to verify that various www_ methods for the Group plugin work.
|
||||
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
use JSON ();
|
||||
use Data::Dumper;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
# put your tests here
|
||||
|
||||
plan tests => 11;
|
||||
|
||||
my $groupAdminUser = WebGUI::User->new($session, 'new');
|
||||
my $groupAdminGroup = WebGUI::Group->new($session, 'new');
|
||||
$groupAdminGroup->addUsers([$groupAdminUser->userId]);
|
||||
$session->setting->set('groupIdAdminGroup', $groupAdminGroup->getId);
|
||||
WebGUI::Test->addToCleanup($groupAdminUser, $groupAdminGroup);
|
||||
|
||||
my $json;
|
||||
|
||||
$json = WebGUI::Form::Group::www_searchGroups($session);
|
||||
is $json, '{"results":[]}', 'www_searchGroups: unprivileged user is not allowed to use this';
|
||||
|
||||
$session->user({user => $groupAdminUser});
|
||||
$json = WebGUI::Form::Group::www_searchGroups($session);
|
||||
is $json, '{"results":[]}', '... without a body parameter, returns valid empty JSON array';
|
||||
|
||||
$session->request->setup_body({query => 'Registered Users'});
|
||||
$json = WebGUI::Form::Group::www_searchGroups($session);
|
||||
my $group_data = JSON::from_json($json);
|
||||
cmp_deeply(
|
||||
$group_data,
|
||||
{
|
||||
results => [
|
||||
{
|
||||
groupId => 2,
|
||||
groupName => 'Registered Users',
|
||||
},
|
||||
],
|
||||
},
|
||||
'... with an exact match, get one result back'
|
||||
);
|
||||
|
||||
{
|
||||
my @groups = map { my $group = WebGUI::Group->new($session, 'new'); $group->name('Test Group '. $_); $group; } 1..20;
|
||||
my $cleanup = WebGUI::Test->cleanupGuard(@groups);
|
||||
$session->request->setup_body({query => 'Test Group'});
|
||||
$json = WebGUI::Form::Group::www_searchGroups($session);
|
||||
my $group_data = JSON::from_json($json);
|
||||
is scalar @{ $group_data->{results} }, 15, '... results are limited to 15';
|
||||
}
|
||||
|
||||
{
|
||||
my @groups = map { my $group = WebGUI::Group->new($session, 'new'); $group->name('Test Group '. $_); $group; } 1..5;
|
||||
$groups[0]->showInForms(0);
|
||||
my $cleanup = WebGUI::Test->cleanupGuard(@groups);
|
||||
$session->request->setup_body({query => 'Test Group'});
|
||||
$json = WebGUI::Form::Group::www_searchGroups($session);
|
||||
my $group_data = JSON::from_json($json);
|
||||
my $has_group0 = grep { $_->{groupName} eq $groups[0]->name } @{ $group_data->{results} };
|
||||
ok ! $has_group0, '... group with showInForms set to false does not show up in the results';
|
||||
}
|
||||
|
||||
my $test_group = WebGUI::Group->new($session, 'new');
|
||||
$test_group->name('Testing Group');
|
||||
|
||||
my $andy = WebGUI::User->new($session, 'new');
|
||||
$andy->username('andy');
|
||||
|
||||
my $red = WebGUI::User->new($session, 'new');
|
||||
$red->username('red');
|
||||
|
||||
WebGUI::Test->addToCleanup($test_group, $andy, $red);
|
||||
|
||||
$session->request->setup_body({});
|
||||
$session->user({userId => 1});
|
||||
$json = WebGUI::Form::Group::www_groupMembers($session);
|
||||
is $json, '{}', 'www_groupMembers: returns empty hashref for an unprivileged user';
|
||||
|
||||
$session->user({user => $groupAdminUser});
|
||||
$json = WebGUI::Form::Group::www_groupMembers($session);
|
||||
is $json, '{}', '... returns empty hashref if no form variable';
|
||||
|
||||
#1234567890123456789012
|
||||
$session->request->setup_body({groupId => 'neverAWebGUIGroupId001'});
|
||||
$json = WebGUI::Form::Group::www_groupMembers($session);
|
||||
is $json, '{}', 'www_groupMembers: returns empty hashref if no groupId does not exist in the db';
|
||||
|
||||
$session->request->setup_body({groupId => $test_group->getId});
|
||||
$json = WebGUI::Form::Group::www_groupMembers($session);
|
||||
$group_data = JSON::from_json($json);
|
||||
cmp_deeply(
|
||||
$group_data,
|
||||
{
|
||||
groupName => 'Testing Group',
|
||||
users => [ ],
|
||||
groups => [
|
||||
{
|
||||
groupId => '3',
|
||||
groupName => 'Admins',
|
||||
},
|
||||
],
|
||||
},
|
||||
'... with an exact match on an empty group, returns a hashref with arrayrefs'
|
||||
);
|
||||
|
||||
$test_group->addUsers([$andy->getId]);
|
||||
$json = WebGUI::Form::Group::www_groupMembers($session);
|
||||
$group_data = JSON::from_json($json);
|
||||
cmp_deeply(
|
||||
$group_data,
|
||||
{
|
||||
groupName => 'Testing Group',
|
||||
users => [
|
||||
{
|
||||
userId => $andy->userId,
|
||||
username => 'andy',
|
||||
}
|
||||
],
|
||||
groups => [
|
||||
{
|
||||
groupId => '3',
|
||||
groupName => 'Admins',
|
||||
},
|
||||
],
|
||||
},
|
||||
'... with an exact match on a populated group, return users and groups'
|
||||
);
|
||||
|
||||
$test_group->addGroups(['2']);
|
||||
$json = WebGUI::Form::Group::www_groupMembers($session);
|
||||
$group_data = JSON::from_json($json);
|
||||
cmp_deeply(
|
||||
$group_data,
|
||||
{
|
||||
groupName => 'Testing Group',
|
||||
users => [
|
||||
{
|
||||
userId => $andy->userId,
|
||||
username => 'andy',
|
||||
}
|
||||
],
|
||||
groups => bag(
|
||||
{
|
||||
groupId => '2',
|
||||
groupName => 'Registered Users',
|
||||
},
|
||||
{
|
||||
groupId => '3',
|
||||
groupName => 'Admins',
|
||||
},
|
||||
),
|
||||
},
|
||||
'... users not listed recursively, groups do not show up twice'
|
||||
);
|
||||
|
||||
|
||||
74
t/Form/User.t
Normal file
74
t/Form/User.t
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
|
||||
# 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::Form;
|
||||
use WebGUI::Form::User;
|
||||
use WebGUI::Group;
|
||||
use WebGUI::Session;
|
||||
|
||||
#The goal of this test is to verify that various www_ methods for the Group plugin work.
|
||||
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
use JSON ();
|
||||
use Data::Dumper;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
# put your tests here
|
||||
|
||||
plan tests => 4;
|
||||
|
||||
my $userAdminUser = WebGUI::User->new($session, 'new');
|
||||
my $userAdminGroup = WebGUI::Group->new($session, 'new');
|
||||
$userAdminGroup->addUsers([$userAdminUser->userId]);
|
||||
$session->setting->set('groupIdAdminUser', $userAdminGroup->getId);
|
||||
WebGUI::Test->addToCleanup($userAdminUser, $userAdminGroup);
|
||||
|
||||
my $json;
|
||||
|
||||
$json = WebGUI::Form::User::www_searchUsers($session);
|
||||
is $json, '{"results":[]}', 'www_searchUsers: unprivileged user is not allowed to use this';
|
||||
|
||||
$session->user({user => $userAdminUser});
|
||||
$json = WebGUI::Form::User::www_searchUsers($session);
|
||||
is $json, '{"results":[]}', '... without a body parameter, returns valid empty JSON array';
|
||||
|
||||
$session->request->setup_body({query => 'Visitor'});
|
||||
$json = WebGUI::Form::User::www_searchUsers($session);
|
||||
my $group_data = JSON::from_json($json);
|
||||
cmp_deeply(
|
||||
$group_data,
|
||||
{
|
||||
results => [
|
||||
{
|
||||
userId => 1,
|
||||
username => 'Visitor',
|
||||
},
|
||||
],
|
||||
},
|
||||
'... with an exact match, get one result back'
|
||||
);
|
||||
|
||||
{
|
||||
my @users = map { my $user = WebGUI::User->new($session, 'new'); $user->username('Test User '. $_); $user; } 1..20;
|
||||
my $cleanup = WebGUI::Test->cleanupGuard(@users);
|
||||
$session->request->setup_body({query => 'Test User'});
|
||||
$json = WebGUI::Form::User::www_searchUsers($session);
|
||||
my $group_data = JSON::from_json($json);
|
||||
is scalar @{ $group_data->{results} }, 15, '... results are limited to 15';
|
||||
}
|
||||
|
||||
|
||||
71
t/Macro/LastUpdatedBy.t
Normal file
71
t/Macro/LastUpdatedBy.t
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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::User;
|
||||
use WebGUI::Macro::LastUpdatedBy;
|
||||
|
||||
use Test::More; # increment this value for each test you create
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
$session->user({userId => 1});
|
||||
|
||||
my $homeAsset = WebGUI::Asset->getDefault($session);
|
||||
|
||||
my $numTests = 3;
|
||||
|
||||
plan tests => $numTests;
|
||||
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||
addToCleanup($versionTag);
|
||||
|
||||
my $output = WebGUI::Macro::LastUpdatedBy::process($session);
|
||||
is($output, '', "Macro returns '' if no asset is defined");
|
||||
|
||||
##Make the homeAsset the default asset in the session.
|
||||
$session->asset($homeAsset);
|
||||
|
||||
$versionTag->set({name=>"Adding asset for LastUpdatedBy macro tests"});
|
||||
|
||||
my $revised_user = WebGUI::User->new($session, 'new');
|
||||
$revised_user->username('Andy');
|
||||
WebGUI::Test->addToCleanup($revised_user);
|
||||
$session->user({user => $revised_user});
|
||||
|
||||
my $root = WebGUI::Asset->getRoot($session);
|
||||
my %properties_A = (
|
||||
className => 'WebGUI::Asset',
|
||||
title => 'Asset A',
|
||||
url => 'asset-a',
|
||||
ownerUserId => 3,
|
||||
groupIdView => 7,
|
||||
groupIdEdit => 3,
|
||||
id => '1',
|
||||
# '1234567890123456789012',
|
||||
);
|
||||
|
||||
my $assetA = $root->addChild(\%properties_A, $properties_A{id});
|
||||
$versionTag->commit;
|
||||
|
||||
$session->asset($assetA);
|
||||
|
||||
$output = WebGUI::Macro::LastUpdatedBy::process($session);
|
||||
is($output, 'Andy', 'Default asset last revised by andy');
|
||||
|
||||
$revised_user->delete;
|
||||
#$revised_user->uncache;
|
||||
|
||||
$output = WebGUI::Macro::LastUpdatedBy::process($session);
|
||||
is($output, 'Unknown', 'macro returns Unknown when the user object cannot be found');
|
||||
Loading…
Add table
Add a link
Reference in a new issue