require_once dirname(__FILE__).'/../../include/CWebTest.php';
class testLowLevelDiscovery extends CWebTest {
const SQL = 'SELECT * FROM items WHERE flags=1 ORDER BY itemid';
const SIMPLE_UPDATE_CLONE_LLD = 'LLD for simple update or clone scenario';
protected static $context = 'host';
protected static $groupid;
protected static $templateid;
protected static $hostid;
protected static $update_lld;
public function getBehaviors() {
CPreprocessingBehavior::class
protected function checkInitialLayout() {
$url = (static::$context === 'template')
? static::$templateid.'&context=template'
: static::$empty_hostid.'&context=host';
$this->page->login()->open('host_discovery.php?filter_set=1&filter_hostids%5B0%5D='.$url);
$this->query('button:Create discovery rule')->waitUntilClickable()->one()->click();
$form = $this->query('id:host-discovery-form')->asForm()->waitUntilVisible()->one();
$this->page->assertHeader('Discovery rules');
$this->page->assertTitle('Configuration of discovery rules');
$this->assertEquals(['Discovery rule', 'Preprocessing', 'LLD macros', 'Filters', 'Overrides'], $form->getTabs());
foreach (['id:add', 'button:Test', 'button:Cancel'] as $button) {
$this->assertTrue($form->query($button)->one()->isClickable());
$required_labels = ['Name', 'Key', 'URL', 'Script', 'Script', 'Master item', 'Host interface', 'SNMP OID', 'JMX endpoint',
'Public key file', 'Private key file', 'Executed script', 'SQL query', 'Update interval', 'Timeout',
'Delete lost resources', 'Disable lost resources'
if (static::$context === 'template') {
$required_labels = array_values(array_diff($required_labels, ['Host interface']));
$this->assertEquals($required_labels, array_values($form->getLabels(CElementFilter::CLASSES_PRESENT,
'form-label-asterisk')->asText())
'Name' => ['maxlength' => 255],
'Type' => ['value' => 'Zabbix agent', 'options' => ['Zabbix agent', 'Zabbix agent (active)', 'Simple check',
'SNMP agent', 'Zabbix internal', 'Zabbix trapper', 'External check', 'Database monitor', 'HTTP agent',
'IPMI agent', 'SSH agent', 'TELNET agent', 'JMX agent', 'Dependent item', 'Script', 'Browser']
'Key' => ['maxlength' => 2048],
'URL' => ['maxlength' => 2048],
'Query fields' => ['value' => [['name' => '', 'value' => '']]],
'name:query_fields[0][name]' => ['maxlength' => 255, 'placeholder' => 'name'],
'name:query_fields[0][value]' => ['maxlength' => 255, 'placeholder' => 'value'],
'Parameters' => ['value' => [['name' => '', 'value' => '']]],