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