Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | |
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
5 | | CiviCRM version 4.3 | | |
6 | +--------------------------------------------------------------------+ | |
7 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
8 | +--------------------------------------------------------------------+ | |
9 | | This file is a part of CiviCRM. | | |
10 | | | | |
11 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
12 | | under the terms of the GNU Affero General Public License | | |
13 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
14 | | | | |
15 | | CiviCRM is distributed in the hope that it will be useful, but | | |
16 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
17 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
18 | | See the GNU Affero General Public License for more details. | | |
19 | | | | |
20 | | You should have received a copy of the GNU Affero General Public | | |
21 | | License and the CiviCRM Licensing Exception along | | |
22 | | with this program; if not, contact CiviCRM LLC | | |
23 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
24 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
25 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
26 | +--------------------------------------------------------------------+ | |
27 | */ | |
28 | ||
29 | /** | |
30 | * File for the CiviCRM APIv3 job functions | |
31 | * | |
32 | * @package CiviCRM_APIv3 | |
33 | * @subpackage API_Job | |
34 | * | |
35 | * @copyright CiviCRM LLC (c) 2004-2013 | |
36 | * @version $Id: Job.php 30879 2010-11-22 15:45:55Z shot $ | |
37 | * | |
38 | */ | |
39 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
40 | class api_v3_JobTest extends CiviUnitTestCase { | |
41 | protected $_apiversion; | |
42 | ||
43 | public $_eNoticeCompliant = TRUE; | |
44 | public $DBResetRequired = FALSE; | |
45 | public $_entity = 'Job'; | |
46 | public $_apiVersion = 3; | |
47 | ||
48 | function setUp() { | |
49 | parent::setUp(); | |
50 | $this->quickCleanup(array('civicrm_job')); | |
51 | } | |
52 | ||
53 | function tearDown() { | |
54 | $this->quickCleanup(array('civicrm_job')); | |
55 | parent::tearDown(); | |
56 | } | |
57 | ||
58 | /** | |
59 | * check with no name | |
60 | */ | |
61 | function testCreateWithoutName() { | |
62 | $params = array( | |
63 | 'is_active' => 1, | |
64 | 'version' => $this->_apiVersion, | |
65 | ); | |
66 | $result = civicrm_api('job', 'create', $params); | |
67 | ||
68 | $this->assertEquals($result['is_error'], 1); | |
69 | $this->assertEquals($result['error_message'], | |
70 | 'Mandatory key(s) missing from params array: run_frequency, name, api_entity, api_action' | |
71 | ); | |
72 | } | |
73 | ||
74 | /** | |
75 | * create job with an invalid "run_frequency" value | |
76 | */ | |
77 | function testCreateWithInvalidFrequency() { | |
78 | $params = array( | |
79 | 'version' => $this->_apiVersion, | |
80 | 'sequential' => 1, | |
81 | 'name' => 'API_Test_Job', | |
82 | 'description' => 'A long description written by hand in cursive', | |
83 | 'run_frequency' => 'Fortnightly', | |
84 | 'api_entity' => 'ApiTestEntity', | |
85 | 'api_action' => 'apitestaction', | |
86 | 'parameters' => 'Semi-formal explanation of runtime job parameters', | |
87 | 'is_active' => 1, | |
88 | ); | |
89 | $result = civicrm_api('job', 'create', $params); | |
90 | $this->assertEquals($result['is_error'], 1); | |
91 | } | |
92 | ||
93 | /** | |
94 | * create job | |
95 | */ | |
96 | function testCreate() { | |
97 | $params = array( | |
98 | 'version' => $this->_apiVersion, | |
99 | 'sequential' => 1, | |
100 | 'name' => 'API_Test_Job', | |
101 | 'description' => 'A long description written by hand in cursive', | |
102 | 'run_frequency' => 'Daily', | |
103 | 'api_entity' => 'ApiTestEntity', | |
104 | 'api_action' => 'apitestaction', | |
105 | 'parameters' => 'Semi-formal explanation of runtime job parameters', | |
106 | 'is_active' => 1, | |
107 | ); | |
108 | $result = civicrm_api('job', 'create', $params); | |
109 | $this->assertAPISuccess($result); | |
110 | $this->documentMe($params, $result, __FUNCTION__, __FILE__); | |
111 | $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__); | |
112 | ||
113 | // mutate $params to match expected return value | |
114 | unset($params['version']); | |
115 | unset($params['sequential']); | |
116 | //assertDBState compares expected values in $result to actual values in the DB | |
117 | $this->assertDBState('CRM_Core_DAO_Job', $result['id'], $params); | |
118 | } | |
119 | ||
120 | /** | |
121 | * check with empty array | |
122 | */ | |
123 | function testDeleteEmpty() { | |
124 | $params = array(); | |
125 | $result = civicrm_api('job', 'delete', $params); | |
126 | $this->assertEquals($result['is_error'], 1); | |
127 | } | |
128 | ||
129 | /** | |
130 | * check with No array | |
131 | */ | |
132 | function testDeleteParamsNotArray() { | |
133 | $result = civicrm_api('job', 'delete', 'string'); | |
134 | $this->assertEquals($result['is_error'], 1); | |
135 | } | |
136 | ||
137 | /** | |
138 | * check if required fields are not passed | |
139 | */ | |
140 | function testDeleteWithoutRequired() { | |
141 | $params = array( | |
142 | 'name' => 'API_Test_PP', | |
143 | 'title' => 'API Test Payment Processor', | |
144 | 'class_name' => 'CRM_Core_Payment_APITest', | |
145 | ); | |
146 | ||
147 | $result = civicrm_api('job', 'delete', $params); | |
148 | $this->assertEquals($result['is_error'], 1); | |
149 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, id'); | |
150 | } | |
151 | ||
152 | /** | |
153 | * check with incorrect required fields | |
154 | */ | |
155 | function testDeleteWithIncorrectData() { | |
156 | $params = array( | |
157 | 'id' => 'abcd', | |
158 | 'version' => $this->_apiVersion, | |
159 | ); | |
160 | ||
161 | $result = civicrm_api('job', 'delete', $params); | |
162 | ||
163 | $this->assertEquals($result['is_error'], 1); | |
164 | $this->assertEquals($result['error_message'], 'Invalid value for job ID'); | |
165 | } | |
166 | ||
167 | /** | |
168 | * check job delete | |
169 | */ | |
170 | function testDelete() { | |
171 | $createParams = array( | |
172 | 'version' => $this->_apiVersion, | |
173 | 'sequential' => 1, | |
174 | 'name' => 'API_Test_Job', | |
175 | 'description' => 'A long description written by hand in cursive', | |
176 | 'run_frequency' => 'Daily', | |
177 | 'api_entity' => 'ApiTestEntity', | |
178 | 'api_action' => 'apitestaction', | |
179 | 'parameters' => 'Semi-formal explanation of runtime job parameters', | |
180 | 'is_active' => 1, | |
181 | ); | |
182 | $createResult = civicrm_api('job', 'create', $createParams); | |
183 | $this->assertAPISuccess($createResult); | |
184 | ||
185 | $params = array( | |
186 | 'id' => $createResult['id'], | |
187 | 'version' => $this->_apiVersion, | |
188 | ); | |
189 | $result = civicrm_api('job', 'delete', $params); | |
190 | $this->documentMe($params, $result, __FUNCTION__, __FILE__); | |
191 | $this->assertAPISuccess($result); | |
192 | } | |
193 | ||
194 | /** | |
195 | ||
196 | public function testCallUpdateGreetingMissingParams() { | |
197 | $result = civicrm_api($this->_entity, 'update_greeting', array('gt' => 1, 'version' => $this->_apiVersion)); | |
198 | $this->assertEquals('Mandatory key(s) missing from params array: ct', $result['error_message']); | |
199 | } | |
200 | ||
201 | public function testCallUpdateGreetingIncorrectParams() { | |
202 | $result = civicrm_api($this->_entity, 'update_greeting', array('gt' => 1, 'ct' => 'djkfhdskjfhds', 'version' => $this->_apiVersion)); | |
203 | $this->assertEquals('ct `djkfhdskjfhds` is not valid.', $result['error_message']); | |
204 | } | |
205 | /* | |
206 | * Note that this test is about tesing the metadata / calling of the function & doesn't test the success of the called function | |
207 | */ | |
208 | public function testCallUpdateGreetingSuccess() { | |
209 | $result = civicrm_api($this->_entity, 'update_greeting', array('gt' => 'postal_greeting', 'ct' => 'Individual', 'version' => $this->_apiVersion)); | |
210 | $this->assertAPISuccess($result); | |
211 | } | |
212 | ||
213 | public function testCallUpdateGreetingCommaSeparatedParamsSuccess() { | |
214 | $gt = 'postal_greeting,email_greeting,addressee'; | |
215 | $ct = 'Individual,Household'; | |
216 | $result = civicrm_api($this->_entity, 'update_greeting', array('gt' => $gt, 'ct' => $ct, 'version' => $this->_apiVersion)); | |
217 | $this->assertAPISuccess($result); | |
218 | } | |
219 | } | |
220 |