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
|
<?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';
/**
* @backup scripts
*/
class testFormAdministrationScripts extends CLegacyWebTest {
// Data provider
public static function providerScripts() {
// data - values for form inputs
// saveResult - if save action should be successful
// dbValues - values which should be in db if saveResult is true
$data = [
[
[
['name' => 'name', 'value' => 'script', 'type' => 'text'],
['name' => 'command', 'value' => 'run', 'type' => 'text']
],
true,
[
'name' => 'script',
'command' => 'run'
]
],
[
[
['name' => 'name', 'value' => 'script1', 'type' => 'text'],
['name' => 'command', 'value' => 'run', 'type' => 'text'],
['name' => 'type', 'value' => 'IPMI', 'type' => 'select']
],
true,
[
'name' => 'script1',
'command' => 'run',
'type' => 1
]
],
[
[
['name' => 'name', 'value' => 'script2', 'type' => 'text'],
['name' => 'command', 'value' => 'run', 'type' => 'text'],
['name' => 'enable_confirmation', 'type' => 'check']
],
false,
[]
],
[
[
['name' => 'name', 'value' => 'script3', 'type' => 'text'],
['name' => 'command', 'value' => '', 'type' => 'text']
],
false,
[]
]
];
return $data;
}
public function testFormAdministrationScripts_testLayout() {
$this->zbxTestLogin('zabbix.php?action=script.edit');
$this->zbxTestCheckTitle('Configuration of scripts');
$this->zbxTestCheckHeader('Scripts');
$this->zbxTestTextPresent(['Name']);
$this->zbxTestAssertElementPresentId('name');
$this->zbxTestTextPresent(['Type']);
$this->zbxTestAssertElementPresentId('type');
$this->zbxTestAssertElementText("//ul[@id='type']//label[@for='type_0']", 'IPMI');
$this->zbxTestAssertElementText("//ul[@id='type']//label[@for='type_1']", 'Script');
$this->zbxTestTextPresent(['Execute on', 'Zabbix agent', 'Zabbix server']);
$this->zbxTestAssertElementPresentId('execute_on_0');
$this->zbxTestAssertElementPresentId('execute_on_1');
$this->zbxTestTextPresent(['Commands']);
$this->zbxTestAssertElementPresentId('command');
$this->zbxTestTextPresent(['Description']);
$this->zbxTestAssertElementPresentId('description');
$this->zbxTestTextPresent(['User group']);
$this->zbxTestAssertElementPresentId('usrgrpid');
$this->zbxTestDropdownHasOptions('usrgrpid', ['All', 'Disabled', 'Enabled debug mode', 'Guests', 'No access to the frontend', 'Zabbix administrators']);
$this->zbxTestTextPresent(['Host group']);
$this->zbxTestAssertElementPresentId('hgstype');
$this->zbxTestDropdownHasOptions('hgstype', ['All', 'Selected']);
$this->zbxTestTextPresent(['Required host permissions']);
$this->zbxTestAssertElementPresentId('host_access');
$this->zbxTestAssertElementText("//ul[@id='host_access']//label[@for='host_access_0']", 'Read');
$this->zbxTestAssertElementText("//ul[@id='host_access']//label[@for='host_access_1']", 'Write');
$this->zbxTestTextPresent(['Enable confirmation']);
$this->zbxTestAssertElementPresentId('enable_confirmation');
$this->assertFalse($this->zbxTestCheckboxSelected('enable_confirmation'));
$this->zbxTestTextPresent(['Confirmation text']);
$this->zbxTestAssertElementPresentId('confirmation');
}
/**
* @dataProvider providerScripts
*/
public function testFormAdministrationScripts_testCreate($data, $resultSave, $dbValues) {
$this->zbxTestLogin('zabbix.php?action=script.edit');
$this->zbxTestCheckTitle('Configuration of scripts');
$this->zbxTestCheckHeader('Scripts');
foreach ($data as $field) {
switch ($field['type']) {
case 'text':
$this->zbxTestInputType($field['name'], $field['value']);
break;
case 'select':
$this->zbxTestClickXpathWait("//ul[@id='".$field['name']."']//label[text()='".$field['value']."']");
break;
case 'check':
$this->zbxTestCheckboxSelect($field['name']);
break;
}
if ($field['name'] == 'name') {
$keyField = $field['value'];
}
}
$sql = 'SELECT '.implode(', ', array_keys($dbValues)).' FROM scripts';
if ($resultSave && isset($keyField)) {
$sql .= ' WHERE name='.zbx_dbstr($keyField);
}
if (!$resultSave) {
$sql = 'SELECT * FROM scripts';
$hash = CDBHelper::getHash($sql);
}
$this->zbxTestClickWait('add');
if ($resultSave) {
$this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Script added');
$dbres = DBfetch(DBselect($sql));
foreach ($dbres as $field => $value) {
$this->assertEquals($value, $dbValues[$field]);
}
}
else {
$this->zbxTestWaitUntilMessageTextPresent('msg-bad', 'Cannot add script');
$this->assertEquals($hash, CDBHelper::getHash($sql));
}
}
}
|