Commit | Line | Data |
---|---|---|
8ca6be76 J |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.6 | | |
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 SystemPreference 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'], 'warning', ' in line ' . __LINE__); | |
67 | } | |
68 | ||
c77f49b7 J |
69 | /** |
70 | * Permanently hushed items should never show up. | |
71 | */ | |
8ca6be76 J |
72 | public function testSystemCheckHushForever() { |
73 | $this->_params = array( | |
74 | 'name' => 'checkDefaultMailbox', | |
a24a0be0 | 75 | 'ignore_severity' => 4, |
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 | } | |
84 | } | |
1da2f9e8 J |
85 | $this->assertArrayNotHasKey('name', $testedCheck, 'warning', ' in line ' . __LINE__); |
86 | } | |
87 | ||
c77f49b7 J |
88 | /** |
89 | * Items hushed through tomorrow shouldn't show up. | |
90 | */ | |
1da2f9e8 J |
91 | public function testSystemCheckHushFuture() { |
92 | $tomorrow = new DateTime('tomorrow'); | |
93 | $this->_params = array( | |
94 | 'name' => 'checkDefaultMailbox', | |
a24a0be0 | 95 | 'ignore_severity' => 4, |
1da2f9e8 J |
96 | 'hush_until' => $tomorrow->format('Y-m-d'), |
97 | ); | |
98 | $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params); | |
99 | $result = $this->callAPISuccess('System', 'check', array()); | |
100 | foreach ($result['values'] as $check) { | |
101 | if ($check['name'] == 'checkDefaultMailbox') { | |
102 | $testedCheck = $check; | |
103 | break; | |
104 | } | |
105 | } | |
8ca6be76 J |
106 | $this->assertArrayNotHasKey('name', $testedCheck, 'warning', ' in line ' . __LINE__); |
107 | } | |
108 | ||
c77f49b7 J |
109 | /** |
110 | * Items hushed through today should show up. | |
111 | */ | |
112 | public function testSystemCheckHushToday() { | |
113 | $today = new DateTime('today'); | |
114 | $this->_params = array( | |
115 | 'name' => 'checkDefaultMailbox', | |
a24a0be0 | 116 | 'ignore_severity' => 4, |
c77f49b7 J |
117 | 'hush_until' => $today->format('Y-m-d'), |
118 | ); | |
119 | $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params); | |
120 | $result = $this->callAPISuccess('System', 'check', array()); | |
121 | foreach ($result['values'] as $check) { | |
122 | if ($check['name'] == 'checkDefaultMailbox') { | |
123 | $testedCheck = $check; | |
124 | break; | |
125 | } | |
126 | } | |
127 | $this->assertArrayHasKey('name', $testedCheck, 'warning', ' in line ' . __LINE__); | |
128 | } | |
129 | ||
130 | /** | |
131 | * Items hushed through yesterday should show up. | |
132 | */ | |
133 | public function testSystemCheckHushYesterday() { | |
134 | $yesterday = new DateTime('yesterday'); | |
135 | $this->_params = array( | |
136 | 'name' => 'checkDefaultMailbox', | |
a24a0be0 | 137 | 'ignore_severity' => 4, |
c77f49b7 J |
138 | 'hush_until' => $yesterday->format('Y-m-d'), |
139 | ); | |
140 | $statusPreference = $this->callAPISuccess('StatusPreference', 'create', $this->_params); | |
141 | $result = $this->callAPISuccess('System', 'check', array()); | |
142 | foreach ($result['values'] as $check) { | |
143 | if ($check['name'] == 'checkDefaultMailbox') { | |
144 | $testedCheck = $check; | |
145 | break; | |
146 | } | |
147 | } | |
148 | fwrite(STDERR, 'yesterday'); | |
149 | fwrite(STDERR, print_r($yesterday->format('Y-m-d'), TRUE)); | |
150 | $this->assertArrayHasKey('name', $testedCheck, 'warning', ' in line ' . __LINE__); | |
151 | } | |
152 | ||
8ca6be76 | 153 | } |