Ready for 7.10.29 development.
This commit is contained in:
commit
c806f99b7b
4236 changed files with 1217679 additions and 0 deletions
127
t/Workflow/Activity/ArchiveOldStories.t
Normal file
127
t/Workflow/Activity/ArchiveOldStories.t
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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::Asset;
|
||||
use WebGUI::Asset::Story;
|
||||
use WebGUI::Asset::Wobject::StoryArchive;
|
||||
use WebGUI::Workflow::Activity::ArchiveOldStories;
|
||||
|
||||
use Data::Dumper;
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
|
||||
plan tests => 6; # increment this value for each test you create
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
$session->user({userId => 3});
|
||||
|
||||
my $home = WebGUI::Asset->getDefault($session);
|
||||
my $wgBday = WebGUI::Test->webguiBirthday;
|
||||
|
||||
my $creationDateSth = $session->db->prepare('update asset set creationDate=? where assetId=?');
|
||||
|
||||
my $archive1 = $home->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::StoryArchive',
|
||||
title => '2001 Stories',
|
||||
archiveAfter => 50*365*24*3600, ##50 years ago
|
||||
});
|
||||
|
||||
my $birthdayFolder = $archive1->getFolder($wgBday);
|
||||
$creationDateSth->execute([$wgBday, $birthdayFolder->getId]);
|
||||
|
||||
my @oldStories = ();
|
||||
push @oldStories, $birthdayFolder->addChild({ className => 'WebGUI::Asset::Story',});
|
||||
push @oldStories, $birthdayFolder->addChild({ className => 'WebGUI::Asset::Story',});
|
||||
foreach my $story (@oldStories) {
|
||||
$creationDateSth->execute([$wgBday, $story->getId]);
|
||||
}
|
||||
|
||||
my $archive2 = $home->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::StoryArchive',
|
||||
title => 'Stories from last week',
|
||||
archiveAfter => 10*24*3600, #10 days ago
|
||||
});
|
||||
|
||||
my $weekAgo = time() - (7*24*3600);
|
||||
my $weekFolder = $archive2->getFolder($weekAgo);
|
||||
my $weekStory = $weekFolder->addChild({className => 'WebGUI::Asset::Story',});
|
||||
$creationDateSth->execute([$weekAgo, $weekFolder->getId]);
|
||||
$creationDateSth->execute([$weekAgo, $weekStory->getId]);
|
||||
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||
$versionTag->commit;
|
||||
WebGUI::Test->addToCleanup($versionTag);
|
||||
foreach my $asset ($archive1, $archive2) {
|
||||
$asset = $asset->cloneFromDb;
|
||||
}
|
||||
|
||||
my $workflow = WebGUI::Workflow->create($session,
|
||||
{
|
||||
enabled => 1,
|
||||
objectType => 'None',
|
||||
mode => 'realtime',
|
||||
},
|
||||
);
|
||||
addToCleanup($workflow);
|
||||
|
||||
my $activity = $workflow->addActivity('WebGUI::Workflow::Activity::ArchiveOldStories');
|
||||
|
||||
my $instance1 = WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
workflowId => $workflow->getId,
|
||||
skipSpectreNotification => 1,
|
||||
}
|
||||
);
|
||||
|
||||
my $retVal;
|
||||
|
||||
$retVal = $instance1->run();
|
||||
is($retVal, 'complete', 'First workflow was run');
|
||||
$retVal = $instance1->run();
|
||||
is($retVal, 'done', 'Workflow is done');
|
||||
|
||||
my $archivedAssets = $home->getLineage(
|
||||
['descendants'],
|
||||
{
|
||||
includeOnlyClasses => ['WebGUI::Asset::Story', 'WebGUI::Asset::Wobject::Folder', 'WebGUI::Asset::Wobject::StoryArchive'],
|
||||
statusToInclude => ['archived'],
|
||||
},
|
||||
);
|
||||
|
||||
cmp_bag( $archivedAssets, [ ], 'Nothing archived.');
|
||||
|
||||
$archive2->update({ archiveAfter => 5*24*3600, });
|
||||
|
||||
my $instance2 = WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
workflowId => $workflow->getId,
|
||||
skipSpectreNotification => 1,
|
||||
}
|
||||
);
|
||||
$retVal = $instance2->run();
|
||||
is($retVal, 'complete', 'Second workflow was run');
|
||||
$retVal = $instance2->run();
|
||||
is($retVal, 'done', 'Workflow is done');
|
||||
|
||||
$archivedAssets = $home->getLineage(
|
||||
['descendants'],
|
||||
{
|
||||
includeOnlyClasses => ['WebGUI::Asset::Story', 'WebGUI::Asset::Wobject::Folder', 'WebGUI::Asset::Wobject::StoryArchive'],
|
||||
statusToInclude => ['archived'],
|
||||
},
|
||||
);
|
||||
|
||||
cmp_bag( $archivedAssets, [ $weekStory->getId, $weekFolder->getId ], 'Nothing archived.');
|
||||
$creationDateSth->finish;
|
||||
145
t/Workflow/Activity/BucketPassiveAnalytics.t
Normal file
145
t/Workflow/Activity/BucketPassiveAnalytics.t
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../../lib";
|
||||
#use DB;
|
||||
|
||||
use WebGUI::Test;
|
||||
use WebGUI::PassiveAnalytics::Rule;
|
||||
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
use Data::Dumper;
|
||||
|
||||
plan tests => 2; # increment this value for each test you create
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
$session->user({userId => 3});
|
||||
|
||||
WebGUI::Test->addToCleanup(SQL => 'delete from passiveLog');
|
||||
WebGUI::Test->addToCleanup(SQL => 'delete from deltaLog');
|
||||
WebGUI::Test->addToCleanup(SQL => 'delete from bucketLog');
|
||||
WebGUI::Test->addToCleanup(SQL => 'delete from analyticRule');
|
||||
WebGUI::Test->addToCleanup(SQL => 'delete from PA_lastLog');
|
||||
|
||||
my $workflow = WebGUI::Workflow->new($session, 'PassiveAnalytics000001');
|
||||
my $activities = $workflow->getActivities();
|
||||
##Note, they're in order, and the order is known.
|
||||
$activities->[0]->set('deltaInterval', 100);
|
||||
$activities->[1]->set('userId', 0); ##To disable sending emails
|
||||
|
||||
my $instance = WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
workflowId => $workflow->getId,
|
||||
skipSpectreNotification => 1,
|
||||
priority => 1,
|
||||
}
|
||||
);
|
||||
WebGUI::Test->addToCleanup($instance);
|
||||
##Rule label, url, and regexp
|
||||
my @ruleSets = (
|
||||
['home', '/home', '^\/home' ],
|
||||
['one', '/one', '^\/one$' ],
|
||||
['two', '/two', '^\/two$' ],
|
||||
['three', '/three', '^\/three$' ],
|
||||
['end', '/blah/blah/end', 'end$' ],
|
||||
['casa', '/home/casa', 'casa$' ],
|
||||
['uno', '/one/uno', 'uno$' ],
|
||||
['dos', '/two/dos', 'dos$' ],
|
||||
['tres', '/three/tres', 'tres$' ],
|
||||
['alpha', '/alpha/aee', '.alpha.aee' ],
|
||||
['beta', '/beta/bee', '.beta.bee' ],
|
||||
['gamma', '/gamma/cee', '.gamma.cee' ],
|
||||
['delta', '/delta/dee', '.delta.dee' ],
|
||||
['eee', '/epsilon/eee', 'eee$' ],
|
||||
['thingy1', '/thingy?thingId=1', '^.thingy\?thingId=1' ],
|
||||
['rogerRoger', '/roger/roger', '(?:\/roger){2}' ],
|
||||
['roger', '/roger', '^\/roger' ],
|
||||
['thingy2', '/thingy?thingId=2', '^.thingy\?thingId=2' ],
|
||||
['beet', '/beta/beet', '.beta.beet' ],
|
||||
['zero', '/yelnats', 'yelnats' ],
|
||||
);
|
||||
|
||||
my @url2 = @ruleSets;
|
||||
while (my $spec = shift @url2) {
|
||||
my ($bucket, undef, $regexp) = @{ $spec };
|
||||
WebGUI::PassiveAnalytics::Rule->create($session, { bucketName => $bucket, regexp => $regexp });
|
||||
}
|
||||
|
||||
my @urls = map {$_->[1]} @ruleSets;
|
||||
#loadLogData($session, @urls);
|
||||
repeatableLogData($session, 'passiveAnalyticsLog');
|
||||
|
||||
##Build rulesets
|
||||
|
||||
##Now, run it and wait for it to finish
|
||||
my $counter = 0;
|
||||
#DB::enable_profile();
|
||||
PAUSE: while (my $retval = $instance->run()) {
|
||||
last PAUSE if $retval eq 'done';
|
||||
last PAUSE if $counter++ >= 16;
|
||||
}
|
||||
#DB::disable_profile();
|
||||
|
||||
cmp_ok $counter, '<', 16, 'Successful completion of PA';
|
||||
|
||||
my $get_line = $session->db->read('select userId, Bucket, duration from bucketLog');
|
||||
|
||||
my @database_dump = ();
|
||||
ROW: while ( 1 ) {
|
||||
my @datum = $get_line->array();
|
||||
last ROW unless @datum;
|
||||
push @database_dump, [ @datum ];
|
||||
}
|
||||
|
||||
cmp_bag(
|
||||
[ @database_dump ],
|
||||
[
|
||||
['user1', 'one', 10],
|
||||
['user1', 'two', 15],
|
||||
['user2', 'zero', 2],
|
||||
['user2', 'uno', 3],
|
||||
['user2', 'Other', 5],
|
||||
],
|
||||
'PA analysis completed, and calculated correctly'
|
||||
) or diag Dumper(\@database_dump);
|
||||
|
||||
sub loadLogData {
|
||||
my ($session, @urls) = @_;
|
||||
$session->db->write('delete from passiveLog');
|
||||
my $insert = $session->db->prepare(
|
||||
q!insert into passiveLog (userId, sessionId, timeStamp, url, assetId) VALUES (?,?,?,?,'assetId')!
|
||||
);
|
||||
my $logCount = 15000;
|
||||
my $counter;
|
||||
my $startTime = 1000;
|
||||
my $numUrls = scalar @urls;
|
||||
while ($counter++ < $logCount) {
|
||||
my $index = int rand($numUrls);
|
||||
my $url = $urls[$index];
|
||||
$insert->execute([2, 25, $startTime, $url]);
|
||||
$startTime += int(rand(10))+1;
|
||||
}
|
||||
}
|
||||
|
||||
sub repeatableLogData {
|
||||
my ($session, $dataLogName) = @_;
|
||||
$session->db->write('delete from passiveLog');
|
||||
my $insert = $session->db->prepare(
|
||||
q!insert into passiveLog (userId, sessionId, timeStamp, url, assetId) VALUES (?,?,?,?,'assetId')!
|
||||
);
|
||||
my $data_name = WebGUI::Test::collateral('passiveAnalyticsLog');
|
||||
open my $log_data, '<', $data_name or
|
||||
die "Unable to open $data_name for reading: $!";
|
||||
local $_;
|
||||
while (<$log_data>) {
|
||||
next if /^\s*#/;
|
||||
s/#\.*$//;
|
||||
chomp;
|
||||
my @data = split;
|
||||
$insert->execute([@data]);
|
||||
}
|
||||
$insert->finish;
|
||||
}
|
||||
|
||||
#vim:ft=perl
|
||||
238
t/Workflow/Activity/CalendarUpdateFeeds.t
Normal file
238
t/Workflow/Activity/CalendarUpdateFeeds.t
Normal file
|
|
@ -0,0 +1,238 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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::Workflow::Activity::CalendarUpdateFeeds;
|
||||
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
use Test::LongString;
|
||||
use WebGUI::Asset::Wobject::Calendar;
|
||||
|
||||
plan skip_all => 'set WEBGUI_LIVE to enable this test'
|
||||
unless $ENV{WEBGUI_LIVE};
|
||||
|
||||
plan tests => 27; # increment this value for each test you create
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
my $home = WebGUI::Asset->getDefault($session);
|
||||
my $sender = $home->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Calendar',
|
||||
title => 'Sending Calendar',
|
||||
});
|
||||
my $receiver = $home->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Calendar',
|
||||
title => 'Receiving Calendar',
|
||||
});
|
||||
|
||||
my $feedId = $receiver->addFeed({
|
||||
url => $session->url->getSiteURL.$session->url->gateway($sender->getUrl('func=ical')),
|
||||
lastUpdated => 'never',
|
||||
});
|
||||
|
||||
my $dt = WebGUI::DateTime->new($session, time());
|
||||
$dt->add(days => 1);
|
||||
|
||||
my $party = $sender->addChild({
|
||||
className => 'WebGUI::Asset::Event',
|
||||
title => 'WebGUI 100th Anniversary',
|
||||
menuTitle => 'Anniversary',
|
||||
description => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum', ##Set at longer than 72 characters to test for line wrapping, and character escaping
|
||||
url => 'webgui_anniversary',
|
||||
startDate => $dt->toDatabaseDate, ##Times and dates have to be entered in UTC
|
||||
endDate => $dt->toDatabaseDate,
|
||||
timeZone => 'America/Chicago',
|
||||
location => 'Madison, Wisconsin',
|
||||
groupIdView => 7,
|
||||
groupIdEdit => 12,
|
||||
ownerUserId => 3,
|
||||
}, undef, undef, {skipAutoCommitWorkflows => 1});
|
||||
|
||||
my $ical_feed = <<"EOICAL";
|
||||
BEGIN:VCALENDAR
|
||||
PRODID:-//Oregon State University//NONSGML Web Calendar//EN
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
UID:20110426T010000Z-51795\@calendar.oregonstate.edu
|
||||
CLASS:PUBLIC
|
||||
SUMMARY:CPR/AED for the Professional Rescuer
|
||||
DESCRIPTION:This class is designed for any individual who has a duty to res
|
||||
pond to emergencies. It combines lectures and video with hands-on sk
|
||||
ill training and it incorporates real-life rescue scenarios and lessons th
|
||||
at reinforce decision-making skills. This class covers Adult/Child A
|
||||
ED & CPR and Infant CPR; two-person CPR; use of a bag-valve mask; a
|
||||
nd introduction to Emergency Medical Services and bloodbourne pathogens.**
|
||||
This course meets Level C CPR requirements. It is the pre-requisite
|
||||
for most nursing and EMT programs. ** Course continues Tuesday \
|
||||
;April 26, 6:00pm - 10:00pm Dixon Upper Classroom.
|
||||
DTSTART:20110426T010000Z
|
||||
DTEND:20110426T050000Z
|
||||
LAST-MODIFIED:20110301T215024Z
|
||||
CREATED:20110301T215024Z
|
||||
DTSTAMP:20110301T215024Z
|
||||
CONTACT:Recreation Services
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
EOICAL
|
||||
|
||||
my $snippet_feed = $home->addChild({
|
||||
className => 'WebGUI::Asset::Snippet',
|
||||
url => 'icalFeed.ics',
|
||||
snippet => $ical_feed,
|
||||
mimeType => 'text/calendar',
|
||||
});
|
||||
|
||||
my $tag = WebGUI::VersionTag->getWorking($session);
|
||||
$tag->commit;
|
||||
WebGUI::Test->addToCleanup($tag);
|
||||
|
||||
$snippet_feed = $snippet_feed->cloneFromDb;
|
||||
|
||||
my $workflow = WebGUI::Workflow->create($session,
|
||||
{
|
||||
enabled => 1,
|
||||
objectType => 'None',
|
||||
mode => 'realtime',
|
||||
},
|
||||
);
|
||||
WebGUI::Test->addToCleanup($workflow);
|
||||
my $icalFetch = $workflow->addActivity('WebGUI::Workflow::Activity::CalendarUpdateFeeds');
|
||||
|
||||
my $instance1 = WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
workflowId => $workflow->getId,
|
||||
skipSpectreNotification => 1,
|
||||
}
|
||||
);
|
||||
|
||||
my $oldEvents = $receiver->getLineage(['children'], { returnObjects => 1, });
|
||||
is(scalar @{ $oldEvents }, 0, 'receiving calendar has no events');
|
||||
|
||||
my $retVal;
|
||||
|
||||
$retVal = $instance1->run();
|
||||
is($retVal, 'complete', 'cleanup: activity complete');
|
||||
$retVal = $instance1->run();
|
||||
is($retVal, 'done', 'cleanup: activity is done');
|
||||
$instance1->delete;
|
||||
|
||||
my $newEvents = $receiver->getLineage(['children'], { returnObjects => 1, });
|
||||
|
||||
my $got_anniversary = is(scalar @{ $newEvents }, 1, 'ical import of 1 event');
|
||||
|
||||
SKIP: {
|
||||
skip "No event recieved", 15 unless $got_anniversary;
|
||||
my $anniversary = pop @{ $newEvents };
|
||||
|
||||
is($anniversary->get('title'), $party->get('title'), 'transferred title');
|
||||
is($anniversary->get('menuTitle'), $party->get('menuTitle'), '... menuTitle');
|
||||
is($anniversary->get('groupIdView'), $party->get('groupIdView'), '... groupIdView');
|
||||
is($anniversary->get('groupIdEdit'), $party->get('groupIdEdit'), '... groupIdEdit');
|
||||
is($anniversary->get('url'), $party->get('url').'2', '... url (accounting for duplicate)');
|
||||
is($anniversary->get('timeZone'), $party->get('timeZone'), '... timeZone');
|
||||
is($anniversary->get('startDate'), $party->get('startDate'), '... startDate');
|
||||
is($anniversary->get('startTime'), $party->get('startTime'), '... startTime');
|
||||
is($anniversary->get('endDate'), $party->get('endDate'), '... endDate');
|
||||
is($anniversary->get('endTime'), $party->get('endTime'), '... endTime');
|
||||
is_string($anniversary->get('description'), $party->get('description'), '... description, checks for line wrapping');
|
||||
|
||||
$party->update({description => "one line\nsecond line"});
|
||||
|
||||
my $instance2 = WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
workflowId => $workflow->getId,
|
||||
skipSpectreNotification => 1,
|
||||
}
|
||||
);
|
||||
|
||||
$retVal = $instance2->run();
|
||||
is($retVal, 'complete', 'cleanup: 2nd activity complete');
|
||||
$retVal = $instance2->run();
|
||||
is($retVal, 'done', 'cleanup: 2nd activity is done');
|
||||
|
||||
$newEvents = $receiver->getLineage(['children'], { returnObjects => 1, });
|
||||
|
||||
is(scalar @{ $newEvents }, 1, 'reimport does not create new children');
|
||||
$anniversary = pop @{ $newEvents };
|
||||
is($anniversary->get('description'), $party->get('description'), '... description, checks for line unwrapping');
|
||||
$anniversary->purge;
|
||||
}
|
||||
|
||||
##Add an ical feed to check time zone processing
|
||||
|
||||
$receiver->deleteFeed($feedId);
|
||||
$feedId = $receiver->addFeed({
|
||||
url => $session->url->getSiteURL.$snippet_feed->getUrl,
|
||||
lastUpdated => 'never',
|
||||
});
|
||||
|
||||
$oldEvents = $receiver->getLineage(['children'], { returnObjects => 1, });
|
||||
is(scalar @{ $oldEvents }, 0, 'receiving calendar has no events');
|
||||
|
||||
$instance1->delete('skipNotify');
|
||||
$instance1 = WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
workflowId => $workflow->getId,
|
||||
skipSpectreNotification => 1,
|
||||
}
|
||||
);
|
||||
|
||||
my $retVal;
|
||||
|
||||
$retVal = $instance1->run();
|
||||
is($retVal, 'complete', 'cleanup: activity complete');
|
||||
$retVal = $instance1->run();
|
||||
is($retVal, 'done', 'cleanup: activity is done');
|
||||
$instance1->delete;
|
||||
|
||||
$newEvents = $receiver->getLineage(['children'], { returnObjects => 1, });
|
||||
|
||||
my $got_cpr = is(scalar @{ $newEvents }, 1, 'ical import of 1 event');
|
||||
|
||||
##Add a feed that will fail, to test that feeds are not modified
|
||||
$receiver->deleteFeed($feedId);
|
||||
my $feedUrl = $session->url->getSiteURL.'do_not_hack_my_url';
|
||||
$feedId = $receiver->addFeed({
|
||||
url => $feedUrl,
|
||||
lastUpdated => 'never',
|
||||
});
|
||||
|
||||
$instance1->delete('skipNotify');
|
||||
$instance1 = WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
workflowId => $workflow->getId,
|
||||
skipSpectreNotification => 1,
|
||||
}
|
||||
);
|
||||
|
||||
my $retVal;
|
||||
|
||||
$retVal = $instance1->run();
|
||||
is($retVal, 'complete', 'cleanup: activity complete');
|
||||
$retVal = $instance1->run();
|
||||
is($retVal, 'done', 'cleanup: activity is done');
|
||||
$instance1->delete;
|
||||
|
||||
$receiver = $receiver->cloneFromDb;
|
||||
my $feed = $receiver->getFeed($feedId);
|
||||
|
||||
##Note, cannot use Test::Deep in here because Asset/Event.pm use Test::Deep::NoTest
|
||||
|
||||
is $feed->{lastResult}, 'Error parsing iCal feed', 'After fetching a bad feed it updated the lastResult';
|
||||
is $feed->{url}, $feedUrl, '... nothing added to feed URL';
|
||||
|
||||
#vim:ft=perl
|
||||
115
t/Workflow/Activity/DeleteExpiredSessions.t
Normal file
115
t/Workflow/Activity/DeleteExpiredSessions.t
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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::Workflow::Activity::DeleteExpiredSessions;
|
||||
|
||||
use Test::More;
|
||||
|
||||
plan tests => 7; # increment this value for each test you create
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
my $workflow = WebGUI::Workflow->create($session,
|
||||
{
|
||||
enabled => 1,
|
||||
objectType => 'None',
|
||||
mode => 'realtime',
|
||||
},
|
||||
);
|
||||
WebGUI::Test->addToCleanup($workflow);
|
||||
my $activity = $workflow->addActivity('WebGUI::Workflow::Activity::DeleteExpiredSessions');
|
||||
|
||||
my $instance1 = WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
workflowId => $workflow->getId,
|
||||
skipSpectreNotification => 1,
|
||||
}
|
||||
);
|
||||
|
||||
my $retVal;
|
||||
|
||||
$retVal = $instance1->run();
|
||||
is($retVal, 'complete', 'cleanup: activity complete');
|
||||
$retVal = $instance1->run();
|
||||
is($retVal, 'done', 'cleanup: activity is done');
|
||||
$instance1->delete('skipNotify');
|
||||
|
||||
my $origSessionTimeout = $session->setting->get('sessionTimeout');
|
||||
|
||||
my $sessionCount = $session->db->quickScalar('select count(*) from userSession');
|
||||
my $scratchCount = $session->db->quickScalar('select count(*) from userSessionScratch');
|
||||
|
||||
my @sessions;
|
||||
|
||||
foreach (1..2) {
|
||||
push @sessions, WebGUI::Session->open(WebGUI::Test->root, WebGUI::Test->file);
|
||||
}
|
||||
|
||||
##Force automatic expiration of the sessions
|
||||
$session->setting->set('sessionTimeout', -500);
|
||||
|
||||
foreach (1..2) {
|
||||
push @sessions, WebGUI::Session->open(WebGUI::Test->root, WebGUI::Test->file);
|
||||
}
|
||||
|
||||
$session->setting->set('sessionTimeout', $origSessionTimeout );
|
||||
|
||||
my $newSessionCount = $session->db->quickScalar('select count(*) from userSession');
|
||||
my $newScratchCount = $session->db->quickScalar('select count(*) from userSessionScratch');
|
||||
|
||||
is ($newSessionCount, $sessionCount+4, 'all new sessions created correctly');
|
||||
is ($newScratchCount, $scratchCount+4, 'all new user sessions created correctly');
|
||||
|
||||
my $instance2 = WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
workflowId => $workflow->getId,
|
||||
skipSpectreNotification => 1,
|
||||
}
|
||||
);
|
||||
WebGUI::Test->addToCleanup($instance2);
|
||||
|
||||
my $counter = 0;
|
||||
PAUSE: while ($retVal = $instance2->run()) {
|
||||
last PAUSE if $retVal eq 'done';
|
||||
last PAUSE if $counter > 6; #Emergency exit clause
|
||||
}
|
||||
|
||||
is($retVal, 'done', 'Workflow completed successfully');
|
||||
|
||||
$newSessionCount = $session->db->quickScalar('select count(*) from userSession');
|
||||
$newScratchCount = $session->db->quickScalar('select count(*) from userSessionScratch');
|
||||
|
||||
is ($newSessionCount, $sessionCount+2, 'two of the sessions were deleted');
|
||||
is ($newScratchCount, $scratchCount+2, 'scratch from both sessions cleaned up');
|
||||
|
||||
foreach my $testSession (@sessions) {
|
||||
$testSession->var->end;
|
||||
$testSession->close;
|
||||
}
|
||||
|
||||
##Add 4 sessions:
|
||||
## 1) Active session
|
||||
## 2) Active session with scratch
|
||||
## 3) Expired session
|
||||
## 4) Expired session with scratch
|
||||
##
|
||||
## run deleteExpiredSessions
|
||||
## Make sure that the two session were kept and the other two deleted.
|
||||
## Make sure that one scratch session was deleted and the other kept.
|
||||
## Close and end all four sessions
|
||||
|
||||
#vim:ft=perl
|
||||
161
t/Workflow/Activity/ExpireIncompleteSurveyResponses.t
Normal file
161
t/Workflow/Activity/ExpireIncompleteSurveyResponses.t
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
# Test WebGUI::Workflow::Activity::ExpireIncompleteSurveyResponses
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use FindBin qw($Bin);
|
||||
use lib "$FindBin::Bin/../../lib";
|
||||
use WebGUI::Test;
|
||||
use Test::More;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
plan tests => 26;
|
||||
|
||||
use_ok('WebGUI::Workflow::Activity::ExpireIncompleteSurveyResponses');
|
||||
|
||||
my $SQL = WebGUI::Workflow::Activity::ExpireIncompleteSurveyResponses->getSql;
|
||||
|
||||
my $wf = WebGUI::Workflow->create($session, {
|
||||
title => 'Test ExpireIncompleteSurveyResponses',
|
||||
enabled => 1,
|
||||
type => 'None',
|
||||
mode => 'realtime',
|
||||
});
|
||||
isa_ok($wf, 'WebGUI::Workflow', 'Test workflow');
|
||||
WebGUI::Test->addToCleanup($wf);
|
||||
|
||||
my $activity = $wf->addActivity('WebGUI::Workflow::Activity::ExpireIncompleteSurveyResponses');
|
||||
isa_ok($activity, 'WebGUI::Workflow::Activity::ExpireIncompleteSurveyResponses', 'Test wf activity');
|
||||
$activity->set('title', 'Test Expire Incomplete Survey Responses');
|
||||
|
||||
my $user = WebGUI::User->new($session, 'new');
|
||||
WebGUI::Test->addToCleanup($user);
|
||||
|
||||
# Create a Survey
|
||||
my $survey = WebGUI::Asset->getImportNode($session)->addChild( { className => 'WebGUI::Asset::Wobject::Survey', } );
|
||||
WebGUI::Test->addToCleanup(WebGUI::VersionTag->getWorking($session));
|
||||
WebGUI::Test->addToCleanup($survey);
|
||||
my $sJSON = $survey->surveyJSON;
|
||||
$sJSON->newObject([0]); # add a question to 0th section
|
||||
$sJSON->update([0,0], { questionType => 'Yes/No' });
|
||||
$survey->persistSurveyJSON;
|
||||
|
||||
# Initially, sql returns no resuts
|
||||
is( scalar $session->db->buildArray($SQL), 0, 'No incomplete responses');
|
||||
|
||||
# Now start a response as the test user
|
||||
$session->user( { user => $user } );
|
||||
my $responseId = $survey->responseId;
|
||||
ok($responseId, 'Started a survey response');
|
||||
my ($endDate, $isComplete) = $session->db->quickArray('select endDate, isComplete from Survey_response where Survey_responseId = ?', [$responseId]);
|
||||
is($endDate, 0, '..currently with no endDate');
|
||||
is($isComplete, 0, '..and marked as in-progress');
|
||||
|
||||
# Still no resuts
|
||||
is( scalar $session->db->buildArray($SQL), 0, 'Still no incomplete responses');
|
||||
|
||||
WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
workflowId => $wf->getId,
|
||||
skipSpectreNotification => 1,
|
||||
priority => 1,
|
||||
}
|
||||
)->start;
|
||||
($endDate, $isComplete) = $session->db->quickArray('select endDate, isComplete from Survey_response where Survey_responseId = ?', [$responseId]);
|
||||
is($endDate + $isComplete, 0, '..no change after workflow runs the first time');
|
||||
|
||||
# Change survey time limit
|
||||
ok(!$survey->hasTimedOut, 'Survey has not timed out (yet)');
|
||||
$survey->update( { timeLimit => 1 } );
|
||||
$survey->startDate($survey->startDate - 100);
|
||||
ok($survey->hasTimedOut, '..until we set a timeLimit and push startDate into the past');
|
||||
|
||||
# Now we have 1 incomplete response
|
||||
is( scalar $session->db->buildArray($SQL), 1, 'Now we have 1 incomplete response');
|
||||
|
||||
WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
workflowId => $wf->getId,
|
||||
skipSpectreNotification => 1,
|
||||
priority => 1,
|
||||
}
|
||||
)->start;
|
||||
($endDate, $isComplete) = $session->db->quickArray('select endDate, isComplete from Survey_response where Survey_responseId = ?', [$responseId]);
|
||||
ok($endDate, 'endDate now set');
|
||||
is($isComplete, 3, '..and isComplete set to timeout code');
|
||||
|
||||
# Afterwards, back to no incomplete responses
|
||||
is( scalar $session->db->buildArray($SQL), 0, 'Afterwards, back to no incomplete responses');
|
||||
|
||||
# Undo out handiwork, and chage doAfterTimeLimit to restartSurvey so that we get a different completeCode
|
||||
$session->db->write('update Survey_response set endDate = 0, isComplete = 0 where Survey_responseId = ?', [$responseId]);
|
||||
$survey->update( { doAfterTimeLimit => 'restartSurvey' } );
|
||||
|
||||
# Now we have 1 incomplete response again
|
||||
is( scalar $session->db->buildArray($SQL), 1, 'Now we have 1 incomplete response again');
|
||||
|
||||
WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
workflowId => $wf->getId,
|
||||
skipSpectreNotification => 1,
|
||||
priority => 1,
|
||||
}
|
||||
)->start;
|
||||
($endDate, $isComplete) = $session->db->quickArray('select endDate, isComplete from Survey_response where Survey_responseId = ?', [$responseId]);
|
||||
ok($endDate, 'endDate set again');
|
||||
is($isComplete, 4, '..and isComplete now set to timeoutRestart code');
|
||||
|
||||
# Afterwards, back to no incomplete responses
|
||||
is( scalar $session->db->buildArray($SQL), 0, 'Afterwards, back to no incomplete responses');
|
||||
|
||||
##
|
||||
# Explicitly test for bug that existed in SQL whereby one email per revision would be sent
|
||||
##
|
||||
|
||||
# Create a new revision
|
||||
$survey->addRevision({}, time+1);
|
||||
WebGUI::Test->addToCleanup(WebGUI::VersionTag->getWorking($session));
|
||||
|
||||
# Undo out handiwork again
|
||||
is($session->db->quickScalar('select count(*) from Survey_response where Survey_responseId = ?', [$responseId]), 1, 'Start off with 1 response');
|
||||
$session->db->write('update Survey_response set endDate = 0, isComplete = 0 where Survey_responseId = ?', [$responseId]);
|
||||
|
||||
# Make sure SQL only returns 1 incomplete response
|
||||
is( scalar $session->db->buildArray($SQL), 1, 'Make sure SQL only returns 1 incomplete response');
|
||||
|
||||
##
|
||||
# Make sure workflow handles responses for deleted users
|
||||
#
|
||||
$session->db->write('update Survey_response set userId = ? where Survey_responseId = ?', ['not-a-user-id', $responseId]);
|
||||
is( scalar $session->db->buildArray($SQL), 1, 'Still returns 1 row, even though user does not exist (sql left outer join)');
|
||||
$session->db->write('update Survey_response set userId = ? where Survey_responseId = ?', [$user->getId, $responseId]);
|
||||
|
||||
##
|
||||
# Delete Expired
|
||||
##
|
||||
|
||||
# Undo out handiwork again, and chage workflow to delete
|
||||
is($session->db->quickScalar('select count(*) from Survey_response where Survey_responseId = ?', [$responseId]), 1, 'Start off with 1 response');
|
||||
$session->db->write('update Survey_response set endDate = 0, isComplete = 0 where Survey_responseId = ?', [$responseId]);
|
||||
$activity->set('deleteExpired', 1);
|
||||
|
||||
# Now we have 1 incomplete response again
|
||||
is( scalar $session->db->buildArray($SQL), 1, 'Now we have 1 incomplete response again');
|
||||
|
||||
WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
workflowId => $wf->getId,
|
||||
skipSpectreNotification => 1,
|
||||
priority => 1,
|
||||
}
|
||||
)->start;
|
||||
is($session->db->quickScalar('select count(*) from Survey_response where Survey_responseId = ?', [$responseId]), 0, 'Response has now been deleted');
|
||||
|
||||
# Afterwards, back to no incomplete responses
|
||||
is( scalar $session->db->buildArray($SQL), 0, 'Afterwards, back to no incomplete responses');
|
||||
|
||||
#vim:ft=perl
|
||||
145
t/Workflow/Activity/ExtendCalendarRecurrences.t
Normal file
145
t/Workflow/Activity/ExtendCalendarRecurrences.t
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
# 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 lib "$FindBin::Bin/../../t/lib";
|
||||
use Test::More;
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Workflow::Activity::ExtendCalendarRecurrences;
|
||||
use DateTime;
|
||||
use Data::Dumper;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
my $temp = WebGUI::Asset->getTempspace($session);
|
||||
|
||||
my $tag = WebGUI::VersionTag->getWorking($session);
|
||||
WebGUI::Test::addToCleanup($tag);
|
||||
|
||||
my $calendar = $temp->addChild(
|
||||
{ className => 'WebGUI::Asset::Wobject::Calendar' }
|
||||
);
|
||||
|
||||
my $eventStartDate = DateTime->today->truncate(to => 'month')->subtract(years => 1);
|
||||
|
||||
my $one_year_ago = $eventStartDate->ymd;
|
||||
|
||||
my $event = $calendar->addChild(
|
||||
{ className => 'WebGUI::Asset::Event',
|
||||
startDate => $one_year_ago,
|
||||
endDate => $one_year_ago,
|
||||
}, undef, undef, {skipAutoCommitWorkflows => 1, }
|
||||
);
|
||||
|
||||
my $trashed_event = $calendar->addChild(
|
||||
{ className => 'WebGUI::Asset::Event',
|
||||
startDate => $one_year_ago,
|
||||
endDate => $one_year_ago,
|
||||
}, undef, undef, {skipAutoCommitWorkflows => 1, }
|
||||
);
|
||||
$trashed_event->trash;
|
||||
|
||||
my $clipped_event = $calendar->addChild(
|
||||
{ className => 'WebGUI::Asset::Event',
|
||||
startDate => $one_year_ago,
|
||||
endDate => $one_year_ago,
|
||||
}, undef, undef, {skipAutoCommitWorkflows => 1, }
|
||||
);
|
||||
$clipped_event->cut;
|
||||
|
||||
$tag->commit;
|
||||
foreach my $asset($calendar, $event, $clipped_event, $trashed_event) {
|
||||
$asset = $asset->cloneFromDb;
|
||||
}
|
||||
|
||||
my $recurId = $event->setRecurrence(
|
||||
{ recurType => 'monthDay',
|
||||
every => 2,
|
||||
startDate => $event->get('startDate'),
|
||||
dayNumber => $eventStartDate->day,
|
||||
}
|
||||
);
|
||||
|
||||
$trashed_event->setRecurrence(
|
||||
{ recurType => 'monthDay',
|
||||
every => 2,
|
||||
startDate => $trashed_event->get('startDate'),
|
||||
dayNumber => $eventStartDate->day,
|
||||
}
|
||||
);
|
||||
|
||||
$clipped_event->setRecurrence(
|
||||
{ recurType => 'monthDay',
|
||||
every => 2,
|
||||
startDate => $clipped_event->get('startDate'),
|
||||
dayNumber => $eventStartDate->day,
|
||||
}
|
||||
);
|
||||
|
||||
my $workflow = WebGUI::Workflow->create(
|
||||
$session, {
|
||||
enabled => 1,
|
||||
objectType => 'None',
|
||||
mode => 'realtime',
|
||||
},
|
||||
);
|
||||
|
||||
WebGUI::Test::addToCleanup($workflow);
|
||||
|
||||
my $activity =
|
||||
$workflow->addActivity('WebGUI::Workflow::Activity::ExtendCalendarRecurrences');
|
||||
|
||||
my $calendars = [ $calendar->getId ];
|
||||
{
|
||||
# We only want to be testing our calendar, not any others in the asset
|
||||
# tree.
|
||||
no warnings 'redefine';
|
||||
sub WebGUI::Workflow::Activity::ExtendCalendarRecurrences::findCalendarIds {
|
||||
return $calendars;
|
||||
}
|
||||
}
|
||||
|
||||
is $activity->findCalendarIds, $calendars, 'mocking worked';
|
||||
|
||||
my $instance = WebGUI::Workflow::Instance->create(
|
||||
$session, {
|
||||
workflowId => $workflow->getId,
|
||||
skipSpectreNotification => 1,
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
while (my $status = $instance->run ne 'complete') {
|
||||
note $status;
|
||||
$instance->run;
|
||||
}
|
||||
|
||||
#my $sql = q{
|
||||
# select e.startDate, e.endDate
|
||||
# from asset a
|
||||
# inner join Event e on e.assetId = a.assetId
|
||||
# and a.parentId = ?
|
||||
# order by e.startDate
|
||||
#};
|
||||
|
||||
#my $dates = $session->db->buildArrayRefOfHashRefs($sql, [$calendar->getId]);
|
||||
my $dates = $calendar->getLineage(['children'], { returnObjects => 1, });
|
||||
# 3 years at every other month (6 times) plus the one we started with
|
||||
is(@{$dates}, 19, 'created right number of dates') or diag Dumper $dates;
|
||||
|
||||
my @uncommitted_events = grep { $_->get('status') ne 'approved' } @{ $dates };
|
||||
is @uncommitted_events, 0, 'all events are committed (approved)';
|
||||
|
||||
done_testing;
|
||||
|
||||
#vim:ft=perl
|
||||
146
t/Workflow/Activity/GetCsMail.t
Normal file
146
t/Workflow/Activity/GetCsMail.t
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
# 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 Test::MockObject;
|
||||
use Test::MockObject::Extends;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 4; # Increment this number for each test you create
|
||||
|
||||
my $sendmock = Test::MockObject->new( {} );
|
||||
$sendmock->set_isa('WebGUI::Mail::Send');
|
||||
$sendmock->set_true('addText', 'send');
|
||||
local *WebGUI::Mail::Send::create;
|
||||
$sendmock->fake_module('WebGUI::Mail::Send',
|
||||
create => sub { return $sendmock },
|
||||
);
|
||||
|
||||
my $getmock = Test::MockObject->new( {} );
|
||||
$getmock->set_isa('WebGUI::Mail::Get');
|
||||
# false for now. use set_series later to add list of messages.
|
||||
$getmock->set_false('getNextMessage');
|
||||
$getmock->set_true('disconnect');
|
||||
local *WebGUI::Mail::Get::connect;
|
||||
$getmock->fake_module('WebGUI::Mail::Get',
|
||||
connect => sub { return $getmock },
|
||||
);
|
||||
|
||||
my $activity = Test::MockObject::Extends->new( 'WebGUI::Workflow::Activity::GetCsMail' );
|
||||
$activity->set_always('session', $session);
|
||||
$activity->set_always('getTTL', 60);
|
||||
$activity->set_always('COMPLETE', 'complete');
|
||||
my $parentAsset;
|
||||
$activity->mock('addPost', sub { $parentAsset = $_[1] } );
|
||||
|
||||
my $cs_id = 'MAILCS________________';
|
||||
my $post_id = 'MAILCSPOST____________';
|
||||
my $cs2_id = 'OTHERCS_______________';
|
||||
my $post2_id = 'OTHERCSPOST___________';
|
||||
|
||||
my $csmock = Test::MockObject->new({
|
||||
getMail => 1,
|
||||
postGroupId => 7,
|
||||
allowReplies => 1,
|
||||
});
|
||||
$csmock->set_isa('WebGUI::Asset::Wobject::Collaboration');
|
||||
$csmock->mock('get', sub {
|
||||
my $self = shift;
|
||||
if (@_) {
|
||||
return $self->{$_[0]};
|
||||
}
|
||||
return $self;
|
||||
});
|
||||
$csmock->set_always('getId', $cs_id);
|
||||
|
||||
my $postmock = Test::MockObject->new( {} );
|
||||
$postmock->set_isa('WebGUI::Asset::Post::Thread', 'WebGUI::Asset::Post');
|
||||
$postmock->set_always('getThread', $postmock);
|
||||
$postmock->set_always('getParent', $csmock);
|
||||
$postmock->set_always('getId', $post_id);
|
||||
|
||||
my $cs2mock = Test::MockObject->new({});
|
||||
$cs2mock->set_isa('WebGUI::Asset::Wobject::Collaboration');
|
||||
$cs2mock->set_always('getId', $cs2_id);
|
||||
|
||||
my $post2mock = Test::MockObject->new( {} );
|
||||
$post2mock->set_isa('WebGUI::Asset::Post::Thread', 'WebGUI::Asset::Post');
|
||||
$post2mock->set_always('getThread', $post2mock);
|
||||
$post2mock->set_always('getParent', $cs2mock);
|
||||
$post2mock->set_always('getId', $post2_id);
|
||||
|
||||
{
|
||||
$getmock->set_series('getNextMessage', {
|
||||
from => 'admin@localhost',
|
||||
parts => ['parts'],
|
||||
subject => 'Subject',
|
||||
messageId => 'Message Id',
|
||||
});
|
||||
$activity->execute($csmock);
|
||||
is $parentAsset->getId, $cs_id, 'add as new thread to current cs if not reply';
|
||||
}
|
||||
|
||||
{
|
||||
# simulate asset not found
|
||||
WebGUI::Test->mockAssetId($post2_id, undef);
|
||||
$getmock->set_series('getNextMessage', {
|
||||
from => 'admin@localhost',
|
||||
parts => ['parts'],
|
||||
subject => 'Subject',
|
||||
messageId => 'Message Id',
|
||||
inReplyTo => 'cs-' . $post2_id . '@',
|
||||
});
|
||||
$activity->execute($csmock);
|
||||
is $parentAsset->getId, $cs_id, 'add as new thread to current cs if reply to nonexistant post';
|
||||
WebGUI::Test->unmockAssetId($post2_id);
|
||||
}
|
||||
|
||||
{
|
||||
WebGUI::Test->mockAssetId($post2_id, $post2mock);
|
||||
$getmock->set_series('getNextMessage', {
|
||||
from => 'admin@localhost',
|
||||
parts => ['parts'],
|
||||
subject => 'Subject',
|
||||
messageId => 'Message Id',
|
||||
inReplyTo => 'cs-' . $post2_id . '@',
|
||||
});
|
||||
$activity->execute($csmock);
|
||||
is $parentAsset->getId, $cs_id, 'add as new thread to current cs if reply to post in another CS';
|
||||
WebGUI::Test->unmockAssetId($post2_id);
|
||||
}
|
||||
|
||||
{
|
||||
WebGUI::Test->mockAssetId($post_id, $postmock);
|
||||
$getmock->set_series('getNextMessage', {
|
||||
from => 'admin@localhost',
|
||||
parts => ['parts'],
|
||||
subject => 'Subject',
|
||||
messageId => 'Message Id',
|
||||
inReplyTo => 'cs-' . $post_id . '@',
|
||||
});
|
||||
$activity->execute($csmock);
|
||||
is $parentAsset->getId, $post_id, 'add as reply to post if reply to post in current CS';
|
||||
WebGUI::Test->unmockAssetId($post_id);
|
||||
}
|
||||
|
||||
#vim:ft=perl
|
||||
211
t/Workflow/Activity/NotifyAboutLowStock.t
Normal file
211
t/Workflow/Activity/NotifyAboutLowStock.t
Normal file
|
|
@ -0,0 +1,211 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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::Asset;
|
||||
use WebGUI::Asset::Sku::Product;
|
||||
use WebGUI::Workflow::Activity::NotifyAboutLowStock;
|
||||
use WebGUI::Inbox;
|
||||
|
||||
use Data::Dumper;
|
||||
use Test::More;
|
||||
use Test::Exception;
|
||||
use URI;
|
||||
|
||||
plan tests => 19; # increment this value for each test you create
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
$session->user({userId => 3});
|
||||
my $admin = $session->user;
|
||||
WebGUI::Test->addToCleanup(sub { WebGUI::Test->cleanupAdminInbox; });
|
||||
WebGUI::Test->addToCleanup(SQL => "delete from mailQueue where message like '%Threshold=15%'");
|
||||
my $inbox = WebGUI::Inbox->new($session);
|
||||
|
||||
my $import = WebGUI::Asset->getImportNode($session);
|
||||
|
||||
my $posters = $import->addChild({
|
||||
className => 'WebGUI::Asset::Sku::Product',
|
||||
url => 'cell_posters',
|
||||
title => "Red's Posters",
|
||||
}, undef, time()-15, { skipAutoCommitWorkflows => 1, });
|
||||
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||
$versionTag->commit();
|
||||
addToCleanup($versionTag);
|
||||
|
||||
my $ritaVarId = $posters->setCollateral('variantsJSON', 'variantId', 'new',
|
||||
{
|
||||
shortdesc => 'Rita Hayworth',
|
||||
varSku => 'rita-1',
|
||||
price => 10,
|
||||
weight => 1,
|
||||
quantity => 25,
|
||||
},
|
||||
);
|
||||
|
||||
my $raquelVarId = $posters->setCollateral('variantsJSON', 'variantId', 'new',
|
||||
{
|
||||
shortdesc => 'Raquel Welch',
|
||||
varSku => 'fuzzy-britches',
|
||||
price => 20,
|
||||
weight => 1,
|
||||
quantity => 500,
|
||||
},
|
||||
);
|
||||
|
||||
my $marilynVarId = $posters->setCollateral('variantsJSON', 'variantId', 'new',
|
||||
{
|
||||
shortdesc => 'Marilyn Monroe',
|
||||
varSku => 'subway-skirt',
|
||||
price => 50,
|
||||
weight => 1,
|
||||
quantity => 10,
|
||||
},
|
||||
);
|
||||
|
||||
my $workflow = WebGUI::Workflow->create($session,
|
||||
{
|
||||
enabled => 1,
|
||||
objectType => 'None',
|
||||
mode => 'realtime',
|
||||
},
|
||||
);
|
||||
addToCleanup($workflow);
|
||||
|
||||
my $threshold = $workflow->addActivity('WebGUI::Workflow::Activity::NotifyAboutLowStock');
|
||||
$threshold->set('className' , 'WebGUI::Activity::NotifyAboutLowStock');
|
||||
$threshold->set('toGroup' , 3);
|
||||
$threshold->set('subject' , 'Threshold=15');
|
||||
$threshold->set('warningLimit' , 15);
|
||||
|
||||
my $instance1 = WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
workflowId => $workflow->getId,
|
||||
skipSpectreNotification => 1,
|
||||
}
|
||||
);
|
||||
|
||||
my $retVal;
|
||||
|
||||
$retVal = $instance1->run();
|
||||
is($retVal, 'complete', 'First workflow was run');
|
||||
$retVal = $instance1->run();
|
||||
is($retVal, 'done', 'Workflow is done');
|
||||
|
||||
is($instance1->getScratch('LowStockMessage'), undef, 'No scratch data for message');
|
||||
is($instance1->getScratch('LowStockLast'), undef, 'No scratch data for last index');
|
||||
|
||||
my $messages = $inbox->getMessagesForUser($admin);
|
||||
is(scalar @{$messages}, 1, 'Received one message');
|
||||
|
||||
my $message = $messages->[0];
|
||||
|
||||
my $body = $message->get('message');
|
||||
is($message->get('subject'), 'Threshold=15', 'Message has the right subject');
|
||||
my @table = split /\n/, $body;
|
||||
my @urls = @table[2..$#table];
|
||||
pop @urls;
|
||||
is (scalar @urls, 1, 'Only one variant is below the threshold');
|
||||
my $url = pop @urls;
|
||||
$url =~ s/^.+?href="([^"]+)".+$/$1/;
|
||||
my $uri = URI->new($url);
|
||||
is($uri->path, $posters->getUrl, 'Link in message has correct URL path');
|
||||
is($uri->query, 'func=editVariant;vid='.$marilynVarId, 'Link in message has function and variant id');
|
||||
|
||||
WebGUI::Test->cleanupAdminInbox;
|
||||
is(scalar @{$inbox->getMessagesForUser($admin)}, 0, 'All messages deleted');
|
||||
$instance1->delete;
|
||||
|
||||
##Now, change the threshold and make sure that we get no messages
|
||||
$threshold->set('warningLimit', 2);
|
||||
is($threshold->get('warningLimit'), 2, 'Reset warningLimit to 2');
|
||||
|
||||
my $instance2 = WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
workflowId => $workflow->getId,
|
||||
skipSpectreNotification => 1,
|
||||
}
|
||||
);
|
||||
|
||||
$retVal = $instance2->run();
|
||||
is($retVal, 'complete', 'The workflow was run the second time');
|
||||
$retVal = $instance2->run();
|
||||
is($retVal, 'done', 'Workflow is done the second time');
|
||||
is(scalar @{$inbox->getMessagesForUser($admin)}, 0, 'No messages sent since threshold is below quantity of all products');
|
||||
|
||||
$message = $inbox->getMessagesForUser($admin)->[0];
|
||||
|
||||
note "Test that the workflow does not die when encountering bad assets";
|
||||
|
||||
my $otherPosters = $posters->duplicate;
|
||||
WebGUI::Test->addToCleanup(sub {
|
||||
$session->db->write("delete from asset where assetId=?",[$otherPosters->getId]);
|
||||
$session->db->write("delete from assetData where assetId=?",[$otherPosters->getId]);
|
||||
$session->db->write("delete from sku where assetId=?",[$otherPosters->getId]);
|
||||
$session->db->write("delete from Product where assetId=?",[$otherPosters->getId]);
|
||||
$session->db->write("delete from assetIndex where assetId=?",[$otherPosters->getId]);
|
||||
});
|
||||
my $movie_posters = $import->addChild({
|
||||
className => 'WebGUI::Asset::Sku::Product',
|
||||
url => 'movie_posters',
|
||||
title => "Movie Posters",
|
||||
}, undef, undef, { skipAutoCommitWorkflows => 1, });
|
||||
|
||||
my $movieVarId = $movie_posters->setCollateral('variantsJSON', 'variantId', 'new',
|
||||
{
|
||||
shortdesc => 'Shawshank Redemption',
|
||||
varSku => 'shawshank-1',
|
||||
price => 10,
|
||||
weight => 1,
|
||||
quantity => 5,
|
||||
},
|
||||
);
|
||||
my $otherTag = WebGUI::VersionTag->getWorking($session);
|
||||
addToCleanup($otherTag);
|
||||
$otherTag->commit;
|
||||
|
||||
$threshold->set('warningLimit' , 10);
|
||||
my $instance3 = WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
workflowId => $workflow->getId,
|
||||
skipSpectreNotification => 1,
|
||||
}
|
||||
);
|
||||
|
||||
$retVal = $instance3->run();
|
||||
$retVal = $instance3->run();
|
||||
is($retVal, 'done', 'Workflow is done');
|
||||
|
||||
$messages = $inbox->getMessagesForUser($admin);
|
||||
is(scalar @{$messages}, 1, 'Received one message');
|
||||
WebGUI::Test->cleanupAdminInbox;
|
||||
|
||||
my $instance4 = WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
workflowId => $workflow->getId,
|
||||
skipSpectreNotification => 1,
|
||||
}
|
||||
);
|
||||
#break the asset
|
||||
$session->db->write('delete from asset where assetId=?', [$otherPosters->getId]);
|
||||
is(WebGUI::Asset->new($session, $otherPosters->getId), undef, 'middle asset broken');
|
||||
|
||||
$retVal = $instance4->run();
|
||||
$retVal = $instance4->run();
|
||||
is($retVal, 'done', 'Workflow is done');
|
||||
|
||||
$messages = $inbox->getMessagesForUser($admin);
|
||||
is(scalar @{$messages}, 1, 'Still received one message');
|
||||
|
||||
#vim:ft=perl
|
||||
113
t/Workflow/Activity/RecheckVATNumber.t
Normal file
113
t/Workflow/Activity/RecheckVATNumber.t
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
# 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
|
||||
#------------------------------------------------------------------
|
||||
|
||||
# Write a little about what this script tests.
|
||||
#
|
||||
#
|
||||
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../../lib";
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||
use WebGUI::Session;
|
||||
|
||||
use WebGUI::Shop::TaxDriver::EU;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 9; # Increment this number for each test you create
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
{
|
||||
my @args;
|
||||
my $called = 0;
|
||||
my $return = '';
|
||||
local *WebGUI::Shop::TaxDriver::EU::recheckVATNumber = sub {
|
||||
my $self = shift;
|
||||
@args = @_;
|
||||
$called++;
|
||||
return $return;
|
||||
};
|
||||
|
||||
my $number = 'NL34567890';
|
||||
my $user = WebGUI::User->new( $session, 'new' );
|
||||
my $userId = $user->userId;
|
||||
addToCleanup( $user );
|
||||
|
||||
# --- valid number ----------------
|
||||
$return = 'VALID';
|
||||
my $instance = createInstance( $session, $number, $userId );
|
||||
|
||||
my $response = $instance->run;
|
||||
is( $response, 'complete', 'Activity completes when recheckVATNumber found a valid VAT number' );
|
||||
$response = $instance->run;
|
||||
is( $response, 'done', 'Workflow finishes on a valid number' );
|
||||
|
||||
cmp_ok( scalar( @args ), '==', 2, 'recheckVATNumber is passed 2 params' );
|
||||
cmp_ok( $args[0], 'eq', $number, 'first passed param is VATNumber' );
|
||||
cmp_ok( $args[1]->getId, 'eq', $userId, 'second passed param is correct user obect' );
|
||||
|
||||
cmp_ok( $called, '==', 1, 'recheckVATNumber is only called once per iteration' );
|
||||
|
||||
# --- Invalid number --------------
|
||||
$return = 'INVALID';
|
||||
my $instance = createInstance( $session, $number, $userId );
|
||||
|
||||
my $response = $instance->run;
|
||||
is( $response, 'complete', 'Activity completes when recheckVATNumber found an invalid VAT number' );
|
||||
$response = $instance->run;
|
||||
is( $response, 'done', 'Workflow finishes on an invalid number' );
|
||||
|
||||
# --- Connection problem ----------
|
||||
$return = 'UNKNOWN';
|
||||
my $instance = createInstance( $session, $number, $userId );
|
||||
|
||||
my $response = $instance->run;
|
||||
is( $response, 'waiting 3600', 'Activity waits for an hour when VIES is unavailable.' );
|
||||
}
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
sub createInstance {
|
||||
my $session = shift;
|
||||
my $number = shift;
|
||||
my $userId = shift;
|
||||
|
||||
my $workflow = WebGUI::Workflow->create($session, {
|
||||
enabled => 1,
|
||||
objectType => 'None',
|
||||
mode => 'realtime',
|
||||
} );
|
||||
my $activity = $workflow->addActivity( 'WebGUI::Workflow::Activity::RecheckVATNumber' );
|
||||
|
||||
addToCleanup( $workflow );
|
||||
|
||||
my $instance = WebGUI::Workflow::Instance->create( $session, {
|
||||
workflowId => $workflow->getId,
|
||||
skipSpectreNotification => 1,
|
||||
parameters => {
|
||||
vatNumber => $number,
|
||||
userId => $userId,
|
||||
}
|
||||
} );
|
||||
|
||||
return $instance;
|
||||
};
|
||||
|
||||
#vim:ft=perl
|
||||
108
t/Workflow/Activity/RemoveOldCarts.t
Normal file
108
t/Workflow/Activity/RemoveOldCarts.t
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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::Workflow::Activity::RemoveOldCarts;
|
||||
use WebGUI::Shop::Cart;
|
||||
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
|
||||
plan tests => 6; # increment this value for each test you create
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
$session->user({userId => 3});
|
||||
|
||||
my $root = WebGUI::Asset->getRoot($session);
|
||||
my $donation = $root->addChild({
|
||||
className => 'WebGUI::Asset::Sku::Donation',
|
||||
title => 'test donation',
|
||||
});
|
||||
my $tag = WebGUI::VersionTag->getWorking($session);
|
||||
$tag->commit;
|
||||
WebGUI::Test->addToCleanup($tag);
|
||||
|
||||
|
||||
my $cart1 = WebGUI::Shop::Cart->create($session);
|
||||
|
||||
my $session2 = WebGUI::Session->open(WebGUI::Test->root, WebGUI::Test->file);
|
||||
$session2->user({userId => 3});
|
||||
WebGUI::Test->addToCleanup($session2);
|
||||
my $cart2 = WebGUI::Shop::Cart->create($session2);
|
||||
$cart2->update({creationDate => time()-10000});
|
||||
|
||||
my @cartIds = $session->db->buildArray('select cartId from cart');
|
||||
cmp_bag(
|
||||
\@cartIds,
|
||||
[ $cart1->getId, $cart2->getId ],
|
||||
'Made two carts for testing'
|
||||
);
|
||||
|
||||
$donation->applyOptions({ price => 1111});
|
||||
my $item1 = $cart1->addItem($donation);
|
||||
|
||||
$donation->applyOptions({ price => 2222});
|
||||
my $item2 = $cart2->addItem($donation);
|
||||
|
||||
my @itemIds = $session->db->buildArray('select itemId from cartItem');
|
||||
cmp_bag(
|
||||
\@itemIds,
|
||||
[ $item1->getId, $item2->getId ],
|
||||
'Made two items for testing'
|
||||
);
|
||||
|
||||
my $workflow = WebGUI::Workflow->create($session,
|
||||
{
|
||||
enabled => 1,
|
||||
objectType => 'None',
|
||||
mode => 'realtime',
|
||||
},
|
||||
);
|
||||
my $guard0 = cleanupGuard($workflow);
|
||||
my $guard1 = cleanupGuard($cart1);
|
||||
my $guard2 = cleanupGuard($cart2);
|
||||
my $cartNuker = $workflow->addActivity('WebGUI::Workflow::Activity::RemoveOldCarts');
|
||||
$cartNuker->set('cartTimeout', 3600);
|
||||
|
||||
my $instance1 = WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
workflowId => $workflow->getId,
|
||||
skipSpectreNotification => 1,
|
||||
}
|
||||
);
|
||||
WebGUI::Test->addToCleanup($instance1);
|
||||
|
||||
my $retVal;
|
||||
|
||||
$retVal = $instance1->run();
|
||||
is($retVal, 'complete', 'cleanup: activity complete');
|
||||
$retVal = $instance1->run();
|
||||
is($retVal, 'done', 'cleanup: activity is done');
|
||||
$instance1->delete('skipNotify');
|
||||
|
||||
@cartIds = $session->db->buildArray('select cartId from cart');
|
||||
cmp_bag(
|
||||
\@cartIds,
|
||||
[ $cart1->getId, ],
|
||||
'Deleted 1 cart, the correct one'
|
||||
);
|
||||
|
||||
@itemIds = $session->db->buildArray('select itemId from cartItem');
|
||||
cmp_bag(
|
||||
\@itemIds,
|
||||
[ $item1->getId, ],
|
||||
'Deleted 1 item, the correct one'
|
||||
);
|
||||
135
t/Workflow/Activity/SendNewsletters.t
Normal file
135
t/Workflow/Activity/SendNewsletters.t
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
# 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 Test::Deep;
|
||||
use Data::Dumper;
|
||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||
use WebGUI::Session;
|
||||
use Test::MockObject;
|
||||
use Test::MockObject::Extends;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 1; # Increment this number for each test you create
|
||||
|
||||
##Disable sending email
|
||||
my $sendmock = Test::MockObject->new( {} );
|
||||
$sendmock->set_isa('WebGUI::Mail::Send');
|
||||
$sendmock->set_true('addText', 'send', 'addHeaderField', 'addHtml', 'queue', 'addFooter');
|
||||
local *WebGUI::Mail::Send::create;
|
||||
$sendmock->fake_module('WebGUI::Mail::Send',
|
||||
create => sub { return $sendmock },
|
||||
);
|
||||
|
||||
##Create Assets;
|
||||
my $home = WebGUI::Asset->getDefault($session);
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||
|
||||
#1234567890123456789012#
|
||||
my $templateId = 'NEWSLETTER_TEMPLATE___';
|
||||
|
||||
my $templateMock = Test::MockObject->new({});
|
||||
$templateMock->set_isa('WebGUI::Asset::Template');
|
||||
$templateMock->set_always('getId', $templateId);
|
||||
my $templateVars;
|
||||
$templateMock->mock('process', sub { $templateVars = $_[1]; } );
|
||||
|
||||
my $cs = $home->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Collaboration::Newsletter',
|
||||
title => 'Test Newsletter',
|
||||
enablePostMetaData => 1,
|
||||
newsletterTemplateId => $templateId, ##Mocked asset for doing template variable checks
|
||||
description => 'Fans of Shawshank Inmates',
|
||||
newsletterHeader => 'newsletter header',
|
||||
newsletterFooter => 'newsletter footer',
|
||||
});
|
||||
|
||||
my $thread = $cs->addChild({
|
||||
className => 'WebGUI::Asset::Post::Thread',
|
||||
title => 'Test Thread',
|
||||
content => 'This is the content',
|
||||
synopsis => 'This is the synopsis',
|
||||
}, undef, undef, {skipAutoCommitWorkflows => 1,});
|
||||
|
||||
$versionTag->commit;
|
||||
WebGUI::Test->addToCleanup($versionTag);
|
||||
|
||||
##Setup metadata
|
||||
$session->setting->set('metaDataEnabled', 1);
|
||||
$cs->addMetaDataField('new', 'newsletterCategory', '', '', 'radioList',
|
||||
join("\n", qw/Andy Red Boggs/),
|
||||
);
|
||||
|
||||
my $metaDataFields = buildNameIndex($cs->getMetaDataFields);
|
||||
$thread->updateMetaData($metaDataFields->{newsletterCategory}, 'Andy');
|
||||
|
||||
##Create subscriber user
|
||||
my $subscriber = WebGUI::User->create($session);
|
||||
$subscriber->update({ 'email', 'going@nowhere.com' });
|
||||
WebGUI::Test->addToCleanup($subscriber);
|
||||
$cs->setUserSubscriptions($metaDataFields->{newsletterCategory}."~Andy", $subscriber->getId);
|
||||
$session->db->write(<<EOSQL, [ time()-24*60*60, $cs->getId, $subscriber->getId ]);
|
||||
update Newsletter_subscriptions set lastTimeSent=? where assetId=? and userId=?
|
||||
EOSQL
|
||||
|
||||
##Setup the workflow activity to run
|
||||
my $activity = Test::MockObject::Extends->new( 'WebGUI::Workflow::Activity::SendNewsletters' );
|
||||
$activity->set_always('session', $session);
|
||||
$activity->set_always('getTTL', 60);
|
||||
$activity->set_always('COMPLETE', 'complete');
|
||||
|
||||
{
|
||||
WebGUI::Test->mockAssetId($templateId, $templateMock);
|
||||
$activity->execute();
|
||||
cmp_deeply(
|
||||
$templateVars,
|
||||
{
|
||||
title => 'Test Newsletter',
|
||||
description => 'Fans of Shawshank Inmates',
|
||||
footer => 'newsletter footer',
|
||||
header => 'newsletter header',
|
||||
thread_loop => [
|
||||
{
|
||||
body => 'This is the content',
|
||||
synopsis => 'This is the synopsis',
|
||||
title => 'Test Thread',
|
||||
url => re('test-newsletter/test-thread'),
|
||||
},
|
||||
],
|
||||
}
|
||||
);
|
||||
WebGUI::Test->unmockAssetId($templateId);
|
||||
}
|
||||
|
||||
foreach my $metadataId (keys %{ $cs->getMetaDataFields }) {
|
||||
$cs->deleteMetaDataField($metadataId);
|
||||
}
|
||||
|
||||
sub buildNameIndex {
|
||||
my ($fidStruct) = @_;
|
||||
my $nameStruct;
|
||||
foreach my $field ( values %{ $fidStruct } ) {
|
||||
$nameStruct->{ $field->{fieldName} } = $field->{fieldId};
|
||||
}
|
||||
return $nameStruct;
|
||||
}
|
||||
|
||||
#vim:ft=perl
|
||||
103
t/Workflow/Activity/TrashExpiredEvents.t
Normal file
103
t/Workflow/Activity/TrashExpiredEvents.t
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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::Workflow::Activity::TrashExpiredEvents;
|
||||
use WebGUI::Asset;
|
||||
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
|
||||
plan tests => 5; # increment this value for each test you create
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
$session->user({userId => 3});
|
||||
|
||||
my $bday = WebGUI::DateTime->new($session, WebGUI::Test->webguiBirthday)->cloneToUserTimeZone;
|
||||
my $now = WebGUI::DateTime->new($session, time())->cloneToUserTimeZone;
|
||||
my $tz = $session->datetime->getTimeZone();
|
||||
|
||||
my $root = WebGUI::Asset->getRoot($session);
|
||||
my $calendar = $root->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Calendar',
|
||||
title => 'Test Calendar',
|
||||
});
|
||||
my $wgBday = $calendar->addChild({
|
||||
className => 'WebGUI::Asset::Event',
|
||||
title => 'WebGUI Birthday',
|
||||
startDate => $bday->toDatabaseDate,
|
||||
endDate => $bday->toDatabaseDate,
|
||||
timeZone => $tz,
|
||||
}, undef, undef, {skipAutoCommitWorkflows => 1});
|
||||
|
||||
my $wrongBday = $calendar->addChild({
|
||||
className => 'WebGUI::Asset::Event',
|
||||
title => 'Wrong Birthday',
|
||||
startDate => $bday->toDatabaseDate,
|
||||
endDate => $bday->toDatabaseDate,
|
||||
timeZone => $tz,
|
||||
}, undef, time()-5, {skipAutoCommitWorkflows => 1});
|
||||
|
||||
$wrongBday->addRevision({
|
||||
startDate => $now->toDatabaseDate,
|
||||
endDate => $now->toDatabaseDate,
|
||||
}, undef, undef, {skipAutoCommitWorkflows => 1});
|
||||
|
||||
my $nowEvent = $calendar->addChild({
|
||||
className => 'WebGUI::Asset::Event',
|
||||
title => 'WebGUI Birthday',
|
||||
startDate => $now->toDatabaseDate,
|
||||
endDate => $now->toDatabaseDate,
|
||||
timeZone => $tz,
|
||||
}, undef, undef, {skipAutoCommitWorkflows => 1});
|
||||
|
||||
my $tag = WebGUI::VersionTag->getWorking($session);
|
||||
$tag->commit;
|
||||
WebGUI::Test->addToCleanup($tag);
|
||||
|
||||
my $workflow = WebGUI::Workflow->create($session,
|
||||
{
|
||||
enabled => 1,
|
||||
objectType => 'None',
|
||||
mode => 'realtime',
|
||||
},
|
||||
);
|
||||
WebGUI::Test->addToCleanup($workflow);
|
||||
my $eventNuker = $workflow->addActivity('WebGUI::Workflow::Activity::TrashExpiredEvents');
|
||||
$eventNuker->set('trashAfter', 3600);
|
||||
|
||||
my $instance1 = WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
workflowId => $workflow->getId,
|
||||
skipSpectreNotification => 1,
|
||||
}
|
||||
);
|
||||
|
||||
my $retVal;
|
||||
|
||||
$retVal = $instance1->run();
|
||||
is($retVal, 'complete', 'cleanup: activity complete');
|
||||
$retVal = $instance1->run();
|
||||
is($retVal, 'done', 'cleanup: activity is done');
|
||||
$instance1->delete('skipNotify');
|
||||
|
||||
my $wgBdayCopy = $wgBday->cloneFromDb;
|
||||
my $nowEventCopy = $nowEvent->cloneFromDb;
|
||||
my $wrongBdayCopy = $wrongBday->cloneFromDb;
|
||||
|
||||
is $wgBdayCopy->get('state'), 'trash', 'old event was trashed';
|
||||
is $nowEventCopy->get('state'), 'published', 'recent event was left alone';
|
||||
is $wrongBdayCopy->get('state'), 'published', 'revisioned event was left alone';
|
||||
86
t/Workflow/Activity/UpdateAssetSubscribers.t
Normal file
86
t/Workflow/Activity/UpdateAssetSubscribers.t
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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::Workflow::Activity::UpdateAssetSubscribers;
|
||||
use WebGUI::Asset;
|
||||
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
|
||||
plan tests => 4; # increment this value for each test you create
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
$session->user({userId => 3});
|
||||
|
||||
my $subscriberGroup = WebGUI::Group->new($session, "new"); ##Group to hold subscribers
|
||||
my $oldGroup = WebGUI::Group->new($session, "new"); ##Pretend group, old groupIdView
|
||||
my $betterGroup = WebGUI::Group->new($session, "new"); ##New group for groupIdView
|
||||
my $oldUser = WebGUI::User->create($session); ##User who should be unsubscribed
|
||||
my $betterUser = WebGUI::User->create($session); ##User who should remain subscribed
|
||||
my $otherUser = WebGUI::User->create($session); ##Just a user, we should never see him
|
||||
my $root = WebGUI::Asset->getRoot($session);
|
||||
my $cs = $root->addChild({
|
||||
className => 'WebGUI::Asset::Wobject::Collaboration',
|
||||
title => 'Test Calendar',
|
||||
subscriptionGroupId => $subscriberGroup->getId,
|
||||
groupIdView => $betterGroup->getId,
|
||||
});
|
||||
my $tag = WebGUI::VersionTag->getWorking($session);
|
||||
$tag->commit;
|
||||
WebGUI::Test->addToCleanup($tag, $oldGroup, $subscriberGroup, $betterGroup, $oldUser, $betterUser, $otherUser);
|
||||
|
||||
$subscriberGroup->addUsers([$oldUser->getId, $betterUser->getId, ]);
|
||||
$betterGroup->addUsers([$betterUser->getId, ]);
|
||||
|
||||
##Plan, since spectre isn't running, we manually simulate an update event and run the
|
||||
##workflow activity by hand.
|
||||
|
||||
cmp_bag(
|
||||
$subscriberGroup->getUsers,
|
||||
[$oldUser->getId, $betterUser->getId],
|
||||
'Initial subscribers are correct'
|
||||
);
|
||||
|
||||
##This workflowId needs to exist, since it's hardcoded in the CS asset
|
||||
my $workflow = WebGUI::Workflow->new($session, 'xR-_GRRbjBojgLsFx3dEMA');
|
||||
|
||||
my $instance1 = WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
workflowId => $workflow->getId,
|
||||
skipSpectreNotification => 1,
|
||||
className => 'WebGUI::Asset',
|
||||
methodName => 'newByDynamicClass',
|
||||
parameters => $cs->getId,
|
||||
}
|
||||
);
|
||||
WebGUI::Test->addToCleanup($instance1);
|
||||
|
||||
my $retVal;
|
||||
|
||||
$retVal = $instance1->run();
|
||||
is($retVal, 'complete', 'cleanup: activity complete');
|
||||
$retVal = $instance1->run();
|
||||
is($retVal, 'done', 'cleanup: activity is done');
|
||||
$instance1->delete('skipNotify');
|
||||
|
||||
$subscriberGroup->clearCaches;
|
||||
|
||||
cmp_bag(
|
||||
$subscriberGroup->getUsers,
|
||||
[$betterUser->getId],
|
||||
'Corrent user removed'
|
||||
);
|
||||
112
t/Workflow/Activity/WaitForUserConfirmation.t
Normal file
112
t/Workflow/Activity/WaitForUserConfirmation.t
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
use warnings;
|
||||
use strict;
|
||||
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../../lib";
|
||||
use lib "$FindBin::Bin/../../t/lib";
|
||||
|
||||
use WebGUI::Test;
|
||||
use Test::More tests => 28;
|
||||
use Test::MockObject;
|
||||
use Test::MockObject::Extends;
|
||||
use WebGUI::Workflow::Activity;
|
||||
use Kwargs;
|
||||
use URI;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
WebGUI::Test->originalConfig('templateParsers');
|
||||
$session->config->addToArray('templateParsers', 'WebGUI::Asset::Template::TemplateToolkit');
|
||||
|
||||
my $act = WebGUI::Workflow::Activity->newByPropertyHashRef(
|
||||
$session, {
|
||||
className => 'WebGUI::Workflow::Activity::WaitForUserConfirmation',
|
||||
activityId => 'test-activity',
|
||||
expireAfter => 60*60*24,
|
||||
waitBetween => 60*5,
|
||||
emailFrom => 3,
|
||||
emailSubject => 'Confirmation Email',
|
||||
templateParser => 'WebGUI::Asset::Template::TemplateToolkit',
|
||||
template => 'Hey [% user.firstName %] [% user.lastName %], '
|
||||
. 'click $link!',
|
||||
}
|
||||
);
|
||||
|
||||
is $act->wait, $act->WAITING(60*5), 'wait helper method';
|
||||
|
||||
$act = Test::MockObject::Extends->new($act);
|
||||
|
||||
my (%scratch, %profile);
|
||||
%profile = (
|
||||
email => 'target@test.com',
|
||||
firstName => 'Target',
|
||||
lastName => 'Targetson',
|
||||
);
|
||||
|
||||
my $user = Test::MockObject->new
|
||||
->mock(get => sub { \%profile })
|
||||
->mock(userId => sub { 'test-user-id' });
|
||||
|
||||
my $workflow = Test::MockObject->new
|
||||
->mock(setScratch => sub { $scratch{$_[1]} = $_[2] })
|
||||
->mock(getScratch => sub { $scratch{$_[1]} })
|
||||
->mock(getId => sub { 'test-workflow' });
|
||||
|
||||
my ($expired, $sent) = (0,0);
|
||||
$act->mock(sendEmail => sub { $sent++ })
|
||||
->mock(expire => sub { $expired++ })
|
||||
->mock(now => sub { 100 })
|
||||
->mock(token => sub { 'test-token' });
|
||||
|
||||
my $st = 'test-activity-status';
|
||||
|
||||
sub ex { $act->execute($user, $workflow) }
|
||||
sub clr {
|
||||
delete @scratch{'test-activity-started', $st};
|
||||
$sent = 0;
|
||||
$expired = 0;
|
||||
}
|
||||
|
||||
is ex, $act->wait, 'from scratch returns waiting';
|
||||
is $sent, 1, 'one email sent';
|
||||
is $scratch{$st}, 'waiting', 'scratch is waiting';
|
||||
is $scratch{'test-activity-started'}, 100, 'started at mocked time';
|
||||
is ex, $act->wait, 'still waiting';
|
||||
is $sent, 1, 'did not send second email';
|
||||
is $scratch{$st}, 'waiting', 'scratch still waiting';
|
||||
$scratch{$st} = 'done';
|
||||
is ex, $act->COMPLETE, 'returns complete after done';
|
||||
is ex, $act->COMPLETE, 'forever';
|
||||
is $expired, 0, 'not expired though';
|
||||
clr;
|
||||
is $act->execute($user, $workflow), $act->wait, 'waiting after clear';
|
||||
is $sent, 1, 'one email sent';
|
||||
$act->mock(now => sub { 60*60*24+101 });
|
||||
is ex, $act->COMPLETE, 'complete after expired';
|
||||
is $scratch{$st}, 'expired', 'expired status';
|
||||
is $expired, 1, 'expire called';
|
||||
|
||||
clr;
|
||||
my ($self, $to, $from, $subject, $body);
|
||||
$act->mock(
|
||||
sendEmail => sub {
|
||||
($self, $to, $from, $subject, $body) = kwn @_, 1,
|
||||
qw(to from subject body);
|
||||
}
|
||||
);
|
||||
ex;
|
||||
is $to, $user->userId, 'to';
|
||||
is $from, 3, 'from';
|
||||
is $subject, 'Confirmation Email', 'subject';
|
||||
my $link = URI->new($act->link($workflow));
|
||||
my %p = $link->query_form;
|
||||
is $body, "Hey Target Targetson, click $link!", 'body';
|
||||
is $p{token}, 'test-token', 'token in link';
|
||||
is $p{instanceId}, 'test-workflow', 'instance id in link';
|
||||
is $p{activityId}, 'test-activity', 'activity id in link';
|
||||
$act->unmock('token');
|
||||
is $act->link($workflow), $link, 'token only generated once';
|
||||
|
||||
ok !$act->confirm($workflow, 'not-the-token'), 'bad token';
|
||||
is $scratch{$st}, 'waiting', 'wait after bad';
|
||||
ok $act->confirm($workflow, 'test-token'), 'good token';
|
||||
is $scratch{$st}, 'done', 'done after good';
|
||||
226
t/Workflow/Instance.t
Normal file
226
t/Workflow/Instance.t
Normal file
|
|
@ -0,0 +1,226 @@
|
|||
# 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
|
||||
#------------------------------------------------------------------
|
||||
|
||||
# Tests for WebGUI::Workflow::Instance
|
||||
#
|
||||
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
use Test::Exception;
|
||||
use Scope::Guard;
|
||||
|
||||
use Test::MockObject;
|
||||
my $mockSpectre = Test::MockObject->new();
|
||||
my @spectreGuts = ();
|
||||
$mockSpectre->fake_module('WebGUI::Workflow::Spectre',
|
||||
'notify', sub{
|
||||
my ($message, $data) = @_;
|
||||
push @spectreGuts, [$message, $data];
|
||||
});
|
||||
$mockSpectre->mock('notify', sub{
|
||||
my ($message, $data) = @_;
|
||||
push @spectreGuts, [$message, $data];
|
||||
});
|
||||
$mockSpectre->fake_new('WebGUI::Workflow::Spectre');
|
||||
|
||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Workflow;
|
||||
use WebGUI::Workflow::Instance;
|
||||
use JSON;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 34; # Increment this number for each test you create
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# put your tests here
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# create a workflow instance
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
my $wf = WebGUI::Workflow->create(
|
||||
$session,
|
||||
{
|
||||
title => 'WebGUI::Workflow::Instance Test',
|
||||
description => 'Description',
|
||||
type => 'None',
|
||||
mode => 'singleton',
|
||||
}
|
||||
);
|
||||
isa_ok($wf, 'WebGUI::Workflow', 'workflow created for test');
|
||||
addToCleanup($wf);
|
||||
|
||||
# create an instance of $wfId
|
||||
my $properties = {
|
||||
workflowId=>$wf->getId,
|
||||
};
|
||||
my $dateUpdated = time();
|
||||
my $instance = WebGUI::Workflow::Instance->create($session, $properties);
|
||||
isa_ok($instance, 'WebGUI::Workflow::Instance', 'create: workflow instance');
|
||||
ok($session->getId, 'getId returns something');
|
||||
ok($session->id->valid($instance->getId), 'New workflow instance has a valid ID');
|
||||
is($instance->get('priority'), 2, 'Default instance priority is 2');
|
||||
cmp_ok(abs ($instance->get('lastUpdate')-$dateUpdated), '<=', 3, 'Date updated field set correctly when instance is created');
|
||||
|
||||
##Singleton checks
|
||||
my $otherInstance = WebGUI::Workflow::Instance->create($session, $properties);
|
||||
is ($otherInstance, undef, 'create: only allows one instance of a singleton to be created');
|
||||
|
||||
WebGUI::Test->interceptLogging;
|
||||
|
||||
$instance->set({ 'parameters' => {session => 1}, });
|
||||
$otherInstance = WebGUI::Workflow::Instance->create($session, {workflowId => $wf->getId, parameters => { session => 1,} });
|
||||
is($otherInstance, undef, 'create: another singleton instance can not be created if it the same parameters as a currently existing instance');
|
||||
my $expectedId = $wf->getId;
|
||||
like($WebGUI::Test::logger_info, qr/An instance of singleton workflow $expectedId already exists/, 'create: Warning logged for trying to make another singleton');
|
||||
|
||||
$otherInstance = WebGUI::Workflow::Instance->create($session, {workflowId => $wf->getId, parameters => { session => 2,}});
|
||||
isnt ($otherInstance, undef, 'create: another singleton instance can be created if it has different parameters');
|
||||
$otherInstance->delete;
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# getWorkflow
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
my $instanceWorkflow = $instance->getWorkflow;
|
||||
is($instanceWorkflow->getId, $wf->getId, 'getWorkflow returns a copy of the workflow for the instance');
|
||||
is($instanceWorkflow->getId, $wf->getId, 'getWorkflow, caching check');
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# new
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
$otherInstance = WebGUI::Workflow::Instance->new($session, 'neverAWebGUIId');
|
||||
is($otherInstance, undef, 'new: non-existant id returns undef');
|
||||
$otherInstance = WebGUI::Workflow::Instance->new($session, $instance->getId);
|
||||
isa_ok($otherInstance, 'WebGUI::Workflow::Instance', 'new with a valid id returns an Instance object');
|
||||
is($otherInstance->getId, $instance->getId, 'new returned the correct instance');
|
||||
is($otherInstance->{_started}, 1, 'By default, _started = 0');
|
||||
$otherInstance = WebGUI::Workflow::Instance->new($session, $instance->getId, 1);
|
||||
is($otherInstance->{_started}, 0, 'By default, _started = 1');
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# set, get
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
$instance->set({
|
||||
priority => 3,
|
||||
lastStatus => 'undefined',
|
||||
workflowId => 'notAWorkflowId',
|
||||
className => 'WebGUI::Session',
|
||||
methodName => 'open',
|
||||
currentActivityId => 'notAnActivityId',
|
||||
} , 1);
|
||||
is($instance->get('priority'), 3, 'set priority');
|
||||
is($instance->get('lastStatus'), 'undefined', 'set lastStatus');
|
||||
is($instance->get('workflowId'), 'notAWorkflowId', 'set workflowId');
|
||||
is($instance->get('className'), 'WebGUI::Session', 'set className');
|
||||
is($instance->get('methodName'), 'open', 'set methodName');
|
||||
is($instance->get('currentActivityId'), 'notAnActivityId', 'set currentActivityId');
|
||||
|
||||
$instance->set({
|
||||
priority => 0,
|
||||
lastStatus => '',
|
||||
workflowId => '',
|
||||
} , 1);
|
||||
is($instance->get('priority'), 3, 'set priority, is sticky');
|
||||
is($instance->get('lastStatus'), 'undefined', 'set lastStatus is sticky');
|
||||
is($instance->get('workflowId'), 'notAWorkflowId', 'set workflowId is sticky');
|
||||
|
||||
$instance->set({
|
||||
className => '',
|
||||
methodName => '',
|
||||
currentActivityId => 0,
|
||||
} , 1);
|
||||
is($instance->get('className'), '', 'set: className can be cleared');
|
||||
is($instance->get('methodName'), '', 'set: methodName can be cleared');
|
||||
is($instance->get('currentActivityId'), 0, 'set: currentActivityId can be cleared');
|
||||
|
||||
my $setTime = time();
|
||||
$instance->set({priority => 2}, 1);
|
||||
cmp_ok( abs($instance->get('lastUpdate') - $setTime), '<=', 2, 'set: lastUpdate set correctly');
|
||||
|
||||
my $params = [ '.38 revolver', 'oily', 'black and evil'];
|
||||
|
||||
$instance->set({parameters => $params},1);
|
||||
cmp_deeply($instance->get('parameters'), $params, 'set, get with parameter');
|
||||
|
||||
my $wf2 = WebGUI::Workflow->create(
|
||||
$session,
|
||||
{
|
||||
title => 'WebGUI::Workflow::Instance Test',
|
||||
description => 'Non-singleton test',
|
||||
type => 'None',
|
||||
}
|
||||
);
|
||||
addToCleanup($wf2);
|
||||
|
||||
my $wf2Instance = WebGUI::Workflow::Instance->create($session, {workflowId => $wf2->getId});
|
||||
cmp_deeply($wf2Instance->get('parameters'), {}, 'get returns {} for parameters when there are no parameters stored');
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# getObject
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
{
|
||||
my $return;
|
||||
Test::MockObject->fake_module('WebGUI::Test::Workflow::Instance::TestObject',
|
||||
new => sub {
|
||||
return $return;
|
||||
},
|
||||
);
|
||||
|
||||
my $wf3 = WebGUI::Workflow->create(
|
||||
$session,
|
||||
{
|
||||
title => 'WebGUI::Workflow::Instance Test',
|
||||
description => 'getObject test',
|
||||
type => 'WebGUI::Test::Workflow::Instance::TestObject',
|
||||
}
|
||||
);
|
||||
my $wf3guard = Scope::Guard->new(sub {
|
||||
$wf3->delete;
|
||||
});
|
||||
|
||||
my $wf3Instance = WebGUI::Workflow::Instance->create( $session, {
|
||||
workflowId => $wf3->getId,
|
||||
className => 'WebGUI::Test::Workflow::Instance::TestObject',
|
||||
methodName => 'new',
|
||||
});
|
||||
|
||||
dies_ok { $wf3Instance->getObject } 'getObject throws when instanciation returns undef';
|
||||
|
||||
$return = Test::MockObject->new;
|
||||
lives_and {
|
||||
is $wf3Instance->getObject, $return;
|
||||
} 'getObject is able to retrieve correct object';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue