<?php
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;
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';
public function checkAvailableItems($url, $widget) {
$this->page->login()->open($url)->waitUntilReady();
$widget_dialog = CDashboardElement::find()->one()->waitUntilReady()->edit()->addWidget();
$widget_form = $widget_dialog->asForm();
$widget_form->fill(['Type' => CFormElement::RELOADABLE_FILL($widget)]);
$select_dialog = $widget_dialog;
$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':
case 'Item history':
$container = ($widget === 'Top hosts') ? 'Columns' : 'Items';
$widget_form->getFieldContainer($container)->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':
$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());
$item_types = ['Float item prototype', 'Unsigned item prototype', 'Unsigned_dependent item prototype'];
break;
case 'Honeycomb':
$select_dialog = $widget_form->getFieldContainer('Item patterns');
break;
}