Merge pull request #16469 from civicrm/5.22
[civicrm-core.git] / tests / phpunit / api / v3 / SystemCheckTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * System.check API has many special test cases, so they have their own class.
14 *
15 * We presume that in a test environment, checkDefaultMailbox and
16 * checkDomainNameEmail always fail with a warning, and checkLastCron fails with
17 * an error.
18 *
19 * @package CiviCRM_APIv3
20 * @group headless
21 */
22 class api_v3_SystemCheckTest extends CiviUnitTestCase {
23 protected $_contactID;
24 protected $_locationType;
25 protected $_params;
26
27 public function setUp() {
28 parent::setUp();
29 $this->useTransaction(TRUE);
30 }
31
32 /**
33 * Ensure that without any StatusPreference set, checkDefaultMailbox shows up.
34 * @param int $version
35 * @dataProvider versionThreeAndFour
36 */
37 public function testSystemCheckBasic($version) {
38 $this->_apiversion = $version;
39 $result = $this->callAPISuccess('System', 'check', []);
40 foreach ($result['values'] as $check) {
41 if ($check['name'] == 'checkDefaultMailbox') {
42 $testedCheck = $check;
43 break;
44 }
45 }
46 $this->assertEquals($testedCheck['severity_id'], '3', ' in line ' . __LINE__);
47 }
48
49 /**
50 * Permanently hushed items should never show up.
51 * @param int $version
52 * @dataProvider versionThreeAndFour
53 */
54 public function testSystemCheckHushForever($version) {
55 $this->_apiversion = $version;
56 $this->_params = [
57 'name' => 'checkDefaultMailbox',
58 'ignore_severity' => 7,
59 ];
60 $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
61 $result = $this->callAPISuccess('System', 'check', []);
62 foreach ($result['values'] as $check) {
63 if ($check['name'] == 'checkDefaultMailbox') {
64 $testedCheck = $check;
65 break;
66 }
67 else {
68 $testedCheck = [];
69 }
70 }
71 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__);
72 }
73
74 /**
75 * Disabled items should never show up.
76 *
77 * @param int $version
78 *
79 * @dataProvider versionThreeAndFour
80 */
81 public function testIsInactive($version) {
82 $this->_apiversion = $version;
83 $this->callAPISuccess('StatusPreference', 'create', [
84 'name' => 'checkDefaultMailbox',
85 'is_active' => 0,
86 ]);
87 $result = $this->callAPISuccess('System', 'check', [])['values'];
88 foreach ($result as $check) {
89 if ($check['name'] === 'checkDefaultMailbox') {
90 $this->fail('Check should have been skipped');
91 }
92 }
93 }
94
95 /**
96 * Items hushed through tomorrow shouldn't show up.
97 *
98 * @param int $version
99 *
100 * @dataProvider versionThreeAndFour
101 * @throws \Exception
102 */
103 public function testSystemCheckHushFuture($version) {
104 $this->_apiversion = $version;
105 $tomorrow = new DateTime('tomorrow');
106 $this->_params = [
107 'name' => 'checkDefaultMailbox',
108 'ignore_severity' => 7,
109 'hush_until' => $tomorrow->format('Y-m-d'),
110 ];
111 $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
112 $result = $this->callAPISuccess('System', 'check', []);
113 foreach ($result['values'] as $check) {
114 if ($check['name'] === 'checkDefaultMailbox') {
115 $testedCheck = $check;
116 break;
117 }
118 else {
119 $testedCheck = [];
120 }
121 }
122 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__);
123 }
124
125 /**
126 * Items hushed through today should show up.
127 * @param int $version
128 * @dataProvider versionThreeAndFour
129 */
130 public function testSystemCheckHushToday($version) {
131 $this->_apiversion = $version;
132 $today = new DateTime('today');
133 $this->_params = [
134 'name' => 'checkDefaultMailbox',
135 'ignore_severity' => 7,
136 'hush_until' => $today->format('Y-m-d'),
137 ];
138 $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
139 $result = $this->callAPISuccess('System', 'check', []);
140 foreach ($result['values'] as $check) {
141 if ($check['name'] == 'checkDefaultMailbox') {
142 $testedCheck = $check;
143 break;
144 }
145 else {
146 $testedCheck = [];
147 }
148 }
149 $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__);
150 }
151
152 /**
153 * Items hushed through yesterday should show up.
154 * @param int $version
155 * @dataProvider versionThreeAndFour
156 */
157 public function testSystemCheckHushYesterday($version) {
158 $this->_apiversion = $version;
159 $yesterday = new DateTime('yesterday');
160 $this->_params = [
161 'name' => 'checkDefaultMailbox',
162 'ignore_severity' => 7,
163 'hush_until' => $yesterday->format('Y-m-d'),
164 ];
165 $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
166 $result = $this->callAPISuccess('System', 'check', []);
167 foreach ($result['values'] as $check) {
168 if ($check['name'] == 'checkDefaultMailbox') {
169 $testedCheck = $check;
170 break;
171 }
172 else {
173 $testedCheck = [];
174 }
175 }
176 $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__);
177 }
178
179 /**
180 * Items hushed above current severity should be hidden.
181 * @param int $version
182 * @dataProvider versionThreeAndFour
183 */
184 public function testSystemCheckHushAboveSeverity($version) {
185 $this->_apiversion = $version;
186 $this->_params = [
187 'name' => 'checkDefaultMailbox',
188 'ignore_severity' => 4,
189 ];
190 $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
191 $result = $this->callAPISuccess('System', 'check', []);
192 foreach ($result['values'] as $check) {
193 if ($check['name'] == 'checkDefaultMailbox') {
194 $testedCheck = $check;
195 break;
196 }
197 else {
198 $testedCheck = [];
199 }
200 }
201 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__);
202 }
203
204 /**
205 * Items hushed at current severity should be hidden.
206 * @param int $version
207 * @dataProvider versionThreeAndFour
208 */
209 public function testSystemCheckHushAtSeverity($version) {
210 $this->_apiversion = $version;
211 $this->_params = [
212 'name' => 'checkDefaultMailbox',
213 'ignore_severity' => 3,
214 ];
215 $this->callAPISuccess('StatusPreference', 'create', $this->_params);
216 $result = $this->callAPISuccess('System', 'check');
217 foreach ($result['values'] as $check) {
218 if ($check['name'] == 'checkDefaultMailbox') {
219 $testedCheck = $check;
220 break;
221 }
222 else {
223 $testedCheck = [];
224 }
225 }
226 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__);
227 }
228
229 /**
230 * Items hushed below current severity should be shown.
231 * @param int $version
232 * @dataProvider versionThreeAndFour
233 */
234 public function testSystemCheckHushBelowSeverity($version) {
235 $this->_apiversion = $version;
236 $this->_params = [
237 'name' => 'checkDefaultMailbox',
238 'ignore_severity' => 2,
239 ];
240 $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
241 $result = $this->callAPISuccess('System', 'check', []);
242 foreach ($result['values'] as $check) {
243 if ($check['name'] == 'checkDefaultMailbox') {
244 $testedCheck = $check;
245 break;
246 }
247 else {
248 $testedCheck = [];
249 }
250 }
251 $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__);
252 }
253
254 }