Index: openacs-4/packages/assessment/tcl/test/as-assessment-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/tcl/test/as-assessment-procs.tcl,v diff -u -r1.6.2.2 -r1.6.2.3 --- openacs-4/packages/assessment/tcl/test/as-assessment-procs.tcl 19 Feb 2021 13:53:44 -0000 1.6.2.2 +++ openacs-4/packages/assessment/tcl/test/as-assessment-procs.tcl 19 Feb 2021 14:19:24 -0000 1.6.2.3 @@ -1,9 +1,9 @@ # packages/assessment/tcl/test/as-assessment-procs.tcl ad_library { - + Tests for assessment procs - + @author Dave Bauer (dave@thedesignexperience.org) @creation-date 2006-08-03 @cvs-id $Id$ @@ -22,11 +22,9 @@ set package_id [site_node::instantiate_and_mount \ -node_name $node_name \ -package_key assessment] - } { # destructor - - if {[catch { + if {[catch { apm_package_instance_delete $package_id } errMsg]} { ns_log error "mount_assessment failed: $errMsg" @@ -49,10 +47,10 @@ } as_instantiate { Test package instantiate and uninstantiate. } { - # If this test fails, turn off rollback, so that you can + # If this test fails, turn off rollback, so that you can # view which objects are still lying around. aa_run_with_teardown -rollback -test_code { - + # mount the assessment package set title [ad_generate_random_string] set user_id [ad_conn user_id] @@ -66,18 +64,25 @@ aa_stub as::assessment::folder_id "return $folder_id" # create an assessment - set assessment_rev_id [as::assessment::new -title $title -package_id $package_id] - set assessment_id [content::revision::item_id -revision_id $assessment_rev_id] + set assessment_rev_id [as::assessment::new \ + -title $title \ + -package_id $package_id] + set assessment_id [content::revision::item_id \ + -revision_id $assessment_rev_id] # create a section - set section_id [as::section::new -title "$title" -package_id $package_id] + set section_id [as::section::new \ + -title "$title" \ + -package_id $package_id] as::section::add_to_assessment \ -assessment_rev_id $assessment_rev_id \ -section_id $section_id aa_log "section_id: $section_id" # create a question - set question_id [as::item_type_sa::new -title $title -package_id $package_id] + set question_id [as::item_type_sa::new \ + -title $title \ + -package_id $package_id] as::item_type_sa::add_to_assessment \ -assessment_id $assessment_id \ -section_id $section_id \ @@ -91,15 +96,18 @@ aa_true "assessment exists" {$assessment_data(assessment_id) > 0} # start a session - set session_id [as::session::new -assessment_id $assessment_rev_id -subject_id $user_id -package_id $package_id] + set session_id [as::session::new \ + -assessment_id $assessment_rev_id \ + -subject_id $user_id \ + -package_id $package_id] aa_true "session exists" {$session_id > 0} set section_list [as::assessment::sections -assessment_id $assessment_rev_id \ -session_id $session_id \ -sort_order_type $assessment_data(section_navigation) \ -random_p $assessment_data(random_p)] set section_id [lindex $section_list 0] - + as::section_data::new -section_id $section_id \ -session_id $session_id \ -subject_id $user_id \ @@ -115,189 +123,175 @@ } } - - - aa_register_case -cats { api } -procs { as::assessment::folder_id as::assessment::new as::assessment::data } as_assessment_new { Test of a new created assessment } { - aa_run_with_teardown \ - -rollback \ - -test_code { - - set folder_name [ns_mktemp as_folder_XXXXXX] - set folder_id [content::folder::new \ - -name $folder_name \ - -label $folder_name \ - -description $folder_name] - aa_true "Folder_id is not null '${folder_id}'" \ - {$folder_id ne ""} + aa_run_with_teardown \ + -rollback \ + -test_code { + + set folder_name [ns_mktemp as_folder_XXXXXX] + set folder_id [content::folder::new \ + -name $folder_name \ + -label $folder_name \ + -description $folder_name] + aa_true "Folder_id is not null '${folder_id}'" {$folder_id ne ""} content::folder::register_content_type \ -folder_id $folder_id \ -content_type as_assessments - aa_stub as::assessment::folder_id \ - [subst { - return $folder_id - }] - set title "JEff's Test Assessment New" - set assessment_id \ - [as::assessment::new \ - -title $title ] - aa_log "tfolder name = '${folder_name}'" - aa_log "tassessment_id = '${assessment_id}'" - - set assessment_id [ content::revision::item_id -revision_id $assessment_id ] - as::assessment::data -assessment_id $assessment_id - - aa_true "Item Created " { $title eq $assessment_data(title)} - aa_log " $assessment_data(title) " - - aa_true "Item Created " { $assessment_data(creator_name) ne ""} - aa_log " $assessment_data(creator_name) " - - } -} + aa_stub as::assessment::folder_id [subst { + return $folder_id + }] + set title "JEff's Test Assessment New" + set assessment_id [as::assessment::new -title $title ] + aa_log "tfolder name = '${folder_name}'" + aa_log "tassessment_id = '${assessment_id}'" + set assessment_id [content::revision::item_id \ + -revision_id $assessment_id] + as::assessment::data -assessment_id $assessment_id + aa_true "Item Created " { $title eq $assessment_data(title)} + aa_log " $assessment_data(title) " + + aa_true "Item Created " { $assessment_data(creator_name) ne ""} + aa_log " $assessment_data(creator_name) " + } +} + aa_register_case -cats { api } -procs { as::assessment::folder_id as::assessment::new as::assessment::edit } as_assessment_edit { Test of an Assessment Edit } { - aa_run_with_teardown \ - -rollback \ - -test_code { - - set folder_name [ns_mktemp as_folder_XXXXXX] - set folder_id [content::folder::new \ - -name $folder_name \ - -label $folder_name \ - -description $folder_name] - aa_true "Folder_id is not null '${folder_id}'" \ - {$folder_id ne ""} + aa_run_with_teardown \ + -rollback \ + -test_code { + + set folder_name [ns_mktemp as_folder_XXXXXX] + set folder_id [content::folder::new \ + -name $folder_name \ + -label $folder_name \ + -description $folder_name] + aa_true "Folder_id is not null '${folder_id}'" {$folder_id ne ""} content::folder::register_content_type \ -folder_id $folder_id \ -content_type as_assessments - aa_stub as::assessment::folder_id \ - [subst { - return $folder_id - }] - - set vartitle "Test Assessment Edit" - set newtitle "New Test Assessment Edit Title" - - set assessment_id \ - [as::assessment::new \ - -title $vartitle ] - - set assessment_id [ content::revision::item_id -revision_id $assessment_id ] - - set new_revision_id [ as::assessment::edit -assessment_id $assessment_id -title $newtitle ] - aa_true "New Title Created" [db_0or1row q "select title from cr_revisions where revision_id=:new_revision_id"] - aa_true "New Title Created - $title " {$title eq $newtitle} - aa_true "New Title Created - $title not equal to $vartitle" {$title ne $vartitle} - aa_log "new_revision_id - $new_revision_id" - - } - -} + aa_stub as::assessment::folder_id [subst { + return $folder_id + }] + set vartitle "Test Assessment Edit" + set newtitle "New Test Assessment Edit Title" + set assessment_id [as::assessment::new -title $vartitle ] + + set assessment_id [content::revision::item_id -revision_id $assessment_id ] + + set new_revision_id [as::assessment::edit \ + -assessment_id $assessment_id \ + -title $newtitle ] + aa_true "New Title Created" [db_0or1row q { + select title + from cr_revisions + where revision_id=:new_revision_id + }] + aa_true "New Title Created - $title " {$title eq $newtitle} + aa_true "New Title Created - $title not equal to $vartitle" {$title ne $vartitle} + aa_log "new_revision_id - $new_revision_id" + } +} + aa_register_case -cats { api } -procs { as::assessment::folder_id as::assessment::new as::assessment::copy } as_assessment_copy { Test of an assessment copy } { - aa_run_with_teardown \ - -rollback \ - -test_code { - - set folder_name [ns_mktemp as_folder_XXXXXX] - set folder_id [content::folder::new \ - -name $folder_name \ - -label $folder_name \ - -description $folder_name] - aa_true "Folder_id is not null '${folder_id}'" \ - {$folder_id ne ""} + aa_run_with_teardown \ + -rollback \ + -test_code { + + set folder_name [ns_mktemp as_folder_XXXXXX] + set folder_id [content::folder::new \ + -name $folder_name \ + -label $folder_name \ + -description $folder_name] + aa_true "Folder_id is not null '${folder_id}'" {$folder_id ne ""} content::folder::register_content_type \ -folder_id $folder_id \ -content_type as_assessments - aa_stub as::assessment::folder_id \ - [subst { - return $folder_id - }] - set vartitle "Test Assessment Copy" - set assessment_id \ - [as::assessment::new \ - -title $vartitle ] - - set assessment_id [ content::revision::item_id -revision_id $assessment_id ] - aa_log "assessment_id - $assessment_id" - - set new_assessment_id [ as::assessment::copy -assessment_id $assessment_id] - aa_true "New Assessment created" { $assessment_id ne $new_assessment_id } - aa_log "new_assessment_id - $new_assessment_id" - } -} + aa_stub as::assessment::folder_id [subst { + return $folder_id + }] + set vartitle "Test Assessment Copy" + set assessment_id [as::assessment::new -title $vartitle] + set assessment_id [content::revision::item_id \ + -revision_id $assessment_id] + aa_log "assessment_id - $assessment_id" + set new_assessment_id [as::assessment::copy \ + -assessment_id $assessment_id] + aa_true "New Assessment created" { $assessment_id ne $new_assessment_id } + aa_log "new_assessment_id - $new_assessment_id" + } +} + aa_register_case -cats { api } -procs { as::assessment::folder_id as::assessment::new as::assessment::new_revision } as_assessment_new_revisions { - Test of an assessment new revisions + Test of an assessment new revisions } { - aa_run_with_teardown \ - -rollback \ - -test_code { + aa_run_with_teardown \ + -rollback \ + -test_code { - set folder_name [ns_mktemp as_folder_XXXXXX] - set folder_id [content::folder::new \ - -name $folder_name \ - -label $folder_name \ - -description $folder_name] + set folder_name [ns_mktemp as_folder_XXXXXX] + set folder_id [content::folder::new \ + -name $folder_name \ + -label $folder_name \ + -description $folder_name] aa_true "Folder_id is not null '${folder_id}'" \ {$folder_id ne ""} content::folder::register_content_type \ -folder_id $folder_id \ -content_type as_assessments - aa_stub as::assessment::folder_id \ - [subst { - return $folder_id - }] - set vartitle "Test Assessment New Revisions" - set assessment_id \ - [as::assessment::new \ - -title $vartitle ] + aa_stub as::assessment::folder_id [subst { + return $folder_id + }] + set vartitle "Test Assessment New Revisions" + set assessment_id [as::assessment::new -title $vartitle ] - set assessment_id [ content::revision::item_id -revision_id $assessment_id ] - aa_log "assessment_id - $assessment_id" - #aa_log "revision_id - $assessment_revision_id" - - set new_revision_id [ as::assessment::new_revision -assessment_id $assessment_id] - aa_true "New Assessment created" { $assessment_id ne $new_revision_id } - aa_log "new_revision_id - $new_revision_id" - } + set assessment_id [content::revision::item_id \ + -revision_id $assessment_id] + aa_log "assessment_id - $assessment_id" + #aa_log "revision_id - $assessment_revision_id" + + set new_revision_id [ as::assessment::new_revision \ + -assessment_id $assessment_id] + aa_true "New Assessment created" { $assessment_id ne $new_revision_id } + aa_log "new_revision_id - $new_revision_id" + } } - aa_register_case -cats { api } -procs { as::assessment::pretty_time } as_assessment { Test for assessment proc } { foreach seconds {"" 0} { catch {as::assessment::pretty_time -seconds $seconds} pretty_time - aa_true "\"$seconds\" returns \"$seconds\"" [expr {$pretty_time eq $seconds}] + aa_true "\"$seconds\" returns \"$seconds\"" [expr {$pretty_time eq $seconds}] } } Index: openacs-4/packages/assessment/tcl/test/as-item-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/tcl/test/as-item-procs.tcl,v diff -u -r1.5.2.1 -r1.5.2.2 --- openacs-4/packages/assessment/tcl/test/as-item-procs.tcl 19 Feb 2021 13:53:44 -0000 1.5.2.1 +++ openacs-4/packages/assessment/tcl/test/as-item-procs.tcl 19 Feb 2021 14:19:24 -0000 1.5.2.2 @@ -1,9 +1,8 @@ # packages/assessment/tcl/test/as-item-procs.tcl - ad_library { - + Tests for as_items (questions) - + @author Dave Bauer (dave@thedesignexperience.org) @creation-date 2006-08-03 @cvs-id $Id$ @@ -20,71 +19,98 @@ } as_item_new { Create a new question } { - aa_run_with_teardown \ -rollback \ -test_code { - + set folder_name [ns_mktemp as_folder_XXXXXX] set folder_id [content::folder::new \ -name $folder_name \ -label $folder_name \ -description $folder_name] - aa_true "Folder_id is not null '${folder_id}'" \ - {$folder_id ne ""} + aa_true "Folder_id is not null '${folder_id}'" {$folder_id ne ""} content::folder::register_content_type \ -folder_id $folder_id \ -content_type as_items - aa_stub as::assessment::folder_id \ - [subst { - return $folder_id - }] + aa_stub as::assessment::folder_id [subst { + return $folder_id + }] aa_log "Testing long title (question text)" set long_text [string repeat X 8000] catch {as::item::new -title $long_text} as_item_rev_id if {[string is integer $as_item_rev_id]} { - aa_true "Item created" [db_0or1row q "select title,mime_type from cr_revisions where revision_id=:as_item_rev_id"] + aa_true "Item created" [db_0or1row q { + select title,mime_type + from cr_revisions + where revision_id=:as_item_rev_id + }] } else { aa_log "Item creation failed with $as_item_rev_id" } - set content [db_string q "select content from cr_revisions where revision_id=:as_item_rev_id"] + set content [db_string q { + select content + from cr_revisions + where revision_id=:as_item_rev_id + }] aa_true "Long title successfully entered" \ {[string range $long_text 0 999] eq $title} aa_true "Long question successfully entered" {$content eq $long_text} aa_true "Mime type is text/html" \ {$mime_type eq "text/html"} - - aa_log "Test item::edit" - set new_item_rev_id \ - [as::item::edit -as_item_id $as_item_rev_id -title $long_text] - aa_true "Item created" [db_0or1row q "select title,mime_type from cr_revisions where revision_id=:new_item_rev_id"] - set content [db_string q "select content from cr_revisions where revision_id=:new_item_rev_id"] + aa_log "Test item::edit" + set new_item_rev_id \ + [as::item::edit -as_item_id $as_item_rev_id -title $long_text] + aa_true "Item created" [db_0or1row q { + select title,mime_type + from cr_revisions + where revision_id=:new_item_rev_id + }] + set content [db_string q { + select content + from cr_revisions + where revision_id=:new_item_rev_id + }] aa_true "Long title successfully entered" \ {[string range $long_text 0 999] eq $title} aa_true "Long question successfully entered" {$content eq $long_text} - aa_log "Test item::new_revision" - set new_rev_rev_id [as::item::new_revision -as_item_id $new_item_rev_id] - aa_true "Item created" [db_0or1row q "select title,mime_type from cr_revisions where revision_id=:new_rev_rev_id"] - set content [db_string q "select content from cr_revisions where revision_id=:new_rev_rev_id"] + aa_log "Test item::new_revision" + set new_rev_rev_id [as::item::new_revision -as_item_id $new_item_rev_id] + aa_true "Item created" [db_0or1row q { + select title,mime_type + from cr_revisions + where revision_id=:new_rev_rev_id + }] + set content [db_string q { + select content + from cr_revisions + where revision_id=:new_rev_rev_id + }] aa_true "Long title successfully entered" \ {[string range $long_text 0 999] eq $title} aa_true "Long question successfully entered" {$content eq $long_text} - aa_log "Test item::copy" - set copy_rev_id [as::item::copy \ - -as_item_id $new_item_rev_id \ - -title $long_text] - aa_true "Item created" [db_0or1row q "select title,mime_type from cr_revisions where revision_id=:copy_rev_id"] - set content [db_string q "select content from cr_revisions where revision_id=:copy_rev_id"] + aa_log "Test item::copy" + set copy_rev_id [as::item::copy \ + -as_item_id $new_item_rev_id \ + -title $long_text] + aa_true "Item created" [db_0or1row q { + select title,mime_type + from cr_revisions + where revision_id=:copy_rev_id + }] + set content [db_string q { + select content + from cr_revisions + where revision_id=:copy_rev_id + }] aa_true "Long title successfully entered" \ {[string range $long_text 0 999] eq $title} aa_true "Long question successfully entered" {$content eq $long_text} - - } + } } - + # Local variables: # mode: tcl # tcl-indent-level: 4