Index: openacs-4/packages/dotlrn-chat/tcl/test/dotlrn-chat-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-chat/tcl/test/dotlrn-chat-test-procs.tcl,v diff -u -r1.1.2.2 -r1.1.2.3 --- openacs-4/packages/dotlrn-chat/tcl/test/dotlrn-chat-test-procs.tcl 24 Aug 2020 09:41:14 -0000 1.1.2.2 +++ openacs-4/packages/dotlrn-chat/tcl/test/dotlrn-chat-test-procs.tcl 31 Aug 2020 17:14:16 -0000 1.1.2.3 @@ -37,6 +37,90 @@ aa_equals "Pretty name" "[dotlrn_chat::get_pretty_name]" "[_ dotlrn-chat.pretty_name]" } +aa_register_case -procs { + dotlrn_chat::add_applet + dotlrn_chat::add_portlet + dotlrn_chat::add_portlet_helper + dotlrn_chat::remove_portlet + dotlrn_chat::remove_applet + } -cats { + api + } dotlrn_chat__applet_portlet { + Test add/remove applet/portlet procs. +} { + # + # Helper proc to check portal elements + # + proc portal_elements {portal_id} { + return [db_string elements { + select count(1) + from portal_element_map pem, + portal_pages pp + where pp.portal_id = :portal_id + and pp.page_id = pem.page_id + }] + } + # + # Start the tests + # + aa_run_with_teardown -rollback -test_code { + # + # Create test user + # + # As this is running in a transaction, it should be cleaned up + # automatically. + # + set portal_user_id [db_nextval acs_object_id_seq] + set user_info [acs::test::user::create -user_id $portal_user_id] + # + # Create portal + # + set portal_id [portal::create $portal_user_id] + set portal_exists_p [db_0or1row foo { + select * from portals where portal_id=:portal_id + }] + if {$portal_exists_p} { + aa_log "Portal created (portal_id: $portal_id)" + if {[dotlrn_applet::get_applet_id_from_key -applet_key [dotlrn_chat::applet_key]] ne ""} { + # + # Remove the applet in advance, if it already exists + # + dotlrn_chat::remove_applet + aa_log "Removed existing applet" + } + # + # Add applet + # + dotlrn_chat::add_applet + aa_true "Add applet" "[expr {[dotlrn_applet::get_applet_id_from_key -applet_key [dotlrn_chat::applet_key]] ne ""}]" + # + # Add portlet to portal + # + dotlrn_chat::add_portlet $portal_id + aa_equals "Number of portal elements after addition" "[portal_elements $portal_id]" "1" + # + # Remove portlet from portal + # + set args [ns_set create] + ns_set put $args package_id 0 + dotlrn_chat::remove_portlet $portal_id $args + aa_equals "Number of portal elements after removal" "[portal_elements $portal_id]" "0" + # + # Add portlet to portal using directly the helper + # + dotlrn_chat::add_portlet_helper $portal_id $args + aa_equals "Number of portal elements after addition" "[portal_elements $portal_id]" "1" + # + # Remove applet + # + dotlrn_chat::remove_applet + aa_equals "Remove applet" "[dotlrn_applet::get_applet_id_from_key -applet_key [dotlrn_chat::applet_key]]" "" + } else { + aa_error "Portal creation failed" + } + } +} + # Local variables: # mode: tcl # tcl-indent-level: 4