Source
xxxxxxxxxx
* Replace macro {date} with specified date in YYYY-MM-DD format for specified fields and for item data to be inserted in DB.
<?php
/*
** Copyright (C) 2001-2024 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';
class testWidgets extends CWebTest {
const HOST_ALL_ITEMS = 'Host for all item value types';
const TABLE_SELECTOR = 'xpath://form[@name="itemform"]//table';
protected static $dashboardid;
/**
* Gets widget and widget_field tables to compare hash values, excludes widget_fieldid because it can change.
*/
const SQL = 'SELECT wf.widgetid, wf.type, wf.name, wf.value_int, wf.value_str, wf.value_groupid, wf.value_hostid,'.
' wf.value_itemid, wf.value_graphid, wf.value_sysmapid, w.widgetid, w.dashboard_pageid, w.type, w.name, w.x, w.y,'.
' w.width, w.height'.
' FROM widget_field wf'.
' INNER JOIN widget w'.
' ON w.widgetid=wf.widgetid'.
' ORDER BY wf.widgetid, wf.name, wf.value_int, wf.value_str, wf.value_groupid, wf.value_itemid,'.
' wf.value_graphid, wf.value_hostid';
/**
* Function which checks that only permitted item types are accessible for widgets.
*
* @param string $url url provided which needs to be opened
* @param string $widget name of widget type
*/
public function checkAvailableItems($url, $widget) {
$this->page->login()->open($url)->waitUntilReady();
// Open widget form dialog.
$widget_dialog = CDashboardElement::find()->one()->waitUntilReady()->edit()->addWidget();
$widget_form = $widget_dialog->asForm();
$widget_form->fill(['Type' => CFormElement::RELOADABLE_FILL($widget)]);
// Assign the dialog from where the last Select button will be clicked.
$select_dialog = $widget_dialog;
// Item types expected in items table. For the most cases theses are all items except of Binary and dependent.
$item_types = (in_array($widget, ['Item navigator', 'Item history', 'Honeycomb', 'Top hosts']))
? ['Binary item', 'Character item', 'Float item', 'Log item', 'Text item', 'Unsigned item', 'Unsigned_dependent item']
: ['Character item', 'Float item', 'Log item', 'Text item', 'Unsigned item', 'Unsigned_dependent item'];
switch ($widget) {
case 'Top hosts':
$widget_form->getFieldContainer('Columns')->query('button:Add')->one()->waitUntilClickable()->click();
$column_dialog = COverlayDialogElement::find()->all()->last()->waitUntilReady();
$select_dialog = $column_dialog;
break;
case 'Item history':
$widget_form->getFieldContainer('Items')->query('button:Add')->one()->waitUntilClickable()->click();
$column_dialog = COverlayDialogElement::find()->all()->last()->waitUntilReady();
$select_dialog = $column_dialog;
break;
case 'Clock':
$widget_form->fill(['Time type' => CFormElement::RELOADABLE_FILL('Host time')]);
$this->assertTrue($widget_form->getField('Item')->isVisible());
break;
case 'Graph':
case 'Gauge':
case 'Pie chart':
// For Graph, Gauge and Pie chart only numeric items are available.
$item_types = ['Float item', 'Unsigned item', 'Unsigned_dependent item'];
break;
case 'Graph prototype':
$widget_form->fill(['Source' => 'Simple graph prototype']);
$this->assertTrue($widget_form->getField('Item prototype')->isVisible());
// For Graph prototype only numeric item prototypes are available.
$item_types = ['Float item prototype', 'Unsigned item prototype', 'Unsigned_dependent item prototype'];
break;