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