Index: openacs-4/contrib/packages/simulation/tcl/template-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/template-procs.tcl,v
diff -u -r1.36 -r1.37
--- openacs-4/contrib/packages/simulation/tcl/template-procs.tcl	8 Jan 2004 13:03:32 -0000	1.36
+++ openacs-4/contrib/packages/simulation/tcl/template-procs.tcl	8 Jan 2004 15:54:01 -0000	1.37
@@ -766,7 +766,7 @@
     # Special for simulation template:
     # If there is no initial-action, we create one now
     
-    set initial_action_id [workflow::get -workflow_id $workflow_id -element initial_action_id]
+    set initial_action_id [workflow::get_element -workflow_id $workflow_id -element initial_action_id]
     if { [empty_string_p $initial_action_id] } {
 
         set action_row(pretty_name) "Start"
Index: openacs-4/contrib/packages/simulation/test/demo-data-setup.test
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/test/Attic/demo-data-setup.test,v
diff -u -r1.17 -r1.18
--- openacs-4/contrib/packages/simulation/test/demo-data-setup.test	8 Jan 2004 11:27:38 -0000	1.17
+++ openacs-4/contrib/packages/simulation/test/demo-data-setup.test	8 Jan 2004 15:54:01 -0000	1.18
@@ -10,19 +10,12 @@
 
     ::twt::simulation::setup::citybuild_objects
 
-    ::twt::simulation::setup::elementary_private_law_template   
-    ::twt::simulation::setup::legislative_drafting_template
-    ::twt::simulation::setup::tilburg_template_from_spec    
-    # TODO: click the ready_p link for the templates
+    ::twt::simulation::setup::all_templates   
 
-    ::twt::simulation::test::permissions_anonymous
-    ::twt::simulation::test::permissions_city_admin
-    ::twt::simulation::test::permissions_sim_admin
-    ::twt::simulation::test::permissions_template_author
-    ::twt::simulation::test::permissions_case_author
-    ::twt::simulation::test::permissions_service_admin
-    ::twt::simulation::test::permissions_actor
+    ::twt::simulation::play::tilburg_template_user_1
 
+    ::twt::simulation::test::permissions_all
+
 } result] } {
     global errorInfo
 
Index: openacs-4/contrib/packages/simulation/test/simulation-test-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/test/Attic/simulation-test-procs.tcl,v
diff -u -r1.7 -r1.8
--- openacs-4/contrib/packages/simulation/test/simulation-test-procs.tcl	8 Jan 2004 11:27:38 -0000	1.7
+++ openacs-4/contrib/packages/simulation/test/simulation-test-procs.tcl	8 Jan 2004 15:54:01 -0000	1.8
@@ -6,6 +6,7 @@
 namespace eval ::twt::simulation {}
 namespace eval ::twt::simulation::setup {}
 namespace eval ::twt::simulation::test {}
+namespace eval ::twt::simulation::play {}
 
 ##############################
 #
@@ -102,6 +103,14 @@
     }
 }
 
+ad_proc ::twt::simulation::setup::all_templates {} {
+
+    ::twt::simulation::setup::elementary_private_law_template   
+    ::twt::simulation::setup::legislative_drafting_template
+    ::twt::simulation::setup::tilburg_template_from_spec    
+    # TODO: click the ready_p link for the templates
+}
+
 ad_proc ::twt::simulation::setup::elementary_private_law_template {} {
 
     # Do this as the template author to make sure he has sufficient permissions
@@ -152,9 +161,75 @@
 
     ::twt::log_section "Create a template from a spec"
     do_request /simulation/simbuild/template-load
-    field fill "Template loaded from spec" ~n pretty_name
+    set template_name "Template loaded from spec"
+    field fill $template_name ~n pretty_name
     field fill [::twt::simulation::data::tilburg_template_spec] ~n spec
     form submit
+
+    do_request /simulation/simbuild
+    link follow ~c $template_name
+    link follow ~u template-sim-type-update
+
+    ::twt::log_section "Login case author"
+    ::twt::user::login [::twt::simulation::permission_user_email "Case Authors"]
+    
+    ::twt::log_section "Instantiate the Tilburg template"
+    do_request /simulation/siminst/simulation-new
+    link follow ~u map-create
+    
+    form find ~n template
+    # Make name unique
+    set unique_name "New Simulation from Template loaded from spec [expr rand()]"
+    field fill $unique_name ~n pretty_name
+    form submit
+
+    # Wizard page 1
+    form find ~n characters
+    form submit
+
+    regexp {workflow_id=([0-9]+)} [response url] match workflow_id
+
+    # Wizard page 2
+    form find ~n tasks
+    form submit ~n next
+
+    # Wizard page 3
+    form find ~n simulation
+    form submit ~n next
+
+    # Enrollment (page 4)
+    form find ~n simulation
+    form submit ~n next
+
+    # Participants (page 5)
+    form find ~n simulation
+    field find ~n __auto_enroll ~t checkbox
+    field check
+    field find ~n __auto_enroll ~t checkbox
+    field check
+    field find ~n __auto_enroll ~t checkbox
+    field check
+    field find ~n __auto_enroll ~t checkbox
+    field check
+    form submit ~n next
+
+    # Wizard page 6
+    form find ~n actors
+    field find ~n parties_ ~t checkbox
+    field check
+    field find ~n parties_ ~t checkbox
+    field check
+    field find ~n parties_ ~t checkbox
+    field check
+    field find ~n parties_ ~t checkbox
+    field check
+    field find ~n parties_ ~t checkbox
+    field check
+    field find ~n parties_ ~t checkbox
+    field check
+    form submit ~n finish
+
+    do_request /simulation/siminst/simulation-start?workflow_id=$workflow_id
 }
 
 ##############################
@@ -163,6 +238,17 @@
 #
 ##############################
 
+ad_proc ::twt::simulation::test::permissions_all {} {
+
+    ::twt::simulation::test::permissions_anonymous
+    ::twt::simulation::test::permissions_city_admin
+    ::twt::simulation::test::permissions_sim_admin
+    ::twt::simulation::test::permissions_template_author
+    ::twt::simulation::test::permissions_case_author
+    ::twt::simulation::test::permissions_service_admin
+    ::twt::simulation::test::permissions_actor
+}
+
 ad_proc ::twt::simulation::test::permissions_anonymous {} {
 
     ::twt::log_section "Permission testing with anonymous user"
@@ -290,6 +376,62 @@
 
 ##############################
 #
+# ::twt::simulation::play
+#
+##############################
+
+ad_proc ::twt::simulation::play::tilburg_template_user_1 {} {
+    set user_name "Demo User 1"
+    ::twt::log_section "Login with $user_name and play tilburg simulation"
+
+    ::twt::user::login [::twt::simulation::email_from_user_name $user_name]
+
+    do_request /simulation/simplay
+    link follow ~u "case.+case"
+
+    # Execute the ask client task
+    link follow ~u task-detail
+    form find ~n action
+    field fill "ask client subject" ~n subject
+    field fill "ask client body" ~n body
+    form submit
+
+    # Execute the finalizing task
+    link follow ~c "Write legal advice"
+    form find ~n action
+    field fill "legal advice subject" ~n subject
+    field fill "legal advice body" ~n body
+    form submit
+
+    # Legal advice was the last task so there shouldn't be any left
+    if { [regexp {task-detail\?} [response body]] } {
+        error "Completed last task ask legal advice but there are still tasks remaining"
+    }
+
+    # Visit case index page again
+    do_request /simulation/simplay
+    link follow ~u "case.+case"    
+
+    # Send a message
+    link follow ~u "message\\?"
+    form find ~n message
+    field find ~n recipient_role_id ~t checkbox
+    field check
+    field fill "message subject" ~n subject
+    field fill "message body" ~n body
+    form submit
+
+    # Upload a document
+    link follow ~u document-upload
+    form find ~n document
+    field find ~n document_file
+    field fill [::twt::config::serverroot]/packages/simulation/test/new-jersey-lawyer-logo.gif    
+    field fill "New Jersey Lawyers Logo" ~n title
+    form submit
+}
+
+##############################
+#
 # ::twt::simulation helper procs
 #
 ##############################
Index: openacs-4/contrib/packages/simulation/www/siminst/simulation-delete.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/siminst/Attic/simulation-delete.adp,v
diff -u -r1.2 -r1.3
--- openacs-4/contrib/packages/simulation/www/siminst/simulation-delete.adp	11 Dec 2003 13:21:53 -0000	1.2
+++ openacs-4/contrib/packages/simulation/www/siminst/simulation-delete.adp	8 Jan 2004 15:54:01 -0000	1.3
@@ -2,4 +2,4 @@
   <property name="title">@page_title;noquote@</property>
   <property name="context">@context;noquote@</property>
 
-<p>Confirmation page for cascading delete of simulation and all cases</p>
\ No newline at end of file
+<p>Confirmation page for cascading delete of simulation and all cases</p>
Index: openacs-4/contrib/packages/simulation/www/siminst/wizard.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/siminst/Attic/wizard.tcl,v
diff -u -r1.7 -r1.8
--- openacs-4/contrib/packages/simulation/www/siminst/wizard.tcl	7 Jan 2004 16:27:35 -0000	1.7
+++ openacs-4/contrib/packages/simulation/www/siminst/wizard.tcl	8 Jan 2004 15:54:01 -0000	1.8
@@ -69,12 +69,14 @@
 if { $highest_available > 6 } {
     set highest_available 6
 }
+
+wizard get_current_step -start $highest_available
+
 if { $highest_available < 5 } {
     set highest_available 5
 }
 
 
-wizard get_current_step -start $highest_available
 
 set sub_title $title(${wizard:current_id})
 
Index: openacs-4/contrib/packages/simulation/www/simplay/message.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simplay/Attic/message.tcl,v
diff -u -r1.14 -r1.15
--- openacs-4/contrib/packages/simulation/www/simplay/message.tcl	7 Jan 2004 16:00:37 -0000	1.14
+++ openacs-4/contrib/packages/simulation/www/simplay/message.tcl	8 Jan 2004 15:54:01 -0000	1.15
@@ -20,6 +20,7 @@
 foreach role_id [workflow::case::get_user_roles -case_id $case_id] {
     lappend from_role_options [list [workflow::role::get_element -role_id $role_id -element pretty_name] $role_id]
 }
+
 # First sender role selected by default
 if { ![exists_and_not_null sender_role_id] } {
     set sender_role_id [lindex [lindex $from_role_options 0] 1]
Index: openacs-4/packages/simulation/tcl/template-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/template-procs.tcl,v
diff -u -r1.36 -r1.37
--- openacs-4/packages/simulation/tcl/template-procs.tcl	8 Jan 2004 13:03:32 -0000	1.36
+++ openacs-4/packages/simulation/tcl/template-procs.tcl	8 Jan 2004 15:54:01 -0000	1.37
@@ -766,7 +766,7 @@
     # Special for simulation template:
     # If there is no initial-action, we create one now
     
-    set initial_action_id [workflow::get -workflow_id $workflow_id -element initial_action_id]
+    set initial_action_id [workflow::get_element -workflow_id $workflow_id -element initial_action_id]
     if { [empty_string_p $initial_action_id] } {
 
         set action_row(pretty_name) "Start"
Index: openacs-4/packages/simulation/test/demo-data-setup.test
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/test/demo-data-setup.test,v
diff -u -r1.17 -r1.18
--- openacs-4/packages/simulation/test/demo-data-setup.test	8 Jan 2004 11:27:38 -0000	1.17
+++ openacs-4/packages/simulation/test/demo-data-setup.test	8 Jan 2004 15:54:01 -0000	1.18
@@ -10,19 +10,12 @@
 
     ::twt::simulation::setup::citybuild_objects
 
-    ::twt::simulation::setup::elementary_private_law_template   
-    ::twt::simulation::setup::legislative_drafting_template
-    ::twt::simulation::setup::tilburg_template_from_spec    
-    # TODO: click the ready_p link for the templates
+    ::twt::simulation::setup::all_templates   
 
-    ::twt::simulation::test::permissions_anonymous
-    ::twt::simulation::test::permissions_city_admin
-    ::twt::simulation::test::permissions_sim_admin
-    ::twt::simulation::test::permissions_template_author
-    ::twt::simulation::test::permissions_case_author
-    ::twt::simulation::test::permissions_service_admin
-    ::twt::simulation::test::permissions_actor
+    ::twt::simulation::play::tilburg_template_user_1
 
+    ::twt::simulation::test::permissions_all
+
 } result] } {
     global errorInfo
 
Index: openacs-4/packages/simulation/test/simulation-test-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/test/simulation-test-procs.tcl,v
diff -u -r1.7 -r1.8
--- openacs-4/packages/simulation/test/simulation-test-procs.tcl	8 Jan 2004 11:27:38 -0000	1.7
+++ openacs-4/packages/simulation/test/simulation-test-procs.tcl	8 Jan 2004 15:54:01 -0000	1.8
@@ -6,6 +6,7 @@
 namespace eval ::twt::simulation {}
 namespace eval ::twt::simulation::setup {}
 namespace eval ::twt::simulation::test {}
+namespace eval ::twt::simulation::play {}
 
 ##############################
 #
@@ -102,6 +103,14 @@
     }
 }
 
+ad_proc ::twt::simulation::setup::all_templates {} {
+
+    ::twt::simulation::setup::elementary_private_law_template   
+    ::twt::simulation::setup::legislative_drafting_template
+    ::twt::simulation::setup::tilburg_template_from_spec    
+    # TODO: click the ready_p link for the templates
+}
+
 ad_proc ::twt::simulation::setup::elementary_private_law_template {} {
 
     # Do this as the template author to make sure he has sufficient permissions
@@ -152,9 +161,75 @@
 
     ::twt::log_section "Create a template from a spec"
     do_request /simulation/simbuild/template-load
-    field fill "Template loaded from spec" ~n pretty_name
+    set template_name "Template loaded from spec"
+    field fill $template_name ~n pretty_name
     field fill [::twt::simulation::data::tilburg_template_spec] ~n spec
     form submit
+
+    do_request /simulation/simbuild
+    link follow ~c $template_name
+    link follow ~u template-sim-type-update
+
+    ::twt::log_section "Login case author"
+    ::twt::user::login [::twt::simulation::permission_user_email "Case Authors"]
+    
+    ::twt::log_section "Instantiate the Tilburg template"
+    do_request /simulation/siminst/simulation-new
+    link follow ~u map-create
+    
+    form find ~n template
+    # Make name unique
+    set unique_name "New Simulation from Template loaded from spec [expr rand()]"
+    field fill $unique_name ~n pretty_name
+    form submit
+
+    # Wizard page 1
+    form find ~n characters
+    form submit
+
+    regexp {workflow_id=([0-9]+)} [response url] match workflow_id
+
+    # Wizard page 2
+    form find ~n tasks
+    form submit ~n next
+
+    # Wizard page 3
+    form find ~n simulation
+    form submit ~n next
+
+    # Enrollment (page 4)
+    form find ~n simulation
+    form submit ~n next
+
+    # Participants (page 5)
+    form find ~n simulation
+    field find ~n __auto_enroll ~t checkbox
+    field check
+    field find ~n __auto_enroll ~t checkbox
+    field check
+    field find ~n __auto_enroll ~t checkbox
+    field check
+    field find ~n __auto_enroll ~t checkbox
+    field check
+    form submit ~n next
+
+    # Wizard page 6
+    form find ~n actors
+    field find ~n parties_ ~t checkbox
+    field check
+    field find ~n parties_ ~t checkbox
+    field check
+    field find ~n parties_ ~t checkbox
+    field check
+    field find ~n parties_ ~t checkbox
+    field check
+    field find ~n parties_ ~t checkbox
+    field check
+    field find ~n parties_ ~t checkbox
+    field check
+    form submit ~n finish
+
+    do_request /simulation/siminst/simulation-start?workflow_id=$workflow_id
 }
 
 ##############################
@@ -163,6 +238,17 @@
 #
 ##############################
 
+ad_proc ::twt::simulation::test::permissions_all {} {
+
+    ::twt::simulation::test::permissions_anonymous
+    ::twt::simulation::test::permissions_city_admin
+    ::twt::simulation::test::permissions_sim_admin
+    ::twt::simulation::test::permissions_template_author
+    ::twt::simulation::test::permissions_case_author
+    ::twt::simulation::test::permissions_service_admin
+    ::twt::simulation::test::permissions_actor
+}
+
 ad_proc ::twt::simulation::test::permissions_anonymous {} {
 
     ::twt::log_section "Permission testing with anonymous user"
@@ -290,6 +376,62 @@
 
 ##############################
 #
+# ::twt::simulation::play
+#
+##############################
+
+ad_proc ::twt::simulation::play::tilburg_template_user_1 {} {
+    set user_name "Demo User 1"
+    ::twt::log_section "Login with $user_name and play tilburg simulation"
+
+    ::twt::user::login [::twt::simulation::email_from_user_name $user_name]
+
+    do_request /simulation/simplay
+    link follow ~u "case.+case"
+
+    # Execute the ask client task
+    link follow ~u task-detail
+    form find ~n action
+    field fill "ask client subject" ~n subject
+    field fill "ask client body" ~n body
+    form submit
+
+    # Execute the finalizing task
+    link follow ~c "Write legal advice"
+    form find ~n action
+    field fill "legal advice subject" ~n subject
+    field fill "legal advice body" ~n body
+    form submit
+
+    # Legal advice was the last task so there shouldn't be any left
+    if { [regexp {task-detail\?} [response body]] } {
+        error "Completed last task ask legal advice but there are still tasks remaining"
+    }
+
+    # Visit case index page again
+    do_request /simulation/simplay
+    link follow ~u "case.+case"    
+
+    # Send a message
+    link follow ~u "message\\?"
+    form find ~n message
+    field find ~n recipient_role_id ~t checkbox
+    field check
+    field fill "message subject" ~n subject
+    field fill "message body" ~n body
+    form submit
+
+    # Upload a document
+    link follow ~u document-upload
+    form find ~n document
+    field find ~n document_file
+    field fill [::twt::config::serverroot]/packages/simulation/test/new-jersey-lawyer-logo.gif    
+    field fill "New Jersey Lawyers Logo" ~n title
+    form submit
+}
+
+##############################
+#
 # ::twt::simulation helper procs
 #
 ##############################
Index: openacs-4/packages/simulation/www/siminst/simulation-delete.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/siminst/simulation-delete.adp,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/simulation/www/siminst/simulation-delete.adp	11 Dec 2003 13:21:53 -0000	1.2
+++ openacs-4/packages/simulation/www/siminst/simulation-delete.adp	8 Jan 2004 15:54:01 -0000	1.3
@@ -2,4 +2,4 @@
   <property name="title">@page_title;noquote@</property>
   <property name="context">@context;noquote@</property>
 
-<p>Confirmation page for cascading delete of simulation and all cases</p>
\ No newline at end of file
+<p>Confirmation page for cascading delete of simulation and all cases</p>
Index: openacs-4/packages/simulation/www/siminst/wizard.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/siminst/wizard.tcl,v
diff -u -r1.7 -r1.8
--- openacs-4/packages/simulation/www/siminst/wizard.tcl	7 Jan 2004 16:27:35 -0000	1.7
+++ openacs-4/packages/simulation/www/siminst/wizard.tcl	8 Jan 2004 15:54:01 -0000	1.8
@@ -69,12 +69,14 @@
 if { $highest_available > 6 } {
     set highest_available 6
 }
+
+wizard get_current_step -start $highest_available
+
 if { $highest_available < 5 } {
     set highest_available 5
 }
 
 
-wizard get_current_step -start $highest_available
 
 set sub_title $title(${wizard:current_id})
 
Index: openacs-4/packages/simulation/www/simplay/message.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simplay/message.tcl,v
diff -u -r1.14 -r1.15
--- openacs-4/packages/simulation/www/simplay/message.tcl	7 Jan 2004 16:00:37 -0000	1.14
+++ openacs-4/packages/simulation/www/simplay/message.tcl	8 Jan 2004 15:54:01 -0000	1.15
@@ -20,6 +20,7 @@
 foreach role_id [workflow::case::get_user_roles -case_id $case_id] {
     lappend from_role_options [list [workflow::role::get_element -role_id $role_id -element pretty_name] $role_id]
 }
+
 # First sender role selected by default
 if { ![exists_and_not_null sender_role_id] } {
     set sender_role_id [lindex [lindex $from_role_options 0] 1]