Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLarisa Grigorjeva <larisa.grigorjeva@zabbix.com>2022-11-04 18:10:13 +0300
committerLarisa Grigorjeva <larisa.grigorjeva@zabbix.com>2022-11-04 18:10:13 +0300
commit6294a9418a729bd232aa1332f01f902db086313d (patch)
tree37addb825152538744257931ce203f08a8ecd685
parentaf8a4830e54abc18c80bad0fc6c968fa43b6befd (diff)
parent4763a61f002a7f40619822f8adde25c1e8e791e7 (diff)
.......... [DEV-2187] rewrote graph tests to the new framework
* commit '4763a61f002a7f40619822f8adde25c1e8e791e7': (23 commits) .......... [DEV-2187] fixed assert .......... [DEV-2187] fixed color picker and protected variables .......... [DEV-2187] fixed color picker and protected variables .......... [DEV-2187] fixed after review .......... [DEV-2187] fixed after review vol.2 .......... [DEV-2187] removed unnecessary field .......... [DEV-2187] deleted trailing comma .......... [DEV-2187] fixed after review .......... [DEV-2187] uncommented lines after bugfix .......... [DEV-2187] removed trailling commas .......... [DEV-2187] fixed after review .......... [DEV-2187] added scenario for text items, fixed some issues .......... [DEV-2187] added functions change scenario .......... [DEV-2187] updated test .......... [DEV-2187] added cancel, delete and clone scenarios .......... [DEV-2187] commented lines due to ZBX .......... [DEV-2187] added update scenario .......... [DEV-2187] refactored tests code .......... [DEV-2187] added more cases for layout and create scenarios .......... [DEV-2187] added create scenario for graphs and prototypes ...
-rw-r--r--ui/tests/selenium/SeleniumTests.php25
-rw-r--r--ui/tests/selenium/common/testFormGraphs.php1066
-rw-r--r--ui/tests/selenium/graphs/testFormGraph.php572
-rw-r--r--ui/tests/selenium/graphs/testFormGraphPrototype.php727
-rw-r--r--ui/tests/selenium/graphs/testGraphAxis.php (renamed from ui/tests/selenium/testGraphAxis.php)3
-rw-r--r--ui/tests/selenium/graphs/testInheritanceGraph.php (renamed from ui/tests/selenium/testInheritanceGraph.php)3
-rw-r--r--ui/tests/selenium/graphs/testInheritanceGraphPrototype.php (renamed from ui/tests/selenium/testInheritanceGraphPrototype.php)3
-rw-r--r--ui/tests/selenium/graphs/testPageGraphPrototypes.php (renamed from ui/tests/selenium/testPageGraphPrototypes.php)5
-rw-r--r--ui/tests/selenium/graphs/testPageHostGraph.php (renamed from ui/tests/selenium/testPageHostGraph.php)3
-rw-r--r--ui/tests/selenium/testFormGraph.php1007
-rw-r--r--ui/tests/selenium/testFormGraphPrototype.php1232
11 files changed, 2388 insertions, 2258 deletions
diff --git a/ui/tests/selenium/SeleniumTests.php b/ui/tests/selenium/SeleniumTests.php
index 4e7b6d97211..85654af2ed3 100644
--- a/ui/tests/selenium/SeleniumTests.php
+++ b/ui/tests/selenium/SeleniumTests.php
@@ -19,7 +19,6 @@
**/
require_once dirname(__FILE__).'/testGeneric.php';
-require_once dirname(__FILE__).'/testGraphAxis.php';
require_once dirname(__FILE__).'/testPageDashboardWidgets.php';
require_once dirname(__FILE__).'/testPageLatestData.php';
require_once dirname(__FILE__).'/testPageWeb.php';
@@ -39,9 +38,14 @@ require_once dirname(__FILE__).'/testPageApiTokensUserSettings.php';
require_once dirname(__FILE__).'/testPageAvailabilityReport.php';
require_once dirname(__FILE__).'/testPageDashboardList.php';
require_once dirname(__FILE__).'/testPageEventCorrelation.php';
-require_once dirname(__FILE__).'/testPageGraphPrototypes.php';
+require_once dirname(__FILE__).'/graphs/testFormGraph.php';
+require_once dirname(__FILE__).'/graphs/testFormGraphPrototype.php';
+require_once dirname(__FILE__).'/graphs/testGraphAxis.php';
+require_once dirname(__FILE__).'/graphs/testInheritanceGraph.php';
+require_once dirname(__FILE__).'/graphs/testInheritanceGraphPrototype.php';
+require_once dirname(__FILE__).'/graphs/testPageGraphPrototypes.php';
+require_once dirname(__FILE__).'/graphs/testPageHostGraph.php';
require_once dirname(__FILE__).'/testPageHistory.php';
-require_once dirname(__FILE__).'/testPageHostGraph.php';
require_once dirname(__FILE__).'/testPageHostInterfaces.php';
require_once dirname(__FILE__).'/testPageHostPrototypes.php';
require_once dirname(__FILE__).'/testPageHosts.php';
@@ -96,8 +100,6 @@ require_once dirname(__FILE__).'/testFormEventCorrelation.php';
require_once dirname(__FILE__).'/filterTabs/testFormFilterHosts.php';
require_once dirname(__FILE__).'/filterTabs/testFormFilterLatestData.php';
require_once dirname(__FILE__).'/filterTabs/testFormFilterProblems.php';
-require_once dirname(__FILE__).'/testFormGraph.php';
-require_once dirname(__FILE__).'/testFormGraphPrototype.php';
require_once dirname(__FILE__).'/hosts/testFormHostConfiguration.php';
require_once dirname(__FILE__).'/hosts/testFormHostMonitoring.php';
require_once dirname(__FILE__).'/hosts/testFormHostStandalone.php';
@@ -161,13 +163,11 @@ require_once dirname(__FILE__).'/items/testFormulaCalculatedItemPrototype.php';
require_once dirname(__FILE__).'/testPageBrowserWarning.php';
require_once dirname(__FILE__).'/items/testInheritanceItem.php';
require_once dirname(__FILE__).'/testInheritanceTrigger.php';
-require_once dirname(__FILE__).'/testInheritanceGraph.php';
require_once dirname(__FILE__).'/testInheritanceWeb.php';
require_once dirname(__FILE__).'/lld/testInheritanceDiscoveryRule.php';
require_once dirname(__FILE__).'/items/testInheritanceItemPrototype.php';
require_once dirname(__FILE__).'/items/testItemTypeSelection.php';
require_once dirname(__FILE__).'/testInheritanceTriggerPrototype.php';
-require_once dirname(__FILE__).'/testInheritanceGraphPrototype.php';
require_once dirname(__FILE__).'/testInheritanceHostPrototype.php';
require_once dirname(__FILE__).'/testLanguage.php';
require_once dirname(__FILE__).'/testMultiselect.php';
@@ -221,7 +221,6 @@ class SeleniumTests {
$suite = new TestSuite('selenium');
$suite->addTestSuite('testGeneric');
- $suite->addTestSuite('testGraphAxis');
$suite->addTestSuite('testPageActions');
$suite->addTestSuite('testPageAdministrationDMProxies');
$suite->addTestSuite('testFormAdministrationGeneralAutoregistration');
@@ -237,11 +236,15 @@ class SeleniumTests {
$suite->addTestSuite('testPageDashboardList');
$suite->addTestSuite('testPageDashboardWidgets');
$suite->addTestSuite('testPageEventCorrelation');
+ $suite->addTestSuite('testFormGraph');
+ $suite->addTestSuite('testFormGraphPrototype');
+ $suite->addTestSuite('testGraphAxis');
+ $suite->addTestSuite('testInheritanceGraph');
+ $suite->addTestSuite('testInheritanceGraphPrototype');
$suite->addTestSuite('testPageGraphPrototypes');
$suite->addTestSuite('testFormUpdateProblem');
$suite->addTestSuite('testPageProblems');
$suite->addTestSuite('testPageHistory');
- $suite->addTestSuite('testPageHostGraph');
$suite->addTestSuite('testPageHostInterfaces');
$suite->addTestSuite('testPageHostPrototypes');
$suite->addTestSuite('testPageHosts');
@@ -309,8 +312,6 @@ class SeleniumTests {
$suite->addTestSuite('testFormFilterProblems');
$suite->addTestSuite('testFormAdministrationGeneralGeomaps');
$suite->addTestSuite('testGeomapWidgetScreenshots');
- $suite->addTestSuite('testFormGraph');
- $suite->addTestSuite('testFormGraphPrototype');
$suite->addTestSuite('testFormHostConfiguration');
$suite->addTestSuite('testFormHostMonitoring');
$suite->addTestSuite('testFormHostStandalone');
@@ -370,8 +371,6 @@ class SeleniumTests {
$suite->addTestSuite('testPageBrowserWarning');
$suite->addTestSuite('testInheritanceItem');
$suite->addTestSuite('testInheritanceTrigger');
- $suite->addTestSuite('testInheritanceGraph');
- $suite->addTestSuite('testInheritanceGraphPrototype');
$suite->addTestSuite('testInheritanceWeb');
$suite->addTestSuite('testInheritanceDiscoveryRule');
$suite->addTestSuite('testInheritanceHostPrototype');
diff --git a/ui/tests/selenium/common/testFormGraphs.php b/ui/tests/selenium/common/testFormGraphs.php
new file mode 100644
index 00000000000..aaf63d77173
--- /dev/null
+++ b/ui/tests/selenium/common/testFormGraphs.php
@@ -0,0 +1,1066 @@
+<?php
+/*
+** Zabbix
+** Copyright (C) 2001-2022 Zabbix SIA
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** 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 General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+**/
+
+
+require_once dirname(__FILE__).'/../../include/CWebTest.php';
+require_once dirname(__FILE__).'/../behaviors/CMessageBehavior.php';
+require_once dirname(__FILE__).'/../../include/helpers/CDataHelper.php';
+
+class testFormGraphs extends CWebTest {
+
+ const HOST = 'Simple form test host'; // Host id = 40001.
+ const HOSTID = 40001; // Simple form test host.
+ const LLDID = 133800; // testFormDiscoveryRule on Simple form test host.
+ const SQL = 'SELECT * FROM graphs ORDER BY graphid';
+
+ /**
+ * Flag for graph prototype.
+ */
+ protected $prototype = false;
+
+ /**
+ * URL for opening graph or graph prototype form.
+ */
+ protected $url;
+
+ /**
+ * Name of graph for update scenario.
+ *
+ */
+ protected static $update_graph;
+
+ /**
+ * Id for item used in graph prototype.
+ *
+ * @var integer
+ */
+ protected static $itemid;
+
+ /**
+ * Ids of items for creating graphs.
+ *
+ * @var array
+ */
+ protected static $items = [
+ 'items' => [
+ 'graph_trap_int' => ['value_type' => ITEM_VALUE_TYPE_UINT64, 'itemid' => null],
+ 'graph_trap_float' => ['value_type' => ITEM_VALUE_TYPE_FLOAT, 'itemid' => null],
+ 'graph_trap_text' => ['value_type' => ITEM_VALUE_TYPE_TEXT, 'itemid' => null],
+ 'graph_trap_log' => ['value_type' => ITEM_VALUE_TYPE_LOG, 'itemid' => null]
+ ],
+ 'item_prototypes' => [
+ 'graph_prototype_trap_int' => ['value_type' => ITEM_VALUE_TYPE_UINT64, 'itemid' => null],
+ 'graph_prototype_trap_float' => ['value_type' => ITEM_VALUE_TYPE_FLOAT, 'itemid' => null],
+ 'graph_prototype_trap_text' => ['value_type' => ITEM_VALUE_TYPE_TEXT, 'itemid' => null],
+ 'graph_prototype_trap_char' => ['value_type' => ITEM_VALUE_TYPE_STR, 'itemid' => null]
+ ]
+ ];
+
+ /**
+ * Attach MessageBehavior to the test.
+ *
+ * @return array
+ */
+ public function getBehaviors() {
+ return [CMessageBehavior::class];
+ }
+
+ private function getGraphSuffix() {
+ return $this->prototype ? ' prototype' : '';
+ }
+
+ public function getLayoutData() {
+ return [
+ [
+ [
+ 'check_defaults' => true,
+ 'set_fields' => [
+ 'Graph type' => 'Normal'
+ ],
+ 'check_fields' => [
+ 'id:name' => ['value' => '', 'maxlength' => 255],
+ 'id:width' => ['value' => '900', 'maxlength' => 5],
+ 'id:height' => ['value' => '200', 'maxlength' => 5],
+ 'id:graphtype' => ['value' => 'Normal'],
+ 'id:show_legend' => ['value' => true],
+ 'id:show_work_period' => ['value' => true],
+ 'id:show_triggers' => ['value' => true],
+ 'id:visible_percent_left' => ['value' => false], // Percentile line (left) checkbox.
+ 'id:visible_percent_right' => ['value' => false], // Percentile line (right) checkbox.
+ 'id:percent_left' => ['visible' => false], // Percentile line (left) input.
+ 'id:percent_right' => ['visible' => false], // Percentile line (right) input.
+ 'id:ymin_type' => ['value' => 'Calculated'], // Y axis MIN value dropdown.
+ 'id:ymax_type' => ['value' => 'Calculated'], // Y axis MAX value dropdown.
+ 'id:yaxismin' => ['visible' => false], // Y axis MIN fixed value input.
+ 'id:yaxismax' => ['visible' => false], // Y axis MAX fixed value input.
+ 'id:ymin_name' => ['visible' => false], // Y axis MIN item input.
+ 'id:ymax_name' => ['visible' => false], // Y axis MAX item input.
+ 'id:itemsTable' => ['visible' => true]
+ ],
+ 'items' => [
+ 'item_columns' => ['', '', 'Name', 'Function', 'Draw style', 'Y axis side', 'Color', 'Action'],
+ 'dropdowns' => [
+ 'calc_fnc' => ['all', 'min', 'avg', 'max'],
+ 'drawtype' => ['Line', 'Filled region', 'Bold line', 'Dot', 'Dashed line', 'Gradient line'],
+ 'yaxisside' => ['Left', 'Right']
+ ]
+ ]
+ ]
+ ],
+ [
+ [
+ 'set_fields' => [
+ 'Graph type' => 'Stacked'
+ ],
+ 'check_fields' => [
+ 'id:name' => ['value' => ''],
+ 'id:width' => ['value' => '900'],
+ 'id:height' => ['value' => '200'],
+ 'id:graphtype' => ['value' => 'Stacked'],
+ 'id:show_legend' => ['value' => true],
+ 'id:show_work_period' => ['value' => true],
+ 'id:show_triggers' => ['value' => true],
+ 'id:visible_percent_left' => ['exists' => false], // Percentile line (left) checkbox.
+ 'id:visible_percent_right' => ['exists' => false], // Percentile line (right) checkbox.
+ 'id:percent_left' => ['exists' => false], // Percentile line (left) input.
+ 'id:percent_right' => ['exists' => false], // Percentile line (right) input.
+ 'id:ymin_type' => ['value' => 'Calculated'], // Y axis MIN value dropdown.
+ 'id:ymax_type' => ['value' => 'Calculated'], // Y axis MAX value dropdown.
+ 'id:yaxismin' => ['visible' => false], // Y axis MIN fixed value input.
+ 'id:yaxismax' => ['visible' => false], // Y axis MAX fixed value input.
+ 'id:ymin_name' => ['visible' => false], // Y axis MIN item input.
+ 'id:ymax_name' => ['visible' => false], // Y axis MAX item input.
+ 'id:itemsTable' => ['visible' => true]
+ ],
+ 'items' => [
+ 'item_columns' => ['', '', 'Name', 'Function', 'Y axis side', 'Color', 'Action'],
+ 'dropdowns' => [
+ 'calc_fnc' => ['min', 'avg', 'max'],
+ 'yaxisside' => ['Left', 'Right']
+ ]
+ ]
+ ]
+ ],
+ [
+ [
+ 'set_fields' => [
+ 'Graph type' => 'Pie'
+ ],
+ 'check_fields' => [
+ 'id:name' => ['value' => ''],
+ 'id:width' => ['value' => '900'],
+ 'id:height' => ['value' => '200'],
+ 'id:graphtype' => ['value' => 'Pie'],
+ 'id:show_legend' => ['value' => true],
+ 'id:show_work_period' => ['exists' => false],
+ 'id:show_triggers' => ['exists' => false],
+ 'id:visible_percent_left' => ['exists' => false], // Percentile line (left) checkbox.
+ 'id:visible_percent_right' => ['exists' => false], // Percentile line (right) checkbox.
+ 'id:percent_left' => ['exists' => false], // Percentile line (left) input.
+ 'id:percent_right' => ['exists' => false], // Percentile line (right) input.
+ 'id:ymin_type' => ['exists' => false], // Y axis MIN value dropdown.
+ 'id:ymax_type' => ['exists' => false], // Y axis MAX value dropdown.
+ 'id:yaxismin' => ['exists' => false], // Y axis MIN fixed value input.
+ 'id:yaxismax' => ['exists' => false], // Y axis MAX fixed value input.
+ 'id:ymin_name' => ['exists' => false], // Y axis MIN item input.
+ 'id:ymax_name' => ['exists' => false], // Y axis MAX item input.
+ 'id:show_3d' => ['value' => false],
+ 'id:itemsTable' => ['visible' => true]
+ ],
+ 'items' => [
+ 'item_columns' => ['', '', 'Name', 'Type', 'Function', 'Color', 'Action'],
+ 'dropdowns' => [
+ 'type' => ['Simple', 'Graph sum'],
+ 'calc_fnc' => ['min', 'avg', 'max', 'last']
+ ]
+ ]
+ ]
+ ],
+ [
+ [
+ 'set_fields' => [
+ 'Graph type' => 'Exploded'
+ ],
+ 'check_fields' => [
+ 'id:name' => ['value' => ''],
+ 'id:width' => ['value' => '900'],
+ 'id:height' => ['value' => '200'],
+ 'id:graphtype' => ['value' => 'Exploded'],
+ 'id:show_legend' => ['value' => true],
+ 'id:show_work_period' => ['exists' => false],
+ 'id:show_triggers' => ['exists' => false],
+ 'id:visible_percent_left' => ['exists' => false], // Percentile line (left) checkbox.
+ 'id:visible_percent_right' => ['exists' => false], // Percentile line (right) checkbox.
+ 'id:percent_left' => ['exists' => false], // Percentile line (left) input.
+ 'id:percent_right' => ['exists' => false], // Percentile line (right) input.
+ 'id:ymin_type' => ['exists' => false], // Y axis MIN value dropdown.
+ 'id:ymax_type' => ['exists' => false], // Y axis MAX value dropdown.
+ 'id:yaxismin' => ['exists' => false], // Y axis MIN fixed value input.
+ 'id:yaxismax' => ['exists' => false], // Y axis MAX fixed value input.
+ 'id:ymin_name' => ['exists' => false], // Y axis MIN item input.
+ 'id:ymax_name' => ['exists' => false], // Y axis MAX item input.
+ 'id:show_3d' => ['value' => false],
+ 'id:itemsTable' => ['visible' => true]
+ ],
+ 'items' => [
+ 'item_columns' => ['', '', 'Name', 'Type', 'Function', 'Color', 'Action'],
+ 'dropdowns' => [
+ 'type' => ['Simple', 'Graph sum'],
+ 'calc_fnc' => ['min', 'avg', 'max', 'last']
+ ]
+ ]
+ ]
+ ],
+ [
+ [
+ 'set_fields' => [
+ 'Graph type' => CFormElement::RELOADABLE_FILL('Normal'),
+ 'id:visible_percent_left' => true, // Percentile line (left) checkbox.
+ 'id:visible_percent_right' => true // Percentile line (right) checkbox.
+ ],
+ 'check_fields' => [
+ 'id:percent_left' => ['value' => 0, 'visible' => true], // Percentile line (left) input.
+ 'id:percent_right' => ['value' => 0, 'visible' => true] // Percentile line (right) input.
+ ]
+ ]
+ ],
+ [
+ [
+ 'set_fields' => [
+ 'Graph type' => CFormElement::RELOADABLE_FILL('Normal'),
+ 'id:ymin_type' => CFormElement::RELOADABLE_FILL('Fixed'), // Y axis MIN value dropdown.
+ 'id:ymax_type' => CFormElement::RELOADABLE_FILL('Fixed') // Y axis MAX value dropdown.
+ ],
+ 'check_fields' => [
+ 'id:yaxismin' => ['value' => 0, 'visible' => true], // Y axis MIN fixed value input.
+ 'id:yaxismax' => ['value' => 100, 'visible' => true] // Y axis MAX fixed value input.
+ ]
+ ]
+ ],
+ [
+ [
+ 'set_fields' => [
+ 'Graph type' => CFormElement::RELOADABLE_FILL('Normal'),
+ 'id:ymin_type' => CFormElement::RELOADABLE_FILL('Item'), // Y axis MIN value dropdown.
+ 'id:ymax_type' => CFormElement::RELOADABLE_FILL('Item') // Y axis MAX value dropdown.
+ ],
+ 'check_fields' => [
+ 'id:ymin_itemid' => ['value' => '', 'visible' => true], // Y axis MIN item input.
+ 'id:ymax_itemid' => ['value' => '', 'visible' => true] // Y axis MAX item input.
+ ]
+ ]
+ ]
+ ];
+ }
+
+ public function checkGraphFormLayout($data) {
+ $this->page->login()->open($this->url)->waitUntilReady();
+ $object = 'Graph'.$this->getGraphSuffix();
+ $this->query('button', 'Create '.lcfirst($object))->waitUntilClickable()->one()->click();
+ $this->page->assertTitle('Configuration of '.lcfirst($object).'s');
+ $form = $this->query('name:graphForm')->waitUntilVisible()->asForm()->one();
+
+ // Check default fields only for first case.
+ if (CTestArrayHelper::get($data, 'check_defaults', false)) {
+ $this->assertEquals([$object, 'Preview'], $form->getTabs());
+ $this->assertFalse($form->query('xpath:.//table[@id="itemsTable"]//div[@class="drag-icon"]')->exists());
+
+ $items_container = $form->getFieldContainer('Items');
+ $this->assertTrue($items_container->query('button:Add')->one()->isClickable());
+
+ if ($this->prototype) {
+ $this->assertTrue($items_container->query('button:Add prototype')->one()->isClickable());
+ $discover_field = $form->getField('Discover');
+ $this->assertTrue($discover_field->isVisible());
+ $this->assertEquals(true, $discover_field->getValue());
+ }
+ else {
+ $this->assertFalse($items_container->query('button:Add prototype')->exists());
+ $this->assertFalse($form->query('id:discover')->exists());
+ }
+
+ $form->selectTab('Preview');
+ $this->page->waitUntilReady();
+ $this->assertTrue($this->query('xpath://div[@id="previewChart"]/img')->waitUntilPresent()->one()->isVisible());
+
+ $form->selectTab($object);
+ $this->page->waitUntilReady();
+ }
+
+ $form->fill($data['set_fields']);
+
+ foreach ($data['check_fields'] as $field => $attribute) {
+ if (array_key_exists('exists', $attribute)) {
+ $this->assertEquals($attribute['exists'], $form->query($field)->exists());
+ }
+
+ if (array_key_exists('visible', $attribute)) {
+ $this->assertTrue($form->query($field)->one(false)->isVisible($attribute['visible']));
+ }
+
+ if (array_key_exists('value', $attribute)) {
+ $this->assertEquals($attribute['value'], $form->getField($field)->getValue());
+ }
+
+ if (array_key_exists('maxlength', $attribute)) {
+ $this->assertEquals($attribute['maxlength'], $form->getField($field)->getAttribute('maxlength'));
+ }
+ };
+
+ // Check items functions fields depending on graph type.
+ if (array_key_exists('items', $data)) {
+ $form->invalidate();
+ $items_container = $form->getFieldContainer('Items');
+
+ $item = ($this->prototype)
+ ? ['button' => 'Add prototype', 'name' => 'testFormItemPrototype1']
+ : ['button' => 'Add', 'name' => 'testFormItem'];
+
+ $items_container->query('button', $item['button'])->waitUntilClickable()->one()->click();
+ $dialog = COverlayDialogElement::find()->one();
+ $dialog->query('link', $item['name'])->waitUntilClickable()->one()->click();
+ $dialog->ensureNotPresent();
+
+ $this->assertEquals($data['items']['item_columns'], $form->query('id:itemsTable')->asTable()->one()->getHeadersText());
+
+ // Check items functions dropdown options depending on graph type.
+ foreach ($data['items']['dropdowns'] as $function => $options) {
+ $dropdown = $items_container->query('xpath:.//z-select[@name="items[0]['.$function.']"]')->asDropdown()->one();
+ $this->assertEquals($options, $dropdown->getOptions()->asText());
+
+ // Check default selected option.
+ $this->assertEquals($options[0], $dropdown->getValue());
+ }
+ }
+ }
+
+ public function getCommonGraphData() {
+ return [
+ [
+ [
+ 'expected' => TEST_BAD,
+ 'fields' => [
+ 'Name' => '',
+ 'Width' => '',
+ 'Height' => ''
+ ],
+ 'error' => 'Page received incorrect data',
+ 'details' => [
+ 'Incorrect value for field "Name": cannot be empty.',
+ 'Incorrect value "0" for "Width" field: must be between 20 and 65535.',
+ 'Incorrect value "0" for "Height" field: must be between 20 and 65535.'
+ ]
+ ]
+ ],
+ [
+ [
+ 'expected' => TEST_BAD,
+ 'fields' => [
+ 'Name' => 'Fractional width and height'.($this->prototype ? ' {#KEY}' : NULL),
+ 'Width' => 1.2,
+ 'Height' => 15.5
+ ],
+ 'error' => 'Page received incorrect data',
+ 'details' => [
+ 'Field "Width" is not integer.',
+ 'Field "Height" is not integer.'
+ ]
+ ]
+ ],
+ [
+ [
+ 'expected' => TEST_BAD,
+ 'fields' => [
+ 'Name' => 'Negative and empty inputs'.($this->prototype ? ' {#KEY}' : NULL),
+ 'Width' => -100,
+ 'Height' => -1,
+ 'id:visible_percent_left' => true,
+ 'id:visible_percent_right' => true,
+ 'id:percent_left' => -2,
+ 'id:percent_right' => -200,
+ 'id:ymin_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:ymax_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:yaxismin' => '',
+ 'id:yaxismax' => ''
+ ],
+ 'error' => 'Page received incorrect data',
+ 'details' => [
+ 'Incorrect value "-100" for "Width" field: must be between 20 and 65535.',
+ 'Incorrect value "-1" for "Height" field: must be between 20 and 65535.',
+ 'Field "yaxismin" is mandatory.',
+ 'Field "yaxismax" is mandatory.',
+ 'Incorrect value "-2" for "Percentile line (left)" field: must be between 0 and 100, and have no more than 4 digits after the decimal point.',
+ 'Incorrect value "-200" for "Percentile line (right)" field: must be between 0 and 100, and have no more than 4 digits after the decimal point.'
+ ]
+ ]
+ ],
+ [
+ [
+ 'expected' => TEST_BAD,
+ 'fields' => [
+ 'Name' => 'Commas in inputs'.($this->prototype ? ' {#KEY}' : NULL),
+ 'Width' => '20,5',
+ 'Height' => '50,9',
+ 'id:visible_percent_left' => true,
+ 'id:visible_percent_right' => true,
+ 'id:percent_left' => '1,3',
+ 'id:percent_right' => '5,6',
+ 'id:ymin_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:ymax_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:yaxismin' => '88,9',
+ 'id:yaxismax' => '0,1'
+ ],
+ 'error' => 'Page received incorrect data',
+ 'details' => [
+ 'Field "yaxismin" is not correct: a number is expected',
+ 'Field "yaxismax" is not correct: a number is expected',
+ 'Field "Percentile line (left)" is not correct: a number is expected',
+ 'Field "Percentile line (right)" is not correct: a number is expected'
+ ]
+ ]
+ ],
+ [
+ [
+ 'expected' => TEST_BAD,
+ 'fields' => [
+ 'Name' => 'Too large inputs'.($this->prototype ? ' {#KEY}' : NULL),
+ 'Width' => 65536,
+ 'Height' => 65536,
+ 'id:visible_percent_left' => true,
+ 'id:visible_percent_right' => true,
+ 'id:percent_left' => 101,
+ 'id:percent_right' => 101,
+ 'id:ymin_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:ymax_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:yaxismin' => 12345678999999998,
+ 'id:yaxismax' => 12345678999999998
+ ],
+ 'error' => 'Page received incorrect data',
+ 'details' => [
+ 'Incorrect value "65536" for "Width" field: must be between 20 and 65535.',
+ 'Incorrect value "65536" for "Height" field: must be between 20 and 65535.',
+ 'Field "yaxismin" is not correct: a number is too large',
+ 'Field "yaxismax" is not correct: a number is too large',
+ 'Incorrect value "101" for "Percentile line (left)" field: must be between 0 and 100, and have no more than 4 digits after the decimal point.',
+ 'Incorrect value "101" for "Percentile line (right)" field: must be between 0 and 100, and have no more than 4 digits after the decimal point.'
+ ]
+ ]
+ ],
+ [
+ [
+ 'expected' => TEST_BAD,
+ 'fields' => [
+ 'Name' => 'Text in inputs'.($this->prototype ? ' {#KEY}' : NULL),
+ 'Width' => 'test',
+ 'Height' => 'value',
+ 'id:visible_percent_left' => true,
+ 'id:visible_percent_right' => true,
+ 'id:percent_left' => 'letters',
+ 'id:percent_right' => 'symbols',
+ 'id:ymin_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:ymax_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:yaxismin' => 'text',
+ 'id:yaxismax' => 'value'
+ ],
+ 'error' => 'Page received incorrect data',
+ 'details' => [
+ 'Incorrect value "0" for "Width" field: must be between 20 and 65535.',
+ 'Incorrect value "0" for "Height" field: must be between 20 and 65535.',
+ 'Field "yaxismin" is not correct: a number is expected',
+ 'Field "yaxismax" is not correct: a number is expected',
+ 'Field "Percentile line (left)" is not correct: a number is expected',
+ 'Field "Percentile line (right)" is not correct: a number is expected'
+ ]
+ ]
+ ],
+ [
+ [
+ 'expected' => TEST_BAD,
+ 'fields' => [
+ 'Name' => 'Low width and height and too many fractional digits in percentile and axis'.
+ ($this->prototype ? ' {#KEY}' : NULL),
+ 'Width' => 1,
+ 'Height' => 19,
+ 'id:visible_percent_left' => true,
+ 'id:visible_percent_right' => true,
+ 'id:percent_left' => 1.99999,
+ 'id:percent_right' => 2.12345,
+ 'id:ymin_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:ymax_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:yaxismin' => 1.12345,
+ 'id:yaxismax' => 1.999999999
+ ],
+ 'error' => 'Page received incorrect data',
+ 'details' => [
+ 'Incorrect value "1" for "Width" field: must be between 20 and 65535.',
+ 'Incorrect value "19" for "Height" field: must be between 20 and 65535.',
+ 'Field "yaxismin" is not correct: a number has too many fractional digits',
+ 'Field "yaxismax" is not correct: a number has too many fractional digits',
+ 'Field "Percentile line (left)" is not correct: a number has too many fractional digits',
+ 'Field "Percentile line (right)" is not correct: a number has too many fractional digits'
+ ]
+ ]
+ ],
+ [
+ [
+ 'expected' => TEST_BAD,
+ 'fields' => [
+ 'Name' => 'Too large negative numbers'.($this->prototype ? ' {#KEY}' : NULL),
+ 'id:visible_percent_left' => true,
+ 'id:visible_percent_right' => true,
+ 'id:percent_left' => -900000,
+ 'id:percent_right' => -900000,
+ 'id:ymin_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:ymax_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:yaxismin' => -90000000000000000,
+ 'id:yaxismax' => -90000000000000000
+ ],
+ 'error' => 'Page received incorrect data',
+ 'details' => [
+ 'Field "yaxismin" is not correct: a number is too large',
+ 'Field "yaxismax" is not correct: a number is too large',
+ 'Incorrect value "-900000" for "Percentile line (left)" field: must be between 0 and 100, and have no more than 4 digits after the decimal point.',
+ 'Incorrect value "-900000" for "Percentile line (right)" field: must be between 0 and 100, and have no more than 4 digits after the decimal point.'
+ ]
+ ]
+ ],
+ [
+ [
+ 'expected' => TEST_BAD,
+ 'fields' => [
+ 'Name' => 'Empty item'.($this->prototype ? ' {#KEY}' : NULL)
+ ],
+ 'details' => [
+ 'Missing items for graph'.$this->getGraphSuffix().' "Empty item'.
+ ($this->prototype ? ' {#KEY}' : NULL).'".'
+ ]
+ ]
+ ],
+ [
+ [
+ 'expected' => TEST_BAD,
+ 'fields' => [
+ 'Name' => 'Empty Y MIN and MAX itmes',
+ 'Width' => 200,
+ 'Height' => 400,
+ 'Graph type' => CFormElement::RELOADABLE_FILL('Normal'),
+ 'id:ymin_type' => CFormElement::RELOADABLE_FILL('Item'),
+ 'id:ymax_type' => CFormElement::RELOADABLE_FILL('Item')
+ ],
+ 'items' => [
+ [
+ 'item' => 'testFormItem',
+ 'color'=> 'BBDEFB',
+ 'functions' => [
+ 'calc_fnc' => 'min',
+ 'drawtype' => 'Bold line',
+ 'yaxisside' => 'Right'
+ ]
+ ]
+ ],
+ 'error' => 'Page received incorrect data',
+ 'details' => [
+ 'Field "ymin_itemid" is mandatory.',
+ 'Field "ymax_itemid" is mandatory.'
+ ]
+ ]
+ ]
+ ];
+ }
+
+ public function checkGraphForm($data, $update = false) {
+ if (CTestArrayHelper::get($data, 'expected', TEST_GOOD) === TEST_BAD) {
+ $old_hash = CDBHelper::getHash(self::SQL);
+ }
+
+ $this->page->login()->open($this->url)->waitUntilReady();
+
+ if ($update) {
+ $this->query('link', self::$update_graph)->waitUntilClickable()->one()->click();
+ }
+ else {
+ $this->query('button', 'Create graph'.$this->getGraphSuffix())->waitUntilClickable()->one()->click();
+ }
+
+ $form = $this->query('name:graphForm')->waitUntilVisible()->asForm()->one();
+
+ // Clear all items from graph to change them to new ones from data provider.
+ if ($update) {
+ $items_container = $form->getFieldContainer('Items');
+ $items_count = $items_container->query('xpath:.//tr[contains(@id, "items_")]')->count();
+
+ for ($i = 0; $i < $items_count; $i++) {
+ // After each deletion item buttons reset their position, so upper items locator is always 0.
+ $remove_button = $items_container->query('xpath:.//button[@id="items_0_remove"]')->one();
+ $remove_button->waitUntilClickable()->click();
+ $remove_button->waitUntilNotPresent();
+ }
+ }
+
+ if ($update && !CTestArrayHelper::get($data, 'expected')) {
+ $data['fields']['Name'] = $data['fields']['Name'].' update';
+ }
+
+ $form->fill($data['fields']);
+ $items_container = $form->getFieldContainer('Items');
+
+ // Fill Y axis Item values separately.
+ if (array_key_exists('yaxis_items', $data)) {
+ foreach ($data['yaxis_items'] as $y => $yaxis_item) {
+ if ($this->prototype) {
+ $form->query('xpath:.//button[@id="yaxis_'.$y.'_prototype"]')->waitUntilClickable()->one()->click();
+ $dialog = COverlayDialogElement::find()->one();
+ $dialog->query('link', $yaxis_item)->waitUntilClickable()->one()->click();
+ $dialog->ensureNotPresent();
+ }
+ else {
+ $form->query('xpath:.//div[@id="y'.$y.'_itemid"]/..')->asMultiselect()->one()
+ ->setFillMode(CMultiselectElement::MODE_TYPE)->fill($yaxis_item);
+ }
+ }
+ }
+
+ // Add items or item prototypes to graph.
+ if (array_key_exists('items', $data)) {
+ foreach ($data['items'] as $i => $item) {
+ $items_container->query('button', CTestArrayHelper::get($item, 'prototype', false) ? 'Add prototype' : 'Add')
+ ->waitUntilClickable()->one()->click();
+ $dialog = COverlayDialogElement::find()->one();
+ $dialog->query('link', $item['item'])->waitUntilClickable()->one()->click();
+ $dialog->ensureNotPresent();
+
+ // Check that added item link appeared.
+ $item_row = $items_container->query('xpath:.//tr[@id="items_'.$i.'"]')->one()->waitUntilPresent();
+ $this->assertTrue($item_row->query('link', self::HOST.': '.$item['item'])->one()->isClickable());
+
+ // Add line styling functions.
+ if (array_key_exists('functions', $item)) {
+ foreach ($item['functions'] as $function => $value) {
+ $item_row->query('xpath:.//z-select[@name="items['.$i.']['.$function.']"]')->asDropdown()->one()->fill($value);
+ }
+ }
+
+ // Add line color.
+ if (array_key_exists('color', $item)) {
+ $item_row->query('xpath:.//div[@class="color-picker"]')->asColorPicker()->one()->fill($item['color']);
+ }
+ }
+ }
+
+ $form->submit();
+ $this->page->waitUntilReady();
+
+ if (CTestArrayHelper::get($data, 'expected', TEST_GOOD) === TEST_BAD) {
+ if (CTestArrayHelper::get($data, 'error')) {
+ $error = $data['error'];
+ }
+ else {
+ $error = $update
+ ? 'Cannot update graph'.$this->getGraphSuffix()
+ : 'Cannot add graph'.$this->getGraphSuffix();
+ }
+
+ $this->assertMessage(TEST_BAD, $error, $data['details']);
+ $this->assertEquals($old_hash, CDBHelper::getHash(self::SQL));
+ }
+ else {
+ // Write new name to update graph for next case, but if it's last case return to initial name 'Graph for update'.
+ if ($update) {
+ self::$update_graph = $data['fields']['Name'];
+ }
+
+ $message = $update
+ ? 'Graph'.$this->getGraphSuffix().' updated'
+ : 'Graph'.$this->getGraphSuffix().' added';
+
+ $this->assertMessage(TEST_GOOD, $message);
+ $this->assertEquals(1, CDBHelper::getCount('SELECT * FROM graphs WHERE name='.
+ zbx_dbstr($data['fields']['Name']))
+ );
+
+ // Open just created graph and check that all fields present correctly in form.
+ $this->query('xpath://form[@name="graphForm"]/table')->asTable()->one()->waitUntilPresent()
+ ->query('link', $data['fields']['Name'])->waitUntilClickable()->one()->click();
+ $form->invalidate();
+ $form->checkValue($data['fields']);
+
+ // Check Y axis Item values multiselects.
+ if (array_key_exists('yaxis_items', $data)) {
+ foreach ($data['yaxis_items'] as $y => $yaxis_item) {
+ $this->assertEquals([self::HOST.': '.$yaxis_item], $form->query('xpath:.//div[@id="y'.$y.'_itemid"]/..')
+ ->asMultiselect()->one()->getValue()
+ );
+ }
+ }
+
+ // Check saved items count.
+ $items_container = $form->getFieldContainer('Items');
+ $this->assertEquals(count($data['items']),
+ $items_container->query('xpath:.//tr[@class="sortable"]')->all()->count()
+ );
+
+ // Check saved items names.
+ foreach ($data['items'] as $i => $item) {
+ $item_row = $items_container->query('xpath:.//tr[@id="items_'.$i.'"]')->one()->waitUntilPresent();
+ $this->assertTrue($item_row->query('link', self::HOST.': '.$item['item'])->one()->isClickable());
+
+ // Check lines styling functions.
+ if (array_key_exists('functions', $item)) {
+ foreach ($item['functions'] as $function => $value) {
+ $this->assertEquals($value, $item_row->query('xpath:.//z-select[@name="items['.$i.']['.$function.']"]')
+ ->asDropdown()->one()->getValue()
+ );
+ }
+ }
+
+ // Check lines color.
+ if (array_key_exists('color', $item)) {
+ $this->assertEquals($item['color'],
+ $item_row->query('xpath:.//div[@class="color-picker"]')->asColorPicker()->one()->getValue()
+ );
+ }
+ }
+ }
+ }
+
+ public static function getCloneData() {
+ return [
+ [
+ [
+ 'fields' => [
+ 'Name' => 'New Cloned graph name with no changes'
+ ],
+ 'check_buttons' => true
+ ]
+ ],
+ [
+ [
+ 'fields' => [
+ 'Name' => 'New Cloned graph name with Items in Y axis',
+ 'Width' => 205,
+ 'Height' => 399,
+ 'Graph type' => CFormElement::RELOADABLE_FILL('Stacked'),
+ 'Show legend' => false,
+ 'Show working time' => false,
+ 'Show triggers' => false,
+ 'id:ymin_type' => CFormElement::RELOADABLE_FILL('Item'),
+ 'id:ymax_type' => CFormElement::RELOADABLE_FILL('Item')
+ ],
+ 'yaxis_items' => [
+ 'min' => 'Failed step of scenario "testFormWeb3".',
+ 'max' => 'Download speed for scenario "testFormWeb4".'
+ ],
+ 'items' => [
+ [
+ 'color'=> 'B39DDB',
+ 'functions' => [
+ 'calc_fnc' => 'min',
+ 'yaxisside' => 'Right'
+ ]
+ ]
+ ]
+ ]
+ ],
+ [
+ [
+ 'fields' => [
+ 'Name' => 'New Cloned graph name with Fixed Y axis',
+ 'id:visible_percent_left' => true,
+ 'id:visible_percent_right' => true,
+ 'id:percent_left' => 3,
+ 'id:percent_right' => 20,
+ 'id:ymin_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:ymax_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:yaxismin' => 1,
+ 'id:yaxismax' => 99
+ ],
+ 'items' => [
+ [
+ 'color'=> '1B5E20',
+ 'functions' => [
+ 'calc_fnc' => 'max',
+ 'drawtype' => 'Bold line',
+ 'yaxisside' => 'Right'
+ ]
+ ]
+ ]
+ ]
+ ]
+ ];
+ }
+
+ public function checkClone($data) {
+ $this->page->login()->open($this->url)->waitUntilReady();
+ $name = 'Graph'.$this->getGraphSuffix().' for clone';
+ $this->query('link', $name)->waitUntilClickable()->one()->click();
+ $form = $this->query('name:graphForm')->waitUntilVisible()->asForm()->one();
+ $form->query('button:Clone')->waitUntilClickable()->one()->click();
+ $form->invalidate();
+
+ if (CTestArrayHelper::get($data, 'check_buttons')) {
+ foreach (['Update', 'Clone', 'Delete'] as $button) {
+ $this->assertFalse($form->query('button', $button)->exists());
+ }
+ }
+
+ $form->fill($data['fields']);
+
+ // Fill Y axis Item values separately because field is not real multiselect.
+ if (array_key_exists('yaxis_items', $data)) {
+ foreach ($data['yaxis_items'] as $y => $yaxis_item) {
+ $form->query('xpath:.//div[@id="y'.$y.'_itemid"]/..')->asMultiselect()->one()
+ ->setFillMode(CMultiselectElement::MODE_TYPE)->fill($yaxis_item);
+ }
+ }
+
+ $items_container = $form->getFieldContainer('Items');
+
+ // Add items or item prototypes to graph.
+ if (array_key_exists('items', $data)) {
+ // Check that added item link appeared.
+ $item_row = $items_container->query('xpath:.//tr[@id="items_0"]')->one()->waitUntilPresent();
+
+ // Add line styling functions.
+ foreach ($data['items'][0]['functions'] as $function => $value) {
+ $item_row->query('xpath:.//z-select[@name="items[0]['.$function.']"]')->asDropdown()->one()->fill($value);
+ }
+
+ // Add line color.
+ $item_row->query('xpath:.//div[@class="color-picker"]')->asColorPicker()->one()->fill($data['items'][0]['color']);
+ }
+
+ $form->submit();
+ $this->assertMessage(TEST_GOOD, 'Graph'.$this->getGraphSuffix().' added');
+
+ // Check that both original graph and clone exist in DB.
+ foreach ([$name, $data['fields']['Name']] as $graph_name) {
+ $this->assertEquals(1, CDBHelper::getCount('SELECT * FROM graphs WHERE name='.zbx_dbstr($graph_name)));
+ }
+
+ $this->query('xpath://form[@name="graphForm"]/table')->asTable()->one()->waitUntilPresent()
+ ->query('link', $data['fields']['Name'])->waitUntilClickable()->one()->click();
+
+ $form->invalidate();
+ $form->checkValue($data['fields']);
+
+ // Check Y axis Item values multiselects.
+ if (array_key_exists('yaxis_items', $data)) {
+ foreach ($data['yaxis_items'] as $y => $yaxis_item) {
+ $this->assertEquals([self::HOST.': '.$yaxis_item], $form->query('xpath:.//div[@id="y'.$y.'_itemid"]/..')
+ ->asMultiselect()->one()->getValue()
+ );
+ }
+ }
+
+ if (array_key_exists('items', $data)) {
+ $item_row = $form->getFieldContainer('Items')->query('xpath:.//tr[@id="items_0"]')->one()->waitUntilPresent();
+
+ // Check lines styling functions.
+ foreach ($data['items'][0]['functions'] as $function => $value) {
+ $this->assertEquals($value, $item_row->query('xpath:.//z-select[@name="items[0]['.$function.']"]')
+ ->asDropdown()->one()->getValue()
+ );
+ }
+
+ // Check lines color.
+ $this->assertEquals($data['items'][0]['color'],
+ $item_row->query('xpath:.//div[@class="color-picker"]')->asColorPicker()->one()->getValue()
+ );
+ }
+ }
+
+ public static function getNoChangesData() {
+ return [
+ [
+ [
+ 'case' => 'simple_update'
+ ]
+ ],
+ [
+ [
+ 'case' => 'Create'
+ ]
+ ],
+ [
+ [
+ 'case' => 'Update'
+ ]
+ ],
+ [
+ [
+ 'case' => 'Clone'
+ ]
+ ],
+ [
+ [
+ 'case' => 'Delete'
+ ]
+ ]
+ ];
+ }
+
+ /**
+ * Function for checking Cancel button in all actions, as well as update graph form without any changes.
+ */
+ public function checkNoChanges($data) {
+ $old_hash = CDBHelper::getHash(self::SQL);
+ $this->page->login()->open($this->url)->waitUntilReady();
+
+ if ($data['case'] === 'Create') {
+ $this->query('button', 'Create graph'.$this->getGraphSuffix())->waitUntilClickable()->one()->click();
+ }
+ else {
+ $this->query('link', self::$update_graph)->waitUntilClickable()->one()->click();
+ }
+
+ $form = $this->query('name:graphForm')->waitUntilVisible()->asForm()->one();
+
+ if ($data['case'] === 'Clone' || $data['case'] === 'Delete') {
+ $form->query('button', $data['case'])->waitUntilClickable()->one()->click();
+ }
+
+ if ($data['case'] === 'Delete') {
+ $this->page->dismissAlert();
+ }
+
+ if ($data['case'] === 'simple_update') {
+ $form->submit();
+ $this->assertMessage(TEST_GOOD, 'Graph'.$this->getGraphSuffix().' updated');
+ }
+ else {
+ $form->query('button:Cancel')->waitUntilClickable()->one()->click();
+ }
+
+ $this->assertTrue($this->query('button', 'Create graph'.$this->getGraphSuffix())->exists());
+
+ // Check that DB hash is not changed.
+ $this->assertEquals($old_hash, CDBHelper::getHash(self::SQL));
+ }
+
+ /**
+ * Function for checking changes functions and color in existing item only.
+ */
+ public function changeItemSettings($data) {
+ $this->page->login()->open($this->url)->waitUntilReady();
+ $this->query('link:Graph for items change')->waitUntilClickable()->one()->click();
+ $form = $this->query('name:graphForm')->waitUntilVisible()->asForm()->one();
+ $item_number = $this->prototype ? 1 : 0;
+ $item_row = $form->getFieldContainer('Items')->query('xpath:.//tr[@id="items_'.$item_number.'"]')
+ ->one()->waitUntilPresent();
+
+ // Change line styling functions.
+ if (array_key_exists('functions', $data['change'])) {
+ foreach ($data['change']['functions'] as $function => $value) {
+ $item_row->query('xpath:.//z-select[@name="items['.$item_number.']['.$function.']"]')
+ ->asDropdown()->one()->fill($value);
+ }
+ }
+
+ // Change line color.
+ if (array_key_exists('color', $data['change'])) {
+ $item_row->query('xpath:.//div[@class="color-picker"]')->asColorPicker()->one()->fill($data['change']['color']);
+ }
+
+ $form->submit();
+ $this->assertMessage(TEST_GOOD, 'Graph'.$this->getGraphSuffix().' updated');
+ $this->query('xpath://form[@name="graphForm"]/table')->asTable()->one()->waitUntilPresent()
+ ->query('link:Graph for items change')->waitUntilClickable()->one()->click();
+ $item_row = $form->getFieldContainer('Items')->query('xpath:.//tr[@id="items_'.$item_number.'"]')
+ ->one()->waitUntilPresent();
+
+ // Check lines styling functions.
+ foreach ($data['expected']['functions'] as $function => $value) {
+ $this->assertEquals($value, $item_row->query('xpath:.//z-select[@name="items['.$item_number.']['.$function.']"]')
+ ->asDropdown()->one()->getValue()
+ );
+ }
+
+ $this->assertEquals($data['expected']['color'],
+ $item_row->query('xpath:.//div[@class="color-picker"]')->asColorPicker()->one()->getValue()
+ );
+ }
+
+ public function checkDelete() {
+ $this->page->login()->open($this->url)->waitUntilReady();
+ $name = 'Graph'.$this->getGraphSuffix().' for delete';
+ $this->query('link', $name)->waitUntilClickable()->one()->click();
+ $form = $this->query('name:graphForm')->waitUntilVisible()->asForm()->one();
+ $form->query('button:Delete')->waitUntilClickable()->one()->click();
+ $this->assertEquals('Delete graph'.$this->getGraphSuffix().'?', $this->page->getAlertText());
+ $this->page->acceptAlert();
+ $this->assertMessage(TEST_GOOD, 'Graph'.$this->getGraphSuffix().' deleted');
+ $this->assertEquals(0, CDBHelper::getCount('SELECT * FROM graphs WHERE name='.zbx_dbstr($name)));
+ }
+
+ /**
+ * Function for asserting that text, log and char items are not eligible for graph creating.
+ */
+ public function checkTextItems($data) {
+ $this->page->login()->open($this->url)->waitUntilReady();
+ $this->query('button', 'Create graph'.$this->getGraphSuffix())->waitUntilClickable()->one()->click();
+ $form = $this->query('name:graphForm')->waitUntilVisible()->asForm()->one();
+ $form->fill($data['fields']);
+ $items_container = $form->getFieldContainer('Items');
+
+ // Assert that text items are not suggested in multiselect.
+ foreach ($data['yaxis_items'] as $y => $yaxis_item) {
+ if ($this->prototype) {
+ $form->query('xpath:.//button[@id="yaxis_'.$y.'_prototype"]')->waitUntilClickable()->one()->click();
+ $dialog = COverlayDialogElement::find()->one();
+ $this->assertFalse($dialog->query('link', $yaxis_item)->exists());
+ $dialog->close();
+ }
+ else {
+ $form->query('xpath:.//div[@id="y'.$y.'_itemid"]/..')->asMultiselect()->one()->query('tag:input')
+ ->one()->type($yaxis_item);
+ $this->assertTrue($this->query('xpath://div[@class="multiselect-matches" and text()="No matches found"]')
+ ->waitUntilVisible()->one()->isVisible()
+ );
+ }
+ }
+
+ $items_container->query('button', 'Add'.$this->getGraphSuffix())->waitUntilClickable()->one()->click();
+ $dialog = COverlayDialogElement::find()->one();
+
+ // Assert that text items are not present in dialog.
+ foreach ($data['items'] as $item) {
+ $this->assertFalse($dialog->query('link', $item)->exists());
+ }
+
+ $dialog->close();
+ }
+
+ public function clearData() {
+ // Delete items.
+ CDataHelper::call('item.delete', [
+ self::$items['graph_trap_int']['itemid'],
+ self::$items['graph_trap_float']['itemid'],
+ self::$items['graph_trap_text']['itemid'],
+ self::$itemid
+ ]);
+
+ // Delete item prototypes.
+ CDataHelper::call('itemprototype.delete', [
+ self::$items['graph_prototype_trap_int']['itemid'],
+ self::$items['graph_prototype_trap_float']['itemid'],
+ self::$items['graph_prototype_trap_text']['itemid']
+ ]);
+ }
+}
diff --git a/ui/tests/selenium/graphs/testFormGraph.php b/ui/tests/selenium/graphs/testFormGraph.php
new file mode 100644
index 00000000000..8c57d3dc884
--- /dev/null
+++ b/ui/tests/selenium/graphs/testFormGraph.php
@@ -0,0 +1,572 @@
+<?php
+/*
+** Zabbix
+** Copyright (C) 2001-2022 Zabbix SIA
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** 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 General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+**/
+
+
+require_once dirname(__FILE__).'/../common/testFormGraphs.php';
+
+/**
+ * @backup graphs
+ *
+ * @onBefore prepareGraphsData
+ *
+ * @onAfter clearData
+ */
+class testFormGraph extends testFormGraphs {
+
+ protected $url = 'graphs.php?filter_set=1&filter_hostids%5B0%5D='.self::HOSTID.'&context=host';
+
+ public function prepareGraphsData() {
+ self::$update_graph = 'Graph for update';
+
+ // Create items on given host.
+ $items_data = [];
+ foreach (self::$items['items'] as $name => $fields) {
+ $items_data[] = [
+ 'hostid' => self::HOSTID,
+ 'name' => $name,
+ 'key_' => $name,
+ 'type' => ITEM_TYPE_TRAPPER,
+ 'value_type' => $fields['value_type']
+ ];
+ }
+
+ $items = CDataHelper::call('item.create', $items_data);
+ $this->assertArrayHasKey('itemids', $items);
+ $itemids = CDataHelper::getIds('name');
+
+ foreach (['int', 'float', 'text', 'log'] as $suffix) {
+ $field = 'graph_trap_'.$suffix;
+ self::$items[$field]['itemid'] = $itemids[$field];
+ }
+
+ // Create graphs with previously created items.
+ $prepared_graphs = [
+ [
+ 'name' => 'Graph for update',
+ 'itemid' => self::$items['graph_trap_int']['itemid']
+ ],
+ [
+ 'name' => 'Graph for delete',
+ 'itemid' => self::$items['graph_trap_float']['itemid']
+ ],
+ [
+ 'name' => 'Duplicated graph',
+ 'itemid' => self::$items['graph_trap_float']['itemid']
+ ],
+ [
+ 'name' => 'Graph for clone',
+ 'itemid' => self::$items['graph_trap_int']['itemid']
+ ],
+ [
+ 'name' => 'Graph for items change',
+ 'itemid' => self::$items['graph_trap_int']['itemid']
+ ]
+ ];
+
+ $graphs_data = [];
+ foreach ($prepared_graphs as $graph) {
+ $graphs_data[] = [
+ 'name' => $graph['name'],
+ 'width' => 850,
+ 'height' => 335,
+ 'gitems' => [
+ [
+ 'itemid' => $graph['itemid'],
+ 'color'=> 'FDD835'
+ ]
+ ]
+ ];
+ }
+
+ CDataHelper::call('graph.create', $graphs_data);
+ }
+
+ /**
+ * @dataProvider getLayoutData
+ */
+ public function testFormGraph_Layout($data) {
+ $this->checkGraphFormLayout($data);
+ }
+
+ public function getGraphData() {
+ return [
+ [
+ [
+ 'expected' => TEST_BAD,
+ 'fields' => [
+ 'Name' => 'Empty color'
+ ],
+ 'items' => [
+ [
+ 'item' => 'testFormItem',
+ 'color' => ''
+ ]
+ ],
+ 'details' => [
+ 'Empty color.'
+ ]
+ ]
+ ],
+ [
+ [
+ 'expected' => TEST_BAD,
+ 'fields' => [
+ 'Name' => 'Duplicated graph'
+ ],
+ 'items' => [
+ [
+ 'item' => 'testFormItem'
+ ]
+ ],
+ 'details' => [
+ 'Graph with name "Duplicated graph" already exists in graphs or graph prototypes.'
+ ]
+ ]
+ ],
+ [
+ [
+ 'expected' => TEST_BAD,
+ 'fields' => [
+ 'Name' => 'Exploded graph duplicated Graph sum type',
+ 'Graph type' => CFormElement::RELOADABLE_FILL('Exploded'),
+ 'Show legend' => false,
+ '3D view' => true
+ ],
+ 'items' => [
+ [
+ 'item' => 'Response code for step "testFormWeb1" of scenario "testFormWeb1".',
+ 'color'=> 'AB47BC',
+ 'functions' => [
+ 'type' => 'Simple',
+ 'calc_fnc' => 'min'
+ ]
+ ],
+ [
+ 'item' => 'Response code for step "testFormWeb2" of scenario "testFormWeb2".',
+ 'color'=> 'FFA000',
+ 'functions' => [
+ 'type' => 'Graph sum',
+ 'calc_fnc' => 'avg'
+ ]
+ ],
+ [
+ 'item' => 'Response code for step "testFormWeb3" of scenario "testFormWeb3".',
+ 'color'=> 'FFA001',
+ 'functions' => [
+ 'type' => 'Graph sum',
+ 'calc_fnc' => 'last'
+ ]
+ ]
+ ],
+ 'details' => [
+ 'Cannot add more than one item with type "Graph sum" on graph "Exploded graph duplicated Graph sum type".'
+ ]
+ ]
+ ],
+ [
+ [
+ 'expected' => TEST_BAD,
+ 'fields' => [
+ 'Name' => 'Max equals min value'.($this->prototype ? ' {#KEY}' : NULL),
+ 'id:ymin_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:ymax_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:yaxismin' => 0.1,
+ 'id:yaxismax' => 0.1
+ ],
+ 'items' => [
+ [
+ 'item' => 'testFormItem'
+ ]
+ ],
+ 'details' => [
+ 'Y axis MAX value must be greater than Y axis MIN value.'
+ ]
+ ]
+ ],
+ [
+ [
+ 'expected' => TEST_BAD,
+ 'fields' => [
+ 'Name' => 'Max less than min'.($this->prototype ? ' {#KEY}' : NULL),
+ 'id:ymin_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:ymax_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:yaxismin' => 0.2,
+ 'id:yaxismax' => 0.1
+ ],
+ 'items' => [
+ [
+ 'item' => 'testFormItem'
+ ]
+ ],
+ 'details' => [
+ 'Y axis MAX value must be greater than Y axis MIN value.'
+ ]
+ ]
+ ],
+ [
+ [
+ 'fields' => [
+ 'Name' => 'Normal graph items in Y axis values',
+ 'Width' => 65535,
+ 'Height' => 65535,
+ 'Graph type' => CFormElement::RELOADABLE_FILL('Normal'),
+ 'Show legend' => false,
+ 'Show working time' => false,
+ 'Show triggers' => false,
+ 'id:visible_percent_left' => true,
+ 'id:visible_percent_right' => true,
+ 'id:percent_left' => 5.5,
+ 'id:percent_right' => 99.9,
+ 'id:ymin_type' => CFormElement::RELOADABLE_FILL('Item'),
+ 'id:ymax_type' => CFormElement::RELOADABLE_FILL('Item')
+ ],
+ 'yaxis_items' => [
+ 'min' => 'Failed step of scenario "testFormWeb1".',
+ 'max' => 'Download speed for scenario "testFormWeb1".'
+ ],
+ 'items' => [
+ [
+ 'item' => 'testFormItem',
+ 'color'=> 'BBDEFB',
+ 'functions' => [
+ 'calc_fnc' => 'min',
+ 'drawtype' => 'Bold line',
+ 'yaxisside' => 'Right'
+ ]
+ ],
+ [
+ 'item' => 'testFormItem2',
+ 'color'=> 'FBC02D',
+ 'functions' => [
+ 'calc_fnc' => 'avg',
+ 'drawtype' => 'Filled region',
+ 'yaxisside' => 'Left'
+ ]
+ ],
+ [
+ 'item' => 'testFormItem3',
+ 'color'=> '7B1FA2',
+ 'functions' => [
+ 'calc_fnc' => 'max',
+ 'drawtype' => 'Dot',
+ 'yaxisside' => 'Right'
+ ]
+ ],
+ [
+ 'item' => 'testFormItem3',
+ 'color'=> 'FFE082',
+ 'functions' => [
+ 'calc_fnc' => 'avg',
+ 'drawtype' => 'Dashed line',
+ 'yaxisside' => 'Right'
+ ]
+ ],
+ [
+ 'item' => 'testFormItem4',
+ 'color'=> '7F3700',
+ 'functions' => [
+ 'calc_fnc' => 'avg',
+ 'drawtype' => 'Gradient line',
+ 'yaxisside' => 'Left'
+ ]
+ ]
+ ]
+ ]
+ ],
+ [
+ [
+ 'fields' => [
+ 'Name' => 'Stacked graph fixed Y axis values',
+ 'Width' => 20,
+ 'Height' => 20,
+ 'Graph type' => CFormElement::RELOADABLE_FILL('Stacked'),
+ 'Show legend' => true,
+ 'Show working time' => true,
+ 'Show triggers' => true,
+ 'id:ymin_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:ymax_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:yaxismin' => 0.1,
+ 'id:yaxismax' => 0.99
+ ],
+ 'items' => [
+ [
+ 'item' => 'testFormItem',
+ 'color'=> '00897B',
+ 'functions' => [
+ 'calc_fnc' => 'max',
+ 'yaxisside' => 'Right'
+ ]
+ ],
+ [
+ 'item' => 'testFormItem',
+ 'color'=> 'C3C3C3',
+ 'functions' => [
+ 'calc_fnc' => 'avg',
+ 'yaxisside' => 'Left'
+ ]
+ ],
+ [
+ 'item' => 'testFormItem',
+ 'color'=> '00897B',
+ 'functions' => [
+ 'calc_fnc' => 'min',
+ 'yaxisside' => 'Right'
+ ]
+ ]
+ ]
+ ]
+ ],
+ [
+ [
+ 'fields' => [
+ 'Name' => 'Pie graph 3D false',
+ 'Graph type' => CFormElement::RELOADABLE_FILL('Pie'),
+ 'Show legend' => true,
+ '3D view' => false
+ ],
+ 'items' => [
+ [
+ 'item' => 'Failed step of scenario "testFormWeb1".',
+ 'color'=> 'D2D2D2',
+ 'functions' => [
+ 'type' => 'Simple',
+ 'calc_fnc' => 'min'
+ ]
+ ],
+ [
+ 'item' => 'Failed step of scenario "testFormWeb2".',
+ 'color'=> 'C0CA33',
+ 'functions' => [
+ 'type' => 'Graph sum',
+ 'calc_fnc' => 'avg'
+ ]
+ ]
+ ]
+ ]
+ ],
+ [
+ [
+ 'fields' => [
+ 'Name' => 'Pie graph 3D true',
+ 'Graph type' => CFormElement::RELOADABLE_FILL('Pie'),
+ 'Show legend' => false,
+ '3D view' => true
+ ],
+ 'items' => [
+ [
+ 'item' => 'Failed step of scenario "testFormWeb3".',
+ 'color'=> 'AB47BC',
+ 'functions' => [
+ 'type' => 'Simple',
+ 'calc_fnc' => 'max'
+ ]
+ ],
+ [
+ 'item' => 'Failed step of scenario "testFormWeb4".',
+ 'color'=> 'FFA000',
+ 'functions' => [
+ 'type' => 'Graph sum',
+ 'calc_fnc' => 'last'
+ ]
+ ]
+ ]
+ ]
+ ],
+ [
+ [
+ 'fields' => [
+ 'Name' => 'Exploded graph 3D true',
+ 'Graph type' => CFormElement::RELOADABLE_FILL('Exploded'),
+ 'Show legend' => false,
+ '3D view' => true
+ ],
+ 'items' => [
+ [
+ 'item' => 'Response code for step "testFormWeb1" of scenario "testFormWeb1".',
+ 'color'=> 'AB47BC',
+ 'functions' => [
+ 'type' => 'Simple',
+ 'calc_fnc' => 'min'
+ ]
+ ],
+ [
+ 'item' => 'Response code for step "testFormWeb2" of scenario "testFormWeb2".',
+ 'color'=> 'FFA000',
+ 'functions' => [
+ 'type' => 'Graph sum',
+ 'calc_fnc' => 'avg'
+ ]
+ ]
+ ]
+ ]
+ ],
+ [
+ [
+ 'fields' => [
+ 'Name' => 'Exploded graph 3D false',
+ 'Graph type' => CFormElement::RELOADABLE_FILL('Exploded'),
+ 'Show legend' => true,
+ '3D view' => false
+ ],
+ 'items' => [
+ [
+ 'item' => 'Response code for step "testFormWeb3" of scenario "testFormWeb3".',
+ 'color'=> 'AB47BC',
+ 'functions' => [
+ 'type' => 'Simple',
+ 'calc_fnc' => 'max'
+ ]
+ ],
+ [
+ 'item' => 'Response code for step "testFormWeb4" of scenario "testFormWeb4".',
+ 'color'=> 'FFA000',
+ 'functions' => [
+ 'type' => 'Graph sum',
+ 'calc_fnc' => 'last'
+ ]
+ ]
+ ]
+ ]
+ ]
+ ];
+ }
+
+ /**
+ * @dataProvider getCommonGraphData
+ * @dataProvider getGraphData
+ */
+ public function testFormGraph_Create($data) {
+ $this->checkGraphForm($data);
+ }
+
+ /**
+ * @dataProvider getCommonGraphData
+ * @dataProvider getGraphData
+ */
+ public function testFormGraph_Update($data) {
+ $this->checkGraphForm($data, true);
+ }
+
+ /**
+ * @dataProvider getCloneData
+ */
+ public function testFormGraph_Clone($data) {
+ $this->checkClone($data);
+ }
+
+ /**
+ * @dataProvider getNoChangesData
+ */
+ public function testFormGraph_NoChanges($data) {
+ $this->checkNoChanges($data);
+ }
+
+ public static function getItemSettingsData() {
+ return [
+ [
+ [
+ 'change' => [
+ 'functions' => [
+ 'calc_fnc' => 'min',
+ 'drawtype' => 'Dashed line',
+ 'yaxisside' => 'Right'
+ ]
+ ],
+ 'expected' => [
+ 'functions' => [
+ 'calc_fnc' => 'min',
+ 'drawtype' => 'Dashed line',
+ 'yaxisside' => 'Right'
+ ],
+ 'color' => 'FDD835'
+ ]
+ ]
+ ],
+ [
+ [
+ 'change' => [
+ 'color' => 'BBDEFB'
+ ],
+ 'expected' => [
+ 'functions' => [
+ 'calc_fnc' => 'min',
+ 'drawtype' => 'Dashed line',
+ 'yaxisside' => 'Right'
+ ],
+ 'color' => 'BBDEFB'
+ ]
+ ]
+ ],
+ [
+ [
+ 'change' => [
+ 'functions' => [
+ 'calc_fnc' => 'all',
+ 'drawtype' => 'Dot',
+ 'yaxisside' => 'Left'
+ ],
+ 'color' => '891515'
+ ],
+ 'expected' => [
+ 'functions' => [
+ 'calc_fnc' => 'all',
+ 'drawtype' => 'Dot',
+ 'yaxisside' => 'Left'
+ ],
+ 'color' => '891515'
+ ]
+ ]
+ ]
+ ];
+ }
+
+ /**
+ * @dataProvider getItemSettingsData
+ */
+ public function testFormGraph_ChangeItemSettings($data) {
+ $this->changeItemSettings($data);
+ }
+
+ public function testFormGraph_Delete() {
+ $this->checkDelete();
+ }
+
+ public function testFormGraph_TextItems() {
+ $data = [
+ 'fields' => [
+ 'Name' => 'Graph of text items',
+ 'id:ymin_type' => CFormElement::RELOADABLE_FILL('Item'),
+ 'id:ymax_type' => CFormElement::RELOADABLE_FILL('Item')
+ ],
+ 'yaxis_items' => [
+ 'min' => 'graph_trap_text',
+ 'max' => 'graph_trap_log'
+ ],
+ 'items' => [
+ [
+ 'item' => 'graph_trap_text',
+ 'item' => 'graph_trap_log'
+ ]
+ ]
+ ];
+
+ $this->checkTextItems($data);
+ }
+}
diff --git a/ui/tests/selenium/graphs/testFormGraphPrototype.php b/ui/tests/selenium/graphs/testFormGraphPrototype.php
new file mode 100644
index 00000000000..66ed6a75791
--- /dev/null
+++ b/ui/tests/selenium/graphs/testFormGraphPrototype.php
@@ -0,0 +1,727 @@
+<?php
+/*
+** Zabbix
+** Copyright (C) 2001-2022 Zabbix SIA
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** 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 General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+**/
+
+
+require_once dirname(__FILE__).'/../common/testFormGraphs.php';
+
+/**
+ * @backup graphs
+ *
+ * @onBefore prepareGraphPrototypesData
+ *
+ * @onAfter clearData
+ */
+class testFormGraphPrototype extends testFormGraphs {
+
+ protected $prototype = true;
+ protected $url = 'graphs.php?parent_discoveryid='.self::LLDID.'&context=host';
+
+ public function prepareGraphPrototypesData() {
+ self::$update_graph = 'Graph for update';
+
+ // Create item on given host.
+ $items = CDataHelper::call('item.create', [
+ 'hostid' => self::HOSTID,
+ 'name' => 'item_graph_ptototype_test',
+ 'key_' => 'item_graph_ptototype_test',
+ 'type' => ITEM_TYPE_TRAPPER,
+ 'value_type' => ITEM_VALUE_TYPE_FLOAT
+ ]);
+ $this->assertArrayHasKey('itemids', $items);
+ self::$itemid = $items['itemids'][0];
+
+ // Create item prototypes on given host with given LLD.
+ foreach (self::$items['item_prototypes'] as $name => $fields) {
+ $item_prototypes_data[] = [
+ 'hostid' => self::HOSTID,
+ 'ruleid' => self::LLDID,
+ 'name' => $name,
+ 'key_' => $name.'[{#KEY}]',
+ 'type' => ITEM_TYPE_TRAPPER,
+ 'value_type' => $fields['value_type']
+ ];
+ }
+
+ $item_prototypes = CDataHelper::call('itemprototype.create', $item_prototypes_data);
+ $this->assertArrayHasKey('itemids', $item_prototypes);
+ $item_prototype_ids = CDataHelper::getIds('name');
+
+ foreach (['int', 'float', 'text', 'char'] as $suffix) {
+ $field = 'graph_prototype_trap_'.$suffix;
+ self::$items[$field]['itemid'] = $item_prototype_ids[$field];
+ }
+
+ // Create graphs with previously created items.
+ $prepared_graph_prototypes = [
+ [
+ 'name' => 'Graph for update',
+ 'itemid' => self::$items['graph_prototype_trap_int']['itemid']
+ ],
+ [
+ 'name' => 'Duplicated graph prototype',
+ 'itemid' => self::$items['graph_prototype_trap_int']['itemid']
+ ],
+ [
+ 'name' => 'Graph prototype for delete',
+ 'itemid' => self::$items['graph_prototype_trap_float']['itemid']
+ ],
+ [
+ 'name' => 'Graph prototype for clone',
+ 'itemid' => self::$items['graph_prototype_trap_int']['itemid']
+ ],
+ [
+ 'name' => 'Graph for items change',
+ 'itemid' => self::$items['graph_prototype_trap_int']['itemid']
+ ]
+ ];
+
+ $graph_prototypes_data = [];
+ foreach ($prepared_graph_prototypes as $graph_prototype) {
+ $graph_prototypes_data[] = [
+ 'name' => $graph_prototype['name'],
+ 'width' => 999,
+ 'height' => 222,
+ 'gitems' => [
+ [
+ 'itemid' => $graph_prototype['itemid'],
+ 'color'=> '5C6BC0'
+ ],
+ [
+ 'itemid' => self::$itemid,
+ 'color'=> '66BB6A'
+ ]
+ ]
+ ];
+ }
+
+ CDataHelper::call('graphprototype.create', $graph_prototypes_data);
+ }
+
+ /**
+ * @dataProvider getLayoutData
+ */
+ public function testFormGraphPrototype_Layout($data) {
+ $this->checkGraphFormLayout($data);
+ }
+
+ public function getGraphPrototypeData() {
+ return [
+ [
+ [
+ 'expected' => TEST_BAD,
+ 'fields' => [
+ 'Name' => 'Empty item prototype {#KEY}'
+ ],
+ 'items' => [
+ [
+ 'item' => 'testFormItem'
+ ]
+ ],
+ 'details' => [
+ 'Graph prototype "Empty item prototype {#KEY}" must have at least one item prototype.'
+ ]
+ ]
+ ],
+ [
+ [
+ 'expected' => TEST_BAD,
+ 'fields' => [
+ 'Name' => 'Empty color in item prototype {#KEY}'
+ ],
+ 'items' => [
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype1',
+ 'color' => ''
+ ]
+ ],
+ 'details' => [
+ 'Empty color.'
+ ]
+ ]
+ ],
+ [
+ [
+ 'fields' => [
+ 'Name' => 'Normal graph prototype without LLD macro'
+ ],
+ 'items' => [
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype1'
+ ]
+ ]
+ ]
+ ],
+ [
+ [
+ 'expected' => TEST_BAD,
+ 'fields' => [
+ 'Name' => 'Duplicated graph prototype'
+ ],
+ 'items' => [
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype1'
+ ]
+ ],
+ 'details' => [
+ 'Graph with name "Duplicated graph prototype" already exists in graphs or graph prototypes.'
+ ]
+ ]
+ ],
+ [
+ [
+ 'expected' => TEST_BAD,
+ 'fields' => [
+ 'Name' => 'Exploded graph prototype duplicated Graph sum type',
+ 'Graph type' => 'Exploded'
+ ],
+ 'items' => [
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype1',
+ 'color'=> 'AB47BC',
+ 'functions' => [
+ 'type' => 'Simple',
+ 'calc_fnc' => 'min'
+ ]
+ ],
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype2',
+ 'color'=> 'FFA000',
+ 'functions' => [
+ 'type' => 'Graph sum',
+ 'calc_fnc' => 'avg'
+ ]
+ ],
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype3',
+ 'color'=> 'FFA001',
+ 'functions' => [
+ 'type' => 'Graph sum',
+ 'calc_fnc' => 'last'
+ ]
+ ]
+ ],
+ 'details' => [
+ 'Cannot add more than one item with type "Graph sum" on graph prototype "Exploded graph prototype'.
+ ' duplicated Graph sum type".'
+ ]
+ ]
+ ],
+ [
+ [
+ 'expected' => TEST_BAD,
+ 'fields' => [
+ 'Name' => 'Exploded graph prototype duplicated Graph sum type mixed',
+ 'Graph type' => 'Exploded'
+ ],
+ 'items' => [
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype1',
+ 'color'=> 'AB47BC',
+ 'functions' => [
+ 'type' => 'Graph sum',
+ 'calc_fnc' => 'min'
+ ]
+ ],
+ [
+ 'item' => 'Response code for step "testFormWeb3" of scenario "testFormWeb3".',
+ 'color'=> 'FFA000',
+ 'functions' => [
+ 'type' => 'Graph sum',
+ 'calc_fnc' => 'avg'
+ ]
+ ]
+ ],
+ 'details' => [
+ 'Cannot add more than one item with type "Graph sum" on graph prototype "Exploded graph prototype '.
+ 'duplicated Graph sum type mixed".'
+ ]
+ ]
+ ],
+ [
+ [
+ 'fields' => [
+ 'Name' => 'Normal graph prototype with items in Y axis values {#KEY}',
+ 'Width' => 65535,
+ 'Height' => 65535,
+ 'Graph type' => CFormElement::RELOADABLE_FILL('Normal'),
+ 'Show legend' => false,
+ 'Show working time' => false,
+ 'Show triggers' => false,
+ 'id:visible_percent_left' => true,
+ 'id:visible_percent_right' => true,
+ 'id:percent_left' => 5.5,
+ 'id:percent_right' => 99.9,
+ 'id:ymin_type' => CFormElement::RELOADABLE_FILL('Item'),
+ 'id:ymax_type' => CFormElement::RELOADABLE_FILL('Item')
+ ],
+ 'yaxis_items' => [
+ 'min' => 'testFormItemPrototype1',
+ 'max' => 'testFormItemPrototype2'
+ ],
+ 'items' => [
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype1',
+ 'color'=> 'BBDEFB',
+ 'functions' => [
+ 'calc_fnc' => 'min',
+ 'drawtype' => 'Bold line',
+ 'yaxisside' => 'Right'
+ ]
+ ],
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype2',
+ 'color'=> 'FBC02D',
+ 'functions' => [
+ 'calc_fnc' => 'avg',
+ 'drawtype' => 'Filled region',
+ 'yaxisside' => 'Left'
+ ]
+ ],
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype3',
+ 'color'=> '7B1FA2',
+ 'functions' => [
+ 'calc_fnc' => 'max',
+ 'drawtype' => 'Dot',
+ 'yaxisside' => 'Right'
+ ]
+ ],
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype4',
+ 'color'=> 'FFE082',
+ 'functions' => [
+ 'calc_fnc' => 'avg',
+ 'drawtype' => 'Dashed line',
+ 'yaxisside' => 'Right'
+ ]
+ ],
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemReuse',
+ 'color'=> '7F3700',
+ 'functions' => [
+ 'calc_fnc' => 'avg',
+ 'drawtype' => 'Gradient line',
+ 'yaxisside' => 'Left'
+ ]
+ ]
+ ]
+ ]
+ ],
+ [
+ [
+ 'fields' => [
+ 'Name' => 'Stacked graph prototype fixed Y axis values',
+ 'Width' => 20,
+ 'Height' => 20,
+ 'Graph type' => CFormElement::RELOADABLE_FILL('Stacked'),
+ 'Show legend' => true,
+ 'Show working time' => true,
+ 'Show triggers' => true,
+ 'id:ymin_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:ymax_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:yaxismin' => 0.1,
+ 'id:yaxismax' => 0.99
+ ],
+ 'items' => [
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype1',
+ 'color'=> '00897B',
+ 'functions' => [
+ 'calc_fnc' => 'max',
+ 'yaxisside' => 'Right'
+ ]
+ ],
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype2',
+ 'color'=> 'C3C3C3',
+ 'functions' => [
+ 'calc_fnc' => 'avg',
+ 'yaxisside' => 'Left'
+ ]
+ ],
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype3',
+ 'color'=> '00897B',
+ 'functions' => [
+ 'calc_fnc' => 'min',
+ 'yaxisside' => 'Right'
+ ]
+ ]
+ ]
+ ]
+ ],
+ [
+ [
+ 'expected' => TEST_BAD,
+ 'fields' => [
+ 'Name' => 'Max equals min value'.($this->prototype ? ' {#KEY}' : NULL),
+ 'id:ymin_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:ymax_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:yaxismin' => 0.1,
+ 'id:yaxismax' => 0.1
+ ],
+ 'items' => [
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype1'
+ ]
+ ],
+ 'details' => [
+ 'Y axis MAX value must be greater than Y axis MIN value.'
+ ]
+ ]
+ ],
+ [
+ [
+ 'expected' => TEST_BAD,
+ 'fields' => [
+ 'Name' => 'Max less than min'.($this->prototype ? ' {#KEY}' : NULL),
+ 'id:ymin_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:ymax_type' => CFormElement::RELOADABLE_FILL('Fixed'),
+ 'id:yaxismin' => 0.2,
+ 'id:yaxismax' => 0.1
+ ],
+ 'items' => [
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype1'
+ ]
+ ],
+ 'details' => [
+ 'Y axis MAX value must be greater than Y axis MIN value.'
+ ]
+ ]
+ ],
+ [
+ [
+ 'fields' => [
+ 'Name' => 'Pie graph prototype 3D false',
+ 'Graph type' => CFormElement::RELOADABLE_FILL('Pie'),
+ 'Show legend' => true,
+ '3D view' => false
+ ],
+ 'items' => [
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype1',
+ 'color'=> 'D2D2D2',
+ 'functions' => [
+ 'type' => 'Simple',
+ 'calc_fnc' => 'min'
+ ]
+ ],
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype2',
+ 'color'=> 'C0CA33',
+ 'functions' => [
+ 'type' => 'Graph sum',
+ 'calc_fnc' => 'avg'
+ ]
+ ]
+ ]
+ ]
+ ],
+ [
+ [
+ 'fields' => [
+ 'Name' => 'Pie graph 3D true',
+ 'Graph type' => CFormElement::RELOADABLE_FILL('Pie'),
+ 'Show legend' => false,
+ '3D view' => true
+ ],
+ 'items' => [
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype3',
+ 'color'=> 'AB47BC',
+ 'functions' => [
+ 'type' => 'Simple',
+ 'calc_fnc' => 'max'
+ ]
+ ],
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype4',
+ 'color'=> 'FFA000',
+ 'functions' => [
+ 'type' => 'Graph sum',
+ 'calc_fnc' => 'last'
+ ]
+ ]
+ ]
+ ]
+ ],
+ [
+ [
+ 'fields' => [
+ 'Name' => 'Exploded graph 3D true, mixed items',
+ 'Graph type' => CFormElement::RELOADABLE_FILL('Exploded'),
+ 'Show legend' => false,
+ '3D view' => true
+ ],
+ 'items' => [
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype1',
+ 'color'=> 'AB47BC',
+ 'functions' => [
+ 'type' => 'Simple',
+ 'calc_fnc' => 'min'
+ ]
+ ],
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype2',
+ 'color'=> 'FFA000',
+ 'functions' => [
+ 'type' => 'Graph sum',
+ 'calc_fnc' => 'avg'
+ ]
+ ],
+ [
+ 'item' => 'Response code for step "testFormWeb3" of scenario "testFormWeb3".',
+ 'color'=> 'AB47BC',
+ 'functions' => [
+ 'type' => 'Simple',
+ 'calc_fnc' => 'max'
+ ]
+ ],
+ [
+ 'item' => 'Response code for step "testFormWeb4" of scenario "testFormWeb4".',
+ 'color'=> 'FFA000',
+ 'functions' => [
+ 'type' => 'Simple',
+ 'calc_fnc' => 'last'
+ ]
+ ]
+ ]
+ ]
+ ],
+ [
+ [
+ 'fields' => [
+ 'Name' => 'Exploded graph 3D false, mixed items',
+ 'Graph type' => CFormElement::RELOADABLE_FILL('Exploded'),
+ 'Show legend' => true,
+ '3D view' => false
+ ],
+ 'items' => [
+ [
+ 'item' => 'Response code for step "testFormWeb3" of scenario "testFormWeb3".',
+ 'color'=> 'AB47BC',
+ 'functions' => [
+ 'type' => 'Simple',
+ 'calc_fnc' => 'max'
+ ]
+ ],
+ [
+ 'item' => 'Response code for step "testFormWeb4" of scenario "testFormWeb4".',
+ 'color'=> 'FFA000',
+ 'functions' => [
+ 'type' => 'Graph sum',
+ 'calc_fnc' => 'last'
+ ]
+ ],
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype1',
+ 'color'=> 'AB47BC',
+ 'functions' => [
+ 'type' => 'Simple',
+ 'calc_fnc' => 'min'
+ ]
+ ],
+ [
+ 'prototype' => true,
+ 'item' => 'testFormItemPrototype2',
+ 'color'=> 'FFA000',
+ 'functions' => [
+ 'type' => 'Simple',
+ 'calc_fnc' => 'avg'
+ ]
+ ]
+ ]
+ ]
+ ]
+ ];
+ }
+
+ /**
+ * @dataProvider getCommonGraphData
+ * @dataProvider getGraphPrototypeData
+ */
+ public function testFormGraphPrototype_Create($data) {
+ $this->checkGraphForm($data);
+ }
+
+ /**
+ * @dataProvider getCommonGraphData
+ * @dataProvider getGraphPrototypeData
+ */
+ public function testFormGraphPrototype_Update($data) {
+ $this->checkGraphForm($data, true);
+ }
+
+ /**
+ * @dataProvider getCloneData
+ */
+ public function testFormGraphPrototype_Clone($data) {
+ $this->checkClone($data);
+ }
+
+ /**
+ * @dataProvider getNoChangesData
+ */
+ public function testFormGraphPrototype_NoChanges($data) {
+ $this->checkNoChanges($data);
+ }
+
+ public static function getItemPrototypeSettingsData() {
+ return [
+ [
+ [
+ 'change' => [
+ 'functions' => [
+ 'calc_fnc' => 'avg',
+ 'drawtype' => 'Gradient line',
+ 'yaxisside' => 'Right'
+ ]
+ ],
+ 'expected' => [
+ 'functions' => [
+ 'calc_fnc' => 'avg',
+ 'drawtype' => 'Gradient line',
+ 'yaxisside' => 'Right'
+ ],
+ 'color' => '66BB6A'
+ ]
+ ]
+ ],
+ [
+ [
+ 'change' => [
+ 'color' => 'FFBF00'
+ ],
+ 'expected' => [
+ 'functions' => [
+ 'calc_fnc' => 'avg',
+ 'drawtype' => 'Gradient line',
+ 'yaxisside' => 'Right'
+ ],
+ 'color' => 'FFBF00'
+ ]
+ ]
+ ],
+ [
+ [
+ 'change' => [
+ 'functions' => [
+ 'calc_fnc' => 'max',
+ 'drawtype' => 'Filled region',
+ 'yaxisside' => 'Left'
+ ],
+ 'color' => 'D7CCC8'
+ ],
+ 'expected' => [
+ 'functions' => [
+ 'calc_fnc' => 'max',
+ 'drawtype' => 'Filled region',
+ 'yaxisside' => 'Left'
+ ],
+ 'color' => 'D7CCC8'
+ ]
+ ]
+ ]
+ ];
+ }
+
+ /**
+ * @dataProvider getItemPrototypeSettingsData
+ */
+ public function testFormGraphPrototype_ChangeItemSettings($data) {
+ $this->changeItemSettings($data);
+ }
+
+ public function testFormGraphPrototype_Delete() {
+ $this->checkDelete();
+ }
+
+ public static function getTextItemPrototypesData() {
+ return [
+ [
+ [
+ 'fields' => [
+ 'Name' => 'Graph prototype of text items',
+ 'id:ymin_type' => CFormElement::RELOADABLE_FILL('Item'),
+ 'id:ymax_type' => CFormElement::RELOADABLE_FILL('Item')
+ ],
+ 'yaxis_items' => [
+ 'min' => 'graph_prototype_trap_text',
+ 'max' => 'graph_prototype_trap_char'
+ ],
+ 'items' => [
+ [
+ 'item' => 'graph_prototype_trap_text',
+ 'item' => 'graph_prototype_trap_char'
+ ]
+ ]
+ ]
+ ]
+ ];
+ }
+
+ public function testFormGraphPrototype_TextItems() {
+ $data = [
+ 'fields' => [
+ 'Name' => 'Graph prototype of text items',
+ 'id:ymin_type' => CFormElement::RELOADABLE_FILL('Item'),
+ 'id:ymax_type' => CFormElement::RELOADABLE_FILL('Item')
+ ],
+ 'yaxis_items' => [
+ 'min' => 'graph_prototype_trap_text',
+ 'max' => 'graph_prototype_trap_char'
+ ],
+ 'items' => [
+ [
+ 'item' => 'graph_prototype_trap_text',
+ 'item' => 'graph_prototype_trap_char'
+ ]
+ ]
+ ];
+
+ $this->checkTextItems($data);
+ }
+}
diff --git a/ui/tests/selenium/testGraphAxis.php b/ui/tests/selenium/graphs/testGraphAxis.php
index 15248820d0c..e835f370cf2 100644
--- a/ui/tests/selenium/testGraphAxis.php
+++ b/ui/tests/selenium/graphs/testGraphAxis.php
@@ -18,7 +18,8 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-require_once dirname(__FILE__).'/../include/CWebTest.php';
+
+require_once dirname(__FILE__).'/../../include/CWebTest.php';
/**
* @backup profiles
diff --git a/ui/tests/selenium/testInheritanceGraph.php b/ui/tests/selenium/graphs/testInheritanceGraph.php
index 3d1e4675993..c90bc539b5d 100644
--- a/ui/tests/selenium/testInheritanceGraph.php
+++ b/ui/tests/selenium/graphs/testInheritanceGraph.php
@@ -18,7 +18,8 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-require_once dirname(__FILE__).'/../include/CLegacyWebTest.php';
+
+require_once dirname(__FILE__).'/../../include/CLegacyWebTest.php';
/**
* Test the creation of inheritance of new objects on a previously linked template.
diff --git a/ui/tests/selenium/testInheritanceGraphPrototype.php b/ui/tests/selenium/graphs/testInheritanceGraphPrototype.php
index 59f5b8875e8..2126a0cdd7c 100644
--- a/ui/tests/selenium/testInheritanceGraphPrototype.php
+++ b/ui/tests/selenium/graphs/testInheritanceGraphPrototype.php
@@ -18,7 +18,8 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-require_once dirname(__FILE__).'/../include/CLegacyWebTest.php';
+
+require_once dirname(__FILE__).'/../../include/CLegacyWebTest.php';
/**
* Test the creation of inheritance of new objects on a previously linked template.
diff --git a/ui/tests/selenium/testPageGraphPrototypes.php b/ui/tests/selenium/graphs/testPageGraphPrototypes.php
index 1c9f40db269..82277a29948 100644
--- a/ui/tests/selenium/testPageGraphPrototypes.php
+++ b/ui/tests/selenium/graphs/testPageGraphPrototypes.php
@@ -18,7 +18,8 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-require_once dirname(__FILE__).'/../include/CLegacyWebTest.php';
+
+require_once dirname(__FILE__).'/../../include/CLegacyWebTest.php';
use Facebook\WebDriver\WebDriverBy;
@@ -78,7 +79,7 @@ class testPageGraphPrototypes extends CLegacyWebTest {
// Check table headers.
$this->assertEquals(['Name', 'Width', 'Height', 'Graph type', 'Discover'],
- $this->getTextOfElements('//form[@name="graphForm"]//thead/tr/th[not(@class)]')
+ $this->getTextOfElements("//form[@name=\"graphForm\"]//thead/tr/th[not(@class)]")
);
// Check graph prototype number in breadcrumb.
diff --git a/ui/tests/selenium/testPageHostGraph.php b/ui/tests/selenium/graphs/testPageHostGraph.php
index 2516df07072..c97c9d46f22 100644
--- a/ui/tests/selenium/testPageHostGraph.php
+++ b/ui/tests/selenium/graphs/testPageHostGraph.php
@@ -18,7 +18,8 @@
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
-require_once dirname(__FILE__).'/../include/CLegacyWebTest.php';
+
+require_once dirname(__FILE__).'/../../include/CLegacyWebTest.php';
use Facebook\WebDriver\WebDriverBy;
diff --git a/ui/tests/selenium/testFormGraph.php b/ui/tests/selenium/testFormGraph.php
deleted file mode 100644
index ab931e740ca..00000000000
--- a/ui/tests/selenium/testFormGraph.php
+++ /dev/null
@@ -1,1007 +0,0 @@
-<?php
-/*
-** Zabbix
-** Copyright (C) 2001-2022 Zabbix SIA
-**
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License as published by
-** the Free Software Foundation; either version 2 of the License, or
-** (at your option) any later version.
-**
-** 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 General Public License for more details.
-**
-** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-**/
-
-require_once dirname(__FILE__).'/../include/CLegacyWebTest.php';
-require_once dirname(__FILE__).'/../../include/items.inc.php';
-
-use Facebook\WebDriver\WebDriverBy;
-
-/**
- * @backup graphs
- */
-class testFormGraph extends CLegacyWebTest {
-
- /**
- * The name of the host for the testing of the create function created in the test data set.
- *
- * @var string
- */
- protected $host = 'Simple form test host';
-
- /**
- * The name of the host group that the above host belongs to.
- *
- * @var string
- */
- protected $hostGroup = 'Zabbix servers';
-
- /**
- * The name of the host item for the testing of the layout of the graphs created in the test data set.
- *
- * @var string
- */
- protected $itemSimple = 'testFormItem';
-
- /**
- * The name of the inheritance item for the testing of the layout of the graphs created in the test data set.
- *
- * @var string
- */
- protected $itemInheritance = 'itemInheritance';
-
- // Returns layout data
- public static function layout() {
- return [
- [
- [
- 'ymin_type' => 'Fixed',
- 'ymax_type' => 'Item',
- 'host' => 'Simple form test host'
- ]
- ],
- [
- [
- 'graphtype' => 'Normal',
- 'host' => 'Simple form test host'
- ]
- ],
- [
- [
- 'graphtype' => 'Stacked',
- 'host' => 'Simple form test host'
- ]
- ],
- [
- [
- 'graphtype' => 'Stacked',
- 'ymin_type' => 'Fixed' ,
- 'host' => 'Simple form test host'
- ]
- ],
- [
- [
- 'graphtype' => 'Stacked',
- 'ymin_type' => 'Item',
- 'ymax_type' => 'Fixed',
- 'host' => 'Simple form test host'
- ]
- ],
- [
- [
- 'graphtype' => 'Stacked',
- 'ymin_type' => 'Item',
- 'ymax_type' => 'Item',
- 'host' => 'Simple form test host'
- ]
- ],
- [
- [
- 'graphtype' => 'Pie',
- 'host' => 'Simple form test host'
- ]
- ],
- [
- [
- 'graphtype' => 'Exploded',
- 'host' => 'Simple form test host'
- ]
- ],
- [
- [
- 'host' => 'Simple form test host',
- 'form' => 'testFormGraph1'
- ]
- ],
- [
- [
- 'ymin_type' => 'Fixed',
- 'ymax_type' => 'Item',
- 'template' => 'Inheritance test template'
- ]
- ],
- [
- [
- 'template' => 'Inheritance test template',
- 'form' => 'testInheritanceGraph1'
- ]
- ],
- [
- [
- 'host' => 'Template inheritance test host',
- 'templatedHost' => 'Inheritance test template',
- 'form' => 'testInheritanceGraph1'
- ]
- ],
- [
- [
- 'graphtype' => 'Normal',
- 'template' => 'Inheritance test template'
- ]
- ],
- [
- [
- 'graphtype' => 'Stacked',
- 'template' => 'Inheritance test template'
- ]
- ],
- [
- [
- 'graphtype' => 'Stacked',
- 'ymin_type' => 'Fixed' ,
- 'template' => 'Inheritance test template'
- ]
- ],
- [
- [
- 'graphtype' => 'Stacked',
- 'ymin_type' => 'Item',
- 'ymax_type' => 'Fixed',
- 'template' => 'Inheritance test template'
- ]
- ],
- [
- [
- 'graphtype' => 'Stacked',
- 'ymin_type' => 'Item',
- 'ymax_type' => 'Item',
- 'template' => 'Inheritance test template'
- ]
- ],
- [
- [
- 'graphtype' => 'Pie',
- 'template' => 'Inheritance test template'
- ]
- ],
- [
- [
- 'graphtype' => 'Exploded',
- 'template' => 'Inheritance test template'
- ]
- ]
- ];
- }
-
- /**
- * @dataProvider layout
- */
- public function testFormGraph_CheckLayout($data) {
-
- if (isset($data['template'])) {
- $this->zbxTestLogin('templates.php');
- $this->query('button:Reset')->one()->click();
- $form = $this->query('name:zbx_filter')->asForm()->waitUntilReady()->one();
- $this->filterEntriesAndOpenGraph($data['template'], $form);
- $hostid = 30000;
- }
-
- if (isset($data['host'])) {
- $this->zbxTestLogin(self::HOST_LIST_PAGE);
- $this->query('button:Reset')->one()->click();
- $form = $this->query('name:zbx_filter')->asForm()->waitUntilReady()->one();
- $this->filterEntriesAndOpenGraph($data['host'], $form);
- if (isset($data['templatedHost'])) {
- $hostid = 30001;
- }
- else {
- $hostid = 40001;
- }
- }
-
- $this->zbxTestCheckTitle('Configuration of graphs');
- $this->zbxTestCheckHeader('Graphs');
-
- if (isset($data['form'])) {
- $this->zbxTestClickLinkTextWait($data['form']);
- }
- else {
- $this->zbxTestContentControlButtonClickTextWait('Create graph');
- }
-
- $this->zbxTestCheckTitle('Configuration of graphs');
- $this->zbxTestTextPresent('Graphs');
-
- if (isset($data['templatedHost'])) {
- $this->zbxTestTextPresent('Parent graphs');
- if (isset($data['hostTemplate'])) {
- $this->zbxTestAssertElementPresentXpath("//a[text()='".$data['hostTemplate']."']");
- }
- }
- else {
- $this->zbxTestTextNotPresent('Parent graphs');
- }
-
- $this->zbxTestTextPresent('Name');
- $this->zbxTestAssertVisibleId('name');
- $this->zbxTestAssertAttribute("//input[@id='name']", 'maxlength', 255);
- $this->zbxTestAssertAttribute("//input[@id='name']", 'autofocus');
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertAttribute("//input[@id='name']", 'readonly');
- }
- else {
- $this->zbxTestAssertElementNotPresentXpath("//input[@id='name'][readonly]");
- }
-
- $this->zbxTestTextPresent('Width');
- $this->zbxTestAssertVisibleId('width');
- $this->zbxTestAssertAttribute("//input[@id='width']", 'maxlength', 5);
- $this->zbxTestAssertElementValue('width', 900);
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertAttribute("//input[@id='width']", 'readonly');
- }
- else {
- $this->zbxTestAssertElementNotPresentXpath("//input[@id='width'][readonly]");
- }
-
- $this->zbxTestTextPresent('Height');
- $this->zbxTestAssertVisibleId('height');
- $this->zbxTestAssertAttribute("//input[@id='height']", 'maxlength', 5);
- $this->zbxTestAssertElementValue('height', 200);
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertAttribute("//input[@id='height']", 'readonly');
- }
- else {
- $this->zbxTestAssertElementNotPresentXpath("//input[@id='height'][readonly]");
- }
-
- $this->zbxTestTextPresent('Graph type');
- $this->zbxTestAssertVisibleId('graphtype');
- $this->zbxTestDropdownHasOptions('graphtype', [
- 'Normal',
- 'Stacked',
- 'Pie',
- 'Exploded'
- ]);
- if (!isset($data['form'])) {
- $this->zbxTestDropdownAssertSelected('graphtype', 'Normal');
- }
-
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertAttribute("//z-select[@id='graphtype']", 'disabled');
- }
- else {
- $this->zbxTestAssertElementNotPresentXpath("//z-select[@id='graphtype'][@disabled]");
- }
-
- if (isset($data['graphtype'])) {
- $this->zbxTestDropdownSelectWait('graphtype', $data['graphtype']);
- }
- $graphtype = $this->zbxTestGetSelectedLabel('graphtype');
-
- if (isset($data['ymin_type'])) {
- $this->zbxTestDropdownSelectWait('ymin_type', $data['ymin_type']);
- }
-
- if (isset($data['ymax_type'])) {
- $this->zbxTestDropdownSelectWait('ymax_type', $data['ymax_type']);
- }
-
- if ($graphtype == 'Normal' || $graphtype == 'Stacked') {
- $ymin_type = $this->zbxTestGetSelectedLabel('ymin_type');
- $ymax_type = $this->zbxTestGetSelectedLabel('ymax_type');
- }
- else {
- $ymin_type = null;
- $ymax_type = null;
- }
-
- $this->zbxTestTextPresent('Show legend');
- $this->zbxTestAssertElementPresentId('show_legend');
- if (!isset($data['form'])) {
- $this->assertTrue($this->zbxTestCheckboxSelected('show_legend'));
- }
-
- if ($graphtype == 'Normal' || $graphtype == 'Stacked') {
- $this->zbxTestTextPresent('Show working time');
- $this->zbxTestAssertElementPresentId('show_work_period');
-
- if (!isset($data['form'])) {
- $this->assertTrue($this->zbxTestCheckboxSelected('show_work_period'));
- }
-
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertAttribute("//*[@id='show_work_period']", 'disabled');
- }
- else {
- $this->zbxTestAssertElementNotPresentXpath("//*[@id='show_work_period'][@disabled]");
- }
- }
- else {
- $this->zbxTestTextNotPresent('Show working time');
- $this->zbxTestAssertElementNotPresentId('show_work_period');
- }
-
- if ($graphtype == 'Normal' || $graphtype == 'Stacked') {
- $this->zbxTestTextPresent('Show triggers');
- $this->zbxTestAssertElementPresentId('show_triggers');
- if (!isset($data['form'])) {
- $this->assertTrue($this->zbxTestCheckboxSelected('show_triggers'));
- }
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertAttribute("//*[@id='show_triggers']", 'disabled');
- }
- else {
- $this->zbxTestAssertElementNotPresentXpath("//*[@id='show_triggers'][@disabled]");
- }
- }
- else {
- $this->zbxTestTextNotPresent('Show triggers');
- $this->zbxTestAssertElementNotPresentId('show_triggers');
- }
-
- if ($graphtype == 'Normal') {
- $this->zbxTestTextPresent('Percentile line (left)');
- $this->zbxTestAssertElementPresentId('visible_percent_left');
- $this->zbxTestTextPresent('Percentile line (right)');
- $this->zbxTestAssertElementPresentId('visible_percent_right');
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertAttribute("//input[@id='visible_percent_left']", 'disabled');
- $this->zbxTestAssertAttribute("//input[@id='visible_percent_right']", 'disabled');
- }
- }
- else {
- $this->zbxTestTextNotPresent('Percentile line (left)');
- $this->zbxTestAssertElementNotPresentId('visible_percent_left');
-
- $this->zbxTestTextNotPresent('Percentile line (right)');
- $this->zbxTestAssertElementNotPresentId('visible_percent_right');
- }
-
- if ($graphtype == 'Pie' || $graphtype == 'Exploded') {
- $this->zbxTestTextPresent('3D view');
- $this->zbxTestAssertElementPresentId('show_3d');
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertAttribute("//input[@id='show_3d']/@disabled", 'disabled');
- }
- else {
- $this->zbxTestAssertElementNotPresentXpath("//input[@id='show_3d'][@disabled]");
- }
- }
- else {
- $this->zbxTestTextNotPresent('3D view');
- $this->zbxTestAssertElementNotPresentId('show_3d');
- }
-
- if ($graphtype == 'Normal' || $graphtype == 'Stacked') {
- $this->zbxTestTextPresent('Y axis MIN value');
- $this->zbxTestAssertElementPresentId('ymin_type');
- $this->zbxTestDropdownHasOptions('ymin_type', [
- 'Calculated',
- 'Fixed',
- 'Item'
- ]);
-
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertAttribute("//z-select[@id='ymin_type']", 'disabled');
- }
- else {
- $this->zbxTestAssertElementNotPresentXpath("//z-select[@id='ymin_type'][@disabled]");
- }
-
- if (!isset($data['form'])) {
- switch ($ymin_type) {
- case 'Calculated':
- case 'Fixed':
- case 'Item':
- $this->zbxTestDropdownAssertSelected('ymin_type', $ymin_type);
- break;
- }
- }
-
- $this->zbxTestTextPresent('Y axis MAX value');
- $this->zbxTestAssertElementPresentId('ymax_type');
- $this->zbxTestDropdownHasOptions('ymax_type', [
- 'Calculated',
- 'Fixed',
- 'Item'
- ]);
-
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertAttribute("//z-select[@id='ymax_type']", 'disabled');
- }
- else {
- $this->zbxTestAssertElementNotPresentXpath("//z-select[@id='ymax_type'][@disabled]");
- }
-
- if (!isset($data['form'])) {
- switch ($ymax_type) {
- case 'Calculated':
- case 'Fixed':
- case 'Item':
- $this->zbxTestDropdownAssertSelected('ymax_type', $ymax_type);
- break;
- }
- }
- }
- else {
- $this->zbxTestTextNotPresent('Y axis MIN value');
- $this->zbxTestAssertElementNotPresentId('ymin_type');
-
- $this->zbxTestTextNotPresent('Y axis MAX value');
- $this->zbxTestAssertElementNotPresentId('ymax_type');
- }
-
- if (!isset($data['form'])) {
- // add general item
- $this->zbxTestClick('add_item');
- $this->zbxTestLaunchOverlayDialog('Items');
-
- if (isset($data['host'])) {
- $host = COverlayDialogElement::find()->one()->query('class:multiselect-control')->asMultiselect()->one();
- $host->fill($this->host);
- COverlayDialogElement::find()->one()->waitUntilReady();
- $this->zbxTestClickLinkText($this->itemSimple);
- }
-
- if (isset($data['template'])) {
- $this->zbxTestClickLinkText($this->itemInheritance);
- }
-
- switch($ymin_type) {
- case 'Fixed':
- $this->zbxTestAssertVisibleId('yaxismin');
- $this->zbxTestAssertElementValue('yaxismin', 0);
-
- $this->zbxTestAssertElementNotPresentId('ymin_itemid');
- break;
- case 'Calculated':
- $this->zbxTestAssertElementNotPresentId('ymin_itemid');
- $this->zbxTestAssertNotVisibleId('yaxismin');
- break;
- case 'Item':
- $this->zbxTestAssertElementPresentId('ymin_itemid');
- $this->zbxTestAssertElementText("//div[@id='ymin_itemid']//following-sibling::div/button", 'Select');
-
- $this->zbxTestAssertNotVisibleId('yaxismin');
- break;
- default:
- $this->zbxTestTextNotPresent('Add graph items first');
- $this->zbxTestAssertElementNotPresentId('ymin_itemid');
- $this->zbxTestAssertElementNotPresentId('yaxismin');
- break;
- }
-
- switch($ymax_type) {
- case 'Fixed':
- $this->zbxTestAssertVisibleId('yaxismax');
- $this->zbxTestAssertElementValue('yaxismax', 100);
-
- $this->zbxTestAssertElementNotPresentId('ymax_itemid');
- break;
- case 'Calculated':
- $this->zbxTestAssertElementNotPresentId('ymax_itemid');
- $this->zbxTestAssertNotVisibleId('yaxismax');
- break;
- case 'Item':
- $this->zbxTestDropdownSelectWait('ymax_type', 'Calculated');
- $this->zbxTestDropdownSelectWait('ymax_type', 'Item');
- $this->zbxTestAssertElementPresentId('ymax_itemid');
- $this->zbxTestAssertElementText("//div[@id='ymax_itemid']//following-sibling::div/button", 'Select');
-
- $this->zbxTestAssertNotVisibleId('yaxismax');
- break;
- default:
- $this->zbxTestTextNotPresent('Add graph items first');
- $this->zbxTestAssertElementNotPresentId('ymax_itemid');
- $this->zbxTestAssertElementNotPresentId('yaxismax');
- break;
- }
-
- switch ($graphtype) {
- case 'Normal':
- $this->zbxTestTextPresent(['Items', 'Name', 'Function', 'Draw style', 'Y axis side', 'Color', 'Action']);
- break;
- case 'Stacked':
- $this->zbxTestTextPresent(['Items', 'Name', 'Function', 'Y axis side', 'Color', 'Action']);
- break;
- case 'Pie':
- case 'Exploded':
- $this->zbxTestTextPresent(['Items', 'Name', 'Type', 'Function', 'Color', 'Action']);
- break;
- }
- }
-
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertElementNotPresentId('add_item');
- }
- else {
- $this->zbxTestAssertVisibleId('add_item');
- $this->zbxTestAssertElementText("//button[@id='add_item']", 'Add');
- $this->zbxTestAssertElementNotPresentXpath("//button[@id='add_item'][@disabled]");
- }
-
- $this->zbxTestTabSwitch('Preview');
-
- $this->zbxTestAssertVisibleId('cancel');
- $this->zbxTestAssertElementText("//button[@id='cancel']", 'Cancel');
-
- if (isset($data['form'])) {
- $this->zbxTestAssertVisibleId('update');
- $this->zbxTestAssertElementValue('update', 'Update');
- $this->zbxTestAssertVisibleId('clone');
- $this->zbxTestAssertElementValue('clone', 'Clone');
- $this->zbxTestAssertVisibleId('delete');
- $this->zbxTestAssertElementValue('delete', 'Delete');
-
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertAttribute("//button[@id='update']", 'disabled');
- $this->zbxTestAssertAttribute("//button[@id='delete']", 'disabled');
- }
- else {
- $this->zbxTestAssertElementNotPresentXpath("//button[@id='update'][@disabled]");
- $this->zbxTestAssertElementNotPresentXpath("//button[@id='delete'][@disabled]");
- }
- }
- else {
- $this->zbxTestAssertVisibleId('add');
- $this->zbxTestAssertElementValue('add', 'Add');
- $this->zbxTestAssertElementNotPresentId('clone');
- $this->zbxTestAssertElementNotPresentId('update');
- $this->zbxTestAssertElementNotPresentId('delete');
- }
- }
-
- // Returns update data
- public static function update() {
- return CDBHelper::getDataProvider(
- 'SELECT * FROM graphs g'.
- ' LEFT JOIN graphs_items gi'.
- ' ON gi.graphid=g.graphid'.
- ' WHERE g.graphid BETWEEN 300000 AND 300010'
- );
- }
-
- /**
- * @dataProvider update
- */
- public function testFormGraph_SimpleUpdate($data) {
- $sqlGraphs = 'SELECT * FROM graphs ORDER BY graphid';
- $oldHashGraphs = CDBHelper::getHash($sqlGraphs);
-
- $this->zbxTestLogin('graphs.php?form=update&graphid='.$data['graphid'].'&hostid=40001&context=host');
- $this->zbxTestClickWait('update');
- $this->zbxTestCheckTitle('Configuration of graphs');
- $this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Graph updated');
- $filter = $this->query('name:zbx_filter')->asForm()->one();
- $filter->getField('Hosts')->clear()->fill('Simple form test host');
- $filter->submit();
- $this->zbxTestTextPresent([
- $data['name'],
- 'Graphs'
- ]);
-
- $this->assertEquals($oldHashGraphs, CDBHelper::getHash($sqlGraphs));
- }
-
- // Returns create data
- public static function create() {
- return [
- [
- [
- 'expected' => TEST_BAD,
- 'error-msg' => 'Page received incorrect data',
- 'errors' => [
- 'Incorrect value for field "Name": cannot be empty.'
- ]
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'name' => 'graphSaveCheck',
- 'addItems' => [
- ['itemName' => 'testFormItem', 'remove' => true],
- ['itemName' => 'testFormItem']
- ],
- 'dbCheck' => true,
- 'formCheck' => true
- ]
- ],
- [
- [
- 'expected' => TEST_BAD,
- 'name' => 'testFormGraph1',
- 'addItems' => [
- ['itemName' => 'testFormItem']
- ],
- 'error-msg' => 'Cannot add graph',
- 'errors' => [
- 'Graph with name "testFormGraph1" already exists in graphs or graph prototypes.'
- ]
- ]
- ],
- [
- [
- 'expected' => TEST_BAD,
- 'name' => 'graphSaveCheck',
- 'error-msg' => 'Cannot add graph',
- 'errors' => [
- 'Missing items for graph "graphSaveCheck".'
- ]
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'name' => 'graphNormal1',
- 'addItems' => [
- ['itemName' => 'testFormItem']
- ],
- 'ymin_type' => 'Fixed',
- 'ymax_type' => 'Item',
- 'ymax_name' => 'testFormItem',
- 'dbCheck' => true,
- 'formCheck' => true
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'name' => 'graphNormal2',
- 'addItems' => [
- ['itemName' => 'testFormItem']
- ],
- 'ymin_type' => 'Item',
- 'ymin_name' => 'testFormItem',
- 'ymax_type' => 'Item',
- 'ymax_name' => 'testFormItem',
- 'dbCheck' => true,
- 'formCheck' => true
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'name' => 'graphNormal3',
- 'addItems' => [
- ['itemName' => 'testFormItem']
- ],
- 'ymin_type' => 'Fixed',
- 'ymax_type' => 'Item',
- 'ymax_name' => 'testFormItem',
- 'dbCheck' => true,
- 'formCheck' => true
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'name' => 'graphNormal4',
- 'graphtype' => 'Normal',
- 'addItems' => [
- ['itemName' => 'testFormItem']
- ]
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'name' => 'graphStacked1',
- 'graphtype' => 'Stacked',
- 'addItems' => [
- ['itemName' => 'testFormItem']
- ]
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'name' => 'graphStacked2',
- 'graphtype' => 'Stacked',
- 'ymin_type' => 'Fixed' ,
- 'addItems' => [
- ['itemName' => 'testFormItem']
- ]
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'name' => 'graphStacked3',
- 'graphtype' => 'Stacked',
- 'ymin_type' => 'Item',
- 'ymin_name' => 'testFormItem',
- 'ymax_type' => 'Fixed',
- 'addItems' => [
- ['itemName' => 'testFormItem']
- ]
- ]
- ],
- [
- [
- 'expected' => TEST_BAD,
- 'name' => 'graphStacked',
- 'graphtype' => 'Stacked',
- 'ymin_type' => 'Item',
- 'ymax_type' => 'Fixed',
- 'addItems' => [
- ['itemName' => 'testFormItem']
- ],
- 'error-msg' => 'Page received incorrect data',
- 'errors' => [
- 'Field "ymin_itemid" is mandatory.'
- ]
- ]
- ],
- [
- [
- 'expected' => TEST_BAD,
- 'name' => 'graphStacked',
- 'width' => '0',
- 'height' => '0',
- 'graphtype' => 'Stacked',
- 'ymin_type' => 'Fixed',
- 'yaxismin' => 'name',
- 'ymax_type' => 'Fixed',
- 'yaxismax' => 'name',
- 'addItems' => [
- ['itemName' => 'testFormItem']
- ],
- 'error-msg' => 'Page received incorrect data',
- 'errors' => [
- 'Incorrect value "0" for "Width" field: must be between 20 and 65535.',
- 'Incorrect value "0" for "Height" field: must be between 20 and 65535.',
- 'Field "yaxismin" is not correct: a number is expected',
- 'Field "yaxismax" is not correct: a number is expected'
- ]
- ]
- ],
- [
- [
- 'expected' => TEST_BAD,
- 'name' => 'graphStacked',
- 'width' => '65536',
- 'height' => '-22',
- 'graphtype' => 'Stacked',
- 'ymin_type' => 'Fixed',
- 'ymax_type' => 'Fixed',
- 'addItems' => [
- ['itemName' => 'testFormItem']
- ],
- 'error-msg' => 'Page received incorrect data',
- 'errors' => [
- 'Incorrect value "65536" for "Width" field: must be between 20 and 65535.',
- 'Incorrect value "-22" for "Height" field: must be between 20 and 65535.'
- ]
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'name' => 'graphPie',
- 'graphtype' => 'Pie',
- 'addItems' => [
- ['itemName' => 'testFormItem']
- ]
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'name' => 'graphExploded',
- 'graphtype' => 'Exploded',
- 'addItems' => [
- ['itemName' => 'testFormItem']
- ]
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'name' => 'graph!@#$%^&*()><>?:"|{},./;',
- 'graphtype' => 'Exploded',
- 'addItems' => [
- ['itemName' => 'testFormItem']
- ],
- 'dbCheck' => true,
- 'formCheck' => true
- ]
- ]
- ];
- }
-
- /**
- * @dataProvider create
- */
- public function testFormGraph_SimpleCreate($data) {
- $this->zbxTestLogin('graphs.php?hostid=40001&context=host&form=Create+graph');
- $this->zbxTestCheckTitle('Configuration of graphs');
-
- if (isset($data['name'])) {
- $this->zbxTestInputTypeOverwrite('name', $data['name']);
- $this->zbxTestAssertElementValue('name', $data['name']);
- }
- $name = $this->zbxTestGetValue("//input[@id='name']");
-
- if (isset($data['graphtype'])) {
- $this->zbxTestDropdownSelectWait('graphtype', $data['graphtype']);
- }
- $graphtype = $this->zbxTestGetSelectedLabel('graphtype');
-
- if (isset($data['addItems'])) {
- foreach($data['addItems'] as $item) {
- $this->zbxTestClick('add_item');
- $this->zbxTestLaunchOverlayDialog('Items');
- $link = $item['itemName'];
- $overlay = COverlayDialogElement::find()->one()->waitUntilReady();
- $host = $overlay->query('class:multiselect-control')->asMultiselect()->one();
- $host->fill([
- 'values' => $this->host,
- 'context' => $this->hostGroup
- ]);
- $this->zbxTestClickLinkTextWait($link);
-
- $this->zbxTestWaitUntilElementVisible(WebDriverBy::id('items_0_name'));
- $this->zbxTestTextPresent($this->host . ': ' . $link);
-
- if(isset($item['remove'])) {
- $this->zbxTestClickWait('items_0_remove');
- $this->zbxTestTextNotPresent($link);
- }
- }
- }
-
- if (isset($data['width'])) {
- $this->zbxTestInputTypeOverwrite('width', $data['width']);
- }
- $width = $this->zbxTestGetValue("//input[@id='width']");
-
- if (isset($data['height'])) {
- $this->zbxTestInputTypeOverwrite('height', $data['height']);
- }
- $height = $this->zbxTestGetValue("//input[@id='height']");
-
- if (isset($data['ymin_type'])) {
- $this->zbxTestDropdownSelectWait('ymin_type', $data['ymin_type']);
- }
-
- if (isset($data['ymax_type'])) {
- $this->zbxTestDropdownSelectWait('ymax_type', $data['ymax_type']);
- }
-
- if ($graphtype == 'Normal' || $graphtype == 'Stacked') {
- $ymin_type = $this->zbxTestGetSelectedLabel('ymin_type');
- $ymax_type = $this->zbxTestGetSelectedLabel('ymax_type');
- }
- else {
- $ymin_type = null;
- $ymax_type = null;
- }
-
- if (isset($data['yaxismin'])) {
- $this->zbxTestInputType('yaxismin' ,$data['yaxismin']);
- $yaxismin = $this->zbxTestGetValue("//input[@id='yaxismin']");
- }
- elseif ($ymin_type == 'Fixed') {
- $yaxismin = $this->zbxTestGetValue("//input[@id='yaxismin']");
- }
- else {
- $yaxismin = null;
- }
-
- if (isset($data['yaxismax'])) {
- $this->zbxTestInputType('yaxismax' ,$data['yaxismax']);
- $yaxismin = $this->zbxTestGetValue("//input[@id='yaxismax']");
- }
- elseif ($ymax_type == 'Fixed') {
- $yaxismax = $this->zbxTestGetValue("//input[@id='yaxismax']");
- }
- else {
- $yaxismax = null;
- }
-
- if (isset($data['ymin_name'])) {
- $this->zbxTestClickXpath('//div[@id="ymin_itemid"]//following-sibling::div/button');
- $this->zbxTestLaunchOverlayDialog('Items');
- $host = COverlayDialogElement::find()->one()->query('class:multiselect-control')->asMultiselect()->one();
- $host->fill([
- 'values' => $this->host,
- 'context' => $this->hostGroup
- ]);
- $this->zbxTestClickLinkTextWait($this->itemSimple);
-
- $ymin_name = $data['ymin_name'];
- $ymin_nameValue = $this->zbxTestGetText('//div[@id="ymin_itemid"]');
- $this->assertEquals($ymin_nameValue, $this->host.": $ymin_name");
- }
-
- if (isset($data['ymax_name'])) {
- $this->zbxTestClickXpath('//div[@id="ymax_itemid"]//following-sibling::div/button');
- $this->zbxTestLaunchOverlayDialog('Items');
- $host = COverlayDialogElement::find()->one()->query('class:multiselect-control')->asMultiselect()->one();
- $host->fill([
- 'values' => $this->host,
- 'context' => $this->hostGroup
- ]);
- $this->zbxTestClickLinkTextWait($this->itemSimple);
-
- $ymax_name = $data['ymax_name'];
- $ymax_nameValue = $this->zbxTestGetText('//div[@id="ymax_itemid"]');
- $this->assertEquals($this->host.": $ymax_name", $ymax_nameValue);
- }
-
- $this->zbxTestClickWait('add');
- $expected = $data['expected'];
- switch ($expected) {
- case TEST_GOOD:
- $this->zbxTestTextNotPresent(['Page received incorrect data', 'Cannot add graph']);
- $this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Graph added');
- $this->zbxTestCheckTitle('Configuration of graphs');
- $this->zbxTestCheckHeader('Graphs');
- break;
- case TEST_BAD:
- $this->zbxTestCheckTitle('Configuration of graphs');
- $this->zbxTestWaitUntilMessageTextPresent('msg-bad', $data['error-msg']);
- $this->zbxTestCheckHeader('Graphs');
- foreach ($data['errors'] as $msg) {
- $this->zbxTestTextPresent($msg);
- }
- $this->zbxTestTextPresent(['Name', 'Width', 'Height']);
- break;
- }
-
- if (isset($data['dbCheck'])) {
- $result = DBselect("SELECT name, width, height FROM graphs where name like '".$name."'");
- while ($row = DBfetch($result)) {
- $this->assertEquals($row['name'], $name);
- $this->assertEquals($row['width'], $width);
- $this->assertEquals($row['height'], $height);
- }
- }
-
- if (isset($data['formCheck'])) {
- $filter = $this->query('name:zbx_filter')->asForm()->one();
- $filter->getField('Hosts')->fill([
- 'values' => $this->host,
- 'context' => $this->hostGroup
- ]);
- $filter->submit();
-
- $this->zbxTestClickLinkTextWait($name);
- $this->zbxTestAssertElementValue('name', $name);
- $this->zbxTestDropdownAssertSelected('graphtype', $graphtype);
- $this->zbxTestAssertElementValue('width', $width);
- $this->zbxTestAssertElementValue('height', $height);
- }
- }
-
- /**
- * Function for filtering necessary hosts or templates and opening their Graphs.
- *
- * @param string $name name of a host
- * @param CFormELement $form filter form element
- */
- private function filterEntriesAndOpenGraph($name, $form) {
- $form->fill(['Name' => $name]);
- $this->query('button:Apply')->one()->waitUntilClickable()->click();
- $this->query('xpath://table[@class="list-table"]')->asTable()->one()->findRow('Name', $name)
- ->getColumn('Graphs')->query('link:Graphs')->one()->click();
- }
-}
diff --git a/ui/tests/selenium/testFormGraphPrototype.php b/ui/tests/selenium/testFormGraphPrototype.php
deleted file mode 100644
index b130bc09d3d..00000000000
--- a/ui/tests/selenium/testFormGraphPrototype.php
+++ /dev/null
@@ -1,1232 +0,0 @@
-<?php
-/*
-** Zabbix
-** Copyright (C) 2001-2022 Zabbix SIA
-**
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License as published by
-** the Free Software Foundation; either version 2 of the License, or
-** (at your option) any later version.
-**
-** 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 General Public License for more details.
-**
-** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-**/
-
-require_once dirname(__FILE__).'/../include/CLegacyWebTest.php';
-
-/**
- * Test the creation of inheritance of new objects on a previously linked template.
- *
- * @backup graphs
- */
-class testFormGraphPrototype extends CLegacyWebTest {
-
- /**
- * The name of the test template created in the test data set.
- *
- * @var string
- */
- protected $template = 'Inheritance test template';
-
- /**
- * The name of the test host created in the test data set.
- *
- * @var string
- */
- protected $host = 'Simple form test host';
-
- /**
- * The name of the host group that the above host belongs to.
- *
- * @var string
- */
- protected $hostGroup = 'Zabbix servers';
-
- /**
- * The name of the test discovery rule created in the test data set.
- *
- * @var string
- */
- protected $discoveryRule = 'testFormDiscoveryRule';
-
- /**
- * The name of the form test discovery rule created in the test data set.
- *
- * @var string
- */
- protected $discoveryRuleTemplate = 'testInheritanceDiscoveryRule';
-
- /**
- * The name of the test discovery rule key created in the test data set.
- *
- * @var string
- */
- protected $discoveryKey = 'discovery-rule-test';
-
- /**
- * The name of the test item created in the test data set.
- *
- * @var string
- */
- protected $itemSimple = 'testFormItem';
-
- /**
- * The name of the test item created in the test data set.
- *
- * @var string
- */
- protected $itemInheritance = 'itemInheritance';
-
- /**
- * The name of the test item created in the test data set.
- *
- * @var string
- */
- protected $itemDiscovery = 'itemDiscovery';
-
- /**
- * The name of the test item key created in the test data set.
- *
- * @var string
- */
- protected $itemKeySimple = 'test-item-reuse';
-
- /**
- * The name of the test item prototype within test discovery rule created in the test data set.
- *
- * @var string
- */
- protected $item = 'testFormItemReuse';
-
- /**
- * The name of the test item prototype key within test discovery rule created in the test data set.
- *
- * @var string
- */
- protected $testFormItemReuse = 'item-prototype-reuse';
-
- /**
- * The value of the yaxismin field to be created in the test data set.
- *
- * @var int
- */
- protected $yaxismin = 100;
-
- /**
- * The value of the yaxismax field to be created in the test data set.
- *
- * @var int
- */
- protected $yaxismax = 500;
-
- // Returns layout data
- public static function layout() {
- return [
- [
- [
- 'ymin_type' => 'Fixed',
- 'ymax_type' => 'Item',
- 'host' => 'Simple form test host'
- ]
- ],
- [
- [
- 'graphtype' => 'Normal',
- 'host' => 'Simple form test host'
- ]
- ],
- [
- [
- 'graphtype' => 'Normal',
- 'ymin_type' => 'Item',
- 'ymax_type' => 'Fixed',
- 'host' => 'Simple form test host'
- ]
- ],
- [
- [
- 'graphtype' => 'Normal',
- 'ymin_type' => 'Item',
- 'ymax_type' => 'Item',
- 'host' => 'Simple form test host'
- ]
- ],
- [
- [
- 'graphtype' => 'Normal',
- 'ymin_type' => 'Fixed',
- 'ymax_type' => 'Item',
- 'host' => 'Simple form test host'
- ]
- ],
- [
- [
- 'graphtype' => 'Stacked',
- 'host' => 'Simple form test host'
- ]
- ],
- [
- [
- 'graphtype' => 'Stacked',
- 'ymin_type' => 'Fixed' ,
- 'host' => 'Simple form test host'
- ]
- ],
- [
- [
- 'graphtype' => 'Stacked',
- 'ymin_type' => 'Item',
- 'ymax_type' => 'Fixed',
- 'host' => 'Simple form test host'
- ]
- ],
- [
- [
- 'graphtype' => 'Stacked',
- 'ymin_type' => 'Item',
- 'ymax_type' => 'Item',
- 'host' => 'Simple form test host'
- ]
- ],
- [
- [
- 'graphtype' => 'Pie',
- 'host' => 'Simple form test host'
- ]
- ],
- [
- [
- 'graphtype' => 'Exploded',
- 'host' => 'Simple form test host'
- ]
- ],
- [
- [
- 'host' => 'Simple form test host',
- 'form' => 'testFormGraphPrototype1'
- ]
- ],
- [
- [
- 'ymin_type' => 'Fixed',
- 'ymax_type' => 'Item',
- 'template' => 'Inheritance test template'
- ]
- ],
- [
- [
- 'template' => 'Inheritance test template',
- 'form' => 'testInheritanceGraphPrototype1'
- ]
- ],
- [
- [
- 'host' => 'Template inheritance test host',
- 'templatedHost' => 'Inheritance test template',
- 'form' => 'testInheritanceGraphPrototype1'
- ]
- ],
- [
- [
- 'graphtype' => 'Normal',
- 'template' => 'Inheritance test template'
- ]
- ],
- [
- [
- 'graphtype' => 'Normal',
- 'ymin_type' => 'Item',
- 'ymax_type' => 'Fixed',
- 'template' => 'Inheritance test template'
- ]
- ],
- [
- [
- 'graphtype' => 'Normal',
- 'ymin_type' => 'Item',
- 'ymax_type' => 'Item',
- 'template' => 'Inheritance test template'
- ]
- ],
- [
- [
- 'graphtype' => 'Normal',
- 'ymin_type' => 'Fixed',
- 'ymax_type' => 'Item',
- 'template' => 'Inheritance test template'
- ]
- ],
- [
- [
- 'graphtype' => 'Stacked',
- 'template' => 'Inheritance test template'
- ]
- ],
- [
- [
- 'graphtype' => 'Stacked',
- 'ymin_type' => 'Fixed' ,
- 'template' => 'Inheritance test template'
- ]
- ],
- [
- [
- 'graphtype' => 'Stacked',
- 'ymin_type' => 'Item',
- 'ymax_type' => 'Fixed',
- 'template' => 'Inheritance test template'
- ]
- ],
- [
- [
- 'graphtype' => 'Stacked',
- 'ymin_type' => 'Item',
- 'ymax_type' => 'Item',
- 'template' => 'Inheritance test template'
- ]
- ],
- [
- [
- 'graphtype' => 'Pie',
- 'template' => 'Inheritance test template'
- ]
- ],
- [
- [
- 'graphtype' => 'Exploded',
- 'template' => 'Inheritance test template'
- ]
- ]
- ];
- }
-
- /**
- * @dataProvider layout
- */
- public function testFormGraphPrototype_CheckLayout($data) {
- if (isset($data['template'])) {
- $this->zbxTestLogin('templates.php');
- $this->query('button:Reset')->one()->click();
- $form = $this->query('name:zbx_filter')->asForm()->waitUntilReady()->one();
- $this->filterEntriesAndOpenDiscovery($form, $data['template']);
- $discoveryRule = $this->discoveryRuleTemplate;
- $hostid = 30000;
- }
-
- if (isset($data['host'])) {
- $this->zbxTestLogin(self::HOST_LIST_PAGE);
- $form = $this->query('name:zbx_filter')->asForm()->waitUntilReady()->one();
- $this->filterEntriesAndOpenDiscovery($form, $data['host']);
- if (!isset($data['templatedHost'])) {
- $discoveryRule = $this->discoveryRule;
- $hostid = 40001;
- }
- else {
- $discoveryRule = $this->discoveryRuleTemplate;
- $hostid = 30001;
- }
- }
-
- $this->zbxTestClickLinkTextWait($discoveryRule);
- $this->zbxTestClickLinkTextWait('Graph prototypes');
-
- $this->zbxTestCheckTitle('Configuration of graph prototypes');
- $this->zbxTestTextPresent(['Graph prototypes', $discoveryRule]);
-
- if (isset($data['form'])) {
- $this->zbxTestClickLinkTextWait($data['form']);
- }
- else {
- $this->zbxTestContentControlButtonClickTextWait('Create graph prototype');
- }
-
- $this->zbxTestCheckTitle('Configuration of graph prototypes');
- $this->zbxTestCheckHeader('Graph prototypes');
- $this->zbxTestAssertElementPresentXpath("//a[@id='tab_graphTab' and text()='Graph prototype']");
-
- if (isset($data['templatedHost'])) {
- $this->zbxTestTextPresent('Parent graphs');
- if (isset($data['hostTemplate'])) {
- $this->zbxTestAssertElementPresentXpath("//a[text()='".$data['hostTemplate']."']");
- }
- }
- else {
- $this->zbxTestTextNotPresent('Parent graphs');
- }
-
- $this->zbxTestTextPresent('Name');
- $this->zbxTestAssertVisibleId('name');
- $this->zbxTestAssertAttribute("//input[@id='name']", 'maxlength', 255);
- $this->zbxTestAssertAttribute("//input[@id='name']", 'autofocus');
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertAttribute("//input[@id='name']", 'readonly');
- }
- else {
- $this->zbxTestAssertElementNotPresentXpath("//input[@id='name'][readonly]");
- }
-
- $this->zbxTestTextPresent('Width');
- $this->zbxTestAssertVisibleId('width');
- $this->zbxTestAssertAttribute("//input[@id='width']", 'maxlength', 5);
- $this->zbxTestAssertElementValue('width', 900);
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertAttribute("//input[@id='width']", 'readonly');
- }
- else {
- $this->zbxTestAssertElementNotPresentXpath("//input[@id='width'][readonly]");
- }
-
- $this->zbxTestTextPresent('Height');
- $this->zbxTestAssertVisibleId('height');
- $this->zbxTestAssertAttribute("//input[@id='height']", 'maxlength', 5);
- $this->zbxTestAssertElementValue('height', 200);
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertAttribute("//input[@id='height']", 'readonly');
- }
- else {
- $this->zbxTestAssertElementNotPresentXpath("//input[@id='height'][readonly]");
- }
-
- $this->zbxTestTextPresent('Graph type');
- $this->zbxTestAssertVisibleId('graphtype');
- $this->zbxTestDropdownHasOptions('graphtype', [
- 'Normal',
- 'Stacked',
- 'Pie',
- 'Exploded'
- ]);
- if (!isset($data['form'])) {
- $this->zbxTestDropdownAssertSelected('graphtype', 'Normal');
- }
-
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertAttribute("//z-select[@id='graphtype']", 'disabled');
- }
- else {
- $this->zbxTestAssertElementNotPresentXpath("//z-select[@id='graphtype'][@disabled]");
- }
-
- if (isset($data['graphtype'])) {
- $this->zbxTestDropdownSelectWait('graphtype', $data['graphtype']);
- }
- $graphtype = $this->zbxTestGetSelectedLabel('graphtype');
-
- if (isset($data['ymin_type'])) {
- $this->zbxTestAssertElementNotPresentId('ymin_name');
- $this->zbxTestAssertElementNotPresentId('yaxis_min');
- $this->zbxTestDropdownSelectWait('ymin_type', $data['ymin_type']);
- }
-
- if (isset($data['ymax_type'])) {
- $this->zbxTestAssertElementNotPresentId('ymax_name');
- $this->zbxTestAssertElementNotPresentId('yaxis_max');
- $this->zbxTestDropdownSelectWait('ymax_type', $data['ymax_type']);
- }
-
- if ($graphtype == 'Normal' || $graphtype == 'Stacked') {
- $ymin_type = $this->zbxTestGetSelectedLabel('ymin_type');
- $ymax_type = $this->zbxTestGetSelectedLabel('ymax_type');
- }
- else {
- $ymin_type = null;
- $ymax_type = null;
- }
-
- $this->zbxTestTextPresent('Show legend');
- $this->zbxTestAssertElementPresentId('show_legend');
- if (!isset($data['form'])) {
- $this->assertTrue($this->zbxTestCheckboxSelected('show_legend'));
- }
-
- if ($graphtype == 'Normal' || $graphtype == 'Stacked') {
- $this->zbxTestTextPresent('Show working time');
- $this->zbxTestAssertElementPresentId('show_work_period');
-
- if (!isset($data['form'])) {
- $this->assertTrue($this->zbxTestCheckboxSelected('show_work_period'));
- }
-
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertAttribute("//*[@id='show_work_period']", 'disabled');
- }
- else {
- $this->zbxTestAssertElementNotPresentXpath("//*[@id='show_work_period'][@disabled]");
- }
- }
- else {
- $this->zbxTestTextNotPresent('Show working time');
- $this->zbxTestAssertElementNotPresentId('show_work_period');
- }
-
- if ($graphtype == 'Normal' || $graphtype == 'Stacked') {
- $this->zbxTestTextPresent('Show triggers');
- $this->zbxTestAssertElementPresentId('show_triggers');
- if (!isset($data['form'])) {
- $this->assertTrue($this->zbxTestCheckboxSelected('show_triggers'));
- }
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertAttribute("//*[@id='show_triggers']", 'disabled');
- }
- else {
- $this->zbxTestAssertElementNotPresentXpath("//*[@id='show_triggers'][@disabled]");
- }
- }
- else {
- $this->zbxTestTextNotPresent('Show triggers');
- $this->zbxTestAssertElementNotPresentId('show_triggers');
- }
-
- if ($graphtype == 'Normal') {
- $this->zbxTestTextPresent('Percentile line (left)');
- $this->zbxTestAssertElementPresentId('visible_percent_left');
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertAttribute("//input[@id='visible_percent_left']", 'disabled');
- $this->zbxTestAssertAttribute("//input[@id='visible_percent_right']", 'disabled');
- }
- $this->zbxTestTextPresent('Percentile line (right)');
- $this->zbxTestAssertElementPresentId('visible_percent_right');
- }
- else {
- $this->zbxTestTextNotPresent('Percentile line (left)');
- $this->zbxTestAssertElementNotPresentId('visible_percent_left');
-
- $this->zbxTestTextNotPresent('Percentile line (right)');
- $this->zbxTestAssertElementNotPresentId('visible_percent_right');
- }
-
- if ($graphtype == 'Pie' || $graphtype == 'Exploded') {
- $this->zbxTestTextPresent('3D view');
- $this->zbxTestAssertElementPresentId('show_3d');
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertAttribute("//input[@id='show_3d']/@disabled", 'disabled');
- }
- else {
- $this->zbxTestAssertElementNotPresentXpath("//input[@id='show_3d'][@disabled]");
- }
- }
- else {
- $this->zbxTestTextNotPresent('3D view');
- $this->zbxTestAssertElementNotPresentId('show_3d');
- }
-
- if ($graphtype == 'Normal' || $graphtype == 'Stacked') {
- $this->zbxTestTextPresent('Y axis MIN value');
- $this->zbxTestAssertElementPresentId('ymin_type');
- $this->zbxTestDropdownHasOptions('ymin_type', [
- 'Calculated',
- 'Fixed',
- 'Item'
- ]);
-
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertAttribute("//z-select[@id='ymin_type']", 'disabled');
- }
- else {
- $this->zbxTestAssertElementNotPresentXpath("//z-select[@id='ymin_type'][@disabled]");
- }
-
- if (!isset($data['form'])) {
- switch ($ymin_type) {
- case 'Calculated':
- case 'Fixed':
- case 'Item':
- $this->zbxTestDropdownAssertSelected('ymin_type', $ymin_type);
- break;
- }
- }
-
- $this->zbxTestTextPresent('Y axis MAX value');
- $this->zbxTestAssertElementPresentId('ymax_type');
- $this->zbxTestDropdownHasOptions('ymax_type', [
- 'Calculated',
- 'Fixed',
- 'Item'
- ]);
-
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertAttribute("//z-select[@id='ymax_type']", 'disabled');
- }
- else {
- $this->zbxTestAssertElementNotPresentXpath("//z-select[@id='ymax_type'][@disabled]");
- }
-
- if (!isset($data['form'])) {
- switch ($ymax_type) {
- case 'Calculated':
- case 'Fixed':
- case 'Item':
- $this->zbxTestDropdownAssertSelected('ymax_type', $ymax_type);
- break;
- }
- }
- }
- else {
- $this->zbxTestTextNotPresent('Y axis MIN value');
- $this->zbxTestAssertElementNotPresentId('ymin_type');
-
- $this->zbxTestTextNotPresent('Y axis MAX value');
- $this->zbxTestAssertElementNotPresentId('ymax_type');
- }
-
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertElementNotPresentId('add_item');
- $this->zbxTestAssertElementNotPresentId('add_protoitem');
- }
- else {
- $this->zbxTestAssertVisibleId('add_item');
- $this->zbxTestAssertElementText("//button[@id='add_item']", 'Add');
- $this->zbxTestAssertVisibleId('add_protoitem');
- $this->zbxTestAssertElementText("//button[@id='add_protoitem']", 'Add prototype');
- }
-
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertElementNotPresentId('add_item');
- }
- else {
- $this->zbxTestAssertElementNotPresentXpath("//button[@id='add_item'][@disabled]");
- }
-
- if (!isset($data['form'])) {
- $this->zbxTestClick('add_item');
- $this->zbxTestLaunchOverlayDialog('Items');
-
- if (isset($data['host'])) {
- $host = COverlayDialogElement::find()->one()->query('class:multiselect-control')->asMultiselect()->one();
- $host->fill($this->host);
- $this->query('link', $this->itemSimple)->waitUntilClickable()->one()->click();
- }
-
- if (isset($data['template'])) {
- $this->zbxTestClickLinkText($this->itemInheritance);
- }
- }
-
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertElementNotPresentId('add_protoitem');
- }
- else {
- $this->zbxTestAssertElementNotPresentXpath("//button[@id='add_protoitem'][@disabled]");
- }
-
- if (!isset($data['form'])) {
- $this->zbxTestClick('add_protoitem');
- $this->zbxTestLaunchOverlayDialog('Item prototypes');
-
- if (isset($data['host'])) {
- $this->zbxTestClickLinkText($this->item);
- }
-
- if (isset($data['template'])) {
- $this->zbxTestClickLinkText($this->itemDiscovery);
- }
- }
-
- switch($ymin_type) {
- case 'Fixed':
- $this->zbxTestAssertVisibleId('yaxismin');
- $this->zbxTestAssertAttribute("//input[@id='yaxismin']", 'maxlength', 255);
- $this->zbxTestAssertElementValue('yaxismin', 0);
-
- $this->zbxTestAssertElementNotPresentId('ymin_itemid');
- break;
- case 'Calculated':
- $this->zbxTestAssertElementNotPresentId('ymin_itemid');
- $this->zbxTestAssertNotVisibleId('yaxismin');
- break;
- case 'Item':
- $this->zbxTestAssertElementPresentId('ymin_itemid');
- $this->zbxTestAssertElementText('//div[@id="ymin_itemid"]//following-sibling::div/button', 'Select');
- $this->zbxTestAssertElementPresentId('yaxis_min_prototype');
- $this->zbxTestAssertElementText("//button[@id='yaxis_min_prototype']", 'Select prototype');
- $this->zbxTestAssertNotVisibleId('yaxismin');
- break;
- default:
- $this->zbxTestTextNotPresent('Add graph items first');
- $this->zbxTestAssertElementNotPresentId('ymin_itemid');
- $this->zbxTestAssertElementNotPresentId('yaxismin');
- break;
- }
-
- switch($ymax_type) {
- case 'Fixed':
- $this->zbxTestAssertVisibleId('yaxismax');
- $this->zbxTestAssertAttribute("//input[@id='yaxismax']", 'maxlength', 255);
- $this->zbxTestAssertElementValue('yaxismax', 100);
-
- $this->zbxTestAssertElementNotPresentId('ymax_itemid');
- break;
- case 'Calculated':
- $this->zbxTestAssertElementNotPresentId('ymax_itemid');
- $this->zbxTestAssertNotVisibleId('yaxismax');
- break;
- case 'Item':
- $this->zbxTestAssertElementPresentId('ymax_itemid');
- $this->zbxTestAssertElementText('//div[@id="ymax_itemid"]//following-sibling::div/button', 'Select');
- $this->zbxTestAssertElementPresentId('yaxis_max_prototype');
- $this->zbxTestAssertElementText("//button[@id='yaxis_max_prototype']", 'Select prototype');
- $this->zbxTestAssertNotVisibleId('yaxismax');
- break;
- default:
- $this->zbxTestTextNotPresent('Add graph items first');
- $this->zbxTestAssertElementNotPresentId('ymax_itemid');
- $this->zbxTestAssertElementNotPresentId('yaxismax');
- break;
- }
-
- switch ($graphtype) {
- case 'Normal':
- $this->zbxTestTextPresent(['Items', 'Name', 'Function', 'Draw style', 'Y axis side', 'Color', 'Action']);
- break;
- case 'Stacked':
- $this->zbxTestTextPresent(['Items', 'Name', 'Function', 'Y axis side', 'Color', 'Action']);
- break;
- case 'Pie':
- case 'Exploded':
- $this->zbxTestTextPresent(['Items', 'Name', 'Type', 'Function', 'Color', 'Action']);
- break;
- }
-
- $this->zbxTestTabSwitch('Preview');
-
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertAttribute("//button[@id='update']", 'disabled');
- }
- else {
- $this->zbxTestAssertElementNotPresentXpath("//button[@id='update'][@disabled]");
- }
-
- $this->zbxTestAssertVisibleId('cancel');
- $this->zbxTestAssertElementText("//button[@id='cancel']", 'Cancel');
-
- if (isset($data['form'])) {
- $this->zbxTestAssertVisibleId('clone');
- $this->zbxTestAssertElementValue('clone', 'Clone');
- $this->zbxTestAssertVisibleId('update');
- $this->zbxTestAssertElementValue('update', 'Update');
- $this->zbxTestAssertVisibleId('delete');
- $this->zbxTestAssertElementValue('delete', 'Delete');
-
- if (isset($data['templatedHost'])) {
- $this->zbxTestAssertAttribute("//button[@id='delete']", 'disabled');
- }
- else {
-
- $this->zbxTestAssertElementNotPresentXpath("//button[@id='delete'][@disabled]");
- }
- }
- else {
- $this->zbxTestAssertVisibleId('add');
- $this->zbxTestAssertElementValue('add', 'Add');
- $this->zbxTestAssertElementNotPresentId('update');
- $this->zbxTestAssertElementNotPresentId('delete');
- $this->zbxTestAssertElementNotPresentId('clone');
- }
- }
-
- // Returns update data
- public static function update() {
- return CDBHelper::getDataProvider("select * from graphs where name LIKE 'testFormGraphPrototype%'");
- }
-
- /**
- * @dataProvider update
- */
- public function testFormGraphPrototype_SimpleUpdate($data) {
- $sqlGraphs = "select * from graphs ORDER BY graphid";
- $oldHashGraphs = CDBHelper::getHash($sqlGraphs);
-
- $this->zbxTestLogin('graphs.php?form=update&graphid='.$data['graphid'].'&parent_discoveryid=133800&hostid=40001&context=host');
- $this->zbxTestClickWait('update');
- $this->zbxTestCheckTitle('Configuration of graph prototypes');
- $this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Graph prototype updated');
- $this->zbxTestTextPresent([
- $this->discoveryRule,
- 'Graph prototype updated',
- $data['name']
- ]);
-
- $this->assertEquals($oldHashGraphs, CDBHelper::getHash($sqlGraphs));
- }
-
- // Returns create data
- public static function create() {
- return [
- [
- [
- 'expected' => TEST_GOOD,
- 'graphName' => 'graphSimple',
- 'hostCheck' => true,
- 'dbCheck' => true
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'graphName' => 'graphName',
- 'hostCheck' => true
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'graphName' => 'graphRemove',
- 'formCheck' => true,
- 'dbCheck' => true,
- 'remove' => true
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'graphName' => 'graphNotRemove',
- 'formCheck' => true,
- 'dbCheck' => true,
- 'remove' => true
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'graphName' => 'graphNormal1',
- 'graphtype' => 'Normal',
- 'formCheck' => true,
- 'dbCheck' => true,
- 'remove' => true
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'graphName' => 'graphNormal2',
- 'graphtype' => 'Normal',
- 'ymin_type' => 'Fixed',
- 'ymax_type' => 'Calculated',
- 'formCheck' => true,
- 'dbCheck' => true,
- 'remove' => true
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'graphName' => 'graphNormal3',
- 'ymin_type' => 'Item',
- 'ymax_type' => 'Fixed',
- 'formCheck' => true,
- 'dbCheck' => true,
- 'remove' => true
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'graphName' => 'graphNormal4',
- 'ymin_type' => 'Fixed',
- 'ymax_type' => 'Item',
- 'formCheck' => true,
- 'dbCheck' => true,
- 'remove' => true
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'graphName' => 'graphNormal5',
- 'ymin_type' => 'Item',
- 'ymax_type' => 'Item',
- 'formCheck' => true,
- 'dbCheck' => true,
- 'remove' => true
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'graphName' => 'graphStacked1',
- 'graphtype' => 'Stacked',
- 'ymin_type' => 'Item',
- 'ymax_type' => 'Fixed',
- 'formCheck' => true,
- 'dbCheck' => true,
- 'remove' => true
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'graphName' => 'graphStacked2',
- 'graphtype' => 'Stacked',
- 'ymin_type' => 'Fixed',
- 'ymax_type' => 'Fixed',
- 'formCheck' => true,
- 'dbCheck' => true,
- 'remove' => true
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'graphName' => 'graphStacked3',
- 'graphtype' => 'Stacked',
- 'ymax_type' => 'Fixed',
- 'formCheck' => true,
- 'dbCheck' => true,
- 'remove' => true
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'graphName' => 'graphStacked4',
- 'graphtype' => 'Stacked',
- 'ymax_type' => 'Item',
- 'formCheck' => true,
- 'dbCheck' => true,
- 'remove' => true
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'graphName' => 'graphStacked5',
- 'graphtype' => 'Stacked',
- 'formCheck' => true,
- 'dbCheck' => true,
- 'remove' => true
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'graphName' => 'graphPie',
- 'graphtype' => 'Pie',
- 'formCheck' => true,
- 'dbCheck' => true,
- 'remove' => true
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'graphName' => 'graphExploded',
- 'graphtype' => 'Exploded',
- 'formCheck' => true,
- 'dbCheck' => true,
- 'remove' => true
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'graphName' => 'graphSomeRemove',
- 'formCheck' => true,
- 'dbCheck' => true,
- 'remove' => true
- ]
- ],
- [
- [
- 'expected' => TEST_BAD,
- 'graphName' => 'graphSimple',
- 'error-msg' => 'Cannot add graph prototype',
- 'errors' => [
- 'Graph with name "graphSimple" already exists in graphs or graph prototypes'
- ]
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'graphName' => 'graph!@#$%^&*()><>?:"|{},./;',
- 'graphtype' => 'Exploded',
- 'formCheck' => true,
- 'dbCheck' => true
- ]
- ],
- [
- [
- 'expected' => TEST_BAD,
- 'graphName' => 'graphSaveCheck',
- 'noItem' => true,
- 'error-msg' => 'Cannot add graph prototype',
- 'errors' => [
- 'Missing items for graph prototype "graphSaveCheck".'
- ]
- ]
- ],
- [
- [
- 'expected' => TEST_BAD,
- 'error-msg' => 'Page received incorrect data',
- 'errors' => [
- 'Incorrect value for field "Name": cannot be empty.'
- ]
- ]
- ],
- [
- [
- 'expected' => TEST_GOOD,
- 'graphName' => 'graphRemoveAddItem',
- 'removeItem' => true,
- 'dbCheck' => true,
- 'formCheck' => true
- ]
- ],
- [
- [
- 'expected' => TEST_BAD,
- 'graphName' => 'graphStackedNoMinAxisItem',
- 'graphtype' => 'Stacked',
- 'noAxisItem' => true,
- 'ymin_type' => 'Item',
- 'ymax_type' => 'Fixed',
- 'error-msg' => 'Page received incorrect data',
- 'errors' => [
- 'Field "ymin_itemid" is mandatory.'
- ]
- ]
- ],
- [
- [
- 'expected' => TEST_BAD,
- 'graphName' => 'graphStackedNoMaxAxisItem',
- 'graphtype' => 'Stacked',
- 'noAxisItem' => true,
- 'ymin_type' => 'Fixed',
- 'ymax_type' => 'Item',
- 'error-msg' => 'Page received incorrect data',
- 'errors' => [
- 'Field "ymax_itemid" is mandatory.'
- ]
- ]
- ],
- [
- [
- 'expected' => TEST_BAD,
- 'graphName' => 'graphStackedMore',
- 'width' => '0',
- 'height' => '0',
- 'graphtype' => 'Stacked',
- 'ymin_type' => 'Fixed',
- 'yaxismin' => 'name',
- 'ymax_type' => 'Fixed',
- 'yaxismax' => 'name',
- 'error-msg' => 'Page received incorrect data',
- 'errors' => [
- 'Incorrect value "0" for "Width" field: must be between 20 and 65535.',
- 'Incorrect value "0" for "Height" field: must be between 20 and 65535.',
- 'Field "yaxismin" is not correct: a number is expected',
- 'Field "yaxismax" is not correct: a number is expected'
- ]
- ]
- ],
- [
- [
- 'expected' => TEST_BAD,
- 'graphName' => 'graphStackedError',
- 'width' => '65536',
- 'height' => '-22',
- 'graphtype' => 'Stacked',
- 'ymin_type' => 'Fixed',
- 'ymax_type' => 'Fixed',
- 'error-msg' => 'Page received incorrect data',
- 'errors' => [
- 'Incorrect value "65536" for "Width" field: must be between 20 and 65535.',
- 'Incorrect value "-22" for "Height" field: must be between 20 and 65535.'
- ]
- ]
- ]
- ];
- }
-
- /**
- * @dataProvider create
- */
- public function testFormGraphPrototype_SimpleCreate($data) {
- $this->zbxTestLogin('graphs.php?parent_discoveryid=133800&context=host&form=Create+graph+prototype');
-
- $this->zbxTestCheckTitle('Configuration of graph prototypes');
- $this->zbxTestCheckHeader('Graph prototypes');
- $this->zbxTestAssertElementPresentXpath("//a[@id='tab_graphTab' and text()='Graph prototype']");
-
- if (isset($data['graphtype'])) {
- $this->zbxTestDropdownSelectWait('graphtype', $data['graphtype']);
- }
- $graphtype = $this->zbxTestGetSelectedLabel('graphtype');
-
- if (isset($data['ymin_type'])) {
- $this->zbxTestDropdownSelectWait('ymin_type', $data['ymin_type']);
- }
-
- if (isset($data['ymax_type'])) {
- $this->zbxTestDropdownSelectWait('ymax_type', $data['ymax_type']);
- }
-
- if (!isset($data['noItem'])) {
- $this->zbxTestClick('add_protoitem');
- $this->zbxTestLaunchOverlayDialog('Item prototypes');
-
- $this->zbxTestClickLinkText($this->item);
-
- $this->zbxTestClick('add_item');
- $this->zbxTestLaunchOverlayDialog('Items');
-
- $host = COverlayDialogElement::find()->one()->waitUntilReady()->query('class:multiselect-control')->asMultiselect()->one();
- $host->fill([
- 'values' => $this->host,
- 'context' => $this->hostGroup
- ]);
- $this->query('link', $this->itemSimple)->waitUntilClickable()->one()->click();
-
- if (isset($data['removeItem'])) {
- $this->zbxTestClickWait('items_0_remove');
- $this->zbxTestTextNotPresent($this->item);
-
- $this->zbxTestClickWait('items_0_remove');
- $this->zbxTestTextNotPresent($this->itemSimple);
-
- $this->zbxTestClick('add_item');
- $this->zbxTestLaunchOverlayDialog('Items');
- $host = COverlayDialogElement::find()->one()->query('class:multiselect-control')->asMultiselect()->one();
- $host->fill([
- 'values' => $this->host,
- 'context' => $this->hostGroup
- ]);
- $this->query('link', $this->itemSimple)->waitUntilClickable()->one()->click();
-
- $this->zbxTestClick('add_protoitem');
- $this->zbxTestLaunchOverlayDialog('Item prototypes');
- $this->zbxTestClickLinkText($this->item);
- }
- }
- if (isset($data['width'])) {
- $this->zbxTestInputTypeOverwrite('width', $data['width']);
- }
-
- if (isset($data['height'])) {
- $this->zbxTestInputTypeOverwrite('height', $data['height']);
- }
-
- if (isset($data['graphName'])) {
- $graphName = $data['graphName'];
- $this->zbxTestInputType('name', $graphName);
- }
- else {
- $graphName = null;
- }
-
- if ($graphtype == 'Normal' || $graphtype == 'Stacked') {
-
- $ymin_type = $this->zbxTestGetSelectedLabel('ymin_type');
- $ymax_type = $this->zbxTestGetSelectedLabel('ymax_type');
-
- switch($ymin_type) {
- case 'Fixed':
- $this->zbxTestInputType('yaxismin', isset($data['yaxismin']) ? $data['yaxismin'] : $this->yaxismin);
- break;
- case 'Item':
- if (!isset($data['noAxisItem'])) {
- $this->zbxTestClick('yaxis_min_prototype');
- $this->zbxTestLaunchOverlayDialog('Item prototypes');
- $this->zbxTestClickLinkText($this->item);
- }
- break;
- case 'Calculated':
- break;
- }
-
- switch($ymax_type) {
- case 'Fixed':
- $this->zbxTestInputType('yaxismax', isset($data['yaxismax']) ? $data['yaxismax'] : $this->yaxismax);
- break;
- case 'Item':
- if (!isset($data['noAxisItem'])) {
- $this->zbxTestClick('yaxis_max_prototype');
- $this->zbxTestLaunchOverlayDialog('Item prototypes');
- $this->zbxTestClickLinkText($this->item);
- }
- break;
- case 'Calculated':
- break;
- }
- }
-
- $this->zbxTestClickWait('add');
-
- switch ($data['expected']) {
- case TEST_GOOD:
- $this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Graph prototype added');
- $this->zbxTestCheckTitle('Configuration of graph prototypes');
- $this->zbxTestTextPresent(['Graph prototypes', $this->discoveryRule]);
- break;
-
- case TEST_BAD:
- $this->zbxTestCheckTitle('Configuration of graph prototypes');
- $this->zbxTestWaitUntilMessageTextPresent('msg-bad', $data['error-msg']);
- $this->zbxTestCheckHeader('Graph prototypes');
- foreach ($data['errors'] as $msg) {
- $this->zbxTestTextPresent($msg);
- }
- break;
- }
-
- if (isset($data['formCheck'])) {
- $this->zbxTestOpen(self::HOST_LIST_PAGE);
- $form = $this->query('name:zbx_filter')->asForm()->waitUntilReady()->one();
- $this->filterEntriesAndOpenDiscovery($form, $this->host);
- $this->zbxTestClickLinkTextWait($this->discoveryRule);
- $this->zbxTestClickLinkTextWait('Graph prototypes');
-
- $this->zbxTestClickLinkTextWait($graphName);
-
- $this->zbxTestAssertElementValue('name', $graphName);
- $this->zbxTestAssertElementPresentXpath("//span[text()='".$this->host.": ".$this->itemSimple."']");
- $this->zbxTestAssertElementPresentXpath("//span[text()='".$this->host.": ".$this->item."']");
- }
-
- if (isset($data['dbCheck'])) {
- $result = DBselect("SELECT name, graphid FROM graphs where name = '".$graphName."' limit 1");
- while ($row = DBfetch($result)) {
- $this->assertEquals($row['name'], $graphName);
- }
- }
-
- if (isset($data['remove'])) {
- $result = DBselect("SELECT graphid FROM graphs where name = '".$graphName."'");
- while ($row = DBfetch($result)) {
- $graphid = $row['graphid'];
- }
-
- $this->zbxTestOpen(self::HOST_LIST_PAGE);
- $form = $this->query('name:zbx_filter')->asForm()->waitUntilReady()->one();
- $this->filterEntriesAndOpenDiscovery($form, $this->host);
- $this->zbxTestClickLinkTextWait($this->discoveryRule);
- $this->zbxTestClickLinkTextWait('Graph prototypes');
-
- $this->zbxTestCheckboxSelect('group_graphid_'.$graphid);
- $this->zbxTestClickButton('graph.massdelete');
-
- $this->zbxTestAcceptAlert();
- $this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Graph prototypes deleted');
- $this->zbxTestTextNotPresent($this->template.": $graphName");
- }
- }
-
- /**
- * Function for filtering necessary hosts or templates and opening their Discovery rules.
- *
- * @param string $name name of a host
- */
- private function filterEntriesAndOpenDiscovery($form, $name) {
- $form->fill(['Name' => $name]);
- $this->query('button:Apply')->one()->waitUntilClickable()->click();
- $this->query('xpath://table[@class="list-table"]')->asTable()->one()->findRow('Name', $name)
- ->getColumn('Discovery')->query('link:Discovery')->one()->click();
- }
-}