Add in Country and StateProvince APIv4 Entities
[civicrm-core.git] / tests / phpunit / api / v3 / SystemCheckTest.php
CommitLineData
8ca6be76
J
1<?php
2/*
3 +--------------------------------------------------------------------+
7d61e75f 4 | Copyright CiviCRM LLC. All rights reserved. |
8ca6be76 5 | |
7d61e75f
TO
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 |
8ca6be76
J
9 +--------------------------------------------------------------------+
10 */
11
8ca6be76
J
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
acb109b7 20 * @group headless
8ca6be76
J
21 */
22class api_v3_SystemCheckTest extends CiviUnitTestCase {
8ca6be76
J
23 protected $_contactID;
24 protected $_locationType;
25 protected $_params;
26
8ca6be76 27 public function setUp() {
8ca6be76
J
28 parent::setUp();
29 $this->useTransaction(TRUE);
30 }
31
32 /**
2d932085
CW
33 * Ensure that without any StatusPreference set, checkDefaultMailbox shows up.
34 * @param int $version
35 * @dataProvider versionThreeAndFour
8ca6be76 36 */
2d932085
CW
37 public function testSystemCheckBasic($version) {
38 $this->_apiversion = $version;
9099cab3 39 $result = $this->callAPISuccess('System', 'check', []);
8ca6be76
J
40 foreach ($result['values'] as $check) {
41 if ($check['name'] == 'checkDefaultMailbox') {
42 $testedCheck = $check;
43 break;
44 }
45 }
d1fa280a 46 $this->assertEquals($testedCheck['severity_id'], '3', ' in line ' . __LINE__);
8ca6be76
J
47 }
48
c77f49b7 49 /**
afa33a28 50 * Permanently hushed items should never show up.
2d932085
CW
51 * @param int $version
52 * @dataProvider versionThreeAndFour
c77f49b7 53 */
2d932085
CW
54 public function testSystemCheckHushForever($version) {
55 $this->_apiversion = $version;
9099cab3 56 $this->_params = [
8ca6be76 57 'name' => 'checkDefaultMailbox',
afa33a28 58 'ignore_severity' => 7,
9099cab3 59 ];
8ca6be76 60 $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
9099cab3 61 $result = $this->callAPISuccess('System', 'check', []);
8ca6be76
J
62 foreach ($result['values'] as $check) {
63 if ($check['name'] == 'checkDefaultMailbox') {
64 $testedCheck = $check;
65 break;
66 }
afa33a28 67 else {
9099cab3 68 $testedCheck = [];
afa33a28 69 }
8ca6be76 70 }
f05193f7 71 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__);
1da2f9e8
J
72 }
73
b4628ea6 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
c77f49b7 95 /**
d1fa280a 96 * Items hushed through tomorrow shouldn't show up.
b4628ea6 97 *
2d932085 98 * @param int $version
b4628ea6 99 *
2d932085 100 * @dataProvider versionThreeAndFour
b4628ea6 101 * @throws \Exception
c77f49b7 102 */
2d932085
CW
103 public function testSystemCheckHushFuture($version) {
104 $this->_apiversion = $version;
1da2f9e8 105 $tomorrow = new DateTime('tomorrow');
9099cab3 106 $this->_params = [
1da2f9e8 107 'name' => 'checkDefaultMailbox',
f62b5bd7 108 'ignore_severity' => 7,
1da2f9e8 109 'hush_until' => $tomorrow->format('Y-m-d'),
9099cab3 110 ];
1da2f9e8 111 $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
9099cab3 112 $result = $this->callAPISuccess('System', 'check', []);
1da2f9e8 113 foreach ($result['values'] as $check) {
b4628ea6 114 if ($check['name'] === 'checkDefaultMailbox') {
1da2f9e8
J
115 $testedCheck = $check;
116 break;
117 }
afa33a28 118 else {
9099cab3 119 $testedCheck = [];
afa33a28 120 }
1da2f9e8 121 }
fe7f4414 122 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__);
8ca6be76
J
123 }
124
c77f49b7 125 /**
d1fa280a 126 * Items hushed through today should show up.
2d932085
CW
127 * @param int $version
128 * @dataProvider versionThreeAndFour
c77f49b7 129 */
2d932085
CW
130 public function testSystemCheckHushToday($version) {
131 $this->_apiversion = $version;
c77f49b7 132 $today = new DateTime('today');
9099cab3 133 $this->_params = [
c77f49b7 134 'name' => 'checkDefaultMailbox',
f62b5bd7 135 'ignore_severity' => 7,
c77f49b7 136 'hush_until' => $today->format('Y-m-d'),
9099cab3 137 ];
c77f49b7 138 $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
9099cab3 139 $result = $this->callAPISuccess('System', 'check', []);
c77f49b7
J
140 foreach ($result['values'] as $check) {
141 if ($check['name'] == 'checkDefaultMailbox') {
142 $testedCheck = $check;
143 break;
144 }
afa33a28 145 else {
9099cab3 146 $testedCheck = [];
afa33a28 147 }
c77f49b7 148 }
f05193f7 149 $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__);
c77f49b7
J
150 }
151
152 /**
d1fa280a 153 * Items hushed through yesterday should show up.
2d932085
CW
154 * @param int $version
155 * @dataProvider versionThreeAndFour
c77f49b7 156 */
2d932085
CW
157 public function testSystemCheckHushYesterday($version) {
158 $this->_apiversion = $version;
c77f49b7 159 $yesterday = new DateTime('yesterday');
9099cab3 160 $this->_params = [
c77f49b7 161 'name' => 'checkDefaultMailbox',
f62b5bd7 162 'ignore_severity' => 7,
c77f49b7 163 'hush_until' => $yesterday->format('Y-m-d'),
9099cab3 164 ];
c77f49b7 165 $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
9099cab3 166 $result = $this->callAPISuccess('System', 'check', []);
c77f49b7
J
167 foreach ($result['values'] as $check) {
168 if ($check['name'] == 'checkDefaultMailbox') {
169 $testedCheck = $check;
170 break;
171 }
afa33a28 172 else {
9099cab3 173 $testedCheck = [];
afa33a28 174 }
c77f49b7 175 }
f05193f7 176 $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__);
f62b5bd7
J
177 }
178
179 /**
d1fa280a 180 * Items hushed above current severity should be hidden.
2d932085
CW
181 * @param int $version
182 * @dataProvider versionThreeAndFour
f62b5bd7 183 */
2d932085
CW
184 public function testSystemCheckHushAboveSeverity($version) {
185 $this->_apiversion = $version;
9099cab3 186 $this->_params = [
f62b5bd7
J
187 'name' => 'checkDefaultMailbox',
188 'ignore_severity' => 4,
9099cab3 189 ];
f62b5bd7 190 $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
9099cab3 191 $result = $this->callAPISuccess('System', 'check', []);
f62b5bd7
J
192 foreach ($result['values'] as $check) {
193 if ($check['name'] == 'checkDefaultMailbox') {
194 $testedCheck = $check;
195 break;
196 }
afa33a28 197 else {
9099cab3 198 $testedCheck = [];
afa33a28 199 }
f62b5bd7 200 }
f05193f7 201 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__);
f62b5bd7
J
202 }
203
204 /**
d1fa280a 205 * Items hushed at current severity should be hidden.
2d932085
CW
206 * @param int $version
207 * @dataProvider versionThreeAndFour
f62b5bd7 208 */
2d932085
CW
209 public function testSystemCheckHushAtSeverity($version) {
210 $this->_apiversion = $version;
9099cab3 211 $this->_params = [
f62b5bd7
J
212 'name' => 'checkDefaultMailbox',
213 'ignore_severity' => 3,
9099cab3 214 ];
2d932085
CW
215 $this->callAPISuccess('StatusPreference', 'create', $this->_params);
216 $result = $this->callAPISuccess('System', 'check');
f62b5bd7
J
217 foreach ($result['values'] as $check) {
218 if ($check['name'] == 'checkDefaultMailbox') {
219 $testedCheck = $check;
220 break;
221 }
afa33a28 222 else {
9099cab3 223 $testedCheck = [];
afa33a28 224 }
f62b5bd7 225 }
f05193f7 226 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__);
f62b5bd7
J
227 }
228
229 /**
d1fa280a 230 * Items hushed below current severity should be shown.
2d932085
CW
231 * @param int $version
232 * @dataProvider versionThreeAndFour
f62b5bd7 233 */
2d932085
CW
234 public function testSystemCheckHushBelowSeverity($version) {
235 $this->_apiversion = $version;
9099cab3 236 $this->_params = [
f62b5bd7
J
237 'name' => 'checkDefaultMailbox',
238 'ignore_severity' => 2,
9099cab3 239 ];
f62b5bd7 240 $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params);
9099cab3 241 $result = $this->callAPISuccess('System', 'check', []);
f62b5bd7
J
242 foreach ($result['values'] as $check) {
243 if ($check['name'] == 'checkDefaultMailbox') {
244 $testedCheck = $check;
245 break;
246 }
afa33a28 247 else {
9099cab3 248 $testedCheck = [];
afa33a28 249 }
f62b5bd7 250 }
f05193f7 251 $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__);
c77f49b7
J
252 }
253
8ca6be76 254}