webgui/t/Workflow.t
Doug Bell 277faae8a1 Merge commit 'v7.10.15' into 8
Conflicts:
	docs/gotcha.txt
	docs/previousVersion.sql
	docs/templates.txt
	lib/WebGUI.pm
	lib/WebGUI/Asset.pm
	lib/WebGUI/Asset/Event.pm
	lib/WebGUI/Asset/File.pm
	lib/WebGUI/Asset/MapPoint.pm
	lib/WebGUI/Asset/RichEdit.pm
	lib/WebGUI/Asset/Sku/Product.pm
	lib/WebGUI/Asset/Snippet.pm
	lib/WebGUI/Asset/Story.pm
	lib/WebGUI/Asset/Template.pm
	lib/WebGUI/Asset/Template/TemplateToolkit.pm
	lib/WebGUI/Asset/Wobject/Calendar.pm
	lib/WebGUI/Asset/Wobject/Carousel.pm
	lib/WebGUI/Asset/Wobject/Collaboration.pm
	lib/WebGUI/Asset/Wobject/Dashboard.pm
	lib/WebGUI/Asset/Wobject/DataForm.pm
	lib/WebGUI/Asset/Wobject/Folder.pm
	lib/WebGUI/Asset/Wobject/Map.pm
	lib/WebGUI/Asset/Wobject/Search.pm
	lib/WebGUI/Asset/Wobject/Shelf.pm
	lib/WebGUI/Asset/Wobject/StockData.pm
	lib/WebGUI/Asset/Wobject/StoryTopic.pm
	lib/WebGUI/Asset/Wobject/SyndicatedContent.pm
	lib/WebGUI/Asset/Wobject/Thingy.pm
	lib/WebGUI/Asset/Wobject/WeatherData.pm
	lib/WebGUI/AssetClipboard.pm
	lib/WebGUI/AssetCollateral/DataForm/Entry.pm
	lib/WebGUI/AssetExportHtml.pm
	lib/WebGUI/AssetLineage.pm
	lib/WebGUI/AssetMetaData.pm
	lib/WebGUI/AssetTrash.pm
	lib/WebGUI/AssetVersioning.pm
	lib/WebGUI/Auth.pm
	lib/WebGUI/Cache/CHI.pm
	lib/WebGUI/Content/AssetManager.pm
	lib/WebGUI/Fork/ProgressBar.pm
	lib/WebGUI/Form/JsonTable.pm
	lib/WebGUI/Form/TimeField.pm
	lib/WebGUI/Form/Zipcode.pm
	lib/WebGUI/Group.pm
	lib/WebGUI/International.pm
	lib/WebGUI/Macro/AssetProxy.pm
	lib/WebGUI/Macro/FileUrl.pm
	lib/WebGUI/Operation/SSO.pm
	lib/WebGUI/Operation/User.pm
	lib/WebGUI/Role/Asset/Subscribable.pm
	lib/WebGUI/Shop/Cart.pm
	lib/WebGUI/Shop/Transaction.pm
	lib/WebGUI/Shop/TransactionItem.pm
	lib/WebGUI/Test.pm
	lib/WebGUI/URL/Content.pm
	lib/WebGUI/URL/Uploads.pm
	lib/WebGUI/User.pm
	lib/WebGUI/Workflow/Activity/ExtendCalendarRecurrences.pm
	lib/WebGUI/Workflow/Activity/SendNewsletters.pm
	lib/WebGUI/i18n/English/Asset.pm
	lib/WebGUI/i18n/English/WebGUI.pm
	sbin/installClass.pl
	sbin/rebuildLineage.pl
	sbin/search.pl
	sbin/testEnvironment.pl
	t/Asset/Asset.t
	t/Asset/AssetClipboard.t
	t/Asset/AssetLineage.t
	t/Asset/AssetMetaData.t
	t/Asset/Event.t
	t/Asset/File.t
	t/Asset/File/Image.t
	t/Asset/Post/notification.t
	t/Asset/Sku.t
	t/Asset/Story.t
	t/Asset/Template.t
	t/Asset/Wobject/Collaboration/templateVariables.t
	t/Asset/Wobject/Collaboration/unarchiveAll.t
	t/Asset/Wobject/Shelf.t
	t/Auth.t
	t/Macro/EditableToggle.t
	t/Macro/FilePump.t
	t/Shop/Cart.t
	t/Shop/Transaction.t
	t/Storage.t
	t/User.t
	t/Workflow.t
2011-05-13 18:15:11 -05:00

266 lines
10 KiB
Perl

#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Workflow;
use WebGUI::Workflow::Cron;
use Test::More tests => 75; # increment this value for each test you create
use Test::Deep;
my $session = WebGUI::Test->session;
my $wf = WebGUI::Workflow->create($session, {title => 'Title', description => 'Description',
type => 'None'});
ok(defined $wf, 'can create workflow');
isa_ok($wf, 'WebGUI::Workflow', 'workflow');
my $wfId = $wf->getId;
ok(defined $wfId, 'workflow has an ID');
ok($session->id->valid($wfId), 'Workflow has a valid Id');
ok(defined WebGUI::Workflow->new($session, $wfId), 'workflow can be retrieved');
is($wf->get('title'), 'Title', 'workflow title is set');
is($wf->get('description'), 'Description', 'workflow description is set');
is($wf->get('type'), 'None', 'workflow type is set');
ok(!$wf->get('enabled'), 'workflow is not enabled');
# TODO: test other properties
is_deeply($wf->getActivities, [], 'workflow has no activities');
is_deeply($wf->getInstances, [], 'workflow has no instances');
is_deeply($wf->getCrons, [], 'workflow has no crons');
##################################################
#
# getList tests
#
##################################################
isa_ok(WebGUI::Workflow->getList($session), 'HASH', 'getList returns a hashref');
ok(! exists WebGUI::Workflow->getList($session)->{$wfId}, 'workflow not in enabled list');
is(scalar keys %{WebGUI::Workflow->getList($session)}, 13, 'There are thirteen enabled, default workflows, of all types, shipped with WebGUI');
$wf->set({enabled => 1});
ok($wf->get('enabled'), 'workflow is enabled');
ok(exists WebGUI::Workflow->getList($session)->{$wfId}, 'workflow in enabled list');
$wf->set({enabled => 0});
ok(!$wf->get('enabled'), 'workflow is disabled again');
is(scalar keys %{WebGUI::Workflow->getList($session, 'WebGUI::User')}, 1, 'There is only 1 WebGUI::User based workflow that ships with WebGUI');
##Throwing in another test here to test how enabled works. It should be sticky
$wf->set({enabled => 1});
ok($wf->get('enabled'), 'Enable workflow again');
$wf->set({description => 'Better stay enabled'});
ok($wf->get('enabled'), 'Workflow is enabled after setting the description');
$wf->set({enabled => 0});
##################################################
#
# Mode tests
#
##################################################
is($wf->get('mode'), 'parallel', 'default mode for created workflows is parallel');
ok(! $wf->isSingleton, 'Is not singleton');
ok(! $wf->isSerial, 'Is not serial');
ok(! $wf->isRealtime, 'Is not realtime, and never will be');
ok( $wf->isParallel, 'Is parallel');
$wf->set({'mode', 'serial'});
is(join('', $wf->isSingleton, $wf->isSerial, $wf->isParallel), '010', 'Is checks after setting mode to serial');
$wf->set({'mode', 'singleton'});
is(join('', $wf->isSingleton, $wf->isSerial, $wf->isParallel), '100', 'Is checks after setting mode to singleton');
$wf->set({'isSerial' => 1});
is(join('', $wf->isSingleton, $wf->isSerial, $wf->isParallel), '010', 'Is checks after setting mode to singleton');
$wf->set({'isSingleton' => 1});
is(join('', $wf->isSingleton, $wf->isSerial, $wf->isParallel), '100', 'Is checks after setting mode to singleton');
##Checking sticky mode settings
$wf->set({description => 'better stay singleton'});
ok($wf->isSingleton, 'After setting description, workflow is still singleton');
$wf->delete;
ok(!defined WebGUI::Workflow->new($session, $wfId), 'deleted workflow cannot be retrieved');
my $wf2 = WebGUI::Workflow->create($session, {title => 'Title', description => 'Description',
type => 'WebGUI::VersionTag'});
ok(defined $wf2, 'can create version tag workflow');
isa_ok($wf2, 'WebGUI::Workflow', 'workflow');
require WebGUI::Workflow::Activity::UnlockVersionTag;
my $activity = WebGUI::Workflow::Activity::UnlockVersionTag->create($session, $wf2->getId);
ok(defined $activity, 'can create activity');
isa_ok($activity, 'WebGUI::Workflow::Activity::UnlockVersionTag', 'activity');
isa_ok($activity, 'WebGUI::Workflow::Activity', 'activity');
my $actId = $activity->getId;
ok(defined $actId, 'activity has an ID');
is(scalar @{$wf2->getActivities}, 1, 'workflow has one activity');
is($wf2->getActivities->[0]->getId, $actId, 'Workflow has the correct activity');
TODO: {
local $TODO = "Tests that test things that do not work yet";
# Mismatched activity with workflow.
require WebGUI::Workflow::Activity::DecayKarma;
my $badActivity = WebGUI::Workflow::Activity::DecayKarma->create($session, $wf2->getId);
ok(!defined $badActivity, 'cannot create mismatched activity');
is(scalar @{$wf2->getActivities}, 1, 'workflow still has one activity');
}
my $cron = WebGUI::Workflow::Cron->create($session,
{monthOfYear => '*', dayOfMonth => '5', hourOfDay => '2',
minuteOfHour => '15', dayOfWeek => '*', enabled => 1,
runOnce => 0, priority => 2, workflowId => $wf2->getId,
title => 'Test Cron'});
ok(defined $cron, 'can create cron');
isa_ok($cron, 'WebGUI::Workflow::Cron', 'cron');
is(scalar @{$wf2->getCrons}, 1, 'workflow has one cron');
is($wf2->getCrons->[0]->getId, $cron->getId, 'one cron is same cron');
$cron->delete;
# More activity and cron tests here?
$wf2->delete;
my $wf3 = WebGUI::Workflow->create($session, {});
isa_ok($wf3, 'WebGUI::Workflow', 'workflow created with all defaults');
is($wf3->get('title'), 'Untitled', 'Default title is Untitled');
is($wf3->get('description'), undef, 'Default description is undefined');
is($wf3->get('type'), 'None', 'Default type is None');
is($wf3->get('enabled'), 0, 'By default, enabled is 0');
is($wf3->get('mode'), 'parallel', 'Default mode is parallel');
my $decayKarma = $wf3->addActivity('WebGUI::Workflow::Activity::DecayKarma');
my $cleanTemp = $wf3->addActivity('WebGUI::Workflow::Activity::CleanTempStorage');
my $oldTrash = $wf3->addActivity('WebGUI::Workflow::Activity::PurgeOldTrash');
#####################################################################
#
# getNextActivityId
#
#####################################################################
is $wf3->getNextActivityId($decayKarma->getId), $cleanTemp->getId, 'getNextActivityId: first activity to second';
is $wf3->getNextActivityId($cleanTemp->getId), $oldTrash->getId, '... second activity to third';
is $wf3->getNextActivityId($oldTrash->getId), undef, '... last returns undef';
is $wf3->getNextActivityId(), $decayKarma->getId, '... with no activityId, returns the first';
#####################################################################
#
# hasNextActivity
#
#####################################################################
ok $wf3->hasNextActivity($decayKarma->getId), 'hasNextActivityId: first activity to second';
ok $wf3->hasNextActivity($cleanTemp->getId), '... second activity to third';
ok $wf3->hasNextActivity(), '... with no activityId, returns the first';
ok !$wf3->hasNextActivity($oldTrash->getId), '... last returns undef';
#####################################################################
#
# Activity tests, promote, demote, reorder, accessing, deleting
#
#####################################################################
my $nextActivity;
$nextActivity = $wf3->getNextActivity($cleanTemp->getId);
isa_ok($nextActivity, 'WebGUI::Workflow::Activity', 'getNextActivity returns a Workflow::Activity object');
is($nextActivity->getId, $oldTrash->getId, 'getNextActivity returns the activity after the specified activity');
$nextActivity = $wf3->getNextActivity($oldTrash->getId);
is($nextActivity, undef, 'getNextActivity returns undef if there is no next activity');
my $getActivity = $wf3->getActivity($decayKarma->getId);
isa_ok($getActivity, 'WebGUI::Workflow::Activity', 'getNextActivity returns a Workflow::Activity object');
is($getActivity->getId, $decayKarma->getId, 'getActivity returns the requested activity by activityId');
cmp_deeply(
$wf3->getActivities,
[$decayKarma, $cleanTemp, $oldTrash],
'getActivities returns activties in the order they were added to the Workflow'
);
$wf3->demoteActivity($oldTrash->getId);
cmp_deeply(
[ map { $_->getId } @{ $wf3->getActivities } ],
[ map { $_->getId } $decayKarma, $cleanTemp, $oldTrash],
'demote works on first activity, even though it does not move'
);
$wf3->promoteActivity($decayKarma->getId);
cmp_deeply(
[ map { $_->getId } @{ $wf3->getActivities } ],
[ map { $_->getId } $decayKarma, $cleanTemp, $oldTrash],
'promote works on last activity, even though it does not move'
);
$wf3->demoteActivity($cleanTemp->getId);
cmp_deeply(
[ map { $_->getId } @{ $wf3->getActivities } ],
[ map { $_->getId } $decayKarma, $oldTrash, $cleanTemp],
'demote activity works'
);
$wf3->promoteActivity($oldTrash->getId);
cmp_deeply(
[ map { $_->getId } @{ $wf3->getActivities } ],
[ map { $_->getId } $oldTrash, $decayKarma, $cleanTemp],
'promote activity works'
);
my $trashClipboard = $wf3->addActivity('WebGUI::Workflow::Activity::TrashClipboard');
$wf3->deleteActivity($cleanTemp->getId);
cmp_deeply(
[ map { $_->getId } @{ $wf3->getActivities } ],
[ map { $_->getId } $oldTrash, $decayKarma, $trashClipboard],
'delete activity works'
);
$wf3->deleteActivity('neverAWebGUIId');
cmp_deeply(
[ map { $_->getId } @{ $wf3->getActivities } ],
[ map { $_->getId } $oldTrash, $decayKarma, $trashClipboard],
'delete activity requires a valid activityId to delete'
);
cmp_deeply(
[ map { $_->get('sequenceNumber') } @{ $wf3->getActivities } ],
[ 1,2,3 ],
'delete updates the sequence numbers of its activities'
);
$decayKarma->delete();
cmp_deeply(
[ map { $_->get('sequenceNumber') } @{ $wf3->getActivities } ],
[ 1,3 ],
'Manual delete of an activity does not update the sequence numbers'
);
$wf3->reorderActivities();
cmp_deeply(
[ map { $_->get('sequenceNumber') } @{ $wf3->getActivities } ],
[ 1,2 ],
'reorder activities works'
);
$wf3->delete;
# Local variables:
# mode: cperl
# End: