diff options
-rw-r--r-- | ui/tests/selenium/SeleniumTests.php | 20 | ||||
-rw-r--r-- | ui/tests/selenium/common/testFormPreprocessing.php | 241 | ||||
-rw-r--r-- | ui/tests/selenium/common/testFormPreprocessingClone.php | 321 | ||||
-rw-r--r-- | ui/tests/selenium/data/data_test.sql | 32 | ||||
-rw-r--r-- | ui/tests/selenium/preprocessing/testFormPreprocessingCloneHost.php | 41 | ||||
-rw-r--r-- | ui/tests/selenium/preprocessing/testFormPreprocessingCloneTemplate.php | 41 | ||||
-rw-r--r-- | ui/tests/selenium/preprocessing/testFormPreprocessingItem.php (renamed from ui/tests/selenium/testFormItemPreprocessing.php) | 93 | ||||
-rw-r--r-- | ui/tests/selenium/preprocessing/testFormPreprocessingItemPrototype.php (renamed from ui/tests/selenium/testFormItemPrototypePreprocessing.php) | 65 | ||||
-rw-r--r-- | ui/tests/selenium/preprocessing/testFormPreprocessingLowLevelDiscovery.php (renamed from ui/tests/selenium/testFormLowLevelDiscoveryPreprocessing.php) | 137 | ||||
-rw-r--r-- | ui/tests/selenium/preprocessing/testFormPreprocessingTest.php (renamed from ui/tests/selenium/testFormItemPreprocessingTest.php) | 12 |
10 files changed, 888 insertions, 115 deletions
diff --git a/ui/tests/selenium/SeleniumTests.php b/ui/tests/selenium/SeleniumTests.php index 2f3a8ef0e58..90f61fef114 100644 --- a/ui/tests/selenium/SeleniumTests.php +++ b/ui/tests/selenium/SeleniumTests.php @@ -106,23 +106,25 @@ require_once dirname(__FILE__).'/testFormHostLinkTemplates.php'; require_once dirname(__FILE__).'/testFormHostPrototype.php'; require_once dirname(__FILE__).'/testFormItem.php'; require_once dirname(__FILE__).'/testFormItemHttpAgent.php'; -require_once dirname(__FILE__).'/testFormItemPreprocessing.php'; -require_once dirname(__FILE__).'/testFormItemPreprocessingTest.php'; require_once dirname(__FILE__).'/testFormItemPrototype.php'; -require_once dirname(__FILE__).'/testFormItemPrototypePreprocessing.php'; require_once dirname(__FILE__).'/testFormTestItem.php'; require_once dirname(__FILE__).'/testFormTestItemPrototype.php'; require_once dirname(__FILE__).'/testFormTestLowLevelDiscovery.php'; require_once dirname(__FILE__).'/testFormLogin.php'; require_once dirname(__FILE__).'/testFormLowLevelDiscovery.php'; require_once dirname(__FILE__).'/testFormLowLevelDiscoveryOverrides.php'; -require_once dirname(__FILE__).'/testFormLowLevelDiscoveryPreprocessing.php'; require_once dirname(__FILE__).'/testFormMacrosHost.php'; require_once dirname(__FILE__).'/testFormMacrosHostPrototype.php'; require_once dirname(__FILE__).'/testFormMacrosTemplate.php'; require_once dirname(__FILE__).'/testFormMaintenance.php'; require_once dirname(__FILE__).'/testFormMap.php'; require_once dirname(__FILE__).'/testFormNetworkDiscovery.php'; +require_once dirname(__FILE__).'/preprocessing/testFormPreprocessingCloneHost.php'; +require_once dirname(__FILE__).'/preprocessing/testFormPreprocessingCloneTemplate.php'; +require_once dirname(__FILE__).'/preprocessing/testFormPreprocessingItem.php'; +require_once dirname(__FILE__).'/preprocessing/testFormPreprocessingItemPrototype.php'; +require_once dirname(__FILE__).'/preprocessing/testFormPreprocessingLowLevelDiscovery.php'; +require_once dirname(__FILE__).'/preprocessing/testFormPreprocessingTest.php'; require_once dirname(__FILE__).'/testFormSetup.php'; require_once dirname(__FILE__).'/testFormSysmap.php'; require_once dirname(__FILE__).'/testFormTabIndicators.php'; @@ -271,23 +273,25 @@ class SeleniumTests { $suite->addTestSuite('testFormHostPrototype'); $suite->addTestSuite('testFormItem'); $suite->addTestSuite('testFormItemHttpAgent'); - $suite->addTestSuite('testFormItemPreprocessing'); - $suite->addTestSuite('testFormItemPreprocessingTest'); $suite->addTestSuite('testFormItemPrototype'); - $suite->addTestSuite('testFormItemPrototypePreprocessing'); $suite->addTestSuite('testFormTestItem'); $suite->addTestSuite('testFormTestItemPrototype'); $suite->addTestSuite('testFormTestLowLevelDiscovery'); $suite->addTestSuite('testFormLogin'); $suite->addTestSuite('testFormLowLevelDiscovery'); $suite->addTestSuite('testFormLowLevelDiscoveryOverrides'); - $suite->addTestSuite('testFormLowLevelDiscoveryPreprocessing'); $suite->addTestSuite('testFormMacrosHost'); $suite->addTestSuite('testFormMacrosHostPrototype'); $suite->addTestSuite('testFormMacrosTemplate'); $suite->addTestSuite('testFormMaintenance'); $suite->addTestSuite('testFormMap'); $suite->addTestSuite('testFormNetworkDiscovery'); + $suite->addTestSuite('testFormPreprocessingCloneHost'); + $suite->addTestSuite('testFormPreprocessingCloneTemplate'); + $suite->addTestSuite('testFormPreprocessingItem'); + $suite->addTestSuite('testFormPreprocessingItemPrototype'); + $suite->addTestSuite('testFormPreprocessingLowLevelDiscovery'); + $suite->addTestSuite('testFormPreprocessingTest'); $suite->addTestSuite('testFormSetup'); $suite->addTestSuite('testFormSysmap'); $suite->addTestSuite('testFormTabIndicators'); diff --git a/ui/tests/selenium/common/testFormPreprocessing.php b/ui/tests/selenium/common/testFormPreprocessing.php index c2aa1c71adf..f1776a7be90 100644 --- a/ui/tests/selenium/common/testFormPreprocessing.php +++ b/ui/tests/selenium/common/testFormPreprocessing.php @@ -20,9 +20,8 @@ require_once 'vendor/autoload.php'; require_once dirname(__FILE__).'/../../include/CWebTest.php'; -require_once dirname(__FILE__).'/../../../include/items.inc.php'; require_once dirname(__FILE__).'/../traits/PreprocessingTrait.php'; -require_once dirname(__FILE__).'/../../include/helpers/CTestArrayHelper.php'; +require_once dirname(__FILE__).'/../behaviors/CMessageBehavior.php'; /** * Base class for Preprocessing tests. @@ -37,6 +36,150 @@ abstract class testFormPreprocessing extends CWebTest { public $button; public $fail_message; + const CLONE_PREPROCESSING = [ + [ + 'type' => '1', + 'params' => '123', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '2', + 'params' => 'abc', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '3', + 'params' => 'def', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '4', + 'params' => '1a2b3c', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '5', + 'params' => "regular expression pattern \noutput template", + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '6', + 'params' => '', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '7', + 'params' => '', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '8', + 'params' => '', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '9', + 'params' => '', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '11', + 'params' => '/document/item/value/text()', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '12', + 'params' => '$.document.item.value parameter.', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '13', + 'params' => "-5\n3", + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '14', + 'params' => 'regular expression pattern for matching', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '15', + 'params' => 'regular expression pattern for not matching', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '16', + 'params' => '/json/path', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '17', + 'params' => '/xml/path', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '18', + 'params' => "regular expression pattern for error matching \ntest output", + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '20', + 'params' => '7', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '21', + 'params' => 'test script', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '23', + 'params' => 'metric', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '24', + 'params' => ".\n/\n1", + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '25', + 'params' => "1\n2", + 'error_handler' => 0, + 'error_handler_params' => '' + ] + ]; + + /** + * Attach MessageBehavior to the test. + * + * @return array + */ + public function getBehaviors() { + return ['class' => CMessageBehavior::class]; + } + /* * Preprocessing validation data for Item and Item prototype. */ @@ -1751,7 +1894,6 @@ abstract class testFormPreprocessing extends CWebTest { protected function addItemWithPreprocessing($data) { $this->page->login()->open($this->link); $this->query('button:'.$this->button)->waitUntilPresent()->one()->click(); - $form = $this->query('name:itemForm')->waitUntilPresent()->asForm()->one(); $form->fill($data['fields']); $form->selectTab('Preprocessing'); @@ -1770,15 +1912,12 @@ abstract class testFormPreprocessing extends CWebTest { } $form = $this->addItemWithPreprocessing($data); - $form->submit(); $this->page->waitUntilReady(); - $message = CMessageElement::find()->one(); switch ($data['expected']) { case TEST_GOOD: - $this->assertTrue($message->isGood()); - $this->assertEquals($this->success_message, $message->getTitle()); + $this->assertMessage(TEST_GOOD, $this->success_message); // Check result in frontend form. $id = CDBHelper::getValue('SELECT itemid FROM items WHERE key_='.zbx_dbstr($data['fields']['Key'])); @@ -1788,9 +1927,8 @@ abstract class testFormPreprocessing extends CWebTest { break; case TEST_BAD: - $this->assertTrue($message->isBad()); - $this->assertEquals($this->fail_message, $message->getTitle()); - $this->assertTrue($message->hasLine($data['error'])); + $this->assertMessage(TEST_BAD, $this->fail_message, $data['error']); + // Check that DB hash is not changed. $this->assertEquals($old_hash, CDBHelper::getHash($sql_items)); break; @@ -1862,12 +2000,9 @@ abstract class testFormPreprocessing extends CWebTest { */ protected function checkTrailingSpaces($data) { $form = $this->addItemWithPreprocessing($data); - $form->submit(); $this->page->waitUntilReady(); - $message = CMessageElement::find()->one(); - $this->assertTrue($message->isGood()); - $this->assertEquals($this->success_message, $message->getTitle()); + $this->assertMessage(TEST_GOOD, $this->success_message); // Remove spaces. foreach ($data['preprocessing'] as $i => &$options) { @@ -2087,11 +2222,7 @@ abstract class testFormPreprocessing extends CWebTest { $form->submit(); $this->page->waitUntilReady(); - - // Check successful message. - $message = CMessageElement::find()->one(); - $this->assertTrue($message->isGood()); - $this->assertEquals($this->success_message, $message->getTitle()); + $this->assertMessage(TEST_GOOD, $this->success_message); // Check saved preprocessing. $itemid = CDBHelper::getValue('SELECT itemid FROM items WHERE key_='.zbx_dbstr($data['fields']['Key'])); @@ -2394,21 +2525,20 @@ abstract class testFormPreprocessing extends CWebTest { /** * Check inheritance of preprocessing steps in items or LLD rules. + * + * @param array $data data provider + * @param string $host_link URL of host configuration */ protected function checkPreprocessingInheritance($data, $host_link) { // Create item on template. $form = $this->addItemWithPreprocessing($data); $form->submit(); $this->page->waitUntilReady(); - - $message = CMessageElement::find()->one(); - $this->assertTrue($message->isGood()); - $this->assertEquals($this->success_message, $message->getTitle()); + $this->assertMessage(TEST_GOOD, $this->success_message); // Check preprocessing steps on host. $this->page->open($host_link); $this->query('link', $data['fields']['Name'])->waitUntilPresent()->one()->click(); - $form->selectTab('Preprocessing'); $steps = $this->assertPreprocessingSteps($data['preprocessing']); @@ -2449,4 +2579,67 @@ abstract class testFormPreprocessing extends CWebTest { } } } + + /** + * Check cloning of inherited preprocessing steps in items, prototypes or LLD rules. + * + * @param string $link cloned item, prototype or LLD URL + * @param string $item what is being cloned: item, prototype or LLD rule + * @param string $templated is it templated item or not + */ + protected function checkCloneItem($link, $item, $templated = false) { + $cloned_values = [ + 'Name' => 'Cloned_testInheritancePreprocessingSteps'.time(), + 'Key' => 'cloned-preprocessing'.time() + ]; + + // Open original item on host and get its' preprocessing steps. + $this->page->login()->open($link); + $form = $this->query('name:itemForm')->waitUntilPresent()->asForm()->one(); + + if ($templated) { + // Check that right templated item is opened. + $label = ($item === 'Discovery rule') ? 'Parent discovery rules' : 'Parent items'; + $this->assertEquals('Inheritance test template', $form->getField($label)->getText()); + } + + $form->selectTab('Preprocessing'); + $original_steps = $this->listPreprocessingSteps(); + $form->selectTab($item); + + // Clone item. + $form->query('button:Clone')->waitUntilPresent()->one()->click(); + $form->invalidate(); + $form->fill($cloned_values); + + $this->checkPreprocessingSteps($form, $original_steps); + $form->submit(); + $message = ($item === 'Discovery rule') ? $item.' created' : $item.' added'; + $this->assertMessage(TEST_GOOD, $message); + + // Open cloned item and check preprocessing steps in saved form. + $id = CDBHelper::getValue('SELECT itemid FROM items WHERE key_='.zbx_dbstr($cloned_values['Key'])); + $this->page->open($this->ready_link.$id); + $form->invalidate(); + $this->assertEquals($cloned_values['Name'], $form->getField('Name')->getValue()); + $this->checkPreprocessingSteps($form, $original_steps); + } + + /** + * Select Preprocessing tab in cloned item, prototype or LLD form and assert + * that steps are the same as in original item. + * + * @param CFormElement $form item, prototype or LLD configuration form + * @param array $original_steps preprocessing steps of original item + */ + private function checkPreprocessingSteps($form, $original_steps) { + $form->selectTab('Preprocessing'); + $this->assertEquals($original_steps, $this->listPreprocessingSteps()); + + // Check that preprocessing steps in cloned form are editable. + foreach (array_keys($this->listPreprocessingSteps()) as $i) { + $step = $this->query('id:preprocessing_'.$i.'_type')->one(); + $this->assertNull($step->getAttribute('readonly')); + } + } } diff --git a/ui/tests/selenium/common/testFormPreprocessingClone.php b/ui/tests/selenium/common/testFormPreprocessingClone.php new file mode 100644 index 00000000000..86e052b9091 --- /dev/null +++ b/ui/tests/selenium/common/testFormPreprocessingClone.php @@ -0,0 +1,321 @@ +<?php +/* +** Zabbix +** Copyright (C) 2001-2021 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__).'/../../include/helpers/CDataHelper.php'; +require_once dirname(__FILE__).'/../traits/PreprocessingTrait.php'; +require_once dirname(__FILE__).'/../behaviors/CMessageBehavior.php'; + +/** + * Common code for cloning hosts and templates with preprocessing steps in items. + */ +class testFormPreprocessingClone extends CWebTest { + + use PreprocessingTrait; + + public $hostid; + public $itemid; + public $lldid; + public $item_prototypeid; + + const COMMON_PREPROCESSING = [ + [ + 'type' => '5', + 'params' => "regular expression pattern \ntest output", + 'error_handler' => 2, + 'error_handler_params' => 'value1' + ], + [ + 'type' => '11', + 'params' => '/document/item/value/text()', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '12', + 'params' => '$.document.item.value parameter.', + 'error_handler' => 3, + 'error_handler_params' => 'error1' + ], + [ + 'type' => '15', + 'params' => 'regular expression pattern for not matching', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '16', + 'params' => '/json/path', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '17', + 'params' => '/xml/path', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '21', + 'params' => 'test script', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '24', + 'params' => ".\n/\n1", + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '25', + 'params' => "1\n2", + 'error_handler' => 0, + 'error_handler_params' => '' + ] + ]; + + /** + * Get preprocessing steps for item and item prototype. + */ + public function getItemPreprocessing() { + return array_merge(self::COMMON_PREPROCESSING, [ + [ + 'type' => '1', + 'params' => '123', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '2', + 'params' => 'abc', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '3', + 'params' => 'def', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '4', + 'params' => '1a2b3c', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + + [ + 'type' => '6', + 'params' => '', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '7', + 'params' => '', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '8', + 'params' => '', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '9', + 'params' => '', + 'error_handler' => 2, + 'error_handler_params' => 'value2' + ], + [ + 'type' => '13', + 'params' => "-5\n3", + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '14', + 'params' => 'regular expression pattern for matching', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '18', + 'params' => "regular expression pattern for error matching \ntest output", + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '19', + 'params' => '', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '22', + 'params' => "cpu_usage_system\nlabel_name", + 'error_handler' => 3, + 'error_handler_params' => 'error2' + ] + ]); + } + + /** + * Get preprocessing steps for discovery rule. + */ + public function getLLDPreprocessing() { + return array_merge(self::COMMON_PREPROCESSING, [ + [ + 'type' => '20', + 'params' => '7', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '23', + 'params' => 'metric', + 'error_handler' => 2, + 'error_handler_params' => 'error3' + ] + ]); + } + + /** + * Add preprocessing steps to LLD. + */ + public function prepareLLDPreprocessing() { + CDataHelper::setSessionId(null); + + CDataHelper::call('discoveryrule.update', [ + 'itemid' => $this->lldid, + 'preprocessing' => $this->getLLDPreprocessing() + ]); + } + + /** + * Add preprocessing steps to item. + */ + public function prepareItemPreprocessing() { + CDataHelper::setSessionId(null); + + CDataHelper::call('item.update', [ + 'itemid' => $this->itemid, + 'preprocessing' => $this->getItemPreprocessing() + ]); + } + + /** + * Add preprocessing steps to item prototype. + */ + public function prepareItemPrototypePreprocessing() { + CDataHelper::setSessionId(null); + + CDataHelper::call('itemprototype.update', [ + 'itemid' => $this->item_prototypeid, + 'preprocessing' => $this->getItemPreprocessing() + ]); + } + + /** + * Attach MessageBehavior to the test. + * + * @return array + */ + public function getBehaviors() { + return ['class' => CMessageBehavior::class]; + } + + /** + * Function for cloning host or template and check whether preprocessing is cloned correctly. + * + * @param boolean $template true if template, false if host + */ + public function executeCloning($template = false) { + $context = ($template) ? 'template' : 'host'; + $this->page->login(); + + // Get item key and preprocessing. + $item_key = CDBHelper::getValue('SELECT key_ FROM items WHERE itemid ='.$this->itemid); + $item_original_steps = $this->getSteps('items.php?form=update&hostid='.$this->hostid. + '&context='.$context.'&itemid='.$this->itemid); + + // Get LLD key and preprocessing. + $lld_key = CDBHelper::getValue('SELECT key_ FROM items WHERE itemid ='.$this->lldid); + $lld_original_steps = $this->getSteps('host_discovery.php?form=update&context='.$context.'&itemid='.$this->lldid); + + // Get item prototype key and preprocessing. + $item_prototype_key = CDBHelper::getValue('SELECT key_ FROM items WHERE itemid ='.$this->item_prototypeid); + $item_prototype_original_steps = $this->getSteps('disc_prototypes.php?form=update&parent_discoveryid='. + $this->lldid.'&context='.$context.'&itemid='.$this->item_prototypeid); + + // Open host or template and make a full clone of it. + $url = ($template) ? 'templates.php?form=update&templateid=' : 'hosts.php?form=update&hostid='; + $this->page->open($url.$this->hostid); + $this->query('button:Full clone')->waitUntilClickable()->one()->click(); + + // Fill cloned host or template form and save it. + $form = $this->query('name', ($template) ? 'templatesForm' : 'hostsForm')->asForm()->waitUntilPresent()->one(); + $new_host_name = 'Cloned host name'.time(); + $form->fill([($template) ? 'Template name' : 'Host name' => $new_host_name]); + $form->submit(); + $this->page->waitUntilReady(); + $this->assertMessage(TEST_GOOD, ($template) ? 'Template added' : 'Host added'); + + // Check new host in DB. + $this->assertEquals(1, CDBHelper::getCount('SELECT * FROM hosts WHERE host ='.zbx_dbstr($new_host_name))); + $cloned_hostid = CDBHelper::getValue('SELECT hostid FROM hosts WHERE host ='.zbx_dbstr($new_host_name)); + + // Get new cloned item id and assert item preprocessing. + $new_itemid = CDBHelper::getValue('SELECT itemid FROM items WHERE hostid ='.$cloned_hostid.' AND key_ ='. + zbx_dbstr($item_key)); + $item_cloned_steps = $this->getSteps('items.php?form=update&context='.$context.'&hostid='.$cloned_hostid. + '&itemid='.$new_itemid); + $this->assertEquals($item_original_steps, $item_cloned_steps); + + // Get new cloned lld rule id and assert lld preprocessing. + $new_lldid = CDBHelper::getValue('SELECT itemid FROM items WHERE hostid ='.$cloned_hostid. + ' AND key_ ='.zbx_dbstr($lld_key)); + $lld_cloned_steps = $this->getSteps('host_discovery.php?form=update&context='.$context.'&itemid='.$new_lldid); + $this->assertEquals($lld_original_steps, $lld_cloned_steps); + + // Get new cloned item prototype id and assert item prototype preprocessing. + $new_item_prototypeid = CDBHelper::getValue('SELECT itemid FROM items WHERE hostid ='.$cloned_hostid. + ' AND key_ ='.zbx_dbstr($item_prototype_key)); + $item_prototype_cloned_steps = $this->getSteps('disc_prototypes.php?form=update&context='.$context.'&parent_discoveryid='. + $new_lldid.'&itemid='.$new_item_prototypeid); + $this->assertEquals($item_prototype_original_steps, $item_prototype_cloned_steps); + } + + /** + * Function for getting preprocessing steps. + * + * @param string $link URL of item, prototype or LLD + * + * @return array + */ + private function getSteps($link) { + $this->page->open($link); + $this->query('name:itemForm')->asForm()->waitUntilPresent()->one()->selectTab('Preprocessing'); + + return $this->listPreprocessingSteps(); + } +} diff --git a/ui/tests/selenium/data/data_test.sql b/ui/tests/selenium/data/data_test.sql index bd192d5846e..cd14fed604b 100644 --- a/ui/tests/selenium/data/data_test.sql +++ b/ui/tests/selenium/data/data_test.sql @@ -662,7 +662,7 @@ INSERT INTO items (itemid, hostid, type, name, key_, delay, value_type, params, INSERT INTO items (itemid, hostid, type, name, key_, delay, value_type, params, description, posts, headers) VALUES (15079, 15002, 0, 'testInheritance' , 'key-item-inheritance' , '30s', 3, '', '', '', ''); INSERT INTO items (itemid, hostid, type, name, key_, delay, value_type, params, description, interfaceid, templateid, posts, headers) VALUES (15080, 15001, 0, 'testInheritance' , 'key-item-inheritance' , '30s', 3, '', '', 15000, 15079, '', ''); --- testFormItem.Preprocessing +-- testFormItem.Preprocessing Inheritance test template->testInheritanceItemPreprocessing INSERT INTO item_preproc (item_preprocid,itemid,step,type,params) VALUES (125,15093,1,1,'123'); INSERT INTO item_preproc (item_preprocid,itemid,step,type,params) VALUES (126,15093,2,2,'abc'); INSERT INTO item_preproc (item_preprocid,itemid,step,type,params) VALUES (127,15093,3,3,'def'); @@ -684,8 +684,15 @@ INSERT INTO item_preproc (item_preprocid,itemid,step,type,params) VALUES (181,15 INSERT INTO item_preproc (item_preprocid,itemid,step,type,params) VALUES (182,15093,17,18,'regular expression pattern for error matching test output'); INSERT INTO item_preproc (item_preprocid,itemid,step,type,params) VALUES (183,15093,18,20,'7'); - - +INSERT INTO item_preproc (item_preprocid,itemid,step,type,params) VALUES (77000,15093,19,25,'1 +2'); +INSERT INTO item_preproc (item_preprocid,itemid,step,type,params) VALUES (77001,15093,20,24,'. +/ +1'); +INSERT INTO item_preproc (item_preprocid,itemid,step,type,params) VALUES (77002,15093,21,21,'test script'); +INSERT INTO item_preproc (item_preprocid,itemid,step,type,params) VALUES (77003,15093,22,23,'metric'); + +-- Template inheritance test host->testInheritanceItemPreprocessing INSERT INTO item_preproc (item_preprocid,itemid,step,type,params) VALUES (136,15094,1,1,'123'); INSERT INTO item_preproc (item_preprocid,itemid,step,type,params) VALUES (137,15094,2,2,'abc'); INSERT INTO item_preproc (item_preprocid,itemid,step,type,params) VALUES (138,15094,3,3,'def'); @@ -708,6 +715,13 @@ INSERT INTO item_preproc (item_preprocid,itemid,step,type,params) VALUES (175,15 test output'); INSERT INTO item_preproc (item_preprocid,itemid,step,type,params) VALUES (176,15094,18,20,'7'); +INSERT INTO item_preproc (item_preprocid,itemid,step,type,params) VALUES (777000,15094,19,25,'1 +2'); +INSERT INTO item_preproc (item_preprocid,itemid,step,type,params) VALUES (777001,15094,20,24,'. +/ +1'); +INSERT INTO item_preproc (item_preprocid,itemid,step,type,params) VALUES (777002,15094,21,21,'test script'); +INSERT INTO item_preproc (item_preprocid,itemid,step,type,params) VALUES (777003,15094,22,23,'metric'); -- testFormTrigger.SimpleUpdate and testInheritanceTrigger.SimpleUpdate INSERT INTO triggers (triggerid, expression, description, comments) VALUES (99000, '{99729}=0', 'testInheritanceTrigger1', ''); @@ -1045,20 +1059,20 @@ INSERT INTO items (name, key_, hostid, value_type, itemid, flags, delay, params, INSERT INTO items (name, key_, hostid, value_type, itemid, flags, delay, params, description, interfaceid, posts, headers) VALUES ('testFormDiscoveryRule4', 'discovery-rule-form4', 40001, 4, 43703, 1, 50, '', '', 40011, '', ''); -- testFormItemPrototype.SimpleUpdate -INSERT INTO items (name, key_, hostid, value_type, itemid, flags, delay, params, description, posts, headers) VALUES ('testFormDiscoveryRule', 'discovery-rule-form', 40001, 4, 133800, 1, 50, '', '', '', ''); +INSERT INTO items (name, key_, hostid, value_type, itemid, flags, delay, params, description, interfaceid, posts, headers) VALUES ('testFormDiscoveryRule', 'discovery-rule-form', 40001, 4, 133800, 1, 50, '', '', 40011, '', ''); -- testFormItemPrototype.SimpleUpdate -INSERT INTO items (name, key_, hostid, value_type, itemid, flags, delay, params, description, posts, headers) VALUES ('testFormItemPrototype1', 'item-prototype-form1', 40001, 3, 23800, 2, 5, '', '', '', ''); +INSERT INTO items (name, key_, hostid, value_type, itemid, flags, delay, params, description, interfaceid, posts, headers) VALUES ('testFormItemPrototype1', 'item-prototype-form1', 40001, 3, 23800, 2, 5, '', '', 40011, '', ''); INSERT INTO item_discovery (itemdiscoveryid, itemid, parent_itemid) values (501, 23800, 133800); -INSERT INTO items (name, key_, hostid, value_type, itemid, flags, delay, params, description, posts, headers) VALUES ('testFormItemPrototype2', 'item-prototype-form2', 40001, 3, 23801, 2, 5, '', '', '', ''); +INSERT INTO items (name, key_, hostid, value_type, itemid, flags, delay, params, description, interfaceid, posts, headers) VALUES ('testFormItemPrototype2', 'item-prototype-form2', 40001, 3, 23801, 2, 5, '', '', 40011, '', ''); INSERT INTO item_discovery (itemdiscoveryid, itemid, parent_itemid) values (502, 23801, 133800); -INSERT INTO items (name, key_, hostid, value_type, itemid, flags, delay, params, description, posts, headers) VALUES ('testFormItemPrototype3', 'item-prototype-form3', 40001, 3, 23802, 2, 5, '', '', '', ''); +INSERT INTO items (name, key_, hostid, value_type, itemid, flags, delay, params, description, interfaceid, posts, headers) VALUES ('testFormItemPrototype3', 'item-prototype-form3', 40001, 3, 23802, 2, 5, '', '', 40011, '', ''); INSERT INTO item_discovery (itemdiscoveryid, itemid, parent_itemid) values (503, 23802, 133800); -INSERT INTO items (name, key_, hostid, value_type, itemid, flags, delay, params, description, posts, headers) VALUES ('testFormItemPrototype4', 'item-prototype-form4', 40001, 3, 23803, 2, 5, '', '', '', ''); +INSERT INTO items (name, key_, hostid, value_type, itemid, flags, delay, params, description, interfaceid, posts, headers) VALUES ('testFormItemPrototype4', 'item-prototype-form4', 40001, 3, 23803, 2, 5, '', '', 40011, '', ''); INSERT INTO item_discovery (itemdiscoveryid, itemid, parent_itemid) values (504, 23803, 133800); -- testFormTriggerPrototype.SimpleCreate -INSERT INTO items (name, key_, hostid, value_type, itemid, flags, delay, params, description, posts, headers) VALUES ('testFormItemReuse', 'item-prototype-reuse', 40001, 3, 23804, 2, 5, '', '', '', ''); +INSERT INTO items (name, key_, hostid, value_type, itemid, flags, delay, params, description, interfaceid, posts, headers) VALUES ('testFormItemReuse', 'item-prototype-reuse', 40001, 3, 23804, 2, 5, '', '', 40011, '', ''); INSERT INTO item_discovery (itemdiscoveryid, itemid, parent_itemid) values (505, 23804, 133800); -- testFormTriggerPrototype.SimpleUpdate diff --git a/ui/tests/selenium/preprocessing/testFormPreprocessingCloneHost.php b/ui/tests/selenium/preprocessing/testFormPreprocessingCloneHost.php new file mode 100644 index 00000000000..88d466ac39a --- /dev/null +++ b/ui/tests/selenium/preprocessing/testFormPreprocessingCloneHost.php @@ -0,0 +1,41 @@ +<?php +/* +** Zabbix +** Copyright (C) 2001-2021 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/testFormPreprocessingClone.php'; + +/** + * Test of cloning host with preprocessing steps in items. + * + * @backup hosts, items + */ +class testFormPreprocessingCloneHost extends testFormPreprocessingClone { + + public $hostid = 40001; // Simple form test host. + public $itemid = 99102; // StestFormItem. + public $lldid = 133800; // testFormDiscoveryRule. + public $item_prototypeid = 23800; // testFormItemPrototype1. + + /** + * @onBefore prepareLLDPreprocessing, prepareItemPreprocessing, prepareItemPrototypePreprocessing + */ + public function testFormPreprocessingCloneHost_FullCloneHost() { + $this->executeCloning(); + } +} diff --git a/ui/tests/selenium/preprocessing/testFormPreprocessingCloneTemplate.php b/ui/tests/selenium/preprocessing/testFormPreprocessingCloneTemplate.php new file mode 100644 index 00000000000..19791d60a49 --- /dev/null +++ b/ui/tests/selenium/preprocessing/testFormPreprocessingCloneTemplate.php @@ -0,0 +1,41 @@ +<?php +/* +** Zabbix +** Copyright (C) 2001-2021 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/testFormPreprocessingClone.php'; + +/** + * Test of cloning template with preprocessing steps in items. + * + * @backup hosts, items + */ +class testFormPreprocessingCloneTemplate extends testFormPreprocessingClone { + + public $hostid = 15000; // Inheritance test template. + public $itemid = 15000; // itemInheritance. + public $lldid = 15011; // testInheritanceDiscoveryRule. + public $item_prototypeid = 15021; // itemDiscovery. + + /** + * @onBefore prepareLLDPreprocessing, prepareItemPreprocessing, prepareItemPrototypePreprocessing + */ + public function testFormPreprocessingCloneTemplate_FullCloneTemplate() { + $this->executeCloning(true); + } +} diff --git a/ui/tests/selenium/testFormItemPreprocessing.php b/ui/tests/selenium/preprocessing/testFormPreprocessingItem.php index 2dda928fdb1..a39bea8c4a8 100644 --- a/ui/tests/selenium/testFormItemPreprocessing.php +++ b/ui/tests/selenium/preprocessing/testFormPreprocessingItem.php @@ -18,22 +18,26 @@ ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ -require_once dirname(__FILE__).'/common/testFormPreprocessing.php'; +require_once dirname(__FILE__).'/../common/testFormPreprocessing.php'; +require_once dirname(__FILE__).'/../../include/helpers/CDataHelper.php'; /** * @backup items */ -class testFormItemPreprocessing extends testFormPreprocessing { - const HOST_ID = 40001; // 'Simple form test host' - const INHERITANCE_TEMPLATE_ID = 15000; // 'Inheritance test template' - const INHERITANCE_HOST_ID = 15001; // 'Template inheritance test host' +class testFormPreprocessingItem extends testFormPreprocessing { - public $link = 'items.php?filter_set=1&context=host&filter_hostids[0]='.self::HOST_ID; - public $ready_link = 'items.php?form=update&context=host&hostid='.self::HOST_ID.'&itemid='; + public $link = 'items.php?filter_set=1&context=host&filter_hostids[0]='.self::HOSTID; + public $ready_link = 'items.php?form=update&context=host&hostid='.self::HOSTID.'&itemid='; public $button = 'Create item'; public $success_message = 'Item added'; public $fail_message = 'Cannot add item'; + const HOSTID = 40001; // 'Simple form test host' + const INHERITANCE_TEMPLATEID = 15000; // 'Inheritance test template' + const INHERITANCE_HOSTID = 15001; // 'Template inheritance test host' + const INHERITED_ITEMID = 15094; // 'testInheritanceItemPreprocessing' + const CLONE_ITEMID = 99102; // 'Simple form test host' -> 'testFormItem' + use PreprocessingTrait; public function getItemPreprocessingPrometheusData() { @@ -89,7 +93,7 @@ class testFormItemPreprocessing extends testFormPreprocessing { * @dataProvider getItemPreprocessingPrometheusData * @dataProvider getCustomOnFailValidationData */ - public function testFormItemPreprocessing_CreateAllSteps($data) { + public function testFormPreprocessingItem_CreateAllSteps($data) { $this->checkCreate($data); } @@ -103,50 +107,48 @@ class testFormItemPreprocessing extends testFormPreprocessing { /** * @dataProvider getItemPreprocessingTrailingSpacesData */ - public function testFormItemPreprocessing_TrailingSpaces($data) { + public function testFormPreprocessingItem_TrailingSpaces($data) { $this->checkTrailingSpaces($data); } /** * Test copies templated item from one host to another. */ - public function testFormItemPreprocessing_CopyItem() { - $preprocessing_item_key = 'test-inheritance-item-preprocessing'; // testInheritanceItemPreprocessing. - $preprocessing_item_name = 'testInheritanceItemPreprocessing'; - $preprocessing_item_id = 15094; - $original_host_id = 15001; // Template inheritance test host + public function testFormPreprocessingItem_CopyItem() { + $item_key = 'test-inheritance-item-preprocessing'; // testInheritanceItemPreprocessing + $item_name = 'testInheritanceItemPreprocessing'; + $itemid = 15094; // testInheritanceItemPreprocessing + $original_hostid = 15001; // "Template inheritance test host" $target_hostname = 'Simple form test host'; - $this->page->login()->open('items.php?filter_set=1&context=host&filter_hostids[0]='.$original_host_id); + $this->page->login()->open('items.php?filter_set=1&context=host&filter_hostids[0]='.$original_hostid); $table = $this->query('xpath://form[@name="items"]/table')->asTable()->one(); - $table->findRow('Key', $preprocessing_item_key)->select(); + $table->findRow('Key', $item_key)->select(); $this->query('button:Copy')->one()->click(); - $form = $this->query('name:elements_form')->waitUntilPresent()->asForm()->one(); - $form->fill([ + $mass_update_form = $this->query('name:elements_form')->waitUntilPresent()->asForm()->one(); + $mass_update_form->fill([ 'Target type' => 'Hosts', 'Target' => $target_hostname ]); - $form->submit(); - + $mass_update_form->submit(); $this->page->waitUntilReady(); - $message = CMessageElement::find()->one(); - $this->assertTrue($message->isGood()); - $this->assertEquals('Item copied', $message->getTitle()); + $this->assertMessage(TEST_GOOD, 'Item copied'); // Open original item form and get steps text. - $this->page->open('items.php?form=update&context=host&hostid='.$original_host_id.'&itemid='.$preprocessing_item_id); + $this->page->open('items.php?form=update&context=host&hostid='.$original_hostid.'&itemid='.$itemid); $form = $this->query('name:itemForm')->waitUntilPresent()->asForm()->one(); $form->selectTab('Preprocessing'); $original_steps = $this->listPreprocessingSteps(); // Open copied item form, get steps text and compare to original. - $this->page->open('items.php?filter_set=1&context=host&filter_hostids[0]='.self::HOST_ID); - $this->query('link', $preprocessing_item_name)->one()->click(); - $form = $this->query('name:itemForm')->waitUntilPresent()->asForm()->one(); - $this->assertEquals($preprocessing_item_name, $form->getField('Name')->getValue()); - $this->assertEquals($preprocessing_item_key, $form->getField('Key')->getValue()); + $this->page->open('items.php?filter_set=1&context=host&filter_hostids[0]='.self::HOSTID); + $this->query('link', $item_name)->one()->click(); + $form->invalidate(); + $this->assertEquals($item_name, $form->getField('Name')->getValue()); + $this->assertEquals($item_key, $form->getField('Key')->getValue()); $form->selectTab('Preprocessing'); $copied_steps = $this->listPreprocessingSteps(); $this->assertEquals($original_steps, $copied_steps); + // Get steps inputs and check if they are not disabled. foreach (array_keys($copied_steps) as $i) { $step = $this->query('id:preprocessing_'.$i.'_type')->one(); @@ -155,18 +157,43 @@ class testFormItemPreprocessing extends testFormPreprocessing { } /** + * Add preprocessing steps to item for cloning. + */ + public function prepareCloneItemPreprocessing() { + CDataHelper::call('item.update', [ + 'itemid' => self::CLONE_ITEMID, + 'preprocessing' => self::CLONE_PREPROCESSING + ]); + } + + /** + * @onBefore prepareCloneItemPreprocessing + * + * @backup profiles + */ + public function testFormPreprocessingItem_CloneItem() { + $link = 'items.php?form=update&context=host&hostid='.self::HOSTID.'&itemid='.self::CLONE_ITEMID; + $this->checkCloneItem($link, 'Item'); + } + + public function testFormPreprocessingItem_CloneTemplatedItem() { + $link = 'items.php?form=update&context=host&hostid='.self::INHERITANCE_HOSTID.'&itemid='.self::INHERITED_ITEMID; + $this->checkCloneItem($link, 'Item', $templated = true); + } + + /** * @dataProvider getItemCustomOnFailData */ - public function testFormItemPreprocessing_CustomOnFail($data) { + public function testFormPreprocessingItem_CustomOnFail($data) { $this->checkCustomOnFail($data); } /** * @dataProvider getItemInheritancePreprocessing */ - public function testFormItemPreprocessing_PreprocessingInheritanceFromTemplate($data) { - $this->link = 'items.php?filter_set=1&context=host&filter_hostids[0]='.self::INHERITANCE_TEMPLATE_ID; - $host_link = 'items.php?filter_set=1&context=host&filter_hostids[0]='.self::INHERITANCE_HOST_ID; + public function testFormPreprocessingItem_PreprocessingInheritanceFromTemplate($data) { + $this->link = 'items.php?filter_set=1&context=host&filter_hostids[0]='.self::INHERITANCE_TEMPLATEID; + $host_link = 'items.php?filter_set=1&context=host&filter_hostids[0]='.self::INHERITANCE_HOSTID; $this->checkPreprocessingInheritance($data, $host_link); } diff --git a/ui/tests/selenium/testFormItemPrototypePreprocessing.php b/ui/tests/selenium/preprocessing/testFormPreprocessingItemPrototype.php index 0a3847e1459..310e1a4714f 100644 --- a/ui/tests/selenium/testFormItemPrototypePreprocessing.php +++ b/ui/tests/selenium/preprocessing/testFormPreprocessingItemPrototype.php @@ -18,25 +18,29 @@ ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ -require_once dirname(__FILE__).'/common/testFormPreprocessing.php'; +require_once dirname(__FILE__).'/../common/testFormPreprocessing.php'; +require_once dirname(__FILE__).'/../../include/helpers/CDataHelper.php'; /** * Test the creation of inheritance of new objects on a previously linked template. * * @backup items */ -class testFormItemPrototypePreprocessing extends testFormPreprocessing { +class testFormPreprocessingItemPrototype extends testFormPreprocessing { - const DISCOVERY_RULE_ID = 133800; // 'Simple form test host' => 'testFormDiscoveryRule' - const TEMPL_DISCOVERY_RULE_ID = 15011; // 'testInheritanceDiscoveryRule' - const HOST_DISCOVERY_RULE_ID = 15016; // 'Template inheritance test host -> testInheritanceDiscoveryRule' - - public $link = 'disc_prototypes.php?context=host&parent_discoveryid='.self::DISCOVERY_RULE_ID; - public $ready_link = 'disc_prototypes.php?context=host&form=update&parent_discoveryid='.self::DISCOVERY_RULE_ID.'&itemid='; + public $link = 'disc_prototypes.php?context=host&parent_discoveryid='.self::DISCOVERY_RULEID; + public $ready_link = 'disc_prototypes.php?form=update&context=host&parent_discoveryid='.self::DISCOVERY_RULEID.'&itemid='; public $button = 'Create item prototype'; public $success_message = 'Item prototype added'; public $fail_message = 'Cannot add item prototype'; + const DISCOVERY_RULEID = 133800; // 'Simple form test host' => 'testFormDiscoveryRule' + const TEMPL_INHERITANCE_RULEID = 15011; //'testInheritanceDiscoveryRule' + const HOST_INHERITANCE_RULEID = 15016; // 'Template inheritance test host' -> 'testInheritanceDiscoveryRule' + const INHERITED_ITEM_PROTOTYPE = 15096; // 'testInheritanceDiscoveryRule' -> 'testInheritanceItemPrototypePreprocessing' + const CLONE_RULEID = 133800; // 'Host for triggers filtering' -> 'Discovery rule for triggers filtering' + const CLONE_ITEM_PROTOTYPEID = 23804; // 'Discovery rule for triggers filtering' -> 'Discovered item {#TEST}' + public function getItemPrototypePrometheusData() { return array_merge($this->getPrometheusData(), [ [ @@ -96,38 +100,55 @@ class testFormItemPrototypePreprocessing extends testFormPreprocessing { * @dataProvider getItemPrototypePrometheusData * @dataProvider getCustomOnFailValidationData */ - public function testFormItemPrototypePreprocessing_CreateAllSteps($data) { + public function testFormPreprocessingItemPrototype_CreateAllSteps($data) { $this->checkCreate($data); } /** - * Check that adding two 'Check for not supported value' - * preprocessing steps is impossible. + * @dataProvider getItemPreprocessingTrailingSpacesData */ - public function testFormItemPrototypePreprocessing_RepeatedNotSupported() { - $this->checkRepeatedNotSupported(); + public function testFormPreprocessingItemPrototype_TrailingSpaces($data) { + $this->checkTrailingSpaces($data); } /** - * @dataProvider getItemCustomOnFailData + * Add preprocessing steps to item prototype for cloning. */ - public function testFormItemPrototypePreprocessing_CustomOnFail($data) { - $this->checkCustomOnFail($data); + public function prepareCloneItemPrototypePreprocessing() { + CDataHelper::call('itemprototype.update', [ + 'itemid' => self::CLONE_ITEM_PROTOTYPEID, + 'preprocessing' => self::CLONE_PREPROCESSING + ]); } /** - * @dataProvider getItemPreprocessingTrailingSpacesData + * @onBefore prepareCloneItemPrototypePreprocessing */ - public function testFormItemPrototypePreprocessing_TrailingSpaces($data) { - $this->checkTrailingSpaces($data); + public function testFormPreprocessingItemPrototype_CloneItemPrototype() { + $link = 'disc_prototypes.php?form=update&context=host&parent_discoveryid='.self::CLONE_RULEID. + '&itemid='.self::CLONE_ITEM_PROTOTYPEID; + $this->checkCloneItem($link, 'Item prototype'); + } + + public function testFormPreprocessingItemPrototype_CloneTemplatedItemPrototype() { + $link = 'disc_prototypes.php?form=update&context=host&parent_discoveryid='.self::HOST_INHERITANCE_RULEID. + '&itemid='.self::INHERITED_ITEM_PROTOTYPE; + $this->checkCloneItem($link, 'Item prototype', $templated = true); + } + + /** + * @dataProvider getItemCustomOnFailData + */ + public function testFormPreprocessingItemPrototype_CustomOnFail($data) { + $this->checkCustomOnFail($data); } /** * @dataProvider getItemInheritancePreprocessing */ - public function testFormItemPrototypePreprocessing_PreprocessingInheritanceFromTemplate($data) { - $this->link = 'disc_prototypes.php?context=template&parent_discoveryid='.self::TEMPL_DISCOVERY_RULE_ID; - $host_link = 'disc_prototypes.php?context=host&parent_discoveryid='.self::HOST_DISCOVERY_RULE_ID; + public function testFormPreprocessingItemPrototype_PreprocessingInheritanceFromTemplate($data) { + $this->link = 'disc_prototypes.php?context=template&parent_discoveryid='.self::TEMPL_INHERITANCE_RULEID; + $host_link = 'disc_prototypes.php?context=host&parent_discoveryid='.self::HOST_INHERITANCE_RULEID; $this->checkPreprocessingInheritance($data, $host_link); } diff --git a/ui/tests/selenium/testFormLowLevelDiscoveryPreprocessing.php b/ui/tests/selenium/preprocessing/testFormPreprocessingLowLevelDiscovery.php index c66e089c0e3..4307c00b4ac 100644 --- a/ui/tests/selenium/testFormLowLevelDiscoveryPreprocessing.php +++ b/ui/tests/selenium/preprocessing/testFormPreprocessingLowLevelDiscovery.php @@ -18,23 +18,94 @@ ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ -require_once dirname(__FILE__).'/common/testFormPreprocessing.php'; +require_once dirname(__FILE__).'/../common/testFormPreprocessing.php'; +require_once dirname(__FILE__).'/../../include/helpers/CDataHelper.php'; /** * @backup items */ -class testFormLowLevelDiscoveryPreprocessing extends testFormPreprocessing { +class testFormPreprocessingLowLevelDiscovery extends testFormPreprocessing { - const HOST_ID = 40001; - const INHERITANCE_TEMPLATE_ID = 15000; // 'Inheritance test template' - const INHERITANCE_HOST_ID = 15001; // 'Template inheritance test host' - - public $link = 'host_discovery.php?filter_set=1&context=host&filter_hostids%5B0%5D='.self::HOST_ID; + public $link = 'host_discovery.php?context=host&filter_set=1&filter_hostids%5B0%5D='.self::HOSTID; public $ready_link = 'host_discovery.php?form=update&context=host&itemid='; public $button = 'Create discovery rule'; public $success_message = 'Discovery rule created'; public $fail_message = 'Cannot add discovery rule'; + const HOSTID = 40001; + const INHERITANCE_TEMPLATEID = 15000; // 'Inheritance test template' + const INHERITANCE_HOSTID = 15001; // 'Template inheritance test host' + const INHERITANCE_LLDID = 15016; // 'Template inheritance test host' -> 'testInheritanceDiscoveryRule' + const CLONE_LLDID = 133800; // 'Simple form test host' -> 'testFormDiscoveryRule1' + const CLONE_PREPROCESSING = [ + [ + 'type' => '5', + 'params' => "regular expression pattern \noutput template", + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '11', + 'params' => '/document/item/value/text()', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '12', + 'params' => '$.document.item.value parameter.', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '15', + 'params' => 'regular expression pattern for not matching', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '16', + 'params' => '/json/path', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '17', + 'params' => '/xml/path', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '20', + 'params' => '7', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '24', + 'params' => ".\n/\n1", + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '25', + 'params' => "1\n2", + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '21', + 'params' => 'test script', + 'error_handler' => 0, + 'error_handler_params' => '' + ], + [ + 'type' => '23', + 'params' => 'metric', + 'error_handler' => 0, + 'error_handler_params' => '' + ] + ]; + /* * Preprocessing data for LLD successful creation. */ @@ -202,30 +273,70 @@ class testFormLowLevelDiscoveryPreprocessing extends testFormPreprocessing { * @dataProvider getLLDPrometheusData * @dataProvider getCustomOnFailValidationData */ - public function testFormLowLevelDiscoveryPreprocessing_CreateAllSteps($data) { + public function testFormPreprocessingLowLevelDiscovery_CreateAllSteps($data) { $this->checkCreate($data); } /** * @dataProvider getCommonPreprocessingTrailingSpacesData */ - public function testFormLowLevelDiscoveryPreprocessing_TrailingSpaces($data) { + public function testFormPreprocessingLowLevelDiscovery_TrailingSpaces($data) { $this->checkTrailingSpaces($data); } /** + * Add preprocessing steps to templated LLD for cloning. + */ + public function prepareСloneTemplatedLLDPreprocessing() { + CDataHelper::setSessionId(null); + + CDataHelper::call('discoveryrule.update', [ + 'itemid' => '15011', + 'preprocessing' => self::CLONE_PREPROCESSING + ]); + } + + /** + * @onBefore prepareСloneTemplatedLLDPreprocessing + */ + public function testFormPreprocessingLowLevelDiscovery_CloneTemplatedLLD() { + $link = 'host_discovery.php?form=update&context=host&itemid='.self::INHERITANCE_LLDID; + $this->checkCloneItem($link, 'Discovery rule', $templated = true); + } + + /** + * Add preprocessing steps to LLD for cloning. + */ + public function prepareCloneLLDPreprocessing() { + CDataHelper::setSessionId(null); + + CDataHelper::call('discoveryrule.update', [ + 'itemid' => self::CLONE_LLDID, + 'preprocessing' => self::CLONE_PREPROCESSING + ]); + } + + /** + * @onBefore prepareCloneLLDPreprocessing + */ + public function testFormPreprocessingLowLevelDiscovery_CloneLLD() { + $link = 'host_discovery.php?form=update&context=host&itemid='.self::CLONE_LLDID; + $this->checkCloneItem($link, 'Discovery rule'); + } + + /** * @dataProvider getCommonCustomOnFailData */ - public function testFormLowLevelDiscoveryPreprocessing_CustomOnFail($data) { + public function testFormPreprocessingLowLevelDiscovery_CustomOnFail($data) { $this->checkCustomOnFail($data, true); } /** * @dataProvider getCommonInheritancePreprocessing */ - public function testFormLowLevelDiscoveryPreprocessing_PreprocessingInheritanceFromTemplate($data) { - $this->link = 'host_discovery.php?filter_set=1&context=template&filter_hostids%5B0%5D='.self::INHERITANCE_TEMPLATE_ID; - $host_link = 'host_discovery.php?filter_set=1&context=host&filter_hostids%5B0%5D='.self::INHERITANCE_HOST_ID; + public function testFormPreprocessingLowLevelDiscovery_PreprocessingInheritanceFromTemplate($data) { + $this->link = 'host_discovery.php?filter_set=1&&context=template&filter_hostids%5B0%5D='.self::INHERITANCE_TEMPLATEID; + $host_link = 'host_discovery.php?filter_set=1&context=host&filter_hostids%5B0%5D='.self::INHERITANCE_HOSTID; $this->checkPreprocessingInheritance($data, $host_link); } diff --git a/ui/tests/selenium/testFormItemPreprocessingTest.php b/ui/tests/selenium/preprocessing/testFormPreprocessingTest.php index 99ffdce60b1..81593b12937 100644 --- a/ui/tests/selenium/testFormItemPreprocessingTest.php +++ b/ui/tests/selenium/preprocessing/testFormPreprocessingTest.php @@ -18,14 +18,14 @@ ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ -require_once dirname(__FILE__).'/../include/CWebTest.php'; -require_once dirname(__FILE__).'/../../include/items.inc.php'; -require_once dirname(__FILE__).'/traits/PreprocessingTrait.php'; +require_once dirname(__FILE__).'/../../include/CWebTest.php'; +require_once dirname(__FILE__).'/../../../include/items.inc.php'; +require_once dirname(__FILE__).'/../traits/PreprocessingTrait.php'; /** * @backup items */ -class testFormItemPreprocessingTest extends CWebTest { +class testFormPreprocessingTest extends CWebTest { const HOST_ID = 40001; //'Simple form test host' @@ -203,7 +203,7 @@ class testFormItemPreprocessingTest extends CWebTest { /** * @dataProvider getTestSingleStepData */ - public function testFormItemPreprocessingTest_TestSingleStep($data) { + public function testFormPreprocessingTest_TestSingleStep($data) { $this->openPreprocessing($data); foreach ($data['preprocessing'] as $i => $step) { @@ -406,7 +406,7 @@ class testFormItemPreprocessingTest extends CWebTest { /** * @dataProvider getTestAllStepsData */ - public function testFormItemPreprocessingTest_TestAllSteps($data) { + public function testFormPreprocessingTest_TestAllSteps($data) { $this->openPreprocessing($data); foreach ($data['preprocessing'] as $step) { |