setting aside test for a bit to do some coding
This commit is contained in:
parent
50988eaa64
commit
3ed18c775b
7 changed files with 155 additions and 13 deletions
96
t/lib/WebGUI/Test/Activity.pm
Normal file
96
t/lib/WebGUI/Test/Activity.pm
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
package WebGUI::Test::Activity;
|
||||
|
||||
use WebGUI::Workflow;
|
||||
|
||||
=head Name
|
||||
|
||||
package WebGUI::Test::Activity;
|
||||
|
||||
=head Description
|
||||
|
||||
This package encapsulates the code required to run
|
||||
an activity.
|
||||
|
||||
=head Usage
|
||||
|
||||
use WebGUI::Test::Activity;
|
||||
|
||||
my $instance = WebGUI::Test::Activity->create( $session, 'WebGUI::Workflow::Activity::RemoveOldCarts', {
|
||||
cartTimeout => 3600,
|
||||
} );
|
||||
|
||||
is( $instance->run, 'complete', 'activity complete' );
|
||||
is( $instance->run, 'done', 'activity done' );
|
||||
$instance->rerun;
|
||||
is( $instance->run, 'complete', 'activity complete' );
|
||||
is( $instance->run, 'done', 'activity done' );
|
||||
$instance->delete;
|
||||
|
||||
=head create
|
||||
|
||||
=params
|
||||
|
||||
session -- the session variable
|
||||
|
||||
class -- the class for the activity to run
|
||||
|
||||
params -- params to set in the workflow
|
||||
|
||||
=cut
|
||||
|
||||
sub create {
|
||||
my $myClass = shift;
|
||||
my $session = shift;
|
||||
my $workflowClass = shift;
|
||||
my $activityParams;
|
||||
if( exists $_[0] and ref $_[0] eq 'HASH' ) {
|
||||
$activityParams = shift ;
|
||||
} else {
|
||||
$activityParams = { @_ };
|
||||
}
|
||||
my $workflow = WebGUI::Workflow->create($session,
|
||||
{
|
||||
enabled => 1,
|
||||
objectType => 'None',
|
||||
mode => 'realtime',
|
||||
},
|
||||
);
|
||||
my $activity = $workflow->addActivity($workflowClass);
|
||||
if( scalar( keys %$activityParams ) > 0 ) {
|
||||
$activity->set(%$activityParams);
|
||||
}
|
||||
|
||||
my $instance = WebGUI::Workflow::Instance->create($session,
|
||||
{
|
||||
workflowId => $workflow->getId,
|
||||
skipSpectreNotification => 1,
|
||||
}
|
||||
);
|
||||
return bless { instance => $instance,
|
||||
session => $session,
|
||||
workflow => $workflow }, __PACKAGE__;
|
||||
}
|
||||
|
||||
sub run {
|
||||
return $_[0]{instance}->run;
|
||||
}
|
||||
|
||||
sub rerun {
|
||||
my $self = shift;
|
||||
$self->{instance}->delete;
|
||||
$self->{instance} = WebGUI::Workflow::Instance->create($self->{session},
|
||||
{
|
||||
workflowId => $self->{workflow}->getId,
|
||||
skipSpectreNotification => 1,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
sub delete {
|
||||
my $self = shift;
|
||||
$self->{instance}->delete;
|
||||
$self->{workflow}->delete;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue