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

testPageDashboardList.php « selenium « tests « ui - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fae8bd0fd72c58aab5e158f13079768fff26bff2 (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
<?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/CWebTest.php';
require_once dirname(__FILE__).'/behaviors/CMessageBehavior.php';
require_once dirname(__FILE__).'/traits/TableTrait.php';

/**
 * @backup dashboard, dashboard_user, dashboard_usrgrp
 */
class testPageDashboardList extends CWebTest {

	use TableTrait;

	/**
	 * Attach MessageBehavior to the test.
	 *
	 * @return array
	 */
	public function getBehaviors() {
		return [CMessageBehavior::class];
	}

	public function testPageDashboardList_CheckLayout() {
		$this->page->login()->open('zabbix.php?action=dashboard.list');
		$this->page->assertTitle('Dashboards');
		$table = $this->query('class:list-table')->asTable()->one();
		$this->assertEquals(['', 'Name'], $table->getHeadersText());

		// Check filter collapse/expand.
		foreach (['true', 'false'] as $status) {
			$filter_tab = $this->query('xpath://a[contains(@class, "filter-trigger")]')->one();
			$filter_tab->parents('xpath:/li[@aria-expanded="'.$status.'"]')->one()->click();
		}

		// Check filter fields.
		$filter_form = $this->query('name:zbx_filter')->asForm()->one();
		$this->assertEquals(['Name', 'Show'], $filter_form->getLabels()->asText());
		foreach (['All', 'Created by me'] as $show_tag) {
			$this->assertTrue($filter_form->query('xpath://ul[@id="filter_show"]/li/label[text()="'.$show_tag.'"]')->exists());
		};

		// Check filter buttons.
		foreach (['Apply', 'Reset'] as $button) {
			$this->assertTrue($filter_form->query('button', $button)->exists());
		}

		// Check dashboard list button.
		$this->assertTrue(($this->query('name:dashboardForm')->asForm()->one())->query('button:Delete')->exists());

		// Check header buttons.
		$this->assertTrue($this->query('button:Create dashboard')->exists());
		$this->assertTrue($this->query('xpath://button[@title="Kiosk mode"]')->exists());
	}

	public static function getCheckFilterData() {
		return [
			[
				[
					'fields' => [
						'Show' => 'All'
					],
					'result_count' => 16
				]
			],
			[
				[
					'fields' => [
						'Show' => 'Created by me'
					],
					'result_count' => 15
				]
			],
			[
				[
					'fields' => [
						'Name' => 'graph',
						'Show' => 'All'
					],
					'result_count' => 3
				]
			],
			[
				[
					'fields' => [
						'Name' => 'widget',
						'Show' => 'Created by me'
					],
					'result_count' => 9
				]
			],
			[
				[
					'fields' => [
						'Name' => '5'
					],
					'result_count' => 0
				]
			],
			[
				[
					'fields' => [
						'Name' => 'Dashboard for Dynamic item'
					],
					'result_count' => 1
				]
			],
			[
				[
					'fields' => [
						'Name' => 'Testing share dashboard',
						'Show' => 'Created by me'
					],
					'result_count' => 0
				]
			]
		];
	}

	/**
	 * @dataProvider getCheckFilterData
	 */
	public function testPageDashboardList_CheckFilter($data) {
		$this->page->login()->open('zabbix.php?action=dashboard.list');
		$table = $this->query('class:list-table')->asTable()->one();
		$start_rows_count = $table->getRows()->count();
		$this->assertTableStats($start_rows_count);
		$form = $this->query('name:zbx_filter')->asForm()->one();
		$form->fill($data['fields']);
		$form->submit();

		// Check that filtered count matches expected.
		if ($data['result_count'] !== 0) {
			$this->assertEquals($data['result_count'], $table->getRows()->count());
		}
		$this->assertTableStats($data['result_count']);
		$form->query('button:Reset')->one()->click();
		$this->assertEquals($start_rows_count, $table->getRows()->count());
	}

	/**
	 * Check that My and Sharing tags displays correctly in Dashboard Lists for Admin.
	 */
	public function testPageDashboardList_CheckOwners() {
		$this->page->login()->open('zabbix.php?action=dashboard.list');
		$table = $this->query('class:list-table')->asTable()->one();

		$dashboards = CDBHelper::getAll('SELECT name, userid, private, dashboardid FROM dashboard');
		$dashboards_usrgrps = CDBHelper::getAll('SELECT dashboardid FROM dashboard_usrgrp');
		$dashboards_users = CDBHelper::getAll('SELECT dashboardid FROM dashboard_user');

		// Checking that dashboard, owned by Admin, has My tag near its name.
		foreach ($dashboards as $dashboard) {
			if ($dashboard['userid'] == 1) {
				$this->assertEquals('My', $this->getTagText($table, $dashboard['name'], 'green'));

				if ($dashboard['private'] == 0) {
					$this->assertEquals('Shared', $this->getTagText($table, $dashboard['name'], 'yellow'));
				}
			}

			// Checking that Admin dashboards, shared with groups, has Shared tag.
			$this->assertDashboardOwner($dashboards_usrgrps, $dashboard, $table);

			// Checking that Admin dashboards, shared with users, has Shared tag.
			$this->assertDashboardOwner($dashboards_users, $dashboard, $table);
		}
	}

	public function testPageDashboardList_DeleteSingleDashboard() {
		$this->page->login()->open('zabbix.php?action=dashboard.list');
		$dashboard_name = 'Testing share dashboard';
		$table = $this->query('class:list-table')->asTable()->one();

		// Delete single Dashboard.
		$before_rows_count = $table->getRows()->count();
		$this->assertTableStats($before_rows_count);
		$table->findRow('Name', $dashboard_name, true)->select();
		$this->query('button:Delete')->one()->click();
		$this->page->acceptAlert();
		$this->page->waitUntilReady();
		$this->assertMessage(TEST_GOOD, 'Dashboard deleted');
		$this->assertTableStats($before_rows_count - 1);

		// Check database.
		$this->assertEquals(0, CDBHelper::getCount('SELECT * FROM dashboard WHERE name='.zbx_dbstr($dashboard_name)));
	}

	public function testPageDashboardList_DeleteAllDashboards() {
		$this->page->login()->open('zabbix.php?action=dashboard.list');
		$this->selectTableRows();
		$this->query('button:Delete')->one()->click();
		$this->page->acceptAlert();
		$this->page->waitUntilReady();
		$this->assertMessage(TEST_GOOD, 'Dashboards deleted');
		$this->assertTableStats(0);

		// Check database.
		$this->assertEquals(0, CDBHelper::getCount('SELECT * FROM dashboard WHERE templateid IS NULL'));
	}

	/**
	 * Allows to check tag near Dashboard name.
	 *
	 * @param element $table	  Table where to find row
	 * @param string $column	  Column name
	 * @param string $color		  Color of tag in the row
	 */
	private function getTagText($table, $column, $color) {
		$row = $table->findRow('Name', $column, true);

		return $row->query('xpath://span[@class="status-'.$color.'"]')->one()->getText();
	}

	/**
	 * Allows to check values in different tables from database.
	 *
	 * @param array $ids		  Dashboard ids where to find particular dashboard id
	 * @param array $dashboard	  Dashboard table from database
	 * @param element $table      Frontend table
	 */
	private function assertDashboardOwner($ids, $dashboard, $table) {
		foreach ($ids as $id) {
			if ($id['dashboardid'] == $dashboard['dashboardid'] && $dashboard['userid'] == 1) {
				$this->assertEquals('Shared', $this->getTagText($table, $dashboard['name'], 'yellow'));
			}
		}
	}
}