Source
xxxxxxxxxx
$this->assertSame(CValueMapHelper::getMappedValue(ITEM_VALUE_TYPE_UINT64, $value, ['mappings' => $mappings]), $expected);
<?php declare(strict_types = 0);
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** 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 Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
use PHPUnit\Framework\TestCase;
class CValueMapHelperTest extends TestCase {
/**
* Data for testing single rule match.
*/
public function dataMatchMapping(): array {
return [
// VALUEMAP_MAPPING_TYPE_EQUAL
[
'.1', ITEM_VALUE_TYPE_FLOAT,
['type' => VALUEMAP_MAPPING_TYPE_EQUAL, 'value' => '0.1', 'newvalue' => 'ok'],
true
],
[
'0.2', ITEM_VALUE_TYPE_FLOAT,
['type' => VALUEMAP_MAPPING_TYPE_EQUAL, 'value' => '.2', 'newvalue' => 'ok'],
true
],
[
'2', ITEM_VALUE_TYPE_UINT64,
['type' => VALUEMAP_MAPPING_TYPE_EQUAL, 'value' => '2', 'newvalue' => 'ok'],
true
],
[
'2', ITEM_VALUE_TYPE_STR,
['type' => VALUEMAP_MAPPING_TYPE_EQUAL, 'value' => '2', 'newvalue' => 'ok'],
true
],
[
'match case sensitive', ITEM_VALUE_TYPE_STR,
['type' => VALUEMAP_MAPPING_TYPE_EQUAL, 'value' => 'match case sensitive', 'newvalue' => 'ok'],
true
],
[
'1024', ITEM_VALUE_TYPE_UINT64,
['type' => VALUEMAP_MAPPING_TYPE_EQUAL, 'value' => '1K', 'newvalue' => 'ok'],
false
],
[
'.1', ITEM_VALUE_TYPE_STR,
['type' => VALUEMAP_MAPPING_TYPE_EQUAL, 'value' => '0.1', 'newvalue' => 'ok'],
false
],
[
'0.2', ITEM_VALUE_TYPE_STR,
['type' => VALUEMAP_MAPPING_TYPE_EQUAL, 'value' => '.2', 'newvalue' => 'ok'],
false
],
[
'match Case Sensitive', ITEM_VALUE_TYPE_STR,
['type' => VALUEMAP_MAPPING_TYPE_EQUAL, 'value' => 'match case sensitive', 'newvalue' => 'ok'],
false
],
[
'11 ', ITEM_VALUE_TYPE_STR,
['type' => VALUEMAP_MAPPING_TYPE_EQUAL, 'value' => '11', 'newvalue' => 'ok'],
false
],
[
'2K', ITEM_VALUE_TYPE_STR,
['type' => VALUEMAP_MAPPING_TYPE_EQUAL, 'value' => '2000', 'newvalue' => 'ok'],
false
],
// VALUEMAP_MAPPING_TYPE_GREATER_EQUAL
[
'.1', ITEM_VALUE_TYPE_FLOAT,
['type' => VALUEMAP_MAPPING_TYPE_GREATER_EQUAL, 'value' => '0.1', 'newvalue' => 'ok'],
true
],
[
'3', ITEM_VALUE_TYPE_UINT64,
['type' => VALUEMAP_MAPPING_TYPE_GREATER_EQUAL, 'value' => '0', 'newvalue' => 'ok'],
true