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