'testFormItem' use PreprocessingTrait; public function getItemPreprocessingPrometheusData() { return array_merge($this->getPrometheusData(), [ [ [ 'expected' => TEST_BAD, 'fields' => [ 'Name' => 'Item Prometeus wrong first parameter - LLD macro', 'Key' => 'wrong-first-parameter-macro' ], 'preprocessing' => [ ['type' => 'Prometheus pattern', 'parameter_1' => '{#METRICNAME}==1'] ], 'error' => 'Incorrect value for field "params": invalid Prometheus pattern.' ] ], [ [ 'expected' => TEST_BAD, 'fields' => [ 'Name' => 'Item Prometeus wrong second parameter - LLD macro', 'Key' => 'wrong-second-parameter-macro' ], 'preprocessing' => [ ['type' => 'Prometheus pattern', 'parameter_1' => 'cpu_usage_system', 'parameter_2' => '{#LABELNAME}'] ], 'error' => 'Incorrect value for field "params": invalid Prometheus output.' ] ], [ [ 'expected' => TEST_BAD, 'fields' => [ 'Name' => 'Item Prometheus to JSON wrong first parameter - LLD macro', 'Key' => 'json-wrong-first-parameter-macro' ], 'preprocessing' => [ ['type' => 'Prometheus to JSON', 'parameter_1' => '{#METRICNAME}==1'] ], 'error' => 'Incorrect value for field "params": invalid Prometheus pattern.' ] ] ]); } /** * @dataProvider getItemPreprocessingValidationData * @dataProvider getItemPreprocessingCreateData * @dataProvider getItemPreprocessingPrometheusData * @dataProvider getCustomOnFailValidationData */ public function testFormPreprocessingItem_CreateAllSteps($data) { $this->checkCreate($data); } /** * @dataProvider getItemPreprocessingTrailingSpacesData */ public function testFormPreprocessingItem_TrailingSpaces($data) { $this->checkTrailingSpaces($data); } /** * Test copies templated item from one host to another. */ 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&filter_hostids[0]='.$original_hostid); $table = $this->query('xpath://form[@name="items"]/table')->asTable()->one(); $table->findRow('Key', $item_key)->select(); $this->query('button:Copy')->one()->click(); $mass_update_form = $this->query('name:elements_form')->waitUntilPresent()->asForm()->one(); $mass_update_form->fill([ 'Target type' => 'Hosts', 'Target' => $target_hostname ]); $mass_update_form->submit(); $this->page->waitUntilReady(); $this->assertMessage(TEST_GOOD, 'Item copied'); // Open original item form and get steps text. $this->page->open('items.php?form=update&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&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(); $this->assertNull($step->getAttribute('readonly')); } } /** * 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&hostid='.self::HOSTID.'&itemid='.self::CLONE_ITEMID; $this->checkCloneItem($link, 'Item'); } public function testFormPreprocessingItem_CloneTemplatedItem() { $link = 'items.php?form=update&hostid='.self::INHERITANCE_HOSTID.'&itemid='.self::INHERITED_ITEMID; $this->checkCloneItem($link, 'Item', $templated = true); } /** * @dataProvider getItemCustomOnFailData */ public function testFormPreprocessingItem_CustomOnFail($data) { $this->checkCustomOnFail($data); } /** * @dataProvider getItemInheritancePreprocessing */ public function testFormPreprocessingItem_PreprocessingInheritanceFromTemplate($data) { $this->link = 'items.php?filter_set=1&filter_hostids[0]='.self::INHERITANCE_TEMPLATEID; $host_link = 'items.php?filter_set=1&filter_hostids[0]='.self::INHERITANCE_HOSTID; $this->checkPreprocessingInheritance($data, $host_link); } }