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