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

testPageHostPrototypes.php « hosts « selenium « tests « ui - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 10e0c5cfc0a23a91cad0c598594a47a2300c6223 (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
<?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__).'/../../include/CLegacyWebTest.php';
require_once dirname(__FILE__).'/../traits/TableTrait.php';

/**
 * @backup hosts
 */
class testPageHostPrototypes extends CLegacyWebTest {

	use TableTrait;

	const DICROVERY_RULE_ID = 90001;
	const HOST_PROTOTYPES_COUNT = 8;

	public function testPageHostPrototypes_CheckLayout() {
		$this->zbxTestLogin('host_prototypes.php?parent_discoveryid='.self::DICROVERY_RULE_ID.'&context=host');
		$this->zbxTestCheckTitle('Configuration of host prototypes');
		$this->zbxTestCheckHeader('Host prototypes');

		$table = $this->query('xpath://form[@name="hosts"]/table[@class="list-table"]')->asTable()->one();
		$headers = ['', 'Name', 'Templates', 'Create enabled', 'Discover', 'Tags'];
		$this->assertSame($headers, $table->getHeadersText());

		foreach (['Create enabled', 'Create disabled', 'Delete'] as $button) {
			$element = $this->query('button', $button)->one();
			$this->assertTrue($element->isPresent());
			$this->assertFalse($element->isEnabled());
		}

		$this->assertTableStats(self::HOST_PROTOTYPES_COUNT);

		// Check tags on the specific host prototype.
		$tags = $table->findRow('Name', 'Host prototype {#1}')->getColumn('Tags')->query('class:tag')->all();
		$this->assertEquals(['host_proto_tag_1: value1', 'host_proto_tag_2: value2'], $tags->asText());

		foreach ($tags as $tag) {
			$tag->click();
			$hint = $this->query('xpath://div[@data-hintboxid]')
					->asOverlayDialog()->waitUntilPresent()->all()->last();
			$this->assertEquals($tag->getText(), $hint->getText());
			$hint->close();
		}
	}

	public static function getSelectedData() {
		return [
			[
				[
					'item' => 'Discovery rule 1',
					'hosts' => [
						'Host prototype {#1}'
					]
				]
			],
			[
				[
					'item' => 'Discovery rule 2',
					'hosts' => 'all'
				]
			],
			[
				[
					'item' => 'Discovery rule 3',
					'hosts' => [
						'Host prototype {#7}',
						'Host prototype {#9}',
						'Host prototype {#10}'
					]
				]
			]
		];
	}

	/**
	 * Select specified hosts from host prototype page.
	 *
	 * @param array $data	test case data from data provider
	 */
	private function selectHostPrototype($data) {
		$discoveryid = DBfetch(DBselect("SELECT itemid FROM items WHERE name=".zbx_dbstr($data['item'])));
		$this->zbxTestLogin("host_prototypes.php?parent_discoveryid=".$discoveryid['itemid'].'&context=host');

		if ($data['hosts'] === 'all') {
			$this->zbxTestCheckboxSelect('all_hosts');
			return;
		}

		foreach ($data['hosts'] as $host) {
			$result = DBselect('SELECT hostid FROM hosts WHERE host='.zbx_dbstr($host));
			while ($row = DBfetch($result)) {
				$this->zbxTestCheckboxSelect('group_hostid_'.$row['hostid']);
			}
		}
	}

	/**
	 * Check specific page action.
	 * Actions are defined by buttons pressed on page.
	 *
	 * @param array  $data		test case data from data provider
	 * @param string $action	button text (action to be executed)
	 * @param int    $status	host status to be checked in DB
	 */
	protected function checkPageAction($data, $action, $status = null) {
		// Click on button with required action.
		if ($action === 'Click on state') {
			foreach ($data['hosts'] as $host) {
				$id = DBfetch(DBselect('SELECT hostid FROM hosts WHERE name='.zbx_dbstr($host)));
				$this->zbxTestClickXpathWait("//a[contains(@onclick,'group_hostid=".$id['hostid']."')]");
			}
		}
		else {
			$this->selectHostPrototype($data);
			$this->zbxTestClickButtonText($action);
			$this->zbxTestAcceptAlert();
		}

		$this->zbxTestIsElementPresent('//*[@class="msg-good"]');
		$this->zbxTestCheckTitle('Configuration of host prototypes');
		$this->zbxTestCheckHeader('Host prototypes');

		// Create query part for status (if any).
		$status_criteria = ($status !== null) ? (' AND status='.$status) : '';

		// Check the results in DB.
		if ($data['hosts'] === 'all') {
			$sql = 'SELECT NULL'.
						' FROM hosts'.
						' WHERE hostid IN ('.
							'SELECT hostid'.
							' FROM host_discovery'.
							' WHERE parent_itemid IN ('.
								'SELECT itemid'.
								' FROM items'.
								' WHERE name='.zbx_dbstr($data['item']).
							')'.
						')';
		}
		else {
			$names = [];
			foreach ($data['hosts'] as $host) {
				$names[] = zbx_dbstr($host);
			}

			$sql = 'SELECT NULL'.
					' FROM hosts'.
					' WHERE host IN ('.implode(',', $names).')';
		}

		$this->assertEquals(0, CDBHelper::getCount($sql.$status_criteria));
	}

	/**
	 * @dataProvider getSelectedData
	 */
	public function testPageHostPrototypes_DisableSelected($data) {
		$this->checkPageAction($data, 'Create disabled', HOST_STATUS_MONITORED);
	}

	/**
	 * @dataProvider getSelectedData
	 */
	public function testPageHostPrototypes_EnableSelected($data) {
		$this->checkPageAction($data, 'Create enabled', HOST_STATUS_NOT_MONITORED);
	}

	/**
	 * @dataProvider getSelectedData
	 */
	public function testPageHostPrototypes_DeleteSelected($data) {
		$this->checkPageAction($data, 'Delete');
	}

	public static function getHostPrototypeData() {
		return [
			[
				[
					'item' => 'Discovery rule 1',
					'hosts' => [
						'Host prototype {#2}'
					],
					'status' => HOST_STATUS_NOT_MONITORED
				]
			],
			[
				[
					'item' => 'Discovery rule 1',
					'hosts' => [
						'Host prototype {#3}'
					],
					'status' => HOST_STATUS_MONITORED
				]
			]
		];
	}

	/**
	 * @dataProvider getHostPrototypeData
	 */
	public function testPageHostPrototypes_SingleEnableDisable($data) {
		$discoveryid = DBfetch(DBselect("SELECT itemid FROM items WHERE name=".zbx_dbstr($data['item'])));
		$this->zbxTestLogin("host_prototypes.php?parent_discoveryid=".$discoveryid['itemid'].'&context=host');

		$this->checkPageAction($data, 'Click on state', $data['status']);
	}
}