Source
[ 'in' => ['value' => '10000000', 'units' => '!uptime', 'convert' => ITEM_CONVERT_WITH_UNITS], 'out' => '10000000 uptime' ],
<?php declare(strict_types = 0);
/*
** Zabbix
** Copyright (C) 2001-2022 Zabbix SIA
**
** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
require_once dirname(__FILE__).'/../../../include/translateDefines.inc.php';
use PHPUnit\Framework\TestCase;
class function_convertUnitsTest extends TestCase {
protected $defaultTimezone;
protected function setUp(): void {
$this->defaultTimezone = date_default_timezone_get();
date_default_timezone_set('UTC');
}
protected function tearDown(): void {
date_default_timezone_set($this->defaultTimezone);
}
public static function provider() {
return [
// No units.
[ 'in' => ['value' => ''], 'out' => '' ],
[ 'in' => ['value' => 'TEXT'], 'out' => 'TEXT' ],
[ 'in' => ['value' => '0'], 'out' => '0' ],
[ 'in' => ['value' => '1'], 'out' => '1' ],
[ 'in' => ['value' => '1.1'], 'out' => '1.1' ],
[ 'in' => ['value' => '1.01'], 'out' => '1.01' ],
[ 'in' => ['value' => '1.001'], 'out' => '1.001' ],
[ 'in' => ['value' => '1.0001'], 'out' => '1.0001' ],
[ 'in' => ['value' => '1.00001'], 'out' => '1' ],
[ 'in' => ['value' => '999.9'], 'out' => '999.9' ],
[ 'in' => ['value' => '999.99'], 'out' => '999.99' ],
[ 'in' => ['value' => '999.999'], 'out' => '999.999' ],
[ 'in' => ['value' => '999.9999'], 'out' => '999.9999' ],
[ 'in' => ['value' => '999.99999'], 'out' => '1000' ],
[ 'in' => ['value' => '999999999999999'], 'out' => '999999999999999' ],
[ 'in' => ['value' => '999999999999999.4'], 'out' => '999999999999999' ],
[ 'in' => ['value' => '999999999999999.5'], 'out' => '1E+15' ],
[ 'in' => ['value' => '-1'], 'out' => '-1' ],
[ 'in' => ['value' => '-1.1'], 'out' => '-1.1' ],
[ 'in' => ['value' => '-1.01'], 'out' => '-1.01' ],
[ 'in' => ['value' => '-1.001'], 'out' => '-1.001' ],
[ 'in' => ['value' => '-1.0001'], 'out' => '-1.0001' ],
[ 'in' => ['value' => '-999.9'], 'out' => '-999.9' ],
[ 'in' => ['value' => '-999.99'], 'out' => '-999.99' ],
[ 'in' => ['value' => '-999.999'], 'out' => '-999.999' ],
[ 'in' => ['value' => '-999.9999'], 'out' => '-999.9999' ],
[ 'in' => ['value' => '-999.99999'], 'out' => '-1000' ],
[ 'in' => ['value' => '-999999999999999'], 'out' => '-999999999999999' ],
[ 'in' => ['value' => '-999999999999999.4'], 'out' => '-999999999999999' ],
[ 'in' => ['value' => '-999999999999999.5'], 'out' => '-1E+15' ],
[ 'in' => ['value' => '1E0'], 'out' => '1' ],
[ 'in' => ['value' => '1E+1'], 'out' => '10' ],
[ 'in' => ['value' => '1E-1'], 'out' => '0.1' ],
[ 'in' => ['value' => '1E+294'], 'out' => '1E+294' ],
[ 'in' => ['value' => '1E-294'], 'out' => '1E-294' ],
[ 'in' => ['value' => '1.23456789012345E+294'], 'out' => '1.2346E+294' ],
[ 'in' => ['value' => '1.23456789012345E-294'], 'out' => '1.2346E-294' ],
[ 'in' => ['value' => '-1E0'], 'out' => '-1' ],
[ 'in' => ['value' => '-1E+1'], 'out' => '-10' ],
[ 'in' => ['value' => '-1E-1'], 'out' => '-0.1' ],
[ 'in' => ['value' => '-1E+294'], 'out' => '-1E+294' ],
[ 'in' => ['value' => '-1E-294'], 'out' => '-1E-294' ],
[ 'in' => ['value' => '-1.23456789012345E+294'], 'out' => '-1.2346E+294' ],
[ 'in' => ['value' => '-1.23456789012345E-294'], 'out' => '-1.2346E-294' ],
// No units, additional options.