Commit | Line | Data |
---|---|---|
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 | ||
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 | |
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 | /** | |
afa33a28 J |
51 | * Ensure that without any StatusPreference set, checkDefaultMailbox shows |
52 | * up. | |
8ca6be76 J |
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 | } | |
d1fa280a | 62 | $this->assertEquals($testedCheck['severity_id'], '3', ' in line ' . __LINE__); |
8ca6be76 J |
63 | } |
64 | ||
c77f49b7 | 65 | /** |
afa33a28 | 66 | * Permanently hushed items should never show up. |
c77f49b7 | 67 | */ |
8ca6be76 J |
68 | public function testSystemCheckHushForever() { |
69 | $this->_params = array( | |
70 | 'name' => 'checkDefaultMailbox', | |
afa33a28 | 71 | 'ignore_severity' => 7, |
8ca6be76 J |
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 | } | |
afa33a28 J |
80 | else { |
81 | $testedCheck = array(); | |
82 | } | |
8ca6be76 | 83 | } |
f05193f7 | 84 | $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__); |
1da2f9e8 J |
85 | } |
86 | ||
c77f49b7 | 87 | /** |
d1fa280a | 88 | * Items hushed through tomorrow shouldn't show up. |
c77f49b7 | 89 | */ |
1da2f9e8 J |
90 | public function testSystemCheckHushFuture() { |
91 | $tomorrow = new DateTime('tomorrow'); | |
92 | $this->_params = array( | |
93 | 'name' => 'checkDefaultMailbox', | |
f62b5bd7 | 94 | 'ignore_severity' => 7, |
1da2f9e8 J |
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 | } | |
afa33a28 J |
104 | else { |
105 | $testedCheck = array(); | |
106 | } | |
1da2f9e8 | 107 | } |
f05193f7 | 108 | $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__);; |
8ca6be76 J |
109 | } |
110 | ||
c77f49b7 | 111 | /** |
d1fa280a | 112 | * Items hushed through today should show up. |
c77f49b7 J |
113 | */ |
114 | public function testSystemCheckHushToday() { | |
115 | $today = new DateTime('today'); | |
116 | $this->_params = array( | |
117 | 'name' => 'checkDefaultMailbox', | |
f62b5bd7 | 118 | 'ignore_severity' => 7, |
c77f49b7 J |
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 | } | |
afa33a28 J |
128 | else { |
129 | $testedCheck = array(); | |
130 | } | |
c77f49b7 | 131 | } |
f05193f7 | 132 | $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__); |
c77f49b7 J |
133 | } |
134 | ||
135 | /** | |
d1fa280a | 136 | * Items hushed through yesterday should show up. |
c77f49b7 J |
137 | */ |
138 | public function testSystemCheckHushYesterday() { | |
139 | $yesterday = new DateTime('yesterday'); | |
140 | $this->_params = array( | |
141 | 'name' => 'checkDefaultMailbox', | |
f62b5bd7 | 142 | 'ignore_severity' => 7, |
c77f49b7 J |
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 | } | |
afa33a28 J |
152 | else { |
153 | $testedCheck = array(); | |
154 | } | |
c77f49b7 | 155 | } |
f05193f7 | 156 | $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__); |
f62b5bd7 J |
157 | } |
158 | ||
159 | /** | |
d1fa280a | 160 | * Items hushed above current severity should be hidden. |
f62b5bd7 J |
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 | } | |
afa33a28 J |
174 | else { |
175 | $testedCheck = array(); | |
176 | } | |
f62b5bd7 | 177 | } |
f05193f7 | 178 | $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__); |
f62b5bd7 J |
179 | } |
180 | ||
181 | /** | |
d1fa280a | 182 | * Items hushed at current severity should be hidden. |
f62b5bd7 J |
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 | } | |
afa33a28 J |
196 | else { |
197 | $testedCheck = array(); | |
198 | } | |
f62b5bd7 | 199 | } |
f05193f7 | 200 | $this->assertEquals($testedCheck['is_visible'], '0', 'in line ' . __LINE__); |
f62b5bd7 J |
201 | } |
202 | ||
203 | /** | |
d1fa280a | 204 | * Items hushed below current severity should be shown. |
f62b5bd7 J |
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 | } | |
afa33a28 J |
218 | else { |
219 | $testedCheck = array(); | |
220 | } | |
f62b5bd7 | 221 | } |
f05193f7 | 222 | $this->assertEquals($testedCheck['is_visible'], '1', 'in line ' . __LINE__); |
c77f49b7 J |
223 | } |
224 | ||
8ca6be76 | 225 | } |