Index: openacs-4/packages/dotlrn-static/tcl/test/dotlrn-static-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-static/tcl/test/Attic/dotlrn-static-test-procs.tcl,v diff -u -N -r1.1.2.1 -r1.1.2.2 --- openacs-4/packages/dotlrn-static/tcl/test/dotlrn-static-test-procs.tcl 10 Sep 2019 09:20:40 -0000 1.1.2.1 +++ openacs-4/packages/dotlrn-static/tcl/test/dotlrn-static-test-procs.tcl 7 Oct 2020 17:32:09 -0000 1.1.2.2 @@ -25,6 +25,106 @@ aa_equals "Applet key" "[dotlrn_static::applet_key]" "dotlrn_static" } +aa_register_case -procs { + dotlrn_static::add_applet + dotlrn_static::add_portlet + dotlrn_static::add_portlet_helper + dotlrn_static::remove_portlet + dotlrn_static::remove_applet + } -cats { + api + } dotlrn_static__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_static::applet_key]] ne ""} { + # + # Remove the applet in advance, if it already exists + # + dotlrn_static::remove_applet + aa_log "Removed existing applet" + } + # + # Create some content + # + set content "Just a test" + set content_pretty_name "foo" + set content_format "text/html" + set content_id [static_portal_content::new \ + -package_id 0 \ + -content $content \ + -pretty_name $content_pretty_name \ + -format $content_format] + set args [ns_set create] + ns_set put $args package_id 0 + ns_set put $args content_id $content_id + ns_set put $args template_id [portal::get_portal_template_id $portal_id] + # + # Add applet + # + dotlrn_static::add_applet + aa_true "Add applet" "[expr {[dotlrn_applet::get_applet_id_from_key -applet_key [dotlrn_static::applet_key]] ne ""}]" + # + # Add portlet to portal + # + # Set portal type first, as it is checked by 'add_portlet' + # + dotlrn::set_type_portal_id -type foo -portal_id $portal_id + set element_id [dotlrn_static::add_portlet $portal_id] + aa_equals "Number of portal elements after addition" "[portal_elements $portal_id]" "1" + # + # Remove portlet from portal + # + dotlrn_static::remove_portlet $portal_id $element_id $args + aa_equals "Number of portal elements after removal" "[portal_elements $portal_id]" "0" + # + # Add portlet to portal using directly the helper + # + dotlrn_static::add_portlet_helper $portal_id $args + aa_equals "Number of portal elements after addition" "[portal_elements $portal_id]" "1" + # + # Remove applet + # + dotlrn_static::remove_applet + aa_equals "Remove applet" "[dotlrn_applet::get_applet_id_from_key -applet_key [dotlrn_static::applet_key]]" "" + } else { + aa_error "Portal creation failed" + } + } +} + # Local variables: # mode: tcl # tcl-indent-level: 4