Index: openacs-4/packages/acs-automated-testing/tcl/test/example-test-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-automated-testing/tcl/test/Attic/example-test-init.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-automated-testing/tcl/test/example-test-init.tcl 4 Apr 2003 09:46:47 -0000 1.1 @@ -0,0 +1,142 @@ +############################################################################## +# +# Copyright 2001, OpenMSG Ltd, Peter Harper. +# +# This file is part of acs-automated-testing. +# +############################################################################## + +aa_register_init_class "my_init" { + An example chunk of initialisation code. +} { + # Constructor + aa_export_vars {my_var1 my_var2} + + set my_var1 "Variable 1" + set my_var2 "Variable 2" + aa_equals "Do a dummy test on my_var1" $my_var1 "Variable 1" + aa_log "Do a test log message" +} { + # Descructor + # aa_log, aa_equals, aa_true and aa_false all ignored here. + set _my_var1 $my_var1 + set _my_var2 $my_var2 + aa_log "Do a log message that should be ignored" +} + + +aa_register_init_class "my_init2" { + An second example chunk of initialisation code. +} { + # Constructor + aa_log "The second constructor" +} { + # Descructor + aa_log "The second destructor" +} + + +aa_register_component "my_component" { + An example chunk of component code. +} { + aa_export_vars {an_example_value} + set an_example_value 1000 + aa_log "Log message from the example component my_component" +} + +aa_register_case -cats { + script +} -init_classes { + my_init +} "aa_example-000" { + Tests successful audit writing. +} { + aa_call_component "my_component" +} { + set test_value 1056 + + aa_stub aa_example_write_audit_entry { + switch $sequence_id { + 1 { + aa_equals "aa_example_write_audit_entry" $name "name1" + aa_equals "aa_example_write_audit_entry" $value "value1" + return 1 + } + 2 { + aa_equals "aa_example_write_audit_entry" $name "name2" + aa_equals "aa_example_write_audit_entry" $value "value2" + return 1 + } + } + } + + set entries {{"name1" "value1"} {"name2" "value2"}} + set entries_ex $entries + + set result [aa_example_write_audit_entries $entries] + + aa_log "This is a test log message" + aa_true "return value true" $result + aa_equals "entries parameter not currupted" $entries $entries_ex +} { + aa_equals "Check that test_value is visible here" $test_value "1056" + aa_equals "Check that my_component set value is visible here" $an_example_value "1000" +} + +aa_register_case -cats { + script +} -init_classes { + my_init my_init2 +} "aa-example-001" { + Tests un-successful audit writing. + First call succeeds, second fails +} { + aa_stub aa_example_write_audit_entry { + switch $sequence_id { + 1 { + aa_equals "aa_example_write_audit_entry, name" $name "name1" + aa_equals "aa_example_write_audit_entry, value" $value "value1" + return 1 + } + 2 { + aa_equals "aa_example_write_audit_entry, name" $name "name2" + aa_equals "aa_example_write_audit_entry, value" $value "value2" + return 0 + } + } + } + + set entries {{"name1" "value1"} {"name2" "value2"}} + set entries_ex $entries + + set result [aa_example_write_audit_entries $entries] + + aa_false "return value false" $result + aa_equals "entries parameter not currupted" $entries $entries_ex +} + +aa_register_case -cats { + script +} "aa_example-002" { + Tests un-successful audit writing. + First call fails. +} { + aa_stub aa_example_write_audit_entry { + switch $sequence_id { + 1 { + aa_equals "aa_example_write_audit_entry, name" $name "name1" + aa_equals "aa_example_write_audit_entry, value" $value "value1" + return 0 + } + } + } + + set entries {{"name1" "value1"} {"name2" "value2"}} + set entries_ex $entries + + set result [aa_example_write_audit_entries $entries] + + aa_false "return value false" $result + aa_equals "entries parameter not currupted" $entries $entries_ex +} + Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-automated-testing/tcl/test/example-test-procs.tcl'. Fisheye: No comparison available. Pass `N' to diff? Index: openacs-4/packages/acs-datetime/tcl/test/acs-calendar-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-datetime/tcl/test/Attic/acs-calendar-init.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-datetime/tcl/test/acs-calendar-init.tcl 4 Apr 2003 09:47:16 -0000 1.1 @@ -0,0 +1,14 @@ +aa_register_case dt_get_days_of_week { +} { + set old_locale [ad_conn locale] + + ad_conn -set locale en_US + aa_true "1-letter weekdays in en_US: [dt_get_days_of_week]" [string equal [dt_get_days_of_week] "S M T W T F S"] + aa_true "3-letter weekdays in en_US: [dt_get_days_of_week -weekday_format ab]" [string equal [dt_get_days_of_week -weekday_format ab] "Sun Mon Tue Wed Thu Fri Sat"] + aa_true "Long weekdays in en_US: [dt_get_days_of_week -weekday_format long]" [string equal [dt_get_days_of_week -weekday_format long] "Sunday Monday Tuesday Wednesday Thursday Friday Saturday"] + + ad_conn -set locale da_DK + aa_true "1-letter weekdays in da_DK: [dt_get_days_of_week]" [string equal [dt_get_days_of_week] "M T O T F L S"] + + ad_conn -set locale $old_locale +} Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/acs-datetime/tcl/test/acs-calendar-procs.tcl'. Fisheye: No comparison available. Pass `N' to diff? Index: openacs-4/packages/acs-lang/tcl/test/acs-lang-test-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/test/Attic/acs-lang-test-init.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-lang/tcl/test/acs-lang-test-init.tcl 4 Apr 2003 09:47:43 -0000 1.1 @@ -0,0 +1,208 @@ +ad_library { + acs-automated-testing test definitions to be sourced on server startup. + + @author Peter Marklund (peter@collaboraid.biz) + @creation-date 18 October 2002 +} + +aa_register_case util__replace_temporary_tags_with_lookups { + Primarily tests lang::util::replace_temporary_tags_with_lookups, + Also tests the procs lang::catalog::export_messages_to_file, lang::catalog::parse, + lang::catalog::read_file, and lang::util::get_temporary_tags_indices. + + A test tcl file and catalog file are created. The temporary tags in the + tcl file are replaced with message lookups and keys and messages are appended + to the catalog file. + + @author Peter Marklund (peter@collaboraid.biz) + @creation-date 18 October 2002 +} { + # The files involved in the test + set test_dir [lang::test::get_dir] + set catalog_file "${test_dir}/acs-lang.en_US.ISO-8859-1.xml" + set backup_file_suffix ".orig" + set catalog_backup_file "${catalog_file}${backup_file_suffix}" + regexp {^.*(packages/.*)$} $test_dir match test_dir_rel + set tcl_file "${test_dir_rel}/test-message-tags.tcl" + set tcl_backup_file "${tcl_file}${backup_file_suffix}" + + # The test messages to use for the catalog file + array set messages_array [list key_1 text_1 key_2 text_2 key_3 text_3] + + # Write the test tcl file + set tcl_file_id [open "[acs_root_dir]/$tcl_file" w] + set new_key_1 "_" + set new_text_1 "Auto Key" + set new_key_2 "key_1" + set new_text_2 "text_1_different" + set new_key_3 "key_1" + set new_text_3 "$messages_array(key_1)" + puts $tcl_file_id "# The following key should be auto-generated and inserted + # <#${new_key_1} ${new_text_1}#> + # + # The following key should be made unique and inserted + # <#${new_key_2} ${new_text_2}#> + # + # The following key should not be inserted in the message catalog + # <#${new_key_3} ${new_text_3}#>" + close $tcl_file_id + + # Write the catalog file + lang::catalog::export_messages_to_file $catalog_file [array get messages_array] + + # Replace message tags in the tcl file and insert into catalog file + lang::util::replace_temporary_tags_with_lookups -catalog_file_path $catalog_file $tcl_file + + # Read the contents of the catalog file + array set catalog_array [lang::catalog::parse [lang::catalog::read_file $catalog_file]] + array set updated_messages_array [lindex [array get catalog_array messages] 1] + + # Assert that the old messages are unchanged + foreach old_message_key [array names messages_array] { + aa_true "old key $old_message_key should be unchanged" [string equal $messages_array($old_message_key) \ + $updated_messages_array($old_message_key)] + } + + # Check that the first new key was autogenerated + ns_log Notice "auto key compare \"$updated_messages_array(Auto_Key)\" - \"$new_text_1\"" + aa_true "check autogenerated key" [string equal $updated_messages_array(Auto_Key) $new_text_1] + + # Check that the second new key was made unique and inserted + aa_true "check key made unique" [string equal $updated_messages_array(${new_key_2}_1) $new_text_2] + + # Check that the third key was not inserted + aa_true "third key not inserted" [string equal [lindex [array get updated_messages_array $new_key_3] 1] \ + $messages_array($new_key_3)] + + # Check that there are no tags left in the tcl file + set tcl_file_id [open "[acs_root_dir]/$tcl_file" r] + set updated_tcl_contents [read $tcl_file_id] + close $tcl_file_id + aa_true "tags in tcl file replaced" [expr [llength [lang::util::get_temporary_tags_indices $updated_tcl_contents]] == 0] + + # Delete the catalog files + file delete $catalog_backup_file + file delete $catalog_file + + # Delete the tcl files + file delete "[acs_root_dir]/$tcl_file" + file delete "[acs_root_dir]/$tcl_backup_file" +} + +aa_register_case util__get_hash_indices { + Tests the lang::util::get_hash_indices proc + + @author Peter Marklund (peter@collaboraid.biz) + @creation-date 21 October 2002 +} { + set multilingual_string "#package1.key1# abc\# #package2.key2#" + set indices_list [lang::util::get_hash_indices $multilingual_string] + set expected_indices_list [list [list 0 14] [list 21 35]] + + aa_true "there should be two hash entries" [expr [llength $indices_list] == 2] + + set counter 0 + foreach index_item $indices_list { + set expected_index_item [lindex $expected_indices_list $counter] + + aa_true "checking start and end indices of item $counter" \ + [expr [string equal [lindex $index_item 0] [lindex $expected_index_item 0]] && \ + [string equal [lindex $index_item 1] [lindex $expected_index_item 1]]] + + set counter [expr $counter + 1] + } +} + +aa_register_case util__convert_adp_variables_to_percentage_signs { + Tests the lang::util::convert_adp_variables_to_percentage_signs proc. + + @author Peter Marklund (peter@collaboraid.biz) + @creation-date 25 October 2002 +} { + set adp_chunk "@array.variable_name@ @variable_name2@ peter@collaboraid.biz" + + set adp_chunk_converted [lang::util::convert_adp_variables_to_percentage_signs $adp_chunk] + set adp_chunk_expected "%array.variable_name% %variable_name2% peter@collaboraid.biz" + + aa_true "adp vars should be subsituted with percentage sings" [string equal $adp_chunk_converted \ + $adp_chunk_expected] + + # Test that a string can start with adp vars + set adp_chunk "@first_names@ @last_name@ peter@collaboraid.biz" + set adp_chunk_converted [lang::util::convert_adp_variables_to_percentage_signs $adp_chunk] + set adp_chunk_expected "%first_names% %last_name% peter@collaboraid.biz" + aa_true "adp vars should be subsituted with percentage sings" [string equal $adp_chunk_converted \ + $adp_chunk_expected] +} + +aa_register_case util__replace_adp_text_with_message_tags { + Test the lang::util::replace_adp_text_with_message_tags proc. + + @author Peter Marklund (peter@collaboraid.biz) + @creation-date 28 October 2002 +} { + # File paths used + set adp_file_path "[lang::test::get_dir]/adp_tmp_file.adp" + + # Write the adp test file + set adp_file_id [open $adp_file_path w] + puts $adp_file_id " +@first_names@ @last_name@ peter@collaboraid.biz +@context_bar@ +Test text" + close $adp_file_id + + # Do the substitutions + lang::util::replace_adp_text_with_message_tags $adp_file_path "write" + + # Read the changed test file + set adp_file_id [open $adp_file_path r] + set adp_contents [read $adp_file_id] + close $adp_file_id + + set expected_adp_pattern { +<#[a-zA-Z_]+ %first_names% %last_name% peter@collaboraid.biz#> +@context_bar@ +<#[a-zA-Z_]+ Test text\s*} + + ns_log Notice "adp_contents $adp_contents" + + # Assert proper replacements have been done + aa_true "replacing adp text with tags" \ + [regexp $expected_adp_pattern $adp_contents match] + + # Remove the adp test file + file delete $adp_file_path +} + +aa_register_case message__format { + Tests the lang::message::format proc + + @author Peter Marklund (peter@collaboraid.biz) + @creation-date 21 October 2002 +} { + + set localized_message "The %frog% jumped across the %fence%. About 50% of the time, he stumbled, or maybe it was %%20 %times%." + set value_list {frog frog fence fence} + + set subst_message [lang::message::format $localized_message $value_list] + set expected_message "The frog jumped across the fence. About 50% of the time, he stumbled, or maybe it was %20 %times%." + + aa_true "the frog should jump across the fence" [string equal $subst_message \ + $expected_message] +} + +aa_register_case message__get_missing_embedded_vars { + Tests the lang::message::get_missing_embedded_vars proc + + @author Peter Marklund (peter@collaboraid.biz) + @creation-date 12 November 2002 +} { + set en_us_message "this is a message with some %vars% and some more %variables%" + set new_message "this message contains no vars" + + set missing_vars_list [lang::message::get_missing_embedded_vars $en_us_message $new_message] + + aa_true "check the missing vars" [expr [string equal [lindex $missing_vars_list 0] "vars"] && \ + [string equal [lindex $missing_vars_list 1] "variables"]] +} Index: openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl 3 Dec 2002 17:27:04 -0000 1.1 +++ openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl 4 Apr 2003 09:47:43 -0000 1.2 @@ -1,5 +1,5 @@ ad_library { - Test TCL procedures in the acs-lang package with acs-automated-testing. + Helper test Tcl procedures. @author Peter Marklund (peter@collaboraid.biz) @creation-date 18 October 2002 @@ -16,205 +16,3 @@ return "[acs_package_root_dir acs-lang]/tcl/test" } } - -aa_register_case util__replace_temporary_tags_with_lookups { - Primarily tests lang::util::replace_temporary_tags_with_lookups, - Also tests the procs lang::catalog::export_messages_to_file, lang::catalog::parse, - lang::catalog::read_file, and lang::util::get_temporary_tags_indices. - - A test tcl file and catalog file are created. The temporary tags in the - tcl file are replaced with message lookups and keys and messages are appended - to the catalog file. - - @author Peter Marklund (peter@collaboraid.biz) - @creation-date 18 October 2002 -} { - # The files involved in the test - set test_dir [lang::test::get_dir] - set catalog_file "${test_dir}/acs-lang.en_US.ISO-8859-1.xml" - set backup_file_suffix ".orig" - set catalog_backup_file "${catalog_file}${backup_file_suffix}" - regexp {^.*(packages/.*)$} $test_dir match test_dir_rel - set tcl_file "${test_dir_rel}/test-message-tags.tcl" - set tcl_backup_file "${tcl_file}${backup_file_suffix}" - - # The test messages to use for the catalog file - array set messages_array [list key_1 text_1 key_2 text_2 key_3 text_3] - - # Write the test tcl file - set tcl_file_id [open "[acs_root_dir]/$tcl_file" w] - set new_key_1 "_" - set new_text_1 "Auto Key" - set new_key_2 "key_1" - set new_text_2 "text_1_different" - set new_key_3 "key_1" - set new_text_3 "$messages_array(key_1)" - puts $tcl_file_id "# The following key should be auto-generated and inserted - # <#${new_key_1} ${new_text_1}#> - # - # The following key should be made unique and inserted - # <#${new_key_2} ${new_text_2}#> - # - # The following key should not be inserted in the message catalog - # <#${new_key_3} ${new_text_3}#>" - close $tcl_file_id - - # Write the catalog file - lang::catalog::export_messages_to_file $catalog_file [array get messages_array] - - # Replace message tags in the tcl file and insert into catalog file - lang::util::replace_temporary_tags_with_lookups -catalog_file_path $catalog_file $tcl_file - - # Read the contents of the catalog file - array set catalog_array [lang::catalog::parse [lang::catalog::read_file $catalog_file]] - array set updated_messages_array [lindex [array get catalog_array messages] 1] - - # Assert that the old messages are unchanged - foreach old_message_key [array names messages_array] { - aa_true "old key $old_message_key should be unchanged" [string equal $messages_array($old_message_key) \ - $updated_messages_array($old_message_key)] - } - - # Check that the first new key was autogenerated - ns_log Notice "auto key compare \"$updated_messages_array(Auto_Key)\" - \"$new_text_1\"" - aa_true "check autogenerated key" [string equal $updated_messages_array(Auto_Key) $new_text_1] - - # Check that the second new key was made unique and inserted - aa_true "check key made unique" [string equal $updated_messages_array(${new_key_2}_1) $new_text_2] - - # Check that the third key was not inserted - aa_true "third key not inserted" [string equal [lindex [array get updated_messages_array $new_key_3] 1] \ - $messages_array($new_key_3)] - - # Check that there are no tags left in the tcl file - set tcl_file_id [open "[acs_root_dir]/$tcl_file" r] - set updated_tcl_contents [read $tcl_file_id] - close $tcl_file_id - aa_true "tags in tcl file replaced" [expr [llength [lang::util::get_temporary_tags_indices $updated_tcl_contents]] == 0] - - # Delete the catalog files - file delete $catalog_backup_file - file delete $catalog_file - - # Delete the tcl files - file delete "[acs_root_dir]/$tcl_file" - file delete "[acs_root_dir]/$tcl_backup_file" -} - -aa_register_case util__get_hash_indices { - Tests the lang::util::get_hash_indices proc - - @author Peter Marklund (peter@collaboraid.biz) - @creation-date 21 October 2002 -} { - set multilingual_string "#package1.key1# abc\# #package2.key2#" - set indices_list [lang::util::get_hash_indices $multilingual_string] - set expected_indices_list [list [list 0 14] [list 21 35]] - - aa_true "there should be two hash entries" [expr [llength $indices_list] == 2] - - set counter 0 - foreach index_item $indices_list { - set expected_index_item [lindex $expected_indices_list $counter] - - aa_true "checking start and end indices of item $counter" \ - [expr [string equal [lindex $index_item 0] [lindex $expected_index_item 0]] && \ - [string equal [lindex $index_item 1] [lindex $expected_index_item 1]]] - - set counter [expr $counter + 1] - } -} - -aa_register_case util__convert_adp_variables_to_percentage_signs { - Tests the lang::util::convert_adp_variables_to_percentage_signs proc. - - @author Peter Marklund (peter@collaboraid.biz) - @creation-date 25 October 2002 -} { - set adp_chunk "@array.variable_name@ @variable_name2@ peter@collaboraid.biz" - - set adp_chunk_converted [lang::util::convert_adp_variables_to_percentage_signs $adp_chunk] - set adp_chunk_expected "%array.variable_name% %variable_name2% peter@collaboraid.biz" - - aa_true "adp vars should be subsituted with percentage sings" [string equal $adp_chunk_converted \ - $adp_chunk_expected] - - # Test that a string can start with adp vars - set adp_chunk "@first_names@ @last_name@ peter@collaboraid.biz" - set adp_chunk_converted [lang::util::convert_adp_variables_to_percentage_signs $adp_chunk] - set adp_chunk_expected "%first_names% %last_name% peter@collaboraid.biz" - aa_true "adp vars should be subsituted with percentage sings" [string equal $adp_chunk_converted \ - $adp_chunk_expected] -} - -aa_register_case util__replace_adp_text_with_message_tags { - Test the lang::util::replace_adp_text_with_message_tags proc. - - @author Peter Marklund (peter@collaboraid.biz) - @creation-date 28 October 2002 -} { - # File paths used - set adp_file_path "[lang::test::get_dir]/adp_tmp_file.adp" - - # Write the adp test file - set adp_file_id [open $adp_file_path w] - puts $adp_file_id " -@first_names@ @last_name@ peter@collaboraid.biz -@context_bar@ -Test text" - close $adp_file_id - - # Do the substitutions - lang::util::replace_adp_text_with_message_tags $adp_file_path "write" - - # Read the changed test file - set adp_file_id [open $adp_file_path r] - set adp_contents [read $adp_file_id] - close $adp_file_id - - set expected_adp_pattern { -<#[a-zA-Z_]+ %first_names% %last_name% peter@collaboraid.biz#> -@context_bar@ -<#[a-zA-Z_]+ Test text\s*} - - ns_log Notice "adp_contents $adp_contents" - - # Assert proper replacements have been done - aa_true "replacing adp text with tags" \ - [regexp $expected_adp_pattern $adp_contents match] - - # Remove the adp test file - file delete $adp_file_path -} - -aa_register_case message__format { - Tests the lang::message::format proc - - @author Peter Marklund (peter@collaboraid.biz) - @creation-date 21 October 2002 -} { - - set localized_message "The %frog% jumped across the %fence%. About 50% of the time, he stumbled, or maybe it was %%20 %times%." - set value_list {frog frog fence fence} - - set subst_message [lang::message::format $localized_message $value_list] - set expected_message "The frog jumped across the fence. About 50% of the time, he stumbled, or maybe it was %20 %times%." - - aa_true "the frog should jump across the fence" [string equal $subst_message \ - $expected_message] -} - -aa_register_case message__get_missing_embedded_vars { - Tests the lang::message::get_missing_embedded_vars proc - - @author Peter Marklund (peter@collaboraid.biz) - @creation-date 12 November 2002 -} { - set en_us_message "this is a message with some %vars% and some more %variables%" - set new_message "this message contains no vars" - - set missing_vars_list [lang::message::get_missing_embedded_vars $en_us_message $new_message] - - aa_true "check the missing vars" [expr [string equal [lindex $missing_vars_list 0] "vars"] && \ - [string equal [lindex $missing_vars_list 1] "variables"]] -} Index: openacs-4/packages/acs-tcl/tcl/apm-file-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/apm-file-procs.tcl,v diff -u -r1.22 -r1.23 --- openacs-4/packages/acs-tcl/tcl/apm-file-procs.tcl 4 Apr 2003 09:17:30 -0000 1.22 +++ openacs-4/packages/acs-tcl/tcl/apm-file-procs.tcl 4 Apr 2003 09:49:08 -0000 1.23 @@ -338,7 +338,7 @@ set file_type [apm_guess_file_type $package_key $package_rel_path] # I would like to add test_procs to the list but currently test_procs files are used to register test cases # and we don't want to resource these files in every interpreter. Test procs should be defined in test_init files. - set watchable_file_types [list tcl_procs query_file] + set watchable_file_types [list tcl_procs query_file test_procs] set right_file_type_p [expr [lsearch -exact $watchable_file_types $file_type] != -1] # Both db type and file type must be right Index: openacs-4/packages/acs-tcl/tcl/test/acs-tcl-test-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/test/Attic/acs-tcl-test-init.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-tcl/tcl/test/acs-tcl-test-init.tcl 4 Apr 2003 09:49:38 -0000 1.1 @@ -0,0 +1,182 @@ +ad_library { + Define acs-automated-testing tests for the acs-tcl package + on server startup. + + @author Peter Marklund (peter@collaboraid.biz) + @creation-date 22 January 2003 +} + +aa_register_case util__sets_equal_p { + Test the util_sets_equal_p proc. + + @author Peter Marklund +} { + aa_true "lists are identical sets" [util_sets_equal_p [list a a a b b c] [list c a a b b a]] + aa_true "lists are identical sets 2" [util_sets_equal_p [list a b c] [list a b c]] + aa_false "lists are not identical sets" [util_sets_equal_p [list a a a b b c] [list c c a b b a]] + aa_false "lists are not identical sets 2" [util_sets_equal_p [list a b c] [list a b c d]] +} + +# By stubbing this proc we can define callbacks valid only during testing +# that are guaranteed not to interfere with any real callbacks in the system +aa_stub apm_supported_callback_types { + return [list __test-callback-type] +} + +aa_stub apm_arg_names_for_callback_type { + return [list arg1 arg2] +} + +aa_register_case apm__test_info_file { + Test that the procs for interfacing with package info files - + apm_generate_package_spec and + apm_read_package_info_file - handle the newly added + callback and auto-mount tags properly. + + @creation-date 22 January 2003 + @author Peter Marklund +} { + set test_dir "[acs_package_root_dir acs-tcl]/tcl/test" + set spec_path "${test_dir}/tmp-test-info-file.xml" + set allowed_type [lindex [apm_supported_callback_types] 0] + array set callback_array [list unknown-type proc_name1 $allowed_type proc_name2] + set version_id [db_string aa_version_id {select version_id + from apm_enabled_package_versions + where package_key = 'acs-automated-testing'}] + set auto_mount_orig [db_string aa_auto_mount {select auto_mount + from apm_package_versions + where version_id = :version_id}] + set auto_mount $auto_mount_orig + if { [empty_string_p $auto_mount] } { + set auto_mount "test_auto_mount_dir" + db_dml set_test_mount {update apm_package_versions + set auto_mount = :auto_mount + where version_id = :version_id} + ail } + + set error_p [catch { + # Add a few test callbacks + foreach {type proc} [array get callback_array] { + db_dml insert_callback {insert into apm_package_callbacks + (version_id, type, proc) + values (:version_id, :type, :proc)} + } + + # Get the xml string + set spec [apm_generate_package_spec $version_id] + + # Write xml to file + set spec_file_id [open $spec_path w] + puts $spec_file_id $spec + close $spec_file_id + + # Read the xml file + array set spec_array [apm_read_package_info_file $spec_path] + + # Assert that info parsed from xml file is correct + array set parsed_callback_array $spec_array(callbacks) + + aa_true "Only one permissible callback should be returned, got array [array get parsed_callback_array]" \ + [expr [llength [array names parsed_callback_array]] == 1] + + aa_equals "Checking name of callback of allowed type $allowed_type" \ + $parsed_callback_array($allowed_type) $callback_array($allowed_type) + + aa_equals "Checking that auto-callback is correct" $spec_array(auto-mount) $auto_mount + + } error] + + # Teardown + file delete $spec_path + foreach {type proc} [array get callback_array] { + db_dml remove_callback {delete from apm_package_callbacks + where version_id = :version_id + and type = :type } + } + db_dml reset_auto_mount {update apm_package_versions + set auto_mount = :auto_mount_orig + where version_id = :version_id} + + + if { $error_p } { + global errorInfo + error "$error - $errorInfo" + } +} + +aa_register_case apm__test_callback_get_set { + Test the procs apm_get_callback_proc, + apm_set_callback_proc, + apm_package_install_callbacks + apm_remove_callback_proc, + apm_post_instantiation_tcl_proc_from_key. + + @author Peter Marklund +} { + # The proc should not accept an invalid callback type + set invalid_type "not-allowed-type" + set error_p [catch {apm_get_callback_proc -type $invalid_type -package_key acs-kernel} error] + aa_true "invalid types should result in error, got error: $error" $error_p + + # Try setting a package callback proc + set callback_type [lindex [apm_supported_callback_types] 0] + set proc_name "test_proc" + set package_key "acs-automated-testing" + set version_id [apm_version_id_from_package_key $package_key] + + set error_p [catch { + apm_package_install_callbacks [list $callback_type $proc_name] $version_id + + # Retrieve the callback proc + set retrieved_proc_name \ + [apm_get_callback_proc -package_key $package_key \ + -type $callback_type] + aa_equals "apm_get_callback_proc retrieve callback proc" \ + $retrieved_proc_name $proc_name + } error] + + # Teardown + apm_remove_callback_proc -package_key $package_key -type $callback_type + + if { $error_p } { + global errorInfo + error "$error - $errorInfo" + } +} + +aa_register_case apm__test_callback_invoke { + Test the proc apm_invoke_callback_proc + + @author Peter Marklund +} { + set package_key acs-automated-testing + set version_id [apm_version_id_from_package_key $package_key] + set type [lindex [apm_supported_callback_types] 0] + set file_path [apm_test_callback_file_path] + + set error_p [catch { + + # Set the callback to be to our little test proc + apm_set_callback_proc -version_id $version_id -type $type "apm_test_callback_proc" + + apm_invoke_callback_proc -version_id $version_id -arg_list [list arg1 value1 arg2 value2] -type $type + + set file_id [open $file_path r] + set file_contents [read $file_id] + aa_equals "The callback proc should have been executed and written argument values to file" \ + [string trim $file_contents] "value1 value2" + close $file_id + + # Provide invalid argument list and the invoke proc should bomb + # TODO... + } error] + + # Teardown + file delete $file_path + apm_remove_callback_proc -package_key $package_key -type $type + + if { $error_p } { + global errorInfo + error "$error - $errorInfo" + } +} Index: openacs-4/packages/acs-tcl/tcl/test/acs-tcl-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/test/acs-tcl-test-procs.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/acs-tcl/tcl/test/acs-tcl-test-procs.tcl 29 Jan 2003 15:48:17 -0000 1.2 +++ openacs-4/packages/acs-tcl/tcl/test/acs-tcl-test-procs.tcl 4 Apr 2003 09:49:38 -0000 1.3 @@ -1,148 +1,11 @@ ad_library { - Test TCL procedures in the acs-tcl package with acs-automated-testing. + Tcl helper procedures for the acs-automated-testing tests of + the acs-tcl package. @author Peter Marklund (peter@collaboraid.biz) @creation-date 22 January 2003 } -aa_register_case util__sets_equal_p { - Test the util_sets_equal_p proc. - - @author Peter Marklund -} { - aa_true "lists are identical sets" [util_sets_equal_p [list a a a b b c] [list c a a b b a]] - aa_true "lists are identical sets 2" [util_sets_equal_p [list a b c] [list a b c]] - aa_false "lists are not identical sets" [util_sets_equal_p [list a a a b b c] [list c c a b b a]] - aa_false "lists are not identical sets 2" [util_sets_equal_p [list a b c] [list a b c d]] -} - -# By stubbing this proc we can define callbacks valid only during testing -# that are guaranteed not to interfere with any real callbacks in the system -aa_stub apm_supported_callback_types { - return [list __test-callback-type] -} - -aa_stub apm_arg_names_for_callback_type { - return [list arg1 arg2] -} - -aa_register_case apm__test_info_file { - Test that the procs for interfacing with package info files - - apm_generate_package_spec and - apm_read_package_info_file - handle the newly added - callback and auto-mount tags properly. - - @creation-date 22 January 2003 - @author Peter Marklund -} { - set test_dir "[acs_package_root_dir acs-tcl]/tcl/test" - set spec_path "${test_dir}/tmp-test-info-file.xml" - set allowed_type [lindex [apm_supported_callback_types] 0] - array set callback_array [list unknown-type proc_name1 $allowed_type proc_name2] - set version_id [db_string aa_version_id {select version_id - from apm_enabled_package_versions - where package_key = 'acs-automated-testing'}] - set auto_mount_orig [db_string aa_auto_mount {select auto_mount - from apm_package_versions - where version_id = :version_id}] - set auto_mount $auto_mount_orig - if { [empty_string_p $auto_mount] } { - set auto_mount "test_auto_mount_dir" - db_dml set_test_mount {update apm_package_versions - set auto_mount = :auto_mount - where version_id = :version_id} - ail } - - set error_p [catch { - # Add a few test callbacks - foreach {type proc} [array get callback_array] { - db_dml insert_callback {insert into apm_package_callbacks - (version_id, type, proc) - values (:version_id, :type, :proc)} - } - - # Get the xml string - set spec [apm_generate_package_spec $version_id] - - # Write xml to file - set spec_file_id [open $spec_path w] - puts $spec_file_id $spec - close $spec_file_id - - # Read the xml file - array set spec_array [apm_read_package_info_file $spec_path] - - # Assert that info parsed from xml file is correct - array set parsed_callback_array $spec_array(callbacks) - - aa_true "Only one permissible callback should be returned, got array [array get parsed_callback_array]" \ - [expr [llength [array names parsed_callback_array]] == 1] - - aa_equals "Checking name of callback of allowed type $allowed_type" \ - $parsed_callback_array($allowed_type) $callback_array($allowed_type) - - aa_equals "Checking that auto-callback is correct" $spec_array(auto-mount) $auto_mount - - } error] - - # Teardown - file delete $spec_path - foreach {type proc} [array get callback_array] { - db_dml remove_callback {delete from apm_package_callbacks - where version_id = :version_id - and type = :type } - } - db_dml reset_auto_mount {update apm_package_versions - set auto_mount = :auto_mount_orig - where version_id = :version_id} - - - if { $error_p } { - global errorInfo - error "$error - $errorInfo" - } -} - -aa_register_case apm__test_callback_get_set { - Test the procs apm_get_callback_proc, - apm_set_callback_proc, - apm_package_install_callbacks - apm_remove_callback_proc, - apm_post_instantiation_tcl_proc_from_key. - - @author Peter Marklund -} { - # The proc should not accept an invalid callback type - set invalid_type "not-allowed-type" - set error_p [catch {apm_get_callback_proc -type $invalid_type -package_key acs-kernel} error] - aa_true "invalid types should result in error, got error: $error" $error_p - - # Try setting a package callback proc - set callback_type [lindex [apm_supported_callback_types] 0] - set proc_name "test_proc" - set package_key "acs-automated-testing" - set version_id [apm_version_id_from_package_key $package_key] - - set error_p [catch { - apm_package_install_callbacks [list $callback_type $proc_name] $version_id - - # Retrieve the callback proc - set retrieved_proc_name \ - [apm_get_callback_proc -package_key $package_key \ - -type $callback_type] - aa_equals "apm_get_callback_proc retrieve callback proc" \ - $retrieved_proc_name $proc_name - } error] - - # Teardown - apm_remove_callback_proc -package_key $package_key -type $callback_type - - if { $error_p } { - global errorInfo - error "$error - $errorInfo" - } -} - ad_proc apm_test_callback_file_path {} { The path of the test file used to check that the callback proc executed ok. } { @@ -159,40 +22,3 @@ puts $file_id "$arg1 $arg2" close $file_id } - -aa_register_case apm__test_callback_invoke { - Test the proc apm_invoke_callback_proc - - @author Peter Marklund -} { - set package_key acs-automated-testing - set version_id [apm_version_id_from_package_key $package_key] - set type [lindex [apm_supported_callback_types] 0] - set file_path [apm_test_callback_file_path] - - set error_p [catch { - - # Set the callback to be to our little test proc - apm_set_callback_proc -version_id $version_id -type $type "apm_test_callback_proc" - - apm_invoke_callback_proc -version_id $version_id -arg_list [list arg1 value1 arg2 value2] -type $type - - set file_id [open $file_path r] - set file_contents [read $file_id] - aa_equals "The callback proc should have been executed and written argument values to file" \ - [string trim $file_contents] "value1 value2" - close $file_id - - # Provide invalid argument list and the invoke proc should bomb - # TODO... - } error] - - # Teardown - file delete $file_path - apm_remove_callback_proc -package_key $package_key -type $type - - if { $error_p } { - global errorInfo - error "$error - $errorInfo" - } -} Index: openacs-4/packages/news/tcl/test/news-db-test-init-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/news/tcl/test/news-db-test-init-oracle.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/news/tcl/test/news-db-test-init-oracle.xql 4 Apr 2003 09:48:13 -0000 1.1 @@ -0,0 +1,175 @@ + + + +oracle8.1.6 + + + + select node_id, object_id, site_node.url(node_id) as url from site_nodes + + + + + + begin + apm_package.delete(:p_package_id); + end; + + + + + + begin + apm_package.delete(:p_package_id); + end; + + + + + + select content_item.get_root_folder from dual + + + + + + begin + :1 := news.new( + text => :p_text, + title => :p_title, + package_id => :p_package_id, + archive_date => :p_archive_date, + approval_user => :p_approval_user, + approval_date => :p_approval_date, + approval_ip => :p_approval_ip, + is_live_p => :p_is_live + ); + end; + + + + + + begin + news.revision_delete(:p_revision_id); + end; + + + + + + begin + :1 := news.revision_new( + item_id => :p_item_id, + text => :p_text, + title => :p_title, + description => :p_description, + package_id => :p_package_id, + archive_date => :p_archive_date, + approval_user => :p_approval_user, + approval_date => :p_approval_date, + approval_ip => :p_approval_ip, + make_active_revision_p => :p_make_active_revision_p + ); + end; + + + + + + begin + :1 := content_item.get_live_revision(:p_item_id); + end; + + + + + + begin + :1 := content_item.get_latest_revision(:p_item_id); + end; + + + + + + begin + news.set_approve(revision_id => :p_revision_id, + approve_p => :p_approve_p); + end; + + + + + + begin + news.set_approve(revision_id => :p_revision_id, + approve_p => :p_approve_p, + publish_date => :p_publish_date, + archive_date => :p_archive_date, + approval_user => :p_approval_user, + approval_date => :p_approval_date, + approval_ip => :p_approval_ip, + live_revision_p => :p_live_revision_p); + end; + + + + + + begin + news.revision_set_active(:p_revision_id); + end; + + + + + + begin + news.delete(:p_item_id); + end; + + + + + + begin + news.make_permanent(:p_item_id); + end; + + + + + + begin + news.archive(item_id => :p_item_id, + archive_date => :p_archive_date); + end; + + + + + + begin + news.archive(item_id => :p_item_id); + end; + + + + + + begin + :1 := news.status(:p_news_id); + end; + + + + + + begin + :1 := news.name(news_id => :p_news_id); + end; + + + + Index: openacs-4/packages/news/tcl/test/news-db-test-init-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/news/tcl/test/news-db-test-init-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/news/tcl/test/news-db-test-init-postgresql.xql 4 Apr 2003 09:48:13 -0000 1.1 @@ -0,0 +1,140 @@ + + + +postgresql7.1 + + + + select node_id, object_id, site_node__url(node_id) as url from site_nodes + + + + + + select apm_package__delete(:p_package_id); + + + + + + select apm_package__delete(:p_package_id); + + + + + + select content_item_globals.c_root_folder_id; + + + + + + select news__new( + null, + null, + current_timestamp, :p_text, null, :p_title, 'text/plain', + :p_package_id, :p_archive_date, :p_approval_user, :p_approval_date, :p_approval_ip, + null, + null,null, + :p_is_live + ); + + + + + + select news__delete(:p_item_id); + + + + + + select news__revision_new( + :p_item_id, + current_timestamp, :p_text, :p_title, + :p_description, + 'text/plain', :p_package_id, :p_archive_date, :p_approval_user, :p_approval_date, + :p_approval_ip, + current_timestamp, null, null, + :p_make_active_revision_p + ); + + + + + + select content_item__get_live_revision(:p_item_id); + + + + + + select content_item__get_latest_revision(:p_item_id); + + + + + + select news__set_approve(:p_revision_id, + :p_approve_p, + null, null, null, null, null, null); + + + + + + select news__set_approve(:p_revision_id, + :p_approve_p, + :p_publish_date, + :p_archive_date, + :p_approval_user, + :p_approval_date, + :p_approval_ip, + :p_live_revision_p); + + + + + + select news__revision_set_active(:p_revision_id); + + + + + + select news__revision_delete(:p_revision_id); + + + + + + select news__make_permanent(:p_item_id); + + + + + + select news__archive(:p_item_id); + + + + + + select news__archive(:p_item_id, :p_archive_date); + + + + + + select news__status(:p_news_id); + + + + + + select news__name(:p_news_id); + + + + + Index: openacs-4/packages/news/tcl/test/news-db-test-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/news/tcl/test/news-db-test-init.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/news/tcl/test/news-db-test-init.tcl 4 Apr 2003 09:48:13 -0000 1.1 @@ -0,0 +1,1473 @@ +################################################################################ +# +# News package database and database configuration tests. +# +################################################################################ + +ad_library { + acs-automated-testing test definitions for the news package to be sourced on + server startup. + + @author peter.harper@open-msg.com + @creation-date 2001-11-18 + @cvs-id $Id: news-db-test-init.tcl,v 1.1 2003/04/04 09:48:13 peterm Exp $ +} + + +################################################################################ +# # +# I N I T C L A S S E S # +# # +################################################################################ + +################################################################################ +# +# Init Class mount-news-package +# +aa_register_init_class "mount-news-package" { + Mounts a copy of the news package in "/_test/news". +} { + # Constructor + # Export variables we want to be visible to the testcase and the destructor. + aa_export_vars {_root_node_id _test_node_id _news_node_id _news_package_id + _news_package_mounted_p _news_package_mounted_err} + + # + # Firstly, make sure the mount point "/_test/news" exists. + # + set _news_node_id -1 + set _test_node_id -1 + set _root_node_id -1 + set _news_package_id -1 + db_foreach get-site-nodes { + select node_id, object_id, site_node.url(node_id) as url from site_nodes + } { + switch [string trim $url] { + "/_test/news/" { + set _news_node_id $node_id + if {$object_id != ""} { + set _news_package_id $object_id + } + } + "/_test/" { + set _test_node_id $node_id + } + "/" { + set _root_node_id $node_id + } + } + } + + set _news_package_mounted_p 1 + if {[catch { + # Create the _test directory if it doesn't already exist. +aa_log "here" + if {$_test_node_id == -1} { + set _test_node_id [site_node_create $_root_node_id "_test"] + } + # If an old news package exists, delete it. + if {$_news_node_id != -1} { + aa_log "Deleting existing node instance." + site_map_unmount_application -delete_p t -sync_p t $_news_node_id + if {$_news_package_id != -1} { + aa_log "Deleting existing package instance." + set p_package_id $_news_package_id + db_exec_plsql package-delete { + begin + apm_package.delete(:p_package_id); + end; + } + } + } + + # Mount the new news package and lookup the new node_id. + set _news_package_id [site_node_mount_application $_test_node_id "news" \ + "news" "News test"] + set _news_node_id [site_node_id "/_test/news/"] + } _news_package_mounted_err]} { + set _news_node_id -1 + set _test_node_id -1 + set _root_node_id -1 + set _news_package_mounted_p 0 + } +} { + # Destructor + + # + # Unmount the news package and delete its directory. + # + if {$_news_package_mounted_p} { + site_map_unmount_application -delete_p t $_news_node_id + set p_package_id $_news_package_id + db_exec_plsql package-delete { + begin + apm_package.delete(:p_package_id) + } + } +} + + +################################################################################ +# # +# C O M P O N E N T S # +# # +################################################################################ + +################################################################################ +# +# Component db-news-globals +# +aa_register_component "db-news-globals" { + Sets up general information regarding the news package +
+ Exports:
+ _news_cr_root_folder_id
+ _news_cr_news_root_folder_id +} { + aa_export_vars {_news_cr_root_folder_id _news_cr_news_root_folder_id} + + set _news_cr_root_folder_id [db_string get-cr-root-folder { + select content_item.get_root_folder from dual + }] + set p_parent_id $_news_cr_root_folder_id + set _news_cr_news_root_folder_id [db_string get-cr-news-root-folder { + select item_id + from cr_items + where parent_id = :p_parent_id + and name = 'news' + }] +} + +################################################################################ +# +# Component db-news-item-create +# +aa_register_component "db-news-item-create" { + Creates a news item. Expects the following variables to be populated:
+ p_title
+ p_text
+ p_package_id
+ p_is_live
+ p_full_details
+

+ Populates:
+ news_id +} { + aa_export_vars {p_full_details p_title p_text p_package_id p_is_live + p_approval_user p_approval_ip p_approval_date p_archive_date + news_id} + if {$p_full_details == "t"} { + set p_approval_user [ad_conn "user_id"] + set p_approval_ip [ad_conn "peeraddr"] + set p_approval_date [dt_sysdate] + set p_archive_date [dt_sysdate] + } else { + set p_approval_user [db_null] + set p_approval_ip [db_null] + set p_approval_date [db_null] + set p_archive_date [db_null] + } + set news_id [db_exec_plsql item-create { + begin + :1 := news.new( + text => :p_text, + title => :p_title, + package_id => :p_package_id, + archive_date => :p_archive_date, + approval_user => :p_approval_user, + approval_date => :p_approval_date, + approval_ip => :p_approval_ip, + is_live_p => :p_is_live + ); + end; + }] +} + +################################################################################ +# +# Component db-news-item-delete +# +aa_register_component "db-news-item-delete" { + Deletes a news item. Expects the following variables to be populated:
+ p_news_id
+} { + aa_export_vars {p_item_id} + db_exec_plsql item-delete { + begin + news.delete(:p_item_id); + end; + } +} + +################################################################################ +# +# Component db-news-revision-create +# +aa_register_component "db-news-revision-create" { + Creates a news item revision. Expects the following variables to be populated:
+ p_title
+ p_text
+ p_description
+ p_package_id
+ p_make_active_revision_p
+ p_full_details
+

+ Populates:
+ revision_id +} { + aa_export_vars {p_item_id + p_full_details p_title p_text p_package_id p_make_active_revision_p + p_description + p_approval_user p_approval_ip p_approval_date p_archive_date + revision_id} + if {$p_full_details == "t"} { + set p_approval_user [ad_conn "user_id"] + set p_approval_ip [ad_conn "peeraddr"] + set p_approval_date [dt_sysdate] + set p_archive_date [dt_sysdate] + } else { + set p_approval_user [db_null] + set p_approval_ip [db_null] + set p_approval_date [db_null] + set p_archive_date [db_null] + } + set revision_id [db_exec_plsql revision-create { + begin + :1 := news.revision_new( + item_id => :p_item_id, + text => :p_text, + title => :p_title, + package_id => :p_package_id, + archive_date => :p_archive_date, + approval_user => :p_approval_user, + approval_date => :p_approval_date, + approval_ip => :p_approval_ip, + make_active_revision_p => :p_make_active_revision_p + ); + end; + }] +} + +################################################################################ +# +# Component db-news-get-live-revision +# +aa_register_component "db-news-get-live-revision" { + Retrieves the id of the live revision of an item_id + p_item_id
+ Provides
+ live_revision_id +} { + aa_export_vars {p_item_id live_revision_id} + set live_revision_id [db_exec_plsql get-live-revision { + begin + :1 := content_item.get_live_revision(:p_item_id); + end; + }] +} + +################################################################################ +# +# Component db-news-get-latest-revision +# +aa_register_component "db-news-get-latest-revision" { + Retrieves the id of the latest revision of an item_id + p_item_id
+ Provides
+ latest_revision_id +} { + aa_export_vars {p_item_id latest_revision_id} + set latest_revision_id [db_exec_plsql get-latest-revision { + begin + :1 := content_item.get_latest_revision(:p_item_id); + end; + }] +} + +################################################################################ +# +# Component db-news-set-approve +# +aa_register_component "db-news-set-approve" { + Sets or removes the approved status on a news article
+ Expects
+ p_revision_id
+ p_approve_p
+ p_publish_date (if p_approve_p == 't')
+ p_archive_date (if p_approve_p == 't')
+ p_approval_user (if p_approve_p == 't')
+ p_approval_date (if p_approve_p == 't')
+ p_approval_ip (if p_approve_p == 't')
+ p_live_revision_p (if p_approve_p == 't')
+} { + aa_export_vars {p_revision_id + p_approve_p p_publish_date p_archive_date + p_approval_user p_approval_date p_approval_ip + p_live_revision_p} + + if {$p_approve_p == "f"} { + db_exec_plsql set-approve-default { + begin + content_item.set_approve-default(revision_id => :p_revision_id, + approve_p => :p_approve_p); + end; + } + } else { + db_exec_plsql set-approve { + begin + content_item.set_approve(revision_id => :p_revision_id, + approve_p => :p_approve_p, + publish_date => :p_publish_date + archive_date => :p_archive_date, + approval_user => :p_approval_user, + approval_date => :p_approval_date, + approvel_ip => :p_approval_id, + live_revision_p => :p_live_revision_ip); + end; + } + } +} + +################################################################################ +# +# Component db-news-revision-set-active +# +aa_register_component "db-news-revision-set-active" { + Sets a specific revision as the live version of the item + Requires:
+ p_revision_id
+} { + aa_export_vars {p_revision_id} + db_exec_plsql revision-set-active { + begin + news.revision_set_active(:p_revision_id); + end; + } +} + +################################################################################ +# +# Component db-news-revision-delete +# +aa_register_component "db-news-revision-delete" { + Deletes a news revision. Expects the following variables to be populated:
+ p_revision_id
+} { + aa_export_vars {p_revision_id} + db_exec_plsql revision-delete { + begin + news.revision_delete(:p_revision_id); + end; + } +} + +################################################################################ +# +# Component db-get-cr-news-row +# +aa_register_component "db-get-cr-news-row" { + Retrieves the cr_news row information for the given news_id: + Expects:
+ p_news_id
+ In addition to the actual row data, populates:
+ retrieval_ok_p
+} { + aa_export_vars {p_news_id + package_id archive_date approval_user approval_date approval_ip + retrieval_ok_p} + set retrieval_ok_p 1 + if {![db_0or1row get-cr-news-row { + select package_id, archive_date, + approval_user, approval_date, approval_ip + from cr_news + where news_id = :p_news_id + }]} { + set retrieval_ok_p 0 + } +} + +################################################################################ +# +# Component db-get-cr-revisions-row +# +aa_register_component "db-get-cr-revisions-row" { + Retrieves the cr_revisions row information for the given news_id: + Expects:
+ p_revision_id
+ In addition to the actual row data, populates:
+ retrieval_ok_p
+} { + aa_export_vars {p_revision_id + item_id title description publish_date mime_type nls_language + content content_length + retrieval_ok_p} + set retrieval_ok_p 1 + if {![db_0or1row get-cr-revisions-row { + select item_id, title, description, publish_date, mime_type, + nls_language, content, content_length + from cr_revisions + where revision_id = :p_revision_id + }]} { + set retrieval_ok_p 0 + } +} + +################################################################################ +# +# Component db-get-cr-items-row +# +aa_register_component "db-get-cr-items-row" { + Retrieves the cr_revisions row information for the given news_id: + Expects:
+ p_revision_id
+ In addition to the actual row data, populates:
+ retrieval_ok_p
+} { + aa_export_vars {p_item_id + parent_id name live_revision latest_revision publish_status content_type + retrieval_ok_p} + set retrieval_ok_p 1 + if {![db_0or1row get-cr-items-row { + select parent_id, name, live_revision, latest_revision, + publish_status, content_type + from cr_items + where item_id = :p_item_id + }]} { + set retrieval_ok_p 0 + } +} + +################################################################################ +# +# Component db-news-make-permanent +# +aa_register_component "db-news-make-permanent" { + Calls the news packages make_permanent function. + p_item_id
+} { + aa_export_vars {p_item_id} + db_exec_plsql make-permanent { + begin + news.make_permanent(:p_item_id); + end; + } +} + +################################################################################ +# +# Component db-news-archive +# +aa_register_component "db-news-archive" { + Calls the news packages archive function. + p_item_id
+ p_archive_date
+} { + aa_export_vars {p_item_id p_archive_date} + if {$p_archive_date == ""} { + db_exec_plsql archive-default { + begin + news.archive(:p_item_id, null); + end; + } + } else { + db_exec_plsql archive { + begin + news.archive(:p_item_id, :p_archive_date); + end; + } + } +} + +################################################################################ +# +# Component db-news-status +# +aa_register_component "db-news-status" { + Calls the news packages status function. + p_news_id
+} { + aa_export_vars {p_news_id status} + set status [db_exec_plsql get-status { + begin + :1 := news.status(:p_news_id); + end; + }] +} + + +################################################################################ +# # +# T E S T C A S E S # +# # +################################################################################ + +################################################################################ +# +# Testcase check-permissions +# +aa_register_case -cats { + db + config +} -on_error { + At least some of the news permission privileges aren't present, or have incorrect + configurations. The most probable cause of this is that the news package datamodel + hasn't been installed. +} "check-permissions" { + Checks the news related permissions. + Checks that the permissions exist, and that they have the correct + heirachy. +} { + # + # Extract the list of all privileges and privilege heirachies. + # + set priv_list {} + db_foreach "get-privileges" { + select privilege from acs_privileges + } { + lappend priv_list $privilege + } + + set priv_h_list {} + db_foreach "get-privilege-heirarchys" { + select privilege, child_privilege from acs_privilege_hierarchy + } { + lappend priv_h_list "$privilege,$child_privilege" + } + + aa_log "Check the news privileges exist" + foreach priv {news_read news_create news_delete news_admin} { + aa_true "Check $priv privilege exists" {[lsearch $priv_list $priv] != -1} + } + + aa_log "Check the news privilege heirachies are correct" + foreach priv_pair {"read,news_read" + "delete,news_delete" + "news_admin,news_read" + "news_admin,news_create" + "news_admin,news_delete" + "admin,news_admin"} { + aa_true "Check $priv_pair privilege exists" {[lsearch $priv_h_list $priv_pair] != -1} + } + + # + # Now check that correct groups have the right privileges. + # + set registered_users_id [acs_magic_object registered_users] + set the_public_id [acs_magic_object the_public] + + aa_log "Check the correct groups have the right privileges." + aa_true "Check public have news_read privilege" \ + [ad_permission_p $the_public_id news_read] + aa_true "Check registered_users have news_create privilege" \ + [ad_permission_p $registered_users_id news_read] +} + + +################################################################################ +# +# Testcase check-views +# +aa_register_case -cats { + db + config +} -on_error { +} "check-views" { + Checks the news related views. + Checks that the views are valid by performing a select from each of them. +} { + aa_log "Check the news_items_approved view." + set error_p 0 + db_transaction { + db_1row select-from-news-items-approved { + select count(*) from news_items_approved + } + } on_error { + set error_p 1 + } + aa_false "Select from news_items_approved view okay" {$error_p} + + + aa_log "Check the news_items_live_or_submitted view." + set error_p 0 + db_transaction { + db_1row select-from-news-items-live-or-submitted { + select count(*) from news_items_live_or_submitted + } + } on_error { + set error_p 1 + } + aa_false "Select from news_items_live_or_submitted view okay" {$error_p} + + + aa_log "Check the news_items_unapproved view." + set error_p 0 + db_transaction { + db_1row select-from-news-items-unapproved { + select count(*) from news_items_unapproved + } + } on_error { + set error_p 1 + } + aa_false "Select from news_items_unapproved view okay" {$error_p} + + + aa_log "Check the news_item_revisions view." + set error_p 0 + db_transaction { + db_1row select-from-news-item-revisions { + select count(*) from news_item_revisions + } + } on_error { + set error_p 1 + } + aa_false "Select from news_item_revisions view okay" {$error_p} + + + aa_log "Check the news_item_unapproved view." + set error_p 0 + db_transaction { + db_1row select-from-news-item-unapproved { + select count(*) from news_item_unapproved + } + } on_error { + set error_p 1 + } + aa_false "Select from news_item_unapproved view okay" {$error_p} + + + aa_log "Check the news_item_full_active view." + set error_p 0 + db_transaction { + db_1row select-from-news-item-full-active { + select count(*) from news_item_full_active + } + } on_error { + set error_p 1 + } + aa_false "Select from news_item_full_active view okay" {$error_p} +} + + +################################################################################ +# +# Testcase check-object-type +# +aa_register_case -cats { + db + config +} -on_error { + The "news" object type doesn't exist, or has isn't configured correctly. + The most probable cause of this is that the news package datamodel hasn't been + installed. +} "check-object-type" { + Checks the news object type. +} { + set news_type_exists_p [db_0or1row "get-news-type-info" { + select supertype + from acs_object_types + where object_type = 'news' + }] + + aa_true "Check news object type exists" {$news_type_exists_p} + + if {$news_type_exists_p} { + aa_equals "Check the supertype is content_revision" $supertype "content_revision" + + db_foreach "get-news-type-attribs" { + select attribute_name + from acs_attributes + where object_type = 'news' + } { + lappend attribs $attribute_name + } + aa_log "Check the news object attributes exist" + foreach attribute_name {"archive_date" + "approval_user" + "approval_date" + "approval_ip"} { + aa_true "Check $attribute_name exists" {[lsearch $attribs $attribute_name] != -1} + } + + set news_folder_exists_p [db_0or1row "get-news-cr-folder" { + select folder_id + from cr_folders + where label = 'news' + }] + aa_true "Check news content_repository folder exists" {$news_folder_exists_p} + } +} + +################################################################################ +# +# Testcase check-package-mount +# +aa_register_case -cats { + db +} -init_classes { + mount-news-package +} -on_error { +} "check-package-mount" { + Checks the mountability of the news package. +} { + aa_true "Check that the news package mount properly" $_news_package_mounted_p + if {$_news_package_mounted_p} { + aa_log "News node_id :$_news_node_id" + aa_log "News package_id :$_news_package_id" + } else { + aa_error "Error from initialiser: $_news_package_mounted_err" + } +} + + +################################################################################ +# +# Testcase db-check-news_create +# +aa_register_case -cats { + db +} -init_classes { + mount-news-package +} "db-check-news-create" { + Creates and deletes a simple news article. Checks contents of cr_news, + cr_items and cr_revisions table after insert. Calls the news name function to retrieve + the article name. Tests news.new, news.delete and news.name. +} { + set news_id -1 + + if {!$_news_package_mounted_p} { + aa_error "News package not mounted, error from initialiser: $_news_package_mounted_err" + } else { + # + # Attempt to create the article + # + set p_title "My title" + set p_text "My text" + set p_package_id $_news_package_id + set p_is_live "t" + set p_full_details "t" + aa_call_component db-news-globals + aa_call_component db-news-item-create + } +} { + aa_true "Check the news_id is populated" {$news_id != -1} + set item_id -1 + if {$news_id != -1} { + aa_log "News id: $news_id" + # + # Retrieve the row from cr_news table and check its contents. Notice that we + # only check the date portion of the date strings. + # + aa_log "Retrieve cr_news row and check its contents" + set p_news_id $news_id + aa_call_component db-get-cr-news-row + if {!$retrieval_ok_p} { + aa_error "cr_news column not found for news_id $news_id" + } else { + aa_equals "Check package_id correct" $package_id $_news_package_id + aa_equals "Check archive_date correct" \ + [string range $archive_date 0 [expr [string length $p_archive_date]-1]] \ + $p_archive_date + aa_equals "Check approval_user correct" $approval_user $p_approval_user + aa_equals "Check approval_date correct" \ + [string range $approval_date 0 [expr [string length $p_approval_date] - 1]] \ + $p_approval_date + aa_equals "Check approval_ip correct" $approval_ip $p_approval_ip + } + + # + # Retrieve the row from cr_revisions table and check its contents. + # NB: The get_cr_revisions_row populates item_id + # + aa_log "Retrieve cr_revisions row and check its contents" + set p_revision_id $news_id + aa_call_component db-get-cr-revisions-row + if {!$retrieval_ok_p} { + aa_error "cr_revisions row not found for news_id (revision_id) $news_id" + } else { + aa_equals "Check title correct" $title $p_title + aa_equals "Check description correct" $description "initial submission" + aa_equals "Check mime_type correct" $mime_type "text/plain" + + # + # Retrieve the row from cr_items table and check its contents. + # + aa_log "Retrieve cr_items row and check its contents" + set p_item_id $item_id + aa_call_component db-get-cr-items-row + if {!$retrieval_ok_p} { + aa_error "cr_items row not found for item_id (revision_id) $news_id" + } else { + aa_equals "Check parent_id correct" $parent_id $_news_cr_news_root_folder_id + aa_equals "Check live_revision correct" $live_revision $news_id + aa_equals "Check latest_revision correct" $latest_revision $news_id + aa_equals "Check publish_status correct" $publish_status "ready" + aa_equals "Check content_type correct" $content_type "news" + + # + # Call the news.name function to retrieve the item name. + # + aa_log "Call news.name function to retrieve title of content revision" + set p_news_id $news_id + set name [db_exec_plsql news-name { + begin + :1 := news.name(news_id => :p_news_id); + end; + }] + aa_equals "Check the return from news.name is correct" $name $p_title + } + } + } +} { + # + # Delete the item. + # + if {$item_id != -1} { + aa_log "Deleting the item." + set p_item_id $item_id + aa_call_component db-news-item-delete + + aa_log "Checking all table data removed." + set p_news_id $news_id + aa_call_component db-get-cr-news-row + aa_false "Check the cr_news row was deleted" {$retrieval_ok_p} + + set p_item_id $item_id + aa_call_component db-get-cr-items-row + aa_false "Check the cr_items row was deleted" {$retrieval_ok_p} + + set p_revision_id $news_id + aa_call_component db-get-cr-revisions-row + aa_false "Check the cr_revisions row was deleted" {$retrieval_ok_p} + } +} + + +################################################################################ +# +# Testcase check-news-revision +# +aa_register_case -cats { + db +} -init_classes { + mount-news-package +} -on_error { + This test may have failed because of a bug in the + content_item.get_latest_revision + database function; where two revisions are created so quickly that they + have the same creation_date value associated with them. This breaks the + logic of the get latest revision function. This problem was found in the + Alpha release of the OpenACS, and may have been fixed in later releases. +

+ A posting + here at the OpenACS bboard was started concerning this problem. +} "db-check-news-revision" { + Checks the news database functions for revision creation, deletion and management. + Tests news.revison_new, news.revision_delete, + news.revision_set_active functions. +} { + set news_id -1 + + if {!$_news_package_mounted_p} { + aa_error "News package not mounted, error from initialiser: $_news_package_mounted_err" + } else { + # + # Create the article + # + set p_title "My title" + set p_text "My text" + set p_package_id $_news_package_id + set p_is_live "t" + set p_full_details "t" + aa_call_component db-news-globals + aa_call_component db-news-item-create + } +} { + aa_true "Check the news_id is populated" {$news_id != -1} + set item_id -1 + set revision1_id -1 + set revision2_id -1 + if {$news_id != -1} { + aa_log "News id: $news_id" + # + # Retrieve the row from cr_revisions table to get item_id + # + set p_revision_id $news_id + aa_call_component db-get-cr-revisions-row + set revision1_id $news_id + + # + # Check the first revision is the latest, and is live. + # + set p_item_id $item_id + aa_call_component db-news-get-live-revision + aa_call_component db-news-get-latest-revision + aa_equals "Confirm that the initial revision of the article is the latest" \ + $latest_revision_id $revision1_id + aa_equals "Confirm that the initial revision of the article is live" \ + $live_revision_id $revision1_id + + # + # Create a new revision of the news article. + # + set p_item_id $item_id + set p_title "My title 2" + set p_text "My text 2" + set p_description "Description 2" + set p_package_id $_news_package_id + set p_full_details "t" + set p_make_active_revision_p "t" + aa_call_component db-news-revision-create + set revision2_id $revision_id + + # + # Retrieve the cr_news column for the new revision + # + set p_news_id $revision2_id + aa_call_component db-get-cr-news-row + if {!$retrieval_ok_p} { + aa_error "cr_news row not found for new revision news_id $revision2_id" + } else { + aa_log "Check the cr_news fields for the second revision" + aa_equals "Check package_id correct" $package_id $_news_package_id + aa_equals "Check archive_date correct" \ + [string range $archive_date 0 [expr [string length $p_archive_date]-1]] \ + $p_archive_date + aa_equals "Check approval_user correct" $approval_user $p_approval_user + aa_equals "Check approval_date correct" \ + [string range $approval_date 0 [expr [string length $p_approval_date] - 1]] \ + $p_approval_date + aa_equals "Check approval_ip correct" $approval_ip $p_approval_ip + + # + # Retrieve the row from cr_revisions table to get item_id + # + set p_revision_id $revision2_id + aa_call_component db-get-cr-revisions-row + if {!$retrieval_ok_p} { + aa_error "cr_revisions row not found for new revision revision_id $revision2_id" + } else { + aa_equals "Check revision2 title correct" $title "My title 2" + aa_equals "Check revision2 description correct" $description "Description 2" + aa_equals "Check revision2 mime_type correct" $mime_type "text/plain" + + # + # Check the second revision is now the latest, and is live. + # + set p_item_id $item_id + aa_call_component db-news-get-live-revision + aa_call_component db-news-get-latest-revision + aa_equals "Confirm that the second revision of the article is the latest" \ + $latest_revision_id $revision2_id + aa_equals "Confirm that the second revision of the article is live" \ + $live_revision_id $revision2_id + + # + # Okay, lets set the original revision as active. + # + aa_log "Reset the first revision as live" + set p_revision_id $revision1_id + aa_call_component db-news-revision-set-active + + # + # Check the second revision is still the latest, but the first one is live. + # + set p_item_id $item_id + aa_call_component db-news-get-live-revision + aa_call_component db-news-get-latest-revision + aa_equals "Confirm that the second revision of the article is still the latest" \ + $latest_revision_id $revision2_id + aa_equals "Confirm that the first revision of the article is now live" \ + $live_revision_id $revision1_id + + # + # Delete the second revision + # + aa_log "Delete the second revision" + set p_revision_id $revision2_id + aa_call_component db-news-revision-delete + + # + # Retrieve the row from cr_revisions table to get item_id + # + set p_revision_id $revision2_id + aa_call_component db-get-cr-revisions-row + aa_false "Check the revision row was deleted" $retrieval_ok_p + } + } + } +} { + # + # Delete the item. + # + if {$item_id != -1} { + aa_log "Deleting item." + set p_item_id $item_id + aa_call_component db-news-item-delete + } +} + +################################################################################ +# +# Testcase check-news-archive +# +aa_register_case -cats { + db +} -init_classes { + mount-news-package +} "db-check-news-archive" { + Checks the news database functions make_permanent and news_archive. +} { + set news_id -1 + + if {!$_news_package_mounted_p} { + aa_error "News package not mounted, error from initialiser: $_news_package_mounted_err" + } else { + # + # Attempt to create the article + # + set p_title "My title" + set p_text "My text" + set p_package_id $_news_package_id + set p_is_live "t" + set p_full_details "t" + aa_call_component db-news-globals + aa_call_component db-news-item-create + } +} { + aa_true "Check the news_id is populated" {$news_id != -1} + set item_id -1 + if {$news_id != -1} { + aa_log "News id: $news_id" + # + # Retrieve the row from cr_revisions table to get item_id + # + set p_revision_id $news_id + aa_call_component db-get-cr-revisions-row + + # + # Call make_permanent to nullify the archive_date. + # + set p_item_id $item_id + aa_call_component db-news-make-permanent + + # + # Retrieve the news row to check its archive date. + # + set p_news_id $news_id + aa_call_component db-get-cr-news-row + aa_equals "Check the archive_date is null" $archive_date [db_null] + + # + # Set the archive period, providing an explicit archive date. + # + set p_item_id $item_id + set p_archive_date "2005-11-05" + aa_call_component db-news-archive + + # + # Retrieve the news row to check its archive date. + # + set p_news_id $news_id + aa_call_component db-get-cr-news-row + aa_equals "Check the explicitly set archive_date is $p_archive_date" \ + [string range $archive_date 0 [expr [string length $p_archive_date] - 1]] \ + $p_archive_date + + # + # Set the archive period, relying on the overloaded "default" function for + # archive_date. + # + set p_item_id $item_id + set p_archive_date "" + aa_call_component db-news-archive + + # + # Retrieve the news row to check its archive date. + # + # Note, this could potentially fail if for some reason it executes over + # midnight...... + # + set p_news_id $news_id + aa_call_component db-get-cr-news-row + aa_true "Check the cr_news row was found" $retrieval_ok_p + set todays_date [clock format [clock seconds] -format "%Y-%m-%d"] + aa_equals "Check the explicitly set archive_date is $todays_date" \ + [string range $archive_date 0 [expr [string length $todays_date] - 1]] \ + $todays_date + } +} { + # + # Delete the item. + # + if {$item_id != -1} { + aa_log "Deleting the item." + set p_item_id $item_id + aa_call_component db-news-item-delete + } +} + + +################################################################################ +# +# Testcase check-news-set-approve +# +aa_register_case -cats { + db +} -init_classes { + mount-news-package +} "db-check-news-set-approve" { + Checks the news database function for approving/unapproving news articles. + Tests news.set_approve function. +} { + set news_id -1 + + if {!$_news_package_mounted_p} { + aa_error "News package not mounted, error from initialiser: $_news_package_mounted_err" + } else { + # + # Create the article + # + set p_title "My title" + set p_text "My text" + set p_package_id $_news_package_id + set p_is_live "t" + set p_full_details "t" + aa_call_component db-news-globals + aa_call_component db-news-item-create + } +} { + aa_true "Check the news_id is populated" {$news_id != -1} + set item_id -1 + set revision1_id -1 + set revision2_id -1 + if {$news_id != -1} { + # + # Retrieve the row from cr_revisions table to get item_id + # + set p_revision_id $news_id + aa_call_component db-get-cr-revisions-row + set revision1_id $news_id + + # + # Create a new revision of the news article. + # + set p_item_id $item_id + set p_title "My title 2" + set p_text "My text 2" + set p_description "Description 2" + set p_package_id $_news_package_id + set p_full_details "t" + set p_make_active_revision_p "t" + aa_call_component db-news-revision-create + set revision2_id $revision_id + + # + # Unapprove revision2. + # + set p_revision_id $revision2_id + set p_approve_p "f" + aa_call_component db-news-set-approve + + # + # Retrieve the cr_news column for revision 2 + # + set p_news_id $revision2_id + aa_call_component db-get-cr-news-row + if {!$retrieval_ok_p} { + aa_error "cr_news row not found for new revision news_id $revision2_id" + } else { + aa_equals "Check the archive_date is null" $archive_date [db_null] + aa_equals "Check the approval_date is null" $approval_date [db_null] + aa_equals "Check the aprroval_user is null" $approval_user [db_null] + aa_equals "Check the approval_ip is null" $approval_ip [db_null] + } + + # + # Retrieve the row from cr_revisions table to check publish date. + # + set p_revision_id $revision2_id + aa_call_component db-get-cr-revisions-row + if {!$retrieval_ok_p} { + aa_error "cr_revisions row not found for new revision revision_id $revision2_id" + } else { + aa_equals "Check revision 2 publish_date is null" $publish_date [db_null] + } + + # + # Approve revision 1 and set it as the live revision. + # + set p_revision_id $revision1_id + set p_approve_p "t" + set p_publish_date "2001-11-01" + set p_archive_date "2001-11-02" + set p_approval_user [ad_conn "user_id"] + set p_approval_date "2001-11-03" + set p_approval_ip [ad_conn "peeraddr"] + set p_live_revision_p "t" + aa_call_component db-news-set-approve + + # + # Check the second revision is now live. + # + set p_item_id $item_id + aa_call_component db-news-get-live-revision + aa_equals "Confirm that revision 1 of the article is now live" \ + $live_revision_id $revision1_id + + # + # Retrieve the cr_news column for revision 1 + # + set p_news_id $revision1_id + aa_call_component db-get-cr-news-row + if {!$retrieval_ok_p} { + aa_error "cr_news row not found for new revision news_id $revision1_id" + } else { + aa_equals "Check the archive_date is correct" \ + [string range $archive_date 0 [expr [string length $p_archive_date]-1]] \ + $p_archive_date + aa_equals "Check the approval_date is correct" \ + [string range $approval_date 0 [expr [string length $p_approval_date]-1]] \ + $p_approval_date + aa_equals "Check the aprroval_user is correct" \ + [string range $approval_user 0 [expr [string length $p_approval_user]-1]] \ + $p_approval_user + aa_equals "Check the approval_ip is correct" \ + [string range $approval_ip 0 [expr [string length $p_approval_ip]-1]] \ + $p_approval_ip + } + + # + # Retrieve the row from cr_revisions table to check publish date. + # + set p_revision_id $revision1_id + aa_call_component db-get-cr-revisions-row + if {!$retrieval_ok_p} { + aa_error "cr_revisions row not found for new revision revision_id $revision1_id" + } else { + aa_equals "Check revision 1 publish_date is null" \ + [string range $publish_date 0 [expr [string length $p_publish_date]-1]] \ + $p_publish_date + } + } +} { + # + # Delete the item. + # + if {$item_id != -1} { + aa_log "Deleting item." + set p_item_id $item_id + aa_call_component db-news-item-delete + } +} + + +################################################################################ +# +# Testcase check-news-status +# +aa_register_case -cats { + db +} -init_classes { + mount-news-package +} "db-check-news-status" { + Checks the news database function that returns information about a news article publish + and archive status. + Tests news.status function. +} { + set news_id -1 + + if {!$_news_package_mounted_p} { + aa_error "News package not mounted, error from initialiser: $_news_package_mounted_err" + } else { + # + # Create the article + # + set p_title "My title" + set p_text "My text" + set p_package_id $_news_package_id + set p_is_live "t" + set p_full_details "t" + aa_call_component db-news-globals + aa_call_component db-news-item-create + } +} { + aa_true "Check the news_id is populated" {$news_id != -1} + set item_id -1 + set revision1_id -1 + set revision2_id -1 + if {$news_id != -1} { + # + # Retrieve the row from cr_revisions table to get item_id + # + set p_revision_id $news_id + aa_call_component db-get-cr-revisions-row + set revision1_id $news_id + + # + # Unapprove revision 1 and set it as the live revision. + # + aa_log "Unapproving revision 1, setting publish_date null, archive_date null" + set p_revision_id $revision1_id + set p_approve_p "t" + set p_publish_date [db_null] + set p_archive_date [db_null] + set p_approval_user [ad_conn "user_id"] + set p_approval_date [db_null] + set p_approval_ip [ad_conn "peeraddr"] + set p_live_revision_p "t" + aa_call_component db-news-set-approve + + # + # Check the status of revision 1. + # + aa_log "Calling news.status function on revision 1" + aa_log "Should be unapproved" + set p_news_id $revision1_id + aa_call_component db-news-status + aa_log "Status string is \"$status\"" + aa_true "Check status string contains \"unapproved\"" \ + {[string first "unapproved" $status] != -1} + + # + # Approve revision 1 and set it as the live revision. + # + aa_log "Approving revision 1, setting archive date as null" + set p_revision_id $revision1_id + set p_approve_p "t" + set p_publish_date "2005-11-01" + set p_archive_date [db_null] + set p_approval_user [ad_conn "user_id"] + set p_approval_date "2001-11-03" + set p_approval_ip [ad_conn "peeraddr"] + set p_live_revision_p "t" + aa_call_component db-news-set-approve + + # + # Check the status of revision 1. + # + aa_log "Calling news.status function on revision 1" + aa_log "Should be going live and not scheduled for archive" + set p_news_id $revision1_id + aa_call_component db-news-status + aa_log "Returned status = \"$status\"" + aa_true "Check status string contains \"going live in\"" \ + {[string first "going live in" $status] != -1} + aa_true "Check status string doesn't contain \"archived in\"" \ + {[string first "archived in" $status] == -1} + + # + # Approve revision 1 and set it as the live revision. + # + aa_log "Approving revision 1, setting archive date as future value" + set p_revision_id $revision1_id + set p_approve_p "t" + set p_publish_date "2005-11-01" + set p_archive_date "2005-11-10" + set p_approval_user [ad_conn "user_id"] + set p_approval_date "2001-11-03" + set p_approval_ip [ad_conn "peeraddr"] + set p_live_revision_p "t" + aa_call_component db-news-set-approve + + # + # Check the status of revision 1. + # + aa_log "Calling news.status function on revision 1" + aa_log "Should be going live and scheduled for archive" + set p_news_id $revision1_id + aa_call_component db-news-status + aa_log "Returned status = \"$status\"" + aa_true "Check status string contains \"going live in\"" \ + {[string first "going live in" $status] != -1} + aa_true "Check status string contains \"archived in\"" \ + {[string first "archived in" $status] != -1} + + # + # Approve revision 1 and set it as the live revision. + # + aa_log "Approving revision 1, setting publish date in past, archive date null" + set p_revision_id $revision1_id + set p_approve_p "t" + set p_publish_date "2000-11-01" + set p_archive_date [db_null] + set p_approval_user [ad_conn "user_id"] + set p_approval_date "2001-11-03" + set p_approval_ip [ad_conn "peeraddr"] + set p_live_revision_p "t" + aa_call_component db-news-set-approve + + # + # Check the status of revision 1. + # + aa_log "Calling news.status function on revision 1" + aa_log "Should be published, and not scheduled for archive" + set p_news_id $revision1_id + aa_call_component db-news-status + aa_log "Returned status = \"$status\"" + aa_true "Check status string contains \"published\"" \ + {[string first "published" $status] != -1} + aa_true "Check status string contains \"not scheduled for archive\"" \ + {[string first "not scheduled for archive" $status] != -1} + + # + # Approve revision 1 and set it as the live revision. + # + aa_log "Approving revision 1, setting publish date in past, archive date in past" + set p_revision_id $revision1_id + set p_approve_p "t" + set p_publish_date "2000-11-01" + set p_archive_date "2000-11-01" + set p_approval_user [ad_conn "user_id"] + set p_approval_date "2001-11-03" + set p_approval_ip [ad_conn "peeraddr"] + set p_live_revision_p "t" + aa_call_component db-news-set-approve + + # + # Check the status of revision 1. + # + aa_log "Calling news.status function on revision 1" + aa_log "Should be archived" + set p_news_id $revision1_id + aa_call_component db-news-status + aa_log "Returned status = \"$status\"" + aa_true "Check status string contains \"archived in\"" \ + {[string first "archived" $status] != -1} + + # + # Approve revision 1 and set it as the live revision. + # + aa_log "Approving revision 1, setting publish date in past, archive date in future" + set p_revision_id $revision1_id + set p_approve_p "t" + set p_publish_date "2000-11-01" + set p_archive_date "2005-11-01" + set p_approval_user [ad_conn "user_id"] + set p_approval_date "2001-11-03" + set p_approval_ip [ad_conn "peeraddr"] + set p_live_revision_p "t" + aa_call_component db-news-set-approve + + # + # Check the status of revision 1. + # + aa_log "Calling news.status function on revision 1" + aa_log "Should be published, schedule for archive in future" + set p_news_id $revision1_id + aa_call_component db-news-status + aa_log "Returned status = \"$status\"" + aa_true "Check status string contains \"published\"" \ + {[string first "published" $status] != -1} + aa_true "Check status string contains \"archived in\"" \ + {[string first "archived in" $status] != -1} + } +} { + # + # Delete the item. + # + if {$item_id != -1} { + aa_log "Deleting item." + set p_item_id $item_id + aa_call_component db-news-item-delete + } +} Index: openacs-4/packages/news/tcl/test/news-db-test-init.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/news/tcl/test/news-db-test-init.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/news/tcl/test/news-db-test-init.xql 4 Apr 2003 09:48:13 -0000 1.1 @@ -0,0 +1,114 @@ + + + + + + select item_id + from cr_items + where parent_id = :p_parent_id + and name = 'news' + + + + + + select news_id, package_id, archive_date, + approval_user, approval_date, approval_ip + from cr_news + where news_id = :p_news_id + + + + + + select item_id, title, description, publish_date, mime_type, + nls_language, content, content_length + from cr_revisions + where revision_id = :p_revision_id + + + + + + + select parent_id, name, live_revision, latest_revision, + publish_status, content_type + from cr_items + where item_id = :p_item_id + + + + + + + select privilege from acs_privileges + + + + + + select privilege, child_privilege from acs_privilege_hierarchy + + + + + + select object_type, supertype + from acs_object_types + where object_type = 'news' + + + + + + select attribute_name + from acs_attributes + where object_type = 'news' + + + + + + select folder_id + from cr_folders + where label = 'news' + + + + + + select count(*) from news_items_approved + + + + + + select count(*) from news_items_live_or_submitted + + + + + + select count(*) from news_items_unapproved + + + + + + select count(*) from news_item_revisions + + + + + + select count(*) from news_item_unapproved + + + + + + select count(*) from news_item_full_active + + + + Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/news/tcl/test/news-db-test-procs-oracle.xql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/news/tcl/test/news-db-test-procs-postgresql.xql'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/news/tcl/test/news-db-test-procs.tcl'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1.2 refers to a dead (removed) revision in file `openacs-4/packages/news/tcl/test/news-db-test-procs.xql'. Fisheye: No comparison available. Pass `N' to diff? Index: openacs-4/packages/workflow/tcl/test/workflow-test-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/tcl/test/Attic/workflow-test-init.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/workflow/tcl/test/workflow-test-init.tcl 4 Apr 2003 09:48:41 -0000 1.1 @@ -0,0 +1,95 @@ +ad_library { + Register acs-automated-testing test cases for the workflow + package on server startup. + + @author Peter Marklund + @creation-date 10 January 2003 + @cvs-id $Id: workflow-test-init.tcl,v 1.1 2003/04/04 09:48:41 peterm Exp $ +} + +##### +# +# Register the test cases +# +##### + +aa_register_case bugtracker_workflow_create_normal { + Test creation and teardown of an FSM workflow case. + + @author Peter Marklund + @creation-date 16 January 2003 +} { + workflow::test::run_bug_tracker_test -create_proc "workflow::test::workflow_setup" +} + +aa_register_case bugtracker_workflow_create_array_style { + Test creation and teardown of an FSM workflow case, with array style specification. + + @author Lars Pind + @creation-date 21 January 2003 +} { + workflow::test::run_bug_tracker_test -create_proc "workflow::test::workflow_setup_array_style" +} + +aa_register_case bugtracker_workflow_clone { + Test creation and teardown of cloning an FSM workflow case. + + @author Lars Pind + @creation-date 22 January 2003 +} { + set workflow_id_list [list] + set test_chunk { + set workflow_id_1 [workflow::test::workflow_setup] + lappend workflow_id_list $workflow_id_1 + set workflow_id_2 [workflow::fsm::clone -workflow_id $workflow_id_1 -object_id [workflow::test::workflow_object_id_2]] + lappend workflow_id_list $workflow_id_2 + + set spec_1 [workflow::fsm::generate_spec -workflow_id $workflow_id_1] + set spec_2 [workflow::fsm::generate_spec -workflow_id $workflow_id_2] + + aa_true "Generated spec from original and cloned workflow should be identical" \ + [string equal $spec_1 $spec_2] + } + + set error_p [catch $test_chunk errMsg] + + # Teardown + foreach workflow_id $workflow_id_list { + workflow::delete -workflow_id $workflow_id + } + + if { $error_p } { + global errorInfo + aa_false "error during setup: $errMsg - $errorInfo" $error_p + } +} + +aa_register_case workflow_spec_with_message_keys { + Test creating a workflow from a spec with message catalog + keys in it and then generating a spec from that workflow + and making sure that the spec is preserved (message keys are not + localized) + + @author Peter Marklund +} { + set test_chunk { + + set workflow_id [workflow::fsm::new_from_spec \ + -spec [workflow::test::get_message_key_spec]] + + set generated_spec [workflow::fsm::generate_spec -workflow_id $workflow_id] + + ns_log Notice "LARS: Generated spec 2: $generated_spec" + ns_log Notice "LARS: Hard-coded spec 2: [workflow::test::get_message_key_spec]" + + aa_true "Checking that generated spec 2 is identical to the spec that we created from (except for ordering)" \ + [array_lists_equal_p $generated_spec [workflow::test::get_message_key_spec]] + } + + set teardown_chunk { + set workflow_id [workflow::get_id -package_key acs-automated-testing -short_name test_message_keys] + workflow::delete -workflow_id $workflow_id + } + + workflow::test::run_with_teardown $test_chunk $teardown_chunk +} Index: openacs-4/packages/workflow/tcl/test/workflow-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/tcl/test/workflow-test-procs.tcl,v diff -u -r1.6 -r1.7 --- openacs-4/packages/workflow/tcl/test/workflow-test-procs.tcl 5 Mar 2003 17:18:38 -0000 1.6 +++ openacs-4/packages/workflow/tcl/test/workflow-test-procs.tcl 4 Apr 2003 09:48:41 -0000 1.7 @@ -1,6 +1,6 @@ ad_library { - Test cases for the Tcl API of the workflow package. The test cases are based - on the acs-automated-testing package. + Test helper procedure library for the acs-automated-testing tests + of the workflow package. @author Peter Marklund @creation-date 10 January 2003 @@ -580,93 +580,3 @@ aa_false "error during setup: $errMsg - $errorInfo" $error_p } } - - - - -##### -# -# Register the test cases -# -##### - -aa_register_case bugtracker_workflow_create_normal { - Test creation and teardown of an FSM workflow case. - - @author Peter Marklund - @creation-date 16 January 2003 -} { - workflow::test::run_bug_tracker_test -create_proc "workflow::test::workflow_setup" -} - -aa_register_case bugtracker_workflow_create_array_style { - Test creation and teardown of an FSM workflow case, with array style specification. - - @author Lars Pind - @creation-date 21 January 2003 -} { - workflow::test::run_bug_tracker_test -create_proc "workflow::test::workflow_setup_array_style" -} - -aa_register_case bugtracker_workflow_clone { - Test creation and teardown of cloning an FSM workflow case. - - @author Lars Pind - @creation-date 22 January 2003 -} { - set workflow_id_list [list] - set test_chunk { - set workflow_id_1 [workflow::test::workflow_setup] - lappend workflow_id_list $workflow_id_1 - set workflow_id_2 [workflow::fsm::clone -workflow_id $workflow_id_1 -object_id [workflow::test::workflow_object_id_2]] - lappend workflow_id_list $workflow_id_2 - - set spec_1 [workflow::fsm::generate_spec -workflow_id $workflow_id_1] - set spec_2 [workflow::fsm::generate_spec -workflow_id $workflow_id_2] - - aa_true "Generated spec from original and cloned workflow should be identical" \ - [string equal $spec_1 $spec_2] - } - - set error_p [catch $test_chunk errMsg] - - # Teardown - foreach workflow_id $workflow_id_list { - workflow::delete -workflow_id $workflow_id - } - - if { $error_p } { - global errorInfo - aa_false "error during setup: $errMsg - $errorInfo" $error_p - } -} - -aa_register_case workflow_spec_with_message_keys { - Test creating a workflow from a spec with message catalog - keys in it and then generating a spec from that workflow - and making sure that the spec is preserved (message keys are not - localized) - - @author Peter Marklund -} { - set test_chunk { - - set workflow_id [workflow::fsm::new_from_spec \ - -spec [workflow::test::get_message_key_spec]] - - set generated_spec [workflow::fsm::generate_spec -workflow_id $workflow_id] - - ns_log Notice "LARS: Generated spec 2: $generated_spec" - ns_log Notice "LARS: Hard-coded spec 2: [workflow::test::get_message_key_spec]" - - aa_true "Checking that generated spec 2 is identical to the spec that we created from (except for ordering)" \ - [array_lists_equal_p $generated_spec [workflow::test::get_message_key_spec]] - } - - set teardown_chunk { - set workflow_id [workflow::get_id -package_key acs-automated-testing -short_name test_message_keys] - workflow::delete -workflow_id $workflow_id - } - - workflow::test::run_with_teardown $test_chunk $teardown_chunk -}