Index: openacs-4/packages/forums/tcl/test/forums-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/tcl/test/forums-procs.tcl,v diff -u -r1.11 -r1.12 --- openacs-4/packages/forums/tcl/test/forums-procs.tcl 24 Jul 2018 17:19:58 -0000 1.11 +++ openacs-4/packages/forums/tcl/test/forums-procs.tcl 3 Sep 2024 15:37:38 -0000 1.12 @@ -10,7 +10,13 @@ aa_register_case \ -cats {api smoke} \ - -procs {forum::new} \ + -procs { + forum::new + callback::forum::forum_new::contract + forum::flush_templating_cache + forum::list_forums + forum::valid_forum_id_p + } \ forum_new { Test the forum::new proc. } { @@ -20,17 +26,51 @@ -test_code { set package_id [subsite::main_site_id] + set no_package_id [db_string get_not_package_id { + select min(package_id) - 1 from apm_packages + }] - # Create forum - set forum_id [forum::new \ - -name "foo" \ - -package_id $package_id] + # Create a couple of forums + set forums [list] + lappend forums \ + [list [forum::new \ + -name "foo" \ + -package_id $package_id] "foo"] + lappend forums \ + [list [forum::new \ + -name "bar" \ + -package_id $package_id] "bar"] - set success_p [db_string success_p { - select 1 from forums_forums where forum_id = :forum_id - } -default "0"] + aa_equals "No forums retrieved for an invalid package" \ + [forum::list_forums -package_id $no_package_id] "" - aa_equals "forum was created successfully" $success_p 1 + set api_forums [list] + foreach s [forum::list_forums -package_id $package_id] { + aa_equals "Set has the expected keys" \ + [lsort [ns_set keys $s]] {forum_id name posting_policy presentation_type} + + set forum_id [ns_set get $s forum_id] + lappend api_forums \ + [list $forum_id [ns_set get $s name]] + + aa_true "Forum id '$forum_id' is valid (without package)" \ + [forum::valid_forum_id_p \ + -forum_id $forum_id] + + aa_true "Forum id '$forum_id' is valid (with package)" \ + [forum::valid_forum_id_p \ + -forum_id $forum_id \ + -package_id $package_id] + + aa_false "Forum id '$forum_id' is not valid (wrong package)" \ + [forum::valid_forum_id_p \ + -forum_id $forum_id \ + -package_id $no_package_id] + } + + aa_equals "Api retrieves the expected forums" \ + [lsort -index 0 $forums] [lsort -index 0 $api_forums] + } } @@ -39,6 +79,16 @@ -procs { forum::message::new forum::new + forum::message::do_notifications + forum::message::get + forum::attachments_enabled_p + forum::message::notify_users + forum::message::notify_moderators + forum::message::approve + forum::message::reject + forum::message::open + forum::message::close + forum::message::set_format } \ forum_message_new { Test the forum::message::new proc. @@ -48,24 +98,113 @@ -rollback \ -test_code { - set package_id [subsite::main_site_id] + set main_site [site_node::get -url "/test"] + set package_id [dict get $main_site object_id] + aa_log "Require the attachments package" + if {![site_node_apm_integration::child_package_exists_p \ + -package_id $package_id \ + -package_key attachments]} { + site_node::instantiate_and_mount \ + -package_key attachments \ + -parent_node_id [dict get $main_site node_id] + } + # Create forum set forum_id [forum::new \ -name "foo" \ + -posting_policy "moderated" \ + -attachments_allowed_p false \ -package_id $package_id] + aa_false "Attachments are disabled" \ + [forum::attachments_enabled_p -forum_id $forum_id] + + aa_log "Enable attachments on the forum" + forum::edit -forum_id $forum_id -attachments_allowed_p true + + aa_true "Attachments are enabled" \ + [forum::attachments_enabled_p -forum_id $forum_id] + # Create message set message_id [forum::message::new \ -forum_id $forum_id \ -subject "foo" \ -content "foo"] - set success_p [db_string success_p { - select 1 from forums_messages where message_id = :message_id - } -default "0"] + set child_message_id [forum::message::new \ + -forum_id $forum_id \ + -parent_id $message_id \ + -format text/plain \ + -subject "bar" \ + -content "bar"] - aa_equals "message was created successfully" $success_p 1 + aa_equals "There are no attachments on message '$message_id'" \ + [llength [attachments::get_attachments -object_id $message_id]] 0 + set attachments [db_list any_objects { + select object_id from acs_objects + where object_id not in (:message_id, :child_message_id, :forum_id, :package_id) + order by object_id desc + fetch first 3 rows only + }] + foreach attachment_id $attachments { + attachments::attach \ + -object_id $message_id \ + -attachment_id $attachment_id \ + -approved_p true + } + aa_equals "There are now 3 attachments on message '$message_id'" \ + [llength [attachments::get_attachments -object_id $message_id]] 3 + + forum::message::get -message_id $message_id -array m + aa_equals "Message '$message_id' is waiting for approval" \ + $m(state) "pending" + + forum::message::get -message_id $child_message_id -array cm + aa_equals "Message '$child_message_id' is waiting for approval" \ + $cm(state) "pending" + aa_equals "Message '$child_message_id' is child of '$message_id'" \ + $cm(parent_id) $message_id + aa_equals "Message '$child_message_id' is in format 'text/plain'" \ + $cm(format) text/plain + + aa_log "Change the format of message '$child_message_id'" + forum::message::set_format -message_id $child_message_id -format text/html + forum::message::get -message_id $child_message_id -array cm + aa_equals "Message '$child_message_id' is now in format 'text/html'" \ + $cm(format) text/html + + aa_log "Reject message '$message_id'" + forum::message::reject -message_id $message_id + forum::message::get -message_id $message_id -array m + aa_equals "Message '$message_id' is rejected" \ + $m(state) "rejected" + forum::message::get -message_id $child_message_id -array cm + aa_equals "Message '$child_message_id' is still waiting for approval" \ + $cm(state) "pending" + + aa_log "Approve message '$message_id'" + forum::message::approve -message_id $message_id + forum::message::get -message_id $message_id -array m + aa_equals "Message '$message_id' is approved" \ + $m(state) "approved" + forum::message::get -message_id $child_message_id -array cm + aa_equals "Message '$child_message_id' is still waiting for approval" \ + $cm(state) "pending" + + aa_log "Close message '$message_id' (meant as subthread)" + forum::message::close -message_id $message_id + forum::message::get -message_id $message_id -array m + aa_false "Message '$message_id' is closed" $m(open_p) + forum::message::get -message_id $child_message_id -array cm + aa_false "Message '$child_message_id' is also closed" $cm(open_p) + + aa_log "Open message '$message_id' (meant as subthread)" + forum::message::open -message_id $message_id + forum::message::get -message_id $message_id -array m + aa_true "Message '$message_id' is open" $m(open_p) + forum::message::get -message_id $child_message_id -array cm + aa_true "Message '$child_message_id' is also open" $cm(open_p) } } @@ -75,7 +214,12 @@ forum::get forum::message::delete forum::message::get + forum::flush_cache + forum::flush_namespaced_cache forum::message::new + forum::message::do_notifications + forum::message::notify_moderators + forum::message::notify_users forum::message::set_state forum::new } \ @@ -175,7 +319,16 @@ aa_register_case \ -cats {api web smoke} \ - -procs {forum::new forum::delete} \ + -procs { + forum::new + forum::delete + + aa_get_first_url + acs_community_member_admin_url + ds_adp_start_box + ds_adp_end_box + forums::form::forum + } \ -urls { /admin/forum-new } web_forum_new { @@ -195,7 +348,8 @@ # Create a new forum # set name [ad_generate_random_string] - set forum_id [forums::test::new -user_id $user_id $name] + set d [forums::test::new -user_info $user_info $name] + set forum_id [dict get $d payload forum_id] } -teardown_code { @@ -212,8 +366,17 @@ } aa_register_case \ - -cats {api web smoke} \ - -procs {forum::new forum::get forum::delete} \ + -cats {web smoke} \ + -procs { + aa_get_first_url + acs_community_member_admin_url + ad_context_node_list + forum::delete + forum::get + forum::new + forums::form::forum + forums::form::search + } \ -urls { /admin/forum-new /forum-view @@ -233,20 +396,21 @@ # Create a new forum # set name [ad_generate_random_string] - set forum_id [forums::test::new -user_id $user_id $name] + set d [forums::test::new -user_info $user_info $name] + set forum_id [dict get $d payload forum_id] aa_log "Created forum with id $forum_id" # # View a forum via name. # set response [forums::test::view \ - -user_id $user_id \ + -last_request $d \ -name $name ] # # View a forum via forum_id. # set response [forums::test::view \ - -user_id $user_id \ + -last_request $d \ -forum_id $forum_id ] } -teardown_code { @@ -263,7 +427,19 @@ aa_register_case \ -cats {web smoke} \ - -procs {forum::new forum::get forum::edit forum::delete} \ + -procs { + aa_get_first_url + acs_community_member_admin_url + ad_context_node_list + ds_adp_end_box + ds_adp_start_box + forum::delete + forum::edit + forum::get + forum::new + forums::form::forum + forums::form::search + } \ -urls { /admin/forum-new /admin/forum-edit @@ -283,13 +459,14 @@ # Create a new forum # set name [ad_generate_random_string] - set forum_id [forums::test::new -user_id $user_id $name] + set d [forums::test::new -user_info $user_info $name] + set forum_id [dict get $d payload forum_id] # # Edit the meta info of the created forum # set response [forums::test::edit \ - -user_id $user_id \ + -last_request $d \ -forum_id $forum_id ] } -teardown_code { @@ -314,6 +491,24 @@ forum::message::set_state forum::new forum::security::require_post_forum + + aa_get_first_url + acs_community_member_admin_url + ad_context_node_list + ds_adp_start_box + ds_adp_end_box + ad_form + forum::format::emoticons + forum::security::can_post_forum_p + forum::security::permissions + forum::security::require_moderate_forum + forum::security::require_read_forum + forum::security::require_post_forum + forum::use_ReadingInfo_p + forum::valid_forum_id_p + forums::form::forum + forums::form::message + forums::form::search } \ -urls { /message-post @@ -345,11 +540,12 @@ # Create a new forum # set name [ad_generate_random_string] - set forum_id [forums::test::new -user_id $user_id $name] + set d [forums::test::new -user_info $user_info $name] + set forum_id [dict get $d payload forum_id] # Post a message in the created forum set message_id [forums::test::new_postings \ - -user_id $user_id \ + -last_request $d \ -forum_id $forum_id ] @@ -364,6 +560,55 @@ } } +aa_register_case -cats { + api +} -procs { + forum::new + forum::enable + forum::disable +} forum_enable_disable { + Test forum enabling and disabling. +} { + # + # Helper proc to check if the forum is enabled + # + proc forum_enabled_p {forum_id} { + return [db_string enabled_p { + select enabled_p + from forums_forums + where forum_id = :forum_id + } -default "0"] + } + # + # Start the tests + # + aa_run_with_teardown -rollback -test_code { + # + # Create forum + # + set package_id [subsite::main_site_id] + set forum_id [forum::new \ + -name "foo" \ + -package_id $package_id] + # + # Enable forum if it is disabled + # + if {![forum_enabled_p $forum_id]} { + forum::enable -forum_id $forum_id + } + aa_true "Forum $forum_id is enabled" [forum_enabled_p $forum_id] + # + # Disable + # + forum::disable -forum_id $forum_id + aa_false "Forum $forum_id is enabled" [forum_enabled_p $forum_id] + # + # Enable again + # + forum::enable -forum_id $forum_id + aa_true "Forum $forum_id is enabled" [forum_enabled_p $forum_id] + } +} # Local variables: # mode: tcl