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

testFormPreprocessingItem.php « preprocessing « selenium « tests « ui - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e3ac95f33a1f858087497f5143b4aedbd14ed3bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?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/testFormPreprocessing.php';
require_once dirname(__FILE__).'/../../include/helpers/CDataHelper.php';

/**
 * @backup items
 */
class testFormPreprocessingItem extends testFormPreprocessing {

	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() {
		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' => 'Invalid parameter "/1/preprocessing/1/params/1": 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' => 'label',
							'parameter_3' => '{#LABELNAME}'
						]
					],
					'error' => 'Invalid parameter "/1/preprocessing/1/params/3": invalid Prometheus label.'
				]
			],
			[
				[
					'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' => 'Invalid parameter "/1/preprocessing/1/params/1": invalid Prometheus pattern.'
				]
			]
		]);
	}

	/**
	 * @dataProvider getItemPreprocessingValidationData
	 * @dataProvider getItemPreprocessingCreateData
	 * @dataProvider getItemPreprocessingPrometheusData
	 * @dataProvider getCustomOnFailValidationData
	 */
	public function testFormPreprocessingItem_CreateAllSteps($data) {
		$this->checkCreate($data);
	}

	/**
	 * Check that adding two 'Check for not supported value'
	 * preprocessing steps is impossible.
	 */
	public function testFormItemPreprocessing_RepeatedNotSupported() {
		$this->checkRepeatedNotSupported();
	}
	/**
	 * @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&context=host&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&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::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&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 testFormPreprocessingItem_CustomOnFail($data) {
		$this->checkCustomOnFail($data);
	}

	/**
	 * @dataProvider getItemInheritancePreprocessing
	 */
	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);
	}

	/**
	 * Check Prometheus 3rd parameter editability depending on formula field.
	 */
	public function testFormPreprocessingItem_PrometheusParameters() {
		$this->page->login()->open($this->link);
		$this->query('button:'.$this->button)->waitUntilPresent()->one()->click();

		// Open preprocessing form and add prometheus step.
		$form = $this->query('name:itemForm')->waitUntilPresent()->asForm()->one();
		$form->selectTab('Preprocessing');
		$this->addPreprocessingSteps([['type' => 'Prometheus pattern', 'parameter_1' => 'pattern']]);

		// Check default values.
		$fields = [
			'dropdown' => 'name:preprocessing[0][params][1]',
			'value' => 'id:preprocessing_0_params_2'
		];

		$this->assertEquals('value', $form->getField($fields['dropdown'])->getValue());
		$this->assertEquals('', $form->getField($fields['value'])->getValue());

		// Fill value with text.
		$form->getField($fields['dropdown'])->fill('label');
		$form->getField($fields['value'])->fill('test');

		$values = [
			'value' => false,
			'label' => true,
			'sum' => false,
			'min' => false,
			'max' => false,
			'avg' => false,
			'count' => false
		];

		// Change dropdown values and check label field value and editability.
		foreach ($values as $value => $enabled) {
			$form->getField($fields['dropdown'])->fill($value);
			$this->assertTrue($form->getField($fields['value'])->isEnabled($enabled));

			// Check that entered value did not disappear.
			$this->assertEquals('test', $form->getField($fields['value'])->getValue());
		}
	}
}