Source
xxxxxxxxxx
* @param boolean $new_page true if the widget is copied to the new page, false if copied to the same page
<?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 __DIR__.'/../../include/CWebTest.php';
require_once __DIR__.'/../behaviors/CMessageBehavior.php';
require_once __DIR__.'/../../include/helpers/CDataHelper.php';
/**
* @onBefore getTemplatedIds
*
* @backup widget, profiles, module
*/
class testDashboardCopyWidgets extends CWebTest {
// Constants for regular dashboard cases.
const NEW_PAGE_NAME = 'Test_page';
const PASTE_DASHBOARD_NAME = 'Dashboard for Paste widgets';
// Constants for templated dashboard cases.
const TEMPLATED_DASHBOARD_NAME = 'Templated dashboard with all widgets';
const TEMPLATED_PAGE_NAME = 'Page for pasting widgets';
const EMPTY_DASHBOARD_NAME = 'Dashboard without widgets';
const MODULES_DASHBOARD_NAME = 'Dashboard for Copying widgets _1';
private static $templated_dashboardid;
private static $templated_empty_dashboardid;
private static $modules_dashboardid;
// Values for replacing widgets.
private static $replaced_widget_name = "Test widget for replace";
const REPLACED_WIDGET_SIZE = [ 'width' => '21', 'height' => '3'];
/**
* Attach MessageBehavior to the test.
*
* @return array
*/
public function getBehaviors() {
return ['class' => CMessageBehavior::class];
}
/**
* Get all widgets from dashboards with name starting with "Dashboard for Copying widgets".
*/
public static function getDashboardsData() {
static $data = null;
if ($data === null) {
global $DB;
if (!isset($DB['DB'])) {
DBconnect($error);
}
CDataHelper::load('CopyWidgetsDashboards');
$data = CDBHelper::getDataProvider('SELECT w.name, dp.dashboardid FROM widget w'.
' JOIN dashboard_page dp ON w.dashboard_pageid=dp.dashboard_pageid'.
' WHERE dp.dashboardid IN ('.
'SELECT dashboardid FROM dashboard '.
'WHERE name LIKE \'%Dashboard for Copying widgets%\''.
') ORDER BY w.widgetid DESC'
);
}
return $data;
}
/**
* Get ids for template dashboard cases.
*/
public static function getTemplatedIds() {
self::$templated_dashboardid = CDBHelper::getValue('SELECT dashboardid FROM dashboard WHERE name='.
zbx_dbstr(self::TEMPLATED_DASHBOARD_NAME)
);
self::$templated_empty_dashboardid = CDBHelper::getValue('SELECT dashboardid FROM dashboard WHERE name='.
zbx_dbstr(self::EMPTY_DASHBOARD_NAME)
);
self::$modules_dashboardid = CDBHelper::getValue('SELECT dashboardid FROM dashboard WHERE name='.
zbx_dbstr(self::MODULES_DASHBOARD_NAME)
);
}