From a69dff3dcf34c51d2b3d6af351ee10372bed73a3 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sun, 2 Mar 2008 22:50:46 +0000 Subject: [PATCH] Adding Knowmad's excellent Instance test script for exposing JSON problems in Workflow::Instance --- t/Workflow/Instance.t | 76 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 t/Workflow/Instance.t diff --git a/t/Workflow/Instance.t b/t/Workflow/Instance.t new file mode 100644 index 000000000..3f7bb8e13 --- /dev/null +++ b/t/Workflow/Instance.t @@ -0,0 +1,76 @@ +# vim:syntax=perl +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2007 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 WebGUI::Test; # Must use this before any other WebGUI modules +use WebGUI::Session; +use WebGUI::Workflow; +use WebGUI::Workflow::Instance; +use JSON; +use Data::Dumper; + +#---------------------------------------------------------------------------- +# Init +my $session = WebGUI::Test->session; + + +#---------------------------------------------------------------------------- +# Tests + +plan tests => 6; # Increment this number for each test you create + +#---------------------------------------------------------------------------- +# put your tests here + +# create a workflow +my $wf = WebGUI::Workflow->create( + $session, + { + title => 'WebGUI::Workflow::Instance Test', + 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(defined WebGUI::Workflow->new($session, $wfId), 'workflow can be retrieved'); + +# create an instance of $wfId +my $properties = { + #workflowId=>$session->setting->get("runOnAdminCreateUser"), + workflowId=>$wfId, + methodName=>"new", + className=>"None", + parameters=>'encode me', + priority=>1 +}; +my $instance = WebGUI::Workflow::Instance->create($session, $properties); +isa_ok($instance, 'WebGUI::Workflow::Instance', 'workflow instance'); + +# test JSON encoding +my $encoded_text = JSON->new->pretty->encode({parameters => $properties->{parameters}}); +ok($encoded_text, 'received encoded text from JSON'); + + +#---------------------------------------------------------------------------- +# Cleanup +END { + $wf->delete; +}