From 9f2db435ba1b4429f24250596f82f685642c3f0a Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Wed, 9 Sep 2009 01:15:59 -0500 Subject: [PATCH] prevent Workflow from trying to run an activity if it didn't get an object --- lib/WebGUI/Workflow/Instance.pm | 4 +-- t/Workflow/Instance.t | 44 ++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/lib/WebGUI/Workflow/Instance.pm b/lib/WebGUI/Workflow/Instance.pm index 27956d104..a53b99db3 100644 --- a/lib/WebGUI/Workflow/Instance.pm +++ b/lib/WebGUI/Workflow/Instance.pm @@ -395,8 +395,8 @@ sub getObject { push @params, $self->session; } push @params, $self->get("parameters"); - WebGUI::Pluggable::load($class); - return $self->{_object} = $class->$method(@params); + my $object = WebGUI::Pluggable::instanciate( $class, $method, \@params ); + return $self->{_object} = $object; } #------------------------------------------------------------------- diff --git a/t/Workflow/Instance.t b/t/Workflow/Instance.t index e84d856ba..11876dd46 100644 --- a/t/Workflow/Instance.t +++ b/t/Workflow/Instance.t @@ -17,6 +17,8 @@ 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(); @@ -46,7 +48,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -plan tests => 32; # Increment this number for each test you create +plan tests => 34; # Increment this number for each test you create #---------------------------------------------------------------------------- # put your tests here @@ -181,6 +183,46 @@ my $wf2 = WebGUI::Workflow->create( 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'; +} + #---------------------------------------------------------------------------- # Cleanup END {