Index: openacs-4/packages/acs-lang/tcl/test/acs-lang-localization-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/test/acs-lang-localization-procs.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/acs-lang/tcl/test/acs-lang-localization-procs.tcl 7 Aug 2017 23:47:57 -0000 1.3 +++ openacs-4/packages/acs-lang/tcl/test/acs-lang-localization-procs.tcl 22 Jul 2018 09:46:48 -0000 1.4 @@ -17,6 +17,10 @@ lc_time_utc_to_local lc_time_local_to_utc + lang::catalog::import + lang::catalog::import + lang::system::locale_set_enabled + } lang_test__lc_numeric { Minimal testset for localization functions. To be extended. @@ -32,22 +36,22 @@ lang::catalog::import -locales it_IT -package_key acs-lang lang::catalog::import -locales de_DE -package_key acs-lang - + aa_equals "format us number" [lc_numeric 123456.789 {} en_US] 123,456.789 aa_equals "format de number" [lc_numeric 123456.789 {} de_DE] 123.456,789 aa_equals "format it number" [lc_numeric 123456.789 {} it_IT] 123.456,789 aa_equals "parse us number" [lc_parse_number 123,456.789 en_US] 123456.789 aa_equals "parse de number" [lc_parse_number 123.456,789 de_DE] 123456.789 aa_equals "parse it number" [lc_parse_number 123.456,789 it_IT] 123456.789 - - set time [lc_time_fmt "2013-09-21 23:11:22" "%c" en_US] + + set time [lc_time_fmt "2013-09-21 23:11:22" "%c" en_US] aa_equals "format us time" [lrange $time 0 end-1] "Sat September 21, 2013 11:11 PM" - set time [lc_time_fmt "2013-09-21 23:11:22" "%c" de_DE] + set time [lc_time_fmt "2013-09-21 23:11:22" "%c" de_DE] aa_equals "format us time" [lrange $time 0 end-1] "Sa, 21. September 2013 23:11" - set time [lc_time_fmt "2013-09-21 23:11:22" "%c" it_IT] + set time [lc_time_fmt "2013-09-21 23:11:22" "%c" it_IT] aa_equals "format us time" [lrange $time 0 end-1] "Sab 21 Settembre 2013 23:11" aa_equals "asian time " [lc_time_utc_to_local "2013-09-21 23:11:22" "Asia/Tokyo"] "2013-09-22 08:11:22" Index: openacs-4/packages/acs-lang/tcl/test/acs-lang-message-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/test/acs-lang-message-procs.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/acs-lang/tcl/test/acs-lang-message-procs.tcl 7 Aug 2017 23:47:57 -0000 1.2 +++ openacs-4/packages/acs-lang/tcl/test/acs-lang-message-procs.tcl 22 Jul 2018 09:46:48 -0000 1.3 @@ -4,31 +4,37 @@ @creation-date 11 Aug 2006 } -aa_register_case -cats {smoke api} \ - -procs {lang::message::register lang::message::get} \ - test_message_register { +aa_register_case \ + -cats {smoke api} \ + -procs { + lang::message::register + lang::message::get + } \ + test_message_register { Simple test that registrates a new message to the BD. - + } { aa_run_with_teardown -rollback -test_code { - set message_key [ad_generate_random_string] + set message_key [ad_generate_random_string] set message [ad_generate_random_string] set package_key "acs-translations" set locale "en_US" aa_log "Creating message : $message || message key: $message_key" - + # Creates the new message lang::message::register $locale $package_key $message_key $message # Try to retrieve the new message created. - lang::message::get -package_key $package_key -message_key $message_key -locale $locale -array message_new + lang::message::get \ + -package_key $package_key \ + -message_key $message_key \ + -locale $locale \ + -array message_new - aa_true "Message add succeeded" [string equal $message_new(message) $message] - + aa_equals "Message add succeeded" $message_new(message) $message } - } 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.26 -r1.27 --- openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl 19 Jul 2018 15:34:39 -0000 1.26 +++ openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl 22 Jul 2018 09:46:48 -0000 1.27 @@ -109,11 +109,19 @@ -array message_actual # Check message properties - aa_equals "Import check: $message_key - lang_messages.message" $message_actual(message) $expect_message - aa_equals "Import check: $message_key - lang_messages.deleted_p" $message_actual(deleted_p) $expect_property(deleted_p) - aa_equals "Import check: $message_key - lang_messages.conflict_p" $message_actual(conflict_p) $expect_property(conflict_p) + aa_equals "Import check: $message_key - lang_messages.message" \ + $message_actual(message) \ + $expect_message + aa_equals "Import check: $message_key - lang_messages.deleted_p" \ + $message_actual(deleted_p) \ + $expect_property(deleted_p) + aa_equals "Import check: $message_key - lang_messages.conflict_p" \ + $message_actual(conflict_p) \ + $expect_property(conflict_p) aa_equals "Import check: $message_key - lang_messages.upgrade_status" \ - $message_actual(upgrade_status) $expect_property(upgrade_status) + $message_actual(upgrade_status) \ + $expect_property(upgrade_status) + if {$expect_property(sync_time) eq "not_null"} { aa_true "Import check: $message_key - lang_messages.sync_time not null" \ {$message_actual(sync_time) ne ""} @@ -467,11 +475,14 @@ aa_register_case \ -procs { - lang::util::replace_temporary_tags_with_lookups lang::catalog::export_to_file + lang::catalog::package_catalog_dir lang::catalog::parse lang::catalog::read_file + lang::message::unregister + lang::test::get_dir lang::util::get_temporary_tags_indices + lang::util::replace_temporary_tags_with_lookups } util__replace_temporary_tags_with_lookups { A test Tcl file and catalog file are created. The temporary tags in the @@ -537,25 +548,29 @@ # 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)] + aa_equals "old key $old_message_key should be unchanged" \ + $messages_array($old_message_key) \ + $updated_messages_array($old_message_key) } # Check that the first new key was autogenerated - aa_true "check autogenerated key" [string equal $updated_messages_array(Auto_Key) $new_text_1] + aa_equals "check autogenerated key" $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] + aa_equals "check key made unique" $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)] + aa_equals "third key not inserted" \ + [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::rootdir/$tcl_file" r] set updated_tcl_contents [read $tcl_file_id] close $tcl_file_id - aa_true "tags in Tcl file replaced" {[llength [lang::util::get_temporary_tags_indices $updated_tcl_contents]] == 0} + aa_equals "tags in Tcl file replaced" \ + [llength [lang::util::get_temporary_tags_indices $updated_tcl_contents]] \ + 0 # Delete the test message keys foreach message_key [concat [array names messages_array] $expected_new_keys] { @@ -588,11 +603,11 @@ foreach index_item $indices_list { set expected_index_item [lindex $expected_indices_list $counter] - aa_true "checking start and end indices of item $counter" \ - {[lindex $index_item 0] eq [lindex $expected_index_item 0] - && [lindex $index_item 1] eq [lindex $expected_index_item 1]} - - set counter [expr {$counter + 1}] + aa_true "checking start and end indices of item $counter" { + [lindex $index_item 0] eq [lindex $expected_index_item 0] + && [lindex $index_item 1] eq [lindex $expected_index_item 1] + } + incr counter } } @@ -628,6 +643,7 @@ aa_register_case \ -procs { + lang::test::get_dir lang::util::replace_adp_text_with_message_tags } util__replace_adp_text_with_message_tags { @@ -693,6 +709,8 @@ aa_register_case \ -procs { lang::message::get_embedded_vars + util_get_subset_missing + util_sets_equal_p } message__get_embedded_vars { @author Peter Marklund (peter@collaboraid.biz) @@ -734,18 +752,25 @@ aa_register_case \ -procs { - lang::system::set_locale + apm_package_id_from_key lang::system::locale + lang::system::locale + lang::system::set_locale lang::system::site_wide_locale + parameter::set_value } locale__test_system_package_setting { Tests whether the system package level setting works @author Lars Pind (lars@collaboraid.biz) @creation-date 2003-08-12 } { - set use_package_level_locales_p_org [parameter::get -parameter UsePackageLevelLocalesP -package_id [apm_package_id_from_key "acs-lang"]] + set use_package_level_locales_p_org [parameter::get \ + -parameter UsePackageLevelLocalesP \ + -package_id [apm_package_id_from_key "acs-lang"]] - parameter::set_value -parameter UsePackageLevelLocalesP -package_id [apm_package_id_from_key "acs-lang"] -value 1 + parameter::set_value \ + -parameter UsePackageLevelLocalesP \ + -package_id [apm_package_id_from_key "acs-lang"] -value 1 # There's no foreign key constraint on the locales column, so this @@ -774,12 +799,15 @@ -value $use_package_level_locales_p_org } - aa_true "Retrieved system locale ('$retrieved_locale') equals the one we just set ('$locale_to_set')" [string equal $locale_to_set $retrieved_locale] + aa_equals "Retrieved system locale ('$retrieved_locale') equals the one we just set ('$locale_to_set')" \ + $locale_to_set \ + $retrieved_locale } aa_register_case \ -procs { lang::conn::browser_locale + lang::system::locale_set_enabled } locale__test_lang_conn_browser_locale { @author Peter Marklund @@ -831,9 +859,13 @@ aa_register_case \ -procs { - lang::user::set_timezone + lang::conn::timezone lang::system::set_timezone lang::system::timezone + lang::system::timezone_support_p + lang::user::set_timezone + lang::user::timezone + lc_list_all_timezones } set_get_timezone { Test that setting and getting user timezone works @@ -865,7 +897,9 @@ ad_try { # User timezone lang::user::set_timezone $desired_user_timezone - aa_equals "User timezone retrieved is the same as the one set" [lang::user::timezone] $desired_user_timezone + aa_equals "User timezone retrieved is the same as the one set" \ + [lang::user::timezone] \ + $desired_user_timezone # Storage set user_id [ad_conn user_id] @@ -876,17 +910,25 @@ # System timezone lang::system::set_timezone $desired_system_timezone - aa_equals "System timezone retrieved is the same as the one set" [lang::system::timezone] $desired_system_timezone + aa_equals "System timezone retrieved is the same as the one set" \ + [lang::system::timezone] \ + $desired_system_timezone # Connection timezone - aa_equals "Using user timezone" [lang::conn::timezone] $desired_user_timezone + aa_equals "Using user timezone" \ + [lang::conn::timezone] \ + $desired_user_timezone ad_conn -set isconnected 0 - aa_equals "Fallback to system timezone when no connection" [lang::conn::timezone] $desired_system_timezone + aa_equals "Fallback to system timezone when no connection" \ + [lang::conn::timezone] \ + $desired_system_timezone ad_conn -set isconnected 1 lang::user::set_timezone {} - aa_equals "Fallback to system timezone when no user pref" [lang::conn::timezone] $desired_system_timezone + aa_equals "Fallback to system timezone when no user pref" \ + [lang::conn::timezone] \ + $desired_system_timezone } on error {errorMsg} { set error_p 1 @@ -903,8 +945,10 @@ aa_register_case \ -procs { - lang::user::set_timezone + lang::conn::timezone lang::system::timezone + lang::system::timezone_support_p + lang::user::set_timezone } set_timezone_not_logged_in { Test that setting and getting user timezone throws an error when user is not logged in } { @@ -914,7 +958,9 @@ set user_id [ad_conn user_id] ad_conn -set user_id 0 - aa_equals "Fallback to system timezone when no user" [lang::conn::timezone] [lang::system::timezone] + aa_equals "Fallback to system timezone when no user" \ + [lang::conn::timezone] \ + [lang::system::timezone] set error_p [catch { lang::user::set_timezone [lang::system::timezone] } errmsg] aa_true "Error when setting user timezone when user not logged in" $error_p @@ -924,15 +970,22 @@ } } -aa_register_case lc_time_fmt_Z_timezone { +aa_register_case \ + -procs { + lang::conn::timezone + lc_time_fmt + } lc_time_fmt_Z_timezone { lc_time_fmt %Z returns current connection timezone } { - aa_equals "%Z returns current timezone" [lc_time_fmt "2003-08-15 13:40:00" "%Z"] [lang::conn::timezone] + aa_equals "%Z returns current timezone" \ + [lc_time_fmt "2003-08-15 13:40:00" "%Z"] \ + [lang::conn::timezone] } aa_register_case \ -procs { lang::message::lookup + lang::message::register } locale_language_fallback { Test that we fall back to 'default locale for language' when requesting a message which exists in default locale for language, but not in the current locale @@ -975,6 +1028,11 @@ lang::catalog::import lang::message::edit lang::message::get + lang::message::unregister + lang::system::locale_set_enabled + lang::test::execute_upgrade + lang::test::setup_test_package + lang::test::teardown_test_package } upgrade { Test that a package can be upgraded with new catalog files and that the resulting keys and messages @@ -1011,6 +1069,8 @@ } aa_register_case -procs { + lang::message::register + lang::message::unregister lang::util::localize } localize { @@ -1034,34 +1094,48 @@ # Test replacements set text1 $message_key_embedded - aa_equals "One message key with no surrounding text" [lang::util::localize $text1] "${message}" + aa_equals "One message key with no surrounding text" \ + [lang::util::localize $text1] \ + $message set text1 "${pre_text}${message_key_embedded}${post_text}" - aa_equals "One message key with surrounding text" [lang::util::localize $text1] "${pre_text}${message}${post_text}" + aa_equals "One message key with surrounding text" \ + [lang::util::localize $text1] \ + "${pre_text}${message}${post_text}" set text1 "${pre_text}${message_key_embedded}" - aa_equals "One message key with text before" [lang::util::localize $text1] "${pre_text}${message}" + aa_equals "One message key with text before" \ + [lang::util::localize $text1] \ + "${pre_text}${message}" set text1 "${message_key_embedded}${post_text}" - aa_equals "One message key with text after" [lang::util::localize $text1] "${message}${post_text}" + aa_equals "One message key with text after" \ + [lang::util::localize $text1] \ + "${message}${post_text}" set text1 "${pre_text}${message_key_embedded}${post_text}${pre_text}${message_key_embedded}${post_text}" - aa_equals "Two message keys with surrounding text" [lang::util::localize $text1] \ + aa_equals "Two message keys with surrounding text" \ + [lang::util::localize $text1] \ "${pre_text}${message}${post_text}${pre_text}${message}${post_text}" } -teardown_code { # We need to clear the cache lang::message::unregister $package_key $message_key } } -aa_register_case lang_messages_correct { +aa_register_case \ + -procs { + lang::message::check + } lang_messages_correct { This test calls the checks to ensure a message is correct on every message in the system } { aa_run_with_teardown -rollback -test_code { - db_foreach query " - select message_key, package_key, locale, message from lang_messages" { + foreach tuple [db_list_of_lists get_message_keys { + select message_key, package_key, locale, message from lang_messages + }] { + lassign $tuple message_key package_key locale message aa_false "Message $message_key in package $package_key for locale $locale correct" \ - [catch {lang::message::check $locale $package_key $message_key $message}] + [catch {lang::message::check $locale $package_key $message_key $message}] } } }