Merge pull request #7529 from rohankatkar/Webtests_Fix_master
[civicrm-core.git] / tests / phpunit / api / v3 / SystemCheckTest.php
CommitLineData
8ca6be76
J
1<?php
2/*
3 +--------------------------------------------------------------------+
81621fee 4 | CiviCRM version 4.7 |
8ca6be76
J
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
29require_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 */
41class 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 /**
afa33a28
J
55 * Ensure that without any StatusPreference set, checkDefaultMailbox shows
56 * up.
8ca6be76
J
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 }
d1fa280a 66 $this->assertEquals($testedCheck['severity_id'], '3', ' in line ' . __LINE__);
8ca6be76
J
67 }
68
c77f49b7 69 /**
afa33a28 70 * Permanently hushed items should never show up.
c77f49b7 71 */
8ca6be76
J
72 public function testSystemCheckHushForever() {
73 $this->_params = array(
74 'name' => 'checkDefaultMailbox',
afa33a28 75 'ignore_severity' => 7,
8ca6be76
J
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 }
afa33a28
J
84 else {
85 $testedCheck = array();
86 }
8ca6be76 87 }
f05193f7 88 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__);
1da2f9e8
J
89 }
90
c77f49b7 91 /**
d1fa280a 92 * Items hushed through tomorrow shouldn't show up.
c77f49b7 93 */
1da2f9e8
J
94 public function testSystemCheckHushFuture() {
95 $tomorrow = new DateTime('tomorrow');
96 $this->_params = array(
97 'name' => 'checkDefaultMailbox',
f62b5bd7 98 'ignore_severity' => 7,
1da2f9e8
J
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 }
afa33a28
J
108 else {
109 $testedCheck = array();
110 }
1da2f9e8 111 }
f05193f7 112 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__);;
8ca6be76
J
113 }
114
c77f49b7 115 /**
d1fa280a 116 * Items hushed through today should show up.
c77f49b7
J
117 */
118 public function testSystemCheckHushToday() {
119 $today = new DateTime('today');
120 $this->_params = array(
121 'name' => 'checkDefaultMailbox',
f62b5bd7 122 'ignore_severity' => 7,
c77f49b7
J
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 }
afa33a28
J
132 else {
133 $testedCheck = array();
134 }
c77f49b7 135 }
f05193f7 136 $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__);
c77f49b7
J
137 }
138
139 /**
d1fa280a 140 * Items hushed through yesterday should show up.
c77f49b7
J
141 */
142 public function testSystemCheckHushYesterday() {
143 $yesterday = new DateTime('yesterday');
144 $this->_params = array(
145 'name' => 'checkDefaultMailbox',
f62b5bd7 146 'ignore_severity' => 7,
c77f49b7
J
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 }
afa33a28
J
156 else {
157 $testedCheck = array();
158 }
c77f49b7 159 }
f05193f7 160 $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__);
f62b5bd7
J
161 }
162
163 /**
d1fa280a 164 * Items hushed above current severity should be hidden.
f62b5bd7
J
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 }
afa33a28
J
178 else {
179 $testedCheck = array();
180 }
f62b5bd7 181 }
f05193f7 182 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__);
f62b5bd7
J
183 }
184
185 /**
d1fa280a 186 * Items hushed at current severity should be hidden.
f62b5bd7
J
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 }
afa33a28
J
200 else {
201 $testedCheck = array();
202 }
f62b5bd7 203 }
f05193f7 204 $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__);
f62b5bd7
J
205 }
206
207 /**
d1fa280a 208 * Items hushed below current severity should be shown.
f62b5bd7
J
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 }
afa33a28
J
222 else {
223 $testedCheck = array();
224 }
f62b5bd7 225 }
f05193f7 226 $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__);
c77f49b7
J
227 }
228
8ca6be76 229}