From 7ca689e190a31e72d3c0e90c5ecf1a759995142d Mon Sep 17 00:00:00 2001 From: Molkobain Date: Sun, 4 Jul 2021 22:49:54 +0200 Subject: [PATCH] Setup: Fix sizes being displayed as bits instead of bytes --- setup/setuputils.class.inc.php | 2 +- test/setup/SetupUtilsTest.php | 41 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/setup/setuputils.class.inc.php b/setup/setuputils.class.inc.php index a996d5793..8a1446352 100644 --- a/setup/setuputils.class.inc.php +++ b/setup/setuputils.class.inc.php @@ -982,7 +982,7 @@ class SetupUtils public static function HumanReadableSize($fBytes) { - $aSizes = array('bytes', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Hb'); + $aSizes = array('bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'HB'); $index = 0; while (($fBytes > 1000) && ($index < count($aSizes))) { $index++; diff --git a/test/setup/SetupUtilsTest.php b/test/setup/SetupUtilsTest.php index a4b04db85..76b22859c 100644 --- a/test/setup/SetupUtilsTest.php +++ b/test/setup/SetupUtilsTest.php @@ -79,5 +79,46 @@ class SetupUtilsTest extends ItopTestCase ]; } + /** + * @dataProvider HumanReadableSizeProvider + */ + public function testHumanReadableSize($fBytes, $sExpected) + { + $sOutput = SetupUtils::HumanReadableSize($fBytes); + $this->assertEquals($sExpected, $sOutput); + } + public function HumanReadableSizeProvider(): array + { + return [ + '10 bytes' => [ + 10, + '10 bytes', + ], + '10 kilobytes' => [ + 10 * 1024, + '10.24 KB', + ], + '10 megabytes' => [ + 10 * 1024 * 1024, + '10.49 MB', + ], + '10 gigabytes' => [ + 10 * 1024 * 1024 * 1024, + '10.74 GB', + ], + '10 terabytes' => [ + 10 * 1024 * 1024 * 1024 * 1024, + '11.00 TB', + ], + '10 petabytes' => [ + 10 * 1024 * 1024 * 1024 * 1024 * 1024, + '11.26 PB', + ], + '10 heptabytes' => [ + 10 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, + '11.53 HB', + ], + ]; + } }