Index: openacs-4/packages/tlf-survey/tcl/test/tlf-survey-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/tlf-survey/tcl/test/tlf-survey-test-procs.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/tlf-survey/tcl/test/tlf-survey-test-procs.tcl 15 Mar 2023 13:09:02 -0000 1.1.2.1 @@ -0,0 +1,161 @@ +namespace eval ::tlf_survey::test { + aa_register_init_class \ + tlf_survey_require_test_instance { + Make sure the test instance is there and create it if necessary. + } { + aa_export_vars {_test_instance_name _test_instance_package_id _user_id _user_info} + set _test_instance_name /tlf-survey-test + set package_id [::acs::test::require_package_instance \ + -package_key tlf-survey \ + -instance_name $_test_instance_name \ + -empty] + + set _test_instance_package_id $package_id + aa_log "Test instance package_id: $_test_instance_package_id" + # do not inherit the permission from the root site_node "/" + #permission::set_not_inherit -object_id $package_id + set _user_id [db_nextval acs_object_id_seq] + set _user_info [acs::test::user::create -user_id $_user_id -admin] + acs::test::confirm_email -user_id $_user_id + } { + # + # Cleanup: unmount the test instance + # + set node_id [site_node::get_node_id_from_object_id -object_id $_test_instance_package_id] + site_node::unmount -node_id $node_id + site_node::delete -node_id $node_id -delete_package + # + # Delete the test user + # + ::xo::dc list delete { + select acs_object__delete(object_id) + from acs_objects + where creation_user in (:_user_id) + } + acs::test::user::delete -user_id $_user_id + } + + aa_register_case -init_classes {tlf_survey_require_test_instance} -cats {web} -procs { + "::xowiki::Package instproc lookup" + } tlf_survey_items_exist { + Check if workflow items have been created in the test instance + } { + set user_id $_user_id + set user_info $_user_info + set instance $_test_instance_name + ::xo::Package initialize -url $instance/ + set question_item [::$package_id lookup -name en:Frage] + aa_true "question item is not 0" {$question_item != 0} + set folder_item [::$package_id lookup -name en:folder.form] + aa_true "folder item is not 0" {$folder_item != 0} + } + + aa_register_case \ + -init_classes {tlf_survey_require_test_instance} \ + -cats {web} \ + -procs { + "::xowiki::FormPage instproc get_all_children" + } tlf_survey_create_survey { + Create a new survey, check if default items have been created + Create a new survey instance, simulate interactions + Test csv export + } { + set user_id $_user_id + set user_info $_user_info + set instance $_test_instance_name + ::xo::Package initialize -url $instance/ + set request_info [acs::test::login $user_info] + # grant explicit read permission to the_public for the test_instance, + # so that ::xowiki::test::require_test_folder will not complain + permission::grant \ + -party_id [acs_magic_object "the_public"] \ + -object_id $package_id \ + -privilege "read" + # + # Create a new admin user and login + # + + aa_section "############# CREATING SURVEY #################" + set testsurvey [::xowiki::test::create_form_page \ + -user_id $user_id \ + -last_request $request_info \ + -instance $instance \ + -parent_id [$package_id set folder_id] \ + -form_name en:folder.form \ + -path "" \ + -update [subst { + _title "Test folder" + _name testsurvey + __action_submit "" + }]] + #submit action will create content + set testsurvey_item [dict get $testsurvey item_id] + aa_log "testsurvey_item $testsurvey_item" + set items [::xowiki::FormPage get_all_children \ + -folder_id $testsurvey_item \ + -publish_status "all"] + + aa_true "items in new survey exist:" {[llength [$items children]] >=3} + foreach i [$items children] { + aa_true "item has been created" {[$i name] in {en:start en:done en:wf-iterate en:f0 en:f1 en:f2}} + } + aa_section "### CREATE SURVEY INSTANCE ###" + set launched_survey [::xowiki::test::create_form_page \ + -user_id $user_id \ + -last_request $request_info \ + -instance $instance \ + -parent_id $testsurvey_item \ + -path testsurvey \ + -form_name "en:wf-iterate" \ + -update [subst { + _name en:___${user_id} + }]] + #creates a form page in initial states + set survey_instance [dict get $launched_survey item_id] + aa_log [$survey_instance instance_attributes] + aa_log [$survey_instance set state] + aa_section "### START SURVEY ###" + #start survey + ::xowiki::test::edit_form_page \ + -user_id $user_id \ + -last_request $request_info \ + -instance $instance \ + -path testsurvey/en:___${user_id} \ + -update { + __action_start + } + aa_section "### Move to next question ###" + #move to next question + ::xowiki::test::edit_form_page \ + -user_id $user_id \ + -last_request $request_info \ + -instance $instance \ + -path testsurvey/en:___${user_id} \ + -refetch=false \ + -update { + __action_next + } + aa_section "### Move to previous question ###" + #move to previous question + ::xowiki::test::edit_form_page \ + -user_id $user_id \ + -last_request $request_info \ + -instance $instance \ + -refetch=false \ + -path testsurvey/en:___${user_id} \ + -update { + __action_previous + } + aa_section "### csv export ###" + #export csv + set d [acs::test::http -user_info $user_info $instance/testsurvey/en:wf-iterate?m=csv-dump] + acs::test::reply_has_status_code $d 200 + } +} + +# +# Local variables: +# mode: tcl +# tcl-indent-level: 4 +# indent-tabs-mode: nil +# End: