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/CWebTest.php';
require_once dirname(__FILE__).'/../../include/helpers/CDataHelper.php';
require_once dirname(__FILE__).'/../behaviors/CMessageBehavior.php';
use Facebook\WebDriver\Exception\UnexpectedAlertOpenException;
use Facebook\WebDriver\Exception\NoSuchElementException;
/**
* @backup dashboard, hosts
*
* @dataSource Services, Sla, Proxies
*
* @onBefore prepareTemplateDashboardsData
*/
class testDashboardsTemplatedDashboardForm extends CWebTest {
const WIDGET_SQL = 'SELECT * FROM widget w INNER JOIN dashboard_page dp ON dp.dashboard_pageid=w.dashboard_pageid'.
' INNER JOIN dashboard d ON d.dashboardid=dp.dashboardid ORDER BY w.widgetid';
const TEMPLATE = 'Template for dashboard testing';
const TEMPLATE_ITEM = 'Templates widget item';
protected static $update_templateid; // ID of the "Template for dashboard testing" for template dashboards tests.
protected static $hostid_for_template; // ID of the "Empty host for template" to which a template with dashboards will be linked.
protected static $template_itemid; // ID of item "Templates widget item" that is used to create widgets.
protected static $dashboardid_with_widgets;
protected static $empty_dashboardid;
protected static $dashboardid_for_update;
protected static $previous_widget_name = 'Widget for update';
/**
* Attach MessageBehavior to the test.
*
* @return array
*/
public function getBehaviors() {
return [
'class' => CMessageBehavior::class
];
}
/**
* Function creates host, template, template dashboards and defines the corresponding dashboard IDs.
*/
public static function prepareTemplateDashboardsData() {
$hosts = CDataHelper::call('host.create', [
'host' => 'Empty host for template',
'groups' => [['groupid' => 4]] //Zabbix servers.
]);
self::$hostid_for_template = $hosts['hostids'][0];
$templates = CDataHelper::createTemplates([
[
'host' => self::TEMPLATE,
'groups' => ['groupid' => 1], // Templates.
'items' => [
[
'name' => self::TEMPLATE_ITEM,
'key_' => 'templ_key[1]',
'type' => ITEM_TYPE_TRAPPER,
'value_type' => ITEM_VALUE_TYPE_UINT64
]
],
'discoveryrules' => [
[
'name' => 'LLD rule for graph prototype widget',
'key_' => 'drule',
'type' => ITEM_TYPE_TRAPPER,
'delay' => 0
]
]
]
]);
self::$update_templateid = $templates['templateids']['Template for dashboard testing'];
self::$template_itemid = $templates['itemids']['Template for dashboard testing:templ_key[1]'];
$discoveryruleid = $templates['discoveryruleids']['Template for dashboard testing:drule'];