Conflicts: docs/gotcha.txt docs/previousVersion.sql docs/templates.txt lib/WebGUI.pm lib/WebGUI/Asset.pm lib/WebGUI/Asset/Event.pm lib/WebGUI/Asset/File.pm lib/WebGUI/Asset/MapPoint.pm lib/WebGUI/Asset/RichEdit.pm lib/WebGUI/Asset/Sku/Product.pm lib/WebGUI/Asset/Snippet.pm lib/WebGUI/Asset/Story.pm lib/WebGUI/Asset/Template.pm lib/WebGUI/Asset/Template/TemplateToolkit.pm lib/WebGUI/Asset/Wobject/Calendar.pm lib/WebGUI/Asset/Wobject/Carousel.pm lib/WebGUI/Asset/Wobject/Collaboration.pm lib/WebGUI/Asset/Wobject/Dashboard.pm lib/WebGUI/Asset/Wobject/DataForm.pm lib/WebGUI/Asset/Wobject/Folder.pm lib/WebGUI/Asset/Wobject/Map.pm lib/WebGUI/Asset/Wobject/Search.pm lib/WebGUI/Asset/Wobject/Shelf.pm lib/WebGUI/Asset/Wobject/StockData.pm lib/WebGUI/Asset/Wobject/StoryTopic.pm lib/WebGUI/Asset/Wobject/SyndicatedContent.pm lib/WebGUI/Asset/Wobject/Thingy.pm lib/WebGUI/Asset/Wobject/WeatherData.pm lib/WebGUI/AssetClipboard.pm lib/WebGUI/AssetCollateral/DataForm/Entry.pm lib/WebGUI/AssetExportHtml.pm lib/WebGUI/AssetLineage.pm lib/WebGUI/AssetMetaData.pm lib/WebGUI/AssetTrash.pm lib/WebGUI/AssetVersioning.pm lib/WebGUI/Auth.pm lib/WebGUI/Cache/CHI.pm lib/WebGUI/Content/AssetManager.pm lib/WebGUI/Fork/ProgressBar.pm lib/WebGUI/Form/JsonTable.pm lib/WebGUI/Form/TimeField.pm lib/WebGUI/Form/Zipcode.pm lib/WebGUI/Group.pm lib/WebGUI/International.pm lib/WebGUI/Macro/AssetProxy.pm lib/WebGUI/Macro/FileUrl.pm lib/WebGUI/Operation/SSO.pm lib/WebGUI/Operation/User.pm lib/WebGUI/Role/Asset/Subscribable.pm lib/WebGUI/Shop/Cart.pm lib/WebGUI/Shop/Transaction.pm lib/WebGUI/Shop/TransactionItem.pm lib/WebGUI/Test.pm lib/WebGUI/URL/Content.pm lib/WebGUI/URL/Uploads.pm lib/WebGUI/User.pm lib/WebGUI/Workflow/Activity/ExtendCalendarRecurrences.pm lib/WebGUI/Workflow/Activity/SendNewsletters.pm lib/WebGUI/i18n/English/Asset.pm lib/WebGUI/i18n/English/WebGUI.pm sbin/installClass.pl sbin/rebuildLineage.pl sbin/search.pl sbin/testEnvironment.pl t/Asset/Asset.t t/Asset/AssetClipboard.t t/Asset/AssetLineage.t t/Asset/AssetMetaData.t t/Asset/Event.t t/Asset/File.t t/Asset/File/Image.t t/Asset/Post/notification.t t/Asset/Sku.t t/Asset/Story.t t/Asset/Template.t t/Asset/Wobject/Collaboration/templateVariables.t t/Asset/Wobject/Collaboration/unarchiveAll.t t/Asset/Wobject/Shelf.t t/Auth.t t/Macro/EditableToggle.t t/Macro/FilePump.t t/Shop/Cart.t t/Shop/Transaction.t t/Storage.t t/User.t t/Workflow.t
190 lines
5 KiB
Perl
190 lines
5 KiB
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 strict;
|
|
|
|
use WebGUI::Test;
|
|
use WebGUI::Session;
|
|
use WebGUI::Macro::GroupAdd;
|
|
use Data::Dumper;
|
|
|
|
use Test::More; # increment this value for each test you create
|
|
use HTML::TokeParser;
|
|
use JSON qw/from_json/;
|
|
|
|
my $session = WebGUI::Test->session;
|
|
|
|
my $homeAsset = WebGUI::Test->asset;
|
|
my ($template, $groups, $users) = setupTest($session, $homeAsset);
|
|
|
|
my @testSets = (
|
|
{
|
|
comment => 'Empty macro call returns null string',
|
|
groupName => '',
|
|
text => '',
|
|
template => '',
|
|
empty => 1,
|
|
userId => $users->[2]->userId,
|
|
},
|
|
{
|
|
comment => 'Empty group returns null string',
|
|
groupName => '',
|
|
text => 'Join up',
|
|
template => '',
|
|
empty => 1,
|
|
userId => $users->[2]->userId,
|
|
},
|
|
{
|
|
comment => 'Empty text returns null string',
|
|
groupName => $groups->[0]->name,
|
|
text => '',
|
|
template => '',
|
|
empty => 1,
|
|
userId => $users->[2]->userId,
|
|
},
|
|
{
|
|
comment => 'Visitor sees empty string with valid group and text',
|
|
groupName => $groups->[0]->name(),
|
|
text => 'Join up!',
|
|
template => '',
|
|
empty => 1,
|
|
userId => 1,
|
|
},
|
|
{
|
|
comment => 'Non-existant group returns null string',
|
|
groupName => "Dudes of the day",
|
|
text => 'Join up!',
|
|
template => '',
|
|
empty => 1,
|
|
userId => $users->[2]->userId,
|
|
},
|
|
{
|
|
comment => 'Group without autoAdd returns null string',
|
|
groupName => $groups->[1]->name,
|
|
text => 'Join up!',
|
|
template => '',
|
|
empty => 1,
|
|
userId => $users->[2]->userId,
|
|
},
|
|
{
|
|
comment => 'Existing member of group sees empty string',
|
|
groupName => $groups->[0]->name,
|
|
text => 'Join up!',
|
|
template => '',
|
|
empty => 1,
|
|
userId => $users->[0]->userId,
|
|
},
|
|
{
|
|
comment => 'Non-member of group sees text and link',
|
|
groupName => $groups->[0]->name,
|
|
groupId => $groups->[0]->getId,
|
|
text => 'Join up!',
|
|
template => '',
|
|
empty => 0,
|
|
userId => $users->[2]->userId,
|
|
parser => \&simpleHTMLParser,
|
|
},
|
|
{
|
|
comment => 'Member of different group sees text and link',
|
|
groupName => $groups->[0]->name,
|
|
groupId => $groups->[0]->getId,
|
|
text => 'Join up!',
|
|
template => '',
|
|
empty => 0,
|
|
userId => $users->[1]->userId,
|
|
parser => \&simpleHTMLParser,
|
|
},
|
|
{
|
|
comment => 'Custom template check',
|
|
groupName => $groups->[0]->name,
|
|
groupId => $groups->[0]->getId,
|
|
text => 'Join up!',
|
|
template => $template->get('url'),
|
|
empty => 0,
|
|
userId => $users->[1]->userId,
|
|
parser => \&simpleTextParser,
|
|
},
|
|
);
|
|
|
|
my $numTests = 0;
|
|
foreach my $testSet (@testSets) {
|
|
$numTests += 1 + ($testSet->{empty} == 0);
|
|
}
|
|
|
|
plan tests => $numTests;
|
|
|
|
foreach my $testSet (@testSets) {
|
|
$session->user({ userId => $testSet->{userId} });
|
|
my $output = WebGUI::Macro::GroupAdd::process($session,
|
|
$testSet->{groupName}, $testSet->{text}, $testSet->{template});
|
|
if ($testSet->{empty}) {
|
|
is($output, '', $testSet->{comment});
|
|
}
|
|
else {
|
|
my ($url, $text) = $testSet->{parser}->($output);
|
|
is($text, $testSet->{text}, 'TEXT: '.$testSet->{comment});
|
|
my $expectedUrl = $session->url->page('op=autoAddToGroup;groupId='.$testSet->{groupId});
|
|
is($url, $expectedUrl, 'URL: '.$testSet->{comment});
|
|
}
|
|
}
|
|
|
|
sub setupTest {
|
|
my ($session, $defaultNode) = @_;
|
|
my @groups;
|
|
##Two groups, one with Group Add and one without
|
|
$groups[0] = WebGUI::Group->new($session, "new");
|
|
$groups[0]->name('AutoAdd Group');
|
|
$groups[0]->autoAdd(1);
|
|
$groups[1] = WebGUI::Group->new($session, "new");
|
|
$groups[1]->name('Regular Old Group');
|
|
$groups[1]->autoAdd(0);
|
|
addToCleanup(@groups);
|
|
|
|
##Three users. One in each group and one with no group membership
|
|
my @users = map { WebGUI::User->new($session, "new") } 0..2;
|
|
$users[0]->addToGroups([$groups[0]->getId]);
|
|
$users[1]->addToGroups([$groups[1]->getId]);
|
|
addToCleanup(@users);
|
|
|
|
my $properties = {
|
|
title => 'GroupAdd test template',
|
|
className => 'WebGUI::Asset::Template',
|
|
parser => 'WebGUI::Asset::Template::HTMLTemplate',
|
|
url => 'groupadd-test',
|
|
namespace => 'Macro/GroupAdd',
|
|
template => qq|{"HREF":"<tmpl_var group.url>",\n"LABEL":"<tmpl_var group.text>"}|,
|
|
# '1234567890123456789012'
|
|
id => 'GroupAdd001100Template',
|
|
usePacked => 1,
|
|
};
|
|
my $asset = $defaultNode->addChild($properties, $properties->{id});
|
|
|
|
return $asset, \@groups, \@users;
|
|
}
|
|
|
|
sub simpleHTMLParser {
|
|
my ($text) = @_;
|
|
my $p = HTML::TokeParser->new(\$text);
|
|
|
|
my $token = $p->get_tag("a");
|
|
my $url = $token->[1]{href} || "-";
|
|
my $label = $p->get_trimmed_text("/a");
|
|
|
|
return ($url, $label);
|
|
}
|
|
|
|
sub simpleTextParser {
|
|
my ($text) = @_;
|
|
|
|
my $json_data = from_json($text);
|
|
my ($url, $label) = @{ $json_data }{qw/HREF LABEL/};
|
|
|
|
return ($url, $label);
|
|
}
|