3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
13 * System.check API has many special test cases, so they have their own class.
15 * We presume that in a test environment, checkDefaultMailbox and
16 * checkDomainNameEmail always fail with a warning, and checkLastCron fails with
19 * @package CiviCRM_APIv3
22 class api_v3_SystemCheckTest
extends CiviUnitTestCase
{
23 protected $_contactID;
24 protected $_locationType;
27 public function setUp() {
29 $this->useTransaction(TRUE);
33 * Ensure that without any StatusPreference set, checkDefaultMailbox shows up.
35 * @dataProvider versionThreeAndFour
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;
46 $this->assertEquals($testedCheck['severity_id'], '3', ' in line ' . __LINE__
);
50 * Permanently hushed items should never show up.
52 * @dataProvider versionThreeAndFour
54 public function testSystemCheckHushForever($version) {
55 $this->_apiversion
= $version;
57 'name' => 'checkDefaultMailbox',
58 'ignore_severity' => 7,
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;
71 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__
);
75 * Disabled items should never show up.
79 * @dataProvider versionThreeAndFour
81 public function testIsInactive($version) {
82 $this->_apiversion
= $version;
83 $this->callAPISuccess('StatusPreference', 'create', [
84 'name' => 'checkDefaultMailbox',
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');
96 * Items hushed through tomorrow shouldn't show up.
100 * @dataProvider versionThreeAndFour
103 public function testSystemCheckHushFuture($version) {
104 $this->_apiversion
= $version;
105 $tomorrow = new DateTime('tomorrow');
107 'name' => 'checkDefaultMailbox',
108 'ignore_severity' => 7,
109 'hush_until' => $tomorrow->format('Y-m-d'),
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;
122 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__
);
126 * Items hushed through today should show up.
127 * @param int $version
128 * @dataProvider versionThreeAndFour
130 public function testSystemCheckHushToday($version) {
131 $this->_apiversion
= $version;
132 $today = new DateTime('today');
134 'name' => 'checkDefaultMailbox',
135 'ignore_severity' => 7,
136 'hush_until' => $today->format('Y-m-d'),
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;
149 $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__
);
153 * Items hushed through yesterday should show up.
154 * @param int $version
155 * @dataProvider versionThreeAndFour
157 public function testSystemCheckHushYesterday($version) {
158 $this->_apiversion
= $version;
159 $yesterday = new DateTime('yesterday');
161 'name' => 'checkDefaultMailbox',
162 'ignore_severity' => 7,
163 'hush_until' => $yesterday->format('Y-m-d'),
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;
176 $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__
);
180 * Items hushed above current severity should be hidden.
181 * @param int $version
182 * @dataProvider versionThreeAndFour
184 public function testSystemCheckHushAboveSeverity($version) {
185 $this->_apiversion
= $version;
187 'name' => 'checkDefaultMailbox',
188 'ignore_severity' => 4,
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;
201 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__
);
205 * Items hushed at current severity should be hidden.
206 * @param int $version
207 * @dataProvider versionThreeAndFour
209 public function testSystemCheckHushAtSeverity($version) {
210 $this->_apiversion
= $version;
212 'name' => 'checkDefaultMailbox',
213 'ignore_severity' => 3,
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;
226 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__
);
230 * Items hushed below current severity should be shown.
231 * @param int $version
232 * @dataProvider versionThreeAndFour
234 public function testSystemCheckHushBelowSeverity($version) {
235 $this->_apiversion
= $version;
237 'name' => 'checkDefaultMailbox',
238 'ignore_severity' => 2,
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;
251 $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__
);