From 9ab36a72ee46055976171bbde5ca8c0af3499327 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Mon, 21 Feb 2011 20:17:03 -0600 Subject: [PATCH] migrate Activity getEditForm to FormBuilder --- lib/WebGUI/Operation/Workflow.pm | 9 ++-- lib/WebGUI/Workflow/Activity.pm | 17 +++--- t/Operation/Workflow.t | 92 ++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 t/Operation/Workflow.t diff --git a/lib/WebGUI/Operation/Workflow.pm b/lib/WebGUI/Operation/Workflow.pm index 86ee36e7e..f68c73e11 100644 --- a/lib/WebGUI/Operation/Workflow.pm +++ b/lib/WebGUI/Operation/Workflow.pm @@ -385,14 +385,15 @@ sub www_editWorkflowActivity { $activity = WebGUI::Workflow::Activity->new($session, $session->form->get("activityId")); } my $form = $activity->getEditForm; - $form->hidden( name=>"op", value=>"editWorkflowActivitySave"); - $form->hidden( name=>"workflowId", value=>$session->form->get("workflowId")); - $form->submit; + $form->action( $session->url->page ); + $form->addField( "hidden", name=>"op", value=>"editWorkflowActivitySave"); + $form->addField( "hidden", name=>"workflowId", value=> scalar $session->form->get("workflowId")); + $form->addField( "submit", name => "submit" ); my $i18n = WebGUI::International->new($session, "Workflow"); my $ac = WebGUI::AdminConsole->new($session,"workflow"); $ac->addSubmenuItem($session->url->page("op=addWorkflow"), $i18n->get("add a new workflow")); $ac->addSubmenuItem($session->url->page("op=manageWorkflows"), $i18n->get("manage workflows")); - return $ac->render($form->print,$activity->getName); + return $ac->render($form->toHtml,$activity->getName); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Workflow/Activity.pm b/lib/WebGUI/Workflow/Activity.pm index 606dc928f..ae85a83e2 100644 --- a/lib/WebGUI/Workflow/Activity.pm +++ b/lib/WebGUI/Workflow/Activity.pm @@ -16,7 +16,7 @@ package WebGUI::Workflow::Activity; =cut use strict; -use WebGUI::HTMLForm; +use WebGUI::FormBuilder; use WebGUI::Pluggable; =head1 NAME @@ -235,12 +235,17 @@ Returns the form that will be used to edit the properties of an activity. sub getEditForm { my $self = shift; - my $form = WebGUI::HTMLForm->new($self->session); - $form->submit; - $form->hidden(name=>"activityId", value=>$self->getId); - $form->hidden(name=>"className", value=>$self->get("className")); + my $form = WebGUI::FormBuilder->new($self->session); + $form->addField( "submit", name => "submit" ); + $form->addField( "hidden", name=>"activityId", value=>$self->getId); + $form->addField( "hidden", name=>"className", value=>$self->get("className")); my $fullDefinition = $self->definition($self->session); - $form->dynamicForm($fullDefinition, "properties", $self); + for my $hash ( map { $_->{properties} } @{$fullDefinition} ) { + for my $fieldName ( keys %$hash ) { + my $field = $hash->{ $fieldName }; + $form->addField( delete $field->{fieldType}, name => $fieldName, %$field ); + } + } return $form; } diff --git a/t/Operation/Workflow.t b/t/Operation/Workflow.t new file mode 100644 index 000000000..d17c523c9 --- /dev/null +++ b/t/Operation/Workflow.t @@ -0,0 +1,92 @@ +# 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 +#------------------------------------------------------------------ + +# Test the forms for Workflow editing +# +# + +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::Test::Mechanize; + +#---------------------------------------------------------------------------- +# Init +my $session = WebGUI::Test->session; + +#---------------------------------------------------------------------------- +# Tests + +plan tests => 14; # Increment this number for each test you create + +#---------------------------------------------------------------------------- +# Add a workflow +my $mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file ); +$mech->get_ok( '/' ); +$mech->session->user({ userId => 3 }); + +$mech->get_ok( '?op=addWorkflow' ); +$mech->submit_form_ok({ + fields => { + type => "None", + }, + }, + "Add a new workflow" +); + +my $workflowId = $mech->value( 'workflowId' ); +ok( $workflowId, "workflow id in edit form" ); +ok( my $workflow = WebGUI::Workflow->new( $mech->session, $workflowId ), "can be instanced" ); +WebGUI::Test::addToCleanup( $workflow ); +is( $workflow->get('type'), "None", "type set correctly" ); + +my %workflowFields = ( + title => 'New Test Workflow', + description => 'Descriptive', +); +$mech->submit_form_ok({ + fields => \%workflowFields, + }, + "Update the new workflow's name and settings", +); + +$workflow = WebGUI::Workflow->new( $mech->session, $workflowId ); +is( $workflow->get('title'), $workflowFields{title}, "title set correctly" ); +is( $workflow->get('description'), $workflowFields{description}, "description set correctly" ); + +# Add an activity +$mech->follow_link_ok( + { + url_regex => qr/WebGUI::Workflow::Activity::DeleteExpiredSessions/, + }, + "Add a DeleteExpiredSessions activity", +); + +my %activityFields = ( + title => 'New Workflow Activity', + description => 'As if you needed one.', +); +$mech->submit_form_ok({ + fields => \%activityFields, + }, + "Edit the activity properties", +); + +my $activities = $workflow->getActivities; +is( @$activities, 1, 'workflow has one activity' ); +is( $activities->[0]->get('title'), $activityFields{title}, "activity title set" ); +is( $activities->[0]->get('description'), $activityFields{description}, "activity description set" ); + + +#vim:ft=perl