3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * System.check API has many special test cases, so they have their own class.
15 * We presume that in a test environment, checkDefaultMailbox and
16 * checkDomainNameEmail always fail with a warning, and checkLastCron fails with
19 * @package CiviCRM_APIv3
22 class api_v3_SystemCheckTest
extends CiviUnitTestCase
{
24 public function setUp() {
26 $this->useTransaction(TRUE);
30 * Ensure that without any StatusPreference set, checkDefaultMailbox shows up.
34 * @dataProvider versionThreeAndFour
36 * @throws \CRM_Core_Exception
38 public function testSystemCheckBasic($version) {
39 $this->_apiversion
= $version;
40 $this->runStatusCheck([], ['severity_id' => 3]);
44 * Permanently hushed items should never show up.
48 * @dataProvider versionThreeAndFour
49 * @throws \CRM_Core_Exception
51 public function testSystemCheckHushForever($version) {
52 $this->_apiversion
= $version;
53 $this->runStatusCheck([
54 'name' => 'checkDefaultMailbox',
55 'ignore_severity' => 7,
56 ], ['is_visible' => 0]);
60 * Disabled items should never show up.
64 * @dataProvider versionThreeAndFour
66 * @throws \CRM_Core_Exception
68 public function testIsInactive($version) {
69 $this->_apiversion
= $version;
70 $this->callAPISuccess('StatusPreference', 'create', [
71 'name' => 'checkDefaultMailbox',
74 $result = $this->callAPISuccess('System', 'check', [])['values'];
75 foreach ($result as $check) {
76 if ($check['name'] === 'checkDefaultMailbox') {
77 $this->fail('Check should have been skipped');
83 * Items hushed through tomorrow shouldn't show up.
87 * @dataProvider versionThreeAndFour
90 public function testSystemCheckHushFuture($version) {
91 $this->_apiversion
= $version;
92 $tomorrow = new DateTime('tomorrow');
93 $this->runStatusCheck([
94 'name' => 'checkDefaultMailbox',
95 'ignore_severity' => 7,
96 'hush_until' => $tomorrow->format('Y-m-d'),
97 ], ['is_visible' => 0]);
101 * Items hushed through today should show up.
103 * @param int $version
105 * @dataProvider versionThreeAndFour
106 * @throws \CRM_Core_Exception
108 public function testSystemCheckHushToday($version) {
109 $this->_apiversion
= $version;
110 $today = new DateTime('today');
111 $this->runStatusCheck([
112 'name' => 'checkDefaultMailbox',
113 'ignore_severity' => 7,
114 'hush_until' => $today->format('Y-m-d'),
115 ], ['is_visible' => 1]);
119 * Items hushed through yesterday should show up.
121 * @param int $version
123 * @dataProvider versionThreeAndFour
125 * @throws \CRM_Core_Exception
127 public function testSystemCheckHushYesterday($version) {
128 $this->_apiversion
= $version;
129 $yesterday = new DateTime('yesterday');
130 $this->runStatusCheck([
131 'name' => 'checkDefaultMailbox',
132 'ignore_severity' => 7,
133 'hush_until' => $yesterday->format('Y-m-d'),
134 ], ['is_visible' => 1]);
138 * Items hushed above current severity should be hidden.
140 * @param int $version
142 * @dataProvider versionThreeAndFour
144 * @throws \CRM_Core_Exception
146 public function testSystemCheckHushAboveSeverity($version) {
147 $this->_apiversion
= $version;
148 $this->runStatusCheck([
149 'name' => 'checkDefaultMailbox',
150 'ignore_severity' => 4,
151 ], ['is_visible' => 0]);
155 * Items hushed at current severity should be hidden.
157 * @param int $version
159 * @dataProvider versionThreeAndFour
161 * @throws \CRM_Core_Exception
163 public function testSystemCheckHushAtSeverity($version) {
164 $this->_apiversion
= $version;
165 $this->runStatusCheck([
166 'name' => 'checkDefaultMailbox',
167 'ignore_severity' => 3,
168 ], ['is_visible' => 0]);
172 * Items hushed below current severity should be shown.
174 * @param int $version
176 * @dataProvider versionThreeAndFour
177 * @throws \CRM_Core_Exception
179 public function testSystemCheckHushBelowSeverity($version) {
180 $this->_apiversion
= $version;
181 $this->runStatusCheck([
182 'name' => 'checkDefaultMailbox',
183 'ignore_severity' => 2,
184 ], ['is_visible' => 1]);
188 * Run check and assert result is as expected.
190 * @param array $params
191 * Values to update the status check with.
192 * @param array $expected
194 * @throws \CRM_Core_Exception
196 protected function runStatusCheck($params, $expected) {
197 if (!empty($params)) {
198 $this->callAPISuccess('StatusPreference', 'create', $params);
200 $result = $this->callAPISuccess('System', 'check', []);
201 foreach ($result['values'] as $check) {
202 if ($check['name'] === 'checkDefaultMailbox') {
203 foreach ($expected as $key => $value) {
204 $this->assertEquals($check[$key], $value);
209 throw new CRM_Core_Exception('checkDefaultMailbox not in results');