require_once __DIR__.'/../../include/CLegacyWebTest.php';
class testFormHostLinkTemplates extends CLegacyWebTest {
const HOST_VISIBLE_NAME = 'Visible host for template linkage';
const TEMPLATE = 'Form test template';
const LINKED_TEMPLATE = 'Linux by Zabbix agent active';
protected static $hostid;
public function getBehaviors() {
return [CMessageBehavior::class];
public static function prepareHostData() {
self::$hostid = 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()->waitUntilReady()->asForm()->one();
$dialog->fill(['Templates' => self::LINKED_TEMPLATE]);
$this->zbxTestTextPresent(self::LINKED_TEMPLATE);
$this->zbxTestCheckTitle('Configuration of hosts');
$this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Host updated');
$this->zbxTestTextPresent(self::HOST_VISIBLE_NAME);
public function testFormHostLinkTemplates_TemplateUnlink() {
$this->zbxTestLogin(self::HOST_LIST_PAGE);
$this->query('button:Reset')->one()->click();
$this->zbxTestClickLinkTextWait(self::HOST_VISIBLE_NAME);
$dialog = COverlayDialogElement::find()->waitUntilReady()->asForm()->one();
$this->assertTrue($dialog->query('link', self::LINKED_TEMPLATE)->exists());
$dialog->query('id:linked-templates')->asTable()->one()->findRow('Name', self::LINKED_TEMPLATE)->getColumn('Action')
->query('button:Unlink')->one()->click();
$this->assertFalse($dialog->query('link', self::LINKED_TEMPLATE)->exists());