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.16 -r1.17
--- openacs-4/contrib/packages/simulation/test/demo-data-setup.test	7 Jan 2004 16:16:06 -0000	1.16
+++ openacs-4/contrib/packages/simulation/test/demo-data-setup.test	8 Jan 2004 11:27:38 -0000	1.17
@@ -1,287 +1,28 @@
 if { [catch {
+
     # Source Tcl libraries
     set script_dir [file dirname [info script]]
     source "${script_dir}/../../../etc/install/tcl/test-procs.tcl"
     source "${script_dir}/simulation-test-procs.tcl"
+    source "${script_dir}/demo-data.tcl"
 
-    # Test Execution START
+    ::twt::simulation::setup::users_and_groups
 
-    global __demo_users_password
-    set __demo_users_password 1
+    ::twt::simulation::setup::citybuild_objects
 
-    source demo-data.tcl
-
-    ::twt::log_section "Login the site wide admin"
-    ::twt::user::login_site_wide_admin
-
-    ###################################
-    #
-    # Users and Groups setup
-    #
-    ###################################
-
-    ::twt::log_section "Add demo users to system"
-    for {set i 1} {$i <= 20} {incr i} {
-        ::twt::simulation::add_user -first_names Demo -last_name "User $i"
-    }    
-
-    ::twt::log_section "Add demo groups"
-    for {set i 1} {$i <= 5} {incr i} {
-        do_request "/admin/group-types/one?group_type=group"
-        link follow ~u "parties/new"
-
-        field find ~n group.group_name
-        field fill "Demo group $i"
-        form submit
-    }
-    
-    ::twt::log_section "Add demo users to groups"
-    for {set i 1} {$i <= 5} {incr i} {
-        
-        set add_user_url [::twt::simulation::add_user_to_group_url -group_name "Demo group $i"]
-
-        for {set user_count [expr ($i - 1)*4 + 1]} {$user_count <= [expr $i*4]} {incr user_count} {
-            ::twt::simulation::add_user_to_group -add_user_url $add_user_url -user_name "Demo User $user_count"
-        }
-    }
-
-    ::twt::log_section "Create a demo user in each permission group"
-    foreach group_name {
-        "Sim Admins"
-        "Template Authors"
-        "Case Authors"
-        "Service Admins"
-        "City Admins"
-        "Actors"
-    } {
-        set first_names [::twt::simulation::permission_user_first_names $group_name]
-        set last_name [::twt::simulation::permission_user_last_name $group_name]
-        ::twt::simulation::add_user -first_names $first_names -last_name $last_name
-
-        ::twt::simulation::add_user_to_group -group_name $group_name -user_name "$first_names $last_name"
-    }
-
-    ###################################
-    #
-    # Citybuild object setup
-    #
-    ###################################
-
-    # Do this as the city build user to make sure he has sufficient permissions
-    ::twt::user::login [::twt::simulation::permission_user_email "City Admins"]
-
-    ::twt::log_section "Create an image object"
-    do_request /simulation/citybuild
-    link follow ~u object-edit
-    form find ~n object
-    field find ~n content_type
-    field select2 ~v image
-    field find ~n __refreshing_p
-    field fill 1
-    form submit    
-    field find ~n title
-    field fill "New Jersey Lawyers"
-    field find ~n description
-    field fill "New Jersey Lawyers and Consumers"
-    field find ~n content_file
-    field fill [::twt::config::serverroot]/packages/simulation/test/new-jersey-lawyer-logo.gif
-    form submit
-
-    ::twt::log_section "Create characters for Elementary private law"
-    foreach character_name [array names characters] {
-        ::twt::simulation::add_object -type character -title $character_name
-    }
-
-    ::twt::log_section "Create characters for Legislative Drafting"
-    foreach character_name [array names characters_ld] {
-        ::twt::simulation::add_object -type character -title $character_name
-    }
-
-    ::twt::log_section "Create properties"
-    foreach property_name [array names properties] {
-        ::twt::simulation::add_object -type sim_prop -title $property_name
-    }
-
-    ###################################
-    #
-    # Elementary private law template
-    #
-    ###################################
-
-    # TODO: do this is as "Template Authors" test user
-    ::twt::user::login_site_wide_admin
-
-    set template_name "Elementary Private Law"
-    ::twt::log_section "Create $template_name simulation template"
-    ::twt::simulation::add_template -template_name $template_name
-
-    ::twt::log_section "Create roles for template"
-    ::twt::simulation::add_roles_to_template \
-        -template_name $template_name \
-        -character_array characters
-
-    ::twt::log_section "Add tasks to template"
-    ::twt::simulation::add_tasks_to_template \
-        -template_name $template_name \
-        -task_array tasks
-
-    ###################################
-    #
-    # Legislative Drafting template
-    #
-    ###################################
-
-    set template_name "Legislative Drafting"
-    ::twt::log_section "Create $template_name simulation template"
-    ::twt::simulation::add_template -template_name $template_name
-
-    ::twt::log_section "Create roles for template"
-    ::twt::simulation::add_roles_to_template \
-        -template_name $template_name \
-        -character_array characters_ld
-
-    ::twt::log_section "Add tasks to template"
-    ::twt::simulation::add_tasks_to_template \
-        -template_name $template_name \
-        -task_array tasks_ld
-
-    ###################################
-    #
-    # Tilburg template created from spec
-    #
-    ###################################
-
-    ::twt::log_section "Create a template from a spec"
-    do_request /simulation/simbuild/template-load
-    field fill "Template loaded from spec" ~n pretty_name
-    field fill [::twt::simulation::get_template_spec] ~n spec
-    form submit
-    
+    ::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
 
-    ###################################
-    #
-    # Permission testing with anonymous user
-    #
-    ###################################
+    ::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::log_section "Permission testing with anonymouse user"
-    ::twt::user::logout
-
-    # The anonymous user can access the index page with the flash map
-    ::twt::simulation::assert_page_accessible /simulation
-
-    # TODO: Should see a list of all simulation open for enrollment
-
-    # The anonymous user can access an object view page
-    ::twt::simulation::assert_page_accessible /simulation/object/motorhome
-
-    # The anonymous user can not access any of the four modules
-    foreach disallowed_url {simplay siminst simbuild citybuild} {
-        do_request /simulation/$disallowed_url
-        if { ![regexp {/register/} $::tclwebtest::url] } {
-            error "Anonymous user was not redirected to login page for url $disallowed_url"
-        }
-    }
-
-    ###################################
-    #
-    # Permission testing with city admin
-    #
-    ###################################
-
-    set group_name "City Admins"
-
-    # login user
-    ::twt::user::login [::twt::simulation::permission_user_email $group_name]
-
-    # city admin can access index page
-    ::twt::simulation::assert_page_accessible /simulation
-
-    # can access citybuild
-    ::twt::simulation::assert_page_accessible /simulation/citybuild
-
-    # can create object
-    set object_title "Test property"
-    ::twt::simulation::add_object -type sim_prop -title $object_title
-
-    # can edit on_map_p attribute of object
-    do_request /simulation/citybuild
-    link follow ~c $object_title
-    link follow ~u object-edit
-    regexp {item%5fid=([0-9]+)} [response url] match item_id
-    form find ~n object
-    field find ~n attr__sim_prop__on_map_p
-    field select2 ~v t
-    form submit
-    if { [regexp "Permission Denied" [response body]] } {
-        error "City admin should not get permission denied when editing on_map_p of an object"
-    }
-
-    # can delete object    
-    do_request "/simulation/citybuild/object-delete?confirm_p=1&item_id=$item_id"
-    if { [regexp "Permission Denied" [response body]] } {
-        error "City admin should not get permission denied when deleting an object"
-    }
-
-    # can not build or instantiate templates
-    foreach module {simbuild siminst} {
-        ::twt::simulation::assert_page_not_accessible /simulation/$module
-    }
-
-    ###################################
-    #
-    # Permission testing with sim admin (simulation super user)
-    #
-    ###################################
-
-    # can do anything within the package
-    # including the on_map_p attribute
-
-    ###################################
-    #
-    # Permission testing with template author
-    #
-    ###################################
-
-    # read/create templates, only own templates
-    # cannot edit other people's templates
-    
-    # can access all modules, can do anything in siminst
-
-    # cannot see case logs
-
-    ###################################
-    #
-    # Permission testing with case author
-    #
-    ###################################
-
-    # cannot access modules: simbuild
-
-    # can see case logs
-
-    # cannot set on_map_p attribute
-
-    ###################################
-    #
-    # Permission testing with service admin
-    #
-    ###################################
-
-    # can add users
-    # can make users eligible for enrollment
-
-    ###################################
-    #
-    # Permission testing Actor (playing in a sim)
-    #
-    ###################################
-    
-    # participate in the simulation in simplay
-
-    # cannot access citybuild, simbuild, siminst
-
 } result] } {
     global errorInfo
 
Index: openacs-4/contrib/packages/simulation/test/demo-data.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/test/Attic/demo-data.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/contrib/packages/simulation/test/demo-data.tcl	7 Jan 2004 16:16:06 -0000	1.1
+++ openacs-4/contrib/packages/simulation/test/demo-data.tcl	8 Jan 2004 11:27:38 -0000	1.2
@@ -1,33 +1,48 @@
-set actors_list {
-    Teacher
-    Student
-    Agent1
-    Agent2
+# Procs returning demo data.
+#
+# Procs to support the Tclwebtest (HTTP level) testing and demo data setup
+# of the simulation package.
+#
+# @author Peter Marklund
+
+namespace eval ::twt::simulation {}
+namespace eval ::twt::simulation::data {}
+
+ad_proc ::twt::simulation::data::actors {} {
+    return {
+        Teacher
+        Student
+        Agent1
+        Agent2
+    }
 }
 
-array set characters {
-    Bernadette         "Bernadette"
-    MOTORHOME          "MOTORHOME"
-    "A of Lawfirm X"   "Her lawyer"
-    "A of Lawfirm Y"   "Its lawyer"
-    "B of Lawfirm X"   "Partner firm X"
-    "B of Lawfirm Y"   "Partner firm Y"
-    "C of Lawfirm X"   "Secretary firm X"
-    "C of Lawfirm Y"   "Secretary firm Y"
-    "Portal"           "Library"          
-    "Lok of Legisl. Dept."		"Member 1 of Legisl. Dept."
-    "Peter of Legisl. Dept."	"Member 2 of Legisl. Dept."
-    "Aernout of Legisl. Dept."	"Head of Legisl. Dept."
-    "Jeroen of Legisl. Dept."	"Deputy Head of Legisl. Dept."
-    "Laurens of Legisl. Dept."	"Chief of Legisl. Dept."
-    "Fred Undraiser"		"Fundraiser"
-    "A of ADC"			"Representative of ADC"	
-    "Minister"			"Minister of Justice"          
-    "General Student"		"Student"
+ad_proc ::twt::simulation::data::characters {} {
+    return {
+        Bernadette         "Bernadette"
+        MOTORHOME          "MOTORHOME"
+        "A of Lawfirm X"   "Her lawyer"
+        "A of Lawfirm Y"   "Its lawyer"
+        "B of Lawfirm X"   "Partner firm X"
+        "B of Lawfirm Y"   "Partner firm Y"
+        "C of Lawfirm X"   "Secretary firm X"
+        "C of Lawfirm Y"   "Secretary firm Y"
+        "Portal"           "Library"          
+        "Lok of Legisl. Dept."		"Member 1 of Legisl. Dept."
+        "Peter of Legisl. Dept."	"Member 2 of Legisl. Dept."
+        "Aernout of Legisl. Dept."	"Head of Legisl. Dept."
+        "Jeroen of Legisl. Dept."	"Deputy Head of Legisl. Dept."
+        "Laurens of Legisl. Dept."	"Chief of Legisl. Dept."
+        "Fred Undraiser"		"Fundraiser"
+        "A of ADC"			"Representative of ADC"	
+        "Minister"			"Minister of Justice"          
+        "General Student"		"Student"
+    }
 }
 
-array set characters_ld {
-    "Lok of Legisl. Dept."		"Member 1 of Legisl. Dept."
+ad_proc ::twt::simulation::data::characters_ld {} {
+    return {
+    "Lok of Legisl. Dept."	"Member 1 of Legisl. Dept."
     "Peter of Legisl. Dept."	"Member 2 of Legisl. Dept."
     "Aernout of Legisl. Dept."	"Head of Legisl. Dept."
     "Jeroen of Legisl. Dept."	"Deputy Head of Legisl. Dept."
@@ -36,14 +51,18 @@
     "A of ADC"			"Representative of ADC"	
     "Minister"			"Minister of Justice"          
     "General Student"		"Student"
+    }
 }
 
-array set properties {
-    "Demo Property 1" "Demo Property 1"
-    "Demo Property 2" "Demo Property 2"
+ad_proc ::twt::simulation::data::properties {} {
+    return {
+        "Demo Property 1" "Demo Property 1"
+        "Demo Property 2" "Demo Property 2"
+    }
 }
 
-array set tasks {
+ad_proc ::twt::simulation::data::tasks {} {
+    return {
     "Ask information from Bernadette" {assigned_role "Her lawyer" recipient_role "Bernadette"}
     "Ask information from MOTORHOME" {assigned_role "Her lawyer" recipient_role "MOTORHOME"}
     "Ask information from opponent's lawyer 1" {assigned_role "Its lawyer" recipient_role "Her lawyer"}
@@ -59,9 +78,11 @@
     "Give information to opponent's lawyer" {assigned_role "Her lawyer" recipient_role "Its lawyer"}
     "Send final report" {assigned_role "Her lawyer" recipient_role "Partner firm X"}
     "Send draft report" {assigned_role "Her lawyer" recipient_role "Partner firm X"}
+    }
 }
 
-array set tasks_ld {
+ad_proc ::twt::simulation::data::tasks_ld {} {
+    return {
     "Write Proposal gr1" {assigned_role "Member 1 of Legisl. Dept." recipient_role "Head of Legisl. Dept."}
     "Write Proposal gr2" {assigned_role "Member 2 of Legisl. Dept." recipient_role "Deputy Head of Legisl. Dept."}
     "Write Opinion SHOULD BE AN ADDINFOTOPORTFOLIO gr1" {assigned_role "Fundraiser" recipient_role "Minister of Justice"}
@@ -82,4 +103,139 @@
     "Implementation of all received comments and opinions SHOULD BE AN ADDINFOTOPORTFOLIO gr2" {assigned_role "Member 2 of Legisl. Dept." recipient_role "Minister of Justice"}
     "Write law SHOULD BE AN ADDINFOTOPORTFOLIO gr1" {assigned_role "Member 1 of Legisl. Dept." recipient_role "Minister of Justice"}
     "Write law SHOULD BE AN ADDINFOTOPORTFOLIO gr2" {assigned_role "Member 1 of Legisl. Dept." recipient_role "Minister of Justice"}
-}   
+    }   
+}
+
+ad_proc ::twt::simulation::data::tilburg_template_spec {} {
+    return "simulatie_tilburg {
+    description {Use case 1 template from Leiden team.}
+    description_mime_type text/enhanced
+    object_type acs_object
+    package_key simulation
+    pretty_name {
+        Simulation Tilburg
+    }
+    roles {
+        lawyer {
+            pretty_name Lawyer
+        }
+        client {
+            pretty_name Client
+        }
+        other_lawyer {
+            pretty_name {
+                Other lawyer
+            }
+        }
+        other_client {
+            pretty_name {
+                Other client
+            }
+        }
+        mentor {
+            pretty_name Mentor
+        }
+        secretary {
+            pretty_name Secretary
+        }
+    }
+    actions {
+        initialize {
+            initial_action_p t
+            new_state started
+            pretty_name Initialize
+            attachment_num 0
+        }
+        ask_client {
+            assigned_role lawyer
+            assigned_states started
+            new_state open
+            pretty_name {
+                Ask client
+            }
+            attachment_num 1
+            recipient_role client
+        }
+        ask_client_for_more_information {
+            assigned_role lawyer
+            enabled_states open
+            pretty_name {Ask Client for more information}
+            attachment_num 1
+            recipient_role client
+        }
+        consult_lawyer {
+            assigned_role lawyer
+            enabled_states open
+            pretty_name {
+                Consult lawyer
+            }
+            attachment_num 1
+            recipient_role other_lawyer
+        }
+        visit_the_library {
+            assigned_role lawyer
+            enabled_states open
+            pretty_name {Visit the library}
+            attachment_num 0
+            recipient_role lawyer
+        }
+        consult_mentor {
+            assigned_role lawyer
+            enabled_states open
+            pretty_name {
+                Consult mentor
+            }
+            attachment_num 1
+            recipient_role mentor
+        }
+        mentor_intervenes {
+            assigned_role mentor
+            enabled_states open
+            pretty_name {
+                Mentor intervenes
+            }
+            attachment_num 1
+            recipient_role lawyer
+        }
+        consult_secretary {
+            assigned_role lawyer
+            enabled_states open
+            pretty_name {
+                Consult secretary
+            }
+            attachment_num 1
+            recipient_role secretary
+        }
+        write_legal_advice {
+            assigned_role lawyer
+            assigned_states open
+            new_state written
+            pretty_name {Write legal advice}
+            attachment_num 1
+            recipient_role secretary
+        }
+        correct_spell_check_etc {
+            assigned_role secretary
+            enabled_states written
+            new_state done
+            pretty_name {Correct, spell-check, etc.}
+            attachment_num 1
+            recipient_role client
+        }
+    }
+    states {
+        started {
+            pretty_name Started
+        }
+        open {
+            pretty_name Open
+        }
+        written {
+            pretty_name Written
+        }
+        done {
+            pretty_name Done
+        }
+    }
+}"
+}
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.6 -r1.7
--- openacs-4/contrib/packages/simulation/test/simulation-test-procs.tcl	7 Jan 2004 16:16:06 -0000	1.6
+++ openacs-4/contrib/packages/simulation/test/simulation-test-procs.tcl	8 Jan 2004 11:27:38 -0000	1.7
@@ -4,7 +4,296 @@
 # @author Peter Marklund
 
 namespace eval ::twt::simulation {}
+namespace eval ::twt::simulation::setup {}
+namespace eval ::twt::simulation::test {}
 
+##############################
+#
+# ::twt::simulation::setup procs
+#
+##############################
+
+ad_proc ::twt::simulation::setup::users_and_groups {} {
+
+    ::twt::log_section "Login site-wide admin"
+    ::twt::user::login_site_wide_admin
+
+    ::twt::log_section "Add demo users to system"
+    for {set i 1} {$i <= 20} {incr i} {
+        ::twt::simulation::add_user -first_names Demo -last_name "User $i"
+    }    
+
+    ::twt::log_section "Add demo groups"
+    for {set i 1} {$i <= 5} {incr i} {
+        do_request "/admin/group-types/one?group_type=group"
+        link follow ~u "parties/new"
+
+        field find ~n group.group_name
+        field fill "Demo group $i"
+        form submit
+    }
+    
+    ::twt::log_section "Add demo users to groups"
+    for {set i 1} {$i <= 5} {incr i} {
+        
+        set add_user_url [::twt::simulation::add_user_to_group_url -group_name "Demo group $i"]
+
+        for {set user_count [expr ($i - 1)*4 + 1]} {$user_count <= [expr $i*4]} {incr user_count} {
+            ::twt::simulation::add_user_to_group -add_user_url $add_user_url -user_name "Demo User $user_count"
+        }
+    }
+
+    ::twt::log_section "Create a demo user in each permission group"
+    foreach group_name {
+        "Sim Admins"
+        "Template Authors"
+        "Case Authors"
+        "Service Admins"
+        "City Admins"
+        "Actors"
+    } {
+        set first_names [::twt::simulation::permission_user_first_names $group_name]
+        set last_name [::twt::simulation::permission_user_last_name $group_name]
+        ::twt::simulation::add_user -first_names $first_names -last_name $last_name
+
+        ::twt::simulation::add_user_to_group -group_name $group_name -user_name "$first_names $last_name"
+    }
+}
+
+ad_proc ::twt::simulation::setup::citybuild_objects {} {
+
+    # Do this as the city build user to make sure he has sufficient permissions
+    ::twt::log_section "Login city admin"
+    ::twt::user::login [::twt::simulation::permission_user_email "City Admins"]
+
+    ::twt::log_section "Create an image object"
+    do_request /simulation/citybuild
+    link follow ~u object-edit
+    form find ~n object
+    field find ~n content_type
+    field select2 ~v image
+    field find ~n __refreshing_p
+    field fill 1
+    form submit    
+    field find ~n title
+    field fill "New Jersey Lawyers"
+    field find ~n description
+    field fill "New Jersey Lawyers and Consumers"
+    field find ~n content_file
+    field fill [::twt::config::serverroot]/packages/simulation/test/new-jersey-lawyer-logo.gif
+    form submit
+
+    ::twt::log_section "Create characters for Elementary private law"
+    array set characters [::twt::simulation::data::characters]
+    foreach character_name [array names characters] {
+        ::twt::simulation::add_object -type character -title $character_name
+    }
+
+    ::twt::log_section "Create characters for Legislative Drafting"
+    array set characters_ld [::twt::simulation::data::characters_ld]
+    foreach character_name [array names characters_ld] {
+        ::twt::simulation::add_object -type character -title $character_name
+    }
+
+    ::twt::log_section "Create properties"
+    array set characters_ld [::twt::simulation::data::properties]
+    foreach property_name [array names properties] {
+        ::twt::simulation::add_object -type sim_prop -title $property_name
+    }
+}
+
+ad_proc ::twt::simulation::setup::elementary_private_law_template {} {
+
+    # Do this as the template author to make sure he has sufficient permissions
+    ::twt::log_section "Login template author"
+    ::twt::user::login [::twt::simulation::permission_user_email "Template Authors"]
+
+    set template_name "Elementary Private Law"
+    ::twt::log_section "Create $template_name simulation template"
+    ::twt::simulation::add_template -template_name $template_name
+
+    ::twt::log_section "Create roles for template"
+    ::twt::simulation::add_roles_to_template \
+        -template_name $template_name \
+        -characters_list [::twt::simulation::data::characters]
+
+    ::twt::log_section "Add tasks to template"
+    ::twt::simulation::add_tasks_to_template \
+        -template_name $template_name \
+        -tasks_list [::twt::simulation::data::tasks]
+}
+
+ad_proc ::twt::simulation::setup::legislative_drafting_template {} {
+
+    # Do this as the sim admin to make sure he has sufficient permissions
+    ::twt::log_section "Login sim admin"
+    ::twt::user::login [::twt::simulation::permission_user_email "Sim Admins"]
+
+    set template_name "Legislative Drafting"
+    ::twt::log_section "Create $template_name simulation template"
+    ::twt::simulation::add_template -template_name $template_name
+
+    ::twt::log_section "Create roles for template"
+    ::twt::simulation::add_roles_to_template \
+        -template_name $template_name \
+        -characters_list [::twt::simulation::data::characters_ld]
+
+    ::twt::log_section "Add tasks to template"
+    ::twt::simulation::add_tasks_to_template \
+        -template_name $template_name \
+        -tasks_list [::twt::simulation::data::tasks_ld]
+}
+
+ad_proc ::twt::simulation::setup::tilburg_template_from_spec {} {
+
+    # Do this as the template author to make sure he has sufficient permissions
+    ::twt::log_section "Login template author"
+    ::twt::user::login [::twt::simulation::permission_user_email "Template Authors"]
+
+    ::twt::log_section "Create a template from a spec"
+    do_request /simulation/simbuild/template-load
+    field fill "Template loaded from spec" ~n pretty_name
+    field fill [::twt::simulation::data::tilburg_template_spec] ~n spec
+    form submit
+}
+
+##############################
+#
+# ::twt::simulation::test procs
+#
+##############################
+
+ad_proc ::twt::simulation::test::permissions_anonymous {} {
+
+    ::twt::log_section "Permission testing with anonymous user"
+    ::twt::user::logout
+
+    # The anonymous user can access the index page with the flash map
+    ::twt::simulation::assert_page_accessible /simulation
+
+    # TODO: Should see a list of all simulation open for enrollment
+
+    # The anonymous user can access an object view page
+    ::twt::simulation::assert_page_accessible /simulation/object/motorhome
+
+    # The anonymous user can not access any of the four modules
+    foreach disallowed_url {simplay siminst simbuild citybuild} {
+        do_request /simulation/$disallowed_url
+        if { ![regexp {/register/} $::tclwebtest::url] } {
+            error "Anonymous user was not redirected to login page for url $disallowed_url"
+        }
+    }
+}
+
+ad_proc ::twt::simulation::test::permissions_city_admin {} {
+
+    set group_name "City Admins"
+    ::twt::log_section "Permission testing for $group_name user"
+    ::twt::user::login [::twt::simulation::permission_user_email $group_name]
+
+    # city admin can access index page
+    ::twt::simulation::assert_page_accessible /simulation
+
+    # can access citybuild
+    ::twt::simulation::assert_page_accessible /simulation/citybuild
+
+    # can create, edit on_map_p, and delete object
+    ::twt::simulation::create_edit_delete_property
+
+    # can not build or instantiate templates
+    foreach module {simbuild siminst} {
+        ::twt::simulation::assert_page_not_accessible /simulation/$module
+    }
+}
+
+ad_proc ::twt::simulation::test::permissions_sim_admin {} {
+
+    set group_name "Sim Admins"
+    ::twt::log_section "Permission testing for $group_name user"
+    ::twt::user::login [::twt::simulation::permission_user_email $group_name]
+
+    # can do anything within the package
+    # including the on_map_p attribute
+
+    # We've already done some testing with the sim admin in the template setup
+
+    # Access each module
+    foreach module {citybuild simbuild siminst simplay} {
+        ::twt::simulation::assert_page_accessible /simulation/$module
+    }
+    
+    # Set the on_map_p attribute
+    ::twt::simulation::create_edit_delete_property
+}
+
+ad_proc ::twt::simulation::test::permissions_template_author {} {
+
+    set group_name "Template Authors"
+    ::twt::log_section "Permission testing for $group_name user"
+    ::twt::user::login [::twt::simulation::permission_user_email $group_name]
+
+    # read/create templates, only own templates
+    # cannot edit other people's templates
+    
+    # TODO: can do anything in siminst
+
+    # Access each module
+    foreach module {citybuild simbuild siminst simplay} {
+        ::twt::simulation::assert_page_accessible /simulation/$module
+    }
+
+    # TODO: cannot see case logs
+}
+
+ad_proc ::twt::simulation::test::permissions_case_author {} {
+
+    set group_name "Case Authors"
+    ::twt::log_section "Permission testing for $group_name user"
+    ::twt::user::login [::twt::simulation::permission_user_email $group_name]
+
+    # cannot access modules: simbuild
+    foreach module {simbuild} {
+        ::twt::simulation::assert_page_not_accessible /simulation/$module
+    }
+    foreach module {citybuild siminst simplay} {
+        ::twt::simulation::assert_page_accessible /simulation/$module
+    }
+
+    # TODO: can see case logs
+
+    # cannot set on_map_p attribute
+}
+
+ad_proc ::twt::simulation::test::permissions_service_admin {} {
+
+    set group_name "Service Admins"
+    ::twt::log_section "Permission testing for $group_name user"
+    ::twt::user::login [::twt::simulation::permission_user_email $group_name]
+
+    # can add users
+
+    # TODO: can make users eligible for enrollment
+}
+
+ad_proc ::twt::simulation::test::permissions_actor {} {
+
+    set group_name "Actors"
+    ::twt::log_section "Permission testing for $group_name user"
+    ::twt::user::login [::twt::simulation::permission_user_email $group_name]
+
+    # TODO: participate in the simulation in simplay
+
+    foreach module {citybuild simbuild siminst} {
+        ::twt::simulation::assert_page_not_accessible /simulation/$module
+    }
+}
+
+##############################
+#
+# ::twt::simulation helper procs
+#
+##############################
+
 ad_proc ::twt::simulation::get_object_short_name { name } {
     set short_name [string tolower $name]
     regsub -all {\s} $short_name {-} short_name
@@ -140,140 +429,6 @@
     form submit    
 }
 
-ad_proc ::twt::simulation::get_template_spec {} {
-    return "simulatie_tilburg {
-    description {Use case 1 template from Leiden team.}
-    description_mime_type text/enhanced
-    object_type acs_object
-    package_key simulation
-    pretty_name {
-        Simulation Tilburg
-    }
-    roles {
-        lawyer {
-            pretty_name Lawyer
-        }
-        client {
-            pretty_name Client
-        }
-        other_lawyer {
-            pretty_name {
-                Other lawyer
-            }
-        }
-        other_client {
-            pretty_name {
-                Other client
-            }
-        }
-        mentor {
-            pretty_name Mentor
-        }
-        secretary {
-            pretty_name Secretary
-        }
-    }
-    actions {
-        initialize {
-            initial_action_p t
-            new_state started
-            pretty_name Initialize
-            attachment_num 0
-        }
-        ask_client {
-            assigned_role lawyer
-            assigned_states started
-            new_state open
-            pretty_name {
-                Ask client
-            }
-            attachment_num 1
-            recipient_role client
-        }
-        ask_client_for_more_information {
-            assigned_role lawyer
-            enabled_states open
-            pretty_name {Ask Client for more information}
-            attachment_num 1
-            recipient_role client
-        }
-        consult_lawyer {
-            assigned_role lawyer
-            enabled_states open
-            pretty_name {
-                Consult lawyer
-            }
-            attachment_num 1
-            recipient_role other_lawyer
-        }
-        visit_the_library {
-            assigned_role lawyer
-            enabled_states open
-            pretty_name {Visit the library}
-            attachment_num 0
-            recipient_role lawyer
-        }
-        consult_mentor {
-            assigned_role lawyer
-            enabled_states open
-            pretty_name {
-                Consult mentor
-            }
-            attachment_num 1
-            recipient_role mentor
-        }
-        mentor_intervenes {
-            assigned_role mentor
-            enabled_states open
-            pretty_name {
-                Mentor intervenes
-            }
-            attachment_num 1
-            recipient_role lawyer
-        }
-        consult_secretary {
-            assigned_role lawyer
-            enabled_states open
-            pretty_name {
-                Consult secretary
-            }
-            attachment_num 1
-            recipient_role secretary
-        }
-        write_legal_advice {
-            assigned_role lawyer
-            assigned_states open
-            new_state written
-            pretty_name {Write legal advice}
-            attachment_num 1
-            recipient_role secretary
-        }
-        correct_spell_check_etc {
-            assigned_role secretary
-            enabled_states written
-            new_state done
-            pretty_name {Correct, spell-check, etc.}
-            attachment_num 1
-            recipient_role client
-        }
-    }
-    states {
-        started {
-            pretty_name Started
-        }
-        open {
-            pretty_name Open
-        }
-        written {
-            pretty_name Written
-        }
-        done {
-            pretty_name Done
-        }
-    }
-}"
-}
-
 ad_proc ::twt::simulation::add_template {
     {-template_name:required}
 } {
@@ -285,9 +440,9 @@
 
 ad_proc ::twt::simulation::add_roles_to_template {
     {-template_name:required}
-    {-character_array:required}
+    {-characters_list:required}
 } {
-    upvar $character_array characters
+    array set characters $characters_list
 
     ::twt::simulation::visit_template_page $template_name 
     link follow ~u role-edit
@@ -303,9 +458,9 @@
 
 ad_proc ::twt::simulation::add_tasks_to_template {
     {-template_name:required}
-    {-task_array:required}
+    {-tasks_list:required}
 } {
-    upvar $task_array tasks
+    array set tasks $tasks_list
 
     ::twt::simulation::visit_template_page $template_name 
 
@@ -359,3 +514,28 @@
                 [regexp $url [response url]] && \
                 ![regexp "Permission Denied" [response body]]]
 }
+
+ad_proc ::twt::simulation::create_edit_delete_property {} {
+
+    set object_title "Test property"
+    ::twt::simulation::add_object -type sim_prop -title $object_title
+
+    # can edit on_map_p attribute of object
+    do_request /simulation/citybuild
+    link follow ~c $object_title
+    link follow ~u object-edit
+    regexp {item%5fid=([0-9]+)} [response url] match item_id
+    form find ~n object
+    field find ~n attr__sim_prop__on_map_p
+    field select2 ~v t
+    form submit
+    if { [regexp "Permission Denied" [response body]] } {
+        error "Got permission denied when editing on_map_p of an object"
+    }
+
+    # can delete object    
+    do_request "/simulation/citybuild/object-delete?confirm_p=1&item_id=$item_id"
+    if { [regexp "Permission Denied" [response body]] } {
+        error "Got permission denied when deleting an object"
+    }
+}
\ No newline at end of file
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.16 -r1.17
--- openacs-4/packages/simulation/test/demo-data-setup.test	7 Jan 2004 16:16:06 -0000	1.16
+++ openacs-4/packages/simulation/test/demo-data-setup.test	8 Jan 2004 11:27:38 -0000	1.17
@@ -1,287 +1,28 @@
 if { [catch {
+
     # Source Tcl libraries
     set script_dir [file dirname [info script]]
     source "${script_dir}/../../../etc/install/tcl/test-procs.tcl"
     source "${script_dir}/simulation-test-procs.tcl"
+    source "${script_dir}/demo-data.tcl"
 
-    # Test Execution START
+    ::twt::simulation::setup::users_and_groups
 
-    global __demo_users_password
-    set __demo_users_password 1
+    ::twt::simulation::setup::citybuild_objects
 
-    source demo-data.tcl
-
-    ::twt::log_section "Login the site wide admin"
-    ::twt::user::login_site_wide_admin
-
-    ###################################
-    #
-    # Users and Groups setup
-    #
-    ###################################
-
-    ::twt::log_section "Add demo users to system"
-    for {set i 1} {$i <= 20} {incr i} {
-        ::twt::simulation::add_user -first_names Demo -last_name "User $i"
-    }    
-
-    ::twt::log_section "Add demo groups"
-    for {set i 1} {$i <= 5} {incr i} {
-        do_request "/admin/group-types/one?group_type=group"
-        link follow ~u "parties/new"
-
-        field find ~n group.group_name
-        field fill "Demo group $i"
-        form submit
-    }
-    
-    ::twt::log_section "Add demo users to groups"
-    for {set i 1} {$i <= 5} {incr i} {
-        
-        set add_user_url [::twt::simulation::add_user_to_group_url -group_name "Demo group $i"]
-
-        for {set user_count [expr ($i - 1)*4 + 1]} {$user_count <= [expr $i*4]} {incr user_count} {
-            ::twt::simulation::add_user_to_group -add_user_url $add_user_url -user_name "Demo User $user_count"
-        }
-    }
-
-    ::twt::log_section "Create a demo user in each permission group"
-    foreach group_name {
-        "Sim Admins"
-        "Template Authors"
-        "Case Authors"
-        "Service Admins"
-        "City Admins"
-        "Actors"
-    } {
-        set first_names [::twt::simulation::permission_user_first_names $group_name]
-        set last_name [::twt::simulation::permission_user_last_name $group_name]
-        ::twt::simulation::add_user -first_names $first_names -last_name $last_name
-
-        ::twt::simulation::add_user_to_group -group_name $group_name -user_name "$first_names $last_name"
-    }
-
-    ###################################
-    #
-    # Citybuild object setup
-    #
-    ###################################
-
-    # Do this as the city build user to make sure he has sufficient permissions
-    ::twt::user::login [::twt::simulation::permission_user_email "City Admins"]
-
-    ::twt::log_section "Create an image object"
-    do_request /simulation/citybuild
-    link follow ~u object-edit
-    form find ~n object
-    field find ~n content_type
-    field select2 ~v image
-    field find ~n __refreshing_p
-    field fill 1
-    form submit    
-    field find ~n title
-    field fill "New Jersey Lawyers"
-    field find ~n description
-    field fill "New Jersey Lawyers and Consumers"
-    field find ~n content_file
-    field fill [::twt::config::serverroot]/packages/simulation/test/new-jersey-lawyer-logo.gif
-    form submit
-
-    ::twt::log_section "Create characters for Elementary private law"
-    foreach character_name [array names characters] {
-        ::twt::simulation::add_object -type character -title $character_name
-    }
-
-    ::twt::log_section "Create characters for Legislative Drafting"
-    foreach character_name [array names characters_ld] {
-        ::twt::simulation::add_object -type character -title $character_name
-    }
-
-    ::twt::log_section "Create properties"
-    foreach property_name [array names properties] {
-        ::twt::simulation::add_object -type sim_prop -title $property_name
-    }
-
-    ###################################
-    #
-    # Elementary private law template
-    #
-    ###################################
-
-    # TODO: do this is as "Template Authors" test user
-    ::twt::user::login_site_wide_admin
-
-    set template_name "Elementary Private Law"
-    ::twt::log_section "Create $template_name simulation template"
-    ::twt::simulation::add_template -template_name $template_name
-
-    ::twt::log_section "Create roles for template"
-    ::twt::simulation::add_roles_to_template \
-        -template_name $template_name \
-        -character_array characters
-
-    ::twt::log_section "Add tasks to template"
-    ::twt::simulation::add_tasks_to_template \
-        -template_name $template_name \
-        -task_array tasks
-
-    ###################################
-    #
-    # Legislative Drafting template
-    #
-    ###################################
-
-    set template_name "Legislative Drafting"
-    ::twt::log_section "Create $template_name simulation template"
-    ::twt::simulation::add_template -template_name $template_name
-
-    ::twt::log_section "Create roles for template"
-    ::twt::simulation::add_roles_to_template \
-        -template_name $template_name \
-        -character_array characters_ld
-
-    ::twt::log_section "Add tasks to template"
-    ::twt::simulation::add_tasks_to_template \
-        -template_name $template_name \
-        -task_array tasks_ld
-
-    ###################################
-    #
-    # Tilburg template created from spec
-    #
-    ###################################
-
-    ::twt::log_section "Create a template from a spec"
-    do_request /simulation/simbuild/template-load
-    field fill "Template loaded from spec" ~n pretty_name
-    field fill [::twt::simulation::get_template_spec] ~n spec
-    form submit
-    
+    ::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
 
-    ###################################
-    #
-    # Permission testing with anonymous user
-    #
-    ###################################
+    ::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::log_section "Permission testing with anonymouse user"
-    ::twt::user::logout
-
-    # The anonymous user can access the index page with the flash map
-    ::twt::simulation::assert_page_accessible /simulation
-
-    # TODO: Should see a list of all simulation open for enrollment
-
-    # The anonymous user can access an object view page
-    ::twt::simulation::assert_page_accessible /simulation/object/motorhome
-
-    # The anonymous user can not access any of the four modules
-    foreach disallowed_url {simplay siminst simbuild citybuild} {
-        do_request /simulation/$disallowed_url
-        if { ![regexp {/register/} $::tclwebtest::url] } {
-            error "Anonymous user was not redirected to login page for url $disallowed_url"
-        }
-    }
-
-    ###################################
-    #
-    # Permission testing with city admin
-    #
-    ###################################
-
-    set group_name "City Admins"
-
-    # login user
-    ::twt::user::login [::twt::simulation::permission_user_email $group_name]
-
-    # city admin can access index page
-    ::twt::simulation::assert_page_accessible /simulation
-
-    # can access citybuild
-    ::twt::simulation::assert_page_accessible /simulation/citybuild
-
-    # can create object
-    set object_title "Test property"
-    ::twt::simulation::add_object -type sim_prop -title $object_title
-
-    # can edit on_map_p attribute of object
-    do_request /simulation/citybuild
-    link follow ~c $object_title
-    link follow ~u object-edit
-    regexp {item%5fid=([0-9]+)} [response url] match item_id
-    form find ~n object
-    field find ~n attr__sim_prop__on_map_p
-    field select2 ~v t
-    form submit
-    if { [regexp "Permission Denied" [response body]] } {
-        error "City admin should not get permission denied when editing on_map_p of an object"
-    }
-
-    # can delete object    
-    do_request "/simulation/citybuild/object-delete?confirm_p=1&item_id=$item_id"
-    if { [regexp "Permission Denied" [response body]] } {
-        error "City admin should not get permission denied when deleting an object"
-    }
-
-    # can not build or instantiate templates
-    foreach module {simbuild siminst} {
-        ::twt::simulation::assert_page_not_accessible /simulation/$module
-    }
-
-    ###################################
-    #
-    # Permission testing with sim admin (simulation super user)
-    #
-    ###################################
-
-    # can do anything within the package
-    # including the on_map_p attribute
-
-    ###################################
-    #
-    # Permission testing with template author
-    #
-    ###################################
-
-    # read/create templates, only own templates
-    # cannot edit other people's templates
-    
-    # can access all modules, can do anything in siminst
-
-    # cannot see case logs
-
-    ###################################
-    #
-    # Permission testing with case author
-    #
-    ###################################
-
-    # cannot access modules: simbuild
-
-    # can see case logs
-
-    # cannot set on_map_p attribute
-
-    ###################################
-    #
-    # Permission testing with service admin
-    #
-    ###################################
-
-    # can add users
-    # can make users eligible for enrollment
-
-    ###################################
-    #
-    # Permission testing Actor (playing in a sim)
-    #
-    ###################################
-    
-    # participate in the simulation in simplay
-
-    # cannot access citybuild, simbuild, siminst
-
 } result] } {
     global errorInfo
 
Index: openacs-4/packages/simulation/test/demo-data.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/test/demo-data.tcl,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/simulation/test/demo-data.tcl	7 Jan 2004 16:16:06 -0000	1.1
+++ openacs-4/packages/simulation/test/demo-data.tcl	8 Jan 2004 11:27:38 -0000	1.2
@@ -1,33 +1,48 @@
-set actors_list {
-    Teacher
-    Student
-    Agent1
-    Agent2
+# Procs returning demo data.
+#
+# Procs to support the Tclwebtest (HTTP level) testing and demo data setup
+# of the simulation package.
+#
+# @author Peter Marklund
+
+namespace eval ::twt::simulation {}
+namespace eval ::twt::simulation::data {}
+
+ad_proc ::twt::simulation::data::actors {} {
+    return {
+        Teacher
+        Student
+        Agent1
+        Agent2
+    }
 }
 
-array set characters {
-    Bernadette         "Bernadette"
-    MOTORHOME          "MOTORHOME"
-    "A of Lawfirm X"   "Her lawyer"
-    "A of Lawfirm Y"   "Its lawyer"
-    "B of Lawfirm X"   "Partner firm X"
-    "B of Lawfirm Y"   "Partner firm Y"
-    "C of Lawfirm X"   "Secretary firm X"
-    "C of Lawfirm Y"   "Secretary firm Y"
-    "Portal"           "Library"          
-    "Lok of Legisl. Dept."		"Member 1 of Legisl. Dept."
-    "Peter of Legisl. Dept."	"Member 2 of Legisl. Dept."
-    "Aernout of Legisl. Dept."	"Head of Legisl. Dept."
-    "Jeroen of Legisl. Dept."	"Deputy Head of Legisl. Dept."
-    "Laurens of Legisl. Dept."	"Chief of Legisl. Dept."
-    "Fred Undraiser"		"Fundraiser"
-    "A of ADC"			"Representative of ADC"	
-    "Minister"			"Minister of Justice"          
-    "General Student"		"Student"
+ad_proc ::twt::simulation::data::characters {} {
+    return {
+        Bernadette         "Bernadette"
+        MOTORHOME          "MOTORHOME"
+        "A of Lawfirm X"   "Her lawyer"
+        "A of Lawfirm Y"   "Its lawyer"
+        "B of Lawfirm X"   "Partner firm X"
+        "B of Lawfirm Y"   "Partner firm Y"
+        "C of Lawfirm X"   "Secretary firm X"
+        "C of Lawfirm Y"   "Secretary firm Y"
+        "Portal"           "Library"          
+        "Lok of Legisl. Dept."		"Member 1 of Legisl. Dept."
+        "Peter of Legisl. Dept."	"Member 2 of Legisl. Dept."
+        "Aernout of Legisl. Dept."	"Head of Legisl. Dept."
+        "Jeroen of Legisl. Dept."	"Deputy Head of Legisl. Dept."
+        "Laurens of Legisl. Dept."	"Chief of Legisl. Dept."
+        "Fred Undraiser"		"Fundraiser"
+        "A of ADC"			"Representative of ADC"	
+        "Minister"			"Minister of Justice"          
+        "General Student"		"Student"
+    }
 }
 
-array set characters_ld {
-    "Lok of Legisl. Dept."		"Member 1 of Legisl. Dept."
+ad_proc ::twt::simulation::data::characters_ld {} {
+    return {
+    "Lok of Legisl. Dept."	"Member 1 of Legisl. Dept."
     "Peter of Legisl. Dept."	"Member 2 of Legisl. Dept."
     "Aernout of Legisl. Dept."	"Head of Legisl. Dept."
     "Jeroen of Legisl. Dept."	"Deputy Head of Legisl. Dept."
@@ -36,14 +51,18 @@
     "A of ADC"			"Representative of ADC"	
     "Minister"			"Minister of Justice"          
     "General Student"		"Student"
+    }
 }
 
-array set properties {
-    "Demo Property 1" "Demo Property 1"
-    "Demo Property 2" "Demo Property 2"
+ad_proc ::twt::simulation::data::properties {} {
+    return {
+        "Demo Property 1" "Demo Property 1"
+        "Demo Property 2" "Demo Property 2"
+    }
 }
 
-array set tasks {
+ad_proc ::twt::simulation::data::tasks {} {
+    return {
     "Ask information from Bernadette" {assigned_role "Her lawyer" recipient_role "Bernadette"}
     "Ask information from MOTORHOME" {assigned_role "Her lawyer" recipient_role "MOTORHOME"}
     "Ask information from opponent's lawyer 1" {assigned_role "Its lawyer" recipient_role "Her lawyer"}
@@ -59,9 +78,11 @@
     "Give information to opponent's lawyer" {assigned_role "Her lawyer" recipient_role "Its lawyer"}
     "Send final report" {assigned_role "Her lawyer" recipient_role "Partner firm X"}
     "Send draft report" {assigned_role "Her lawyer" recipient_role "Partner firm X"}
+    }
 }
 
-array set tasks_ld {
+ad_proc ::twt::simulation::data::tasks_ld {} {
+    return {
     "Write Proposal gr1" {assigned_role "Member 1 of Legisl. Dept." recipient_role "Head of Legisl. Dept."}
     "Write Proposal gr2" {assigned_role "Member 2 of Legisl. Dept." recipient_role "Deputy Head of Legisl. Dept."}
     "Write Opinion SHOULD BE AN ADDINFOTOPORTFOLIO gr1" {assigned_role "Fundraiser" recipient_role "Minister of Justice"}
@@ -82,4 +103,139 @@
     "Implementation of all received comments and opinions SHOULD BE AN ADDINFOTOPORTFOLIO gr2" {assigned_role "Member 2 of Legisl. Dept." recipient_role "Minister of Justice"}
     "Write law SHOULD BE AN ADDINFOTOPORTFOLIO gr1" {assigned_role "Member 1 of Legisl. Dept." recipient_role "Minister of Justice"}
     "Write law SHOULD BE AN ADDINFOTOPORTFOLIO gr2" {assigned_role "Member 1 of Legisl. Dept." recipient_role "Minister of Justice"}
-}   
+    }   
+}
+
+ad_proc ::twt::simulation::data::tilburg_template_spec {} {
+    return "simulatie_tilburg {
+    description {Use case 1 template from Leiden team.}
+    description_mime_type text/enhanced
+    object_type acs_object
+    package_key simulation
+    pretty_name {
+        Simulation Tilburg
+    }
+    roles {
+        lawyer {
+            pretty_name Lawyer
+        }
+        client {
+            pretty_name Client
+        }
+        other_lawyer {
+            pretty_name {
+                Other lawyer
+            }
+        }
+        other_client {
+            pretty_name {
+                Other client
+            }
+        }
+        mentor {
+            pretty_name Mentor
+        }
+        secretary {
+            pretty_name Secretary
+        }
+    }
+    actions {
+        initialize {
+            initial_action_p t
+            new_state started
+            pretty_name Initialize
+            attachment_num 0
+        }
+        ask_client {
+            assigned_role lawyer
+            assigned_states started
+            new_state open
+            pretty_name {
+                Ask client
+            }
+            attachment_num 1
+            recipient_role client
+        }
+        ask_client_for_more_information {
+            assigned_role lawyer
+            enabled_states open
+            pretty_name {Ask Client for more information}
+            attachment_num 1
+            recipient_role client
+        }
+        consult_lawyer {
+            assigned_role lawyer
+            enabled_states open
+            pretty_name {
+                Consult lawyer
+            }
+            attachment_num 1
+            recipient_role other_lawyer
+        }
+        visit_the_library {
+            assigned_role lawyer
+            enabled_states open
+            pretty_name {Visit the library}
+            attachment_num 0
+            recipient_role lawyer
+        }
+        consult_mentor {
+            assigned_role lawyer
+            enabled_states open
+            pretty_name {
+                Consult mentor
+            }
+            attachment_num 1
+            recipient_role mentor
+        }
+        mentor_intervenes {
+            assigned_role mentor
+            enabled_states open
+            pretty_name {
+                Mentor intervenes
+            }
+            attachment_num 1
+            recipient_role lawyer
+        }
+        consult_secretary {
+            assigned_role lawyer
+            enabled_states open
+            pretty_name {
+                Consult secretary
+            }
+            attachment_num 1
+            recipient_role secretary
+        }
+        write_legal_advice {
+            assigned_role lawyer
+            assigned_states open
+            new_state written
+            pretty_name {Write legal advice}
+            attachment_num 1
+            recipient_role secretary
+        }
+        correct_spell_check_etc {
+            assigned_role secretary
+            enabled_states written
+            new_state done
+            pretty_name {Correct, spell-check, etc.}
+            attachment_num 1
+            recipient_role client
+        }
+    }
+    states {
+        started {
+            pretty_name Started
+        }
+        open {
+            pretty_name Open
+        }
+        written {
+            pretty_name Written
+        }
+        done {
+            pretty_name Done
+        }
+    }
+}"
+}
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.6 -r1.7
--- openacs-4/packages/simulation/test/simulation-test-procs.tcl	7 Jan 2004 16:16:06 -0000	1.6
+++ openacs-4/packages/simulation/test/simulation-test-procs.tcl	8 Jan 2004 11:27:38 -0000	1.7
@@ -4,7 +4,296 @@
 # @author Peter Marklund
 
 namespace eval ::twt::simulation {}
+namespace eval ::twt::simulation::setup {}
+namespace eval ::twt::simulation::test {}
 
+##############################
+#
+# ::twt::simulation::setup procs
+#
+##############################
+
+ad_proc ::twt::simulation::setup::users_and_groups {} {
+
+    ::twt::log_section "Login site-wide admin"
+    ::twt::user::login_site_wide_admin
+
+    ::twt::log_section "Add demo users to system"
+    for {set i 1} {$i <= 20} {incr i} {
+        ::twt::simulation::add_user -first_names Demo -last_name "User $i"
+    }    
+
+    ::twt::log_section "Add demo groups"
+    for {set i 1} {$i <= 5} {incr i} {
+        do_request "/admin/group-types/one?group_type=group"
+        link follow ~u "parties/new"
+
+        field find ~n group.group_name
+        field fill "Demo group $i"
+        form submit
+    }
+    
+    ::twt::log_section "Add demo users to groups"
+    for {set i 1} {$i <= 5} {incr i} {
+        
+        set add_user_url [::twt::simulation::add_user_to_group_url -group_name "Demo group $i"]
+
+        for {set user_count [expr ($i - 1)*4 + 1]} {$user_count <= [expr $i*4]} {incr user_count} {
+            ::twt::simulation::add_user_to_group -add_user_url $add_user_url -user_name "Demo User $user_count"
+        }
+    }
+
+    ::twt::log_section "Create a demo user in each permission group"
+    foreach group_name {
+        "Sim Admins"
+        "Template Authors"
+        "Case Authors"
+        "Service Admins"
+        "City Admins"
+        "Actors"
+    } {
+        set first_names [::twt::simulation::permission_user_first_names $group_name]
+        set last_name [::twt::simulation::permission_user_last_name $group_name]
+        ::twt::simulation::add_user -first_names $first_names -last_name $last_name
+
+        ::twt::simulation::add_user_to_group -group_name $group_name -user_name "$first_names $last_name"
+    }
+}
+
+ad_proc ::twt::simulation::setup::citybuild_objects {} {
+
+    # Do this as the city build user to make sure he has sufficient permissions
+    ::twt::log_section "Login city admin"
+    ::twt::user::login [::twt::simulation::permission_user_email "City Admins"]
+
+    ::twt::log_section "Create an image object"
+    do_request /simulation/citybuild
+    link follow ~u object-edit
+    form find ~n object
+    field find ~n content_type
+    field select2 ~v image
+    field find ~n __refreshing_p
+    field fill 1
+    form submit    
+    field find ~n title
+    field fill "New Jersey Lawyers"
+    field find ~n description
+    field fill "New Jersey Lawyers and Consumers"
+    field find ~n content_file
+    field fill [::twt::config::serverroot]/packages/simulation/test/new-jersey-lawyer-logo.gif
+    form submit
+
+    ::twt::log_section "Create characters for Elementary private law"
+    array set characters [::twt::simulation::data::characters]
+    foreach character_name [array names characters] {
+        ::twt::simulation::add_object -type character -title $character_name
+    }
+
+    ::twt::log_section "Create characters for Legislative Drafting"
+    array set characters_ld [::twt::simulation::data::characters_ld]
+    foreach character_name [array names characters_ld] {
+        ::twt::simulation::add_object -type character -title $character_name
+    }
+
+    ::twt::log_section "Create properties"
+    array set characters_ld [::twt::simulation::data::properties]
+    foreach property_name [array names properties] {
+        ::twt::simulation::add_object -type sim_prop -title $property_name
+    }
+}
+
+ad_proc ::twt::simulation::setup::elementary_private_law_template {} {
+
+    # Do this as the template author to make sure he has sufficient permissions
+    ::twt::log_section "Login template author"
+    ::twt::user::login [::twt::simulation::permission_user_email "Template Authors"]
+
+    set template_name "Elementary Private Law"
+    ::twt::log_section "Create $template_name simulation template"
+    ::twt::simulation::add_template -template_name $template_name
+
+    ::twt::log_section "Create roles for template"
+    ::twt::simulation::add_roles_to_template \
+        -template_name $template_name \
+        -characters_list [::twt::simulation::data::characters]
+
+    ::twt::log_section "Add tasks to template"
+    ::twt::simulation::add_tasks_to_template \
+        -template_name $template_name \
+        -tasks_list [::twt::simulation::data::tasks]
+}
+
+ad_proc ::twt::simulation::setup::legislative_drafting_template {} {
+
+    # Do this as the sim admin to make sure he has sufficient permissions
+    ::twt::log_section "Login sim admin"
+    ::twt::user::login [::twt::simulation::permission_user_email "Sim Admins"]
+
+    set template_name "Legislative Drafting"
+    ::twt::log_section "Create $template_name simulation template"
+    ::twt::simulation::add_template -template_name $template_name
+
+    ::twt::log_section "Create roles for template"
+    ::twt::simulation::add_roles_to_template \
+        -template_name $template_name \
+        -characters_list [::twt::simulation::data::characters_ld]
+
+    ::twt::log_section "Add tasks to template"
+    ::twt::simulation::add_tasks_to_template \
+        -template_name $template_name \
+        -tasks_list [::twt::simulation::data::tasks_ld]
+}
+
+ad_proc ::twt::simulation::setup::tilburg_template_from_spec {} {
+
+    # Do this as the template author to make sure he has sufficient permissions
+    ::twt::log_section "Login template author"
+    ::twt::user::login [::twt::simulation::permission_user_email "Template Authors"]
+
+    ::twt::log_section "Create a template from a spec"
+    do_request /simulation/simbuild/template-load
+    field fill "Template loaded from spec" ~n pretty_name
+    field fill [::twt::simulation::data::tilburg_template_spec] ~n spec
+    form submit
+}
+
+##############################
+#
+# ::twt::simulation::test procs
+#
+##############################
+
+ad_proc ::twt::simulation::test::permissions_anonymous {} {
+
+    ::twt::log_section "Permission testing with anonymous user"
+    ::twt::user::logout
+
+    # The anonymous user can access the index page with the flash map
+    ::twt::simulation::assert_page_accessible /simulation
+
+    # TODO: Should see a list of all simulation open for enrollment
+
+    # The anonymous user can access an object view page
+    ::twt::simulation::assert_page_accessible /simulation/object/motorhome
+
+    # The anonymous user can not access any of the four modules
+    foreach disallowed_url {simplay siminst simbuild citybuild} {
+        do_request /simulation/$disallowed_url
+        if { ![regexp {/register/} $::tclwebtest::url] } {
+            error "Anonymous user was not redirected to login page for url $disallowed_url"
+        }
+    }
+}
+
+ad_proc ::twt::simulation::test::permissions_city_admin {} {
+
+    set group_name "City Admins"
+    ::twt::log_section "Permission testing for $group_name user"
+    ::twt::user::login [::twt::simulation::permission_user_email $group_name]
+
+    # city admin can access index page
+    ::twt::simulation::assert_page_accessible /simulation
+
+    # can access citybuild
+    ::twt::simulation::assert_page_accessible /simulation/citybuild
+
+    # can create, edit on_map_p, and delete object
+    ::twt::simulation::create_edit_delete_property
+
+    # can not build or instantiate templates
+    foreach module {simbuild siminst} {
+        ::twt::simulation::assert_page_not_accessible /simulation/$module
+    }
+}
+
+ad_proc ::twt::simulation::test::permissions_sim_admin {} {
+
+    set group_name "Sim Admins"
+    ::twt::log_section "Permission testing for $group_name user"
+    ::twt::user::login [::twt::simulation::permission_user_email $group_name]
+
+    # can do anything within the package
+    # including the on_map_p attribute
+
+    # We've already done some testing with the sim admin in the template setup
+
+    # Access each module
+    foreach module {citybuild simbuild siminst simplay} {
+        ::twt::simulation::assert_page_accessible /simulation/$module
+    }
+    
+    # Set the on_map_p attribute
+    ::twt::simulation::create_edit_delete_property
+}
+
+ad_proc ::twt::simulation::test::permissions_template_author {} {
+
+    set group_name "Template Authors"
+    ::twt::log_section "Permission testing for $group_name user"
+    ::twt::user::login [::twt::simulation::permission_user_email $group_name]
+
+    # read/create templates, only own templates
+    # cannot edit other people's templates
+    
+    # TODO: can do anything in siminst
+
+    # Access each module
+    foreach module {citybuild simbuild siminst simplay} {
+        ::twt::simulation::assert_page_accessible /simulation/$module
+    }
+
+    # TODO: cannot see case logs
+}
+
+ad_proc ::twt::simulation::test::permissions_case_author {} {
+
+    set group_name "Case Authors"
+    ::twt::log_section "Permission testing for $group_name user"
+    ::twt::user::login [::twt::simulation::permission_user_email $group_name]
+
+    # cannot access modules: simbuild
+    foreach module {simbuild} {
+        ::twt::simulation::assert_page_not_accessible /simulation/$module
+    }
+    foreach module {citybuild siminst simplay} {
+        ::twt::simulation::assert_page_accessible /simulation/$module
+    }
+
+    # TODO: can see case logs
+
+    # cannot set on_map_p attribute
+}
+
+ad_proc ::twt::simulation::test::permissions_service_admin {} {
+
+    set group_name "Service Admins"
+    ::twt::log_section "Permission testing for $group_name user"
+    ::twt::user::login [::twt::simulation::permission_user_email $group_name]
+
+    # can add users
+
+    # TODO: can make users eligible for enrollment
+}
+
+ad_proc ::twt::simulation::test::permissions_actor {} {
+
+    set group_name "Actors"
+    ::twt::log_section "Permission testing for $group_name user"
+    ::twt::user::login [::twt::simulation::permission_user_email $group_name]
+
+    # TODO: participate in the simulation in simplay
+
+    foreach module {citybuild simbuild siminst} {
+        ::twt::simulation::assert_page_not_accessible /simulation/$module
+    }
+}
+
+##############################
+#
+# ::twt::simulation helper procs
+#
+##############################
+
 ad_proc ::twt::simulation::get_object_short_name { name } {
     set short_name [string tolower $name]
     regsub -all {\s} $short_name {-} short_name
@@ -140,140 +429,6 @@
     form submit    
 }
 
-ad_proc ::twt::simulation::get_template_spec {} {
-    return "simulatie_tilburg {
-    description {Use case 1 template from Leiden team.}
-    description_mime_type text/enhanced
-    object_type acs_object
-    package_key simulation
-    pretty_name {
-        Simulation Tilburg
-    }
-    roles {
-        lawyer {
-            pretty_name Lawyer
-        }
-        client {
-            pretty_name Client
-        }
-        other_lawyer {
-            pretty_name {
-                Other lawyer
-            }
-        }
-        other_client {
-            pretty_name {
-                Other client
-            }
-        }
-        mentor {
-            pretty_name Mentor
-        }
-        secretary {
-            pretty_name Secretary
-        }
-    }
-    actions {
-        initialize {
-            initial_action_p t
-            new_state started
-            pretty_name Initialize
-            attachment_num 0
-        }
-        ask_client {
-            assigned_role lawyer
-            assigned_states started
-            new_state open
-            pretty_name {
-                Ask client
-            }
-            attachment_num 1
-            recipient_role client
-        }
-        ask_client_for_more_information {
-            assigned_role lawyer
-            enabled_states open
-            pretty_name {Ask Client for more information}
-            attachment_num 1
-            recipient_role client
-        }
-        consult_lawyer {
-            assigned_role lawyer
-            enabled_states open
-            pretty_name {
-                Consult lawyer
-            }
-            attachment_num 1
-            recipient_role other_lawyer
-        }
-        visit_the_library {
-            assigned_role lawyer
-            enabled_states open
-            pretty_name {Visit the library}
-            attachment_num 0
-            recipient_role lawyer
-        }
-        consult_mentor {
-            assigned_role lawyer
-            enabled_states open
-            pretty_name {
-                Consult mentor
-            }
-            attachment_num 1
-            recipient_role mentor
-        }
-        mentor_intervenes {
-            assigned_role mentor
-            enabled_states open
-            pretty_name {
-                Mentor intervenes
-            }
-            attachment_num 1
-            recipient_role lawyer
-        }
-        consult_secretary {
-            assigned_role lawyer
-            enabled_states open
-            pretty_name {
-                Consult secretary
-            }
-            attachment_num 1
-            recipient_role secretary
-        }
-        write_legal_advice {
-            assigned_role lawyer
-            assigned_states open
-            new_state written
-            pretty_name {Write legal advice}
-            attachment_num 1
-            recipient_role secretary
-        }
-        correct_spell_check_etc {
-            assigned_role secretary
-            enabled_states written
-            new_state done
-            pretty_name {Correct, spell-check, etc.}
-            attachment_num 1
-            recipient_role client
-        }
-    }
-    states {
-        started {
-            pretty_name Started
-        }
-        open {
-            pretty_name Open
-        }
-        written {
-            pretty_name Written
-        }
-        done {
-            pretty_name Done
-        }
-    }
-}"
-}
-
 ad_proc ::twt::simulation::add_template {
     {-template_name:required}
 } {
@@ -285,9 +440,9 @@
 
 ad_proc ::twt::simulation::add_roles_to_template {
     {-template_name:required}
-    {-character_array:required}
+    {-characters_list:required}
 } {
-    upvar $character_array characters
+    array set characters $characters_list
 
     ::twt::simulation::visit_template_page $template_name 
     link follow ~u role-edit
@@ -303,9 +458,9 @@
 
 ad_proc ::twt::simulation::add_tasks_to_template {
     {-template_name:required}
-    {-task_array:required}
+    {-tasks_list:required}
 } {
-    upvar $task_array tasks
+    array set tasks $tasks_list
 
     ::twt::simulation::visit_template_page $template_name 
 
@@ -359,3 +514,28 @@
                 [regexp $url [response url]] && \
                 ![regexp "Permission Denied" [response body]]]
 }
+
+ad_proc ::twt::simulation::create_edit_delete_property {} {
+
+    set object_title "Test property"
+    ::twt::simulation::add_object -type sim_prop -title $object_title
+
+    # can edit on_map_p attribute of object
+    do_request /simulation/citybuild
+    link follow ~c $object_title
+    link follow ~u object-edit
+    regexp {item%5fid=([0-9]+)} [response url] match item_id
+    form find ~n object
+    field find ~n attr__sim_prop__on_map_p
+    field select2 ~v t
+    form submit
+    if { [regexp "Permission Denied" [response body]] } {
+        error "Got permission denied when editing on_map_p of an object"
+    }
+
+    # can delete object    
+    do_request "/simulation/citybuild/object-delete?confirm_p=1&item_id=$item_id"
+    if { [regexp "Permission Denied" [response body]] } {
+        error "Got permission denied when deleting an object"
+    }
+}
\ No newline at end of file