Merge pull request #4840 from owncloud/adding-tb-master
adding TB and GB to OC_Helper::humanFileSize
This commit is contained in:
commit
c149b57d3b
2 changed files with 42 additions and 34 deletions
|
@ -282,7 +282,6 @@ class OC_Helper {
|
||||||
*/
|
*/
|
||||||
public static function humanFileSize($bytes) {
|
public static function humanFileSize($bytes) {
|
||||||
if ($bytes < 0) {
|
if ($bytes < 0) {
|
||||||
$l = OC_L10N::get('lib');
|
|
||||||
return "?";
|
return "?";
|
||||||
}
|
}
|
||||||
if ($bytes < 1024) {
|
if ($bytes < 1024) {
|
||||||
|
@ -296,11 +295,18 @@ class OC_Helper {
|
||||||
if ($bytes < 1024) {
|
if ($bytes < 1024) {
|
||||||
return "$bytes MB";
|
return "$bytes MB";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wow, heavy duty for owncloud
|
|
||||||
$bytes = round($bytes / 1024, 1);
|
$bytes = round($bytes / 1024, 1);
|
||||||
|
if ($bytes < 1024) {
|
||||||
return "$bytes GB";
|
return "$bytes GB";
|
||||||
}
|
}
|
||||||
|
$bytes = round($bytes / 1024, 1);
|
||||||
|
if ($bytes < 1024) {
|
||||||
|
return "$bytes TB";
|
||||||
|
}
|
||||||
|
|
||||||
|
$bytes = round($bytes / 1024, 1);
|
||||||
|
return "$bytes PB";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Make a computer file size
|
* @brief Make a computer file size
|
||||||
|
|
|
@ -8,40 +8,42 @@
|
||||||
|
|
||||||
class Test_Helper extends PHPUnit_Framework_TestCase {
|
class Test_Helper extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
function testHumanFileSize() {
|
/**
|
||||||
$result = OC_Helper::humanFileSize(0);
|
* @dataProvider humanFileSizeProvider
|
||||||
$expected = '0 B';
|
*/
|
||||||
$this->assertEquals($result, $expected);
|
public function testHumanFileSize($expected, $input)
|
||||||
|
{
|
||||||
$result = OC_Helper::humanFileSize(1024);
|
$result = OC_Helper::humanFileSize($input);
|
||||||
$expected = '1 kB';
|
$this->assertEquals($expected, $result);
|
||||||
$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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testComputerFileSize() {
|
public function humanFileSizeProvider()
|
||||||
$result = OC_Helper::computerFileSize("0 B");
|
{
|
||||||
$expected = '0.0';
|
return array(
|
||||||
$this->assertEquals($result, $expected);
|
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("1 kB");
|
/**
|
||||||
$expected = '1024.0';
|
* @dataProvider computerFileSizeProvider
|
||||||
$this->assertEquals($result, $expected);
|
*/
|
||||||
|
function testComputerFileSize($expected, $input) {
|
||||||
|
$result = OC_Helper::computerFileSize($input);
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
}
|
||||||
|
|
||||||
$result = OC_Helper::computerFileSize("9.5 MB");
|
function computerFileSizeProvider(){
|
||||||
$expected = '9961472.0';
|
return array(
|
||||||
$this->assertEquals($result, $expected);
|
array(0.0, "0 B"),
|
||||||
|
array(1024.0, "1 kB"),
|
||||||
$result = OC_Helper::computerFileSize("465.7 GB");
|
array(9961472.0, "9.5 MB"),
|
||||||
$expected = '500041567436.8';
|
array(500041567436.8, "465.7 GB"),
|
||||||
$this->assertEquals($result, $expected);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testGetMimeType() {
|
function testGetMimeType() {
|
||||||
|
|
Loading…
Reference in a new issue