aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Pudeyev <oleg@bsdpower.com>2012-11-16 10:25:06 -0500
committerOleg Pudeyev <oleg@bsdpower.com>2012-11-16 10:25:06 -0500
commitaf5d8b502ebf454e058794b8b082f62b4fa4cbe5 (patch)
tree18877ee8661589c560bef8f66b9a3433d7c82d3b
parent17a7c4821aa9fb83e8addfd4f32cd8dfdc9d89fc (diff)
parent8851f9589a5295d569316e76b366f1b16f1a9a96 (diff)
downloadforums-af5d8b502ebf454e058794b8b082f62b4fa4cbe5.tar
forums-af5d8b502ebf454e058794b8b082f62b4fa4cbe5.tar.gz
forums-af5d8b502ebf454e058794b8b082f62b4fa4cbe5.tar.bz2
forums-af5d8b502ebf454e058794b8b082f62b4fa4cbe5.tar.xz
forums-af5d8b502ebf454e058794b8b082f62b4fa4cbe5.zip
Merge PR #1074 branch 'bantu/ticket/11192' into develop-olympus
* bantu/ticket/11192: [ticket/11192] Merge dataProvider arrays because the test is the same now. [ticket/11192] Update $value parameter description to support other types. [ticket/11192] Mark negative byte numbers as unsupported. [ticket/11192] Test strings not converted to int/float before. [ticket/11192] Also test strings, e.g. sums returned by the database. [ticket/11192] Also test powers of 10 / 1000. [ticket/11192] Add tests. [ticket/11192] Add Tebibyte to get_formatted_filesize().
-rw-r--r--phpBB/includes/functions.php9
-rw-r--r--phpBB/language/en/common.php2
-rw-r--r--tests/functions/get_formatted_filesize_test.php71
3 files changed, 81 insertions, 1 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 65d8be32ad..6e661228b7 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -289,7 +289,8 @@ function phpbb_gmgetdate($time = false)
/**
* Return formatted string for filesizes
*
-* @param int $value filesize in bytes
+* @param mixed $value filesize in bytes
+* (non-negative number; int, float or string)
* @param bool $string_only true if language string should be returned
* @param array $allowed_units only allow these units (data array indexes)
*
@@ -301,6 +302,12 @@ function get_formatted_filesize($value, $string_only = true, $allowed_units = fa
global $user;
$available_units = array(
+ 'tb' => array(
+ 'min' => 1099511627776, // pow(2, 40)
+ 'index' => 4,
+ 'si_unit' => 'TB',
+ 'iec_unit' => 'TIB',
+ ),
'gb' => array(
'min' => 1073741824, // pow(2, 30)
'index' => 3,
diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php
index 0184dd083b..844d5ef3ef 100644
--- a/phpBB/language/en/common.php
+++ b/phpBB/language/en/common.php
@@ -568,9 +568,11 @@ $lang = array_merge($lang, array(
'SUBJECT' => 'Subject',
'SUBMIT' => 'Submit',
+ 'TB' => 'TB',
'TERMS_USE' => 'Terms of use',
'TEST_CONNECTION' => 'Test connection',
'THE_TEAM' => 'The team',
+ 'TIB' => 'TiB',
'TIME' => 'Time',
'TOO_LARGE' => 'The value you entered is too large.',
diff --git a/tests/functions/get_formatted_filesize_test.php b/tests/functions/get_formatted_filesize_test.php
new file mode 100644
index 0000000000..96ea2be132
--- /dev/null
+++ b/tests/functions/get_formatted_filesize_test.php
@@ -0,0 +1,71 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_get_formatted_filesize_test extends phpbb_test_case
+{
+ public function get_formatted_filesize_test_data()
+ {
+ return array(
+ // exact powers of 2
+ array(1, '1 BYTES'),
+ array(1024, '1 KIB'),
+ array(1048576, '1 MIB'),
+ array(1073741824, '1 GIB'),
+ array(1099511627776, '1 TIB'),
+
+ // exact powers of 10
+ array(1000, '1000 BYTES'),
+ array(1000000, '976.56 KIB'),
+ array(1000000000, '953.67 MIB'),
+ array(1000000000000, '931.32 GIB'),
+ array(100000000000000, '90.95 TIB'),
+
+ array(0, '0 BYTES'),
+ array(2, '2 BYTES'),
+
+ array(1023, '1023 BYTES'),
+ array(1025, '1 KIB'),
+ array(1048575, '1024 KIB'),
+
+ // String values
+ // exact powers of 2
+ array('1', '1 BYTES'),
+ array('1024', '1 KIB'),
+ array('1048576', '1 MIB'),
+ array('1073741824', '1 GIB'),
+ array('1099511627776', '1 TIB'),
+
+ // exact powers of 10
+ array('1000', '1000 BYTES'),
+ array('1000000', '976.56 KIB'),
+ array('1000000000', '953.67 MIB'),
+ array('1000000000000', '931.32 GIB'),
+ array('100000000000000', '90.95 TIB'),
+
+ array('0', '0 BYTES'),
+ array('2', '2 BYTES'),
+
+ array('1023', '1023 BYTES'),
+ array('1025', '1 KIB'),
+ array('1048575', '1024 KIB'),
+ );
+ }
+
+ /**
+ * @dataProvider get_formatted_filesize_test_data
+ */
+ public function test_get_formatted_filesize($input, $expected)
+ {
+ $output = get_formatted_filesize($input);
+
+ $this->assertEquals($expected, $output);
+ }
+}