Index: openacs-4/packages/calendar-portlet/tcl/test/calendar-portlet-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/calendar-portlet/tcl/test/calendar-portlet-procs.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/packages/calendar-portlet/tcl/test/calendar-portlet-procs.tcl 22 May 2018 16:44:55 -0000 1.5 +++ openacs-4/packages/calendar-portlet/tcl/test/calendar-portlet-procs.tcl 3 Sep 2024 15:37:36 -0000 1.6 @@ -15,7 +15,7 @@ tclwebtest::cookies clear # Login user - array set user_info [twt::user::create -admin] + array set user_info [acs::test::user::create -admin] twt::user::login $user_info(email) $user_info(password) calendar_portlet::twt::go_to_dotlrn_calendar_page_url @@ -40,7 +40,7 @@ tclwebtest::cookies clear # Login user - array set user_info [twt::user::create -admin] + array set user_info [acs::test::user::create -admin] twt::user::login $user_info(email) $user_info(password) calendar_portlet::twt::go_to_dotlrn_calendar_page_url @@ -73,7 +73,7 @@ tclwebtest::cookies clear # Login user - array set user_info [twt::user::create -admin] + array set user_info [acs::test::user::create -admin] twt::user::login $user_info(email) $user_info(password) calendar_portlet::twt::go_to_dotlrn_calendar_page_url @@ -98,7 +98,7 @@ tclwebtest::cookies clear # Login user - array set user_info [twt::user::create -admin] + array set user_info [acs::test::user::create -admin] twt::user::login $user_info(email) $user_info(password) calendar_portlet::twt::go_to_dotlrn_calendar_page_url @@ -127,7 +127,7 @@ tclwebtest::cookies clear # Login user - array set user_info [twt::user::create -admin] + array set user_info [acs::test::user::create -admin] twt::user::login $user_info(email) $user_info(password) calendar_portlet::twt::go_to_dotlrn_calendar_page_url @@ -161,7 +161,7 @@ tclwebtest::cookies clear # Login user - array set user_info [twt::user::create -admin] + array set user_info [acs::test::user::create -admin] twt::user::login $user_info(email) $user_info(password) calendar_portlet::twt::go_to_dotlrn_calendar_page_url @@ -195,7 +195,7 @@ tclwebtest::cookies clear # Login user - array set user_info [twt::user::create -admin] + array set user_info [acs::test::user::create -admin] twt::user::login $user_info(email) $user_info(password) calendar_portlet::twt::go_to_dotlrn_calendar_page_url @@ -239,7 +239,7 @@ tclwebtest::cookies clear # Login user - array set user_info [twt::user::create -admin] + array set user_info [acs::test::user::create -admin] twt::user::login $user_info(email) $user_info(password) calendar_portlet::twt::go_to_dotlrn_calendar_page_url @@ -268,7 +268,7 @@ tclwebtest::cookies clear # Login user - array set user_info [twt::user::create -admin] + array set user_info [acs::test::user::create -admin] twt::user::login $user_info(email) $user_info(password) calendar_portlet::twt::go_to_dotlrn_calendar_page_url @@ -298,7 +298,7 @@ tclwebtest::cookies clear # Login user - array set user_info [twt::user::create -admin] + array set user_info [acs::test::user::create -admin] twt::user::login $user_info(email) $user_info(password) calendar_portlet::twt::go_to_dotlrn_calendar_page_url @@ -309,6 +309,339 @@ } } + +aa_register_case -procs { + calendar_full_portlet::link + calendar_admin_portlet::link + calendar_list_portlet::link + calendar_portlet::link + calendar_full_portlet::get_pretty_name + calendar_admin_portlet::get_pretty_name + calendar_list_portlet::get_pretty_name + calendar_portlet::get_pretty_name + } -cats { + api + production_safe + } calendar_portlet_links_names { + Test diverse link and name procs. +} { + set pretty_name [parameter::get_from_package_key \ + -package_key [calendar_portlet::my_package_key] \ + -parameter pretty_name] + set fp_pretty_name [parameter::get_from_package_key \ + -package_key [calendar_full_portlet::my_package_key] \ + -parameter full_portlet_pretty_name] + aa_equals "Calendar full portlet link" "[calendar_full_portlet::link]" "" + aa_equals "Calendar admin portlet link" "[calendar_admin_portlet::link]" "" + aa_equals "Calendar list portlet link" "[calendar_list_portlet::link]" "" + aa_equals "Calendar portlet link" "[calendar_portlet::link]" "" + aa_equals "Calendar full portlet pretty name" "[calendar_full_portlet::get_pretty_name]" "$fp_pretty_name" + aa_equals "Calendar admin portlet pretty name" "[calendar_admin_portlet::get_pretty_name]" "#calendar-portlet.admin_pretty_name#" + aa_equals "Calendar list portlet pretty name" "[calendar_list_portlet::get_pretty_name]" "\#calendar-portlet.Schedule\#" + aa_equals "Calendar portlet pretty name" "[calendar_portlet::get_pretty_name]" "$pretty_name" +} + +aa_register_case -procs { + calendar_portlet::add_self_to_page + calendar_portlet::remove_self_from_page + calendar_list_portlet::add_self_to_page + calendar_list_portlet::remove_self_from_page + calendar_full_portlet::add_self_to_page + calendar_full_portlet::remove_self_from_page + calendar_admin_portlet::add_self_to_page + calendar_admin_portlet::remove_self_from_page + } -cats { + api + } calendar_portlet_add_remove_from_page { + Test add/remove portlet procs. +} { + # + # Helper proc to check portal elements + # + proc portlet_exists_p {portal_id portlet_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] + set calendar_id [calendar::new -owner_id [ad_conn user_id] -calendar_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 [calendar_portlet::my_package_key]] + # + # calendar_portlet + # + set portlet_name [calendar_portlet::get_my_name] + # + # Add portlet. + # + calendar_portlet::add_self_to_page -portal_id $portal_id -calendar_id $calendar_id + aa_true "Portlet is in community portal after addition" "[portlet_exists_p $portal_id $portlet_name]" + # + # Remove portlet. + # + calendar_portlet::remove_self_from_page -portal_id $portal_id -calendar_id $calendar_id + aa_false "Portlet is in community portal after removal" "[portlet_exists_p $portal_id $portlet_name]" + # + # Add portlet. + # + calendar_portlet::add_self_to_page -portal_id $portal_id -calendar_id $calendar_id + aa_true "Portlet is in community portal after addition" "[portlet_exists_p $portal_id $portlet_name]" + # + # calendar_list_portlet + # + set portlet_name [calendar_list_portlet::get_my_name] + # + # Add portlet. + # + calendar_list_portlet::add_self_to_page -portal_id $portal_id -calendar_id $calendar_id + aa_true "List portlet is in community portal after addition" "[portlet_exists_p $portal_id $portlet_name]" + # + # Remove portlet. + # + calendar_list_portlet::remove_self_from_page $portal_id $calendar_id + aa_false "List portlet is in community portal after removal" "[portlet_exists_p $portal_id $portlet_name]" + # + # Add portlet. + # + calendar_list_portlet::add_self_to_page -portal_id $portal_id -calendar_id $calendar_id + aa_true "List portlet is in community portal after addition" "[portlet_exists_p $portal_id $portlet_name]" + # + # calendar_full_portlet + # + set portlet_name [calendar_full_portlet::get_my_name] + # + # Add portlet. + # + calendar_full_portlet::add_self_to_page -portal_id $portal_id -calendar_id $calendar_id + aa_true "Full portlet is in community portal after addition" "[portlet_exists_p $portal_id $portlet_name]" + # + # Remove portlet. + # + calendar_full_portlet::remove_self_from_page -portal_id $portal_id -calendar_id $calendar_id + aa_false "Full portlet is in community portal after removal" "[portlet_exists_p $portal_id $portlet_name]" + # + # Add portlet. + # + calendar_full_portlet::add_self_to_page -portal_id $portal_id -calendar_id $calendar_id + aa_true "Full portlet is in community portal after addition" "[portlet_exists_p $portal_id $portlet_name]" + # + # admin_portlet + # + set portlet_name [calendar_admin_portlet::get_my_name] + # + # Add portlet. + # + calendar_admin_portlet::add_self_to_page -portal_id $portal_id -calendar_id $calendar_id + aa_true "Admin portlet is in community portal after addition" "[portlet_exists_p $portal_id $portlet_name]" + # + # Remove portlet. + # + calendar_admin_portlet::remove_self_from_page $portal_id + aa_false "Admin portlet is in community portal after removal" "[portlet_exists_p $portal_id $portlet_name]" + # + # Add portlet. + # + calendar_admin_portlet::add_self_to_page -portal_id $portal_id -calendar_id $calendar_id + aa_true "Admin portlet is in community portal after addition" "[portlet_exists_p $portal_id $portlet_name]" + } else { + aa_error "Community creation failed" + } + } +} + +aa_register_case -procs { + calendar_admin_portlet::show + calendar_admin_portlet::get_my_name + calendar_full_portlet::show + calendar_full_portlet::get_my_name + calendar_list_portlet::show + calendar_list_portlet::get_my_name + calendar_portlet::show + calendar_portlet::get_my_name + calendar::new +} -cats { + api + smoke +} calendar_render_portlet { + Test the rendering of the portlets +} { + set orig_user_id [ad_conn user_id] + set user [acs::test::user::create] + set user_id [dict get $user user_id] + ad_conn -set user_id $user_id + + aa_run_with_teardown -rollback -test_code { + set package_id [site_node::instantiate_and_mount \ + -package_key calendar \ + -node_name __test_calendar_portlet] + + set calendar_id [calendar::new \ + -owner_id $user_id -private_p t \ + -calendar_name __test_portlet_calendar \ + -package_id $package_id] + + aa_section "Admin Portlet" + + foreach default_view {day list week month} { + set cf [list \ + calendar_id $calendar_id \ + default_view $default_view + ] + + set portlet [acs_sc::invoke \ + -contract portal_datasource \ + -operation Show \ + -impl [calendar_admin_portlet::get_my_name] \ + -call_args [list $cf]] + + aa_log "Portlet returns: [ns_quotehtml $portlet]" + + aa_false "View: $default_view - No error was returned" { + [string first "Error in include template" $portlet] >= 0 + } + + aa_false "View: $default_view - No unresolved message keys" { + [string first "MESSAGE KEY MISSING: " $portlet] >= 0 + } + + aa_true "View: $default_view - Portlet contains something" { + [string length [string trim $portlet]] > 0 + } + } + + foreach shaded_p {true false} { + set section_name "Standard Portlet" + if {$shaded_p} { + append section_name " (shaded)" + } + aa_section $section_name + + foreach default_view {day list week month} { + set cf [list \ + calendar_id $calendar_id \ + default_view $default_view \ + shaded_p $shaded_p + ] + + set portlet [acs_sc::invoke \ + -contract portal_datasource \ + -operation Show \ + -impl [calendar_portlet::get_my_name] \ + -call_args [list $cf]] + + aa_log "Portlet returns: [ns_quotehtml $portlet]" + + aa_false "View: $default_view - No error was returned" { + [string first "Error in include template" $portlet] >= 0 + } + + aa_false "View: $default_view - No unresolved message keys" { + [string first "MESSAGE KEY MISSING: " $portlet] >= 0 + } + + aa_true "View: $default_view - Portlet contains something" { + [string length [string trim $portlet]] > 0 + } + } + + set section_name "List Portlet" + if {$shaded_p} { + append section_name " (shaded)" + } + aa_section $section_name + + foreach default_view {day list week month} { + set cf [list \ + calendar_id $calendar_id \ + default_view $default_view \ + scoped_p false \ + shaded_p $shaded_p \ + ] + + set portlet [acs_sc::invoke \ + -contract portal_datasource \ + -operation Show \ + -impl [calendar_list_portlet::get_my_name] \ + -call_args [list $cf]] + + aa_log "Portlet returns: [ns_quotehtml $portlet]" + + aa_false "View: $default_view - No error was returned" { + [string first "Error in include template" $portlet] >= 0 + } + + aa_false "View: $default_view - No unresolved message keys" { + [string first "MESSAGE KEY MISSING: " $portlet] >= 0 + } + + aa_true "View: $default_view - Portlet contains something" { + [string length [string trim $portlet]] > 0 + } + } + + set section_name "Full Portlet" + if {$shaded_p} { + append section_name " (shaded)" + } + aa_section $section_name + + foreach default_view {day list week month} { + set cf [list \ + calendar_id $calendar_id \ + default_view $default_view \ + scoped_p false \ + shaded_p $shaded_p \ + ] + + set portlet [acs_sc::invoke \ + -contract portal_datasource \ + -operation Show \ + -impl [calendar_full_portlet::get_my_name] \ + -call_args [list $cf]] + + aa_log "Portlet returns: [ns_quotehtml $portlet]" + + aa_false "View: $default_view - No error was returned" { + [string first "Error in include template" $portlet] >= 0 + } + + aa_false "View: $default_view - No unresolved message keys" { + [string first "MESSAGE KEY MISSING: " $portlet] >= 0 + } + + aa_true "View: $default_view - Portlet contains something" { + [string length [string trim $portlet]] > 0 + } + } + + } + } -teardown_code { + ad_conn -set user_id $orig_user_id + if {[info exists user_id]} { + acs::test::user::delete -user_id $user_id + } + } +} + # Local variables: # mode: tcl # tcl-indent-level: 4