require_once dirname(__FILE__).'/../include/CIntegrationTest.php';
require_once dirname(__FILE__).'/../include/CAPITest.php';
class testUserMacrosInItemNames extends CIntegrationTest {
const HOSTNAME1 = 'test_user_macros_in_item_names1';
const HOSTNAME2 = 'test_user_macros_in_item_names2';
public function prepareData() {
$response = $this->call('host.create', [
'host' => self::HOSTNAME1,
'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}',
'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',
'type' => ITEM_TYPE_TRAPPER
$this->assertArrayHasKey('itemids', $response['result']);
$this->assertArrayHasKey(0, $response['result']['itemids']);
$ruleid = $response['result']['itemids'][0];
$response = $this->call('itemprototype.create', [
'hostid' => self::$hostid1,
'name' => 'LLD {$TEST} {#KEY}',
'key_' => 'trap[{#KEY}]',
'type' => ITEM_TYPE_TRAPPER,
'value_type' => ITEM_VALUE_TYPE_TEXT
$this->assertArrayHasKey('itemids', $response['result']);
$this->assertArrayHasKey(0, $response['result']['itemids']);
$response = $this->call('usermacro.createglobal', [
$this->assertArrayHasKey('result', $response);
$this->assertArrayHasKey('globalmacroids', $response['result']);
self::$macroid = $response['result']['globalmacroids'][0];