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

testFormMaintenance.php « selenium « tests « php « frontends - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4fe437786d1760c01f093a1602f1dac423e22d34 (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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<?php
/*
** Zabbix
** Copyright (C) 2001-2019 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';

/**
 * Tests for "Configuration -> Maintenance".
 *
 * Forms:
 * - Create maintenance.
 * - Clone maintenance.
 * - Delete maintenance.
 *
 * @backup maintenances
 */
class testFormMaintenance extends CLegacyWebTest {
	public $name = 'Test maintenance';

	/**
	 * Create maintenance with periods and host group.
	 */
	public function testFormMaintenance_Create() {
		$this->zbxTestLogin('maintenance.php?ddreset=1');
		$this->zbxTestCheckTitle('Configuration of maintenance periods');
		$this->zbxTestCheckHeader('Maintenance periods');
		$this->zbxTestContentControlButtonClickTextWait('Create maintenance period');

		// Type maintenance name.
		$this->zbxTestInputTypeWait('mname', $this->name);

		// "Periods" tab.
		$this->zbxTestTabSwitchById('tab_periodsTab', 'Periods');

		// Add "One time only" maintenance period.
		$this->zbxTestClickXpathWait('//button[@class="btn-link" and text()="Add"]');
		$this->zbxTestClickXpathWait('//div[@id="overlay_dialogue"]//button[text()="Add"]');
		$this->zbxTestWaitUntilElementNotVisible(WebDriverBy::xpath('//div[@id="overlay_dialogue"]'));
		$this->zbxTestAssertElementText('//ul[@id="maintenancePeriodFormList"]//tbody/tr/td','One time only');

		// Add "Daily" maintenance period.
		$this->zbxTestClickXpathWait('//button[@class="btn-link" and text()="Add"]');
		COverlayDialogElement::find()->one()->waitUntilReady();
		$this->zbxTestDropdownSelectWait('timeperiod_type', 'Daily');
		$this->zbxTestClickXpathWait('//div[@id="overlay_dialogue"]//button[text()="Add"]');
		$this->page->waitUntilReady();
		$this->zbxTestAssertElementText('//ul[@id="maintenancePeriodFormList"]//tbody/tr[2]/td','Daily');

		// Add "Weekly" maintenance period with "Monday" and "Sunday".
		$this->zbxTestClickXpathWait('//button[@class="btn-link" and text()="Add"]');
		COverlayDialogElement::find()->one()->waitUntilReady();
		$this->zbxTestDropdownSelectWait('timeperiod_type', 'Weekly');
		$this->zbxTestCheckboxSelect('days_1');
		$this->zbxTestCheckboxSelect('days_64');
		$this->zbxTestClickXpathWait('//div[@id="overlay_dialogue"]//button[text()="Add"]');
		$this->page->waitUntilReady();
		// Check weekly period in frontend.
		$this->zbxTestAssertElementText('//ul[@id="maintenancePeriodFormList"]//tbody/tr[3]/td','Weekly');
		$text = $this->zbxTestGetText('//ul[@id="maintenancePeriodFormList"]//tbody/tr[3]/td[2]');
		$this->assertRegexp('/Monday/', $text);
		$this->assertRegexp('/Sunday/', $text);

		// Add "Monthly" maintenance period with "January" and "November".
		$this->zbxTestClickXpathWait('//button[@class="btn-link" and text()="Add"]');
		COverlayDialogElement::find()->one()->waitUntilReady();
		$this->zbxTestDropdownSelectWait('timeperiod_type', 'Monthly');
		$this->zbxTestCheckboxSelect('months_1');
		$this->zbxTestCheckboxSelect('months_1024');
		$this->zbxTestClickXpathWait('//div[@id="overlay_dialogue"]//button[text()="Add"]');
		$this->page->waitUntilReady();
		// Check monthly period in frontend.
		$this->zbxTestAssertElementText('//ul[@id="maintenancePeriodFormList"]//tbody/tr[4]/td','Monthly');
		$text = $this->zbxTestGetText('//ul[@id="maintenancePeriodFormList"]//tbody/tr[4]/td[2]');
		$this->assertRegexp('/January/', $text);
		$this->assertRegexp('/November/', $text);

		// Open "Hosts and groups" tab and add group.
		$this->zbxTestTabSwitchById('tab_hostTab', 'Hosts and groups');
		$this->zbxTestClickButtonMultiselect('groupids_');
		$this->zbxTestLaunchOverlayDialog('Host groups');
		$this->zbxTestClickLinkTextWait('Zabbix servers');

		// Add problem tags.
		$this->zbxTestClickXpath('//label[text()="Or"]');
		$tags = ['Tag1', 'Tag2', 'Tag3'];
		$value = 'Value';
		foreach ($tags as $i => $tag) {
			$this->zbxTestInputTypeWait('tags_'.$i.'_tag', $tag);
			$this->zbxTestClickXpath('//label[@for="tags_'.$i.'_operator_1"]');
			$this->zbxTestInputType('tags_'.$i.'_value', $value );
			$this->zbxTestClick('tags_add');
		}

		// Create maintenance and check the results in frontend.
		$this->zbxTestClickXpath('//button[@id="add"][@type="submit"]');
		$this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Maintenance added');
		$this->zbxTestTextPresent($this->name);

		$this->assertEquals(1, CDBHelper::getCount('SELECT NULL FROM maintenances WHERE name='.zbx_dbstr($this->name)));
		$this->assertEquals(3, CDBHelper::getCount('SELECT NULL FROM maintenance_tag WHERE value='.zbx_dbstr($value)));
	}

	/**
	 * Changes not preserve when close edit form using cancel button.
	 *
	 * @depends testFormMaintenance_Create
	 */
	public function testFromMaintenance_Cancel() {
		$sql_hash = 'SELECT * FROM maintenances ORDER BY maintenanceid';
		$old_hash = CDBHelper::getHash($sql_hash);

		// Open form and change maintenance name.
		$this->zbxTestLogin('maintenance.php?ddreset=1');
		$this->zbxTestClickLinkTextWait($this->name);
		$this->zbxTestInputTypeOverwrite('mname', 'Some random text');

		// Open "Periods" tab and remove 4th defined period.
		$this->zbxTestTabSwitchById('tab_periodsTab', 'Periods');
		$this->zbxTestClickXpathWait('//td[contains(text(), "Monthly")]/..//button[text()="Remove"]');
		$this->zbxTestWaitForPageToLoad();

		// Close the form.
		$this->zbxTestClickWait('cancel');
		$this->zbxTestWaitForPageToLoad();

		// Check the result in DB.
		$this->assertEquals($old_hash, CDBHelper::getHash($sql_hash));

		// Open form to check changes was not saved.
		$this->zbxTestClickLinkTextWait($this->name);

		// "Maintenance" tab, check name.
		$this->zbxTestAssertElementValue('mname', $this->name);

		// "Periods" tab, check that 4th period exist.
		$this->zbxTestTabSwitchById('tab_periodsTab', 'Periods');
		$this->zbxTestAssertElementPresentXpath('//td[contains(text(), "Monthly")]/..//button[text()="Edit"]');
	}

	/**
	 * Test update by changing maintenance period and type.
	 *
	 * @depends testFormMaintenance_Create
	 */
	public function testFormMaintenance_Update() {
		$this->zbxTestLogin('maintenance.php?ddreset=1');
		$this->zbxTestCheckTitle('Configuration of maintenance periods');
		$this->zbxTestCheckHeader('Maintenance periods');
		$this->zbxTestClickLinkTextWait($this->name);

		// Change maintenance type.
		$this->zbxTestClickXpathWait('//label[contains(text(), "No data collection")]');

		// Open "Periods" tab.
		$this->zbxTestTabSwitchById('tab_periodsTab', 'Periods');
		// Remove "One time only".
		$this->zbxTestClickXpath('//td[contains(text(), "One time only")]/..//button[text()="Remove"]');
		$this->zbxTestWaitForPageToLoad();
		// Edit "Weekly".
		$this->zbxTestClickXpathWait('//td[contains(text(), "Weekly")]/..//button[text()="Edit"]');
		$this->zbxTestCheckboxSelect('days_4');
		$this->zbxTestCheckboxSelect('days_16');
		$this->zbxTestClickXpathWait('//div[@id="overlay_dialogue"]//button[text()="Apply"]');
		$this->zbxTestWaitUntilElementNotVisible(WebDriverBy::xpath('//div[@id="overlay_dialogue"]'));
		$this->zbxTestWaitForPageToLoad();
		$text = $this->query('xpath://div[@id="maintenance_periods"]//tbody/tr[2]/td[2]')->waitUntilVisible()->one()->getText();
		$this->assertRegexp('/Monday/', $text);
		$this->assertRegexp('/Wednesday/', $text);
		$this->assertRegexp('/Friday/', $text);
		$this->assertRegexp('/Sunday/', $text);
		// Edit "Monthly".
		$this->zbxTestClickXpath('//td[contains(text(), "Monthly")]/..//button[text()="Edit"]');
		$this->zbxTestCheckboxSelect('months_32');
		$this->zbxTestCheckboxSelect('months_256');
		$this->zbxTestClickXpath('//ul[@id="month_date_type"]//label[contains(text(), "Day of week")]');
		$this->zbxTestCheckboxSelect('monthly_days_4');
		$this->zbxTestClickXpathWait('//div[@id="overlay_dialogue"]//button[text()="Apply"]');
		$this->zbxTestWaitUntilElementNotVisible(WebDriverBy::xpath('//div[@id="overlay_dialogue"]'));
		$this->zbxTestWaitForPageToLoad();
		$text = $this->query('xpath://div[@id="maintenance_periods"]//tbody/tr[3]/td[2]')->waitUntilVisible()->one()->getText();
		$this->assertRegexp('/Wednesday/', $text);
		$this->assertRegexp('/January/', $text);
		$this->assertRegexp('/June/', $text);
		$this->assertRegexp('/September/', $text);
		$this->assertRegexp('/November/', $text);
		$this->zbxTestClick('update');

		// Check the results in frontend.
		$this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Maintenance updated');
		$this->zbxTestAssertElementText('//a[text()="'.$this->name.'"]/../../td[3]', 'No data collection');
		$this->zbxTestTextPresent($this->name);

		// Check the results in DB.
		$this->assertEquals(1, CDBHelper::getCount('SELECT NULL FROM maintenances WHERE name='.zbx_dbstr($this->name)));
	}

	public function testFormMaintenance_UpdateTags() {
		$maintenance = 'Maintenance for update (data collection)';
		$this->zbxTestLogin('maintenance.php?ddreset=1');
		$this->zbxTestCheckTitle('Configuration of maintenance periods');
		$this->zbxTestCheckHeader('Maintenance periods');
		$this->zbxTestClickLinkTextWait($maintenance);

		// Update tags.
		$this->zbxTestTabSwitch('Hosts and groups');
		$this->zbxTestClickXpathWait('//label[text()="And/Or"]');
		$tag = 'Tag';
		$values = ['A1','B1'];
		foreach ($values as $i => $value) {
			$this->zbxTestInputTypeOverwrite('tags_'.$i.'_tag', $tag);
			$this->zbxTestInputTypeOverwrite('tags_'.$i.'_value', $value);
		}
		$this->zbxTestClickXpath('//label[@for="tags_0_operator_1"]');
		$this->zbxTestClickXpath('//label[@for="tags_1_operator_0"]');

		$this->zbxTestClick('update');
		$this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Maintenance updated');

		$this->assertEquals(2, CDBHelper::getCount('SELECT NULL FROM maintenance_tag WHERE tag='.zbx_dbstr($tag)));
		$this->assertEquals(1, CDBHelper::getCount('SELECT NULL FROM maintenance_tag WHERE value=\'A1\' AND operator=0'));
		$this->assertEquals(1, CDBHelper::getCount('SELECT NULL FROM maintenance_tag WHERE value=\'B1\' AND operator=2'));
	}

	/**
	 * Test cloning of maintenance.
	 *
	 * @depends testFormMaintenance_Create
	 */
	public function testFormMaintenance_Clone() {
		$suffix = ' (clone)';

		$this->zbxTestLogin('maintenance.php?ddreset=1');
		$this->zbxTestCheckTitle('Configuration of maintenance periods');
		$this->zbxTestCheckHeader('Maintenance periods');

		// Open existing maintenance form.
		$this->zbxTestClickLinkText($this->name);

		// Clone maintenance, rename the clone and save it.
		$this->zbxTestClickWait('clone');
		$this->zbxTestInputTypeOverwrite('mname', $this->name.$suffix);
		$this->zbxTestClickXpath('//button[@id="add"][@type="submit"]');

		// Check the result in frontend.
		$this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Maintenance added');
		$this->zbxTestTextPresent([$this->name.$suffix, $this->name]);

		$this->assertEquals(1, CDBHelper::getCount('SELECT NULL FROM maintenances WHERE name='.zbx_dbstr($this->name)));
		$this->assertEquals(1, CDBHelper::getCount('SELECT NULL FROM maintenances WHERE name='.zbx_dbstr($this->name.$suffix)));
	}

	/**
	 * Test deleting of maintenance.
	 *
	 * @depends testFormMaintenance_Create
	 */
	public function testFormMaintenance_Delete() {
		$this->zbxTestLogin('maintenance.php?ddreset=1');
		$this->zbxTestCheckTitle('Configuration of maintenance periods');
		$this->zbxTestCheckHeader('Maintenance periods');

		$this->zbxTestClickLinkText($this->name);

		// Delete a maintenance and check the result in frontend.
		$this->zbxTestClickAndAcceptAlert('delete');
		$this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Maintenance deleted');

		$this->assertEquals(0, CDBHelper::getCount('SELECT NULL FROM maintenances WHERE name='.zbx_dbstr($this->name)));
	}
}