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