Merge pull request #10393 from JMAConsulting/exportBatch
[civicrm-core.git] / tests / phpunit / api / v3 / SystemCheckTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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
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
36 * @group headless
37 */
38 class 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 /**
52 * Ensure that without any StatusPreference set, checkDefaultMailbox shows
53 * up.
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 }
63 $this->assertEquals($testedCheck['severity_id'], '3', ' in line ' . __LINE__);
64 }
65
66 /**
67 * Permanently hushed items should never show up.
68 */
69 public function testSystemCheckHushForever() {
70 $this->_params = array(
71 'name' => 'checkDefaultMailbox',
72 'ignore_severity' => 7,
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 }
81 else {
82 $testedCheck = array();
83 }
84 }
85 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__);
86 }
87
88 /**
89 * Items hushed through tomorrow shouldn't show up.
90 */
91 public function testSystemCheckHushFuture() {
92 $tomorrow = new DateTime('tomorrow');
93 $this->_params = array(
94 'name' => 'checkDefaultMailbox',
95 'ignore_severity' => 7,
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 }
105 else {
106 $testedCheck = array();
107 }
108 }
109 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__);;
110 }
111
112 /**
113 * Items hushed through today should show up.
114 */
115 public function testSystemCheckHushToday() {
116 $today = new DateTime('today');
117 $this->_params = array(
118 'name' => 'checkDefaultMailbox',
119 'ignore_severity' => 7,
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 }
129 else {
130 $testedCheck = array();
131 }
132 }
133 $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__);
134 }
135
136 /**
137 * Items hushed through yesterday should show up.
138 */
139 public function testSystemCheckHushYesterday() {
140 $yesterday = new DateTime('yesterday');
141 $this->_params = array(
142 'name' => 'checkDefaultMailbox',
143 'ignore_severity' => 7,
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 }
153 else {
154 $testedCheck = array();
155 }
156 }
157 $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__);
158 }
159
160 /**
161 * Items hushed above current severity should be hidden.
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 }
175 else {
176 $testedCheck = array();
177 }
178 }
179 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__);
180 }
181
182 /**
183 * Items hushed at current severity should be hidden.
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 }
197 else {
198 $testedCheck = array();
199 }
200 }
201 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__);
202 }
203
204 /**
205 * Items hushed below current severity should be shown.
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 }
219 else {
220 $testedCheck = array();
221 }
222 }
223 $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__);
224 }
225
226 }