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

testAuditlogScheduledReport.php « api_json « tests « ui - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4365e1111f69ef0b38683efd23f1a74c0afa4603 (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
<?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__).'/common/testAuditlogCommon.php';

/**
 * @backup report
 */
class testAuditlogScheduledReport extends testAuditlogCommon {

	/**
	 * Created scheduled report id
	 */
	protected static $resourceid;

	/**
	 * Created scheduled reports user group id (before update)
	 */
	protected static $before_usrgrp;

	/**
	 * Created scheduled reports user id (before update)
	 */
	protected static $before_user;

	public function testAuditlogScheduledReport_Create() {
		$create = $this->call('report.create', [
			[
				'userid' => 1,
				'name' => 'Report for audit',
				'dashboardid' => 1,
				'period' => 1,
				'cycle' => 1,
				'start_time' => 43200,
				'weekdays' => 31,
				'active_since' => '2021-04-01',
				'active_till' => '2021-08-31',
				'subject' => 'Weekly report',
				'message' => 'Report accompanying text',
				'status' => 1,
				'description' => 'Report description',
				'users' => [
					[
						'userid' => 1,
						'access_userid' => 1,
						'exclude' => 0
					]
				],
				'user_groups' => [
					[
						'usrgrpid' => 7,
						'access_userid' => 0
					]
				]
			]
		]);

		self::$resourceid = $create['result']['reportids'][0];
		self::$before_usrgrp = CDBHelper::getRow('SELECT reportusrgrpid FROM report_usrgrp WHERE reportid='.
				zbx_dbstr(self::$resourceid)
		);
		self::$before_user = CDBHelper::getRow('SELECT reportuserid FROM report_user WHERE reportid='.
				zbx_dbstr(self::$resourceid)
		);

		$created = json_encode([
			'report.userid' => ['add', '1'],
			'report.name' => ['add', 'Report for audit'],
			'report.dashboardid' => ['add', '1'],
			'report.period' => ['add', '1'],
			'report.cycle' => ['add', '1'],
			'report.start_time' => ['add', '43200'],
			'report.weekdays' => ['add', '31'],
			'report.active_since' => ['add', '1617235200'],
			'report.active_till' => ['add', '1630454399'],
			'report.subject' => ['add', 'Weekly report'],
			'report.message' => ['add', 'Report accompanying text'],
			'report.status' => ['add', '1'],
			'report.description' => ['add', 'Report description'],
			'report.users['.self::$before_user['reportuserid'].']' => ['add'],
			'report.users['.self::$before_user['reportuserid'].'].userid' => ['add', '1'],
			'report.users['.self::$before_user['reportuserid'].'].access_userid' => ['add', '1'],
			'report.users['.self::$before_user['reportuserid'].'].reportuserid' => ['add', self::$before_user['reportuserid']],
			'report.user_groups['.self::$before_usrgrp['reportusrgrpid'].']' => ['add'],
			'report.user_groups['.self::$before_usrgrp['reportusrgrpid'].'].usrgrpid' => ['add', '7'],
			'report.user_groups['.self::$before_usrgrp['reportusrgrpid'].'].access_userid' => ['add', '0'],
			'report.user_groups['.self::$before_usrgrp['reportusrgrpid'].'].reportusrgrpid'
				=> ['add', self::$before_usrgrp['reportusrgrpid']],
			'report.reportid' => ['add', self::$resourceid]
		]);

		$this->getAuditDetails('details', $this->add_actionid, $created, self::$resourceid);
	}

	/**
	 * @depends testAuditlogScheduledReport_Create
	 */
	public function testAuditlogScheduledReport_Update() {
		$this->call('report.update', [
			[
				'reportid' => self::$resourceid,
				'userid' => 1,
				'name' => 'Updated report for audit',
				'dashboardid' => 2,
				'period' => 3,
				'cycle' => 2,
				'start_time' => 44200,
				'weekdays' => 0,
				'active_since' => '2022-01-01',
				'active_till' => '2022-03-31',
				'subject' => 'Updated subject',
				'message' => 'Updated message',
				'status' => 0,
				'description' => 'Updated description',
				'users' => [
					[
						'userid' => 2,
						'access_userid' => 0,
						'exclude' => 1
					]
				],
				'user_groups' => [
					[
						'usrgrpid' => 8,
						'access_userid' => 1
					]
				]
			]
		]);

		$usrgrp = CDBHelper::getRow('SELECT reportusrgrpid FROM report_usrgrp WHERE reportid='.zbx_dbstr(self::$resourceid));
		$user = CDBHelper::getRow('SELECT reportuserid FROM report_user WHERE reportid='.zbx_dbstr(self::$resourceid));

		$updated = json_encode([
			'report.users['.self::$before_user['reportuserid'].']' => ['delete'],
			'report.user_groups['.self::$before_usrgrp['reportusrgrpid'].']' => ['delete'],
			'report.users['.$user['reportuserid'].']' => ['add'],
			'report.user_groups['.$usrgrp['reportusrgrpid'].']' => ['add'],
			'report.name' => ['update', 'Updated report for audit', 'Report for audit'],
			'report.dashboardid' => ['update', '2', '1'],
			'report.period' => ['update', '3', '1'],
			'report.cycle' => ['update', '2', '1'],
			'report.start_time' => ['update', '44200', '43200'],
			'report.weekdays' => ['update', '0', '31'],
			'report.active_since' => ['update', '1640995200', '1617235200'],
			'report.active_till' => ['update', '1648771199', '1630454399'],
			'report.subject' => ['update', 'Updated subject', 'Weekly report'],
			'report.message' => ['update', 'Updated message', 'Report accompanying text'],
			'report.status' => ['update', '0', '1'],
			'report.description' => ['update', 'Updated description', 'Report description'],
			'report.users['.$user['reportuserid'].'].userid' => ['add', '2'],
			'report.users['.$user['reportuserid'].'].access_userid' => ['add', '0'],
			'report.users['.$user['reportuserid'].'].exclude' => ['add', '1'],
			'report.users['.$user['reportuserid'].'].reportuserid' => ['add', $user['reportuserid']],
			'report.user_groups['.$usrgrp['reportusrgrpid'].'].usrgrpid' => ['add', '8'],
			'report.user_groups['.$usrgrp['reportusrgrpid'].'].access_userid' => ['add', '1'],
			'report.user_groups['.$usrgrp['reportusrgrpid'].'].reportusrgrpid' => ['add', $usrgrp['reportusrgrpid']]
		]);

		$this->getAuditDetails('details', $this->update_actionid, $updated, self::$resourceid);
	}

	/**
	 * @depends testAuditlogScheduledReport_Create
	 */
	public function testAuditlogScheduledReport_Delete() {
		$this->call('report.delete', [self::$resourceid]);
		$this->getAuditDetails('resourcename', $this->delete_actionid, 'Updated report for audit', self::$resourceid);
	}
}