From 0932803a2c0a61924209dfe277dec32bced63c0c Mon Sep 17 00:00:00 2001 From: webchick Date: Mon, 26 Mar 2012 22:25:40 -0700 Subject: =?UTF-8?q?Issue=20#1221276=20by=20gumanist,=20fietserwin,=20G?= =?UTF-8?q?=C3=A1bor=20Hojtsy,=20sun,=20kalman.hosszu:=20Fixed=20locale=5F?= =?UTF-8?q?get=5Fplural()=20only=20works=20for=20a=20single=20language=20w?= =?UTF-8?q?ithin=20a=20request=20and=20does=20not=20work=20for=20English.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/locale/tests/locale_test.module | 124 ++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) (limited to 'modules/locale/tests/locale_test.module') diff --git a/modules/locale/tests/locale_test.module b/modules/locale/tests/locale_test.module index 2af50a69d..64f4aed57 100644 --- a/modules/locale/tests/locale_test.module +++ b/modules/locale/tests/locale_test.module @@ -54,6 +54,22 @@ function locale_test_language_types_info() { } } +/** + * Implements hook_menu(). + * + * @return array + */ +function locale_test_menu() { + $items = array(); + $items['locale_test_plural_format_page'] = array( + 'page callback' => 'locale_test_plural_format_page', + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + ); + + return $items; +} + /** * Implements hook_language_types_info_alter(). */ @@ -116,3 +132,111 @@ function locale_test_store_language_negotiation() { function locale_test_language_provider($languages) { return 'it'; } + +/** + * Returns markup for locale_get_plural testing. + * + * @return array + */ +function locale_test_plural_format_page() { + $tests = _locale_test_plural_format_tests(); + $result = array(); + foreach ($tests as $test) { + $string_param = array( + '@lang' => $test['language'], + '@locale_get_plural' => locale_get_plural($test['count'], $test['language']) + ); + $result[] = array( + '#prefix' => '
', + '#markup' => format_string('Language: @lang, locale_get_plural: @locale_get_plural.', $string_param), + ); + } + return $result; +} + +/** + * Helper function with list of test cases + * + * @return array + */ +function _locale_test_plural_format_tests() { + return array( + // Test data for English (no formula present). + array( + 'count' => 1, + 'language' => 'en', + 'expected-result' => 0, + ), + array( + 'count' => 0, + 'language' => 'en', + 'expected-result' => 1, + ), + array( + 'count' => 5, + 'language' => 'en', + 'expected-result' => 1, + ), + + // Test data for French (simpler formula). + array( + 'count' => 1, + 'language' => 'fr', + 'expected-result' => 0, + ), + array( + 'count' => 0, + 'language' => 'fr', + 'expected-result' => 1, + ), + array( + 'count' => 5, + 'language' => 'fr', + 'expected-result' => 1, + ), + + // Test data for Croatian (more complex formula). + array( + 'count' => 1, + 'language' => 'hr', + 'expected-result' => 0, + ), + array( + 'count' => 21, + 'language' => 'hr', + 'expected-result' => 0, + ), + array( + 'count' => 0, + 'language' => 'hr', + 'expected-result' => 2, + ), + array( + 'count' => 2, + 'language' => 'hr', + 'expected-result' => 1, + ), + array( + 'count' => 8, + 'language' => 'hr', + 'expected-result' => 2, + ), + + // Test data for Hungarian (nonexistent language). + array( + 'count' => 1, + 'language' => 'hu', + 'expected-result' => -1, + ), + array( + 'count' => 21, + 'language' => 'hu', + 'expected-result' => -1, + ), + array( + 'count' => 0, + 'language' => 'hu', + 'expected-result' => -1, + ), + ); +} -- cgit v1.2.3