<?php
require_once dirname(__FILE__).'/../../include/CLegacyWebTest.php';
class testFormHostLinkTemplates extends CLegacyWebTest {
const HOST_VISIBLE_NAME = 'Visible host for template linkage';
public static function prepareHostData() {
CDataHelper::call('host.create', [
[
'host' => 'Template linkage test host',
'name' => self::HOST_VISIBLE_NAME,
'groups' => ['groupid' => 4]
]
]);
}
public function testFormHostLinkTemplates_Layout() {
$this->page->login()->open('zabbix.php?action=host.list')->waitUntilReady();
$this->query('button:Create host')->one()->click();
$form = COverlayDialogElement::find()->asForm()->one()->waitUntilVisible();
$form->selectTab('Inventory');
$inventoryFields = getHostInventories();
$inventoryFields = zbx_toHash($inventoryFields, 'db_field');
foreach ($inventoryFields as $fieldId => $fieldName) {
$this->zbxTestTextPresent($fieldName['title']);
$this->zbxTestAssertElementPresentId('host_inventory_'.$fieldId.'');
}
COverlayDialogElement::find()->one()->close();
}
public function testFormHostLinkTemplates_TemplateLink() {
$this->zbxTestLogin(self::HOST_LIST_PAGE);
$this->query('button:Reset')->one()->click();
$this->zbxTestClickLinkTextWait(self::HOST_VISIBLE_NAME);
$dialog = COverlayDialogElement::find()->asForm()->waitUntilReady()->one();
$dialog->fill(['Templates' => 'Linux by Zabbix agent active']);
$this->zbxTestTextPresent('Linux by Zabbix agent active');
$dialog->submit();
$this->zbxTestCheckTitle('Configuration of hosts');
$this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Host updated');
$this->zbxTestTextPresent(self::HOST_VISIBLE_NAME);
}
public function testFormHostLinkTemplates_TemplateUnlink() {
$template = 'Linux by Zabbix agent active';
$host = 'Template linkage test host';
$sql = 'select hostid from hosts where host='.zbx_dbstr($host).' and status in ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.')';
$this->assertEquals(1, CDBHelper::getCount($sql));
$row = DBfetch(DBselect($sql));
$hostid = $row['hostid'];
$sql2 = "select hostid from hosts where host='".$template."';";
$this->assertEquals(1, CDBHelper::getCount($sql2));
$this->zbxTestLogin(self::HOST_LIST_PAGE);
$this->query('button:Reset')->one()->click();
$this->zbxTestClickLinkTextWait(self::HOST_VISIBLE_NAME);
$dialog = COverlayDialogElement::find()->asForm()->waitUntilReady()->one();
$this->assertTrue($dialog->query('link', $template)->exists());
$dialog->query('id:linked-templates')->asTable()->one()->findRow('Name', $template)->getColumn('Action')