3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * System.check API has many special test cases, so they have their own class.
31 * We presume that in a test environment, checkDefaultMailbox and
32 * checkDomainNameEmail always fail with a warning, and checkLastCron fails with
35 * @package CiviCRM_APIv3
38 class api_v3_SystemCheckTest
extends CiviUnitTestCase
{
39 protected $_contactID;
40 protected $_locationType;
43 public function setUp() {
45 $this->useTransaction(TRUE);
49 * Ensure that without any StatusPreference set, checkDefaultMailbox shows up.
51 * @dataProvider versionThreeAndFour
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;
62 $this->assertEquals($testedCheck['severity_id'], '3', ' in line ' . __LINE__
);
66 * Permanently hushed items should never show up.
68 * @dataProvider versionThreeAndFour
70 public function testSystemCheckHushForever($version) {
71 $this->_apiversion
= $version;
73 'name' => 'checkDefaultMailbox',
74 'ignore_severity' => 7,
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;
87 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__
);
91 * Disabled items should never show up.
95 * @dataProvider versionThreeAndFour
97 public function testIsInactive($version) {
98 $this->_apiversion
= $version;
99 $this->callAPISuccess('StatusPreference', 'create', [
100 'name' => 'checkDefaultMailbox',
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');
112 * Items hushed through tomorrow shouldn't show up.
114 * @param int $version
116 * @dataProvider versionThreeAndFour
119 public function testSystemCheckHushFuture($version) {
120 $this->_apiversion
= $version;
121 $tomorrow = new DateTime('tomorrow');
123 'name' => 'checkDefaultMailbox',
124 'ignore_severity' => 7,
125 'hush_until' => $tomorrow->format('Y-m-d'),
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;
138 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__
);;
142 * Items hushed through today should show up.
143 * @param int $version
144 * @dataProvider versionThreeAndFour
146 public function testSystemCheckHushToday($version) {
147 $this->_apiversion
= $version;
148 $today = new DateTime('today');
150 'name' => 'checkDefaultMailbox',
151 'ignore_severity' => 7,
152 'hush_until' => $today->format('Y-m-d'),
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;
165 $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__
);
169 * Items hushed through yesterday should show up.
170 * @param int $version
171 * @dataProvider versionThreeAndFour
173 public function testSystemCheckHushYesterday($version) {
174 $this->_apiversion
= $version;
175 $yesterday = new DateTime('yesterday');
177 'name' => 'checkDefaultMailbox',
178 'ignore_severity' => 7,
179 'hush_until' => $yesterday->format('Y-m-d'),
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;
192 $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__
);
196 * Items hushed above current severity should be hidden.
197 * @param int $version
198 * @dataProvider versionThreeAndFour
200 public function testSystemCheckHushAboveSeverity($version) {
201 $this->_apiversion
= $version;
203 'name' => 'checkDefaultMailbox',
204 'ignore_severity' => 4,
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;
217 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__
);
221 * Items hushed at current severity should be hidden.
222 * @param int $version
223 * @dataProvider versionThreeAndFour
225 public function testSystemCheckHushAtSeverity($version) {
226 $this->_apiversion
= $version;
228 'name' => 'checkDefaultMailbox',
229 'ignore_severity' => 3,
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;
242 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__
);
246 * Items hushed below current severity should be shown.
247 * @param int $version
248 * @dataProvider versionThreeAndFour
250 public function testSystemCheckHushBelowSeverity($version) {
251 $this->_apiversion
= $version;
253 'name' => 'checkDefaultMailbox',
254 'ignore_severity' => 2,
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;
267 $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__
);