Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /** | |
3 | * File for the TestActivity class | |
4 | * | |
5 | * (PHP 5) | |
6 | * | |
6c6e6187 TO |
7 | * @author Walt Haas <walt@dharmatech.org> (801) 534-1262 |
8 | * @copyright Copyright CiviCRM LLC (C) 2009 | |
9 | * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html | |
6a488035 | 10 | * GNU Affero General Public License version 3 |
6c6e6187 TO |
11 | * @version $Id: ActivityTest.php 31254 2010-12-15 10:09:29Z eileen $ |
12 | * @package CiviCRM | |
6a488035 TO |
13 | * |
14 | * This file is part of CiviCRM | |
15 | * | |
16 | * CiviCRM is free software; you can redistribute it and/or | |
17 | * modify it under the terms of the GNU Affero General Public License | |
18 | * as published by the Free Software Foundation; either version 3 of | |
19 | * the License, or (at your option) any later version. | |
20 | * | |
21 | * CiviCRM is distributed in the hope that it will be useful, | |
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | * GNU Affero General Public License for more details. | |
25 | * | |
26 | * You should have received a copy of the GNU Affero General Public | |
27 | * License along with this program. If not, see | |
28 | * <http://www.gnu.org/licenses/>. | |
29 | */ | |
30 | ||
31 | /** | |
32 | * Include class definitions | |
33 | */ | |
34 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
35 | ||
36 | ||
37 | /** | |
38 | * Test APIv3 civicrm_activity_* functions | |
39 | * | |
6c6e6187 TO |
40 | * @package CiviCRM_APIv3 |
41 | * @subpackage API_Activity | |
6a488035 | 42 | */ |
6a488035 TO |
43 | class api_v3_ActivityTest extends CiviUnitTestCase { |
44 | protected $_params; | |
45 | protected $_params2; | |
46 | protected $_entity = 'activity'; | |
47 | protected $_apiversion = 3; | |
48 | protected $test_activity_type_value; | |
b8a3da18 | 49 | protected $_contactID; |
9f1b81e0 | 50 | |
6a488035 TO |
51 | /** |
52 | * Test setup for every test | |
53 | * | |
54 | * Connect to the database, truncate the tables that will be used | |
55 | * and redirect stdin to a temporary file | |
56 | */ | |
57 | public function setUp() { | |
58 | // Connect to the database | |
59 | parent::setUp(); | |
6a488035 | 60 | |
b8a3da18 | 61 | $this->_contactID = $this->individualCreate(); |
6a488035 | 62 | //create activity types |
b8a3da18 | 63 | $activityTypes = $this->callAPISuccess('option_value', 'create', array( |
64 | 'option_group_id' => 2, | |
65 | 'name' => 'Test activity type', | |
66 | 'label' => 'Test activity type', | |
21dfd5f5 | 67 | 'sequential' => 1, |
b8a3da18 | 68 | )); |
6a488035 TO |
69 | $this->test_activity_type_value = $activityTypes['values'][0]['value']; |
70 | $this->test_activity_type_id = $activityTypes['id']; | |
71 | $this->_params = array( | |
b8a3da18 | 72 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
73 | 'activity_type_id' => $this->test_activity_type_value, |
74 | 'subject' => 'test activity type id', | |
75 | 'activity_date_time' => '2011-06-02 14:36:13', | |
76 | 'status_id' => 2, | |
77 | 'priority_id' => 1, | |
78 | 'duration' => 120, | |
79 | 'location' => 'Pensulvania', | |
80 | 'details' => 'a test activity', | |
6a488035 TO |
81 | ); |
82 | $this->_params2 = array( | |
b8a3da18 | 83 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
84 | 'subject' => 'Eat & drink', |
85 | 'activity_date_time' => date('Ymd'), | |
86 | 'duration' => 120, | |
87 | 'location' => 'Napier', | |
88 | 'details' => 'discuss & eat', | |
89 | 'status_id' => 1, | |
90 | 'activity_type_id' => $this->test_activity_type_value, | |
6a488035 TO |
91 | ); |
92 | // create a logged in USER since the code references it for source_contact_id | |
93 | $this->createLoggedInUser(); | |
94 | } | |
95 | ||
96 | /** | |
97 | * Tears down the fixture, for example, closes a network connection. | |
98 | * This method is called after a test is executed. | |
6a488035 | 99 | */ |
00be9182 | 100 | public function tearDown() { |
6a488035 TO |
101 | $tablesToTruncate = array( |
102 | 'civicrm_contact', | |
103 | 'civicrm_activity', | |
b319d00a | 104 | 'civicrm_activity_contact', |
6a488035 TO |
105 | ); |
106 | $this->quickCleanup($tablesToTruncate, TRUE); | |
9f1b81e0 | 107 | $this->callAPISuccess('option_value', 'delete', array('id' => $this->test_activity_type_id)); |
6a488035 TO |
108 | } |
109 | ||
110 | /** | |
100fef9d | 111 | * Check with empty array |
6a488035 | 112 | */ |
00be9182 | 113 | public function testActivityCreateEmpty() { |
9f1b81e0 | 114 | $result = $this->callAPIFailure('activity', 'create', array()); |
6a488035 TO |
115 | } |
116 | ||
117 | /** | |
100fef9d | 118 | * Check if required fields are not passed |
6a488035 | 119 | */ |
00be9182 | 120 | public function testActivityCreateWithoutRequired() { |
6a488035 TO |
121 | $params = array( |
122 | 'subject' => 'this case should fail', | |
123 | 'scheduled_date_time' => date('Ymd'), | |
6a488035 | 124 | ); |
d0e1eff2 | 125 | $result = $this->callAPIFailure('activity', 'create', $params); |
6a488035 TO |
126 | } |
127 | ||
128 | /** | |
129 | * Test civicrm_activity_create() with mismatched activity_type_id | |
130 | * and activity_name | |
131 | */ | |
00be9182 | 132 | public function testActivityCreateMismatchNameType() { |
6a488035 | 133 | $params = array( |
b8a3da18 | 134 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
135 | 'subject' => 'Test activity', |
136 | 'activity_date_time' => date('Ymd'), | |
137 | 'duration' => 120, | |
138 | 'location' => 'Pensulvania', | |
139 | 'details' => 'a test activity', | |
140 | 'status_id' => 1, | |
141 | 'activity_name' => 'Fubar activity type', | |
142 | 'activity_type_id' => 5, | |
143 | 'scheduled_date_time' => date('Ymd'), | |
6a488035 TO |
144 | ); |
145 | ||
d0e1eff2 | 146 | $result = $this->callAPIFailure('activity', 'create', $params); |
6a488035 TO |
147 | } |
148 | ||
149 | /** | |
150 | * Test civicrm_activity_id() with missing source_contact_id is put with the current user. | |
151 | */ | |
00be9182 | 152 | public function testActivityCreateWithMissingContactId() { |
6a488035 TO |
153 | $params = array( |
154 | 'subject' => 'Make-it-Happen Meeting', | |
155 | 'activity_date_time' => date('Ymd'), | |
156 | 'duration' => 120, | |
157 | 'location' => 'Pensulvania', | |
158 | 'details' => 'a test activity', | |
159 | 'status_id' => 1, | |
160 | 'activity_name' => 'Test activity type', | |
6a488035 TO |
161 | ); |
162 | ||
b8a3da18 | 163 | $result = $this->callAPISuccess('activity', 'create', $params); |
6a488035 TO |
164 | } |
165 | ||
166 | /** | |
167 | * Test civicrm_activity_id() with non-numeric source_contact_id | |
168 | */ | |
00be9182 | 169 | public function testActivityCreateWithNonNumericContactId() { |
6a488035 TO |
170 | $params = array( |
171 | 'source_contact_id' => 'fubar', | |
172 | 'subject' => 'Make-it-Happen Meeting', | |
173 | 'activity_date_time' => date('Ymd'), | |
174 | 'duration' => 120, | |
175 | 'location' => 'Pensulvania', | |
176 | 'details' => 'a test activity', | |
177 | 'status_id' => 1, | |
178 | 'activity_name' => 'Test activity type', | |
6a488035 TO |
179 | ); |
180 | ||
b8a3da18 | 181 | $result = $this->callAPIFailure('activity', 'create', $params); |
6a488035 TO |
182 | } |
183 | ||
6a488035 | 184 | /** |
feb2a730 | 185 | * Ensure that an invalid activity type causes failure |
186 | * oddly enough this test was failing because the creation of the invalid type | |
187 | * got added to the set up routine. Probably a mis-fix on a test | |
6a488035 | 188 | */ |
00be9182 | 189 | public function testActivityCreateWithNonNumericActivityTypeId() { |
6a488035 | 190 | $params = array( |
b8a3da18 | 191 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
192 | 'subject' => 'Make-it-Happen Meeting', |
193 | 'activity_date_time' => date('Ymd'), | |
194 | 'duration' => 120, | |
195 | 'location' => 'Pensulvania', | |
196 | 'details' => 'a test activity', | |
197 | 'status_id' => 1, | |
feb2a730 | 198 | 'activity_type_id' => 'Invalid Test activity type', |
6a488035 TO |
199 | ); |
200 | ||
d0e1eff2 | 201 | $result = $this->callAPIFailure('activity', 'create', $params); |
6a488035 TO |
202 | } |
203 | ||
204 | /** | |
100fef9d | 205 | * Check with incorrect required fields |
6a488035 | 206 | */ |
00be9182 | 207 | public function testActivityCreateWithUnknownActivityTypeId() { |
6a488035 | 208 | $params = array( |
b8a3da18 | 209 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
210 | 'subject' => 'Make-it-Happen Meeting', |
211 | 'activity_date_time' => date('Ymd'), | |
212 | 'duration' => 120, | |
213 | 'location' => 'Pensulvania', | |
214 | 'details' => 'a test activity', | |
215 | 'status_id' => 1, | |
216 | 'activity_type_id' => 699, | |
6a488035 TO |
217 | ); |
218 | ||
d0e1eff2 | 219 | $result = $this->callAPIFailure('activity', 'create', $params); |
6a488035 TO |
220 | } |
221 | ||
00be9182 | 222 | public function testActivityCreateWithInvalidPriority() { |
6a488035 | 223 | $params = array( |
b8a3da18 | 224 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
225 | 'subject' => 'Make-it-Happen Meeting', |
226 | 'activity_date_time' => date('Ymd'), | |
227 | 'duration' => 120, | |
228 | 'location' => 'Pensulvania', | |
229 | 'details' => 'a test activity', | |
230 | 'status_id' => 1, | |
231 | 'priority_id' => 44, | |
232 | 'activity_type_id' => 1, | |
6a488035 TO |
233 | ); |
234 | ||
b8a3da18 | 235 | $result = $this->callAPIFailure('activity', 'create', $params, |
236 | "'44' is not a valid option for field priority_id"); | |
283f988c | 237 | $this->assertEquals('priority_id', $result['error_field']); |
6a488035 TO |
238 | } |
239 | ||
feb2a730 | 240 | |
00be9182 | 241 | public function testActivityCreateWithValidStringPriority() { |
6a488035 | 242 | $params = array( |
b8a3da18 | 243 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
244 | 'subject' => 'Make-it-Happen Meeting', |
245 | 'activity_date_time' => date('Ymd'), | |
246 | 'duration' => 120, | |
247 | 'location' => 'Pensulvania', | |
248 | 'details' => 'a test activity', | |
249 | 'status_id' => 1, | |
250 | 'priority_id' => 'Urgent', | |
251 | 'activity_type_id' => 1, | |
6a488035 TO |
252 | ); |
253 | ||
b8a3da18 | 254 | $result = $this->callAPISuccess('activity', 'create', $params); |
6a488035 TO |
255 | $this->assertEquals(1, $result['values'][$result['id']]['priority_id']); |
256 | } | |
257 | ||
00be9182 | 258 | public function testActivityCreateWithInValidStringPriority() { |
6a488035 | 259 | $params = array( |
b8a3da18 | 260 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
261 | 'subject' => 'Make-it-Happen Meeting', |
262 | 'activity_date_time' => date('Ymd'), | |
263 | 'duration' => 120, | |
264 | 'location' => 'Pensulvania', | |
265 | 'details' => 'a test activity', | |
266 | 'status_id' => 1, | |
267 | 'priority_id' => 'ergUrgent', | |
268 | 'activity_type_id' => 1, | |
6a488035 TO |
269 | ); |
270 | ||
b8a3da18 | 271 | $result = $this->callAPIFailure('activity', 'create', $params, |
272 | "'ergUrgent' is not a valid option for field priority_id"); | |
6a488035 TO |
273 | } |
274 | ||
275 | /** | |
276 | * Test civicrm_activity_create() with valid parameters | |
277 | */ | |
00be9182 | 278 | public function testActivityCreate() { |
6a488035 | 279 | |
b8a3da18 | 280 | $result = $this->callAPISuccess('activity', 'create', $this->_params); |
281 | $result = $this->callAPISuccess('activity', 'get', $this->_params); | |
6a488035 TO |
282 | $this->assertEquals($result['values'][$result['id']]['duration'], 120, 'in line ' . __LINE__); |
283 | $this->assertEquals($result['values'][$result['id']]['subject'], 'test activity type id', 'in line ' . __LINE__); | |
284 | $this->assertEquals($result['values'][$result['id']]['activity_date_time'], '2011-06-02 14:36:13', 'in line ' . __LINE__); | |
285 | $this->assertEquals($result['values'][$result['id']]['location'], 'Pensulvania', 'in line ' . __LINE__); | |
286 | $this->assertEquals($result['values'][$result['id']]['details'], 'a test activity', 'in line ' . __LINE__); | |
287 | $this->assertEquals($result['values'][$result['id']]['status_id'], 2, 'in line ' . __LINE__); | |
288 | $this->assertEquals($result['values'][$result['id']]['id'], $result['id'], 'in line ' . __LINE__); | |
289 | } | |
290 | ||
291 | /** | |
292 | * Test civicrm_activity_create() with valid parameters - use type_id | |
293 | */ | |
00be9182 | 294 | public function testActivityCreateCampaignTypeID() { |
07fd63f5 | 295 | $this->enableCiviCampaign(); |
6a488035 TO |
296 | |
297 | $defaults = array(); | |
298 | ||
299 | $params = array( | |
b8a3da18 | 300 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
301 | 'subject' => 'Make-it-Happen Meeting', |
302 | 'activity_date_time' => '20110316', | |
303 | 'duration' => 120, | |
304 | 'location' => 'Pensulvania', | |
305 | 'details' => 'a test activity', | |
306 | 'status_id' => 1, | |
307 | 'activity_type_id' => 29, | |
6a488035 TO |
308 | 'priority_id' => 1, |
309 | ); | |
310 | ||
b8a3da18 | 311 | $result = $this->callAPISuccess('activity', 'create', $params); |
6a488035 | 312 | //todo test target & assignee are set |
6a488035 | 313 | |
b8a3da18 | 314 | //$this->assertEquals($result['values'][$result['id']]['source_contact_id'], $this->_contactID, 'in line ' . __LINE__); |
2b46f1da | 315 | $result = $this->callAPISuccess('activity', 'get', array('id' => $result['id'])); |
6a488035 TO |
316 | $this->assertEquals($result['values'][$result['id']]['duration'], 120, 'in line ' . __LINE__); |
317 | $this->assertEquals($result['values'][$result['id']]['subject'], 'Make-it-Happen Meeting', 'in line ' . __LINE__); | |
318 | $this->assertEquals($result['values'][$result['id']]['activity_date_time'], '2011-03-16 00:00:00', 'in line ' . __LINE__); | |
319 | $this->assertEquals($result['values'][$result['id']]['location'], 'Pensulvania', 'in line ' . __LINE__); | |
320 | $this->assertEquals($result['values'][$result['id']]['details'], 'a test activity', 'in line ' . __LINE__); | |
321 | $this->assertEquals($result['values'][$result['id']]['status_id'], 1, 'in line ' . __LINE__); | |
322 | } | |
323 | ||
00be9182 | 324 | public function testActivityReturnTargetAssignee() { |
6a488035 TO |
325 | |
326 | $description = "Example demonstrates setting & retrieving the target & source"; | |
92915c55 TO |
327 | $subfile = "GetTargetandAssignee"; |
328 | $params = array( | |
b8a3da18 | 329 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
330 | 'subject' => 'Make-it-Happen Meeting', |
331 | 'activity_date_time' => '20110316', | |
332 | 'duration' => 120, | |
333 | 'location' => 'Pensulvania', | |
334 | 'details' => 'a test activity', | |
335 | 'status_id' => 1, | |
336 | 'activity_type_id' => 1, | |
6a488035 | 337 | 'priority_id' => 1, |
b8a3da18 | 338 | 'target_contact_id' => $this->_contactID, |
339 | 'assignee_contact_id' => $this->_contactID, | |
6a488035 TO |
340 | ); |
341 | ||
9f1b81e0 | 342 | $result = $this->callAPIAndDocument('activity', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); |
92915c55 | 343 | $result = $this->callAPISuccess('activity', 'get', array( |
c301f76e | 344 | 'id' => $result['id'], |
345 | 'version' => $this->_apiversion, | |
346 | 'return.assignee_contact_id' => 1, | |
347 | 'return.target_contact_id' => 1, | |
348 | )); | |
6a488035 | 349 | |
b8a3da18 | 350 | $this->assertEquals($this->_contactID, $result['values'][$result['id']]['assignee_contact_id'][0], 'in line ' . __LINE__); |
351 | $this->assertEquals($this->_contactID, $result['values'][$result['id']]['target_contact_id'][0], 'in line ' . __LINE__); | |
6a488035 TO |
352 | } |
353 | ||
00be9182 | 354 | public function testActivityCreateExample() { |
6a488035 TO |
355 | /** |
356 | * Test civicrm_activity_create() using example code | |
357 | */ | |
3ec6e38d | 358 | require_once 'api/v3/examples/Activity/Create.php'; |
6a488035 TO |
359 | $result = activity_create_example(); |
360 | $expectedResult = activity_create_expectedresult(); | |
361 | $this->assertEquals($result, $expectedResult); | |
362 | } | |
363 | ||
6a488035 TO |
364 | /** |
365 | * Test civicrm_activity_create() with valid parameters | |
366 | * and some custom data | |
367 | */ | |
00be9182 | 368 | public function testActivityCreateCustom() { |
6a488035 TO |
369 | $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); |
370 | $params = $this->_params; | |
371 | $params['custom_' . $ids['custom_field_id']] = "custom string"; | |
9f1b81e0 | 372 | $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__); |
92915c55 | 373 | $result = $this->callAPISuccess($this->_entity, 'get', array( |
c301f76e | 374 | 'return.custom_' . $ids['custom_field_id'] => 1, |
375 | 'version' => 3, | |
376 | 'id' => $result['id'], | |
377 | )); | |
6a488035 TO |
378 | $this->assertEquals("custom string", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); |
379 | ||
380 | $this->customFieldDelete($ids['custom_field_id']); | |
381 | $this->customGroupDelete($ids['custom_group_id']); | |
382 | } | |
383 | ||
384 | /** | |
385 | * Test civicrm_activity_create() with valid parameters | |
386 | * and some custom data | |
387 | */ | |
00be9182 | 388 | public function testActivityCreateCustomContactRefField() { |
6a488035 | 389 | |
b8a3da18 | 390 | $this->callAPISuccess('contact', 'create', array('id' => $this->_contactID, 'sort_name' => 'Contact, Test')); |
92915c55 | 391 | $subfile = 'ContactRefCustomField'; |
6a488035 | 392 | $description = "demonstrates create with Contact Reference Custom Field"; |
92915c55 TO |
393 | $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); |
394 | $params = array( | |
6a488035 TO |
395 | 'custom_group_id' => $ids['custom_group_id'], |
396 | 'name' => 'Worker_Lookup', | |
397 | 'label' => 'Worker Lookup', | |
398 | 'html_type' => 'Autocomplete-Select', | |
399 | 'data_type' => 'ContactReference', | |
400 | 'weight' => 4, | |
401 | 'is_searchable' => 1, | |
402 | 'is_active' => 1, | |
6a488035 TO |
403 | ); |
404 | ||
b8a3da18 | 405 | $customField = $this->callAPISuccess('custom_field', 'create', $params); |
6a488035 | 406 | $params = $this->_params; |
b8a3da18 | 407 | $params['custom_' . $customField['id']] = "$this->_contactID"; |
6a488035 | 408 | |
9f1b81e0 | 409 | $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description, $subfile, 'Create'); |
92915c55 | 410 | $result = $this->callAPIAndDocument($this->_entity, 'get', array( |
c301f76e | 411 | 'return.custom_' . $customField['id'] => 1, |
412 | 'id' => $result['id'], | |
413 | ), __FUNCTION__, __FILE__, 'Get with Contact Ref Custom Field', 'ContactRefCustomFieldGet', 'get'); | |
6a488035 | 414 | |
b8a3da18 | 415 | $this->assertEquals('Anderson, Anthony', $result['values'][$result['id']]['custom_' . $customField['id']], ' in line ' . __LINE__); |
416 | $this->assertEquals($this->_contactID, $result['values'][$result['id']]['custom_' . $customField['id'] . "_id"], ' in line ' . __LINE__); | |
417 | $this->assertEquals('Anderson, Anthony', $result['values'][$result['id']]['custom_' . $customField['id'] . '_1'], ' in line ' . __LINE__); | |
418 | $this->assertEquals($this->_contactID, $result['values'][$result['id']]['custom_' . $customField['id'] . "_1_id"], ' in line ' . __LINE__); | |
6a488035 TO |
419 | $this->customFieldDelete($ids['custom_field_id']); |
420 | $this->customGroupDelete($ids['custom_group_id']); | |
421 | } | |
422 | ||
423 | /** | |
424 | * Test civicrm_activity_create() with an invalid text status_id | |
425 | */ | |
00be9182 | 426 | public function testActivityCreateBadTextStatus() { |
6a488035 TO |
427 | |
428 | $params = array( | |
b8a3da18 | 429 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
430 | 'subject' => 'Discussion on Apis for v3', |
431 | 'activity_date_time' => date('Ymd'), | |
432 | 'duration' => 120, | |
433 | 'location' => 'Pensulvania', | |
434 | 'details' => 'a test activity', | |
435 | 'status_id' => 'Invalid', | |
436 | 'activity_name' => 'Test activity type', | |
6a488035 TO |
437 | ); |
438 | ||
d0e1eff2 | 439 | $result = $this->callAPIFailure('activity', 'create', $params); |
feb2a730 | 440 | } |
441 | ||
442 | /** | |
443 | * Test civicrm_activity_create() with an invalid text status_id | |
444 | */ | |
00be9182 | 445 | public function testActivityCreateSupportActivityStatus() { |
feb2a730 | 446 | |
447 | $params = array( | |
b8a3da18 | 448 | 'source_contact_id' => $this->_contactID, |
feb2a730 | 449 | 'subject' => 'Discussion on Apis for v3', |
450 | 'activity_date_time' => date('Ymd'), | |
451 | 'duration' => 120, | |
452 | 'location' => 'Pensulvania', | |
453 | 'details' => 'a test activity', | |
454 | 'activity_status_id' => 'Invalid', | |
455 | 'activity_name' => 'Test activity type', | |
6a488035 | 456 | ); |
feb2a730 | 457 | |
b8a3da18 | 458 | $result = $this->callAPIFailure('activity', 'create', $params, |
459 | "'Invalid' is not a valid option for field status_id"); | |
6a488035 TO |
460 | } |
461 | ||
feb2a730 | 462 | |
6a488035 TO |
463 | /** |
464 | * Test civicrm_activity_create() with valid parameters, | |
465 | * using a text status_id | |
466 | */ | |
00be9182 | 467 | public function testActivityCreateTextStatus() { |
6a488035 | 468 | |
6a488035 | 469 | $params = array( |
b8a3da18 | 470 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
471 | 'subject' => 'Make-it-Happen Meeting', |
472 | 'activity_date_time' => date('Ymd'), | |
473 | 'duration' => 120, | |
474 | 'location' => 'Pensulvania', | |
475 | 'details' => 'a test activity', | |
476 | 'status_id' => 'Scheduled', | |
477 | 'activity_name' => 'Test activity type', | |
6a488035 TO |
478 | ); |
479 | ||
b8a3da18 | 480 | $result = $this->callAPISuccess('activity', 'create', $params); |
6a488035 TO |
481 | $this->assertEquals($result['values'][$result['id']]['duration'], 120, 'in line ' . __LINE__); |
482 | $this->assertEquals($result['values'][$result['id']]['subject'], 'Make-it-Happen Meeting', 'in line ' . __LINE__); | |
483 | $this->assertEquals($result['values'][$result['id']]['activity_date_time'], date('Ymd') . '000000', 'in line ' . __LINE__); | |
484 | $this->assertEquals($result['values'][$result['id']]['location'], 'Pensulvania', 'in line ' . __LINE__); | |
485 | $this->assertEquals($result['values'][$result['id']]['details'], 'a test activity', 'in line ' . __LINE__); | |
6a488035 TO |
486 | } |
487 | ||
488 | /** | |
489 | * Test civicrm_activity_get() with no params | |
490 | */ | |
00be9182 | 491 | public function testActivityGetEmpty() { |
b8a3da18 | 492 | $result = $this->callAPISuccess('activity', 'get', array()); |
6a488035 TO |
493 | } |
494 | ||
495 | /** | |
496 | * Test civicrm_activity_get() with a good activity ID | |
497 | */ | |
00be9182 | 498 | public function testActivityGetGoodID1() { |
6a488035 TO |
499 | // Insert rows in civicrm_activity creating activities 4 and |
500 | // 13 | |
501 | $description = "Function demonstrates getting asignee_contact_id & using it to get the contact"; | |
92915c55 TO |
502 | $subfile = 'ReturnAssigneeContact'; |
503 | $activity = $this->callAPISuccess('activity', 'create', $this->_params); | |
6a488035 | 504 | |
b8a3da18 | 505 | $contact = $this->callAPISuccess('Contact', 'Create', array( |
92915c55 TO |
506 | 'first_name' => "The Rock", |
507 | 'last_name' => 'roccky', | |
508 | 'contact_type' => 'Individual', | |
509 | 'version' => 3, | |
510 | 'api.activity.create' => array( | |
511 | 'id' => $activity['id'], | |
512 | 'assignee_contact_id' => '$value.id', | |
513 | ), | |
514 | )); | |
6a488035 TO |
515 | |
516 | $params = array( | |
517 | 'activity_id' => $activity['id'], | |
518 | 'version' => $this->_apiversion, | |
519 | 'sequential' => 1, | |
520 | 'return.assignee_contact_id' => 1, | |
521 | 'api.contact.get' => array( | |
522 | 'id' => '$value.source_contact_id', | |
523 | ), | |
524 | ); | |
525 | ||
9f1b81e0 | 526 | $result = $this->callAPIAndDocument('Activity', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile); |
6a488035 TO |
527 | |
528 | $this->assertEquals($activity['id'], $result['id'], 'In line ' . __LINE__); | |
6a488035 TO |
529 | |
530 | $this->assertEquals($contact['id'], $result['values'][0]['assignee_contact_id'][0], 'In line ' . __LINE__); | |
531 | ||
b8a3da18 | 532 | $this->assertEquals($this->_contactID, $result['values'][0]['api.contact.get']['values'][0]['contact_id'], 'In line ' . __LINE__); |
6a488035 TO |
533 | $this->assertEquals($this->test_activity_type_value, $result['values'][0]['activity_type_id'], 'In line ' . __LINE__); |
534 | $this->assertEquals("test activity type id", $result['values'][0]['subject'], 'In line ' . __LINE__); | |
535 | } | |
536 | ||
d424ffde | 537 | /** |
42d30b83 DL |
538 | * test that get functioning does filtering |
539 | */ | |
00be9182 | 540 | public function testGetFilter() { |
6a488035 | 541 | $params = array( |
b8a3da18 | 542 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
543 | 'subject' => 'Make-it-Happen Meeting', |
544 | 'activity_date_time' => '20110316', | |
545 | 'duration' => 120, | |
546 | 'location' => 'Pensulvania', | |
547 | 'details' => 'a test activity', | |
548 | 'status_id' => 1, | |
549 | 'activity_name' => 'Test activity type', | |
6a488035 TO |
550 | 'priority_id' => 1, |
551 | ); | |
9f1b81e0 | 552 | $result = $this->callAPISuccess('Activity', 'Create', $params); |
553 | $this->callAPISuccess('Activity', 'Get', array('subject' => 'Make-it-Happen Meeting')); | |
6a488035 TO |
554 | $this->assertEquals(1, $result['count']); |
555 | $this->assertEquals('Make-it-Happen Meeting', $result['values'][$result['id']]['subject']); | |
9f1b81e0 | 556 | $this->callAPISuccess('Activity', 'Delete', array('id' => $result['id'])); |
6a488035 | 557 | } |
6e1bb60c N |
558 | |
559 | ||
560 | /** | |
561 | * Test civicrm_activity_get() with filter target_contact_id | |
562 | */ | |
00be9182 | 563 | public function testActivityGetTargetFilter() { |
6e1bb60c N |
564 | $params = $this->_params; |
565 | $contact1Params = array( | |
566 | 'first_name' => 'John', | |
567 | 'middle_name' => 'J.', | |
568 | 'last_name' => 'Anderson', | |
569 | 'prefix_id' => 3, | |
570 | 'suffix_id' => 3, | |
571 | 'email' => 'john_anderson@civicrm.org', | |
572 | 'contact_type' => 'Individual', | |
573 | ); | |
574 | ||
575 | $contact1 = $this->individualCreate($contact1Params); | |
576 | $contact2Params = array( | |
577 | 'first_name' => 'Michal', | |
578 | 'middle_name' => 'J.', | |
579 | 'last_name' => 'Anderson', | |
580 | 'prefix_id' => 3, | |
581 | 'suffix_id' => 3, | |
582 | 'email' => 'michal_anderson@civicrm.org', | |
583 | 'contact_type' => 'Individual', | |
584 | ); | |
585 | ||
586 | $contact2 = $this->individualCreate($contact2Params); | |
587 | ||
588 | $params['assignee_contact_id'] = array($contact1, $contact2); | |
589 | $params['target_contact_id'] = array($contact2 => $contact2); | |
590 | $activity = $this->callAPISuccess('Activity', 'Create', $params); | |
591 | ||
92915c55 | 592 | $activityget = $this->callAPISuccess('Activity', 'get', array( |
c301f76e | 593 | 'id' => $activity['id'], |
594 | 'target_contact_id' => $contact2, | |
595 | 'return.target_contact_id' => 1, | |
596 | )); | |
6e1bb60c N |
597 | $this->assertEquals($activity['id'], $activityget['id'], 'In line ' . __LINE__); |
598 | $this->assertEquals($contact2, $activityget['values'][$activityget['id']]['target_contact_id'][0], 'In line ' . __LINE__); | |
599 | ||
92915c55 | 600 | $activityget = $this->callAPISuccess('activity', 'get', array( |
c301f76e | 601 | 'target_contact_id' => $this->_contactID, |
602 | 'return.target_contact_id' => 1, | |
603 | 'id' => $activity['id'], | |
604 | )); | |
6e1bb60c N |
605 | if ($activityget['count'] > 0) { |
606 | $this->assertNotEquals($contact2, $activityget['values'][$activityget['id']]['target_contact_id'][0], 'In line ' . __LINE__); | |
607 | } | |
608 | } | |
609 | ||
d424ffde | 610 | /** |
42d30b83 DL |
611 | * test that get functioning does filtering |
612 | */ | |
00be9182 | 613 | public function testGetStatusID() { |
6a488035 | 614 | $params = array( |
b8a3da18 | 615 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
616 | 'subject' => 'Make-it-Happen Meeting', |
617 | 'activity_date_time' => '20110316', | |
618 | 'duration' => 120, | |
619 | 'location' => 'Pensulvania', | |
620 | 'details' => 'a test activity', | |
621 | 'status_id' => 1, | |
622 | 'activity_name' => 'Test activity type', | |
6a488035 TO |
623 | 'priority_id' => 1, |
624 | ); | |
b8a3da18 | 625 | $this->callAPISuccess('Activity', 'Create', $params); |
2b46f1da | 626 | $result = $this->callAPISuccess('Activity', 'Get', array('activity_status_id' => '1')); |
6a488035 TO |
627 | $this->assertEquals(1, $result['count'], 'one activity of status 1 should exist'); |
628 | ||
2b46f1da | 629 | $result = $this->callAPISuccess('Activity', 'Get', array('status_id' => '1')); |
6a488035 TO |
630 | $this->assertEquals(1, $result['count'], 'status_id should also work'); |
631 | ||
2b46f1da | 632 | $result = $this->callAPISuccess('Activity', 'Get', array('activity_status_id' => '2')); |
6a488035 | 633 | $this->assertEquals(0, $result['count'], 'No activities of status 1 should exist'); |
b8a3da18 | 634 | $result = $this->callAPISuccess('Activity', 'Get', array( |
92915c55 | 635 | 'version' => $this->_apiversion, |
c301f76e | 636 | 'status_id' => '2', |
92915c55 | 637 | )); |
6a488035 TO |
638 | $this->assertEquals(0, $result['count'], 'No activities of status 1 should exist'); |
639 | ||
42d30b83 | 640 | } |
6a488035 | 641 | |
d424ffde | 642 | /** |
42d30b83 DL |
643 | * test that get functioning does filtering |
644 | */ | |
00be9182 | 645 | public function testGetFilterMaxDate() { |
6a488035 | 646 | $params = array( |
b8a3da18 | 647 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
648 | 'subject' => 'Make-it-Happen Meeting', |
649 | 'activity_date_time' => '20110101', | |
650 | 'duration' => 120, | |
651 | 'location' => 'Pensulvania', | |
652 | 'details' => 'a test activity', | |
653 | 'status_id' => 1, | |
654 | 'activity_name' => 'Test activity type', | |
655 | 'version' => $this->_apiversion, | |
656 | 'priority_id' => 1, | |
657 | ); | |
b8a3da18 | 658 | $activityOne = $this->callAPISuccess('Activity', 'Create', $params); |
6a488035 | 659 | $params['activity_date_time'] = 20120216; |
b8a3da18 | 660 | $activityTwo = $this->callAPISuccess('Activity', 'Create', $params); |
661 | $result = $this->callAPISuccess('Activity', 'Get', array( | |
92915c55 TO |
662 | 'version' => 3, |
663 | )); | |
6a488035 TO |
664 | $description = "demonstrates _low filter (at time of writing doesn't work if contact_id is set"; |
665 | $subfile = "DateTimeLow"; | |
666 | $this->assertEquals(2, $result['count']); | |
667 | $params = array( | |
668 | 'version' => 3, | |
669 | 'filter.activity_date_time_low' => '20120101000000', | |
670 | 'sequential' => 1, | |
671 | ); | |
9f1b81e0 | 672 | $result = $this->callAPIAndDocument('Activity', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile); |
6a488035 TO |
673 | $this->assertEquals(1, $result['count'], 'in line ' . __LINE__); |
674 | $description = "demonstrates _high filter (at time of writing doesn't work if contact_id is set"; | |
675 | $subfile = "DateTimeHigh"; | |
676 | $this->assertEquals('2012-02-16 00:00:00', $result['values'][0]['activity_date_time'], 'in line ' . __LINE__); | |
677 | $params = array( | |
b8a3da18 | 678 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
679 | 'version' => 3, |
680 | 'filter.activity_date_time_high' => '20120101000000', | |
681 | 'sequential' => 1, | |
682 | ); | |
9f1b81e0 | 683 | $result = $this->callAPIAndDocument('Activity', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile); |
6a488035 TO |
684 | |
685 | $this->assertEquals(1, $result['count']); | |
686 | $this->assertEquals('2011-01-01 00:00:00', $result['values'][0]['activity_date_time'], 'in line ' . __LINE__); | |
687 | ||
b8a3da18 | 688 | $this->callAPISuccess('Activity', 'Delete', array('version' => 3, 'id' => $activityOne['id'])); |
689 | $this->callAPISuccess('Activity', 'Delete', array('version' => 3, 'id' => $activityTwo['id'])); | |
6a488035 TO |
690 | } |
691 | ||
692 | /** | |
693 | * Test civicrm_activity_get() with a good activity ID which | |
694 | * has associated custom data | |
695 | */ | |
00be9182 | 696 | public function testActivityGetGoodIDCustom() { |
6a488035 TO |
697 | $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); |
698 | ||
699 | $params = $this->_params; | |
700 | $params['custom_' . $ids['custom_field_id']] = "custom string"; | |
701 | ||
b8a3da18 | 702 | $result = $this->callAPISuccess($this->_entity, 'create', $params); |
9f1b81e0 | 703 | |
6a488035 TO |
704 | // Retrieve the test value |
705 | $params = array( | |
706 | 'activity_type_id' => $this->test_activity_type_value, | |
6a488035 TO |
707 | 'sequential' => 1, |
708 | 'return.custom_' . $ids['custom_field_id'] => 1, | |
709 | ); | |
9f1b81e0 | 710 | $result = $this->callAPIAndDocument('activity', 'get', $params, __FUNCTION__, __FILE__); |
711 | $this->assertEquals("custom string", $result['values'][0]['custom_' . $ids['custom_field_id']]); | |
6a488035 | 712 | |
9f1b81e0 | 713 | $this->assertEquals($this->test_activity_type_value, $result['values'][0]['activity_type_id']); |
6a488035 TO |
714 | $this->assertEquals('test activity type id', $result['values'][0]['subject'], 'In line ' . __LINE__); |
715 | $this->customFieldDelete($ids['custom_field_id']); | |
716 | $this->customGroupDelete($ids['custom_group_id']); | |
717 | } | |
718 | ||
719 | /** | |
720 | * Test civicrm_activity_get() with a good activity ID which | |
721 | * has associated custom data | |
722 | */ | |
00be9182 | 723 | public function testActivityGetContact_idCustom() { |
6a488035 TO |
724 | $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); |
725 | ||
726 | $params = $this->_params; | |
727 | $params['custom_' . $ids['custom_field_id']] = "custom string"; | |
728 | ||
b8a3da18 | 729 | $result = $this->callAPISuccess($this->_entity, 'create', $params); |
6a488035 TO |
730 | // Retrieve the test value |
731 | $params = array( | |
732 | 'contact_id' => $this->_params['source_contact_id'], | |
733 | 'activity_type_id' => $this->test_activity_type_value, | |
6a488035 TO |
734 | 'sequential' => 1, |
735 | 'return.custom_' . $ids['custom_field_id'] => 1, | |
736 | ); | |
9f1b81e0 | 737 | $result = $this->callAPIAndDocument('activity', 'get', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
738 | $this->assertEquals("custom string", $result['values'][0]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); |
739 | ||
6a488035 TO |
740 | $this->assertEquals($this->test_activity_type_value, $result['values'][0]['activity_type_id'], 'In line ' . __LINE__); |
741 | $this->assertEquals('test activity type id', $result['values'][0]['subject'], 'In line ' . __LINE__); | |
742 | $this->assertEquals($result['values'][0]['id'], $result['id'], 'in line ' . __LINE__); | |
743 | } | |
744 | ||
745 | /** | |
100fef9d | 746 | * Check activity deletion with empty params |
6a488035 | 747 | */ |
00be9182 | 748 | public function testDeleteActivityForEmptyParams() { |
6a488035 | 749 | $params = array('version' => $this->_apiversion); |
d0e1eff2 | 750 | $result = $this->callAPIFailure('activity', 'delete', $params); |
6a488035 TO |
751 | } |
752 | ||
753 | /** | |
100fef9d | 754 | * Check activity deletion without activity id |
6a488035 | 755 | */ |
00be9182 | 756 | public function testDeleteActivityWithoutId() { |
6a488035 TO |
757 | $params = array( |
758 | 'activity_name' => 'Meeting', | |
759 | 'version' => $this->_apiversion, | |
760 | ); | |
d0e1eff2 | 761 | $result = $this->callAPIFailure('activity', 'delete', $params); |
6a488035 TO |
762 | } |
763 | ||
764 | /** | |
100fef9d | 765 | * Check activity deletion without activity type |
6a488035 | 766 | */ |
00be9182 | 767 | public function testDeleteActivityWithoutActivityType() { |
6a488035 | 768 | $params = array('id' => 1); |
d0e1eff2 | 769 | $result = $this->callAPIFailure('activity', 'delete', $params); |
6a488035 TO |
770 | } |
771 | ||
772 | /** | |
100fef9d | 773 | * Check activity deletion with incorrect data |
6a488035 | 774 | */ |
00be9182 | 775 | public function testDeleteActivityWithIncorrectActivityType() { |
6a488035 TO |
776 | $params = array( |
777 | 'id' => 1, | |
778 | 'activity_name' => 'Test Activity', | |
779 | ); | |
780 | ||
d0e1eff2 | 781 | $result = $this->callAPIFailure('activity', 'delete', $params); |
6a488035 TO |
782 | } |
783 | ||
784 | /** | |
100fef9d | 785 | * Check activity deletion with correct data |
6a488035 | 786 | */ |
00be9182 | 787 | public function testDeleteActivity() { |
b8a3da18 | 788 | $result = $this->callAPISuccess('activity', 'create', $this->_params); |
6a488035 TO |
789 | $params = array( |
790 | 'id' => $result['id'], | |
791 | 'version' => $this->_apiversion, | |
792 | ); | |
793 | ||
b8a3da18 | 794 | $result = $this->callAPISuccess('activity', 'delete', $params); |
6a488035 | 795 | $this->documentMe($params, $result, __FUNCTION__, __FILE__); |
6a488035 TO |
796 | } |
797 | ||
6a488035 | 798 | /** |
100fef9d | 799 | * Check if required fields are not passed |
6a488035 | 800 | */ |
00be9182 | 801 | public function testActivityUpdateWithoutRequired() { |
6a488035 TO |
802 | $params = array( |
803 | 'subject' => 'this case should fail', | |
804 | 'scheduled_date_time' => date('Ymd'), | |
805 | ); | |
806 | ||
d0e1eff2 | 807 | $result = $this->callAPIFailure('activity', 'create', $params); |
6a488035 TO |
808 | } |
809 | ||
810 | /** | |
811 | * Test civicrm_activity_update() with non-numeric id | |
812 | */ | |
00be9182 | 813 | public function testActivityUpdateWithNonNumericId() { |
6a488035 TO |
814 | $params = array( |
815 | 'id' => 'lets break it', | |
816 | 'activity_name' => 'Meeting', | |
817 | 'subject' => 'this case should fail', | |
818 | 'scheduled_date_time' => date('Ymd'), | |
819 | ); | |
820 | ||
d0e1eff2 | 821 | $result = $this->callAPIFailure('activity', 'create', $params); |
6a488035 TO |
822 | } |
823 | ||
824 | /** | |
100fef9d | 825 | * Check with incorrect required fields |
6a488035 | 826 | */ |
00be9182 | 827 | public function testActivityUpdateWithIncorrectContactActivityType() { |
6a488035 TO |
828 | $params = array( |
829 | 'id' => 1, | |
830 | 'activity_name' => 'Test Activity', | |
831 | 'subject' => 'this case should fail', | |
832 | 'scheduled_date_time' => date('Ymd'), | |
b8a3da18 | 833 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
834 | ); |
835 | ||
b8a3da18 | 836 | $result = $this->callAPIFailure('activity', 'create', $params, |
837 | 'Invalid Activity Id'); | |
6a488035 TO |
838 | } |
839 | ||
840 | /** | |
841 | * Test civicrm_activity_update() to update an existing activity | |
842 | */ | |
00be9182 | 843 | public function testActivityUpdate() { |
b8a3da18 | 844 | $result = $this->callAPISuccess('activity', 'create', $this->_params); |
6a488035 TO |
845 | |
846 | $params = array( | |
847 | 'id' => $result['id'], | |
848 | 'subject' => 'Make-it-Happen Meeting', | |
849 | 'activity_date_time' => '20091011123456', | |
850 | 'duration' => 120, | |
851 | 'location' => '21, Park Avenue', | |
852 | 'details' => 'Lets update Meeting', | |
853 | 'status_id' => 1, | |
b8a3da18 | 854 | 'source_contact_id' => $this->_contactID, |
6a488035 | 855 | 'priority_id' => 1, |
6a488035 TO |
856 | ); |
857 | ||
b8a3da18 | 858 | $result = $this->callAPISuccess('activity', 'create', $params); |
6a488035 TO |
859 | //hack on date comparison - really we should make getAndCheck smarter to handle dates |
860 | $params['activity_date_time'] = '2009-10-11 12:34:56'; | |
42d30b83 DL |
861 | // we also unset source_contact_id since it is stored in an aux table |
862 | unset($params['source_contact_id']); | |
6a488035 TO |
863 | $this->getAndCheck($params, $result['id'], 'activity'); |
864 | } | |
865 | ||
866 | /** | |
867 | * Test civicrm_activity_update() with valid parameters | |
868 | * and some custom data | |
869 | */ | |
00be9182 | 870 | public function testActivityUpdateCustom() { |
6a488035 TO |
871 | $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); |
872 | ||
873 | $params = $this->_params; | |
874 | ||
875 | // Create an activity with custom data | |
876 | //this has been updated from the previous 'old format' function - need to make it work | |
877 | $params = array( | |
b8a3da18 | 878 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
879 | 'subject' => 'Make-it-Happen Meeting', |
880 | 'activity_date_time' => '2009-10-18', | |
881 | 'duration' => 120, | |
882 | 'location' => 'Pensulvania', | |
883 | 'details' => 'a test activity to check the update api', | |
884 | 'status_id' => 1, | |
885 | 'activity_name' => 'Test activity type', | |
886 | 'version' => $this->_apiversion, | |
887 | 'custom_' . $ids['custom_field_id'] => 'custom string', | |
888 | ); | |
b8a3da18 | 889 | $result = $this->callAPISuccess('activity', 'create', $params); |
6a488035 TO |
890 | |
891 | $activityId = $result['id']; | |
92915c55 | 892 | $result = $this->callAPISuccess($this->_entity, 'get', array( |
c301f76e | 893 | 'return.custom_' . $ids['custom_field_id'] => 1, |
894 | 'version' => 3, | |
895 | 'id' => $result['id'], | |
896 | )); | |
6a488035 TO |
897 | $this->assertEquals("custom string", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); |
898 | $this->assertEquals("2009-10-18 00:00:00", $result['values'][$result['id']]['activity_date_time'], ' in line ' . __LINE__); | |
b8a3da18 | 899 | $fields = $this->callAPISuccess('activity', 'getfields', array('version' => $this->_apiversion)); |
6a488035 TO |
900 | $this->assertTrue(is_array($fields['values']['custom_' . $ids['custom_field_id']])); |
901 | ||
902 | // Update the activity with custom data | |
903 | $params = array( | |
904 | 'id' => $activityId, | |
b8a3da18 | 905 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
906 | 'subject' => 'Make-it-Happen Meeting', |
907 | 'status_id' => 1, | |
908 | 'activity_name' => 'Test activity type', | |
909 | // add this since dates are messed up | |
910 | 'activity_date_time' => date('Ymd'), | |
911 | 'custom_' . $ids['custom_field_id'] => 'Updated my test data', | |
912 | 'version' => $this->_apiversion, | |
913 | ); | |
b8a3da18 | 914 | $result = $this->callAPISuccess('Activity', 'Create', $params); |
6a488035 | 915 | |
92915c55 | 916 | $result = $this->callAPISuccess($this->_entity, 'get', array( |
c301f76e | 917 | 'return.custom_' . $ids['custom_field_id'] => 1, |
918 | 'version' => 3, | |
919 | 'id' => $result['id'], | |
920 | )); | |
6a488035 TO |
921 | $this->assertEquals("Updated my test data", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); |
922 | } | |
923 | ||
924 | /** | |
925 | * Test civicrm_activity_update() for core activity fields | |
926 | * and some custom data | |
927 | */ | |
00be9182 | 928 | public function testActivityUpdateCheckCoreFields() { |
6a488035 TO |
929 | $params = $this->_params; |
930 | $contact1Params = array( | |
931 | 'first_name' => 'John', | |
932 | 'middle_name' => 'J.', | |
933 | 'last_name' => 'Anderson', | |
934 | 'prefix_id' => 3, | |
935 | 'suffix_id' => 3, | |
936 | 'email' => 'john_anderson@civicrm.org', | |
937 | 'contact_type' => 'Individual', | |
938 | ); | |
939 | ||
940 | $contact1 = $this->individualCreate($contact1Params); | |
941 | $contact2Params = array( | |
942 | 'first_name' => 'Michal', | |
943 | 'middle_name' => 'J.', | |
944 | 'last_name' => 'Anderson', | |
945 | 'prefix_id' => 3, | |
946 | 'suffix_id' => 3, | |
947 | 'email' => 'michal_anderson@civicrm.org', | |
948 | 'contact_type' => 'Individual', | |
949 | ); | |
950 | ||
951 | $contact2 = $this->individualCreate($contact2Params); | |
952 | ||
953 | $params['assignee_contact_id'] = array($contact1, $contact2); | |
954 | $params['target_contact_id'] = array($contact2 => $contact2); | |
b8a3da18 | 955 | $result = $this->callAPISuccess('Activity', 'Create', $params); |
6a488035 | 956 | |
6a488035 | 957 | $activityId = $result['id']; |
6a488035 TO |
958 | $getParams = array( |
959 | 'return.assignee_contact_id' => 1, | |
960 | 'return.target_contact_id' => 1, | |
961 | 'version' => $this->_apiversion, | |
962 | 'id' => $activityId, | |
963 | ); | |
481a74f4 | 964 | $result = $this->callAPISuccess($this->_entity, 'get', $getParams); |
6a488035 TO |
965 | $assignee = $result['values'][$result['id']]['assignee_contact_id']; |
966 | $target = $result['values'][$result['id']]['target_contact_id']; | |
967 | $this->assertEquals(2, count($assignee), ' in line ' . __LINE__); | |
968 | $this->assertEquals(1, count($target), ' in line ' . __LINE__); | |
969 | $this->assertEquals(TRUE, in_array($contact1, $assignee), ' in line ' . __LINE__); | |
970 | $this->assertEquals(TRUE, in_array($contact2, $target), ' in line ' . __LINE__); | |
971 | ||
972 | $contact3Params = array( | |
973 | 'first_name' => 'Jijo', | |
974 | 'middle_name' => 'J.', | |
975 | 'last_name' => 'Anderson', | |
976 | 'prefix_id' => 3, | |
977 | 'suffix_id' => 3, | |
978 | 'email' => 'jijo_anderson@civicrm.org', | |
979 | 'contact_type' => 'Individual', | |
980 | ); | |
981 | ||
982 | $contact4Params = array( | |
983 | 'first_name' => 'Grant', | |
984 | 'middle_name' => 'J.', | |
985 | 'last_name' => 'Anderson', | |
986 | 'prefix_id' => 3, | |
987 | 'suffix_id' => 3, | |
988 | 'email' => 'grant_anderson@civicrm.org', | |
989 | 'contact_type' => 'Individual', | |
990 | ); | |
991 | ||
992 | $contact3 = $this->individualCreate($contact3Params); | |
993 | $contact4 = $this->individualCreate($contact4Params); | |
994 | ||
995 | $params = array(); | |
996 | $params['id'] = $activityId; | |
6a488035 TO |
997 | $params['assignee_contact_id'] = array($contact3 => $contact3); |
998 | $params['target_contact_id'] = array($contact4 => $contact4); | |
999 | ||
b8a3da18 | 1000 | $result = $this->callAPISuccess('activity', 'create', $params); |
6a488035 TO |
1001 | |
1002 | $this->assertEquals($activityId, $result['id'], ' in line ' . __LINE__); | |
1003 | ||
b8a3da18 | 1004 | $result = $this->callAPISuccess( |
42d30b83 DL |
1005 | $this->_entity, |
1006 | 'get', | |
1007 | array( | |
1008 | 'return.assignee_contact_id' => 1, | |
1009 | 'return.target_contact_id' => 1, | |
1010 | 'return.source_contact_id' => 1, | |
21dfd5f5 | 1011 | 'id' => $result['id'], |
42d30b83 DL |
1012 | ) |
1013 | ); | |
6a488035 TO |
1014 | |
1015 | $assignee = $result['values'][$result['id']]['assignee_contact_id']; | |
1016 | $target = $result['values'][$result['id']]['target_contact_id']; | |
1017 | ||
1018 | $this->assertEquals(1, count($assignee), ' in line ' . __LINE__); | |
1019 | $this->assertEquals(1, count($target), ' in line ' . __LINE__); | |
1020 | $this->assertEquals(TRUE, in_array($contact3, $assignee), ' in line ' . __LINE__); | |
1021 | $this->assertEquals(TRUE, in_array($contact4, $target), ' in line ' . __LINE__); | |
1022 | ||
1023 | foreach ($this->_params as $fld => $val) { | |
9f1b81e0 | 1024 | $this->assertEquals($val, $result['values'][$result['id']][$fld]); |
6a488035 TO |
1025 | } |
1026 | } | |
1027 | ||
1028 | /** | |
1029 | * Test civicrm_activity_update() where the DB has a date_time | |
1030 | * value and there is none in the update params. | |
1031 | */ | |
00be9182 | 1032 | public function testActivityUpdateNotDate() { |
b8a3da18 | 1033 | $result = $this->callAPISuccess('activity', 'create', $this->_params); |
6a488035 TO |
1034 | |
1035 | $params = array( | |
1036 | 'id' => $result['id'], | |
1037 | 'subject' => 'Make-it-Happen Meeting', | |
1038 | 'duration' => 120, | |
1039 | 'location' => '21, Park Avenue', | |
1040 | 'details' => 'Lets update Meeting', | |
1041 | 'status_id' => 1, | |
b8a3da18 | 1042 | 'source_contact_id' => $this->_contactID, |
6a488035 | 1043 | 'priority_id' => 1, |
6a488035 TO |
1044 | ); |
1045 | ||
b8a3da18 | 1046 | $result = $this->callAPISuccess('activity', 'create', $params); |
6a488035 TO |
1047 | //hack on date comparison - really we should make getAndCheck smarter to handle dates |
1048 | $params['activity_date_time'] = $this->_params['activity_date_time']; | |
42d30b83 DL |
1049 | // we also unset source_contact_id since it is stored in an aux table |
1050 | unset($params['source_contact_id']); | |
6a488035 TO |
1051 | $this->getAndCheck($params, $result['id'], 'activity'); |
1052 | } | |
1053 | ||
1054 | /** | |
100fef9d | 1055 | * Check activity update with status |
6a488035 | 1056 | */ |
00be9182 | 1057 | public function testActivityUpdateWithStatus() { |
b8a3da18 | 1058 | $activity = $this->callAPISuccess('activity', 'create', $this->_params); |
6a488035 TO |
1059 | $params = array( |
1060 | 'id' => $activity['id'], | |
b8a3da18 | 1061 | 'source_contact_id' => $this->_contactID, |
6a488035 TO |
1062 | 'subject' => 'Hurry update works', |
1063 | 'status_id' => 1, | |
1064 | 'activity_name' => 'Test activity type', | |
6a488035 TO |
1065 | ); |
1066 | ||
b8a3da18 | 1067 | $result = $this->callAPISuccess('activity', 'create', $params); |
9f1b81e0 | 1068 | $this->assertEquals($result['id'], $activity['id']); |
1069 | $this->assertEquals($result['values'][$activity['id']]['subject'], 'Hurry update works'); | |
1070 | $this->assertEquals($result['values'][$activity['id']]['status_id'], 1 | |
6a488035 TO |
1071 | ); |
1072 | } | |
1073 | ||
1074 | /** | |
1075 | * Test civicrm_activity_update() where the source_contact_id | |
1076 | * is not in the update params. | |
1077 | */ | |
00be9182 | 1078 | public function testActivityUpdateKeepSource() { |
b8a3da18 | 1079 | $activity = $this->callAPISuccess('activity', 'create', $this->_params); |
6a488035 | 1080 | // Updating the activity but not providing anything for the source contact |
b8a3da18 | 1081 | // (It was set as $this->_contactID earlier.) |
6a488035 TO |
1082 | $params = array( |
1083 | 'id' => $activity['id'], | |
1084 | 'subject' => 'Updated Make-it-Happen Meeting', | |
1085 | 'duration' => 120, | |
1086 | 'location' => '21, Park Avenue', | |
1087 | 'details' => 'Lets update Meeting', | |
1088 | 'status_id' => 1, | |
1089 | 'activity_name' => 'Test activity type', | |
1090 | 'priority_id' => 1, | |
6a488035 TO |
1091 | ); |
1092 | ||
b8a3da18 | 1093 | $result = $this->callAPISuccess('activity', 'create', $params); |
9f1b81e0 | 1094 | $findactivity = $this->callAPISuccess('Activity', 'Get', array('id' => $activity['id'])); |
6a488035 TO |
1095 | } |
1096 | ||
1097 | /** | |
1098 | * Test civicrm_activities_contact_get() | |
1099 | */ | |
00be9182 | 1100 | public function testActivitiesContactGet() { |
b8a3da18 | 1101 | $activity = $this->callAPISuccess('activity', 'create', $this->_params); |
1102 | $activity2 = $this->callAPISuccess('activity', 'create', $this->_params2); | |
1103 | // Get activities associated with contact $this->_contactID | |
6a488035 | 1104 | $params = array( |
b8a3da18 | 1105 | 'contact_id' => $this->_contactID, |
6a488035 | 1106 | ); |
b8a3da18 | 1107 | $result = $this->callAPISuccess('activity', 'get', $params); |
6a488035 | 1108 | |
6a488035 TO |
1109 | $this->assertEquals(2, $result['count'], 'In line ' . __LINE__); |
1110 | $this->assertEquals($this->test_activity_type_value, $result['values'][$activity['id']]['activity_type_id'], 'In line ' . __LINE__); | |
1111 | $this->assertEquals('Test activity type', $result['values'][$activity['id']]['activity_name'], 'In line ' . __LINE__); | |
1112 | $this->assertEquals('Test activity type', $result['values'][$activity2['id']]['activity_name'], 'In line ' . __LINE__); | |
1113 | } | |
92915c55 | 1114 | |
d424ffde | 1115 | /** |
42d30b83 DL |
1116 | * test chained Activity format |
1117 | */ | |
00be9182 | 1118 | public function testchainedActivityGet() { |
6a488035 | 1119 | |
b8a3da18 | 1120 | $activity = $this->callAPISuccess('Contact', 'Create', array( |
92915c55 TO |
1121 | 'display_name' => "bob brown", |
1122 | 'contact_type' => 'Individual', | |
1123 | 'api.activity_type.create' => array( | |
1124 | 'weight' => '2', | |
1125 | 'label' => 'send out letters', | |
1126 | 'filter' => 0, | |
1127 | 'is_active' => 1, | |
1128 | 'is_optgroup' => 1, | |
1129 | 'is_default' => 0, | |
1130 | ), | |
1131 | 'api.activity.create' => array( | |
1132 | 'subject' => 'send letter', | |
c301f76e | 1133 | 'activity_type_id' => '$value.api.activity_type.create.values.0.value', |
92915c55 TO |
1134 | ), |
1135 | )); | |
6a488035 | 1136 | |
b8a3da18 | 1137 | $result = $this->callAPISuccess('Activity', 'Get', array( |
92915c55 TO |
1138 | 'id' => $activity['id'], |
1139 | 'return.assignee_contact_id' => 1, | |
1140 | 'api.contact.get' => array('api.pledge.get' => 1), | |
1141 | )); | |
6a488035 TO |
1142 | } |
1143 | ||
6a488035 TO |
1144 | /** |
1145 | * Test civicrm_activity_contact_get() with invalid Contact Id | |
1146 | */ | |
00be9182 | 1147 | public function testActivitiesContactGetWithInvalidContactId() { |
6a488035 | 1148 | $params = array('contact_id' => 'contact'); |
d0e1eff2 | 1149 | $result = $this->callAPIFailure('activity', 'get', $params); |
6a488035 TO |
1150 | } |
1151 | ||
1152 | /** | |
1153 | * Test civicrm_activity_contact_get() with contact having no Activity | |
1154 | */ | |
00be9182 | 1155 | public function testActivitiesContactGetHavingNoActivity() { |
6a488035 TO |
1156 | $params = array( |
1157 | 'first_name' => 'dan', | |
1158 | 'last_name' => 'conberg', | |
1159 | 'email' => 'dan.conberg@w.co.in', | |
1160 | 'contact_type' => 'Individual', | |
6a488035 TO |
1161 | ); |
1162 | ||
b8a3da18 | 1163 | $contact = $this->callAPISuccess('contact', 'create', $params); |
6a488035 TO |
1164 | $params = array( |
1165 | 'contact_id' => $contact['id'], | |
6a488035 | 1166 | ); |
b8a3da18 | 1167 | $result = $this->callAPISuccess('activity', 'get', $params); |
6a488035 TO |
1168 | $this->assertEquals($result['count'], 0, 'in line ' . __LINE__); |
1169 | } | |
1170 | ||
00be9182 | 1171 | public function testGetFields() { |
b8a3da18 | 1172 | $params = array('action' => 'create'); |
9f1b81e0 | 1173 | $result = $this->callAPIAndDocument('activity', 'getfields', $params, __FUNCTION__, __FILE__, NULL, NULL, 'getfields'); |
6a488035 TO |
1174 | $this->assertTrue(is_array($result['values']), 'get fields doesnt return values array in line ' . __LINE__); |
1175 | // $this->assertTrue(is_array($result['values']['priority_id']['options'])); | |
1176 | foreach ($result['values'] as $key => $value) { | |
1177 | $this->assertTrue(is_array($value), $key . " is not an array in line " . __LINE__); | |
1178 | } | |
1179 | } | |
96025800 | 1180 | |
6a488035 | 1181 | } |