aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2011-09-20 01:39:21 +0200
committerOleg Pudeyev <oleg@bsdpower.com>2011-11-25 15:10:49 -0500
commit2de7153afd428f44d1c4c012ffe0bf072e449c64 (patch)
tree9370ea2b97dc97c1de92cff727a379e6f9976395
parent179662e949967090724c5e14ea4d4d399886a38a (diff)
downloadforums-2de7153afd428f44d1c4c012ffe0bf072e449c64.tar
forums-2de7153afd428f44d1c4c012ffe0bf072e449c64.tar.gz
forums-2de7153afd428f44d1c4c012ffe0bf072e449c64.tar.bz2
forums-2de7153afd428f44d1c4c012ffe0bf072e449c64.tar.xz
forums-2de7153afd428f44d1c4c012ffe0bf072e449c64.zip
[ticket/10345] Allow float as array key and add some tests
Added tests for the fallback when a key is missing and the float-feature. PHPBB3-10345
-rw-r--r--phpBB/includes/session.php6
-rw-r--r--tests/user/lang_test.php18
2 files changed, 22 insertions, 2 deletions
diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php
index 0733e4f7fb..3e3c9dc072 100644
--- a/phpBB/includes/session.php
+++ b/phpBB/includes/session.php
@@ -1869,7 +1869,7 @@ class user extends session
// We now get the first number passed and will select the key based upon this number
for ($i = 1, $num_args = sizeof($args); $i < $num_args; $i++)
{
- if (is_int($args[$i]))
+ if (is_int($args[$i]) || is_float($args[$i]))
{
$use_plural_form = $this->get_plural_form($args[$i]);
$numbers = array_keys($lang);
@@ -1905,12 +1905,14 @@ class user extends session
* Determine which plural form we should use.
* For some languages this is not as simple as for English.
*
- * @param $number int The number we want to get the plural case for
+ * @param $number int|float The number we want to get the plural case for
* @param $force_rule mixed False to use the plural rule of the language package
* or an integer to force a certain plural rule
*/
function get_plural_form($number, $force_rule = false)
{
+ $number = (int) $number;
+
if ($number == 0)
{
// We use special language strings for 0, so it's "no users" instead of "0 users"
diff --git a/tests/user/lang_test.php b/tests/user/lang_test.php
index 90b0cdfb0f..971a9475f0 100644
--- a/tests/user/lang_test.php
+++ b/tests/user/lang_test.php
@@ -26,6 +26,14 @@ class phpbb_user_lang_test extends phpbb_test_case
1 => '1 post', // 1
2 => '%d posts', // 2+
),
+ 'ARRY_NO_ZERO' => array(
+ 1 => '1 post', // 1
+ 2 => '%d posts', // 0, 2+
+ ),
+ 'ARRY_FLOAT' => array(
+ 1 => '1 post', // 1.x
+ 2 => '%1$.1f posts', // 0.x, 2+.x
+ ),
);
// No param
@@ -51,6 +59,16 @@ class phpbb_user_lang_test extends phpbb_test_case
$this->assertEquals($user->lang('ARRY', 2), '2 posts');
$this->assertEquals($user->lang('ARRY', 123), '123 posts');
+ // Array with missing keys
+ $this->assertEquals($user->lang('ARRY_NO_ZERO', 0), '0 posts');
+ $this->assertEquals($user->lang('ARRY_NO_ZERO', 1), '1 post');
+ $this->assertEquals($user->lang('ARRY_NO_ZERO', 2), '2 posts');
+
+ // Floats as array key
+ $this->assertEquals($user->lang('ARRY_FLOAT', 1.3), '1 post');
+ $this->assertEquals($user->lang('ARRY_FLOAT', 2.0), '2.0 posts');
+ $this->assertEquals($user->lang('ARRY_FLOAT', 2.51), '2.5 posts');
+
// ticket PHPBB3-9949
$this->assertEquals($user->lang('ARRY', 1, 2), '1 post');
$this->assertEquals($user->lang('ARRY', 1, 's', 2), '1 post');