Source
// If host or item of data set exist in data provider, add the xpath selector and value from data provider to them.
<?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__).'/../behaviors/CMessageBehavior.php';
require_once dirname(__FILE__).'/../behaviors/CTagBehavior.php';
require_once dirname(__FILE__).'/../common/testWidgets.php';
/**
* @backup widget, profiles
*
* @dataSource AllItemValueTypes
*
* @onBefore setDefaultWidgetType
*/
class testDashboardGraphWidget extends testWidgets {
const DASHBOARD_URL = 'zabbix.php?action=dashboard.view&dashboardid=1030';
/**
* Attach MessageBehavior and TagBehavior to the test.
*/
public function getBehaviors() {
return [
CMessageBehavior::class,
[
'class' => CTagBehavior::class,
'tag_selector' => 'id:tags_table_tags'
],
CTableBehavior::class
];
}
/*
* Set "Graph" as default widget type.
*/
public function setDefaultWidgetType() {
DBexecute('DELETE FROM profiles WHERE idx=\'web.dashboard.last_widget_type\' AND userid=\'1\'');
DBexecute('INSERT INTO profiles (profileid, userid, idx, value_str, type)'.
' VALUES (99999,1,\'web.dashboard.last_widget_type\',\'svggraph\',3)');
}
/**
* Open dashboard and add/edit graph widget.
*
* @param string $name name of graphic widget to be opened
*/
private function openGraphWidgetConfiguration($name = null) {
$dashboard = CDashboardElement::find()->one()->edit();
// Open existed widget by widget name.
if ($name) {
$widget = $dashboard->getWidget($name);
$this->assertEquals(true, $widget->isEditable());
$form = $widget->edit();
}
// Add new graph widget.
else {
$overlay = $dashboard->addWidget();
$form = $overlay->asForm();
}
return $form;
}
/**
* Save dashboard and check added/updated graph widget.
*
* @param string $name name of graphic widget to be checked
*/
private function saveGraphWidget($name) {
COverlayDialogElement::ensureNotPresent();
$dashboard = CDashboardElement::find()->one();
$widget = $dashboard->getWidget($name);
$widget->getContent()->query('class:svg-graph')->waitUntilVisible();
$dashboard->save();
$this->assertMessage(TEST_GOOD, 'Dashboard updated');
}