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

testFormApplication.php « selenium « tests « php « frontends - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6304440b302847588456ce8345010c277f05162c (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
<?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';

/**
 * Test checks Configuration -> Hosts or Templates -> Applications form.
 *
 * @backup applications
 */
class testFormApplication extends CLegacyWebTest {

	/**
	 * The name of the test application used in the test data set.
	 *
	 * @var string
	 */
	public static $application;

	/**
	 * @beforeClass
	 */
	public static function initializeTest() {
		// Initialize test application name - random name is used.
		self::$application = 'Test application '.microtime(true);
	}

	/**
	 * Update application data.
	 *
	 * @param string $name      current application name
	 * @param string $new_name  new application name (can be null if application should not be renamed)
	 */
	protected function updateApplication($name, $new_name = null) {
		if ($new_name === null) {
			$new_name = $name;
		}

		// Open an application.
		$this->zbxTestLogin('applications.php');
		$this->zbxTestMainFilterDropdownSelectWait('groupid', '4');
		$this->zbxTestMainFilterDropdownSelectWait('hostid', '40001');
		$this->zbxTestClickLinkTextWait($name);

		// Change application name if new name differs from existing name.
		if ($new_name !== $name) {
			$this->zbxTestInputTypeOverwrite('appname', $new_name);
		}

		$this->zbxTestClickWait('update');

		// Check the results of an update.
		$this->zbxTestCheckTitle('Configuration of applications');
		$this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Application updated');
		$this->zbxTestTextPresent($new_name);

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

		if ($new_name !== $name) {
			// There should be no application with previous name if name was changed.
			$this->assertEquals(0, CDBHelper::getCount("SELECT NULL FROM applications WHERE name='".$name."'"));
		}
	}

	/**
	 * Test creation of an application.
	 */
	public function testFormApplication_Create() {
		$name = self::$application;

		// Select hostgroup and host, open a form.
		$this->zbxTestLogin('applications.php');
		$this->zbxTestMainFilterDropdownSelectWait('groupid', '4');
		$this->zbxTestMainFilterDropdownSelectWait('hostid', '40001');
		$this->zbxTestContentControlButtonClickTextWait('Create application');

		// Set application name and submit the form.
		$this->zbxTestInputTypeWait('appname', $name);
		$this->zbxTestClickWait('add');

		// Check the results in frontend.
		$this->zbxTestCheckTitle('Configuration of applications');
		$this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Application added');
		$this->zbxTestTextPresent($name);

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

	/**
	 * Test form validations.
	 */
	public function testFormApplication_CheckValidation() {
		// Select hostgroup and host, open a form.
		$this->zbxTestLogin('applications.php');
		$this->zbxTestMainFilterDropdownSelectWait('groupid', '4');
		$this->zbxTestMainFilterDropdownSelectWait('hostid', '40001');
		$this->zbxTestContentControlButtonClickTextWait('Create application');

		// Check error message on posting the empty form.
		$this->zbxTestClickWait('add');
		$this->zbxTestWaitUntilMessageTextPresent('msg-bad', 'Incorrect value for field "Name": cannot be empty.');

		// Change application name to multiple spaces and check an error message.
		$this->zbxTestInputTypeOverwrite('appname', '      ');
		$this->zbxTestClickWait('add');
		$this->zbxTestWaitUntilMessageTextPresent('msg-bad', 'Incorrect value for field "Name": cannot be empty.');
	}

	/**
	 * Test update without any modification of application data.
	 */
	public function testFormApplication_SimpleUpdate() {
		$sql_hash = 'SELECT * FROM applications ORDER BY applicationid';
		$old_hash = CDBHelper::getHash($sql_hash);

		$this->updateApplication(self::$application);

		$this->assertEquals($old_hash, CDBHelper::getHash($sql_hash));
	}

	/**
	 * Test update by changing application name.
	 */
	public function testFormApplication_Update() {
		$suffix = ' (updated)';

		// Update performing multiple times to assure that consequential updates are not broken.
		for ($i = 0; $i < 3; $i++) {
			$this->updateApplication(self::$application, self::$application.$suffix);

			// Application name is also updated for the other test cases
			self::$application .= $suffix;
		}
	}

	/**
	 * Test form canceling functionality.
	 */
	public function testFormApplication_Cancel() {
		$sql_hash = 'SELECT * FROM applications ORDER BY applicationid';
		$old_hash = CDBHelper::getHash($sql_hash);

		// Select hostgroup and host, open a form.
		$this->zbxTestLogin('applications.php');
		$this->zbxTestMainFilterDropdownSelectWait('groupid', '4');
		$this->zbxTestMainFilterDropdownSelectWait('hostid', '40001');
		$this->zbxTestClickLinkTextWait(self::$application);

		// Change application name.
		$this->zbxTestInputTypeOverwrite('appname', self::$application.' (updated)');

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

		// Check the result in frontend.
		$this->zbxTestCheckTitle('Configuration of applications');

		$this->assertEquals($old_hash, CDBHelper::getHash($sql_hash));
	}

	/**
	 * Test cloning of application.
	 */
	public function testFormApplication_Clone() {
		$suffix = ' (clone)';
		$name = self::$application;

		// Select hostgroup and host, open a form.
		$this->zbxTestLogin('applications.php');
		$this->zbxTestMainFilterDropdownSelectWait('groupid', '4');
		$this->zbxTestMainFilterDropdownSelectWait('hostid', '40001');
		$this->zbxTestClickLinkTextWait($name);

		// Clone the application, rename the clone and save it.
		$this->zbxTestClickWait('clone');
		$this->zbxTestInputTypeOverwrite('appname', $name.$suffix);
		$this->zbxTestClickWait('add');

		// Check the result in frontend.
		$this->zbxTestCheckTitle('Configuration of applications');
		$this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Application added');
		$this->zbxTestTextPresent($name.$suffix);
	}

	/**
	 * Test deleting of application.
	 */
	public function testFormApplication_Delete() {
		$name = self::$application;

		// Select hostgroup and host, open a form.
		$this->zbxTestLogin('applications.php');
		$this->zbxTestMainFilterDropdownSelectWait('groupid', '4');
		$this->zbxTestMainFilterDropdownSelectWait('hostid', '40001');
		$this->zbxTestClickLinkTextWait($name);

		// Delete an application.
		$this->zbxTestClickAndAcceptAlert('delete');

		// Check the result in frontend.
		$this->zbxTestCheckTitle('Configuration of applications');
		$this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Application deleted');

		// Check the result in DB.
		$this->assertEquals(0, CDBHelper::getCount("SELECT NULL FROM applications WHERE name='".$name."'"));
	}
}