Index: openacs-4/packages/acs-automated-testing/tcl/aa-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-automated-testing/tcl/aa-test-procs.tcl,v diff -u -r1.79.2.8 -r1.79.2.9 --- openacs-4/packages/acs-automated-testing/tcl/aa-test-procs.tcl 9 Apr 2019 14:30:49 -0000 1.79.2.8 +++ openacs-4/packages/acs-automated-testing/tcl/aa-test-procs.tcl 16 Apr 2019 09:27:24 -0000 1.79.2.9 @@ -1115,6 +1115,58 @@ namespace eval acs::test { + ad_proc -public ::acs::test::require_package_instance { + -package_key:required + {-instance_name ""} + {-empty:boolean} + } { + Returns a test instance of specified package_key mounted under + specified name. Will create it if it is not found. It is + currently assumed the instance will be mounted under the main + subsite. + + @param package_key package to be instantiated + @param instance name name of the site-node this instance will + be mounted to. Will default to -test + @param empty require an empty instance. If an existing + instance is found, it will be deleted. If a package + different than is found, it won't be + deleted and the proc will return an error + + @return a package_id + } { + set main_node_id [site_node::get_element \ + -url / -element node_id] + + set instance_name [expr {$instance_name eq "" ? + "${package_key}-test" : [string trim $instance_name /]}] + + set package_exists_p [::xo::dc 0or1row lookup_test_package { + select node_id, object_id as package_id + from site_nodes + where parent_id = :main_node_id + and name = :instance_name + }] + + if {$package_exists_p} { + set existing_package_key [apm_package_key_from_id $package_id] + if {$existing_package_key ne $package_key} { + error "An instance of '$existing_package_key' is already mounted at '$instance_name'" + } elseif {$empty_p} { + site_node::delete -node_id $node_id -delete_package + } + } + + if {!$package_exists_p || $empty_p} { + set package_id [site_node::instantiate_and_mount \ + -package_name $instance_name \ + -node_name $instance_name \ + -package_key $package_key] + } + + return $package_id + } + ad_proc -public ::acs::test::form_reply { {-user_id 0} {-last_request ""}