Merge branch 'master' of git@github.com:plainblack/webgui

Conflicts:

	lib/WebGUI/Asset/Wobject/EventManagementSystem.pm
	lib/WebGUI/i18n/English/Asset_EventManagementSystem.pm
This commit is contained in:
daviddelikat 2009-10-31 10:05:59 -05:00
commit b645d3e1b2
44 changed files with 941 additions and 577 deletions

View file

@ -49,7 +49,7 @@ $versionTag->set({name=>"EventManagementSystem Test"});
#----------------------------------------------------------------------------
# Tests
plan tests => 35 ; # Increment this number for each test you create
plan tests => 41; # Increment this number for each test you create
#----------------------------------------------------------------------------
@ -128,16 +128,26 @@ ok(scalar(@$badges) == 2, 'Two Badges exist');
# Add tickets
my @tickets;
push(@tickets, $ems->addChild({
className => 'WebGUI::Asset::Sku::EMSTicket',
startDate => '2009-01-01 14:00:00',
eventNumber => 1,
location => 'qq',
className => 'WebGUI::Asset::Sku::EMSTicket',
title => 'Test Ticket 1',
url => 'test-ems/ticket-1',
startDate => '2009-01-01 14:00:00',
eventNumber => 1,
location => 'qq',
seatsAvailable => 5,
price => 5,
duration => 1,
}));
push(@tickets, $ems->addChild({
className => 'WebGUI::Asset::Sku::EMSTicket',
startDate => '2009-01-01 14:00:00',
eventNumber => 2,
location => 'qq',
className => 'WebGUI::Asset::Sku::EMSTicket',
title => 'Test Ticket 2',
url => 'test-ems/ticket-2',
startDate => '2009-01-01 14:00:00',
eventNumber => 2,
location => 'qq',
seatsAvailable => 3,
price => 10,
duration => 2,
}));
foreach my $ticket(@tickets) {
@ -163,17 +173,198 @@ ok(scalar(@$ribbons) == 2, 'Two ribbons exist');
ok( $ems->can('www_getScheduleDataJSON'), 'Can call get Schedule data' );
ok( $ems->can('www_viewSchedule'), 'Can call view Schedule' );
ok( $ems->can('www_printRemainingTickets'), 'Can call print remaining tickets' );
#Test that the default template is correct
my $printRemainingTicketsTemplateId = $ems->get('printRemainingTicketsTemplateId');
is($printRemainingTicketsTemplateId, "hreA_bgxiTX-EzWCSZCZJw", 'Default print remaining tickets template id ok');
#Make sure printRemainingTickets template returns the right data
my $templateMock = Test::MockObject->new({});
$templateMock->set_isa('WebGUI::Asset::Template');
$templateMock->set_always('getId', $printRemainingTicketsTemplateId);
my $templateVars;
$templateMock->mock('process', sub { $templateVars = $_[1]; } );
{
WebGUI::Test->mockAssetId($printRemainingTicketsTemplateId, $templateMock);
$ems->www_printRemainingTickets();
my $ticket1 = {
'seatsRemaining' => '5',
'ticketTitle' => 'Test Ticket 1',
'newWindow' => ignore(),
'extraHeadTagsPacked' => ignore(),
'synopsis' => ignore(),
'extraHeadTags' => ignore(),
'ownerUserId' => ignore(),
'url' => 'test-ems/ticket-1',
'assetId' => ignore(),
'isPrototype' => ignore(),
'isHidden' => ignore(),
'groupIdEdit' => ignore(),
'inheritUrlFromParent' => ignore(),
'ticketEventNumber' => '1',
'lastModified' => ignore(),
'price' => '5',
'title' => 'Test Ticket 1',
'groupIdView' => ignore(),
'ticketLocation' => 'qq',
'skipNotification' => ignore(),
'status' => ignore(),
'menuTitle' => 'Test Ticket 1',
'assetSize' => ignore(),
'ticketDuration' => '1',
'relatedRibbons' => ignore(),
'revisionDate' => ignore(),
'relatedBadgeGroups' => ignore(),
'isPackage' => ignore(),
'usePackedHeadTags' => ignore(),
'encryptPage' => ignore(),
'tagId' => ignore(),
'seatsAvailable' => '5',
'revisedBy' => ignore(),
'isExportable' => ignore(),
'creationDate' => ignore(),
'ticketStart' => '2009-01-01 14:00:00'
};
my $ticket2 = {
'seatsRemaining' => '3',
'ticketTitle' => 'Test Ticket 2',
'newWindow' => ignore(),
'extraHeadTagsPacked' => ignore(),
'synopsis' => ignore(),
'extraHeadTags' => ignore(),
'ownerUserId' => ignore(),
'url' => 'test-ems/ticket-2',
'assetId' => ignore(),
'isPrototype' => ignore(),
'isHidden' => ignore(),
'groupIdEdit' => ignore(),
'inheritUrlFromParent' => ignore(),
'ticketEventNumber' => '2',
'lastModified' => ignore(),
'price' => '10',
'title' => 'Test Ticket 2',
'groupIdView' => ignore(),
'ticketLocation' => 'qq',
'skipNotification' => ignore(),
'status' => ignore(),
'menuTitle' => 'Test Ticket 2',
'assetSize' => ignore(),
'ticketDuration' => '2',
'relatedRibbons' => ignore(),
'revisionDate' => ignore(),
'relatedBadgeGroups' => ignore(),
'isPackage' => ignore(),
'usePackedHeadTags' => ignore(),
'encryptPage' => ignore(),
'tagId' => ignore(),
'seatsAvailable' => '3',
'revisedBy' => ignore(),
'isExportable' => ignore(),
'creationDate' => ignore(),
'ticketStart' => '2009-01-01 14:00:00'
};
my @ticketArray = ();
for(1..3) {
push(@ticketArray,$ticket2);
}
for(1..5) {
push(@ticketArray,$ticket1);
}
cmp_deeply(
$templateVars,
{
'badgeInstructions' => ignore(),
'displayTitle' => ignore(),
'createdBy' => ignore(),
'lastExportedAs' => ignore(),
'printRemainingTicketsTemplateId' => ignore(),
'state' => ignore(),
'printTicketTemplateId' => ignore(),
'newWindow' => ignore(),
'scheduleColumnsPerPage' => ignore(),
'synopsis' => ignore(),
'extraHeadTagsPacked' => ignore(),
'ownerUserId' => ignore(),
'extraHeadTags' => ignore(),
'assetId' => ignore(),
'url' => 'test-ems',
'isHidden' => ignore(),
'isPrototype' => ignore(),
'groupIdEdit' => ignore(),
'timezone' => ignore(),
'styleTemplateId' => ignore(),
'inheritUrlFromParent' => ignore(),
'description' => 'This is a test ems',
'stateChangedBy' => ignore(),
'lineage' => ignore(),
'className' => 'WebGUI::Asset::Wobject::EventManagementSystem',
'groupToApproveEvents' => ignore(),
'lastModified' => ignore(),
'title' => 'Test EMS',
'groupIdView' => ignore(),
'mobileStyleTemplateId' => ignore(),
'skipNotification' => ignore(),
'scheduleTemplateId' => ignore(),
'status' => ignore(),
'menuTitle' => 'Test EMS',
'assetSize' => ignore(),
'lookupRegistrantTemplateId' => ignore(),
'isLockedBy' => ignore(),
'stateChanged' => ignore(),
'revisionDate' => ignore(),
'ribbonInstructions' => ignore(),
'isPackage' => ignore(),
'usePackedHeadTags' => ignore(),
'templateId' => ignore(),
'badgeBuilderTemplateId' => ignore(),
'printBadgeTemplateId' => ignore(),
'encryptPage' => ignore(),
'tagId' => ignore(),
'isSystem' => ignore(),
'revisedBy' => ignore(),
'isExportable' => ignore(),
'creationDate' => ignore(),
'registrationStaffGroupId' => ignore(),
'parentId' => ignore(),
'tokenInstructions' => ignore(),
'printableStyleTemplateId' => ignore(),
'ticketInstructions' => ignore(),
'tickets_loop' => \@ticketArray,
},
"www_printRemainingTickets: template variables valid"
);
WebGUI::Test->unmockAssetId($printRemainingTicketsTemplateId);
}
#Make sure permissions work on pages
my $data;
$session->user({userId => $crasher->getId});
$session->http->setStatus(201);
$data = $ems->www_viewSchedule();
is($session->http->getStatus, 401, 'www_viewSchedule: visitor may not see the schedule');
$data = $ems->www_printRemainingTickets();
is($session->http->getStatus, 401, 'www_printRemainingTickets: visitor may not print the remaining tickets');
$session->http->setStatus(201);
$session->user({userId => $attender->getId});
$data = $ems->www_viewSchedule();
is($session->http->getStatus, 201, '... attender user can see the schedule');
$data = $ems->www_printRemainingTickets();
is($session->http->getStatus, 401, 'www_printRemainingTickets: attender may not print the remaining tickets');
$session->http->setStatus(201);
$session->user({userId => $registrar->getId});
$data = $ems->www_printRemainingTickets();
is($session->http->getStatus, 201, 'www_printRemainingTickets: registration staff may print the remaining tickets');
$session->http->setStatus(201);
$session->user({userId => $crasher->getId});

View file

@ -17,7 +17,7 @@ use WebGUI::Keyword;
use WebGUI::Asset;
# load your modules here
use Test::More tests => 14; # increment this value for each test you create
use Test::More tests => 15; # increment this value for each test you create
use Test::Deep;
use Data::Dumper;
@ -94,6 +94,12 @@ cmp_deeply(
'... retrieving assets in more than one state'
);
cmp_deeply(
$keyword->getTopKeywords(),
{ 'webgui' => '2' },
'check getTopKeywords returns correctly'
);
$keyword->deleteKeywordsForAsset($home);
is(scalar(@{$keyword->getKeywordsForAsset({ asset=>$home, asArrayRef=>1})}), 0, "getKeywordsForAsset()");

View file

@ -15,6 +15,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use Data::Dumper;
use WebGUI::Macro::Env;
use Test::More; # increment this value for each test you create
@ -27,17 +28,10 @@ my $session = WebGUI::Test->session;
my %env = %{ $session->env->{_env} };
my @keys = keys %env;
my $numTests = 1 + 3 + scalar keys %env;
my $numTests = 3 + scalar keys %env;
plan tests => $numTests;
my $macro = 'WebGUI::Macro::Env';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
my $output;
$output = WebGUI::Macro::Env::process($session, '');
@ -53,5 +47,3 @@ foreach my $key (keys %env) {
my $output = WebGUI::Macro::Env::process($session, $key);
is($output, $env{$key}, 'Fetching: '.$key);
}
}

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::FetchMimeType;
use Test::More; # increment this value for each test you create
@ -49,17 +50,8 @@ my @testSets = (
my $numTests = scalar @testSets;
$numTests += 1; #For the use_ok
plan tests => $numTests;
my $macro = 'WebGUI::Macro::FetchMimeType';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
foreach my $testSet (@testSets) {
my $file = $testSet->{input}
? join '/', WebGUI::Test->root, 'www/extras', $testSet->{input}
@ -67,5 +59,3 @@ foreach my $testSet (@testSets) {
my $output = WebGUI::Macro::FetchMimeType::process($session, $file);
is($output, $testSet->{output}, $testSet->{comment} );
}
}

View file

@ -16,6 +16,7 @@ use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Storage;
use Data::Dumper;
use WebGUI::Macro::FileUrl;
use Test::More; # increment this value for each test you create
@ -85,21 +86,13 @@ my @testSets = (
my $numTests = scalar @testSets;
$numTests += 1; #For the use_ok
$numTests += 1; #non-existant URL
plan tests => $numTests;
my $macro = 'WebGUI::Macro::FileUrl';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
my $homeAsset = WebGUI::Asset->getDefault($session);
my ($versionTag, @testSets) = setupTest($session, $homeAsset, @testSets);
my @testSets = setupTest($session, $homeAsset, @testSets);
foreach my $testSet (@testSets) {
my $output = WebGUI::Macro::FileUrl::process($session, $testSet->{url});
@ -114,8 +107,6 @@ foreach my $testSet (@testSets) {
my $output = WebGUI::Macro::FileUrl::process($session, "non-existant-url");
is($output, $i18n->get('invalid url'), "Non-existant url returns error message");
}
sub setupTest {
my ($session, $homeAsset, @testSets) = @_;
my $versionTag = WebGUI::VersionTag->getWorking($session);
@ -145,9 +136,6 @@ sub setupTest {
++$testNum;
}
$versionTag->commit;
WebGUI::Test->tagsToRollback($versionTag);
return $versionTag, @testSets;
}
END { ##Clean-up after yourself, always
addToCleanup($versionTag);
return @testSets;
}

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::FormParam;
use Test::More; # increment this value for each test you create
use Test::MockObject;
@ -53,23 +54,13 @@ my @testSets = (
my $numTests = scalar @testSets;
$numTests += 1; ##use_ok
$numTests += 1; ##testBlock has no name collisions
$numTests += 3; ##TODO block
plan tests => $numTests;
my $macro = 'WebGUI::Macro::FormParam';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
auto_check($session, \@testSets);
}
TODO: {
local $TODO = "Tests to write later";
ok(0, "What will this do with a non-existant form param?");

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::GroupAdd;
use Data::Dumper;
use Test::More; # increment this value for each test you create
@ -22,7 +23,7 @@ use HTML::TokeParser;
my $session = WebGUI::Test->session;
my $homeAsset = WebGUI::Asset->getDefault($session);
my ($versionTag, $template, $groups, $users) = setupTest($session, $homeAsset);
my ($template, $groups, $users) = setupTest($session, $homeAsset);
my @testSets = (
{
@ -118,17 +119,8 @@ foreach my $testSet (@testSets) {
$numTests += 1 + ($testSet->{empty} == 0);
}
$numTests += 1; #For the use_ok
plan tests => $numTests;
my $macro = 'WebGUI::Macro::GroupAdd';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
foreach my $testSet (@testSets) {
$session->user({ userId => $testSet->{userId} });
my $output = WebGUI::Macro::GroupAdd::process($session,
@ -144,8 +136,6 @@ foreach my $testSet (@testSets) {
}
}
}
sub setupTest {
my ($session, $defaultNode) = @_;
my @groups;
@ -156,13 +146,13 @@ sub setupTest {
$groups[1] = WebGUI::Group->new($session, "new");
$groups[1]->name('Regular Old Group');
$groups[1]->autoAdd(0);
WebGUI::Test->groupsToDelete(@groups);
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]);
WebGUI::Test->usersToDelete(@users);
addToCleanup(@users);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"GroupAdd test"});
@ -178,8 +168,9 @@ sub setupTest {
};
my $asset = $defaultNode->addChild($properties, $properties->{id});
$versionTag->commit;
addToCleanup($versionTag);
return $versionTag, $asset, \@groups, \@users;
return $asset, \@groups, \@users;
}
sub simpleHTMLParser {
@ -201,9 +192,3 @@ sub simpleTextParser {
return ($url, $label);
}
END { ##Clean-up after yourself, always
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') {
$versionTag->rollback;
}
}

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::GroupDelete;
use Data::Dumper;
use Test::More; # increment this value for each test you create
@ -22,7 +23,7 @@ use HTML::TokeParser;
my $session = WebGUI::Test->session;
my $homeAsset = WebGUI::Asset->getDefault($session);
my ($versionTag, $template, $groups, $users) = setupTest($session, $homeAsset);
my ($template, $groups, $users) = setupTest($session, $homeAsset);
my @testSets = (
{
@ -118,17 +119,8 @@ foreach my $testSet (@testSets) {
$numTests += 1 + ($testSet->{empty} == 0);
}
$numTests += 1; #For the use_ok
plan tests => $numTests;
my $macro = 'WebGUI::Macro::GroupDelete';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
foreach my $testSet (@testSets) {
$session->user({ userId => $testSet->{userId} });
my $output = WebGUI::Macro::GroupDelete::process($session,
@ -144,8 +136,6 @@ foreach my $testSet (@testSets) {
}
}
}
sub setupTest {
my ($session, $defaultNode) = @_;
my @groups;
@ -156,13 +146,13 @@ sub setupTest {
$groups[1] = WebGUI::Group->new($session, "new");
$groups[1]->name('Regular Old Group');
$groups[1]->autoDelete(0);
WebGUI::Test->groupsToDelete(@groups);
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]);
WebGUI::Test->usersToDelete(@users);
addToCleanup(@users);
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"GroupDelete test"});
@ -178,8 +168,9 @@ sub setupTest {
};
my $asset = $defaultNode->addChild($properties, $properties->{id});
$versionTag->commit;
addToCleanup($versionTag);
return $versionTag, $asset, \@groups, \@users;
return $asset, \@groups, \@users;
}
sub simpleHTMLParser {
@ -201,9 +192,3 @@ sub simpleTextParser {
return ($url, $label);
}
END { ##Clean-up after yourself, always
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') {
$versionTag->rollback;
}
}

View file

@ -16,6 +16,7 @@ use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Group;
use WebGUI::User;
use WebGUI::Macro::GroupText;
my $session = WebGUI::Test->session;
@ -24,21 +25,13 @@ use Test::More; # increment this value for each test you create
my $numTests;
$numTests = 3; #Direct Macro tests
$numTests += 4; #Bug tests
$numTests += 1; #For the use_ok
plan tests => $numTests;
my $macro = 'WebGUI::Macro::GroupText';
my $loaded = use_ok($macro);
my @mob;
my ($ms_users, $ms_distributors, $ms_int_distributors);
my ($disti, $int_disti);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
my $output;
$session->user({userId => 1});
@ -65,14 +58,14 @@ my $sth = $session->db->prepare('INSERT INTO myUserTable VALUES(?)');
foreach my $mob (@mob) {
$sth->execute([ $mob->userId ]);
}
WebGUI::Test->usersToDelete(@mob);
addToCleanup(@mob);
##Create the 3 groups
$ms_users = WebGUI::Group->new($session, "new");
$ms_distributors = WebGUI::Group->new($session, "new");
$ms_int_distributors = WebGUI::Group->new($session, "new");
WebGUI::Test->groupsToDelete($ms_users, $ms_distributors, $ms_int_distributors);
addToCleanup($ms_users, $ms_distributors, $ms_int_distributors);
$ms_users->name('MS Users');
$ms_distributors->name('MS Distributors');
@ -94,7 +87,7 @@ $ms_distributors->addGroups([$ms_int_distributors->getId]);
$disti = WebGUI::User->new($session, 'new');
$int_disti = WebGUI::User->new($session, 'new');
WebGUI::Test->usersToDelete($disti, $int_disti);
addToCleanup($disti, $int_disti);
$ms_distributors->addUsers([$disti->userId]);
$ms_int_distributors->addUsers([$int_disti->userId]);
@ -123,8 +116,6 @@ $output = join ',',
;
is($output, 'user,disti,int_disti', 'user is in all three groups');
}
##clean up everything
END {
$session->db->dbh->do('DROP TABLE IF EXISTS myUserTable');

View file

@ -16,6 +16,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::Hash_userId;
use Data::Dumper;
my $session = WebGUI::Test->session;
@ -35,21 +36,10 @@ my @testSets = (
my $numTests = scalar @testSets;
$numTests += 1; #For the use_ok
plan tests => $numTests;
my $macro = 'WebGUI::Macro::Hash_userId';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
foreach my $testSet (@testSets) {
$session->user({userId => $testSet->{userId}});
my $output = WebGUI::Macro::Hash_userId::process($session);
is($output, $testSet->{userId}, 'testing '.$testSet->{comment});
}
}

View file

@ -14,23 +14,17 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::If;
use Data::Dumper;
my $session = WebGUI::Test->session;
use Test::More; # increment this value for each test you create
my $numTests = 8 + 1; # For conditional load and skip
my $numTests = 8; # For conditional load and skip
plan tests => $numTests;
my $macro = 'WebGUI::Macro::If';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
my $output;
$output = WebGUI::Macro::If::process($session, '', 'full', 'empty');
@ -56,5 +50,3 @@ is($output, 'There are 5 lights', 'true text works with sprintf');
$output = WebGUI::Macro::If::process($session, 0, 'Full', 'There are %s lights');
is($output, 'There are %s lights', '...false text does not');
}

View file

@ -15,6 +15,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Storage;
use WebGUI::Macro::Include;
use Test::More; # increment this value for each test you create
@ -85,18 +86,10 @@ my @testSets = (
my $numTests = scalar @testSets;
$numTests += 1; #For the use_ok
$numTests += 1; #For the unreadable file test
plan tests => $numTests;
my $macro = 'WebGUI::Macro::Include';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
foreach my $testSet (@testSets) {
my $output = WebGUI::Macro::Include::process($session, $testSet->{file});
is($output, $testSet->{output}, $testSet->{comment} . ":" .$testSet->{file});
@ -109,8 +102,3 @@ SKIP: {
my $output = WebGUI::Macro::Include::process($session, $file);
is($output, $i18n->get('not found'), q|Unreadable file returns NOT FOUND|. ":" .$file);
}
}
END {
}

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::International;
use Data::Dumper;
use Test::More; # increment this value for each test you create
@ -50,18 +51,9 @@ my @testSets = (
my $numTests = scalar @testSets;
$numTests += 1;
plan tests => $numTests;
my $loaded = use_ok('WebGUI::Macro::International');
SKIP: {
skip 'Module was not loaded, skipping all tests', $numTests -1 unless $loaded;
foreach my $testSet (@testSets) {
my $output = WebGUI::Macro::International::process($session, @{ $testSet->{input} });
is($output, $testSet->{output}, $testSet->{comment} );
}
}

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::L_loginBox;
use HTML::TokeParser;
use Test::More; # increment this value for each test you create
@ -22,7 +23,7 @@ my $session = WebGUI::Test->session;
my $homeAsset = WebGUI::Asset->getDefault($session);
$session->asset($homeAsset);
my ($versionTag, $template) = setupTest($session, $homeAsset);
my $template = setupTest($session, $homeAsset);
$session->user({userId=>1});
##Replace the original ENV hash with one that will return a
@ -37,17 +38,7 @@ $session->{_env}->{_env} = \%newEnvHash;
my $i18n = WebGUI::International->new($session,'Macro_L_loginBox');
my $numTests = 1; #Module loading test
$numTests += 30; #Static tests
plan tests => $numTests;
my $macro = 'WebGUI::Macro::L_loginBox';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
plan tests => 30;
my $output = WebGUI::Macro::L_loginBox::process($session,'','',$template->getId);
my %vars = simpleTextParser($output);
@ -170,8 +161,6 @@ $output = WebGUI::Macro::L_loginBox::process($session,'','','');
my $passwordLabel = $i18n->get(51, 'WebGUI');
like($output, qr/$passwordLabel/, 'default template works');
}
sub simpleTextParser {
my ($text) = @_;
@ -236,11 +225,6 @@ sub setupTest {
#$properties->{template} .= "\n";
my $template = $defaultNode->addChild($properties, $properties->{id});
$versionTag->commit;
return ($versionTag, $template);
}
END { ##Clean-up after yourself, always
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') {
$versionTag->rollback;
}
addToCleanup($versionTag);
return $template;
}

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::LastModified;
use Test::More; # increment this value for each test you create
@ -46,17 +47,12 @@ my @testSets = (
my $numTests = scalar @testSets;
$numTests += 1 + 2; #For the use_ok, default asset, and revisionDate=0
$numTests += 2; #For the use_ok, default asset, and revisionDate=0
plan tests => $numTests;
my $macro = 'WebGUI::Macro::LastModified';
my $loaded = use_ok($macro);
my $versionTag = WebGUI::VersionTag->getWorking($session);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
addToCleanup($versionTag);
my $output = WebGUI::Macro::LastModified::process($session);
is($output, '', "Macro returns '' if no asset is defined");
@ -97,11 +93,3 @@ is($output, $i18n->get('never'), 'asset with 0 revisionDate returns never modifi
##Restore the original revisionDate, otherwise it dies during clean-up
$session->db->write('update assetData set revisionDate=? where assetId=?', [$revDate, $assetA->getId]);
}
END { ##Clean-up after yourself, always
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') {
$versionTag->rollback;
}
}

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::LoginToggle;
use HTML::TokeParser;
use Data::Dumper;
@ -23,7 +24,7 @@ my $session = WebGUI::Test->session;
my $homeAsset = WebGUI::Asset->getDefault($session);
$session->asset($homeAsset);
my ($versionTag, $template) = setupTest($session, $homeAsset);
my $template = setupTest($session, $homeAsset);
my $i18n = WebGUI::International->new($session,'Macro_LoginToggle');
@ -131,16 +132,8 @@ foreach my $testSet (@testSets) {
$numTests += 1 + (ref $testSet->{parser} eq 'CODE');
}
$numTests += 1; #for the use_ok
plan tests => $numTests;
my $macro = 'WebGUI::Macro::LoginToggle';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
foreach my $testSet (@testSets) {
$session->user({userId=>$testSet->{userId}});
if ($testSet->{userId} eq '1') {
@ -163,8 +156,6 @@ foreach my $testSet (@testSets) {
}
}
}
sub simpleHTMLParser {
my ($text) = @_;
my $p = HTML::TokeParser->new(\$text);
@ -205,11 +196,6 @@ sub setupTest {
};
my $template = $defaultNode->addChild($properties, $properties->{id});
$versionTag->commit;
return ($versionTag, $template);
}
END { ##Clean-up after yourself, always
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') {
$versionTag->rollback;
}
addToCleanup($versionTag);
return ($template);
}

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::MiniCart;
use JSON;
use Data::Dumper;
@ -22,14 +23,7 @@ use Test::Deep;
my $session = WebGUI::Test->session;
my $numTests = 4;
$numTests += 1; #For the use_ok
plan tests => $numTests;
my $macro = 'WebGUI::Macro::MiniCart';
my $loaded = use_ok($macro);
plan tests => 4;
my $cart = WebGUI::Shop::Cart->newBySession($session);
my $donation = WebGUI::Asset->getRoot($session)->addChild({
@ -40,105 +34,94 @@ my $donation = WebGUI::Asset->getRoot($session)->addChild({
});
my $template = setupJSONtemplate($session);
addToCleanup($cart, $donation, $template);
SKIP: {
my $json;
my $templateVars;
skip "Unable to load $macro", $numTests-1 unless $loaded;
$json = WebGUI::Macro::MiniCart::process($session, $template->getId);
$templateVars = JSON::from_json($json);
cmp_deeply(
$templateVars,
{
totalPrice => '0',
totalItems => '0',
items => [],
},
'Empty cart works'
);
my $json;
my $templateVars;
my $item1 = $cart->addItem($donation);
$json = WebGUI::Macro::MiniCart::process($session, $template->getId);
$templateVars = JSON::from_json($json);
cmp_deeply(
$templateVars,
{
totalPrice => '10',
totalItems => '1',
items => [
{
name => $donation->getConfiguredTitle(),
quantity => 1,
price => 10,
url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item1->getId),
},
],
},
'Cart with one item works'
);
$json = WebGUI::Macro::MiniCart::process($session, $template->getId);
$templateVars = JSON::from_json($json);
cmp_deeply(
$templateVars,
{
totalPrice => '0',
totalItems => '0',
items => [],
},
'Empty cart works'
);
my $item2 = $cart->addItem($donation);
$json = WebGUI::Macro::MiniCart::process($session, $template->getId);
$templateVars = JSON::from_json($json);
cmp_deeply(
$templateVars,
{
totalPrice => '20',
totalItems => '2',
items => bag(
{
name => $donation->getConfiguredTitle(),
quantity => 1,
price => 10,
url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item1->getId),
},
{
name => $donation->getConfiguredTitle(),
quantity => 1,
price => 10,
url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item2->getId),
},
),
},
'Cart with two items works'
);
my $item1 = $cart->addItem($donation);
$json = WebGUI::Macro::MiniCart::process($session, $template->getId);
$templateVars = JSON::from_json($json);
cmp_deeply(
$templateVars,
{
totalPrice => '10',
totalItems => '1',
items => [
{
name => $donation->getConfiguredTitle(),
quantity => 1,
price => 10,
url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item1->getId),
},
],
},
'Cart with one item works'
);
my $item2 = $cart->addItem($donation);
$json = WebGUI::Macro::MiniCart::process($session, $template->getId);
$templateVars = JSON::from_json($json);
cmp_deeply(
$templateVars,
{
totalPrice => '20',
totalItems => '2',
items => bag(
{
name => $donation->getConfiguredTitle(),
quantity => 1,
price => 10,
url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item1->getId),
},
{
name => $donation->getConfiguredTitle(),
quantity => 1,
price => 10,
url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item2->getId),
},
),
},
'Cart with two items works'
);
$item2->setQuantity(9);
$json = WebGUI::Macro::MiniCart::process($session, $template->getId);
$templateVars = JSON::from_json($json);
cmp_deeply(
$templateVars,
{
totalPrice => '100',
totalItems => '10',
items => bag(
{
name => $donation->getConfiguredTitle(),
quantity => 1,
price => 10,
url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item1->getId),
},
{
name => $donation->getConfiguredTitle(),
quantity => 9,
price => 10,
url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item2->getId),
},
),
},
'Cart with two items and multiple quantities works'
);
}
END {
$cart->delete;
$donation->purge;
$template->purge;
}
$item2->setQuantity(9);
$json = WebGUI::Macro::MiniCart::process($session, $template->getId);
$templateVars = JSON::from_json($json);
cmp_deeply(
$templateVars,
{
totalPrice => '100',
totalItems => '10',
items => bag(
{
name => $donation->getConfiguredTitle(),
quantity => 1,
price => 10,
url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item1->getId),
},
{
name => $donation->getConfiguredTitle(),
quantity => 9,
price => 10,
url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item2->getId),
},
),
},
'Cart with two items and multiple quantities works'
);
sub setupJSONtemplate {
my ($session) = @_;

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::Page;
use Data::Dumper;
use Test::More; # increment this value for each test you create
@ -46,22 +47,13 @@ foreach my $testSet (@testSets) {
$numTests += scalar keys %{ $testSet };
}
$numTests += 1; #For the use_ok
$numTests += 1; #For macro call with undefined session asset
plan tests => $numTests;
my $macro = 'WebGUI::Macro::Page';
my $loaded = use_ok($macro);
my $homeAsset = WebGUI::Asset->getDefault($session);
my $versionTag;
($versionTag, @testSets) = setupTest($session, $homeAsset, @testSets);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
@testSets = setupTest($session, $homeAsset, @testSets);
is(
WebGUI::Macro::Page::process($session,'url'),
@ -80,8 +72,6 @@ foreach my $testSet (@testSets) {
}
}
}
sub setupTest {
my ($session, $homeAsset, @testSets) = @_;
my $versionTag = WebGUI::VersionTag->getWorking($session);
@ -92,9 +82,6 @@ sub setupTest {
$testSet->{asset} = $asset;
}
$versionTag->commit;
return $versionTag, @testSets;
}
END { ##Clean-up after yourself, always
$versionTag->rollback;
addToCleanup($versionTag);
return @testSets;
}

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::PageTitle;
use Data::Dumper;
use Test::More;
@ -22,13 +23,9 @@ use Test::MockObject;
my $session = WebGUI::Test->session;
my $numTests = 7;
$numTests += 1; #For the use_ok
plan tests => $numTests;
my $macro = 'WebGUI::Macro::PageTitle';
my $loaded = use_ok($macro);
my $homeAsset = WebGUI::Asset->getDefault($session);
my $versionTag = WebGUI::VersionTag->getWorking($session);
@ -45,10 +42,7 @@ my $snippet = $homeAsset->addChild({
});
$versionTag->commit;
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
addToCleanup($versionTag);
is(
WebGUI::Macro::PageTitle::process($session),
@ -66,7 +60,6 @@ $session->asset($snippet);
my $macroOutput = WebGUI::Macro::PageTitle::process($session);
is($macroOutput, $snippet->get('title'), "testing title returned from localy created asset with known title");
my $origSessionRequest = $session->{_request};
my ($operation, $function) = (0,0);
@ -105,9 +98,3 @@ $operation = 1;
$function = 1;
$output = WebGUI::Macro::PageTitle::process($session);
is($output, $urlizedTitle, 'fetching urlized title via an operation and function');
}
END {
$versionTag->rollback;
}

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Asset::Template;
use WebGUI::Macro::PickLanguage;
use Test::More; # increment this value for each test you create
use Test::Deep;
@ -24,13 +25,8 @@ my $session = WebGUI::Test->session;
my $numTests = 3;
$numTests += 1; #For the use_ok
plan tests => $numTests;
my $macro = 'WebGUI::Macro::PickLanguage';
my $loaded = use_ok($macro);
my $macroMock = Test::MockObject->new({});
$macroMock->set_isa('WebGUI::Macro::PickLanguage');
$macroMock->set_true('process');
@ -61,6 +57,8 @@ $templateMock->mock('process', sub { $templateVars = $_[1]; } );
'language_langEng' => 'English'
},
],
delete_url => '?op=setLanguage;language=delete;',
delete_label => 'Go back to profile language.',
},
'some template variables are created'
);
@ -90,6 +88,8 @@ $templateMock->mock('process', sub { $templateVars = $_[1]; } );
'language_langEng' => 'English'
},
],
delete_url => '?op=setLanguage;language=delete;',
delete_label => "Go back to profile language.",
},
'some template variables are created, when no templateId is passed on with the macro'
);

View file

@ -13,8 +13,8 @@ use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Macro::RootTitle;
use WebGUI::Session;
use WebGUI::Macro::RootTitle;
use Data::Dumper;
use Test::More; # increment this value for each test you create
@ -32,6 +32,7 @@ my $session = WebGUI::Test->session;
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"Adding assets for RootTitle tests"});
addToCleanup($versionTag);
my $root = WebGUI::Asset->getRoot($session);
my %properties_A = (
@ -160,17 +161,10 @@ my @testSets = (
);
my $numTests = scalar @testSets;
$numTests += 2;
$numTests += 1;
plan tests => $numTests;
my $macro = 'WebGUI::Macro::RootTitle';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
is(
WebGUI::Macro::RootTitle::process($session),
'',
@ -183,12 +177,3 @@ foreach my $testSet (@testSets) {
my $output = WebGUI::Macro::RootTitle::process($session);
is($output, $testSet->{title}, $testSet->{comment});
}
}
END { ##Clean-up after yourself, always
$session->db->write('update asset set lineage=? where assetId=?',[$origLineage, $asset_->getId]);
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') {
$versionTag->rollback;
}
}

View file

@ -17,6 +17,7 @@ use WebGUI::Macro::Slash_gatewayUrl;
use WebGUI::Session;
use WebGUI::International;
use WebGUI::DatabaseLink;
use WebGUI::Macro::SQL;
use Data::Dumper;
use Test::More; # increment this value for each test you create
@ -119,14 +120,10 @@ my @testSets = (
my $numTests = scalar @testSets;
++$numTests; ##For the load check;
++$numTests; ##For the allow macro access test;
plan tests => $numTests;
my $macro = 'WebGUI::Macro::SQL';
my $loaded = use_ok($macro);
$WebGUIdbLink->set({allowMacroAccess=>0});
# run one test to test allowMacroAccess
@ -136,10 +133,6 @@ is($output, $i18n->get('database access not allowed'), 'Test allow access from m
# set allowMacroAccess to 1 to allow other tests to run
$WebGUIdbLink->set({allowMacroAccess=>1});
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
foreach my $testSet (@testSets) {
# we know some of these will fail. Keep them quiet.
local $SIG{__WARN__} = sub {};
@ -148,8 +141,6 @@ foreach my $testSet (@testSets) {
is($output, $testSet->{output}, $testSet->{comment});
}
}
# reset allowMacroAccess to original value
$WebGUIdbLink->set({allowMacroAccess=>$originalMacroAccessValue});

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::SessionId;
use HTML::TokeParser;
use Data::Dumper;
@ -21,16 +22,7 @@ use Test::More; # increment this value for each test you create
my $session = WebGUI::Test->session;
my $numTests = 1;
$numTests += 1; #For the use_ok
plan tests => 2;
plan tests => 1;
my $macro = 'WebGUI::Macro::SessionId';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
my $output = WebGUI::Macro::SessionId::process( $session );
is($session->getId, $output, 'Session macro works');
}
my $output = WebGUI::Macro::SessionId::process( $session );
is($session->getId, $output, 'Session macro works');

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::Slash_gatewayUrl;
use Data::Dumper;
use Test::More; # increment this value for each test you create
@ -24,17 +25,7 @@ my $session = WebGUI::Test->session;
##in t/Session/Url.t All we need to do is make sure that the macro
##fetches the same thing as the method.
my $numTests = 4;
$numTests += 1; #For the use_ok
plan tests => $numTests;
my $macro = 'WebGUI::Macro::Slash_gatewayUrl';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
plan tests => 4;
$session->setting->set('preventProxyCache', 0);
@ -54,9 +45,3 @@ like($output, qr{/\?noCache=\d+:\d+$}, 'checking the cache settings in the URL')
$output = WebGUI::Macro::Slash_gatewayUrl::process($session, '/foo/bar');
like($output, qr{/foo/bar\?noCache=\d+:\d+$}, 'checking the cache settings in the URL are at the end of the URL');
$session->setting->set('preventProxyCache', 0);
}
END {
}

View file

@ -68,6 +68,7 @@ $asset->update({
$asset->generateThumbnail();
$versionTag->commit;
addToCleanup($versionTag);
##Call the Thumbnail Macro with that Asset's URL and see if it returns
@ -95,10 +96,3 @@ SKIP: {
cmp_bag([$thumbImg->GetPixels(width=>1, height=>1, x=>50, y=>50, map=>'RGB', normalize=>'true')], [0,0,1], 'blue pixel #3');
}
END {
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') {
$versionTag->rollback;
}
##Storage is cleaned up by rolling back the version tag
}

View file

@ -79,6 +79,3 @@ sub setupTest {
}
return @testSets;
}
END { ##Clean-up after yourself, always
}

View file

@ -29,130 +29,119 @@ my $template = setupJSONtemplate($session);
my @users = setupUsers($session);
my $i18n = WebGUI::International->new($session,'Macro_UsersOnline');
my $numTests = 1; # Module loading test
$numTests += 30; # Static tests
plan tests => 30;
plan tests => $numTests;
# Basic testing -----------------------------------------------------------
my $macro = 'WebGUI::Macro::UsersOnline';
my $loaded = use_ok($macro);
# Check for default template
my $defTemplate = WebGUI::Asset->new($session, 'h_T2xtOxGRQ9QJOR6ebLpQ');
ok(defined $defTemplate, 'default template is present');
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
# Basic testing -----------------------------------------------------------
# Check for default template
my $defTemplate = WebGUI::Asset->new($session, 'h_T2xtOxGRQ9QJOR6ebLpQ');
ok(defined $defTemplate, 'default template is present');
# Call with default values
my $html = WebGUI::Macro::UsersOnline::process($session);
cmp_ok((length $html), '>', 0, 'call with default template and values returns some output');
# Call with default values
my $html = WebGUI::Macro::UsersOnline::process($session);
cmp_ok((length $html), '>', 0, 'call with default template and values returns some output');
# Test labels -------------------------------------------------------------
# Test labels -------------------------------------------------------------
$session->user({userId => 1});
my $json = WebGUI::Macro::UsersOnline::process($session, $template->getId);
my $vars = JSON::from_json($json);
$session->user({userId => 1});
my $json = WebGUI::Macro::UsersOnline::process($session, $template->getId);
my $vars = JSON::from_json($json);
is($vars->{'usersOnline_label'}, $i18n->get('Users Online'), 'usersOnline_label');
is($vars->{'members_label'}, $i18n->get('Members'), 'members_label');
is($vars->{'visitors_label'}, $i18n->get('Visitors'), 'visitors_label');
is($vars->{'total_label'}, $i18n->get('Total'), 'total_label');
is($vars->{'membersOnline_label'}, $i18n->get('Members Online'), 'membersOnline_label');
is($vars->{'visitorsOnline_label'}, $i18n->get('Visitors Online'), 'visitorsOnline_label');
is($vars->{'avatar_label'}, $i18n->get('Avatar'), 'avatar_label');
is($vars->{'name_label'}, $i18n->get('Name'), 'name_label');
is($vars->{'alias_label'}, $i18n->get('Alias'), 'alias_label');
is($vars->{'session_label'}, $i18n->get('Session'), 'session_label');
is($vars->{'ip_label'}, $i18n->get('IP'), 'ip_label');
is($vars->{'lastActivity_label'}, $i18n->get('Last Activity'), 'lastActivity_label');
is($vars->{'usersOnline_label'}, $i18n->get('Users Online'), 'usersOnline_label');
is($vars->{'members_label'}, $i18n->get('Members'), 'members_label');
is($vars->{'visitors_label'}, $i18n->get('Visitors'), 'visitors_label');
is($vars->{'total_label'}, $i18n->get('Total'), 'total_label');
is($vars->{'membersOnline_label'}, $i18n->get('Members Online'), 'membersOnline_label');
is($vars->{'visitorsOnline_label'}, $i18n->get('Visitors Online'), 'visitorsOnline_label');
is($vars->{'avatar_label'}, $i18n->get('Avatar'), 'avatar_label');
is($vars->{'name_label'}, $i18n->get('Name'), 'name_label');
is($vars->{'alias_label'}, $i18n->get('Alias'), 'alias_label');
is($vars->{'session_label'}, $i18n->get('Session'), 'session_label');
is($vars->{'ip_label'}, $i18n->get('IP'), 'ip_label');
is($vars->{'lastActivity_label'}, $i18n->get('Last Activity'), 'lastActivity_label');
# Test logic --------------------------------------------------------------
# Test logic --------------------------------------------------------------
like($vars->{'visitors'}, qr/[0-9]+/, 'visitors is numeric');
like($vars->{'visitors'}, qr/[0-9]+/, 'visitors is numeric');
# Does not work in testing environments that run on the loopback interface,
# since these queries are filtered out by the macro.
# is($vars->{'visitors'} > 0, 1, 'visitors > 0 when calling as visitor');
like($vars->{'members'}, qr/[0-9]+/, 'members is numeric');
cmp_ok($vars->{'members'}, '>', 0, 'members > 0 since we have created one visible active member');
is($vars->{'total'}, $vars->{'visitors'} + $vars->{'members'}, 'total == visitors + members');
ok($vars->{'isVisitor'}, 'isVisitor is true when calling as visitor');
ok(defined $vars->{'hasMembers'}, 'hasMembers is defined since we have created one visible active member');
like($vars->{'members'}, qr/[0-9]+/, 'members is numeric');
cmp_ok($vars->{'members'}, '>', 0, 'members > 0 since we have created one visible active member');
is($vars->{'total'}, $vars->{'visitors'} + $vars->{'members'}, 'total == visitors + members');
ok($vars->{'isVisitor'}, 'isVisitor is true when calling as visitor');
ok(defined $vars->{'hasMembers'}, 'hasMembers is defined since we have created one visible active member');
# Check member loop -------------------------------------------------------
# Check member loop -------------------------------------------------------
my $allFieldsSet = 1;
my $firstUserPresent = 0;
my $secondUserAbsent = 1;
my $allFieldsSet = 1;
my $firstUserPresent = 0;
my $secondUserAbsent = 1;
foreach (@{$vars->{'member_loop'}}) {
# Check whether first user is present
if ($_->{'username'} eq 'tester1') {
# Indicate success
$firstUserPresent = 1;
# Check whether alias and name have been set correctly
$allFieldsSet = $_->{'alias'} eq 'alias1';
$allFieldsSet &&= $_->{'firstName'} eq 'first1';
$allFieldsSet &&= $_->{'middleName'} eq 'middle1';
$allFieldsSet &&= $_->{'lastName'} eq 'last1';
}
# Check whether second user is present
if ($_->{'username'} eq 'tester2') {
# Indicate failure
$secondUserAbsent = 0;
}
# Check whether remaining fields have been set. Note that we cannot
# check for the alias, name or avatar, since these values may be
# optional.
$allFieldsSet &&= $_->{'uid'} =~ /.*/;
$allFieldsSet &&= $_->{'sessionId'} =~ /.*/;
# $allFieldsSet &&= $_->{'ip'} =~ /.*/; # IP is not set for our test user
$allFieldsSet &&= $_->{'lastActivity'} =~ /.*/;
}
# Check booleans indicating errors
ok($allFieldsSet, 'fields in the member loop have been set correctly');
ok($firstUserPresent, 'the first user is present in the member loop');
ok($secondUserAbsent, 'the second user is absent from the member loop');
# Check visitor loop ------------------------------------------------------
$allFieldsSet = 1;
foreach (@{$vars->{'visitor_loop'}}) {
# $allFieldsSet &&= $_->{'ip'} =~ /.*/; # IP is not set for our test user
$allFieldsSet &&= $_->{'sessionId'} =~ /.*/;
$allFieldsSet &&= $_->{'lastActivity'} =~ /.*/;
foreach (@{$vars->{'member_loop'}}) {
# Check whether first user is present
if ($_->{'username'} eq 'tester1') {
# Indicate success
$firstUserPresent = 1;
# Check whether alias and name have been set correctly
$allFieldsSet = $_->{'alias'} eq 'alias1';
$allFieldsSet &&= $_->{'firstName'} eq 'first1';
$allFieldsSet &&= $_->{'middleName'} eq 'middle1';
$allFieldsSet &&= $_->{'lastName'} eq 'last1';
}
# Check booleans indicating errors
ok($allFieldsSet, 'fields in the visitor loop have been set correctly');
# Check whether second user is present
if ($_->{'username'} eq 'tester2') {
# Indicate failure
$secondUserAbsent = 0;
}
# Test macro parameters ---------------------------------------------------
# Call with zero max limits
$json = WebGUI::Macro::UsersOnline::process($session, $template->getId, undef, 0, 0);
$vars = JSON::from_json($json);
ok(!defined $vars->{'hasMembers'}, 'hasMembers undefined when display limit is set to zero');
is(@{$vars->{'member_loop'}} == 0, 1, 'empty member loop when display limit is set to zero');
is(@{$vars->{'visitor_loop'}} == 0, 1, 'empty visitor loop when display limit is set to zero');
# Call with zero max inactivity time
$json = WebGUI::Macro::UsersOnline::process($session, $template->getId, 0, undef, undef);
$vars = JSON::from_json($json);
ok(!defined $vars->{'hasMembers'}, 'hasMembers undefined when max inactivity time is set to zero');
is(@{$vars->{'member_loop'}} == 0, 1, 'empty member loop when max inactivity time is set to zero');
is(@{$vars->{'visitor_loop'}} == 0, 1, 'empty visitor loop when max inactivity time is set to zero');
# Check whether remaining fields have been set. Note that we cannot
# check for the alias, name or avatar, since these values may be
# optional.
$allFieldsSet &&= $_->{'uid'} =~ /.*/;
$allFieldsSet &&= $_->{'sessionId'} =~ /.*/;
# $allFieldsSet &&= $_->{'ip'} =~ /.*/; # IP is not set for our test user
$allFieldsSet &&= $_->{'lastActivity'} =~ /.*/;
}
# Check booleans indicating errors
ok($allFieldsSet, 'fields in the member loop have been set correctly');
ok($firstUserPresent, 'the first user is present in the member loop');
ok($secondUserAbsent, 'the second user is absent from the member loop');
# Check visitor loop ------------------------------------------------------
$allFieldsSet = 1;
foreach (@{$vars->{'visitor_loop'}}) {
# $allFieldsSet &&= $_->{'ip'} =~ /.*/; # IP is not set for our test user
$allFieldsSet &&= $_->{'sessionId'} =~ /.*/;
$allFieldsSet &&= $_->{'lastActivity'} =~ /.*/;
}
# Check booleans indicating errors
ok($allFieldsSet, 'fields in the visitor loop have been set correctly');
# Test macro parameters ---------------------------------------------------
# Call with zero max limits
$json = WebGUI::Macro::UsersOnline::process($session, $template->getId, undef, 0, 0);
$vars = JSON::from_json($json);
ok(!defined $vars->{'hasMembers'}, 'hasMembers undefined when display limit is set to zero');
is(@{$vars->{'member_loop'}} == 0, 1, 'empty member loop when display limit is set to zero');
is(@{$vars->{'visitor_loop'}} == 0, 1, 'empty visitor loop when display limit is set to zero');
# Call with zero max inactivity time
$json = WebGUI::Macro::UsersOnline::process($session, $template->getId, 0, undef, undef);
$vars = JSON::from_json($json);
ok(!defined $vars->{'hasMembers'}, 'hasMembers undefined when max inactivity time is set to zero');
is(@{$vars->{'member_loop'}} == 0, 1, 'empty member loop when max inactivity time is set to zero');
is(@{$vars->{'visitor_loop'}} == 0, 1, 'empty visitor loop when max inactivity time is set to zero');
sub setupUsers {
@ -192,7 +181,7 @@ sub setupUsers {
my $newSession = WebGUI::Session->open(WebGUI::Test::root, WebGUI::Test::file);
$newSession->user({user => $_});
}
WebGUI::Test->usersToDelete(@users);
addToCleanup(@users);
return @users;
}
@ -246,10 +235,6 @@ sub setupJSONtemplate {
}
EOTMPL
my $template = WebGUI::Asset->getImportNode($session)->addChild({className=>'WebGUI::Asset::Template', namespace => 'Macro/UsersOnline', template=>$templateBody});
addToCleanup($template);
return $template;
}
END { ##Clean-up after yourself, always
$template->purge;
}

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::ViewCart;
use HTML::TokeParser;
use Data::Dumper;
@ -21,8 +22,6 @@ use Test::More; # increment this value for each test you create
my $session = WebGUI::Test->session;
my @testSets = (
{
comment => 'default',
@ -41,17 +40,8 @@ foreach my $testSet (@testSets) {
$numTests += 1 + (ref $testSet->{output} eq 'CODE');
}
$numTests += 1; #For the use_ok
plan tests => $numTests;
my $macro = 'WebGUI::Macro::ViewCart';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
foreach my $testSet (@testSets) {
my $output = WebGUI::Macro::ViewCart::process( $session, $testSet->{label});
if (ref $testSet->{output} eq 'CODE') {
@ -64,9 +54,6 @@ foreach my $testSet (@testSets) {
}
}
}
sub simpleHTMLParser {
my ($text) = @_;
my $p = HTML::TokeParser->new(\$text);
@ -86,6 +73,3 @@ sub simpleTextParser {
return ($url, $label);
}
END {
}

View file

@ -24,7 +24,7 @@ my $session = WebGUI::Test->session;
plan tests => 2;
my $output = WebGUI::Macro::c_companyName::process($session);
is($output, $originalCompanyName, "Testing companyName");
is($output, $session->setting->get('companyName'), "Testing companyName");
$session->setting->set('companyName', q|Gooey's Consulting, LLC|);
$output = WebGUI::Macro::c_companyName::process($session);

View file

@ -25,7 +25,7 @@ my $session = WebGUI::Test->session;
my $homeAsset = WebGUI::Asset->getDefault($session);
$session->asset($homeAsset);
my ($versionTag, $template) = setupTest($session, $homeAsset);
my $template = setupTest($session, $homeAsset);
my $i18n = WebGUI::International->new($session, 'Macro_r_printable');
@ -125,8 +125,9 @@ sub setupTest {
};
my $asset = $defaultNode->addChild($properties, $properties->{id});
$versionTag->commit;
addToCleanup($versionTag);
return $versionTag, $asset;
return $asset;
}
sub simpleHTMLParser {
@ -148,9 +149,3 @@ sub simpleTextParser {
return ($url, $label);
}
END { ##Clean-up after yourself, always
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') {
$versionTag->rollback;
}
}

View file

@ -26,11 +26,6 @@ use Test::More; # increment this value for each test you create
my $numTests = 0;
my $session = WebGUI::Test->session;
my $lib = WebGUI::Test->lib;
##Find the name of the International macro in the user's config file.
#note "International macro name = $international";
##Regexp setup for parsing out the Macro calls.
my $macro = qr{
@ -43,19 +38,28 @@ my $macro = qr{
$numTests = $session->db->quickScalar('select count(distinct(assetId)) from template');
plan tests => $numTests;
plan tests => 2*$numTests;
my $validLinks = 0;
my $nonRootLink = qr{
^
\s* #Optional whitespace
(?: \^ (?: / | Extras)) #Gateway or Extras macro
| # OR
<tmpl_var #A template variable
}x;
sub checkLinks {
my ($tag, $attrs) = @_;
if ($tag eq 'link' && $attrs->{href}) {
if ($attrs->{href} !~ /\s*\^(?:\/|Extras)/) {
diag sprintf '%s: %s', $tag, $attrs->{href};
if ($attrs->{href} !~ $nonRootLink) {
$validLinks = 0;
}
}
elsif ($tag eq 'script' && $attrs->{src}) {
if ($attrs->{src} !~ /\s*\^(?:\/|Extras)/) {
if ($attrs->{src} !~ $nonRootLink) {
$validLinks = 0;
}
}
@ -70,15 +74,22 @@ my $parser = HTML::Parser->new(
my $getATemplate = WebGUI::Asset::Template->getIsa($session);
TEMPLATE: while (my $templateAsset = $getATemplate->()) {
my $template = $templateAsset->get('template');
my $header = $templateAsset->get('extraHeadTags');
if(! $header) {
ok(1, sprintf "%s: %s (%s) has no rooted link urls", $templateAsset->getTitle, $templateAsset->getId, $templateAsset->getUrl);
next TEMPLATE;
ok(1, sprintf "%s: %s (%s) has no rooted link urls in the head tags", $templateAsset->getTitle, $templateAsset->getId, $templateAsset->getUrl);
}
else {
$validLinks = 1;
$parser->parse($header);
ok($validLinks, sprintf "%s: %s (%s) has no rooted link urls in the head tags", $templateAsset->getTitle, $templateAsset->getId, $templateAsset->getUrl);
}
my $template = $templateAsset->get('template');
if(! $template) {
ok(1, sprintf "%s: %s (%s) has no rooted link urls in the template", $templateAsset->getTitle, $templateAsset->getId, $templateAsset->getUrl);
}
else {
$validLinks = 1;
$parser->parse($template);
ok($validLinks, sprintf "%s: %s (%s) has no rooted link urls in the template", $templateAsset->getTitle, $templateAsset->getId, $templateAsset->getUrl);
}
$validLinks = 1;
$parser->parse($header);
ok($validLinks, sprintf "%s: %s (%s) has no rooted link urls", $templateAsset->getTitle, $templateAsset->getId, $templateAsset->getUrl);
}