From 69796a98f38b45c9e67f67b7326e066534d9c4a5 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Fri, 12 Jun 2020 09:42:54 +0200 Subject: [PATCH] fixed formatting issue --- lam/lib/modules/quota.inc | 8 ++-- lam/tests/lib/modules/quotaTest.php | 67 +++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 lam/tests/lib/modules/quotaTest.php diff --git a/lam/lib/modules/quota.inc b/lam/lib/modules/quota.inc index 56cba488..df05899a 100644 --- a/lam/lib/modules/quota.inc +++ b/lam/lib/modules/quota.inc @@ -232,7 +232,7 @@ class quota extends baseModule { * * @param int $value raw value */ - private function addBlockUnits($value) { + public function addBlockUnits($value) { $mebibytes = 1024; $gibibytes = 1024 * $mebibytes; $tebibytes = 1024 * $gibibytes; @@ -248,6 +248,7 @@ class quota extends baseModule { if (($value >= $mebibytes) && (($value % $mebibytes) === 0)) { return ($value / $mebibytes) . 'M'; } + return $value; } /** @@ -255,12 +256,12 @@ class quota extends baseModule { * * @param int $value raw value */ - private function addInodeUnits($value) { + public function addInodeUnits($value) { $kilo = 1000; $million = 1000 * $kilo; $billion = 1000 * $million; $trillion = 1000 * $billion; - if (empty($value) || !get_preg($value, 'digit') || ($value < $million)) { + if (empty($value) || !get_preg($value, 'digit')) { return $value; } if (($value >= $trillion) && (($value % $trillion) === 0)) { @@ -275,6 +276,7 @@ class quota extends baseModule { if (($value >= $kilo) && (($value % $kilo) === 0)) { return ($value / $kilo) . 'k'; } + return $value; } /** diff --git a/lam/tests/lib/modules/quotaTest.php b/lam/tests/lib/modules/quotaTest.php new file mode 100644 index 00000000..a5f9a527 --- /dev/null +++ b/lam/tests/lib/modules/quotaTest.php @@ -0,0 +1,67 @@ + 'de_DE.utf8'); + } + + public function testAddBlockUnits() { + $quota = new quota('user'); + + $this->assertEquals('123T', $quota->addBlockUnits(1024*1024*1024*123)); + $this->assertEquals('123G', $quota->addBlockUnits(1024*1024*123)); + $this->assertEquals('123M', $quota->addBlockUnits(1024*123)); + $this->assertEquals('123', $quota->addBlockUnits(123)); + $this->assertEquals('1025', $quota->addBlockUnits(1025)); + $this->assertEquals('5000G', $quota->addBlockUnits(1024*1024*5000)); + $this->assertEquals('5000M', $quota->addBlockUnits(1024*5000)); + $this->assertEquals('5000', $quota->addBlockUnits(5000)); + } + + public function testAddInodeUnits() { + $quota = new quota('user'); + + $this->assertEquals('123t', $quota->addInodeUnits(1000*1000*1000*1000*123)); + $this->assertEquals('123g', $quota->addInodeUnits(1000*1000*1000*123)); + $this->assertEquals('123m', $quota->addInodeUnits(1000*1000*123)); + $this->assertEquals('123k', $quota->addInodeUnits(1000*123)); + $this->assertEquals('123', $quota->addInodeUnits(123)); + $this->assertEquals('1025', $quota->addInodeUnits(1025)); + $this->assertEquals('5001g', $quota->addInodeUnits(1000*1000*1000*5001)); + $this->assertEquals('5001m', $quota->addInodeUnits(1000*1000*5001)); + $this->assertEquals('5001k', $quota->addInodeUnits(1000*5001)); + $this->assertEquals('5001', $quota->addInodeUnits(5001)); + } + +}