Source
<?php
/*
** 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/>.
**/
require_once dirname(__FILE__).'/../include/CIntegrationTest.php';
require_once dirname(__FILE__).'/../include/CAPITest.php';
/**
* Test suite for user macro expansion in item names.
*
* @required-components server
* @backup hosts,items,item_rtname,globalmacro,hosts
*/
class testUserMacrosInItemNames extends CIntegrationTest {
const HOSTNAME1 = 'test_user_macros_in_item_names1';
const HOSTNAME2 = 'test_user_macros_in_item_names2';
private static $hostid1;
private static $hostid2;
private static $macroid;
/**
* @inheritdoc
*/
public function prepareData() {
$response = $this->call('host.create', [
[
'host' => self::HOSTNAME1,
'interfaces' => [],
'groups' => [['groupid' => 4]],
'status' => HOST_STATUS_MONITORED
]
]);
$this->assertArrayHasKey('hostids', $response['result']);
$this->assertArrayHasKey(0, $response['result']['hostids']);
self::$hostid1 = $response['result']['hostids'][0];
$response = $this->call('item.create', [
'hostid' => self::$hostid1,
'name' => 'Item {$TEST}',
'key_' => 'item1',
'type' => ITEM_TYPE_TRAPPER,
'value_type' => ITEM_VALUE_TYPE_UINT64
]);
$this->assertArrayHasKey('itemids', $response['result']);
$this->assertEquals(1, count($response['result']['itemids']));
$response = $this->call('discoveryrule.create', [
'hostid' => self::$hostid1,
'name' => 'Trapper discovery',
'key_' => 'item_discovery',