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" # Test Execution START global __demo_users_password set __demo_users_password 1 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 # TODO: click the ready_p link for the templates ################################### # # Permission testing with anonymous user # ################################### ::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 # Output error stack trace and HTML response body ::twt::log $result ::twt::log "*** Tcl TRACE ***" ::twt::log $errorInfo ::twt::log "The response body is: [response body]" error "Test failed: $result" }