summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-09-13 10:29:35 -0700
committerThomas Müller <thomas.mueller@tmit.eu>2013-09-13 10:29:35 -0700
commitc149b57d3b4020c65d33966d5dc8395b8b821fc9 (patch)
treec90a5f2f3e1ad9e4811f824ef15a8b2813b991c6
parent3790cbb493e44e9e089fe6f2966b90cbc2eda161 (diff)
parent049e57ac4aff9691bd74777749a5edfa5e26c0ec (diff)
downloadnextcloud-server-c149b57d3b4020c65d33966d5dc8395b8b821fc9.tar.gz
nextcloud-server-c149b57d3b4020c65d33966d5dc8395b8b821fc9.zip
Merge pull request #4840 from owncloud/adding-tb-master
adding TB and GB to OC_Helper::humanFileSize
-rw-r--r--lib/helper.php12
-rw-r--r--tests/lib/helper.php62
2 files changed, 41 insertions, 33 deletions
diff --git a/lib/helper.php b/lib/helper.php
index 29660b9e1f1..66e7acb407a 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -282,7 +282,6 @@ class OC_Helper {
*/
public static function humanFileSize($bytes) {
if ($bytes < 0) {
- $l = OC_L10N::get('lib');
return "?";
}
if ($bytes < 1024) {
@@ -296,10 +295,17 @@ class OC_Helper {
if ($bytes < 1024) {
return "$bytes MB";
}
+ $bytes = round($bytes / 1024, 1);
+ if ($bytes < 1024) {
+ return "$bytes GB";
+ }
+ $bytes = round($bytes / 1024, 1);
+ if ($bytes < 1024) {
+ return "$bytes TB";
+ }
- // Wow, heavy duty for owncloud
$bytes = round($bytes / 1024, 1);
- return "$bytes GB";
+ return "$bytes PB";
}
/**
diff --git a/tests/lib/helper.php b/tests/lib/helper.php
index 67b5a3d43ec..b4d896e5196 100644
--- a/tests/lib/helper.php
+++ b/tests/lib/helper.php
@@ -8,40 +8,42 @@
class Test_Helper extends PHPUnit_Framework_TestCase {
- function testHumanFileSize() {
- $result = OC_Helper::humanFileSize(0);
- $expected = '0 B';
- $this->assertEquals($result, $expected);
-
- $result = OC_Helper::humanFileSize(1024);
- $expected = '1 kB';
- $this->assertEquals($result, $expected);
-
- $result = OC_Helper::humanFileSize(10000000);
- $expected = '9.5 MB';
- $this->assertEquals($result, $expected);
-
- $result = OC_Helper::humanFileSize(500000000000);
- $expected = '465.7 GB';
- $this->assertEquals($result, $expected);
+ /**
+ * @dataProvider humanFileSizeProvider
+ */
+ public function testHumanFileSize($expected, $input)
+ {
+ $result = OC_Helper::humanFileSize($input);
+ $this->assertEquals($expected, $result);
}
- function testComputerFileSize() {
- $result = OC_Helper::computerFileSize("0 B");
- $expected = '0.0';
- $this->assertEquals($result, $expected);
-
- $result = OC_Helper::computerFileSize("1 kB");
- $expected = '1024.0';
- $this->assertEquals($result, $expected);
+ public function humanFileSizeProvider()
+ {
+ return array(
+ array('0 B', 0),
+ array('1 kB', 1024),
+ array('9.5 MB', 10000000),
+ array('465.7 GB', 500000000000),
+ array('454.7 TB', 500000000000000),
+ array('444.1 PB', 500000000000000000),
+ );
+ }
- $result = OC_Helper::computerFileSize("9.5 MB");
- $expected = '9961472.0';
- $this->assertEquals($result, $expected);
+ /**
+ * @dataProvider computerFileSizeProvider
+ */
+ function testComputerFileSize($expected, $input) {
+ $result = OC_Helper::computerFileSize($input);
+ $this->assertEquals($expected, $result);
+ }
- $result = OC_Helper::computerFileSize("465.7 GB");
- $expected = '500041567436.8';
- $this->assertEquals($result, $expected);
+ function computerFileSizeProvider(){
+ return array(
+ array(0.0, "0 B"),
+ array(1024.0, "1 kB"),
+ array(9961472.0, "9.5 MB"),
+ array(500041567436.8, "465.7 GB"),
+ );
}
function testGetMimeType() {