Index: openacs-4/packages/bm-portlet/tcl/test/bm-portlet-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/bm-portlet/tcl/test/Attic/bm-portlet-procs.tcl,v diff -u -N -r1.1.2.1 -r1.1.2.2 --- openacs-4/packages/bm-portlet/tcl/test/bm-portlet-procs.tcl 19 Aug 2020 16:57:51 -0000 1.1.2.1 +++ openacs-4/packages/bm-portlet/tcl/test/bm-portlet-procs.tcl 2 Oct 2020 16:50:14 -0000 1.1.2.2 @@ -17,6 +17,66 @@ aa_equals "BM portlet link" "[bm_portlet::link]" "" } +aa_register_case -procs { + bm_portlet::add_self_to_page + bm_portlet::remove_self_from_page + } -cats { + api + } bm_portlet_add_remove_from_page { + Test add/remove portlet procs. +} { + # + # Helper proc to check portal elements + # + proc portlet_exists_p {portal_id} { + set portlet_name [bm_portlet::get_my_name] + return [db_0or1row portlet_in_portal { + select 1 from dual where exists ( + select 1 + from portal_element_map pem, + portal_pages pp + where pp.portal_id = :portal_id + and pp.page_id = pem.page_id + and pem.name = :portlet_name + ) + }] + } + # + # Start the tests + # + aa_run_with_teardown -rollback -test_code { + # + # Create a community. + # + # As this is running in a transaction, it should be cleaned up + # automatically. + # + set community_id [dotlrn_community::new -community_type dotlrn_community -pretty_name foo] + if {$community_id ne ""} { + aa_log "Community created: $community_id" + set portal_id [dotlrn_community::get_admin_portal_id -community_id $community_id] + set package_id [dotlrn::instantiate_and_mount $community_id [bm_portlet::my_package_key]] + # + # Add portlet. + # + bm_portlet::add_self_to_page -portal_id $portal_id -package_id $package_id + aa_true "Portlet is in community portal after addition" "[portlet_exists_p $portal_id]" + # + # Remove portlet. + # + bm_portlet::remove_self_from_page -portal_id $portal_id -package_id $package_id + aa_false "Portlet is in community portal after removal" "[portlet_exists_p $portal_id]" + # + # Add portlet. + # + bm_portlet::add_self_to_page -portal_id $portal_id -package_id $package_id + aa_true "Portlet is in community portal after addition" "[portlet_exists_p $portal_id]" + } else { + aa_error "Community creation failed" + } + } +} + # Local variables: # mode: tcl # tcl-indent-level: 4