Merge branch 'develop' of github.com:LDAPAccountManager/lam into develop

This commit is contained in:
Roland Gruber 2020-06-14 19:58:24 +02:00
commit 2fcabf0c07
2 changed files with 72 additions and 3 deletions

View File

@ -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;
}
/**

View File

@ -0,0 +1,67 @@
<?php
use PHPUnit\Framework\TestCase;
/*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2020 Roland Gruber
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
include_once __DIR__ . '/../../../lib/baseModule.inc';
include_once __DIR__ . '/../../../lib/modules.inc';
include_once __DIR__ . '/../../../lib/modules/quota.inc';
/**
* Checks the quota class.
*
* @author Roland Gruber
*/
class QuotaTest extends TestCase {
protected function setUp(): void {
$_SESSION = array('language' => '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));
}
}