Index: openacs-4/packages/xowf/tcl/test/xowf-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowf/tcl/test/xowf-test-procs.tcl,v diff -u -r1.14 -r1.15 --- openacs-4/packages/xowf/tcl/test/xowf-test-procs.tcl 29 Jan 2019 11:49:52 -0000 1.14 +++ openacs-4/packages/xowf/tcl/test/xowf-test-procs.tcl 3 Sep 2024 15:37:54 -0000 1.15 @@ -1,30 +1,81 @@ namespace eval ::xowf::test { + # aa_register_init_class \ + # xowf_require_test_instance { + # Make sure the test instance is there and create it if necessary. + # } { + # aa_export_vars {_xowf_test_instance_name} + # set _xowf_test_instance_name /xowf-test + # ::acs::test::require_package_instance \ + # -package_key xowf \ + # -instance_name $_xowf_test_instance_name + # } { + # # Here one might unmount the package afterwards. Right now + # # we decide to keep it so it is possible to e.g. inspect + # # the results or test further in the mounted instance. + # } + aa_register_case -cats {web} -procs { + "::lang::system::locale" + "::xowiki::test::create_form_page" + "::xowiki::test::edit_form_page" + "::xowiki::test::require_test_folder" + + "::acs::test::dom_html" + "::acs::test::form_get_fields" + "::acs::test::form_reply" + "::acs::test::get_form" + "::acs::test::get_url_from_location" + "::acs::test::xpath::get_form" + "::acs::test::xpath::get_form_values" + "::ad_log" + "::ad_return_complaint" + "::ad_script_abort" + "::ad_urlencode_query" + "::xo::Context instproc invoke_object" + "::xo::Package instproc reply_to_user" + "::xo::PackageMgr instproc require" + "::xo::db::CrClass instproc get_instance_from_db" + "::xo::db::CrClass proc lookup" + "::xo::db::CrItem instproc is_package_root_folder" + "::xo::db::CrItem instproc set_live_revision" + "::xotcl::Class instproc instmixin" "::xowf::Package instproc initialize" + "::xowiki::BootstrapNavbar instproc render" + "::xowiki::BootstrapNavbarDropdownMenu instproc render" + "::xowiki::BootstrapNavbarDropdownMenuItem instproc render" + "::xowiki::BootstrapNavbarDropzone instproc render" + "::xowiki::FormPage instproc set_live_revision" + "::xowiki::Includelet proc html_encode" + "::xowiki::MenuItem instproc init" "::xowiki::Package instproc invoke" - "::xo::Package instproc reply_to_user" + "::xowiki::require_parameter_page" + } create_folder_with_page { - Create a folder in a xowf instance with a form page and edit this + Create a folder in an xowf instance with a form page and edit this } { - # - # Run the test under the current user_id. - # - set user_id [ad_conn user_id] - ns_log notice USER=$user_id + ::xowf::test::require_test_instance - set instance /xowf + set instance $_xowf_test_instance_name set testfolder .testfolder + set locale [lang::system::locale] + set lang [string range $locale 0 1] + # + # Setup of test user_id and login + # + set user_info [::acs::test::user::create -email xowf@acs-testing.test -admin] + set d [::acs::test::login $user_info] + try { ########################################################### aa_section "Make sure we have a fresh test folder" ############################################################ set folder_info [::xowiki::test::require_test_folder \ - -user_id $user_id \ + -last_request $d \ -instance $instance \ -folder_name $testfolder \ -fresh \ @@ -40,65 +91,127 @@ ########################################################### ::xowiki::test::create_form_page \ - -user_id $user_id \ + -last_request $d \ -instance $instance \ -path $testfolder \ -parent_id $folder_id \ -form_name page.form \ - -update { + -update [subst { _title "Sample page" _name hello _text "Hello world!" - } + _nls_language $locale + }] ########################################################### aa_section "Edit the form page." ########################################################### ::xowiki::test::edit_form_page \ - -user_id $user_id \ + -last_request $d \ -instance $instance \ -path $testfolder/hello \ - -update { + -update [subst { _title "Sample page 2" _text "Brave new world!" - } + _nls_language $locale + }] } on error {errorMsg} { aa_true "Error msg: $errorMsg" 0 } finally { - #calendar::delete -calendar_id $temp_calendar_id - + # + # In case something has to be cleaned manually, do it here. + # } } aa_register_case -cats {web} -procs { + "::lang::system::locale" + "::xowiki::test::create_form" + "::xowiki::test::create_form_page" + "::xowiki::test::edit_form_page" + "::xowiki::test::require_test_folder" + "::xowf::WorkflowPage instproc www-edit" + "::xowf::WorkflowPage instproc www-view" + + "::acs::test::form_get_fields" + "::acs::test::form_set_fields" + "::ad_log" + "::ad_return_complaint" + "::ad_script_abort" + "::export_vars" + "::security::csrf::validate" + "::xo::ConnectionContext instproc form_parameter" + "::xo::ConnectionContext instproc mobile" + "::xo::ConnectionContext instproc set_parameter" + "::xo::ConnectionContext instproc url" + "::xo::ConnectionContext instproc user_id" + "::xo::Context instproc invoke_object" + "::xo::Package instproc reply_to_user" + "::xo::Page proc requireCSS" + "::xo::db::CrClass proc get_instance_from_db" + "::xo::db::CrItem instproc is_package_root_folder" + "::xo::db::CrItem instproc set_live_revision" + "::xo::require_html_procs" + "::xotcl::Class instproc instmixin" + "::xowf::Context proc require" + "::xowf::Package instproc destroy" "::xowf::Package instproc initialize" + "::xowf::WorkflowPage instproc footer" + "::xowf::WorkflowPage instproc get_action_obj" + "::xowf::WorkflowPage instproc is_wf" + "::xowf::WorkflowPage instproc is_wf_instance" + "::xowf::WorkflowPage instproc post_process_dom_tree" + "::xowf::WorkflowPage instproc post_process_form_fields" + "::xowf::WorkflowPage instproc render_form_action_buttons" + "::xowf::WorkflowPage instproc render_form_action_buttons_widgets" + "::xowf::WorkflowPage instproc render_icon" + "::xowf::WorkflowPage instproc wf_context" + "::xowiki::BootstrapNavbar instproc render" + "::xowiki::BootstrapNavbarDropdownMenu instproc render" + "::xowiki::BootstrapNavbarDropdownMenuItem instproc render" + "::xowiki::BootstrapNavbarDropzone instproc render" + "::xowiki::FormPage instproc set_live_revision" + "::xowiki::FormPage instproc www-edit" + "::xowiki::Includelet proc html_encode" + "::xowiki::MenuItem instproc init" "::xowiki::Package instproc invoke" - "::xo::Package instproc reply_to_user" + "::xowiki::Package proc get_package_id_from_page_id" + "::xowiki::Package proc instantiate_page_from_id" + "::xowiki::autoname proc basename" + "::xowiki::autoname proc new" + "::xowiki::test::edit_form_page" + rp_internal_redirect } create_workflow_with_instance { - Create a xowf workflow and a instance in a folder. + Create an xowf workflow and a instance in a folder. + The procs list contains the public methods called via the web + interface. } { - # - # Run the test under the current user_id. - # - set user_id [ad_conn user_id] - ns_log notice USER=$user_id + ::xowf::test::require_test_instance - set instance /xowf + set instance $_xowf_test_instance_name set testfolder .testfolder + set locale [lang::system::locale] + set lang [string range $locale 0 1] + # + # Setup of test user_id and login + # + set user_info [::acs::test::user::create -email xowf@acs-testing.test -admin] + set d [::acs::test::login $user_info] + try { ########################################################### aa_section "Require test folder" ########################################################### set folder_info [::xowiki::test::require_test_folder \ - -user_id $user_id \ + -last_request $d \ -instance $instance \ -folder_name $testfolder \ -fresh \ @@ -111,7 +224,7 @@ set locale [lang::system::locale] set lang [string range $locale 0 1] ::xowiki::test::create_form \ - -user_id $user_id \ + -last_request $d \ -instance $instance \ -path $testfolder \ -parent_id $folder_id \ @@ -137,14 +250,15 @@ ########################################################### ::xowiki::test::create_form_page \ - -user_id $user_id \ + -last_request $d \ -instance $instance \ -path $testfolder \ -parent_id $folder_id \ -form_name Workflow.form \ - -update { + -update [subst -nocommands { _title "TIP Workflow" _name tip.wf + _nls_language $locale workflow_definition { # Actions are used here with the following parameters: # next_state: state after activation of action @@ -156,7 +270,7 @@ # Action save -roles admin Action propose -next_state proposed -proc activate {obj} { - :log "$obj is going to state [:next_state]" + :log "\$obj is going to state [:next_state]" } Action accept -next_state accepted Action reject -next_state rejected @@ -177,7 +291,7 @@ State implemented -actions {save} } form_constraints {@table:_name,wf_current_state,_creator,_last_modified} - } + }] aa_log "Workflow $lang:tip.wf created" @@ -187,17 +301,18 @@ ########################################################### ::xowiki::test::create_form_page \ - -user_id $user_id \ + -last_request $d \ -instance $instance \ -path $testfolder \ -parent_id $folder_id \ -form_name $lang:tip.wf \ - -update { + -update [subst { _title "TIP 1" _name tip1 _text {Should we create a tip?} __action_save "" - } + _nls_language $locale + }] aa_log "Workflow instance tip1 created" @@ -207,7 +322,7 @@ ########################################################### ::xowiki::test::edit_form_page \ - -user_id $user_id \ + -last_request $d \ -instance $instance \ -path $testfolder/tip1 \ -update { @@ -218,8 +333,9 @@ } on error {errorMsg} { aa_true "Error msg: $errorMsg" 0 } finally { - #calendar::delete -calendar_id $temp_calendar_id - + # + # In case something has to be cleaned manually, do it here. + # } } @@ -237,13 +353,18 @@ ::xowf::WorkflowConstruct instforward true set "" 1 ::xowf::WorkflowConstruct instforward false set "" 0 - ::xowf::WorkflowConstruct x + # + # Silence message "cannot determine wf_context from call-stack" + # + aa_silence_log_entries -severities warning { + ::xowf::WorkflowConstruct x + } aa_equals "non-conditional test with empty" [x get_value ""] "" - aa_equals "non-conditional test with non-empty scalar" [x get_value "a"] "a" + aa_equals "non-conditional test with nonempty scalar" [x get_value "a"] "a" - aa_equals "non-conditional test with non-empty list" [x get_value {a b}] "a b" - aa_equals "non-conditional test with non-empty list" [x get_value "a b"] "a b" + aa_equals "non-conditional test with nonempty list" [x get_value {a b}] "a b" + aa_equals "non-conditional test with nonempty list" [x get_value "a b"] "a b" aa_equals "conditional test, true branch" [x get_value "? true a default b"] "a" aa_equals "conditional test, false branch" [x get_value "? false a default b"] "b" @@ -252,6 +373,97 @@ aa_equals "conditional test, false branch list" [x get_value "? false {a b} default {b c}"] "b c" } + aa_register_case \ + -cats {api} \ + -procs { + "::xowf::Package proc create_new_workflow_page" + } create_new_workflow_page { + + Test ::xowf::Package create_new_workflow_page + + } { + ::xowf::test::require_test_instance + + aa_run_with_teardown -rollback -test_code { + set instance $_xowf_test_instance_name + set testfolder .testfolder + + set n [site_node::get_from_url -url $instance] + set package_id [dict get $n object_id] + + ::xowf::Package initialize -package_id $package_id + set parent_id [$package_id folder_id] + + set item_ref_info [$package_id item_ref \ + -use_site_wide_pages true \ + -default_lang en \ + -parent_id $parent_id \ + en:Workflow.form] + set page_template [dict get $item_ref_info item_id] + + set name testWF + set title testWFTitle + set wf [::xowf::Package create_new_workflow_page \ + -package_id $package_id \ + -parent_id $parent_id \ + -name $name \ + -title $title \ + -instance_attributes { + a b + c d + }] + $wf volatile + + aa_equals "$wf: name is correct" $name [$wf name] + aa_equals "$wf: title is correct" $title [$wf title] + aa_equals "$wf: property 'a' is correct" b [$wf property a] + aa_equals "$wf: property 'c' is correct" d [$wf property c] + + aa_false "$wf: package_id is not set on the fresh object" [$wf exists package_id] + + $wf set package_id $package_id + $wf save_new + + set item_id [$wf item_id] + set found_p [::xo::dc 0or1row check_wf { + select instance_attributes from + xowiki_form_instance_item_index i, + cr_revisions r, + xowiki_page_instance pi + where i.item_id = :item_id + and r.item_id = i.item_id + and r.revision_id = pi.page_instance_id + and i.package_id = :package_id + and i.page_template = :page_template + and i.name like '%' || name + and r.title = :title + }] + aa_true "Workflow was created in the database" $found_p + if {$found_p} { + aa_equals "Properties have been stored correctly" \ + [dict create {*}$instance_attributes] [dict create a b c d] + } + } + } + + # + # This test could be used to make sure binaries in use in the code are + # actually available to the system. + # + # aa_register_case -cats { + # smoke production_safe + # } -procs { + # util::which + # } xowf_exec_dependencies { + # Test external command dependencies for this package. + # } { + # foreach cmd [list \ + # [::util::which qrencode] \ + # ] { + # aa_true "'$cmd' is executable" [file executable $cmd] + # } + # } + } #